diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index a5f2ab3df709317a4824608a480278a8119660d0..46fa22e2a0e027fda5bd4ddbcc4b8c0fdef860dc 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -95,9 +95,10 @@ void OHOSExternalTextureGL::Attach() OhosSurfaceGLSkia* ohosSurfaceGLSkia_ = (OhosSurfaceGLSkia*)ohos_surface_ptr; auto result = ohosSurfaceGLSkia_->GLContextMakeCurrent(); if (result->GetResult()) { - FML_DLOG(INFO)<<"ResourceContextMakeCurrent successed"; + FML_DLOG(INFO) << "ResourceContextMakeCurrent successed"; glGenTextures(1, &texture_name_); - FML_DLOG(INFO) << "OHOSExternalTextureGL::Paint, glGenTextures texture_name_=" << texture_name_ << ", Id()=" << Id(); + FML_DLOG(INFO) << "OHOSExternalTextureGL::Attach, glGenTextures texture_name_=" + << texture_name_ << ", Id()=" << Id(); if (nativeImage_ == nullptr) { nativeImage_ = OH_NativeImage_Create(texture_name_, GL_TEXTURE_EXTERNAL_OES); if (nativeImage_ == nullptr) { @@ -130,22 +131,10 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, FML_LOG(ERROR) << "OHOSExternalTextureGL::Paint, the current status is detached"; return; } - if (state_ == AttachmentState::uninitialized) { - Attach(); - if (!freeze && new_frame_ready_ && pixelMap_ != nullptr) { - ProducePixelMapToNativeImage(); - Update(); - } - new_frame_ready_ = false; - } - - if (!freeze && texture_update_ && pixelMap_ == nullptr) { - Update(); - } GrGLTextureInfo textureInfo; - if (!freeze && !first_update_ && !isEmulator_ && !new_frame_ready_ && pixelMap_ == nullptr) { + if (!freeze && !first_update_ && !isEmulator_ && backGroundTextureName_ == 0 && pixelMap_ == nullptr) { setBackground(bounds.width(), bounds.height()); textureInfo = {GL_TEXTURE_EXTERNAL_OES, backGroundTextureName_, GL_RGBA8_OES}; } else { @@ -189,13 +178,13 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, void OHOSExternalTextureGL::OnGrContextCreated() { - FML_DLOG(INFO)<<" OHOSExternalTextureGL::OnGrContextCreated"; + FML_DLOG(INFO) << " OHOSExternalTextureGL::OnGrContextCreated"; state_ = AttachmentState::uninitialized; } void OHOSExternalTextureGL::OnGrContextDestroyed() { - FML_DLOG(INFO)<<" OHOSExternalTextureGL::OnGrContextDestroyed"; + FML_DLOG(INFO) << " OHOSExternalTextureGL::OnGrContextDestroyed"; if (state_ == AttachmentState::attached) { Detach(); glDeleteTextures(1, &texture_name_); @@ -208,14 +197,15 @@ void OHOSExternalTextureGL::OnGrContextDestroyed() void OHOSExternalTextureGL::MarkNewFrameAvailable() { - FML_DLOG(INFO)<<" OHOSExternalTextureGL::MarkNewFrameAvailable"; + FML_DLOG(INFO) << " OHOSExternalTextureGL::MarkNewFrameAvailable"; new_frame_ready_ = true; - texture_update_ = true; - if (pixelMap_ == nullptr) { - Update(); - } else { - FML_DLOG(INFO) << "pixelMap_ is nullptr, texture_name_=" << texture_name_; + if (texture_name_ == 0) { + Attach(); + } + if (pixelMap_ != nullptr) { // 外接纹理图片场景 + ProducePixelMapToNativeImage(); } + Update(); } void OHOSExternalTextureGL::OnTextureUnregistered() @@ -224,10 +214,6 @@ void OHOSExternalTextureGL::OnTextureUnregistered() << ", Id()=" << Id() << ", nativeImage_=" << nativeImage_ << ", backGroundNativeImage_=" << backGroundNativeImage_; - if (state_ != AttachmentState::attached) { - FML_LOG(ERROR) << "OHOSExternalTextureGL::OnTextureUnregistered, the current status is not attached"; - return; - } first_update_ = false; if (nativeImage_ != nullptr) { OH_NativeImage_UnsetOnFrameAvailableListener(nativeImage_); @@ -252,7 +238,6 @@ void OHOSExternalTextureGL::Update() FML_LOG(ERROR) << "OHOSExternalTextureGL OH_NativeImage_UpdateSurfaceImage err code:" << ret; return; } - texture_update_ = false; first_update_ = true; UpdateTransform(nativeImage_); } @@ -300,7 +285,7 @@ void OHOSExternalTextureGL::DispatchImage(ImageNative* image) void OHOSExternalTextureGL::setBackground(int32_t width, int32_t height) { - FML_DLOG(INFO)<<" OHOSExternalTextureGL::setBackground"; + FML_DLOG(INFO) << " OHOSExternalTextureGL::setBackground"; if (backGroundNativeImage_ != nullptr) { return; } @@ -309,7 +294,7 @@ void OHOSExternalTextureGL::setBackground(int32_t width, int32_t height) OhosSurfaceGLSkia* ohosSurfaceGLSkia_ = (OhosSurfaceGLSkia*)ohos_surface_ptr; auto result = ohosSurfaceGLSkia_->GLContextMakeCurrent(); if (result->GetResult()) { - FML_DLOG(INFO)<<"ResourceContextMakeCurrent successed"; + FML_DLOG(INFO) << "ResourceContextMakeCurrent successed"; glGenTextures(1, &backGroundTextureName_); FML_DLOG(INFO) << "OHOSExternalTextureGL::setBackground, glGenTextures backGroundTextureName_=" << backGroundTextureName_; if (backGroundNativeImage_ == nullptr) { diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index 495eb025945578bec4e430bbadcb58592a005ab9..5ac18743a67d53aed5fac19176371923b9186f48 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -92,12 +92,10 @@ class OHOSExternalTextureGL : public flutter::Texture { enum class AttachmentState { uninitialized, attached, detached }; - std::atomic state_; + AttachmentState state_; bool new_frame_ready_ = false; - bool texture_update_ = false; - GLuint texture_name_ = 0; GLuint backGroundTextureName_ = 0; diff --git a/shell/platform/ohos/ohos_main.cpp b/shell/platform/ohos/ohos_main.cpp index 90b66207292d98d9c785b9fb4aa7ec73dd77e761..6e5553f5cf1570f14a7d103da5bddbee7bc90c5a 100644 --- a/shell/platform/ohos/ohos_main.cpp +++ b/shell/platform/ohos/ohos_main.cpp @@ -35,40 +35,6 @@ namespace flutter { -std::vector StringArrayToVector(napi_env env, - napi_value arrayValue) { - napi_status status; - uint32_t arrayLength = 0; - status = napi_get_array_length(env, arrayValue, &arrayLength); - LOGE("StringArrayToVector get array length %{pubilc}d", arrayLength); - if (status != napi_ok) { - LOGE("StringArrayToVector napi_get_array_length error "); - } - std::vector stringArray; - for (uint32_t i = 0; i < arrayLength; i++) { - napi_value elementValue; - status = napi_get_element(env, arrayValue, i, &elementValue); - if (status != napi_ok) { - LOGE("StringArrayToVector napi_get_element error"); - } - size_t stringLength; - status = napi_get_value_string_utf8(env, elementValue, nullptr, 0, - &stringLength); - if (status != napi_ok) { - LOGE("StringArrayToVector napi_get_value_string_utf8 error"); - } - - std::string stringValue(stringLength, '\0'); - status = napi_get_value_string_utf8(env, elementValue, &stringValue[0], - stringLength + 1, nullptr); - if (status != napi_ok) { - LOGE("StringArrayToVector napi_get_value_string_utf8 error"); - } - stringArray.push_back(stringValue); - } - return stringArray; -} - OhosMain::OhosMain(const flutter::Settings& settings) : settings_(settings), observatory_uri_callback_() {} diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 562e17f44b8a24286b035dbc9e8d2f0f3f6e9895..4d49b0c7536dbdc58ac623f75907d43830d02b04 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -345,14 +345,14 @@ void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, void* wind int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, &width_, &height_); if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { - LOGD("XComponent Current width:%{public}d,height:%{public}d", + LOGD("XComponentManger::OnSurfaceChanged Current width:%{public}d,height:%{public}d", static_cast(width_), static_cast(height_)); } if (isEngineAttached_) { PlatformViewOHOSNapi::SurfaceChanged(std::stoll(shellholderId_), width_, height_); } else { - LOGE("OnSurfaceChanged XComponentBase is not attached"); + LOGE("XComponentManger::OnSurfaceChanged XComponentBase is not attached"); } }