From a0276302589e9362ed823e3aeaa5ea1e7c3df56e Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sun, 15 Sep 2024 11:57:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=B3=E5=AE=9A=E6=80=A7=E9=97=AE=E9=A2=98,?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=9A=E7=BA=BF=E7=A8=8B=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84=E5=8F=AF=E8=A7=81?= =?UTF-8?q?=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../ohos/ohos_external_texture_gl.cpp | 4 +++ .../platform/ohos/ohos_external_texture_gl.h | 2 +- shell/platform/ohos/platform_view_ohos.cpp | 28 +++++++++++++------ shell/platform/ohos/platform_view_ohos.h | 2 +- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 3c4c9f91a2..a5f2ab3df7 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -224,6 +224,10 @@ void OHOSExternalTextureGL::OnTextureUnregistered() << ", Id()=" << Id() << ", nativeImage_=" << nativeImage_ << ", backGroundNativeImage_=" << backGroundNativeImage_; + if (state_ != AttachmentState::attached) { + FML_LOG(ERROR) << "OHOSExternalTextureGL::OnTextureUnregistered, the current status is not attached"; + return; + } first_update_ = false; if (nativeImage_ != nullptr) { OH_NativeImage_UnsetOnFrameAvailableListener(nativeImage_); diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index 3925a4cb33..495eb02594 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -92,7 +92,7 @@ class OHOSExternalTextureGL : public flutter::Texture { enum class AttachmentState { uninitialized, attached, detached }; - AttachmentState state_; + std::atomic state_; bool new_frame_ready_ = false; diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index b66be4705f..bad544f3f8 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -139,9 +139,13 @@ void PlatformViewOHOS::NotifyCreate( fml::TaskRunner::RunNowOrPostTask( task_runners_.GetRasterTaskRunner(), [&latch, surface = ohos_surface_.get(), - native_window = std::move(native_window)]() { - LOGI("NotifyCreate start4"); - surface->SetNativeWindow(native_window); + native_window = std::move(native_window), this]() { + if (GetDestroyed()) { + LOGW("NotifyCreate, GetDestroyed is true, ignore this call."); + } else { + LOGI("NotifyCreate start4"); + surface->SetNativeWindow(native_window); + } latch.Signal(); }); latch.Wait(); @@ -158,9 +162,13 @@ void PlatformViewOHOS::NotifySurfaceWindowChanged( fml::TaskRunner::RunNowOrPostTask( task_runners_.GetRasterTaskRunner(), [&latch, surface = ohos_surface_.get(), - native_window = std::move(native_window)]() { - surface->TeardownOnScreenContext(); - surface->SetNativeWindow(native_window); + native_window = std::move(native_window), this]() { + if (GetDestroyed()) { + LOGW("NotifySurfaceWindowChanged, GetDestroyed is true, ignore this call."); + } else { + surface->TeardownOnScreenContext(); + surface->SetNativeWindow(native_window); + } latch.Signal(); }); latch.Wait(); @@ -173,8 +181,12 @@ void PlatformViewOHOS::NotifyChanged(const SkISize& size) { fml::AutoResetWaitableEvent latch; fml::TaskRunner::RunNowOrPostTask( task_runners_.GetRasterTaskRunner(), // - [&latch, surface = ohos_surface_.get(), size]() { - surface->OnScreenSurfaceResize(size); + [&latch, surface = ohos_surface_.get(), size, this]() { + if (GetDestroyed()) { + LOGW("NotifyChanged, GetDestroyed is true, ignore this call."); + } else { + surface->OnScreenSurfaceResize(size); + } latch.Signal(); }); latch.Wait(); diff --git a/shell/platform/ohos/platform_view_ohos.h b/shell/platform/ohos/platform_view_ohos.h index f7cc0778e1..14c60e884c 100644 --- a/shell/platform/ohos/platform_view_ohos.h +++ b/shell/platform/ohos/platform_view_ohos.h @@ -141,7 +141,7 @@ class PlatformViewOHOS final : public PlatformView { std::map> external_texture_gl_; std::map contextDatas_; - bool isDestroyed_; + std::atomic isDestroyed_; bool GetDestroyed(); -- Gitee