| /* |
| * Copyright (c) 2021 The Fuchsia Authors. All Rights Reserved. |
| * |
| * Permission is hereby granted, free of charge, to any person obtaining a |
| * copy of this software and associated documentation files (the |
| * "Software"), to deal in the Software without restriction, including |
| * without limitation the rights to use, copy, modify, merge, publish, |
| * distribute, sub license, and/or sell copies of the Software, and to |
| * permit persons to whom the Software is furnished to do so, subject to |
| * the following conditions: |
| * |
| * The above copyright notice and this permission notice (including the |
| * next paragraph) shall be included in all copies or substantial portions |
| * of the Software. |
| * |
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR |
| * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| */ |
| |
| #include <filesystem> |
| #include <lib/zx/channel.h> |
| #include <lib/fdio/directory.h> |
| #include <assert.h> |
| #include <stdlib.h> |
| #include <string.h> |
| #include <va/va_magma.h> |
| #include "va_display.h" |
| |
| // Use a global here following the pattern for the other implementations. |
| static magma_device_t magma_device; |
| |
| static VADisplay va_open_display_magma(void) |
| { |
| const uint64_t kIntelVendorId = 0x8086; |
| |
| for (auto& p : std::filesystem::directory_iterator("/dev/class/gpu")) { |
| { |
| zx::channel local, remote; |
| zx_status_t zx_status = zx::channel::create(0 /*flags*/, &local, &remote); |
| assert(zx_status == ZX_OK); |
| zx_status = fdio_service_connect(p.path().c_str(), remote.release()); |
| assert(zx_status == ZX_OK); |
| magma_status_t status = magma_device_import(local.release(), &magma_device); |
| assert(status == MAGMA_STATUS_OK); |
| if (status != MAGMA_STATUS_OK) |
| continue; |
| } |
| { |
| uint64_t vendor_id; |
| magma_status_t magma_status = magma_query2(magma_device, MAGMA_QUERY_VENDOR_ID, &vendor_id); |
| if (magma_status == MAGMA_STATUS_OK && vendor_id == kIntelVendorId) { |
| break; |
| } |
| } |
| |
| magma_device_release(magma_device); |
| magma_device = {}; |
| } |
| |
| if (!magma_device) |
| return NULL; |
| |
| return vaGetDisplayMagma(magma_device); |
| } |
| |
| static void va_close_display_magma(VADisplay va_dpy) |
| { |
| if (magma_device) { |
| magma_device_release(magma_device); |
| magma_device = {}; |
| } |
| } |
| |
| static VAStatus va_put_surface_magma( |
| VADisplay va_dpy, |
| VASurfaceID surface, |
| const VARectangle *src_rect, |
| const VARectangle *dst_rect |
| ) |
| { |
| return VA_STATUS_ERROR_UNIMPLEMENTED; |
| } |
| |
| extern "C" const VADisplayHooks va_display_hooks_magma = { |
| "magma", |
| va_open_display_magma, |
| va_close_display_magma, |
| va_put_surface_magma, |
| }; |