[Impeller] Encode render passes concurrently on iOS. (flutter/engine#42028)

Allows pushing encoding of command buffers to a worker thread, relying on the fact that these buffers are always scheduled in the order that they are enqueued. This follows the guidelines from https://developer.apple.com/documentation/metal/mtlcommandbuffer?language=objc
This commit is contained in:
Jonah Williams
2023-05-23 12:40:05 -07:00
committed by GitHub
parent 3e4dabb16d
commit be33a58e18
31 changed files with 442 additions and 129 deletions

View File

@@ -375,11 +375,7 @@ std::shared_ptr<Texture> ContentContext::MakeSubpass(
return nullptr;
}
if (!sub_renderpass->EncodeCommands()) {
return nullptr;
}
if (!sub_command_buffer->SubmitCommands()) {
if (!sub_command_buffer->SubmitCommandsAsync(std::move(sub_renderpass))) {
return nullptr;
}

View File

@@ -54,15 +54,9 @@ bool InlinePassContext::EndPass() {
return true;
}
if (!pass_->EncodeCommands()) {
VALIDATION_LOG
<< "Failed to encode commands while ending the current render pass.";
return false;
}
if (!command_buffer_->SubmitCommands()) {
VALIDATION_LOG
<< "Failed to submit command buffer while ending render pass.";
if (!command_buffer_->SubmitCommandsAsync(std::move(pass_))) {
VALIDATION_LOG << "Failed to encode and submit command buffer while ending "
"render pass.";
return false;
}

View File

@@ -6,7 +6,9 @@
#include <memory>
#include "flutter/fml/concurrent_message_loop.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/sync_switch.h"
#include "impeller/playground/playground_impl.h"
namespace impeller {
@@ -27,6 +29,8 @@ class PlaygroundImplMTL final : public PlaygroundImpl {
// To ensure that ObjC stuff doesn't leak into C++ TUs.
std::unique_ptr<Data> data_;
std::shared_ptr<Context> context_;
std::shared_ptr<fml::ConcurrentMessageLoop> concurrent_loop_;
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch_;
// |PlaygroundImpl|
std::shared_ptr<Context> GetContext() const override;

View File

@@ -63,7 +63,9 @@ void PlaygroundImplMTL::DestroyWindowHandle(WindowHandle handle) {
PlaygroundImplMTL::PlaygroundImplMTL(PlaygroundSwitches switches)
: PlaygroundImpl(switches),
handle_(nullptr, &DestroyWindowHandle),
data_(std::make_unique<Data>()) {
data_(std::make_unique<Data>()),
concurrent_loop_(fml::ConcurrentMessageLoop::Create()),
is_gpu_disabled_sync_switch_(new fml::SyncSwitch(false)) {
::glfwDefaultWindowHints();
::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
@@ -71,8 +73,10 @@ PlaygroundImplMTL::PlaygroundImplMTL(PlaygroundSwitches switches)
if (!window) {
return;
}
auto context = ContextMTL::Create(ShaderLibraryMappingsForPlayground(),
"Playground Library");
auto worker_task_runner = concurrent_loop_->GetTaskRunner();
auto context = ContextMTL::Create(
ShaderLibraryMappingsForPlayground(), worker_task_runner,
is_gpu_disabled_sync_switch_, "Playground Library");
if (!context) {
return;
}

View File

@@ -36,6 +36,9 @@ class CommandBufferMTL final : public CommandBuffer {
// |CommandBuffer|
void OnWaitUntilScheduled() override;
// |CommandBuffer|
bool SubmitCommandsAsync(std::shared_ptr<RenderPass> render_pass) override;
// |CommandBuffer|
std::shared_ptr<RenderPass> OnCreateRenderPass(RenderTarget target) override;

View File

@@ -4,8 +4,13 @@
#include "impeller/renderer/backend/metal/command_buffer_mtl.h"
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/synchronization/semaphore.h"
#include "flutter/fml/trace_event.h"
#include "impeller/renderer/backend/metal/blit_pass_mtl.h"
#include "impeller/renderer/backend/metal/compute_pass_mtl.h"
#include "impeller/renderer/backend/metal/context_mtl.h"
#include "impeller/renderer/backend/metal/render_pass_mtl.h"
namespace impeller {
@@ -171,6 +176,62 @@ bool CommandBufferMTL::OnSubmitCommands(CompletionCallback callback) {
return true;
}
bool CommandBufferMTL::SubmitCommandsAsync(
std::shared_ptr<RenderPass> render_pass) {
TRACE_EVENT0("impeller", "CommandBufferMTL::SubmitCommandsAsync");
if (!IsValid() || !render_pass->IsValid()) {
return false;
}
auto context = context_.lock();
if (!context) {
return false;
}
[buffer_ enqueue];
auto buffer = buffer_;
buffer_ = nil;
auto worker_task_runner = ContextMTL::Cast(*context).GetWorkerTaskRunner();
auto mtl_render_pass = static_cast<RenderPassMTL*>(render_pass.get());
// Render command encoder creation has been observed to exceed the stack size
// limit for worker threads, and therefore is intentionally constructed on the
// raster thread.
auto render_command_encoder =
[buffer renderCommandEncoderWithDescriptor:mtl_render_pass->desc_];
if (!render_command_encoder) {
return false;
}
auto task = fml::MakeCopyable([render_pass, buffer, render_command_encoder,
weak_context = context_]() {
auto context = weak_context.lock();
if (!context) {
return;
}
auto is_gpu_disabled_sync_switch =
ContextMTL::Cast(*context).GetIsGpuDisabledSyncSwitch();
is_gpu_disabled_sync_switch->Execute(fml::SyncSwitch::Handlers().SetIfFalse(
[&render_pass, &render_command_encoder, &buffer, &context] {
auto mtl_render_pass = static_cast<RenderPassMTL*>(render_pass.get());
if (!mtl_render_pass->label_.empty()) {
[render_command_encoder
setLabel:@(mtl_render_pass->label_.c_str())];
}
auto result = mtl_render_pass->EncodeCommands(
context->GetResourceAllocator(), render_command_encoder);
[render_command_encoder endEncoding];
if (result) {
[buffer commit];
} else {
VALIDATION_LOG << "Failed to encode command buffer";
}
}));
});
worker_task_runner->PostTask(task);
return true;
}
void CommandBufferMTL::OnWaitUntilScheduled() {}
std::shared_ptr<RenderPass> CommandBufferMTL::OnCreateRenderPass(

View File

@@ -9,7 +9,9 @@
#include <string>
#include <vector>
#include "flutter/fml/concurrent_message_loop.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/sync_switch.h"
#include "impeller/base/backend_cast.h"
#include "impeller/core/sampler.h"
#include "impeller/renderer/backend/metal/allocator_mtl.h"
@@ -26,10 +28,14 @@ class ContextMTL final : public Context,
public std::enable_shared_from_this<ContextMTL> {
public:
static std::shared_ptr<ContextMTL> Create(
const std::vector<std::string>& shader_library_paths);
const std::vector<std::string>& shader_library_paths,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
static std::shared_ptr<ContextMTL> Create(
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
const std::string& label);
// |Context|
@@ -66,6 +72,10 @@ class ContextMTL final : public Context,
id<MTLCommandBuffer> CreateMTLCommandBuffer() const;
const std::shared_ptr<fml::ConcurrentTaskRunner>& GetWorkerTaskRunner() const;
std::shared_ptr<const fml::SyncSwitch> GetIsGpuDisabledSyncSwitch() const;
private:
id<MTLDevice> device_ = nullptr;
id<MTLCommandQueue> command_queue_ = nullptr;
@@ -74,9 +84,15 @@ class ContextMTL final : public Context,
std::shared_ptr<SamplerLibrary> sampler_library_;
std::shared_ptr<AllocatorMTL> resource_allocator_;
std::shared_ptr<const Capabilities> device_capabilities_;
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner_;
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch_;
bool is_valid_ = false;
ContextMTL(id<MTLDevice> device, NSArray<id<MTLLibrary>>* shader_libraries);
ContextMTL(
id<MTLDevice> device,
NSArray<id<MTLLibrary>>* shader_libraries,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
std::shared_ptr<CommandBuffer> CreateCommandBufferInQueue(
id<MTLCommandQueue> queue) const;

View File

@@ -65,9 +65,14 @@ static std::unique_ptr<Capabilities> InferMetalCapabilities(
.Build();
}
ContextMTL::ContextMTL(id<MTLDevice> device,
NSArray<id<MTLLibrary>>* shader_libraries)
: device_(device) {
ContextMTL::ContextMTL(
id<MTLDevice> device,
NSArray<id<MTLLibrary>>* shader_libraries,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch)
: device_(device),
worker_task_runner_(std::move(worker_task_runner)),
is_gpu_disabled_sync_switch_(std::move(is_gpu_disabled_sync_switch)) {
// Validate device.
if (!device_) {
VALIDATION_LOG << "Could not setup valid Metal device.";
@@ -200,10 +205,13 @@ static id<MTLDevice> CreateMetalDevice() {
}
std::shared_ptr<ContextMTL> ContextMTL::Create(
const std::vector<std::string>& shader_library_paths) {
const std::vector<std::string>& shader_library_paths,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch) {
auto device = CreateMetalDevice();
auto context = std::shared_ptr<ContextMTL>(new ContextMTL(
device, MTLShaderLibraryFromFilePaths(device, shader_library_paths)));
device, MTLShaderLibraryFromFilePaths(device, shader_library_paths),
std::move(worker_task_runner), std::move(is_gpu_disabled_sync_switch)));
if (!context->IsValid()) {
FML_LOG(ERROR) << "Could not create Metal context.";
return nullptr;
@@ -213,11 +221,14 @@ std::shared_ptr<ContextMTL> ContextMTL::Create(
std::shared_ptr<ContextMTL> ContextMTL::Create(
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
const std::string& label) {
auto device = CreateMetalDevice();
auto context = std::shared_ptr<ContextMTL>(new ContextMTL(
device,
MTLShaderLibraryFromFileData(device, shader_libraries_data, label)));
MTLShaderLibraryFromFileData(device, shader_libraries_data, label),
worker_task_runner, std::move(is_gpu_disabled_sync_switch)));
if (!context->IsValid()) {
FML_LOG(ERROR) << "Could not create Metal context.";
return nullptr;
@@ -257,6 +268,16 @@ std::shared_ptr<CommandBuffer> ContextMTL::CreateCommandBuffer() const {
return CreateCommandBufferInQueue(command_queue_);
}
const std::shared_ptr<fml::ConcurrentTaskRunner>&
ContextMTL::GetWorkerTaskRunner() const {
return worker_task_runner_;
}
std::shared_ptr<const fml::SyncSwitch> ContextMTL::GetIsGpuDisabledSyncSwitch()
const {
return is_gpu_disabled_sync_switch_;
}
std::shared_ptr<CommandBuffer> ContextMTL::CreateCommandBufferInQueue(
id<MTLCommandQueue> queue) const {
if (!IsValid()) {

View File

@@ -6,11 +6,13 @@
#include "flutter/fml/closure.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/trace_event.h"
#include "impeller/base/backend_cast.h"
#include "impeller/core/formats.h"
#include "impeller/core/host_buffer.h"
#include "impeller/core/shader_types.h"
#include "impeller/renderer/backend/metal/context_mtl.h"
#include "impeller/renderer/backend/metal/device_buffer_mtl.h"
#include "impeller/renderer/backend/metal/formats_mtl.h"
#include "impeller/renderer/backend/metal/pipeline_mtl.h"

View File

@@ -36,6 +36,21 @@ void CommandBuffer::WaitUntilScheduled() {
return OnWaitUntilScheduled();
}
bool CommandBuffer::SubmitCommandsAsync(
std::shared_ptr<RenderPass>
render_pass // NOLINT(performance-unnecessary-value-param)
) {
TRACE_EVENT0("impeller", "CommandBuffer::SubmitCommandsAsync");
if (!render_pass->IsValid() || !IsValid()) {
return false;
}
if (!render_pass->EncodeCommands()) {
return false;
}
return SubmitCommands(nullptr);
}
std::shared_ptr<RenderPass> CommandBuffer::CreateRenderPass(
const RenderTarget& render_target) {
auto pass = OnCreateRenderPass(render_target);

View File

@@ -55,7 +55,8 @@ class CommandBuffer {
//----------------------------------------------------------------------------
/// @brief Schedule the command encoded by render passes within this
/// command buffer on the GPU.
/// command buffer on the GPU. The encoding of these commnands is
/// performed immediately on the calling thread.
///
/// A command buffer may only be committed once.
///
@@ -65,6 +66,17 @@ class CommandBuffer {
[[nodiscard]] bool SubmitCommands();
//----------------------------------------------------------------------------
/// @brief Schedule the command encoded by render passes within this
/// command buffer on the GPU. The enqueing of this buffer is
/// performed immediately but encoding is pushed to a worker
/// thread if possible.
///
/// A command buffer may only be committed once.
///
[[nodiscard]] virtual bool SubmitCommandsAsync(
std::shared_ptr<RenderPass> render_pass);
//----------------------------------------------------------------------------
/// @brief Force execution of pending GPU commands.
///

View File

@@ -7,6 +7,7 @@
#include <string>
#include "impeller/renderer/command.h"
#include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/render_target.h"
namespace impeller {

View File

@@ -81,7 +81,9 @@ TEST_F(ShellTest, VSyncTargetTime) {
[vsync_clock, &create_vsync_waiter](Shell& shell) {
return ShellTestPlatformView::Create(
shell, shell.GetTaskRunners(), vsync_clock, create_vsync_waiter,
ShellTestPlatformView::BackendType::kDefaultBackend, nullptr);
ShellTestPlatformView::BackendType::kDefaultBackend, nullptr,
shell.GetConcurrentWorkerTaskRunner(),
shell.GetIsGpuDisabledSyncSwitch());
},
[](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
ASSERT_TRUE(DartVMRef::IsInstanceRunning());

View File

@@ -352,12 +352,15 @@ std::unique_ptr<Shell> ShellTest::CreateShell(
shell_test_external_view_embedder, //
rendering_backend //
](Shell& shell) {
return ShellTestPlatformView::Create(shell, //
shell.GetTaskRunners(), //
vsync_clock, //
create_vsync_waiter, //
rendering_backend, //
shell_test_external_view_embedder //
return ShellTestPlatformView::Create(
shell, //
shell.GetTaskRunners(), //
vsync_clock, //
create_vsync_waiter, //
rendering_backend, //
shell_test_external_view_embedder, //
shell.GetConcurrentWorkerTaskRunner(), //
shell.GetIsGpuDisabledSyncSwitch() //
);
};
}

View File

@@ -24,7 +24,9 @@ std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::Create(
const CreateVsyncWaiter& create_vsync_waiter,
BackendType backend,
const std::shared_ptr<ShellTestExternalViewEmbedder>&
shell_test_external_view_embedder) {
shell_test_external_view_embedder,
const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch) {
// TODO(gw280): https://github.com/flutter/flutter/issues/50298
// Make this fully runtime configurable
switch (backend) {
@@ -45,7 +47,8 @@ std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::Create(
case BackendType::kMetalBackend:
return std::make_unique<ShellTestPlatformViewMetal>(
delegate, task_runners, vsync_clock, create_vsync_waiter,
shell_test_external_view_embedder);
shell_test_external_view_embedder, worker_task_runner,
is_gpu_disabled_sync_switch);
#endif // SHELL_ENABLE_METAL
default:

View File

@@ -28,7 +28,10 @@ class ShellTestPlatformView : public PlatformView {
const CreateVsyncWaiter& create_vsync_waiter,
BackendType backend,
const std::shared_ptr<ShellTestExternalViewEmbedder>&
shell_test_external_view_embedder);
shell_test_external_view_embedder,
const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
const std::shared_ptr<const fml::SyncSwitch>&
is_gpu_disabled_sync_switch);
virtual void SimulateVSync() = 0;

View File

@@ -17,12 +17,16 @@ class DarwinContextMetal;
class ShellTestPlatformViewMetal final : public ShellTestPlatformView,
public GPUSurfaceMetalDelegate {
public:
ShellTestPlatformViewMetal(PlatformView::Delegate& delegate,
const TaskRunners& task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter,
std::shared_ptr<ShellTestExternalViewEmbedder>
shell_test_external_view_embedder);
ShellTestPlatformViewMetal(
PlatformView::Delegate& delegate,
const TaskRunners& task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter,
std::shared_ptr<ShellTestExternalViewEmbedder>
shell_test_external_view_embedder,
const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
const std::shared_ptr<const fml::SyncSwitch>&
is_gpu_disabled_sync_switch);
// |ShellTestPlatformView|
virtual ~ShellTestPlatformViewMetal() override;

View File

@@ -31,9 +31,15 @@ static fml::scoped_nsprotocol<id<MTLTexture>> CreateOffscreenTexture(id<MTLDevic
// non-Objective-C TUs.
class DarwinContextMetal {
public:
explicit DarwinContextMetal(bool impeller)
explicit DarwinContextMetal(bool impeller,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch)
: context_(impeller ? nil : [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice]),
impeller_context_(impeller ? [[FlutterDarwinContextMetalImpeller alloc] init] : nil),
impeller_context_(
impeller ? [[FlutterDarwinContextMetalImpeller alloc]
initWithTaskRunner:std::move(worker_task_runner)
is_gpu_disabled_sync_switch:std::move(is_gpu_disabled_sync_switch)]
: nil),
offscreen_texture_(CreateOffscreenTexture(
impeller ? [impeller_context_ context]->GetMTLDevice() : [context_ device])) {}
@@ -67,10 +73,14 @@ ShellTestPlatformViewMetal::ShellTestPlatformViewMetal(
const TaskRunners& task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter,
std::shared_ptr<ShellTestExternalViewEmbedder> shell_test_external_view_embedder)
std::shared_ptr<ShellTestExternalViewEmbedder> shell_test_external_view_embedder,
const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch)
: ShellTestPlatformView(delegate, task_runners),
GPUSurfaceMetalDelegate(MTLRenderTargetType::kMTLTexture),
metal_context_(std::make_unique<DarwinContextMetal>(GetSettings().enable_impeller)),
metal_context_(std::make_unique<DarwinContextMetal>(GetSettings().enable_impeller,
worker_task_runner,
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)) {

View File

@@ -409,7 +409,9 @@ TEST_F(ShellTest,
return static_cast<std::unique_ptr<VsyncWaiter>>(
std::make_unique<VsyncWaiterFallback>(task_runners));
},
ShellTestPlatformView::BackendType::kDefaultBackend, nullptr);
ShellTestPlatformView::BackendType::kDefaultBackend, nullptr,
shell.GetConcurrentWorkerTaskRunner(),
shell.GetIsGpuDisabledSyncSwitch());
},
[](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
ASSERT_TRUE(ValidateShell(shell.get()));

View File

@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import <Metal/Metal.h>
#include "flutter/fml/concurrent_message_loop.h"
#include "flutter/fml/platform/darwin/cf_utils.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h"
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h"
@@ -24,7 +25,9 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Initializes a FlutterDarwinContextMetalImpeller.
*/
- (instancetype)init;
- (instancetype)initWithTaskRunner:(std::shared_ptr<fml::ConcurrentTaskRunner>)task_runner
is_gpu_disabled_sync_switch:
(std::shared_ptr<const fml::SyncSwitch>)is_gpu_disabled_sync_switch;
/**
* Creates an external texture with the specified ID and contents.
@@ -34,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
texture:(NSObject<FlutterTexture>*)texture;
/**
* Impeller context;
* Impeller context.
*/
@property(nonatomic, readonly) std::shared_ptr<impeller::ContextMTL> context;

View File

@@ -16,7 +16,9 @@
FLUTTER_ASSERT_ARC
static std::shared_ptr<impeller::ContextMTL> CreateImpellerContext() {
static std::shared_ptr<impeller::ContextMTL> CreateImpellerContext(
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch) {
std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_data,
impeller_entity_shaders_length),
@@ -27,7 +29,9 @@ static std::shared_ptr<impeller::ContextMTL> CreateImpellerContext() {
std::make_shared<fml::NonOwnedMapping>(impeller_framebuffer_blend_shaders_data,
impeller_framebuffer_blend_shaders_length),
};
auto context = impeller::ContextMTL::Create(shader_mappings, "Impeller Library");
auto context =
impeller::ContextMTL::Create(shader_mappings, std::move(worker_task_runner),
std::move(is_gpu_disabled_sync_switch), "Impeller Library");
if (!context) {
FML_LOG(ERROR) << "Could not create Metal Impeller Context.";
return nullptr;
@@ -39,10 +43,13 @@ static std::shared_ptr<impeller::ContextMTL> CreateImpellerContext() {
@implementation FlutterDarwinContextMetalImpeller
- (instancetype)init {
- (instancetype)initWithTaskRunner:(std::shared_ptr<fml::ConcurrentTaskRunner>)task_runner
is_gpu_disabled_sync_switch:
(std::shared_ptr<const fml::SyncSwitch>)is_gpu_disabled_sync_switch {
self = [super init];
if (self != nil) {
_context = CreateImpellerContext();
_context =
CreateImpellerContext(std::move(task_runner), std::move(is_gpu_disabled_sync_switch));
id<MTLDevice> device = _context->GetMTLDevice();
if (!device) {
FML_DLOG(ERROR) << "Could not acquire Metal device.";

View File

@@ -836,7 +836,8 @@ static void SetEntryPoint(flutter::Settings* settings, NSString* entrypoint, NSS
[self](flutter::Shell& shell) {
[self recreatePlatformViewController];
return std::make_unique<flutter::PlatformViewIOS>(
shell, self->_renderingApi, self->_platformViewsController, shell.GetTaskRunners());
shell, self->_renderingApi, self->_platformViewsController, shell.GetTaskRunners(),
shell.GetConcurrentWorkerTaskRunner(), shell.GetIsGpuDisabledSyncSwitch());
};
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =

View File

@@ -74,7 +74,9 @@ flutter::FakeDelegate fake_delegate;
/*delegate=*/fake_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
weak_factory = std::make_unique<fml::WeakPtrFactory<flutter::PlatformView>>(platform_view.get());
}
@@ -105,7 +107,9 @@ flutter::FakeDelegate fake_delegate;
/*delegate=*/fake_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kMetal,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
XCTAssertEqual(msaa_4x_platform_view->GetIosContext()->GetMsaaSampleCount(),
MsaaSampleCount::kFour);

View File

@@ -150,7 +150,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -204,7 +206,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -256,7 +260,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -326,7 +332,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -396,7 +404,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -467,7 +477,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -578,7 +590,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -713,7 +727,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -988,7 +1004,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -1286,7 +1304,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -1340,7 +1360,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -1432,7 +1454,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -1501,7 +1525,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -1566,7 +1592,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -1630,7 +1658,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -1701,7 +1731,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -1772,7 +1804,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -1844,7 +1878,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -1906,7 +1942,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -2025,7 +2063,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -2134,7 +2174,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -2194,7 +2236,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -2254,7 +2298,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease];
flutterPlatformViewsController->SetFlutterView(mockFlutterView);
@@ -2302,7 +2348,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease];
flutterPlatformViewsController->SetFlutterView(mockFlutterView);
@@ -2356,7 +2404,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease];
flutterPlatformViewsController->SetFlutterView(mockFlutterView);
@@ -2452,7 +2502,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease];
flutterPlatformViewsController->SetFlutterView(mockFlutterView);
@@ -2548,7 +2600,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease];
flutterPlatformViewsController->SetFlutterView(mockFlutterView);
@@ -2696,7 +2750,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -2803,7 +2859,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease];
flutterPlatformViewsController->SetFlutterView(mockFlutterView);
@@ -2909,7 +2967,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];

View File

@@ -149,7 +149,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
auto bridge =
std::make_unique<flutter::AccessibilityBridge>(/*view=*/nil,
/*platform_view=*/platform_view.get(),
@@ -169,7 +171,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController viewIfLoaded]).andReturn(mockFlutterView);
@@ -196,7 +200,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -241,7 +247,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -271,7 +279,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -328,7 +338,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
MockFlutterPlatformFactory* factory = [[MockFlutterPlatformFactory new] autorelease];
flutterPlatformViewsController->RegisterViewFactory(
@@ -371,7 +383,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id engine = OCMClassMock([FlutterEngine class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
FlutterView* flutterView = [[FlutterView alloc] initWithDelegate:engine
@@ -463,7 +477,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id engine = OCMClassMock([FlutterEngine class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
FlutterView* flutterView = [[FlutterView alloc] initWithDelegate:engine
@@ -533,7 +549,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id engine = OCMClassMock([FlutterEngine class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
FlutterView* flutterView = [[FlutterView alloc] initWithDelegate:engine
@@ -603,7 +621,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -669,7 +689,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id engine = OCMClassMock([FlutterEngine class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
FlutterView* flutterView = [[FlutterView alloc] initWithDelegate:engine
@@ -714,7 +736,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -796,7 +820,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -869,7 +895,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -941,7 +969,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -996,7 +1026,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1091,7 +1123,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1175,7 +1209,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1265,7 +1301,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1333,7 +1371,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1400,7 +1440,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1473,7 +1515,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1548,7 +1592,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1619,7 +1665,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1692,7 +1740,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1747,7 +1797,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1807,7 +1859,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1875,7 +1929,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
fml::AutoResetWaitableEvent latch;
thread_task_runner->PostTask([&] {
auto weakFactory =
@@ -1908,7 +1964,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
@@ -1956,7 +2014,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*delegate=*/test_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
/*task_runners=*/runners,
/*worker_task_runner=*/nil,
/*is_gpu_disabled_sync_switch=*/nil);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
auto flutterPlatformViewsController =

View File

@@ -10,8 +10,10 @@
#include "flutter/common/graphics/gl_context_switch.h"
#include "flutter/common/graphics/msaa_sample_count.h"
#include "flutter/common/graphics/texture.h"
#include "flutter/fml/concurrent_message_loop.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
#include "flutter/fml/synchronization/sync_switch.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h"
#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
@@ -51,12 +53,17 @@ class IOSContext {
/// @param[in] msaa_samples
/// The number of MSAA samples to use. Only supplied to
/// Skia, must be either 0, 1, 2, 4, or 8.
/// @param[in] task_runner
/// The engine concurrent task runner.
///
/// @return A valid context on success. `nullptr` on failure.
///
static std::unique_ptr<IOSContext> Create(IOSRenderingAPI api,
IOSRenderingBackend backend,
MsaaSampleCount msaa_samples);
static std::unique_ptr<IOSContext> Create(
IOSRenderingAPI api,
IOSRenderingBackend backend,
MsaaSampleCount msaa_samples,
std::shared_ptr<fml::ConcurrentTaskRunner> task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
//----------------------------------------------------------------------------
/// @brief Collects the context object. This must happen on the thread on

View File

@@ -18,9 +18,12 @@ IOSContext::IOSContext(MsaaSampleCount msaa_samples) : msaa_samples_(msaa_sample
IOSContext::~IOSContext() = default;
std::unique_ptr<IOSContext> IOSContext::Create(IOSRenderingAPI api,
IOSRenderingBackend backend,
MsaaSampleCount msaa_samples) {
std::unique_ptr<IOSContext> IOSContext::Create(
IOSRenderingAPI api,
IOSRenderingBackend backend,
MsaaSampleCount msaa_samples,
std::shared_ptr<fml::ConcurrentTaskRunner> task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch) {
switch (api) {
case IOSRenderingAPI::kSoftware:
return std::make_unique<IOSContextSoftware>();
@@ -30,7 +33,8 @@ std::unique_ptr<IOSContext> IOSContext::Create(IOSRenderingAPI api,
case IOSRenderingBackend::kSkia:
return std::make_unique<IOSContextMetalSkia>(msaa_samples);
case IOSRenderingBackend::kImpeller:
return std::make_unique<IOSContextMetalImpeller>();
return std::make_unique<IOSContextMetalImpeller>(std::move(task_runner),
std::move(is_gpu_disabled_sync_switch));
}
#endif // SHELL_ENABLE_METAL
default:

View File

@@ -20,7 +20,8 @@ namespace flutter {
class IOSContextMetalImpeller final : public IOSContext {
public:
IOSContextMetalImpeller();
IOSContextMetalImpeller(std::shared_ptr<fml::ConcurrentTaskRunner> task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
~IOSContextMetalImpeller();

View File

@@ -8,10 +8,14 @@
namespace flutter {
IOSContextMetalImpeller::IOSContextMetalImpeller()
IOSContextMetalImpeller::IOSContextMetalImpeller(
std::shared_ptr<fml::ConcurrentTaskRunner> task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch)
: IOSContext(MsaaSampleCount::kFour),
darwin_context_metal_impeller_(fml::scoped_nsobject<FlutterDarwinContextMetalImpeller>{
[[FlutterDarwinContextMetalImpeller alloc] init]}) {}
[[FlutterDarwinContextMetalImpeller alloc]
initWithTaskRunner:std::move(task_runner)
is_gpu_disabled_sync_switch:std::move(is_gpu_disabled_sync_switch)]}) {}
IOSContextMetalImpeller::~IOSContextMetalImpeller() = default;

View File

@@ -49,7 +49,9 @@ class PlatformViewIOS final : public PlatformView {
PlatformView::Delegate& delegate,
IOSRenderingAPI rendering_api,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller,
const flutter::TaskRunners& task_runners);
const flutter::TaskRunners& task_runners,
const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
~PlatformViewIOS() override;

View File

@@ -55,14 +55,18 @@ PlatformViewIOS::PlatformViewIOS(
PlatformView::Delegate& delegate,
IOSRenderingAPI rendering_api,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller,
const flutter::TaskRunners& task_runners)
const flutter::TaskRunners& task_runners,
const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch)
: PlatformViewIOS(
delegate,
IOSContext::Create(
rendering_api,
delegate.OnPlatformViewGetSettings().enable_impeller ? IOSRenderingBackend::kImpeller
: IOSRenderingBackend::kSkia,
static_cast<MsaaSampleCount>(delegate.OnPlatformViewGetSettings().msaa_samples)),
static_cast<MsaaSampleCount>(delegate.OnPlatformViewGetSettings().msaa_samples),
worker_task_runner,
std::move(is_gpu_disabled_sync_switch)),
platform_views_controller,
task_runners) {}