From 05234b70aabdfd4717db3344f307c9ae6d20d35e Mon Sep 17 00:00:00 2001 From: liujiake Date: Sat, 15 Feb 2025 17:24:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E5=9B=BE=E7=89=87=E7=BA=B9?= =?UTF-8?q?=E7=90=86=E6=95=B0=E6=8D=AE=E6=97=B6=E5=88=A4=E6=96=AD=E7=BC=93?= =?UTF-8?q?=E5=86=B2=E5=8C=BA=E5=A4=A7=E5=B0=8F=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E6=BA=A2=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liujiake --- .../ohos/ohos_external_texture_gl.cpp | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index e369bd0689..d7916fb86c 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -676,6 +676,36 @@ void OHOSExternalTextureGL::ProducePixelMapToBackGroundImage() UpdateTransform(backGroundNativeImage_); } +void CopyPixelToHandle(uint32_t *destAddr, uint32_t *pixel, OhosPixelMapInfos pixelMapInfo, BufferHandle *handle) +{ + uint32_t real_height = pixelMapInfo.height; + if (IsPixelMapYUVFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat)) { + // y is height, uv is height/2 + real_height = pixelMapInfo.height + (pixelMapInfo.height + 1) / 2; + } + + // 复制图片纹理数据到内存中,需要处理DMA内存补齐相关的逻辑 + if (pixelMapInfo.width * PIXEL_SIZE != pixelMapInfo.rowSize) { + // 直接复制整块内存 + if ((real_height * pixelMapInfo.rowSize) > (uint32_t)handle->size) { + memcpy(destAddr, pixel, handle->size); + } else { + memcpy(destAddr, pixel, real_height * pixelMapInfo.rowSize); + } + } else { + // 需要处理DMA内存补齐相关的逻辑 + for (uint32_t i = 0; i < real_height; i++) { + if (pixelMapInfo.rowSize > (uint32_t)handle->stride) { + memcpy(destAddr, pixel, handle->stride); + } else { + memcpy(destAddr, pixel, pixelMapInfo.rowSize); + } + destAddr += handle->stride / PIXEL_SIZE; + pixel += pixelMapInfo.width; + } + } +} + void OHOSExternalTextureGL::HandlePixelMapBuffer(NativePixelMap* pixelMap, OHNativeWindowBuffer* buffer) { BufferHandle *handle = OH_NativeWindow_GetBufferHandleFromNative(buffer); @@ -707,24 +737,8 @@ 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 - real_height = pixelMapInfo.height + (pixelMapInfo.height + 1) / 2; - } + CopyPixelToHandle(destAddr, pixel, pixelMapInfo, handle); - // 复制图片纹理数据到内存中,需要处理DMA内存补齐相关的逻辑 - if (pixelMapInfo.width * PIXEL_SIZE != pixelMapInfo.rowSize) { - // 直接复制整块内存 - memcpy(destAddr, pixel, real_height * pixelMapInfo.rowSize); - } else { - // 需要处理DMA内存补齐相关的逻辑 - for (uint32_t i = 0; i < real_height; i++) { - memcpy(destAddr, pixel, pixelMapInfo.rowSize); - destAddr += stride / PIXEL_SIZE; - pixel += pixelMapInfo.width; - } - } OH_PixelMap_UnAccessPixels(pixelMap); // munmap after use ret = munmap(mappedAddr, handle->size); -- Gitee