From cf09170d64d87583280bc36a2ba665eec24e35a0 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Tue, 8 Oct 2024 16:08:23 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=96=E6=8E=A5?= =?UTF-8?q?=E7=BA=B9=E7=90=86=E7=9A=84Detach=E6=96=B9=E6=B3=95?= 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 | 71 +++++++++++-------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 05c8449bf5..69d104bb71 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -99,14 +99,7 @@ OHOSExternalTextureGL::~OHOSExternalTextureGL() { FML_DLOG(INFO) << "~OHOSExternalTextureGL, texture_name_=" << texture_name_ << ", Id()=" << Id(); if (state_ == AttachmentState::attached) { - if (texture_name_ != 0) { - glDeleteTextures(1, &texture_name_); - texture_name_ = 0; - } - if (backGroundTextureName_ != 0) { - glDeleteTextures(1, &backGroundTextureName_); - backGroundTextureName_ = 0; - } + Detach(); } state_ = AttachmentState::uninitialized; nativeImage_ = nullptr; @@ -124,7 +117,6 @@ OHOSExternalTextureGL::~OHOSExternalTextureGL() void OHOSExternalTextureGL::Attach() { - FML_DLOG(INFO) << "OHOSExternalTextureGL::Attach, Id()=" << Id(); if (state_ != AttachmentState::uninitialized) { FML_LOG(ERROR) << "OHOSExternalTextureGL::Attach, the current status is not uninitialized"; return; @@ -216,20 +208,20 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, void OHOSExternalTextureGL::OnGrContextCreated() { - FML_DLOG(INFO) << " OHOSExternalTextureGL::OnGrContextCreated"; + FML_DLOG(INFO) << " OHOSExternalTextureGL::OnGrContextCreated" + << ", texture_name_=" << texture_name_ + << ", Id()=" << Id(); state_ = AttachmentState::uninitialized; } void OHOSExternalTextureGL::OnGrContextDestroyed() { - FML_DLOG(INFO) << " OHOSExternalTextureGL::OnGrContextDestroyed"; + FML_DLOG(INFO) << " OHOSExternalTextureGL::OnGrContextDestroyed" + << ", texture_name_=" << texture_name_ + << ", Id()=" << Id(); if (state_ == AttachmentState::attached) { Detach(); - glDeleteTextures(1, &texture_name_); - } - state_ = AttachmentState::detached; - if (backGroundTextureName_ != 0) { - glDeleteTextures(1, &backGroundTextureName_); + state_ = AttachmentState::detached; } } @@ -253,14 +245,9 @@ void OHOSExternalTextureGL::OnTextureUnregistered() << ", nativeImage_=" << nativeImage_ << ", backGroundNativeImage_=" << backGroundNativeImage_; first_update_ = false; - if (nativeImage_ != nullptr) { - OH_NativeImage_UnsetOnFrameAvailableListener(nativeImage_); - OH_NativeImage_Destroy(&nativeImage_); - nativeImage_ = nullptr; - } - if (backGroundNativeImage_ != nullptr) { - OH_NativeImage_Destroy(&backGroundNativeImage_); - backGroundNativeImage_ = nullptr; + if (state_ == AttachmentState::attached) { + Detach(); + state_ = AttachmentState::detached; } } @@ -287,12 +274,36 @@ void OHOSExternalTextureGL::Detach() FML_LOG(ERROR) << "OHOSExternalTextureGL::Detach, the current status is not attached"; return; } - OH_NativeImage_DetachContext(nativeImage_); - OH_NativeImage_DetachContext(backGroundNativeImage_); - OH_NativeWindow_DestroyNativeWindow(nativeWindow_); - OH_NativeWindow_DestroyNativeWindow(backGroundNativeWindow_); - nativeWindow_ = nullptr; - backGroundNativeWindow_ = nullptr; + + if (nativeImage_ != nullptr) { + OH_NativeImage_DetachContext(nativeImage_); + OH_NativeImage_UnsetOnFrameAvailableListener(nativeImage_); + OH_NativeImage_Destroy(&nativeImage_); + nativeImage_ = nullptr; + } + if (nativeWindow_ != nullptr) { + OH_NativeWindow_DestroyNativeWindow(nativeWindow_); + nativeWindow_ = nullptr; + } + + if (backGroundNativeImage_ != nullptr) { + OH_NativeImage_DetachContext(backGroundNativeImage_); + OH_NativeImage_Destroy(&backGroundNativeImage_); + backGroundNativeImage_ = nullptr; + } + if (backGroundNativeWindow_ != nullptr) { + OH_NativeWindow_DestroyNativeWindow(backGroundNativeWindow_); + backGroundNativeWindow_ = nullptr; + } + + if (texture_name_ != 0) { + glDeleteTextures(1, &texture_name_); + texture_name_ = 0; + } + if (backGroundTextureName_ != 0) { + glDeleteTextures(1, &backGroundTextureName_); + backGroundTextureName_ = 0; + } } void OHOSExternalTextureGL::UpdateTransform(OH_NativeImage *image) -- Gitee From 4cbf3e0a660adc09880fa88b6d172391bb4653b7 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Tue, 8 Oct 2024 21:30:05 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=9A=E5=BC=95?= =?UTF-8?q?=E6=93=8E=E5=9C=BA=E6=99=AF=E7=9A=84=E5=A4=96=E6=8E=A5=E7=BA=B9?= =?UTF-8?q?=E7=90=86=E7=9B=B8=E5=85=B3=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 --- shell/platform/ohos/ohos_external_texture_gl.cpp | 6 ++++++ shell/platform/ohos/ohos_external_texture_gl.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 69d104bb71..741edd1020 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -161,6 +161,10 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, FML_LOG(ERROR) << "OHOSExternalTextureGL::Paint, the current status is detached"; return; } + if (!freeze && texture_update_ && pixelMap_ == nullptr) { + // 多引擎场景(multi_flutters_ohos)需要在这里执行Update + Update(); + } GrGLTextureInfo textureInfo; @@ -229,6 +233,7 @@ void OHOSExternalTextureGL::MarkNewFrameAvailable() { FML_DLOG(INFO) << " OHOSExternalTextureGL::MarkNewFrameAvailable"; new_frame_ready_ = true; + texture_update_ = true; if (texture_name_ == 0) { Attach(); } @@ -259,6 +264,7 @@ void OHOSExternalTextureGL::Update() return; } int32_t ret = OH_NativeImage_UpdateSurfaceImage(nativeImage_); + texture_update_ = false; if (ret != 0) { FML_LOG(ERROR) << "OHOSExternalTextureGL OH_NativeImage_UpdateSurfaceImage err code:" << ret; return; diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index 2458ac9c54..26847c228b 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -97,6 +97,8 @@ class OHOSExternalTextureGL : public flutter::Texture { bool new_frame_ready_ = false; + bool texture_update_ = false; + GLuint texture_name_ = 0; GLuint backGroundTextureName_ = 0; -- Gitee From 5d49bd1f3f3de8e99f808425aded46c649579f42 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Fri, 11 Oct 2024 21:27:40 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E4=B8=BA0,=E5=87=8F=E5=B0=91appfreeze?= =?UTF-8?q?=E7=9A=84=E6=A6=82=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- shell/platform/ohos/ohos_external_texture_gl.cpp | 6 ++++++ shell/platform/ohos/ohos_xcomponent_adapter.cpp | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 741edd1020..50f08f4711 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -589,6 +589,12 @@ void OHOSExternalTextureGL::ProducePixelMapToNativeImage() return; } + ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow_, SET_TIMEOUT, 0); + if (ret != 0) { + FML_LOG(ERROR) << "OHOSExternalTextureGL SET_TIMEOUT err:" << ret; + return; + } + uint64_t usage = 0; OH_NativeWindow_NativeWindowHandleOpt(nativeWindow_, GET_USAGE, &usage); usage |= NATIVEBUFFER_USAGE_CPU_READ; diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index d6b8f9446d..ce9b10f61d 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -199,6 +199,14 @@ static int32_t SetNativeWindowOpt(OHNativeWindow* nativeWindow, ",w:%{public}d x %{public}d:%{public}d", nativeWindow, width, height, ret); } + + ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_TIMEOUT, 0); + if (ret) { + LOGE( + "Set NativeWindow SET_TIMEOUT Failed :window:%{public}p " + ",w:%{public}d x %{public}d:%{public}d", + nativeWindow, width, height, ret); + } return ret; } -- Gitee