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 279c97baa1ad512f3fa9f31e28a4050901c05468..7b9ed9c76f0afd4282addd8d19f3fa0b17d33014 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 e36a5666822d8dfde8b31ffe32e10d7ac7b3729a..343ae880f052551691727291f91bf310b04db476 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 9d00c43494d9784aadd88ee16b3f41ae561054f8..15c23fd1716a15d4171eb98c8212f0dbd83943e5 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 6ba421adf64bc2d3dfacc1ed9f2814a97e432d7b..760eb28b98ccc3e9ffcfbca843b0da5ec7ea8d37 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 7b2c7da1c04a7232d100042ab23a770b07400797..4772fa02ef7fc3398c53c22dce49083bb18dcece 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 33535deff89e02f51bc200fa02353bdaa95586e0..121f9e03c28929ec98c4be713982b78a53521f44 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 013557aeae1f5e6755b59a19826fd91da5cf22ea..32af05f3294ece44146616c08dad7c775778da33 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 e8a941fe8408f598edb05336c12b27517cd8530a..b3c52bdceaa4ecc16b7cc3904f326e1c8a479a3b 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 113aeb52968852bb2066d01174413bd424d29a6b..8027094688493811e346847db0419f7331103c5f 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 2ba37590a3c446987780e057a660fcdd80c863a8..25cbfd946d98d0dc75785cb40c2903b1f870ef33 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 c6dd57ccfb4241e6d16a568f0f2c08d3c2e1a81a..031bed75227569cf4aef35605e82f559ea5b4d3c 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|