diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 894611215b1d4acc22b8aebe9884a31853c51c48..a113f3763bb336f89d7bc9b2ea808a949cd13915 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,36 @@ 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 a5a3c1d5fc24fedaa11a9b845557fcd37c6bd654..6e7b35e11e7f2529f91eead062736c2347bebe8f 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -100,7 +100,7 @@ class OHOSExternalTextureGL : public flutter::Texture { void ProducePixelMapToBackGroundImage(); - enum class AttachmentState { uninitialized, attached, detached }; + enum class AttachmentState { uninitialized, attached, detached, }; AttachmentState state_; @@ -134,6 +134,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 1f5fd79368785ff899e7da844276710ae2b4e974..4fc99fd3d752bcc3f46e7448be714b9faea0d07c 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; }