From bb2ce220a531071db63a7089b2d1ead0a8c67d73 Mon Sep 17 00:00:00 2001 From: Michael Hoisie Date: Fri, 3 May 2024 16:56:18 +0000 Subject: Use kN32_SkColorType when creating the buffer for SkiaHostPipeline kN32_SkColorType is determined at compile-time using a macro that checks the current architectiure. On Mac, this value is different than Linux or Windows. As a result, when HW rendering occurs on a Mac, the blue and red pixels are swapped, which implies one is using kRGBA_8888_SkColorType and the other is using kBGRA_8888_SkColorType. When an Android Bitmap object is initialized using Bitmap.Config.ARGB_8888, it uses kN32_SkColorType Update SkiaHostPipeline to use kN32_SkColorType so the value is consistent with what Bitmap uses. Test: HardwareAcceleratedActivityRenderTest on Mac Test: ShadowNativeHardwareRendererTest on Mac Bug: 338399395 Change-Id: Ic037fea16abcbf950d69daafadbf91fb9c6653a6 --- libs/hwui/pipeline/skia/SkiaHostPipeline.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/libs/hwui/pipeline/skia/SkiaHostPipeline.cpp b/libs/hwui/pipeline/skia/SkiaHostPipeline.cpp index 5faeb9dc503e..431487a65121 100644 --- a/libs/hwui/pipeline/skia/SkiaHostPipeline.cpp +++ b/libs/hwui/pipeline/skia/SkiaHostPipeline.cpp @@ -69,16 +69,14 @@ bool SkiaHostPipeline::setSurface(ANativeWindow* surface, SwapBehavior swapBehav int width, height; surface->query(surface, NATIVE_WINDOW_WIDTH, &width); surface->query(surface, NATIVE_WINDOW_HEIGHT, &height); - // The image must have color type BGRA for all platforms. - // Robolectric note: - // This forces Skia to render ARGB even though we fill an ImageReader - // Surface declared as RGBA_8888. - // Doing this allows us to directly match an Android Bitmap which also - // as the ARGB_8888 format (BGRA and ARGB are essentially the same data - // seen from a different endianness perspective). - SkImageInfo imageInfo = - SkImageInfo::Make(width, height, SkColorType::kBGRA_8888_SkColorType, - SkAlphaType::kPremul_SkAlphaType); + // The ColorType param here must match the ColorType used by + // Bitmap.Config.ARGB_8888. Android Bitmap objects use kN32_SkColorType + // by default for Bitmap.Config.ARGB_8888. The value of this is + // determined at compile time based on architecture (either BGRA or + // RGBA). If other Android Bitmap configs are used, 'kN32_SkColorType' + // may not be correct. + SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, + SkAlphaType::kPremul_SkAlphaType); size_t widthBytes = width * 4; void* pixels = buffer->reserved[0]; mSurface = SkSurface::MakeRasterDirect(imageInfo, pixels, widthBytes); -- cgit v1.2.3