This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[shell tests] Integrate Vulkan with Shell Tests #16621
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ | |
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/shell/common/shell_test_platform_view_vulkan.h" | ||
| #include "flutter/shell/gpu/gpu_surface_vulkan.h" | ||
|
|
||
| namespace flutter { | ||
| namespace testing { | ||
|
|
@@ -30,7 +29,7 @@ void ShellTestPlatformViewVulkan::SimulateVSync() { | |
|
|
||
| // |PlatformView| | ||
| std::unique_ptr<Surface> ShellTestPlatformViewVulkan::CreateRenderingSurface() { | ||
| return std::make_unique<GPUSurfaceVulkan>(this, nullptr, true); | ||
| return std::make_unique<OffScreenSurface>(proc_table_); | ||
| } | ||
|
|
||
| // |PlatformView| | ||
|
|
@@ -40,9 +39,132 @@ PointerDataDispatcherMaker ShellTestPlatformViewVulkan::GetDispatcherMaker() { | |
| }; | ||
| } | ||
|
|
||
| // |GPUSurfaceVulkanDelegate| | ||
| fml::RefPtr<vulkan::VulkanProcTable> ShellTestPlatformViewVulkan::vk() { | ||
| return proc_table_; | ||
| // TODO(gw280): This code was forked from vulkan_window.cc specifically for | ||
| // shell_test. | ||
| // We need to merge this functionality back into //vulkan. | ||
| // https://github.com/flutter/flutter/issues/51132 | ||
| ShellTestPlatformViewVulkan::OffScreenSurface::OffScreenSurface( | ||
| fml::RefPtr<vulkan::VulkanProcTable> vk) | ||
| : valid_(false), vk_(std::move(vk)) { | ||
| if (!vk_ || !vk_->HasAcquiredMandatoryProcAddresses()) { | ||
| FML_DLOG(ERROR) << "Proc table has not acquired mandatory proc addresses."; | ||
| return; | ||
| } | ||
|
|
||
| // Create the application instance. | ||
| std::vector<std::string> extensions = {}; | ||
|
|
||
| application_ = std::make_unique<vulkan::VulkanApplication>( | ||
| *vk_, "FlutterTest", std::move(extensions)); | ||
|
|
||
| if (!application_->IsValid() || !vk_->AreInstanceProcsSetup()) { | ||
| // Make certain the application instance was created and it setup the | ||
| // instance proc table entries. | ||
| FML_DLOG(ERROR) << "Instance proc addresses have not been setup."; | ||
| return; | ||
| } | ||
|
|
||
| // Create the device. | ||
|
|
||
| logical_device_ = application_->AcquireFirstCompatibleLogicalDevice(); | ||
|
|
||
| if (logical_device_ == nullptr || !logical_device_->IsValid() || | ||
| !vk_->AreDeviceProcsSetup()) { | ||
| // Make certain the device was created and it setup the device proc table | ||
| // entries. | ||
| FML_DLOG(ERROR) << "Device proc addresses have not been setup."; | ||
| return; | ||
| } | ||
|
|
||
| // Create the Skia GrContext. | ||
| if (!CreateSkiaGrContext()) { | ||
| FML_DLOG(ERROR) << "Could not create Skia context."; | ||
| return; | ||
| } | ||
|
|
||
| valid_ = true; | ||
| } | ||
|
|
||
| bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaGrContext() { | ||
| GrVkBackendContext backend_context; | ||
|
|
||
| if (!CreateSkiaBackendContext(&backend_context)) { | ||
| FML_DLOG(ERROR) << "Could not create Skia backend context."; | ||
| return false; | ||
| } | ||
|
|
||
| sk_sp<GrContext> context = GrContext::MakeVulkan(backend_context); | ||
|
|
||
| if (context == nullptr) { | ||
| FML_DLOG(ERROR) << "Failed to create GrContext"; | ||
| return false; | ||
| } | ||
|
|
||
| context->setResourceCacheLimits(vulkan::kGrCacheMaxCount, | ||
| vulkan::kGrCacheMaxByteSize); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this currently causes a test failure because on the GL backend we set the max byte size to 24MB, which doesn't match the Vulkan defaults. I think we want to keep using the Vulkan defaults but we will need to adjust the unit test appropriately. I'm good with landing this now and figuring out how to adjust the unit tests in the follow up PR to enable the unittests. |
||
|
|
||
| context_ = context; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaBackendContext( | ||
| GrVkBackendContext* context) { | ||
| auto getProc = vk_->CreateSkiaGetProc(); | ||
|
|
||
| if (getProc == nullptr) { | ||
| FML_DLOG(ERROR) << "GetProcAddress is null"; | ||
| return false; | ||
| } | ||
|
|
||
| uint32_t skia_features = 0; | ||
| if (!logical_device_->GetPhysicalDeviceFeaturesSkia(&skia_features)) { | ||
| FML_DLOG(ERROR) << "Failed to get Physical Device features"; | ||
| return false; | ||
| } | ||
|
|
||
| context->fInstance = application_->GetInstance(); | ||
| context->fPhysicalDevice = logical_device_->GetPhysicalDeviceHandle(); | ||
| context->fDevice = logical_device_->GetHandle(); | ||
| context->fQueue = logical_device_->GetQueueHandle(); | ||
| context->fGraphicsQueueIndex = logical_device_->GetGraphicsQueueIndex(); | ||
| context->fMinAPIVersion = application_->GetAPIVersion(); | ||
| context->fMaxAPIVersion = application_->GetAPIVersion(); | ||
| context->fFeatures = skia_features; | ||
| context->fGetProc = std::move(getProc); | ||
| context->fOwnsInstanceAndDevice = false; | ||
| return true; | ||
| } | ||
|
|
||
| ShellTestPlatformViewVulkan::OffScreenSurface::~OffScreenSurface() {} | ||
|
|
||
| bool ShellTestPlatformViewVulkan::OffScreenSurface::IsValid() { | ||
| return valid_; | ||
| } | ||
|
|
||
| std::unique_ptr<SurfaceFrame> | ||
| ShellTestPlatformViewVulkan::OffScreenSurface::AcquireFrame( | ||
| const SkISize& size) { | ||
| auto image_info = SkImageInfo::Make(size, SkColorType::kRGBA_8888_SkColorType, | ||
| SkAlphaType::kOpaque_SkAlphaType); | ||
| auto surface = SkSurface::MakeRenderTarget(context_.get(), SkBudgeted::kNo, | ||
| image_info, 0, nullptr); | ||
| SurfaceFrame::SubmitCallback callback = | ||
| [](const SurfaceFrame&, SkCanvas* canvas) -> bool { return true; }; | ||
|
|
||
| return std::make_unique<SurfaceFrame>(std::move(surface), true, | ||
| std::move(callback)); | ||
| } | ||
|
|
||
| GrContext* ShellTestPlatformViewVulkan::OffScreenSurface::GetContext() { | ||
| return context_.get(); | ||
| } | ||
|
|
||
| SkMatrix ShellTestPlatformViewVulkan::OffScreenSurface::GetRootTransformation() | ||
| const { | ||
| SkMatrix matrix; | ||
| matrix.reset(); | ||
| return matrix; | ||
| } | ||
|
|
||
| } // namespace testing | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.