diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 05c8449bf5e64c9a800b3258f61c8d13700e1baf..50f08f4711fcde49e43e7b952fa9003d64fd15eb 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; @@ -169,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; @@ -216,20 +212,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; } } @@ -237,6 +233,7 @@ void OHOSExternalTextureGL::MarkNewFrameAvailable() { FML_DLOG(INFO) << " OHOSExternalTextureGL::MarkNewFrameAvailable"; new_frame_ready_ = true; + texture_update_ = true; if (texture_name_ == 0) { Attach(); } @@ -253,14 +250,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; } } @@ -272,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; @@ -287,12 +280,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) @@ -572,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_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index 2458ac9c540e3b0cafa4debce439f94dcac9da8f..26847c228b420b1469c0c58987d487f95befcba2 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; diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index d6b8f9446d91fda32f09f6f8df86ba3867bef704..ce9b10f61d4301818eca106aa4f50d0fa9905e5c 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; }