From f460e4424b22432cfd7d4ff4b33c1581da5bcdf0 Mon Sep 17 00:00:00 2001 From: chaoxizhang Date: Fri, 18 Oct 2024 16:29:13 +0800 Subject: [PATCH] Fix https://gitee.com/openharmony-sig/flutter_engine/issues/IAXKIK Signed-off-by: chaoxizhang --- .../ohos/ohos_external_texture_gl.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 966d566e3d..fda7cae8a0 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -136,11 +136,12 @@ void OHOSExternalTextureGL::Attach() FML_LOG(ERROR) << "Error with OH_NativeImage_Create"; return; } - nativeWindow_ = OH_NativeImage_AcquireNativeWindow(nativeImage_); - if (nativeWindow_ == nullptr) { - FML_LOG(ERROR) << "Error with OH_NativeImage_AcquireNativeWindow"; - return; - } + } + + nativeWindow_ = OH_NativeImage_AcquireNativeWindow(nativeImage_); + if (nativeWindow_ == nullptr) { + FML_LOG(ERROR) << "Error with OH_NativeImage_AcquireNativeWindow"; + return; } int32_t ret = OH_NativeImage_AttachContext(nativeImage_, texture_name_); @@ -382,6 +383,15 @@ void OHOSExternalTextureGL::setBackground(int32_t width, int32_t height) void OHOSExternalTextureGL::setTextureBufferSize(int32_t width, int32_t height) { FML_DLOG(INFO) << "OHOSExternalTextureGL::SetTextureBufferSize"; + if (nativeWindow_ == nullptr && nativeImage_) { + nativeWindow_ = OH_NativeImage_AcquireNativeWindow(nativeImage_); + } + + if (nativeWindow_ == nullptr) { + FML_LOG(ERROR) << "OHOSExternalTextureGL::SetTextureBufferSize nativeWindow_ is nullptr"; + return; + } + int code = SET_BUFFER_GEOMETRY; int32_t ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow_, code, width, height); if (ret != 0) { -- Gitee