diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets index 142a41da70a76ff0041b3fe90af893569c2331fe..f88f0688f8493af61fe5a3e16b141212bab2237e 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets @@ -123,6 +123,4 @@ export const nativeUnregisterTexture: (nativeShellHolderId: number, textureId: n export const nativeRegisterPixelMap: (nativeShellHolderId: number, textureId: number, pixelMap: PixelMap) => void; -export const nativeSetTextureBackGroundPixelMap: (nativeShellHolderId: number, textureId: number, pixelMap: PixelMap) => void; - export const nativeRegisterTexture: (nativeShellHolderId: number, textureId: number) => number; diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets index 6fcf4a574fde2c3b46e070c6159b36ec3b14597b..bf10b17cabb64e69566ab6c451b68ada4d535dba 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets @@ -467,11 +467,6 @@ export default class FlutterNapi { flutter.nativeRegisterPixelMap(this.nativeShellHolderId!, textureId, pixelMap); } - setTextureBackGroundPixelMap(textureId: number, pixelMap: PixelMap): void { - Log.d(TAG, "called setTextureBackGroundPixelMap "); - flutter.nativeSetTextureBackGroundPixelMap(this.nativeShellHolderId!, textureId, pixelMap); - } - registerTexture(textureId: number): number { Log.d(TAG, "called registerTexture "); if (!this.isAttached()) { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/FlutterRenderer.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/FlutterRenderer.ets index 5d9fe37697523931f8099d7ff7d5bc9304abffbd..c6bf632f88820974405234a9665dda19b4e17353 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/FlutterRenderer.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/FlutterRenderer.ets @@ -62,10 +62,6 @@ export class FlutterRenderer implements TextureRegistry { return this.nextTextureId; } - setTextureBackGroundPixelMap(textureId: number, pixelMap: PixelMap): void { - this.flutterNapi.setTextureBackGroundPixelMap(textureId, pixelMap); - } - unregisterTexture(textureId: number): void { this.flutterNapi.unregisterTexture(textureId); } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/TextureRegistry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/TextureRegistry.ets index 8568b03568fc13477531b401252ac1464973c265..fa79eb238c0781f3f23b690e00d08101a0969830 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/TextureRegistry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/TextureRegistry.ets @@ -21,7 +21,6 @@ export interface TextureRegistry { registerTexture(textureId: number): SurfaceTextureEntry; registerSurfaceTexture(receiver: image.ImageReceiver): SurfaceTextureEntry; registerPixelMap(pixelMap: PixelMap): number; - setTextureBackGroundPixelMap(textureId: number, pixelMap: PixelMap): void; unregisterTexture(textureId: number): void; onTrimMemory(level: number) : void; } diff --git a/shell/platform/ohos/library_loader.cpp b/shell/platform/ohos/library_loader.cpp index c6289c3017aec01345d07e934c572a1814774483..653cbc76f033135c58eb7088cb581d2f67d72809 100644 --- a/shell/platform/ohos/library_loader.cpp +++ b/shell/platform/ohos/library_loader.cpp @@ -126,9 +126,6 @@ static napi_value Init(napi_env env, napi_value exports) { DECLARE_NAPI_FUNCTION( "nativeRegisterPixelMap", flutter::PlatformViewOHOSNapi::nativeRegisterPixelMap), - DECLARE_NAPI_FUNCTION( - "nativeSetTextureBackGroundPixelMap", - flutter::PlatformViewOHOSNapi::nativeSetTextureBackGroundPixelMap), }; diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index a3a3110cb0058c3af8301eb6e14a25b50ce8fbb7..2d0cc3adc67e7aa687c1eafb2cda120c3bdb010e 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -1529,23 +1529,6 @@ napi_value PlatformViewOHOSNapi::nativeRegisterPixelMap( return nullptr; } -napi_value PlatformViewOHOSNapi::nativeSetTextureBackGroundPixelMap( - napi_env env, - napi_callback_info info) -{ - FML_DLOG(INFO)<<"PlatformViewOHOSNapi::nativeSetTextureBackGroundPixelMap"; - size_t argc = 3; - napi_value args[3] = {nullptr}; - int64_t shell_holder; - int64_t textureId; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); - NAPI_CALL(env, napi_get_value_int64(env, args[0], &shell_holder)); - NAPI_CALL(env, napi_get_value_int64(env, args[1], &textureId)); - NativePixelMap *nativePixelMap = OH_PixelMap_InitNativePixelMap(env, args[2]); - OHOS_SHELL_HOLDER->GetPlatformView()->SetExternalTextureBackGroundPixelMap(textureId, nativePixelMap); - return nullptr; -} - void PlatformViewOHOSNapi::SurfaceCreated(int64_t shell_holder, void* window) { auto native_window = fml::MakeRefCounted( static_cast(window)); diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.h b/shell/platform/ohos/napi/platform_view_ohos_napi.h index 09d3424d9e08e0d65aae7bc51ead27b4ea34f542..b91367ae88f7442984bbe5db6e3fedfbb91401e6 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -171,10 +171,6 @@ class PlatformViewOHOSNapi { napi_env env, napi_callback_info info); - static napi_value nativeSetTextureBackGroundPixelMap( - napi_env env, - napi_callback_info info); - static napi_value nativeRegisterTexture( napi_env env, napi_callback_info info); diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index b508f735e3e8f10886900e219ebf9d76b2770949..aa9b14ca9a3c250fc54fe7d4377495a0cbbefc8f 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"; OHOSExternalTextureGL::OHOSExternalTextureGL(int64_t id, const std::shared_ptr& ohos_surface) : Texture(id), ohos_surface_(std::move(ohos_surface)), transform(SkMatrix::I()) { - state_ = AttachmentState::uninitialized; nativeImage_ = nullptr; backGroundNativeImage_ = nullptr; nativeWindow_ = nullptr; @@ -52,7 +51,6 @@ OHOSExternalTextureGL::OHOSExternalTextureGL(int64_t id, const std::shared_ptrGLContextMakeCurrent(); @@ -193,9 +170,6 @@ void OHOSExternalTextureGL::OnGrContextDestroyed() glDeleteTextures(1, &texture_name_); } state_ = AttachmentState::detached; - if (backGroundTextureName_ != 0) { - glDeleteTextures(1, &backGroundTextureName_); - } } void OHOSExternalTextureGL::MarkNewFrameAvailable() @@ -211,9 +185,6 @@ void OHOSExternalTextureGL::OnTextureUnregistered() first_update_ = false; OH_NativeImage_UnsetOnFrameAvailableListener(nativeImage_); OH_NativeImage_Destroy(&nativeImage_); - OH_NativeImage_Destroy(&backGroundNativeImage_); - nativeImage_ = nullptr; - backGroundNativeImage_ = nullptr; } void OHOSExternalTextureGL::Update() @@ -224,27 +195,19 @@ void OHOSExternalTextureGL::Update() return; } first_update_ = true; - UpdateTransform(nativeImage_); + UpdateTransform(); } void OHOSExternalTextureGL::Detach() { - if (state_ != AttachmentState::attached) { - FML_LOG(ERROR) << "OHOSExternalTextureGL::Detach "; - return; - } OH_NativeImage_DetachContext(nativeImage_); - OH_NativeImage_DetachContext(backGroundNativeImage_); OH_NativeWindow_DestroyNativeWindow(nativeWindow_); - OH_NativeWindow_DestroyNativeWindow(backGroundNativeWindow_); - nativeWindow_ = nullptr; - backGroundNativeWindow_ = nullptr; } -void OHOSExternalTextureGL::UpdateTransform(OH_NativeImage *image) +void OHOSExternalTextureGL::UpdateTransform() { float m[16] = { 0.0f }; - int32_t ret = OH_NativeImage_GetTransformMatrixV2(image, m); + int32_t ret = OH_NativeImage_GetTransformMatrixV2(nativeImage_, m); if (ret != 0) { FML_DLOG(FATAL)<<"OHOSExternalTextureGL OH_NativeImage_GetTransformMatrixV2 err code:"<< ret; } @@ -293,23 +256,10 @@ void OHOSExternalTextureGL::setBackground(int32_t width, int32_t height) return; } } - int32_t ret = OH_NativeImage_AttachContext(backGroundNativeImage_, backGroundTextureName_); - if (ret != 0) { - FML_DLOG(FATAL)<<"OHOSExternalTextureGL::setBackground OH_NativeImage_AttachContext err code:"<< ret; - } } else { FML_DLOG(FATAL)<<"ResourceContextMakeCurrent failed"; } - if (backGroundPixelMap_ != nullptr) { - ProducePixelMapToBackGroundImage(); - } else { - ProduceColorToBackGroundImage(width, height); - } -} -void OHOSExternalTextureGL::ProduceColorToBackGroundImage(int32_t width, int32_t height) -{ - FML_DLOG(INFO) << "OHOSExternalTextureGL::ProduceColorToBackGroundImage"; int code = SET_BUFFER_GEOMETRY; int32_t ret = OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, code, width, height); if (ret != 0) { @@ -333,7 +283,7 @@ void OHOSExternalTextureGL::ProduceColorToBackGroundImage(int32_t width, int32_t uint32_t* destAddr = static_cast(mappedAddr); uint32_t value = 0xFFFFFFFF; - for (int32_t x = 0; x < handle->width; x++) { + for(int32_t x = 0; x < handle->width; x++) { for (int32_t y = 0; y < handle->height; y++) { *destAddr++ = value; } @@ -354,76 +304,12 @@ void OHOSExternalTextureGL::ProduceColorToBackGroundImage(int32_t width, int32_t ret = OH_NativeImage_UpdateSurfaceImage(backGroundNativeImage_); if (ret != 0) { FML_DLOG(FATAL)<<"OHOSExternalTextureGL::setBackground OH_NativeImage_UpdateSurfaceImage err code:"<< ret; - return; - } -} - -void OHOSExternalTextureGL::ProducePixelMapToBackGroundImage() -{ - FML_DLOG(INFO) << "OHOSExternalTextureGL::ProducePixelMapToBackGroundImage"; - if (backGroundPixelMap_ == nullptr) { - FML_DLOG(INFO) << "backGroundPixelMap_ is nullptr"; - return; - } - int32_t ret = -1; - ret = OH_PixelMap_GetImageInfo(backGroundPixelMap_, &pixelMapInfo); - if (ret != 0) { - FML_DLOG(ERROR) - << "OHOSExternalTextureGL::ProducePixelMapToBackGroundImage " - "OH_PixelMap_GetImageInfo err:" - << ret; - return; - } - int code = SET_BUFFER_GEOMETRY; - ret = OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, code, pixelMapInfo.width, pixelMapInfo.height); - if (ret != 0) { - FML_DLOG(ERROR) - << "OHOSExternalTextureGL::ProducePixelMapToBackGroundImage " - "OH_NativeWindow_NativeWindowHandleOpt err:" - << ret; - return; - } - - int32_t usage = 0; - OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, GET_USAGE, &usage); - usage |= NATIVEBUFFER_USAGE_CPU_READ; - OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, SET_USAGE, usage); - - if (backGroundBuffer_ != nullptr) { - OH_NativeWindow_NativeWindowAbortBuffer(backGroundNativeWindow_, backGroundBuffer_); - backGroundBuffer_ = nullptr; - } - ret = OH_NativeWindow_NativeWindowRequestBuffer(backGroundNativeWindow_, &backGroundBuffer_, &backGroundFenceFd); - if (ret != 0) { - FML_DLOG(ERROR) - << "OHOSExternalTextureGL::ProducePixelMapToBackGroundImage " - "OH_NativeWindow_NativeWindowRequestBuffer err:" - << ret; - return; - } - HandlePixelMapBuffer(backGroundPixelMap_, backGroundBuffer_); - Region region{nullptr, 0}; - ret = OH_NativeWindow_NativeWindowFlushBuffer(backGroundNativeWindow_, backGroundBuffer_, backGroundFenceFd, region); - if (ret != 0) { - FML_DLOG(FATAL) - << "OHOSExternalTextureGL::ProducePixelMapToBackGroundImage " - "OH_NativeWindow_NativeWindowFlushBuffer err:" - << ret; } - ret = OH_NativeImage_UpdateSurfaceImage(backGroundNativeImage_); - if (ret != 0) { - FML_DLOG(FATAL) - << "OHOSExternalTextureGL::ProducePixelMapToBackGroundImage " - "OH_NativeImage_UpdateSurfaceImage err code:" - << ret; - return; - } - UpdateTransform(backGroundNativeImage_); } -void OHOSExternalTextureGL::HandlePixelMapBuffer(NativePixelMap* pixelMap, OHNativeWindowBuffer* buffer) +void OHOSExternalTextureGL::HandlePixelMapBuffer() { - BufferHandle *handle = OH_NativeWindow_GetBufferHandleFromNative(buffer); + BufferHandle *handle = OH_NativeWindow_GetBufferHandleFromNative(buffer_); // get virAddr of bufferHandl by mmap sys interface uint32_t stride = handle->stride; FML_DLOG(INFO) << "OHOSExternalTextureGL stride:" << stride; @@ -434,7 +320,7 @@ void OHOSExternalTextureGL::HandlePixelMapBuffer(NativePixelMap* pixelMap, OHNat } void *pixelAddr = nullptr; - int64_t ret = OH_PixelMap_AccessPixels(pixelMap, &pixelAddr); + int64_t ret = OH_PixelMap_AccessPixels(pixelMap_, &pixelAddr); if (ret != IMAGE_RESULT_SUCCESS) { FML_DLOG(FATAL)<<"OHOSExternalTextureGL OH_PixelMap_AccessPixels err:"<< ret; return; @@ -460,7 +346,7 @@ void OHOSExternalTextureGL::HandlePixelMapBuffer(NativePixelMap* pixelMap, OHNat pixel += pixelMapInfo.width; } } - OH_PixelMap_UnAccessPixels(pixelMap); + OH_PixelMap_UnAccessPixels(pixelMap_); // munmap after use ret = munmap(mappedAddr, handle->size); if (ret == -1) { @@ -475,10 +361,7 @@ void OHOSExternalTextureGL::ProducePixelMapToNativeImage() FML_DLOG(ERROR) << "OHOSExternalTextureGL AttachmentState err"; return; } - if (pixelMap_ == nullptr) { - FML_DLOG(ERROR) << "pixelMap_ is nullptr"; - return; - } + int32_t ret = -1; ret = OH_PixelMap_GetImageInfo(pixelMap_, &pixelMapInfo); if (ret != 0) { @@ -504,7 +387,7 @@ void OHOSExternalTextureGL::ProducePixelMapToNativeImage() if (ret != 0) { FML_DLOG(ERROR) << "OHOSExternalTextureGL OH_NativeWindow_NativeWindowRequestBuffer err:" << ret; } - HandlePixelMapBuffer(pixelMap_, buffer_); + HandlePixelMapBuffer(); Region region{nullptr, 0}; ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow_, buffer_, fenceFd, region); if (ret != 0) { @@ -559,11 +442,4 @@ void OHOSExternalTextureGL::DispatchPixelMap(NativePixelMap* pixelMap) } } -void OHOSExternalTextureGL::DispatchBackGroundPixelMap(NativePixelMap* pixelMap) -{ - if (pixelMap != nullptr) { - backGroundPixelMap_ = pixelMap; - } -} - } // 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 29d2e3eb9fb20a4aaaf54da90d992511ef7a3d80..39999f7ef0ddf036c65d8d938cc7d9e2ea536d04 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -65,8 +65,6 @@ class OHOSExternalTextureGL : public flutter::Texture { void DispatchPixelMap(NativePixelMap* pixelMap); - void DispatchBackGroundPixelMap(NativePixelMap* pixelMap); - private: void Attach(); @@ -74,20 +72,16 @@ class OHOSExternalTextureGL : public flutter::Texture { void Detach(); - void UpdateTransform(OH_NativeImage *image); + void UpdateTransform(); EGLDisplay GetPlatformEglDisplay(EGLenum platform, void *native_display, const EGLint *attrib_list); bool CheckEglExtension(const char *extensions, const char *extension); - void HandlePixelMapBuffer(NativePixelMap* pixelMap, OHNativeWindowBuffer* buffer); + void HandlePixelMapBuffer(); void ProducePixelMapToNativeImage(); - void ProduceColorToBackGroundImage(int32_t width, int32_t height); - - void ProducePixelMapToBackGroundImage(); - enum class AttachmentState { uninitialized, attached, detached }; AttachmentState state_; @@ -110,8 +104,6 @@ class OHOSExternalTextureGL : public flutter::Texture { OHNativeWindowBuffer *backGroundBuffer_; - NativePixelMap* backGroundPixelMap_; - NativePixelMap* pixelMap_; ImageNative* lastImage_; diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index fe4c393b2cd8af4306e7e64d2b44a3f00ef86d2a..a9d59218199ea2afbf9c9a26fc3205987df35bc7 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -473,7 +473,6 @@ uint64_t PlatformViewOHOS::RegisterExternalTexture(int64_t texture_id) FML_DLOG(ERROR) << "Error with OH_NativeImage_GetSurfaceId"; return surface_id; } - external_texture_gl_[texture_id] = ohos_external_gl; RegisterTexture(ohos_external_gl); } return surface_id; @@ -544,16 +543,6 @@ void PlatformViewOHOS::RegisterExternalTextureByPixelMap(int64_t texture_id, Nat } } -void PlatformViewOHOS::SetExternalTextureBackGroundPixelMap(int64_t texture_id, NativePixelMap* pixelMap) -{ - if (ohos_context_->RenderingApi() == OHOSRenderingAPI::kOpenGLES) { - auto iter = external_texture_gl_.find(texture_id); - if (iter != external_texture_gl_.end()) { - iter->second->DispatchBackGroundPixelMap(pixelMap); - } - } -} - void PlatformViewOHOS::OnTouchEvent(const std::shared_ptr touchPacketString, int size) { return napi_facade_->FlutterViewOnTouchEvent(touchPacketString, size); diff --git a/shell/platform/ohos/platform_view_ohos.h b/shell/platform/ohos/platform_view_ohos.h index cccbc048466eca73b9c5dd5ec496d5b7d36fb6fa..8d0c3ef6bef73364978426314aeb258818081c43 100644 --- a/shell/platform/ohos/platform_view_ohos.h +++ b/shell/platform/ohos/platform_view_ohos.h @@ -95,8 +95,6 @@ class PlatformViewOHOS final : public PlatformView { uint64_t RegisterExternalTexture(int64_t texture_id); void RegisterExternalTextureByPixelMap(int64_t texture_id, NativePixelMap* pixelMap); - - void SetExternalTextureBackGroundPixelMap(int64_t texture_id, NativePixelMap* pixelMap); void UnRegisterExternalTexture(int64_t texture_id);