| // Copyright 2026 The Fuchsia Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #ifndef SRC_VIRTUALIZATION_TESTS_LIB_GPU_ENCLOSED_GUEST_H_ | |
| #define SRC_VIRTUALIZATION_TESTS_LIB_GPU_ENCLOSED_GUEST_H_ | |
| #include <lib/async/dispatcher.h> | |
| #include <lib/sys/cpp/service_directory.h> | |
| #include <zircon/errors.h> | |
| #include <zircon/types.h> | |
| #include <cstdint> | |
| #include <memory> | |
| #include <optional> | |
| #include <utility> | |
| #include "src/ui/testing/ui_test_manager/ui_test_manager.h" | |
| #include "src/virtualization/tests/lib/enclosed_guest.h" | |
| struct DisplayInfo { | |
| uint32_t width; | |
| uint32_t height; | |
| }; | |
| namespace gpu_enclosed_guest::internal { | |
| class GpuUiSession { | |
| public: | |
| std::unique_ptr<sys::ServiceDirectory> Start(EnclosedGuest& guest, | |
| GuestLaunchInfo& guest_launch_info); | |
| void Teardown(EnclosedGuest& guest); | |
| DisplayInfo WaitForDisplay(EnclosedGuest& guest); | |
| private: | |
| std::optional<ui_testing::UITestManager> ui_test_manager_; | |
| }; | |
| } // namespace gpu_enclosed_guest::internal | |
| template <typename BaseGuest> | |
| class GpuEnclosedGuest final : public BaseGuest { | |
| public: | |
| GpuEnclosedGuest(async_dispatcher_t* dispatcher, EnclosedGuest::RunLoopUntilFunc run_loop_until) | |
| : BaseGuest(dispatcher, std::move(run_loop_until)) {} | |
| ~GpuEnclosedGuest() override { gpu_ui_.Teardown(*this); } | |
| zx_status_t BuildLaunchInfo(GuestLaunchInfo* launch_info) override { | |
| if (zx_status_t status = BaseGuest::BuildLaunchInfo(launch_info); status != ZX_OK) { | |
| return status; | |
| } | |
| launch_info->config.set_virtio_gpu(true); | |
| return ZX_OK; | |
| } | |
| // Waits for a view to be created and presented using the GraphicalPresenter protocol. | |
| DisplayInfo WaitForDisplay() { return gpu_ui_.WaitForDisplay(*this); } | |
| protected: | |
| std::unique_ptr<sys::ServiceDirectory> StartGuestRealm( | |
| GuestLaunchInfo& guest_launch_info) override { | |
| return gpu_ui_.Start(*this, guest_launch_info); | |
| } | |
| private: | |
| gpu_enclosed_guest::internal::GpuUiSession gpu_ui_; | |
| }; | |
| using ZirconGpuEnclosedGuest = GpuEnclosedGuest<ZirconEnclosedGuest>; | |
| using DebianGpuEnclosedGuest = GpuEnclosedGuest<DebianEnclosedGuest>; | |
| #endif // SRC_VIRTUALIZATION_TESTS_LIB_GPU_ENCLOSED_GUEST_H_ |