From bd7931ff236843fd2943265df3395dbf4c6e38f3 Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Mon, 19 Dec 2022 15:30:23 +0100 Subject: [PATCH] LibGPU+LibVirtGPU: Allow loading the driver and instantiating the device This adds LibVirtGPU to the list of allowed drivers in LibGPU and adds a factory method to create the device to libVirtGPU. --- Userland/Libraries/LibGPU/Driver.cpp | 3 +++ Userland/Libraries/LibVirtGPU/Device.cpp | 15 +++++++++++++++ Userland/Libraries/LibVirtGPU/Device.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/Userland/Libraries/LibGPU/Driver.cpp b/Userland/Libraries/LibGPU/Driver.cpp index 85e0b56cf6..4927d48a85 100644 --- a/Userland/Libraries/LibGPU/Driver.cpp +++ b/Userland/Libraries/LibGPU/Driver.cpp @@ -13,16 +13,19 @@ namespace GPU { // FIXME: Think of a better way to configure these paths. Maybe use ConfigServer? +// clang-format off static HashMap const s_driver_path_map { #if defined(AK_OS_SERENITY) { "softgpu", "libsoftgpu.so.serenity" }, + { "virtgpu", "libvirtgpu.so.serenity" }, #elif defined(AK_OS_MACOS) { "softgpu", "liblagom-softgpu.dylib" }, #else { "softgpu", "liblagom-softgpu.so.0" }, #endif }; +// clang-format on static HashMap> s_loaded_drivers; diff --git a/Userland/Libraries/LibVirtGPU/Device.cpp b/Userland/Libraries/LibVirtGPU/Device.cpp index 42c351f428..68c25adda4 100644 --- a/Userland/Libraries/LibVirtGPU/Device.cpp +++ b/Userland/Libraries/LibVirtGPU/Device.cpp @@ -4,12 +4,18 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include namespace VirtGPU { +ErrorOr> Device::create(Gfx::IntSize) +{ + return make(); +} + GPU::DeviceInfo Device::info() const { return { @@ -173,3 +179,12 @@ void Device::bind_fragment_shader(RefPtr) } } + +extern "C" GPU::Device* serenity_gpu_create_device(Gfx::IntSize size) +{ + auto device_or_error = VirtGPU::Device::create(size); + if (device_or_error.is_error()) + return nullptr; + + return device_or_error.release_value().leak_ptr(); +} diff --git a/Userland/Libraries/LibVirtGPU/Device.h b/Userland/Libraries/LibVirtGPU/Device.h index 9e7fed22f6..148d28ab8a 100644 --- a/Userland/Libraries/LibVirtGPU/Device.h +++ b/Userland/Libraries/LibVirtGPU/Device.h @@ -12,6 +12,8 @@ namespace VirtGPU { class Device final : public GPU::Device { public: + static ErrorOr> create(Gfx::IntSize min_size); + virtual GPU::DeviceInfo info() const override; virtual void draw_primitives(GPU::PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, Vector& vertices) override;