diff --git a/shell/platform/darwin/ios/platform_view_ios.h b/shell/platform/darwin/ios/platform_view_ios.h index e1e85fa9de3f1..566d08052f072 100644 --- a/shell/platform/darwin/ios/platform_view_ios.h +++ b/shell/platform/darwin/ios/platform_view_ios.h @@ -49,7 +49,10 @@ class PlatformViewIOS final : public PlatformView { private: fml::WeakPtr owner_controller_; - std::unique_ptr ios_surface_; + // Since the `ios_surface_` is created on the platform thread but + // used on the GPU thread we need to protect it with a mutex. + std::mutex ios_surface_mutex_; + std::unique_ptr ios_surface_ FML_GUARDED_BY(ios_surface_mutex_); std::shared_ptr gl_context_; PlatformMessageRouter platform_message_router_; std::unique_ptr accessibility_bridge_; diff --git a/shell/platform/darwin/ios/platform_view_ios.mm b/shell/platform/darwin/ios/platform_view_ios.mm index 8de372f60af85..af8bbfec1c570 100644 --- a/shell/platform/darwin/ios/platform_view_ios.mm +++ b/shell/platform/darwin/ios/platform_view_ios.mm @@ -43,6 +43,8 @@ } void PlatformViewIOS::SetOwnerViewController(fml::WeakPtr owner_controller) { + FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread()); + std::lock_guard guard(ios_surface_mutex_); if (ios_surface_ || !owner_controller) { NotifyDestroyed(); ios_surface_.reset(); @@ -92,6 +94,8 @@ new AccessibilityBridge(static_cast(owner_controller_.get().view), // |PlatformView| std::unique_ptr PlatformViewIOS::CreateRenderingSurface() { + FML_DCHECK(task_runners_.GetGPUTaskRunner()->RunsTasksOnCurrentThread()); + std::lock_guard guard(ios_surface_mutex_); if (!ios_surface_) { FML_DLOG(INFO) << "Could not CreateRenderingSurface, this PlatformViewIOS " "has no ViewController."; @@ -102,6 +106,7 @@ new AccessibilityBridge(static_cast(owner_controller_.get().view), // |PlatformView| sk_sp PlatformViewIOS::CreateResourceContext() const { + FML_DCHECK(task_runners_.GetIOTaskRunner()->RunsTasksOnCurrentThread()); if (!gl_context_ || !gl_context_->ResourceMakeCurrent()) { FML_DLOG(INFO) << "Could not make resource context current on IO thread. " "Async texture uploads will be disabled. On Simulators, "