From cb51f57d6c15e88aa623c154ff8acd54374d195a Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 3 Oct 2019 14:25:49 -0700 Subject: [PATCH 1/2] Added some thread asserts to the code and made ios_surface_ safe since its being written and read from different threads. --- shell/platform/darwin/ios/platform_view_ios.h | 1 + shell/platform/darwin/ios/platform_view_ios.mm | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/shell/platform/darwin/ios/platform_view_ios.h b/shell/platform/darwin/ios/platform_view_ios.h index e1e85fa9de3f1..53f80c67958c1 100644 --- a/shell/platform/darwin/ios/platform_view_ios.h +++ b/shell/platform/darwin/ios/platform_view_ios.h @@ -50,6 +50,7 @@ class PlatformViewIOS final : public PlatformView { private: fml::WeakPtr owner_controller_; std::unique_ptr ios_surface_; + std::mutex 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, " From a3d410373848c457221b275f660126e361dddd20 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 3 Oct 2019 14:54:41 -0700 Subject: [PATCH 2/2] responded to chinmays feedback, added comment --- shell/platform/darwin/ios/platform_view_ios.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/platform_view_ios.h b/shell/platform/darwin/ios/platform_view_ios.h index 53f80c67958c1..566d08052f072 100644 --- a/shell/platform/darwin/ios/platform_view_ios.h +++ b/shell/platform/darwin/ios/platform_view_ios.h @@ -49,8 +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_;