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
Extract backend-specific code in ShellTestPlatformView #56722
Merged
auto-submit
merged 1 commit into
flutter:main
from
cbracken:arc-shell-test-platform-view
Nov 22, 2024
Merged
Changes from all commits
Commits
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,52 +4,25 @@ | |
|
|
||
| #include "flutter/shell/common/shell_test_platform_view_metal.h" | ||
|
|
||
| #import <Metal/Metal.h> | ||
|
|
||
| #include <utility> | ||
|
|
||
| #include "flutter/shell/gpu/gpu_surface_metal_impeller.h" | ||
| #include "flutter/shell/gpu/gpu_surface_metal_skia.h" | ||
| #include "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h" | ||
| #include "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h" | ||
|
|
||
| FLUTTER_ASSERT_ARC | ||
|
|
||
| namespace flutter { | ||
| namespace testing { | ||
|
|
||
| // This is out of the header so that shell_test_platform_view_metal.h can be included in | ||
| // non-Objective-C TUs. | ||
| struct DarwinContextMetal { | ||
| FlutterDarwinContextMetalSkia* skia_context; | ||
| FlutterDarwinContextMetalImpeller* impeller_context; | ||
| id<MTLTexture> offscreen_texture; | ||
| }; | ||
|
Member
Author
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. No longer necessary -- these fields are now directly on |
||
| namespace flutter::testing { | ||
|
|
||
| static std::unique_ptr<DarwinContextMetal> CreateDarwinContext( | ||
| bool impeller, | ||
| std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::CreateMetal( | ||
| PlatformView::Delegate& delegate, | ||
| const TaskRunners& task_runners, | ||
| const std::shared_ptr<ShellTestVsyncClock>& vsync_clock, | ||
| const CreateVsyncWaiter& create_vsync_waiter, | ||
| const std::shared_ptr<ShellTestExternalViewEmbedder>& shell_test_external_view_embedder, | ||
| const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch) { | ||
| FlutterDarwinContextMetalSkia* skia_context = nil; | ||
| FlutterDarwinContextMetalImpeller* impeller_context = nil; | ||
| id<MTLDevice> device = nil; | ||
| if (impeller) { | ||
| impeller_context = [[FlutterDarwinContextMetalImpeller alloc] init:is_gpu_disabled_sync_switch]; | ||
| FML_CHECK(impeller_context.context); | ||
| device = impeller_context.context->GetMTLDevice(); | ||
| } else { | ||
| skia_context = [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice]; | ||
| FML_CHECK(skia_context.mainContext); | ||
| device = skia_context.device; | ||
| } | ||
| auto descriptor = | ||
| [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm | ||
| width:800 | ||
| height:600 | ||
| mipmapped:NO]; | ||
| descriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead; | ||
| id<MTLTexture> offscreen_texture = [device newTextureWithDescriptor:descriptor]; | ||
| return std::make_unique<DarwinContextMetal>( | ||
| DarwinContextMetal{skia_context, impeller_context, offscreen_texture}); | ||
| return std::make_unique<ShellTestPlatformViewMetal>( | ||
| delegate, task_runners, vsync_clock, create_vsync_waiter, shell_test_external_view_embedder, | ||
| is_gpu_disabled_sync_switch); | ||
| } | ||
|
|
||
| ShellTestPlatformViewMetal::ShellTestPlatformViewMetal( | ||
|
|
@@ -61,11 +34,28 @@ | |
| const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch) | ||
| : ShellTestPlatformView(delegate, task_runners), | ||
| GPUSurfaceMetalDelegate(MTLRenderTargetType::kMTLTexture), | ||
| metal_context_( | ||
| CreateDarwinContext(GetSettings().enable_impeller, is_gpu_disabled_sync_switch)), | ||
| create_vsync_waiter_(std::move(create_vsync_waiter)), | ||
| vsync_clock_(std::move(vsync_clock)), | ||
| shell_test_external_view_embedder_(std::move(shell_test_external_view_embedder)) {} | ||
| shell_test_external_view_embedder_(std::move(shell_test_external_view_embedder)) { | ||
| id<MTLDevice> device = nil; | ||
| if (GetSettings().enable_impeller) { | ||
| impeller_context_ = | ||
| [[FlutterDarwinContextMetalImpeller alloc] init:is_gpu_disabled_sync_switch]; | ||
| FML_CHECK(impeller_context_.context); | ||
| device = impeller_context_.context->GetMTLDevice(); | ||
| } else { | ||
| skia_context_ = [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice]; | ||
| FML_CHECK(skia_context_.mainContext); | ||
| device = skia_context_.device; | ||
| } | ||
|
Member
Author
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. In a followup patch I'll replace the separate |
||
| auto descriptor = | ||
| [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm | ||
| width:800 | ||
| height:600 | ||
| mipmapped:NO]; | ||
| descriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead; | ||
| offscreen_texture_ = [device newTextureWithDescriptor:descriptor]; | ||
| } | ||
|
|
||
| ShellTestPlatformViewMetal::~ShellTestPlatformViewMetal() = default; | ||
|
|
||
|
|
@@ -93,16 +83,16 @@ | |
| // |PlatformView| | ||
| std::unique_ptr<Surface> ShellTestPlatformViewMetal::CreateRenderingSurface() { | ||
| if (GetSettings().enable_impeller) { | ||
| auto context = metal_context_->impeller_context.context; | ||
| auto context = impeller_context_.context; | ||
| return std::make_unique<GPUSurfaceMetalImpeller>( | ||
| this, std::make_shared<impeller::AiksContext>(context, nullptr)); | ||
| } | ||
| return std::make_unique<GPUSurfaceMetalSkia>(this, metal_context_->skia_context.mainContext); | ||
| return std::make_unique<GPUSurfaceMetalSkia>(this, skia_context_.mainContext); | ||
| } | ||
|
|
||
| // |PlatformView| | ||
| std::shared_ptr<impeller::Context> ShellTestPlatformViewMetal::GetImpellerContext() const { | ||
| return metal_context_->impeller_context.context; | ||
| return impeller_context_.context; | ||
| } | ||
|
|
||
| // |GPUSurfaceMetalDelegate| | ||
|
|
@@ -123,7 +113,7 @@ | |
| GPUMTLTextureInfo ShellTestPlatformViewMetal::GetMTLTexture(const SkISize& frame_info) const { | ||
| return { | ||
| .texture_id = 0, | ||
| .texture = (__bridge GPUMTLTextureHandle)metal_context_->offscreen_texture, | ||
| .texture = (__bridge GPUMTLTextureHandle)offscreen_texture_, | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -133,5 +123,4 @@ | |
| return true; | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter | ||
| } // namespace flutter::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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of instantiating all the backend-specific stuff here, the implementations are now in the appropriate
shell_test_platform_view_metal.mmorshell_test_platform_view_vulkan.ccetc. file, with fallback implementations in this file for any backends that are disabled.