未验证 提交 362e3fe5 编写于 作者: G gaaclarke 提交者: GitHub

Added some thread asserts to the code and made ios_surface_ safe since (#12775)

* Added some thread asserts to the code and made ios_surface_ safe since
its being written and read from different threads.

* responded to chinmays feedback, added comment
上级 f3d04a98
......@@ -49,7 +49,10 @@ class PlatformViewIOS final : public PlatformView {
private:
fml::WeakPtr<FlutterViewController> owner_controller_;
std::unique_ptr<IOSSurface> 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<IOSSurface> ios_surface_ FML_GUARDED_BY(ios_surface_mutex_);
std::shared_ptr<IOSGLContext> gl_context_;
PlatformMessageRouter platform_message_router_;
std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
......
......@@ -43,6 +43,8 @@ fml::WeakPtr<FlutterViewController> PlatformViewIOS::GetOwnerViewController() co
}
void PlatformViewIOS::SetOwnerViewController(fml::WeakPtr<FlutterViewController> owner_controller) {
FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
std::lock_guard<std::mutex> guard(ios_surface_mutex_);
if (ios_surface_ || !owner_controller) {
NotifyDestroyed();
ios_surface_.reset();
......@@ -92,6 +94,8 @@ void PlatformViewIOS::RegisterExternalTexture(int64_t texture_id,
// |PlatformView|
std::unique_ptr<Surface> PlatformViewIOS::CreateRenderingSurface() {
FML_DCHECK(task_runners_.GetGPUTaskRunner()->RunsTasksOnCurrentThread());
std::lock_guard<std::mutex> guard(ios_surface_mutex_);
if (!ios_surface_) {
FML_DLOG(INFO) << "Could not CreateRenderingSurface, this PlatformViewIOS "
"has no ViewController.";
......@@ -102,6 +106,7 @@ std::unique_ptr<Surface> PlatformViewIOS::CreateRenderingSurface() {
// |PlatformView|
sk_sp<GrContext> 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, "
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册