From 2e544f7512ba409d534dda7a18122b21002baf41 Mon Sep 17 00:00:00 2001 From: MTChannn Date: Tue, 31 Dec 2024 15:17:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Flutter=E5=A4=96=E6=8E=A5?= =?UTF-8?q?=E7=BA=B9=E7=90=86=E7=AC=AC=E4=B8=80=E5=B8=A7=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E8=89=B2=E8=87=AA=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MTChannn --- .../src/main/cpp/types/libflutter/index.d.ets | 2 ++ .../main/ets/embedding/engine/FlutterNapi.ets | 5 +++++ .../engine/renderer/FlutterRenderer.ets | 4 ++++ .../src/main/ets/view/TextureRegistry.ets | 1 + shell/platform/ohos/library_loader.cpp | 3 +++ .../ohos/napi/platform_view_ohos_napi.cpp | 18 ++++++++++++++++++ .../ohos/napi/platform_view_ohos_napi.h | 3 +++ .../platform/ohos/ohos_external_texture_gl.cpp | 8 ++++++-- shell/platform/ohos/ohos_external_texture_gl.h | 4 ++++ shell/platform/ohos/platform_view_ohos.cpp | 11 +++++++++++ shell/platform/ohos/platform_view_ohos.h | 2 ++ 11 files changed, 59 insertions(+), 2 deletions(-) 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 279c97baa1..7b9ed9c76f 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 @@ -133,6 +133,8 @@ export const nativeRegisterPixelMap: (nativeShellHolderId: number, textureId: nu export const nativeSetTextureBackGroundPixelMap: (nativeShellHolderId: number, textureId: number, pixelMap: PixelMap) => void; +export const nativeSetTextureBackGroundColor: (nativeShellHolderId: number, textureId: number, color: number) => void; + export const nativeRegisterTexture: (nativeShellHolderId: number, textureId: number) => number; export const nativeEncodeUtf8: (str: string) => Uint8Array; 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 e36a566682..343ae880f0 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 @@ -497,6 +497,11 @@ export default class FlutterNapi { flutter.nativeSetTextureBackGroundPixelMap(this.nativeShellHolderId!, textureId, pixelMap); } + setTextureBackGroundColor(textureId: number, color: number): void { + Log.d(TAG, "called setTextureBackGroundColor "); + flutter.nativeSetTextureBackGroundColor(this.nativeShellHolderId!, textureId, color); + } + 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 9d00c43494..15c23fd171 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 @@ -66,6 +66,10 @@ export class FlutterRenderer implements TextureRegistry { this.flutterNapi.setTextureBackGroundPixelMap(textureId, pixelMap); } + setTextureBackGroundColor(textureId: number, color: number): void { + this.flutterNapi.setTextureBackGroundColor(textureId, color); + } + setTextureBufferSize(textureId: number, width: number, height: number): void { this.flutterNapi.setTextureBufferSize(textureId, width, height); } 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 6ba421adf6..760eb28b98 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 @@ -22,6 +22,7 @@ export interface TextureRegistry { registerSurfaceTexture(receiver: image.ImageReceiver): SurfaceTextureEntry; registerPixelMap(pixelMap: PixelMap): number; setTextureBackGroundPixelMap(textureId: number, pixelMap: PixelMap): void; + setTextureBackGroundColor(textureId: number, color: number): void; setTextureBufferSize(textureId: number, width: number, height: number): 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 7b2c7da1c0..4772fa02ef 100644 --- a/shell/platform/ohos/library_loader.cpp +++ b/shell/platform/ohos/library_loader.cpp @@ -132,6 +132,9 @@ static napi_value Init(napi_env env, napi_value exports) { DECLARE_NAPI_FUNCTION( "nativeSetTextureBackGroundPixelMap", flutter::PlatformViewOHOSNapi::nativeSetTextureBackGroundPixelMap), + DECLARE_NAPI_FUNCTION( + "nativeSetTextureBackGroundColor", + flutter::PlatformViewOHOSNapi::nativeSetTextureBackGroundColor), DECLARE_NAPI_FUNCTION("nativeEncodeUtf8", flutter::PlatformViewOHOSNapi::nativeEncodeUtf8), DECLARE_NAPI_FUNCTION("nativeDecodeUtf8", diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 33535deff8..121f9e03c2 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -1584,6 +1584,24 @@ napi_value PlatformViewOHOSNapi::nativeSetTextureBackGroundPixelMap( return nullptr; } +napi_value PlatformViewOHOSNapi::nativeSetTextureBackGroundColor( + napi_env env, + napi_callback_info info) { + FML_DLOG(INFO) << "PlatformViewOHOSNapi::nativeSetTextureBackGroundColor"; + size_t argc = 3; + napi_value args[3] = {nullptr}; + int64_t shell_holder; + int64_t textureId; + uint32_t color; + 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)); + NAPI_CALL(env, napi_get_value_uint32(env, args[2], &color)); + OHOS_SHELL_HOLDER->GetPlatformView()->SetExternalTextureBackGroundColor( + textureId, color); + 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 013557aeae..32af05f329 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -184,6 +184,9 @@ class PlatformViewOHOSNapi { static napi_value nativeSetTextureBackGroundPixelMap(napi_env env, napi_callback_info info); + static napi_value nativeSetTextureBackGroundColor(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 e8a941fe84..b3c52bdcea 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -39,7 +39,6 @@ constexpr const char *CHARACTER_STRING_WHITESPACE = " "; constexpr const char *EGL_EXT_PLATFORM_WAYLAND = "EGL_EXT_platform_wayland"; constexpr const char *EGL_KHR_PLATFORM_WAYLAND = "EGL_KHR_platform_wayland"; 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}; @@ -601,7 +600,7 @@ void OHOSExternalTextureGL::ProduceColorToBackGroundImage(int32_t width, int32_t uint32_t* destAddr = static_cast(mappedAddr); for (int32_t x = 0; x < handle->size / PIXEL_SIZE; x++) { - *destAddr++ = WHITE_COLOR; + *destAddr++ = backGroundColor_; } // munmap after use @@ -848,4 +847,9 @@ void OHOSExternalTextureGL::DispatchBackGroundPixelMap(NativePixelMap* pixelMap) } } +void OHOSExternalTextureGL::DispatchBackGroundColor(uint32_t color) +{ + backGroundColor_ = color; +} + } // 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 113aeb5296..8027094688 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -80,6 +80,8 @@ class OHOSExternalTextureGL : public flutter::Texture, public std::enable_shared void DispatchBackGroundPixelMap(NativePixelMap* pixelMap); + void DispatchBackGroundColor(uint32_t color); + private: void Attach(); @@ -123,6 +125,8 @@ class OHOSExternalTextureGL : public flutter::Texture, public std::enable_shared NativePixelMap* backGroundPixelMap_; + uint32_t backGroundColor_ = 0xFFFFFFFF; // white color + NativePixelMap* pixelMap_; ImageNative* lastImage_; diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index 2ba37590a3..25cbfd946d 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -525,6 +525,17 @@ void PlatformViewOHOS::SetExternalTextureBackGroundPixelMap( } } +void PlatformViewOHOS::SetExternalTextureBackGroundColor( + int64_t texture_id, + uint32_t color) { + if (ohos_context_->RenderingApi() == OHOSRenderingAPI::kOpenGLES) { + auto iter = external_texture_gl_.find(texture_id); + if (iter != external_texture_gl_.end()) { + iter->second->DispatchBackGroundColor(color); + } + } +} + void PlatformViewOHOS::OnTouchEvent( const std::shared_ptr touchPacketString, int size) { diff --git a/shell/platform/ohos/platform_view_ohos.h b/shell/platform/ohos/platform_view_ohos.h index c6dd57ccfb..031bed7522 100644 --- a/shell/platform/ohos/platform_view_ohos.h +++ b/shell/platform/ohos/platform_view_ohos.h @@ -109,6 +109,8 @@ class PlatformViewOHOS final : public PlatformView { void SetExternalTextureBackGroundPixelMap(int64_t texture_id, NativePixelMap* pixelMap); + void SetExternalTextureBackGroundColor(int64_t texture_id, uint32_t color); + void UnRegisterExternalTexture(int64_t texture_id); // |PlatformView| -- Gitee