From f2356ee677f67038dfb55ca5b6581579776c95d2 Mon Sep 17 00:00:00 2001 From: liujiake Date: Thu, 21 Nov 2024 22:00:06 +0800 Subject: [PATCH 1/6] =?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=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=B5=81=E7=A8=8B=EF=BC=8C=E8=A7=A3=E5=86=B3=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=92=AD=E8=B7=B3=E8=BD=AC=E8=BF=94=E5=9B=9E=E5=90=8E?= =?UTF-8?q?=E9=BB=91=E5=B1=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liujiake --- .../ohos/ohos_external_texture_gl.cpp | 61 ++++++++++++-- .../platform/ohos/ohos_external_texture_gl.h | 22 +++++- shell/platform/ohos/platform_view_ohos.cpp | 79 +------------------ shell/platform/ohos/platform_view_ohos.h | 14 ---- 4 files changed, 78 insertions(+), 98 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 8c8d58f72a..6dd6962627 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -42,7 +42,7 @@ constexpr const char *EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT"; constexpr uint32_t WHITE_COLOR = 0xFFFFFFFF; const SkScalar DEFAULT_MATRIX[] = {1, 0, 0, 0, -1, 1, 0, 0, 1}; -const int UPDATE_FRAME_COUNT = 2; +const int UPDATE_FRAME_COUNT = 1; static int PixelMapToWindowFormat(PIXEL_FORMAT pixel_format) { @@ -83,8 +83,10 @@ static bool IsPixelMapYUVFormat(PIXEL_FORMAT format) OHOSExternalTextureGL::OHOSExternalTextureGL( int64_t id, - const std::shared_ptr& ohos_surface) + const std::shared_ptr& ohos_surface, + PlatformView::Delegate& delegate) : Texture(id), + delegate_(delegate), ohos_surface_(std::move(ohos_surface)), transform(SkMatrix::I()) { @@ -99,6 +101,7 @@ OHOSExternalTextureGL::OHOSExternalTextureGL( backGroundPixelMap_ = nullptr; lastImage_ = nullptr; isEmulator_ = OhosMain::IsEmulator(); + frameData_ = nullptr; } OHOSExternalTextureGL::~OHOSExternalTextureGL() @@ -119,6 +122,20 @@ OHOSExternalTextureGL::~OHOSExternalTextureGL() lastImage_ = nullptr; } +void OnNativeImageFrameAvailable(void *data) +{ + auto frameData = reinterpret_cast(data); + if (frameData == nullptr) { + FML_DLOG(ERROR) << "OnNativeImageFrameAvailable, frameData is null."; + return; + } + if (!frameData->t) { + FML_DLOG(ERROR) << "OnNativeImageFrameAvailable, frameData value is not valid."; + return; + } + frameData->t->delegate_.OnPlatformViewMarkTextureFrameAvailable(frameData->texture_id_); +} + void OHOSExternalTextureGL::Attach() { FML_DLOG(INFO) << "Attach, texture_name_=" << texture_name_ @@ -153,6 +170,20 @@ void OHOSExternalTextureGL::Attach() if (ret != 0) { FML_LOG(ERROR) << "OHOSExternalTextureGL OH_NativeImage_AttachContext err code:" << ret; } + + if (frameData_ == nullptr) { + frameData_ = new OhosImageFrameData(this, Id()); + } + OH_OnFrameAvailableListener listener; + listener.context = frameData_; + listener.onFrameAvailable = OnNativeImageFrameAvailable; + ret = OH_NativeImage_SetOnFrameAvailableListener(nativeImage_, listener); + if (ret != 0) { + FML_DLOG(ERROR) + << "Error with OH_NativeImage_SetOnFrameAvailableListener"; + return; + } + state_ = AttachmentState::attached; } else { FML_LOG(ERROR) << "ResourceContextMakeCurrent failed"; @@ -174,10 +205,10 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, // 外接纹理图片场景 ProducePixelMapToNativeImage(); newFrameCount++; + Update(); } } if (!freeze && newFrameCount > 0) { - Update(); new_frame_ready_ = false; newFrameCount--; } @@ -226,7 +257,9 @@ void OHOSExternalTextureGL::OnGrContextCreated() FML_DLOG(INFO) << " OHOSExternalTextureGL::OnGrContextCreated" << ", texture_name_=" << texture_name_ << ", Id()=" << Id(); - state_ = AttachmentState::uninitialized; + if (state_ == AttachmentState::attached) { + delegate_.OnPlatformViewMarkTextureFrameAvailable(Id()); + } } void OHOSExternalTextureGL::OnGrContextDestroyed() @@ -234,10 +267,6 @@ void OHOSExternalTextureGL::OnGrContextDestroyed() FML_DLOG(INFO) << " OHOSExternalTextureGL::OnGrContextDestroyed" << ", texture_name_=" << texture_name_ << ", Id()=" << Id(); - if (state_ == AttachmentState::attached) { - Detach(); - } - state_ = AttachmentState::detached; } void OHOSExternalTextureGL::MarkNewFrameAvailable() @@ -245,6 +274,9 @@ void OHOSExternalTextureGL::MarkNewFrameAvailable() FML_DLOG(INFO) << " OHOSExternalTextureGL::MarkNewFrameAvailable"; new_frame_ready_ = true; newFrameCount = UPDATE_FRAME_COUNT; + if (state_ == AttachmentState::attached) { + Update(); + } } void OHOSExternalTextureGL::OnTextureUnregistered() @@ -289,6 +321,10 @@ void OHOSExternalTextureGL::Detach() OH_NativeImage_Destroy(&nativeImage_); nativeImage_ = nullptr; } + if (frameData_ != nullptr) { + delete (OhosImageFrameData *)frameData_; + frameData_ = nullptr; + } if (nativeWindow_ != nullptr) { OH_NativeWindow_DestroyNativeWindow(nativeWindow_); nativeWindow_ = nullptr; @@ -677,4 +713,13 @@ void OHOSExternalTextureGL::DispatchBackGroundPixelMap(NativePixelMap* pixelMap) } } +OhosImageFrameData::OhosImageFrameData( + OHOSExternalTextureGL *t, + int64_t texture_id + ) + : t(t), + texture_id_(texture_id) {} + +OhosImageFrameData::~OhosImageFrameData() = default; + } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index a8b5de6629..b8da68b753 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -31,6 +31,7 @@ #include "flutter/shell/platform/ohos/napi/platform_view_ohos_napi.h" #include "flutter/shell/platform/ohos/ohos_surface_gl_skia.h" #include "flutter/shell/platform/ohos/surface/ohos_surface.h" +#include "flutter/shell/common/platform_view.h" // maybe now unused namespace flutter { @@ -38,13 +39,19 @@ namespace flutter { class OHOSExternalTextureGL : public flutter::Texture { public: explicit OHOSExternalTextureGL(int64_t id, const std::shared_ptr& ohos_surface); + explicit OHOSExternalTextureGL(int64_t id, const std::shared_ptr& ohos_surface, + PlatformView::Delegate& delegate); ~OHOSExternalTextureGL() override; + PlatformView::Delegate& delegate_; + OH_NativeImage *nativeImage_; OH_NativeImage *backGroundNativeImage_; + void *frameData_; + bool first_update_ = false; void Paint(PaintContext& context, @@ -96,7 +103,8 @@ class OHOSExternalTextureGL : public flutter::Texture { AttachmentState state_; bool new_frame_ready_ = false; - int newFrameCount = 0; + + std::atomic newFrameCount = 0; GLuint texture_name_ = 0; @@ -129,5 +137,17 @@ class OHOSExternalTextureGL : public flutter::Texture { FML_DISALLOW_COPY_AND_ASSIGN(OHOSExternalTextureGL); }; + +class OhosImageFrameData { + public: + OhosImageFrameData(OHOSExternalTextureGL *t, int64_t texture_id); + + ~OhosImageFrameData(); + + OHOSExternalTextureGL *t; + + int64_t texture_id_; +}; + } // namespace flutter #endif \ No newline at end of file diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index 4285b3d8fd..041ace656a 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -117,17 +117,6 @@ PlatformViewOHOS::PlatformViewOHOS( PlatformViewOHOS::~PlatformViewOHOS() { FML_LOG(INFO) << "PlatformViewOHOS::~PlatformViewOHOS"; - for (std::map::iterator it = contextDatas_.begin(); - it != contextDatas_.end(); ++it) { - if (it->second != nullptr) { - OhosImageFrameData* data = - reinterpret_cast(it->second); - delete data; - data = nullptr; - it->second = nullptr; - } - } - contextDatas_.clear(); } void PlatformViewOHOS::NotifyCreate( @@ -435,7 +424,7 @@ void PlatformViewOHOS::RegisterExternalTextureByImage(int64_t texture_id, iter->second->DispatchImage(image); } else { std::shared_ptr ohos_external_gl = - std::make_shared(texture_id, ohos_surface_); + std::make_shared(texture_id, ohos_surface_, delegate_); external_texture_gl_[texture_id] = ohos_external_gl; RegisterTexture(ohos_external_gl); ohos_external_gl->DispatchImage(image); @@ -456,25 +445,13 @@ uint64_t PlatformViewOHOS::RegisterExternalTexture(int64_t texture_id) int ret = -1; if (ohos_context_->RenderingApi() == OHOSRenderingAPI::kOpenGLES) { std::shared_ptr ohos_external_gl = - std::make_shared(texture_id, ohos_surface_); + std::make_shared(texture_id, ohos_surface_, delegate_); ohos_external_gl->nativeImage_ = OH_NativeImage_Create(texture_id, GL_TEXTURE_EXTERNAL_OES); if (ohos_external_gl->nativeImage_ == nullptr) { FML_DLOG(ERROR) << "Error with OH_NativeImage_Create"; return surface_id; } - void* contextData = new OhosImageFrameData(this, texture_id); - contextDatas_.insert(std::pair(texture_id, contextData)); - OH_OnFrameAvailableListener listener; - listener.context = contextData; - listener.onFrameAvailable = &PlatformViewOHOS::OnNativeImageFrameAvailable; - ret = OH_NativeImage_SetOnFrameAvailableListener( - ohos_external_gl->nativeImage_, listener); - if (ret != 0) { - FML_DLOG(ERROR) - << "Error with OH_NativeImage_SetOnFrameAvailableListener"; - return surface_id; - } ret = OH_NativeImage_GetSurfaceId(ohos_external_gl->nativeImage_, &surface_id); ohos_external_gl->first_update_ = false; @@ -484,6 +461,7 @@ uint64_t PlatformViewOHOS::RegisterExternalTexture(int64_t texture_id) } external_texture_gl_[texture_id] = ohos_external_gl; RegisterTexture(ohos_external_gl); + MarkTextureFrameAvailable(texture_id); } return surface_id; } @@ -501,54 +479,11 @@ void PlatformViewOHOS::SetTextureBufferSize( } } -void PlatformViewOHOS::OnNativeImageFrameAvailable(void* data) { - auto frameData = reinterpret_cast(data); - if (frameData == nullptr || frameData->context_ == nullptr) { - FML_DLOG(ERROR) - << "OnNativeImageFrameAvailable, frameData or context_ is null."; - return; - } - - if (frameData->context_->GetDestroyed()) { - FML_LOG(ERROR) << "OnNativeImageFrameAvailable NotifyDstroyed, will not " - "MarkTextureFrameAvailable"; - return; - } - - std::shared_ptr ohos_surface = - frameData->context_->ohos_surface_; - const TaskRunners task_runners = frameData->context_->task_runners_; - if (ohos_surface) { - fml::TaskRunner::RunNowOrPostTask( - task_runners.GetPlatformTaskRunner(), [frameData]() { - if (frameData->context_->GetDestroyed()) { - FML_LOG(ERROR) << "OnNativeImageFrameAvailable NotifyDstroyed, " - "will not MarkTextureFrameAvailable"; - return; - } - frameData->context_->MarkTextureFrameAvailable( - frameData->texture_id_); - }); - } -} - void PlatformViewOHOS::UnRegisterExternalTexture(int64_t texture_id) { FML_DLOG(INFO) << "PlatformViewOHOS::UnRegisterExternalTexture, texture_id=" << texture_id; external_texture_gl_.erase(texture_id); UnregisterTexture(texture_id); - std::map::iterator it = contextDatas_.find(texture_id); - if (it != contextDatas_.end()) { - if (it->second != nullptr) { - OhosImageFrameData* data = - reinterpret_cast(it->second); - task_runners_.GetPlatformTaskRunner()->PostDelayedTask( - [data_ = data]() { delete data_; }, fml::TimeDelta::FromSeconds(2)); - data = nullptr; - it->second = nullptr; - } - contextDatas_.erase(texture_id); - } } void PlatformViewOHOS::RegisterExternalTextureByPixelMap( @@ -560,7 +495,7 @@ void PlatformViewOHOS::RegisterExternalTextureByPixelMap( iter->second->DispatchPixelMap(pixelMap); } else { std::shared_ptr ohos_external_gl = - std::make_shared(texture_id, ohos_surface_); + std::make_shared(texture_id, ohos_surface_, delegate_); external_texture_gl_[texture_id] = ohos_external_gl; RegisterTexture(ohos_external_gl); ohos_external_gl->DispatchPixelMap(pixelMap); @@ -613,10 +548,4 @@ void PlatformViewOHOS::RunTask(OHOS_THREAD_TYPE type, const fml::closure& task) fml::TaskRunner::RunNowOrPostTask(TaskRunnerPtr, task); } -OhosImageFrameData::OhosImageFrameData(PlatformViewOHOS* context, - int64_t texture_id) - : context_(context), texture_id_(texture_id) {} - -OhosImageFrameData::~OhosImageFrameData() = default; - } // namespace flutter diff --git a/shell/platform/ohos/platform_view_ohos.h b/shell/platform/ohos/platform_view_ohos.h index 8e1b233b3b..eb853a3e4f 100644 --- a/shell/platform/ohos/platform_view_ohos.h +++ b/shell/platform/ohos/platform_view_ohos.h @@ -154,7 +154,6 @@ class PlatformViewOHOS final : public PlatformView { std::shared_ptr surface_factory_; std::map> external_texture_gl_; - std::map contextDatas_; std::atomic isDestroyed_; @@ -209,19 +208,6 @@ class PlatformViewOHOS final : public PlatformView { FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewOHOS); - static void OnNativeImageFrameAvailable(void *data); -}; - -class OhosImageFrameData { - public: - OhosImageFrameData(PlatformViewOHOS* context, - int64_t texture_id); - - ~OhosImageFrameData(); - - PlatformViewOHOS* context_; - - int64_t texture_id_; }; } // namespace flutter -- Gitee From 267d464fa8a611aed35c7e9e3f8ba0a469496e18 Mon Sep 17 00:00:00 2001 From: liujiake Date: Wed, 27 Nov 2024 10:44:46 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81=EF=BC=88=E4=BF=AE=E5=A4=8D=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=B3=84=E6=BC=8F=EF=BC=8C=E5=8F=96=E6=B6=88=E5=8E=9F=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E5=B8=A7=E5=88=A4=E6=96=AD=E6=A0=87=E5=BF=97=EF=BC=9B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=88=90=E5=91=98=E5=91=BD=E5=90=8D=EF=BC=9B?= =?UTF-8?q?=E5=87=8F=E5=B0=91=E4=BB=A3=E7=A0=81=E5=B5=8C=E5=A5=97=E6=B7=B1?= =?UTF-8?q?=E5=BA=A6=EF=BC=9B=E4=BF=AE=E6=94=B9log=E7=AD=89=E7=BA=A7?= =?UTF-8?q?=E3=80=82=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liujiake --- .../ohos/ohos_external_texture_gl.cpp | 48 ++++++++++--------- .../platform/ohos/ohos_external_texture_gl.h | 14 +++--- shell/platform/ohos/platform_view_ohos.cpp | 1 - 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 6dd6962627..b57a54df8b 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -42,7 +42,6 @@ constexpr const char *EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT"; constexpr uint32_t WHITE_COLOR = 0xFFFFFFFF; const SkScalar DEFAULT_MATRIX[] = {1, 0, 0, 0, -1, 1, 0, 0, 1}; -const int UPDATE_FRAME_COUNT = 1; static int PixelMapToWindowFormat(PIXEL_FORMAT pixel_format) { @@ -126,14 +125,10 @@ void OnNativeImageFrameAvailable(void *data) { auto frameData = reinterpret_cast(data); if (frameData == nullptr) { - FML_DLOG(ERROR) << "OnNativeImageFrameAvailable, frameData is null."; + FML_LOG(ERROR) << "OnNativeImageFrameAvailable, frameData is null."; return; } - if (!frameData->t) { - FML_DLOG(ERROR) << "OnNativeImageFrameAvailable, frameData value is not valid."; - return; - } - frameData->t->delegate_.OnPlatformViewMarkTextureFrameAvailable(frameData->texture_id_); + frameData->OnPlatformViewMarkTextureFrameAvailable(); } void OHOSExternalTextureGL::Attach() @@ -179,8 +174,12 @@ void OHOSExternalTextureGL::Attach() listener.onFrameAvailable = OnNativeImageFrameAvailable; ret = OH_NativeImage_SetOnFrameAvailableListener(nativeImage_, listener); if (ret != 0) { - FML_DLOG(ERROR) + FML_LOG(ERROR) << "Error with OH_NativeImage_SetOnFrameAvailableListener"; + if (frameData_ != nullptr) { + delete (OhosImageFrameData *)frameData_; + frameData_ = nullptr; + } return; } @@ -204,17 +203,12 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, if (pixelMap_ != nullptr) { // 外接纹理图片场景 ProducePixelMapToNativeImage(); - newFrameCount++; Update(); } } - if (!freeze && newFrameCount > 0) { - new_frame_ready_ = false; - newFrameCount--; - } GrGLTextureInfo textureInfo; - if (!freeze && !first_update_ && !isEmulator_ && !new_frame_ready_ && pixelMap_ == nullptr) { + if (!freeze && !first_update_ && !isEmulator_ && pixelMap_ == nullptr) { setBackground(bounds.width(), bounds.height()); textureInfo = {GL_TEXTURE_EXTERNAL_OES, backGroundTextureName_, GL_RGBA8_OES}; } else { @@ -272,8 +266,6 @@ void OHOSExternalTextureGL::OnGrContextDestroyed() void OHOSExternalTextureGL::MarkNewFrameAvailable() { FML_DLOG(INFO) << " OHOSExternalTextureGL::MarkNewFrameAvailable"; - new_frame_ready_ = true; - newFrameCount = UPDATE_FRAME_COUNT; if (state_ == AttachmentState::attached) { Update(); } @@ -714,12 +706,24 @@ void OHOSExternalTextureGL::DispatchBackGroundPixelMap(NativePixelMap* pixelMap) } OhosImageFrameData::OhosImageFrameData( - OHOSExternalTextureGL *t, - int64_t texture_id - ) - : t(t), - texture_id_(texture_id) {} + OHOSExternalTextureGL *ohosExternalTextureGL, + int64_t texture_id) + : ohosExternalTextureGL(ohosExternalTextureGL), + texture_id_(texture_id) +{} -OhosImageFrameData::~OhosImageFrameData() = default; +OhosImageFrameData::~OhosImageFrameData() +{ + ohosExternalTextureGL = nullptr; + texture_id_ = 0; +} + +void OhosImageFrameData::OnPlatformViewMarkTextureFrameAvailable() +{ + if(ohosExternalTextureGL != nullptr) { + PlatformView::Delegate& dalegate = ohosExternalTextureGL->delegate_; + dalegate.OnPlatformViewMarkTextureFrameAvailable(texture_id_); + } +} } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index b8da68b753..9d398ff977 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -102,10 +102,6 @@ class OHOSExternalTextureGL : public flutter::Texture { AttachmentState state_; - bool new_frame_ready_ = false; - - std::atomic newFrameCount = 0; - GLuint texture_name_ = 0; GLuint backGroundTextureName_ = 0; @@ -140,11 +136,17 @@ class OHOSExternalTextureGL : public flutter::Texture { class OhosImageFrameData { public: - OhosImageFrameData(OHOSExternalTextureGL *t, int64_t texture_id); + OhosImageFrameData(OHOSExternalTextureGL *ohosExternalTextureGL, int64_t texture_id); + + OhosImageFrameData() = delete; ~OhosImageFrameData(); - OHOSExternalTextureGL *t; + void OnPlatformViewMarkTextureFrameAvailable(); + + private: + + OHOSExternalTextureGL *ohosExternalTextureGL; int64_t texture_id_; }; diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index 041ace656a..1f5fd79368 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -461,7 +461,6 @@ uint64_t PlatformViewOHOS::RegisterExternalTexture(int64_t texture_id) } external_texture_gl_[texture_id] = ohos_external_gl; RegisterTexture(ohos_external_gl); - MarkTextureFrameAvailable(texture_id); } return surface_id; } -- Gitee From 731e58acbfc6c5990ec9227230b542c3b62a08fc Mon Sep 17 00:00:00 2001 From: liujiake Date: Wed, 27 Nov 2024 12:15:59 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=A8=E7=A6=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liujiake --- .../ohos/ohos_external_texture_gl.cpp | 40 +++++++++++-------- shell/platform/ohos/platform_view_ohos.h | 1 - 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index b57a54df8b..8cae8fc854 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -131,6 +131,27 @@ void OnNativeImageFrameAvailable(void *data) frameData->OnPlatformViewMarkTextureFrameAvailable(); } +void RegisterFrameAvailableListener(OH_NativeImage *nativeImage, OHOSExternalTextureGL *context) +{ + auto frameData = reinterpret_cast(context->frameData_); + if (frameData == nullptr) { + frameData = new OhosImageFrameData(context, context->Id()); + } + OH_OnFrameAvailableListener listener; + listener.context = frameData; + listener.onFrameAvailable = OnNativeImageFrameAvailable; + int64_t ret = OH_NativeImage_SetOnFrameAvailableListener(nativeImage, listener); + if (ret != 0) { + FML_LOG(ERROR) + << "Error with OH_NativeImage_SetOnFrameAvailableListener"; + if (frameData != nullptr) { + delete (OhosImageFrameData *)frameData; + frameData = nullptr; + } + return; + } +} + void OHOSExternalTextureGL::Attach() { FML_DLOG(INFO) << "Attach, texture_name_=" << texture_name_ @@ -166,22 +187,7 @@ void OHOSExternalTextureGL::Attach() FML_LOG(ERROR) << "OHOSExternalTextureGL OH_NativeImage_AttachContext err code:" << ret; } - if (frameData_ == nullptr) { - frameData_ = new OhosImageFrameData(this, Id()); - } - OH_OnFrameAvailableListener listener; - listener.context = frameData_; - listener.onFrameAvailable = OnNativeImageFrameAvailable; - ret = OH_NativeImage_SetOnFrameAvailableListener(nativeImage_, listener); - if (ret != 0) { - FML_LOG(ERROR) - << "Error with OH_NativeImage_SetOnFrameAvailableListener"; - if (frameData_ != nullptr) { - delete (OhosImageFrameData *)frameData_; - frameData_ = nullptr; - } - return; - } + RegisterFrameAvailableListener(nativeImage_, this); state_ = AttachmentState::attached; } else { @@ -720,7 +726,7 @@ OhosImageFrameData::~OhosImageFrameData() void OhosImageFrameData::OnPlatformViewMarkTextureFrameAvailable() { - if(ohosExternalTextureGL != nullptr) { + if (ohosExternalTextureGL != nullptr) { PlatformView::Delegate& dalegate = ohosExternalTextureGL->delegate_; dalegate.OnPlatformViewMarkTextureFrameAvailable(texture_id_); } diff --git a/shell/platform/ohos/platform_view_ohos.h b/shell/platform/ohos/platform_view_ohos.h index eb853a3e4f..c6dd57ccfb 100644 --- a/shell/platform/ohos/platform_view_ohos.h +++ b/shell/platform/ohos/platform_view_ohos.h @@ -207,7 +207,6 @@ class PlatformViewOHOS final : public PlatformView { void FireFirstFrameCallback(); FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewOHOS); - }; } // namespace flutter -- Gitee From c3f376a2670f260bd1ac794e8530af37dfb68a34 Mon Sep 17 00:00:00 2001 From: liujiake Date: Wed, 27 Nov 2024 12:40:58 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=A8=E7=A6=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liujiake --- .../ohos/ohos_external_texture_gl.cpp | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 8cae8fc854..db3e2e42f1 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -131,25 +131,21 @@ void OnNativeImageFrameAvailable(void *data) frameData->OnPlatformViewMarkTextureFrameAvailable(); } -void RegisterFrameAvailableListener(OH_NativeImage *nativeImage, OHOSExternalTextureGL *context) +bool RegisterFrameAvailableListener(OH_NativeImage *nativeImage, OhosImageFrameData *frameData) { - auto frameData = reinterpret_cast(context->frameData_); if (frameData == nullptr) { - frameData = new OhosImageFrameData(context, context->Id()); + FML_LOG(ERROR) << "Error with RegisterFrameAvailableListener, frameData is null"; + return false; } OH_OnFrameAvailableListener listener; listener.context = frameData; listener.onFrameAvailable = OnNativeImageFrameAvailable; int64_t ret = OH_NativeImage_SetOnFrameAvailableListener(nativeImage, listener); if (ret != 0) { - FML_LOG(ERROR) - << "Error with OH_NativeImage_SetOnFrameAvailableListener"; - if (frameData != nullptr) { - delete (OhosImageFrameData *)frameData; - frameData = nullptr; - } - return; + FML_LOG(ERROR) << "Error with OH_NativeImage_SetOnFrameAvailableListener"; + return false; } + return true; } void OHOSExternalTextureGL::Attach() @@ -187,8 +183,14 @@ void OHOSExternalTextureGL::Attach() FML_LOG(ERROR) << "OHOSExternalTextureGL OH_NativeImage_AttachContext err code:" << ret; } - RegisterFrameAvailableListener(nativeImage_, this); - + if (frameData_ == nullptr) { + frameData_ = new OhosImageFrameData(this, Id()); + } + if (!RegisterFrameAvailableListener(nativeImage_, this)) { + delete (OhosImageFrameData *)frameData_; + frameData_ = nullptr; + return; + } state_ = AttachmentState::attached; } else { FML_LOG(ERROR) << "ResourceContextMakeCurrent failed"; -- Gitee From db735779dd032720630ffc12625563b5a8622cfd Mon Sep 17 00:00:00 2001 From: liujiake Date: Wed, 27 Nov 2024 13:08:26 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=A8=E7=A6=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liujiake --- shell/platform/ohos/ohos_external_texture_gl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index db3e2e42f1..27a4caf4e0 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -186,7 +186,7 @@ void OHOSExternalTextureGL::Attach() if (frameData_ == nullptr) { frameData_ = new OhosImageFrameData(this, Id()); } - if (!RegisterFrameAvailableListener(nativeImage_, this)) { + if (!RegisterFrameAvailableListener(nativeImage_, (OhosImageFrameData *)frameData_)) { delete (OhosImageFrameData *)frameData_; frameData_ = nullptr; return; -- Gitee From fe22df3223ab469034fd40665027d5520ea5c3f0 Mon Sep 17 00:00:00 2001 From: liujiake Date: Wed, 27 Nov 2024 14:07:45 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=A8=E7=A6=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liujiake --- shell/platform/ohos/ohos_external_texture_gl.cpp | 8 ++++---- shell/platform/ohos/ohos_external_texture_gl.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 27a4caf4e0..f52ffd1670 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -715,22 +715,22 @@ void OHOSExternalTextureGL::DispatchBackGroundPixelMap(NativePixelMap* pixelMap) OhosImageFrameData::OhosImageFrameData( OHOSExternalTextureGL *ohosExternalTextureGL, - int64_t texture_id) + int64_t textureId) : ohosExternalTextureGL(ohosExternalTextureGL), - texture_id_(texture_id) + textureId_(textureId) {} OhosImageFrameData::~OhosImageFrameData() { ohosExternalTextureGL = nullptr; - texture_id_ = 0; + textureId_ = 0; } void OhosImageFrameData::OnPlatformViewMarkTextureFrameAvailable() { if (ohosExternalTextureGL != nullptr) { PlatformView::Delegate& dalegate = ohosExternalTextureGL->delegate_; - dalegate.OnPlatformViewMarkTextureFrameAvailable(texture_id_); + dalegate.OnPlatformViewMarkTextureFrameAvailable(textureId_); } } diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index 9d398ff977..6f8379cc0c 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -136,7 +136,7 @@ class OHOSExternalTextureGL : public flutter::Texture { class OhosImageFrameData { public: - OhosImageFrameData(OHOSExternalTextureGL *ohosExternalTextureGL, int64_t texture_id); + OhosImageFrameData(OHOSExternalTextureGL *ohosExternalTextureGL, int64_t textureId); OhosImageFrameData() = delete; @@ -148,7 +148,7 @@ class OhosImageFrameData { OHOSExternalTextureGL *ohosExternalTextureGL; - int64_t texture_id_; + int64_t textureId_; }; } // namespace flutter -- Gitee