From 3112230e95970a3944af5609e9807eb595d91e65 Mon Sep 17 00:00:00 2001 From: liujiake Date: Tue, 3 Dec 2024 21:28:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=A4=9A=E5=BC=95=E6=93=8E=E7=89=B9=E6=80=A7=E7=9A=84=E5=8A=A8?= =?UTF-8?q?=E7=94=BB=E9=A1=B5=E9=9D=A2=E8=B7=B3=E8=BD=AC=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=90=8E=E5=8D=A1=E6=AD=BB=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 | 40 ++++++++++++++++--- .../platform/ohos/ohos_external_texture_gl.h | 10 ++++- shell/platform/ohos/platform_view_ohos.cpp | 10 +++++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 894611215b..0bead82e11 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -216,17 +216,16 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, bool freeze, const SkSamplingOptions& sampling) { + context_ = eglGetCurrentContext(); + display_ = eglGetCurrentDisplay(); + draw_surface_ = eglGetCurrentSurface(EGL_DRAW); + read_surface_ = eglGetCurrentSurface(EGL_READ); if (state_ == AttachmentState::detached) { FML_LOG(ERROR) << "Paint, the current status is detached"; return; } if (state_ == AttachmentState::uninitialized) { - Attach(); - if (pixelMap_ != nullptr) { - // 外接纹理图片场景 - ProducePixelMapToNativeImage(); - Update(); - } + delegate_.OnPlatformViewMarkTextureFrameAvailable(Id()); } GrGLTextureInfo textureInfo; @@ -288,6 +287,9 @@ void OHOSExternalTextureGL::OnGrContextDestroyed() void OHOSExternalTextureGL::MarkNewFrameAvailable() { FML_DLOG(INFO) << " OHOSExternalTextureGL::MarkNewFrameAvailable"; + if (state_ == AttachmentState::uninitialized) { + Attach(); + } if (state_ == AttachmentState::attached) { Update(); } @@ -306,9 +308,35 @@ void OHOSExternalTextureGL::OnTextureUnregistered() } } +bool OHOSExternalTextureGL::IsContextCurrent() { + EGLContext current_egl_context = eglGetCurrentContext(); + if (context_ != current_egl_context) { + return false; + } + EGLDisplay current_egl_display = eglGetCurrentDisplay(); + if (display_ != current_egl_display) { + return false; + } + EGLSurface draw_surface = eglGetCurrentSurface(EGL_DRAW); + if (draw_surface != draw_surface_) { + return false; + } + EGLSurface read_surface = eglGetCurrentSurface(EGL_READ); + if (read_surface != read_surface_) { + return false; + } + return true; +} + void OHOSExternalTextureGL::Update() { FML_DLOG(INFO) << "OHOSExternalTextureGL::Update, texture_name_=" << texture_name_; + if (!IsContextCurrent() && context_) { + if (eglMakeCurrent(display_, draw_surface_, read_surface_, context_) != EGL_TRUE) { + FML_LOG(WARNING) << "eglMakeCurrent in update failed"; + } + } + if (nativeImage_ == nullptr) { FML_LOG(ERROR) << "Update, nativeImage_ is nullptr, texture_name_=" << texture_name_; return; diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index a5a3c1d5fc..ce8faf8e3f 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -54,6 +54,7 @@ class OHOSExternalTextureGL : public flutter::Texture { bool first_update_ = false; + void Paint(PaintContext& context, const SkRect& bounds, bool freeze, @@ -100,7 +101,7 @@ class OHOSExternalTextureGL : public flutter::Texture { void ProducePixelMapToBackGroundImage(); - enum class AttachmentState { uninitialized, attached, detached }; + enum class AttachmentState { uninitialized, attached, detached, todetach }; AttachmentState state_; @@ -134,6 +135,13 @@ class OHOSExternalTextureGL : public flutter::Texture { EGLDisplay eglDisplay_; FML_DISALLOW_COPY_AND_ASSIGN(OHOSExternalTextureGL); + + void* display_; + void* draw_surface_; + void* read_surface_; + void* context_; + + bool IsContextCurrent(); }; class OhosImageFrameData { diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index 1f5fd79368..4fc99fd3d7 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -117,6 +117,15 @@ PlatformViewOHOS::PlatformViewOHOS( PlatformViewOHOS::~PlatformViewOHOS() { FML_LOG(INFO) << "PlatformViewOHOS::~PlatformViewOHOS"; + for (std::map>::iterator it = external_texture_gl_.begin(); + it != external_texture_gl_.end(); ++it) { + if (it->second != nullptr) { + OH_NativeImage_Destroy(&(it->second->nativeImage_)); + it->second->nativeImage_ = nullptr; + } + } + external_texture_gl_.clear(); + FML_LOG(INFO) << "PlatformViewOHOS::~PlatformViewOHOS finish"; } void PlatformViewOHOS::NotifyCreate( @@ -461,6 +470,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; } -- Gitee From 8eb34e99794367c1da29a7ebbd6bd74a2ecbd94c Mon Sep 17 00:00:00 2001 From: liujiake Date: Tue, 3 Dec 2024 21:59:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=A8=E7=A6=81?= =?UTF-8?q?=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 | 3 ++- shell/platform/ohos/ohos_external_texture_gl.h | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 0bead82e11..a113f3763b 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -308,7 +308,8 @@ void OHOSExternalTextureGL::OnTextureUnregistered() } } -bool OHOSExternalTextureGL::IsContextCurrent() { +bool OHOSExternalTextureGL::IsContextCurrent() +{ EGLContext current_egl_context = eglGetCurrentContext(); if (context_ != current_egl_context) { return false; diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index ce8faf8e3f..6e7b35e11e 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -54,7 +54,6 @@ class OHOSExternalTextureGL : public flutter::Texture { bool first_update_ = false; - void Paint(PaintContext& context, const SkRect& bounds, bool freeze, @@ -101,7 +100,7 @@ class OHOSExternalTextureGL : public flutter::Texture { void ProducePixelMapToBackGroundImage(); - enum class AttachmentState { uninitialized, attached, detached, todetach }; + enum class AttachmentState { uninitialized, attached, detached, }; AttachmentState state_; -- Gitee