diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index fda7cae8a09d23be4530818ccf48a889a7563cf3..374e63a1d047864b76ca75a46326e28bfb86869d 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -26,6 +26,7 @@ #include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrDirectContext.h" +#include "types.h" #define EGL_PLATFORM_OHOS_KHR 0x34E0 @@ -77,16 +78,19 @@ static bool IsPixelMapYUVFormat(PIXEL_FORMAT format) format == PIXEL_FORMAT_YCBCR_P010 || format == PIXEL_FORMAT_YCRCB_P010; } - -OHOSExternalTextureGL::OHOSExternalTextureGL(int64_t id, const std::shared_ptr& ohos_surface) - : Texture(id), ohos_surface_(std::move(ohos_surface)), transform(SkMatrix::I()) +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; backGroundNativeWindow_ = nullptr; - eglContext_ = EGL_NO_CONTEXT; + eglContext_ = EGL_NO_CONTEXT; eglDisplay_ = EGL_NO_DISPLAY; buffer_ = nullptr; backGroundBuffer_ = nullptr; @@ -178,8 +182,9 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, } GrBackendTexture backendTexture(1, 1, GrMipMapped::kNo, textureInfo); + GrSurfaceOrigin grOrigin = isEmulator_ ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; sk_sp image = SkImage::MakeFromTexture( - context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin, + context.gr_context, backendTexture, grOrigin, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); if (image) { SkAutoCanvasRestore autoRestore(context.canvas, true); @@ -188,13 +193,8 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, // back. OpenGL's coordinate system has Positive Y equivalent to up, while // Skia's coordinate system has Negative Y equvalent to up. // 模拟器和真机在外接纹理功能的表现不一致,需要进行适配 - if (isEmulator_) { - context.canvas->translate(bounds.x(), bounds.y()); - context.canvas->scale(bounds.width(), bounds.height()); - } else { - context.canvas->translate(bounds.x(), bounds.y() + bounds.height()); - context.canvas->scale(bounds.width(), -bounds.height()); - } + context.canvas->translate(bounds.x(), bounds.y() + bounds.height()); + context.canvas->scale(bounds.width(), -bounds.height()); if (!transform.isIdentity()) { sk_sp shader = image->makeShader( @@ -410,6 +410,11 @@ void OHOSExternalTextureGL::ProduceColorToBackGroundImage(int32_t width, int32_t return; } + uint64_t usage = 0; + OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, GET_USAGE, &usage); + usage |= NATIVEBUFFER_USAGE_CPU_READ | (BUFFER_USAGE_HW_COMPOSER); + OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, SET_USAGE, usage); + ret = OH_NativeWindow_NativeWindowRequestBuffer(backGroundNativeWindow_, &backGroundBuffer_, &backGroundFenceFd); if (ret != 0) { FML_LOG(ERROR) << "OHOSExternalTextureGL::setBackground OH_NativeWindow_NativeWindowRequestBuffer err:" << ret; @@ -479,7 +484,7 @@ void OHOSExternalTextureGL::ProducePixelMapToBackGroundImage() uint64_t usage = 0; OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, GET_USAGE, &usage); - usage |= NATIVEBUFFER_USAGE_CPU_READ; + usage |= NATIVEBUFFER_USAGE_CPU_READ | (BUFFER_USAGE_HW_COMPOSER); OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, SET_USAGE, usage); if (backGroundBuffer_ != nullptr) { @@ -605,7 +610,7 @@ void OHOSExternalTextureGL::ProducePixelMapToNativeImage() uint64_t usage = 0; OH_NativeWindow_NativeWindowHandleOpt(nativeWindow_, GET_USAGE, &usage); - usage |= NATIVEBUFFER_USAGE_CPU_READ; + usage |= NATIVEBUFFER_USAGE_CPU_READ | (BUFFER_USAGE_HW_COMPOSER); OH_NativeWindow_NativeWindowHandleOpt(nativeWindow_, SET_USAGE, usage); if (buffer_ != nullptr) { diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index ce9b10f61d4301818eca106aa4f50d0fa9905e5c..1770ab6c46b87071fe7fe6f14af4f1cfd655d4f3 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -117,51 +117,15 @@ void XComponentAdapter::OnMouseWheel(std::string& id, mouseWheelEvent event) } #include -using OHOS_SurfaceBufferUsage = enum { - BUFFER_USAGE_CPU_READ = (1ULL << 0), /**< CPU read buffer */ - BUFFER_USAGE_CPU_WRITE = (1ULL << 1), /**< CPU write memory */ - BUFFER_USAGE_MEM_MMZ = (1ULL << 2), /**< Media memory zone (MMZ) */ - BUFFER_USAGE_MEM_DMA = (1ULL << 3), /**< Direct memory access (DMA) buffer */ - BUFFER_USAGE_MEM_SHARE = (1ULL << 4), /**< Shared memory buffer*/ - BUFFER_USAGE_MEM_MMZ_CACHE = (1ULL << 5), /**< MMZ with cache*/ - BUFFER_USAGE_MEM_FB = (1ULL << 6), /**< Framebuffer */ - BUFFER_USAGE_ASSIGN_SIZE = (1ULL << 7), /**< Memory assigned */ - BUFFER_USAGE_HW_RENDER = (1ULL << 8), /**< For GPU write case */ - BUFFER_USAGE_HW_TEXTURE = (1ULL << 9), /**< For GPU read case */ - BUFFER_USAGE_HW_COMPOSER = (1ULL << 10), /**< For hardware composer */ - BUFFER_USAGE_PROTECTED = - (1ULL << 11), /**< For safe buffer case, such as DRM */ - BUFFER_USAGE_CAMERA_READ = (1ULL << 12), /**< For camera read case */ - BUFFER_USAGE_CAMERA_WRITE = (1ULL << 13), /**< For camera write case */ - BUFFER_USAGE_VIDEO_ENCODER = (1ULL << 14), /**< For encode case */ - BUFFER_USAGE_VIDEO_DECODER = (1ULL << 15), /**< For decode case */ - BUFFER_USAGE_VENDOR_PRI0 = (1ULL << 44), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI1 = (1ULL << 45), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI2 = (1ULL << 46), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI3 = (1ULL << 47), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI4 = (1ULL << 48), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI5 = (1ULL << 49), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI6 = (1ULL << 50), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI7 = (1ULL << 51), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI8 = (1ULL << 52), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI9 = (1ULL << 53), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI10 = (1ULL << 54), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI11 = (1ULL << 55), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI12 = (1ULL << 56), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI13 = (1ULL << 57), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI14 = (1ULL << 58), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI15 = (1ULL << 59), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI16 = (1ULL << 60), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI17 = (1ULL << 61), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI18 = (1ULL << 62), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI19 = (1ULL << 63), /**< Reserverd for vendor */ -}; + static int32_t SetNativeWindowOpt(OHNativeWindow* nativeWindow, int32_t width, int height) { // Set the read and write scenarios of the native window buffer. - int code = SET_USAGE; - int32_t ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, BUFFER_USAGE_MEM_DMA); + uint64_t usage = 0; + int ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_USAGE, &usage); + usage |= BUFFER_USAGE_MEM_DMA | (BUFFER_USAGE_HW_COMPOSER); + ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_USAGE, usage); if (ret) { LOGE( "Set NativeWindow Usage Failed :window:%{public}p ,w:%{public}d x " @@ -169,7 +133,7 @@ static int32_t SetNativeWindowOpt(OHNativeWindow* nativeWindow, nativeWindow, width, height, ret); } // Set the width and height of the native window buffer. - code = SET_BUFFER_GEOMETRY; + int code = SET_BUFFER_GEOMETRY; ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, width, height); if (ret) { diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index bad544f3f89e7b26751c3a892b4ce1b2c1c483f2..956e8c03a9e4e93c964669e9bfd6c1740c5147d0 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -434,7 +434,7 @@ void PlatformViewOHOS::RegisterExternalTextureByImage( iter->second->DispatchImage(image); } else { std::shared_ptr ohos_external_gl = - std::make_shared(texture_id, ohos_surface_); + std::make_shared(texture_id, ohos_surface_); external_texture_gl_[texture_id] = ohos_external_gl; RegisterTexture(ohos_external_gl); ohos_external_gl->DispatchImage(image); @@ -454,7 +454,7 @@ uint64_t PlatformViewOHOS::RegisterExternalTexture(int64_t texture_id) int ret = -1; if (ohos_context_->RenderingApi() == OHOSRenderingAPI::kOpenGLES) { std::shared_ptr ohos_external_gl = - std::make_shared(texture_id, ohos_surface_); + std::make_shared(texture_id, ohos_surface_); ohos_external_gl->nativeImage_ = OH_NativeImage_Create(texture_id, GL_TEXTURE_EXTERNAL_OES); if (ohos_external_gl->nativeImage_ == nullptr) { FML_DLOG(ERROR) << "Error with OH_NativeImage_Create"; diff --git a/shell/platform/ohos/types.h b/shell/platform/ohos/types.h index 9be037096beb0ab63c0aeacae7d04ff0dd1ba6cd..69fa5fd484d54e9d6e878aaaa56ae7c9ee86f0cd 100644 --- a/shell/platform/ohos/types.h +++ b/shell/platform/ohos/types.h @@ -24,5 +24,45 @@ enum Locales { SCRIPT_INDEX, }; +using OHOS_SurfaceBufferUsage = enum { + BUFFER_USAGE_CPU_READ = (1ULL << 0), /**< CPU read buffer */ + BUFFER_USAGE_CPU_WRITE = (1ULL << 1), /**< CPU write memory */ + BUFFER_USAGE_MEM_MMZ = (1ULL << 2), /**< Media memory zone (MMZ) */ + BUFFER_USAGE_MEM_DMA = (1ULL << 3), /**< Direct memory access (DMA) buffer */ + BUFFER_USAGE_MEM_SHARE = (1ULL << 4), /**< Shared memory buffer*/ + BUFFER_USAGE_MEM_MMZ_CACHE = (1ULL << 5), /**< MMZ with cache*/ + BUFFER_USAGE_MEM_FB = (1ULL << 6), /**< Framebuffer */ + BUFFER_USAGE_ASSIGN_SIZE = (1ULL << 7), /**< Memory assigned */ + BUFFER_USAGE_HW_RENDER = (1ULL << 8), /**< For GPU write case */ + BUFFER_USAGE_HW_TEXTURE = (1ULL << 9), /**< For GPU read case */ + BUFFER_USAGE_HW_COMPOSER = (1ULL << 10), /**< For hardware composer */ + BUFFER_USAGE_PROTECTED = + (1ULL << 11), /**< For safe buffer case, such as DRM */ + BUFFER_USAGE_CAMERA_READ = (1ULL << 12), /**< For camera read case */ + BUFFER_USAGE_CAMERA_WRITE = (1ULL << 13), /**< For camera write case */ + BUFFER_USAGE_VIDEO_ENCODER = (1ULL << 14), /**< For encode case */ + BUFFER_USAGE_VIDEO_DECODER = (1ULL << 15), /**< For decode case */ + BUFFER_USAGE_VENDOR_PRI0 = (1ULL << 44), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI1 = (1ULL << 45), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI2 = (1ULL << 46), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI3 = (1ULL << 47), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI4 = (1ULL << 48), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI5 = (1ULL << 49), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI6 = (1ULL << 50), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI7 = (1ULL << 51), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI8 = (1ULL << 52), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI9 = (1ULL << 53), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI10 = (1ULL << 54), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI11 = (1ULL << 55), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI12 = (1ULL << 56), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI13 = (1ULL << 57), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI14 = (1ULL << 58), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI15 = (1ULL << 59), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI16 = (1ULL << 60), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI17 = (1ULL << 61), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI18 = (1ULL << 62), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI19 = (1ULL << 63), /**< Reserverd for vendor */ +}; + } // namespace flutter #endif \ No newline at end of file