From 89b5494a05189e6f10183224b8ebaa34b7b48f89 Mon Sep 17 00:00:00 2001 From: wwyang <137208408@qq.com> Date: Wed, 9 Oct 2024 11:43:09 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3YUV10bit=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E7=BC=A9=E7=95=A5=E5=9B=BE=E8=8A=B1=E5=B1=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwyang <137208408@qq.com> --- .../ohos/ohos_external_texture_gl.cpp | 53 ++++++++++++++++++- .../platform/ohos/ohos_external_texture_gl.h | 1 + 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 59887d8d3d..966afa007a 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -39,6 +39,42 @@ 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"; +static int PixelMapToWindowFormat(PIXEL_FORMAT pixel_format) { + switch (pixel_format) { + case PIXEL_FORMAT_RGB_565: + return NATIVEBUFFER_PIXEL_FMT_RGB_565; + case PIXEL_FORMAT_RGBA_8888: + return NATIVEBUFFER_PIXEL_FMT_RGBA_8888; + case PIXEL_FORMAT_BGRA_8888: + return NATIVEBUFFER_PIXEL_FMT_BGRA_8888; + case PIXEL_FORMAT_RGB_888: + return NATIVEBUFFER_PIXEL_FMT_RGB_888; + case PIXEL_FORMAT_NV21: + return NATIVEBUFFER_PIXEL_FMT_YCRCB_420_SP; + case PIXEL_FORMAT_NV12: + return NATIVEBUFFER_PIXEL_FMT_YCBCR_420_SP; + case PIXEL_FORMAT_RGBA_1010102: + return NATIVEBUFFER_PIXEL_FMT_RGBA_1010102; + case PIXEL_FORMAT_YCBCR_P010: + return NATIVEBUFFER_PIXEL_FMT_YCBCR_P010; + case PIXEL_FORMAT_YCRCB_P010: + return NATIVEBUFFER_PIXEL_FMT_YCRCB_P010; + case PIXEL_FORMAT_ALPHA_8: + case PIXEL_FORMAT_RGBA_F16: + case PIXEL_FORMAT_UNKNOWN: + default: + // no support/unknow format: cannot copy + return 0; + } + return 0; +} + +static bool IsPixelMapYUVFormat(PIXEL_FORMAT format) { + return format == PIXEL_FORMAT_NV21 || format == PIXEL_FORMAT_NV12 || + 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()) { @@ -410,6 +446,10 @@ void OHOSExternalTextureGL::ProducePixelMapToBackGroundImage() << ret; return; } + + int window_format = PixelMapToWindowFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat); + ret = OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, SET_FORMAT, window_format); + uint64_t usage = 0; OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, GET_USAGE, &usage); usage |= NATIVEBUFFER_USAGE_CPU_READ; @@ -478,13 +518,22 @@ void OHOSExternalTextureGL::HandlePixelMapBuffer(NativePixelMap* pixelMap, OHNat FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo rowSize:" << pixelMapInfo.rowSize << " format:" << pixelMapInfo.pixelFormat; + FML_LOG(ERROR)<<"OHOSExternalTextureGL IsPixelMapYUVFormat 0"; + + uint32_t real_height = pixelMapInfo.height; + if (IsPixelMapYUVFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat)) { + FML_LOG(ERROR)<<"OHOSExternalTextureGL IsPixelMapYUVFormat 1"; + // y is height, uv is height/2 + real_height = pixelMapInfo.height + (pixelMapInfo.height + 1) / 2; + } + // 复制图片纹理数据到内存中,需要处理DMA内存补齐相关的逻辑 if (pixelMapInfo.width * PIXEL_SIZE != pixelMapInfo.rowSize) { // 直接复制整块内存 - memcpy(destAddr, pixel, pixelMapInfo.height * pixelMapInfo.rowSize); + memcpy(destAddr, pixel, real_height * pixelMapInfo.rowSize); } else { // 需要处理DMA内存补齐相关的逻辑 - for (uint32_t i = 0; i < pixelMapInfo.height; i++) { + for (uint32_t i = 0; i < real_height; i++) { memcpy(destAddr, pixel, pixelMapInfo.rowSize); destAddr += stride / PIXEL_SIZE; pixel += pixelMapInfo.width; diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index 5ac18743a6..2458ac9c54 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include -- Gitee From 388d241eea692a83e22556d41f81ef7491a61375 Mon Sep 17 00:00:00 2001 From: wwyang <137208408@qq.com> Date: Wed, 9 Oct 2024 11:47:03 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3YUV10bit=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E7=BC=A9=E7=95=A5=E5=9B=BE=E8=8A=B1=E5=B1=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwyang <137208408@qq.com> --- shell/platform/ohos/ohos_external_texture_gl.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 966afa007a..ac9f116b78 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -518,11 +518,9 @@ void OHOSExternalTextureGL::HandlePixelMapBuffer(NativePixelMap* pixelMap, OHNat FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo rowSize:" << pixelMapInfo.rowSize << " format:" << pixelMapInfo.pixelFormat; - FML_LOG(ERROR)<<"OHOSExternalTextureGL IsPixelMapYUVFormat 0"; uint32_t real_height = pixelMapInfo.height; if (IsPixelMapYUVFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat)) { - FML_LOG(ERROR)<<"OHOSExternalTextureGL IsPixelMapYUVFormat 1"; // y is height, uv is height/2 real_height = pixelMapInfo.height + (pixelMapInfo.height + 1) / 2; } -- Gitee From 3f7f42b91ca42d9ba4fd3c35fd0e1f60b9f2d10e Mon Sep 17 00:00:00 2001 From: wwyang <137208408@qq.com> Date: Wed, 9 Oct 2024 16:52:40 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E9=97=A8=E7=A6=81=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwyang <137208408@qq.com> --- shell/platform/ohos/ohos_external_texture_gl.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index ac9f116b78..05c8449bf5 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -39,7 +39,8 @@ 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"; -static int PixelMapToWindowFormat(PIXEL_FORMAT pixel_format) { +static int PixelMapToWindowFormat(PIXEL_FORMAT pixel_format) +{ switch (pixel_format) { case PIXEL_FORMAT_RGB_565: return NATIVEBUFFER_PIXEL_FMT_RGB_565; @@ -69,7 +70,8 @@ static int PixelMapToWindowFormat(PIXEL_FORMAT pixel_format) { return 0; } -static bool IsPixelMapYUVFormat(PIXEL_FORMAT format) { +static bool IsPixelMapYUVFormat(PIXEL_FORMAT format) +{ return format == PIXEL_FORMAT_NV21 || format == PIXEL_FORMAT_NV12 || format == PIXEL_FORMAT_YCBCR_P010 || format == PIXEL_FORMAT_YCRCB_P010; } @@ -447,8 +449,8 @@ void OHOSExternalTextureGL::ProducePixelMapToBackGroundImage() return; } - int window_format = PixelMapToWindowFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat); - ret = OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, SET_FORMAT, window_format); + int windowFormat = PixelMapToWindowFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat); + ret = OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, SET_FORMAT, windowFormat); uint64_t usage = 0; OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, GET_USAGE, &usage); @@ -518,7 +520,6 @@ void OHOSExternalTextureGL::HandlePixelMapBuffer(NativePixelMap* pixelMap, OHNat FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo rowSize:" << pixelMapInfo.rowSize << " format:" << pixelMapInfo.pixelFormat; - uint32_t real_height = pixelMapInfo.height; if (IsPixelMapYUVFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat)) { // y is height, uv is height/2 -- Gitee