From 920b2693bbc012ebf9e61df751e36de89a9bbb87 Mon Sep 17 00:00:00 2001 From: Klaus_q Date: Fri, 26 Apr 2024 09:08:21 +0800 Subject: [PATCH] bugfix for redraw colorType Signed-off-by: Klaus_q Change-Id: If9b42a9541cd5d8c093fbba192f3647d7fe23be7 --- .../src/pixel_map_from_surface.cpp | 3 +- .../core/pipeline/rs_base_render_engine.cpp | 20 ++------- .../core/pipeline/rs_base_render_util.cpp | 43 ++++++++++++++----- .../core/pipeline/rs_base_render_util.h | 2 + .../core/pipeline/rs_hardware_thread.cpp | 37 +++------------- 5 files changed, 45 insertions(+), 60 deletions(-) diff --git a/rosen/modules/create_pixelmap_surface/src/pixel_map_from_surface.cpp b/rosen/modules/create_pixelmap_surface/src/pixel_map_from_surface.cpp index c95114517c..689fd6892d 100644 --- a/rosen/modules/create_pixelmap_surface/src/pixel_map_from_surface.cpp +++ b/rosen/modules/create_pixelmap_surface/src/pixel_map_from_surface.cpp @@ -544,7 +544,8 @@ bool PixelMapFromSurface::DrawImage(GrRecordingContext *context, int bufferHeight = surfaceBuffer_->GetHeight(); if (pixelFormat == GRAPHIC_PIXEL_FMT_BGRA_8888) { colorType = kBGRA_8888_SkColorType; - } else if (pixelFormat == GRAPHIC_PIXEL_FMT_YCBCR_P010 || pixelFormat == GRAPHIC_PIXEL_FMT_YCRCB_P010) { + } else if (pixelFormat == GRAPHIC_PIXEL_FMT_YCBCR_P010 || pixelFormat == GRAPHIC_PIXEL_FMT_YCRCB_P010 || + pixelFormat == GRAPHIC_PIXEL_FMT_RGBA_1010102) { colorType = kRGBA_1010102_SkColorType; glType = GL_RGB10_A2; } diff --git a/rosen/modules/render_service/core/pipeline/rs_base_render_engine.cpp b/rosen/modules/render_service/core/pipeline/rs_base_render_engine.cpp index bce768aec4..43f3097282 100644 --- a/rosen/modules/render_service/core/pipeline/rs_base_render_engine.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_base_render_engine.cpp @@ -223,14 +223,8 @@ std::shared_ptr RSBaseRenderEngine::CreateEglImageFromBuffer(RSP #else (void)colorGamut; #endif - Drawing::ColorType colorType = Drawing::ColorType::COLORTYPE_RGBA_8888; auto pixelFmt = buffer->GetFormat(); - if (pixelFmt == GRAPHIC_PIXEL_FMT_BGRA_8888) { - colorType = Drawing::ColorType::COLORTYPE_BGRA_8888; - } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCBCR_P010 || pixelFmt == GRAPHIC_PIXEL_FMT_YCRCB_P010) { - colorType = Drawing::ColorType::COLORTYPE_RGBA_1010102; - } - Drawing::BitmapFormat bitmapFormat = { colorType, Drawing::AlphaType::ALPHATYPE_PREMUL }; + auto bitmapFormat = RSBaseRenderUtil::GenerateDrawingBitmapFormat(buffer); auto image = std::make_shared(); Drawing::TextureInfo externalTextureInfo; @@ -251,7 +245,8 @@ std::shared_ptr RSBaseRenderEngine::CreateEglImageFromBuffer(RSP auto glType = GR_GL_RGBA8; if (pixelFmt == GRAPHIC_PIXEL_FMT_BGRA_8888) { glType = GR_GL_BGRA8; - } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCBCR_P010 || pixelFmt == GRAPHIC_PIXEL_FMT_YCRCB_P010) { + } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCBCR_P010 || pixelFmt == GRAPHIC_PIXEL_FMT_YCRCB_P010 || + pixelFmt == GRAPHIC_PIXEL_FMT_RGBA_1010102) { glType = GR_GL_RGB10_A2; } externalTextureInfo.SetFormat(glType); @@ -663,14 +658,7 @@ void RSBaseRenderEngine::DrawImage(RSPaintFilterCanvas& canvas, BufferDrawParam& #endif Drawing::ColorType drawingColorType = Drawing::ColorType::COLORTYPE_RGBA_8888; auto pixelFmt = params.buffer->GetFormat(); - if (pixelFmt == GRAPHIC_PIXEL_FMT_BGRA_8888) { - drawingColorType = Drawing::ColorType::COLORTYPE_BGRA_8888; - } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCBCR_P010 || pixelFmt == GRAPHIC_PIXEL_FMT_YCRCB_P010) { - drawingColorType = Drawing::ColorType::COLORTYPE_RGBA_1010102; - } else if (pixelFmt == GRAPHIC_PIXEL_FMT_RGB_565) { - drawingColorType = Drawing::ColorType::COLORTYPE_RGB_565; - } - Drawing::BitmapFormat bitmapFormat = { drawingColorType, Drawing::AlphaType::ALPHATYPE_PREMUL }; + auto bitmapFormat = RSBaseRenderUtil::GenerateDrawingBitmapFormat(pixelFmt); #ifndef ROSEN_EMULATOR auto surfaceOrigin = Drawing::TextureOrigin::TOP_LEFT; #else diff --git a/rosen/modules/render_service/core/pipeline/rs_base_render_util.cpp b/rosen/modules/render_service/core/pipeline/rs_base_render_util.cpp index 9ce6086c7c..1038a35c29 100644 --- a/rosen/modules/render_service/core/pipeline/rs_base_render_util.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_base_render_util.cpp @@ -649,15 +649,6 @@ bool ConvertBufferColorGamut(std::vector& dstBuf, const sptr& buffer) -{ - Drawing::ColorType colorType = (buffer->GetFormat() == GRAPHIC_PIXEL_FMT_BGRA_8888) ? - Drawing::ColorType::COLORTYPE_BGRA_8888 : Drawing::ColorType::COLORTYPE_RGBA_8888; - Drawing::AlphaType alphaType = Drawing::AlphaType::ALPHATYPE_PREMUL; - Drawing::BitmapFormat format { colorType, alphaType }; - return format; -} - // YUV to RGBA: Pixel value conversion table static int Table_fv1[256] = { -180, -179, -177, -176, -174, -173, -172, -170, -169, -167, -166, -165, -163, -162, -160, -159, -158, -156, -155, -153, -152, -151, -149, -148, -146, -145, -144, -142, -141, -139, @@ -900,6 +891,24 @@ GSError RSBaseRenderUtil::DropFrameProcess(RSSurfaceHandler& node) return OHOS::GSERROR_OK; } +Drawing::ColorType RSBaseRenderUtil::GetColorTypeFromBufferFormat(int32_t pixelFmt) +{ + switch (pixelFmt) { + case GRAPHIC_PIXEL_FMT_RGBA_8888: + return Drawing::ColorType::COLORTYPE_RGBA_8888; + case GRAPHIC_PIXEL_FMT_BGRA_8888 : + return Drawing::ColorType::COLORTYPE_BGRA_8888; + case GRAPHIC_PIXEL_FMT_RGB_565: + return Drawing::ColorType::COLORTYPE_RGB_565; + case GRAPHIC_PIXEL_FMT_YCBCR_P010: + case GRAPHIC_PIXEL_FMT_YCRCB_P010: + case GRAPHIC_PIXEL_FMT_RGBA_1010102: + return Drawing::ColorType::COLORTYPE_RGBA_1010102; + default: + return Drawing::ColorType::COLORTYPE_RGBA_8888; + } +} + Rect RSBaseRenderUtil::MergeBufferDamages(const std::vector& damages) { RectI damage; @@ -1205,12 +1214,24 @@ bool RSBaseRenderUtil::CreateYuvToRGBABitMap(sptr buffer, s bool RSBaseRenderUtil::CreateBitmap(sptr buffer, Drawing::Bitmap& bitmap) { - Drawing::BitmapFormat format = Detail::GenerateDrawingBitmapFormat(buffer); + Drawing::BitmapFormat format = GenerateDrawingBitmapFormat(buffer); bitmap.Build(buffer->GetWidth(), buffer->GetHeight(), format, buffer->GetStride()); bitmap.SetPixels(buffer->GetVirAddr()); return true; } +Drawing::BitmapFormat RSBaseRenderUtil::GenerateDrawingBitmapFormat(const sptr& buffer) +{ + Drawing::BitmapFormat format; + if (buffer == nullptr) { + return format; + } + Drawing::ColorType colorType = GetColorTypeFromBufferFormat(buffer->GetFormat()); + Drawing::AlphaType alphaType = Drawing::AlphaType::ALPHATYPE_PREMUL; + format = { colorType, alphaType }; + return format; +} + bool RSBaseRenderUtil::CreateNewColorGamutBitmap(sptr buffer, std::vector& newBuffer, Drawing::Bitmap& bitmap, GraphicColorGamut srcGamut, GraphicColorGamut dstGamut, const std::vector& metaDatas) @@ -1218,7 +1239,7 @@ bool RSBaseRenderUtil::CreateNewColorGamutBitmap(sptr buffe bool convertRes = Detail::ConvertBufferColorGamut(newBuffer, buffer, srcGamut, dstGamut, metaDatas); if (convertRes) { RS_LOGW("CreateNewColorGamutBitmap: convert color gamut succeed, use new buffer to create bitmap."); - Drawing::BitmapFormat format = Detail::GenerateDrawingBitmapFormat(buffer); + Drawing::BitmapFormat format = GenerateDrawingBitmapFormat(buffer); bitmap.Build(buffer->GetWidth(), buffer->GetHeight(), format, buffer->GetStride()); bitmap.SetPixels(newBuffer.data()); return true; diff --git a/rosen/modules/render_service/core/pipeline/rs_base_render_util.h b/rosen/modules/render_service/core/pipeline/rs_base_render_util.h index 71c3d66997..f53218cdc2 100644 --- a/rosen/modules/render_service/core/pipeline/rs_base_render_util.h +++ b/rosen/modules/render_service/core/pipeline/rs_base_render_util.h @@ -99,6 +99,8 @@ public: static Drawing::Matrix GetSurfaceTransformMatrix(GraphicTransformType rotationTransform, const RectF& bounds); static Drawing::Matrix GetGravityMatrix(Gravity gravity, const sptr& buffer, const RectF& bounds); static void SetPropertiesForCanvas(RSPaintFilterCanvas& canvas, const BufferDrawParam& params); + static Drawing::ColorType GetColorTypeFromBufferFormat(int32_t pixelFmt); + static Drawing::BitmapFormat GenerateDrawingBitmapFormat(const sptr& buffer); static GSError DropFrameProcess(RSSurfaceHandler& node); static Rect MergeBufferDamages(const std::vector& damages); diff --git a/rosen/modules/render_service/core/pipeline/rs_hardware_thread.cpp b/rosen/modules/render_service/core/pipeline/rs_hardware_thread.cpp index 9b1a4dc356..3c9182e70d 100644 --- a/rosen/modules/render_service/core/pipeline/rs_hardware_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_hardware_thread.cpp @@ -62,26 +62,8 @@ #endif namespace OHOS::Rosen { -namespace { constexpr uint32_t HARDWARE_THREAD_TASK_NUM = 3; -#if defined(RS_ENABLE_VK) -Drawing::ColorType GetColorTypeFromBufferFormat(int32_t pixelFmt) -{ - switch (pixelFmt) { - case GRAPHIC_PIXEL_FMT_RGBA_8888: - return Drawing::ColorType::COLORTYPE_RGBA_8888; - case GRAPHIC_PIXEL_FMT_BGRA_8888 : - return Drawing::ColorType::COLORTYPE_BGRA_8888; - case GRAPHIC_PIXEL_FMT_RGB_565: - return Drawing::ColorType::COLORTYPE_RGB_565; - default: - return Drawing::ColorType::COLORTYPE_RGBA_8888; - } -} -#endif -} - RSHardwareThread& RSHardwareThread::Instance() { static RSHardwareThread instance; @@ -461,18 +443,10 @@ void RSHardwareThread::Redraw(const sptr& surface, const std::vector image = nullptr; + Drawing::BitmapFormat bitmapFormat = RSBaseRenderUtil::GenerateDrawingBitmapFormat(params.buffer); + #if defined(RS_ENABLE_GL) && defined(RS_ENABLE_EGLIMAGE) if (RSSystemProperties::GetGpuApiType() == GpuApiType::OPENGL) { - Drawing::ColorType colorType = Drawing::ColorType::COLORTYPE_RGBA_8888; - auto pixelFmt = params.buffer->GetFormat(); - if (pixelFmt == GRAPHIC_PIXEL_FMT_BGRA_8888) { - colorType = Drawing::ColorType::COLORTYPE_BGRA_8888; - } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCBCR_P010 || pixelFmt == GRAPHIC_PIXEL_FMT_YCRCB_P010) { - colorType = Drawing::ColorType::COLORTYPE_RGBA_1010102; - } - - Drawing::BitmapFormat bitmapFormat = { colorType, Drawing::AlphaType::ALPHATYPE_PREMUL }; - Drawing::TextureInfo externalTextureInfo; externalTextureInfo.SetWidth(params.buffer->GetSurfaceBufferWidth()); externalTextureInfo.SetHeight(params.buffer->GetSurfaceBufferHeight()); @@ -480,9 +454,11 @@ void RSHardwareThread::Redraw(const sptr& surface, const std::vectorGetFormat(); if (pixelFmt == GRAPHIC_PIXEL_FMT_BGRA_8888) { glType = GR_GL_BGRA8; - } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCBCR_P010 || pixelFmt == GRAPHIC_PIXEL_FMT_YCRCB_P010) { + } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCBCR_P010 || pixelFmt == GRAPHIC_PIXEL_FMT_YCRCB_P010 || + pixelFmt == GRAPHIC_PIXEL_FMT_RGBA_1010102) { glType = GL_RGB10_A2; } externalTextureInfo.SetFormat(glType); @@ -506,9 +482,6 @@ void RSHardwareThread::Redraw(const sptr& surface, const std::vectorGetSeqNum(); imageCacheSeqsVK[bufferId] = imageCache; auto& backendTexture = imageCache->GetBackendTexture(); - - Drawing::BitmapFormat bitmapFormat = { colorType, Drawing::AlphaType::ALPHATYPE_PREMUL }; - image = std::make_shared(); if (!image->BuildFromTexture(*canvas->GetGPUContext(), backendTexture.GetTextureInfo(), Drawing::TextureOrigin::TOP_LEFT, bitmapFormat, drawingColorSpace, -- Gitee