Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59700406 authored by Alec Mouri's avatar Alec Mouri
Browse files

Add more plumbing for translating 10-bit BGRA into skia

Bug: 414794424
Flag: com.android.graphics.hwui.flags.requested_formats_bgra_1010102
Test: Hacking up a device that normally swizzles RGBA1010102 for
readback to not swizzle produces a correct image when telling skia it's
a BGRA1010102 image for PNG encoding

Change-Id: Ibe702a533e7f51adbefbced9897ae75ed0933899
parent c892ddf1
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include <ui/GraphicTypes.h>
#include <ui/PixelFormat.h>

#include "aidl/android/hardware/graphics/common/PixelFormat.h"
#include "screencap_utils.h"
#include "utils/Errors.h"

@@ -87,12 +88,14 @@ static const struct option LONG_OPTIONS[] = {{"png", no_argument, nullptr, 'p'},
                                              LongOpts::HintForSeamless},
                                             {0, 0, 0, 0}};

static int32_t flinger2bitmapFormat(PixelFormat f) {
static int32_t flinger2bitmapFormat(aidl::android::hardware::graphics::common::PixelFormat f) {
    switch (f) {
        case PIXEL_FORMAT_RGB_565:
        case aidl::android::hardware::graphics::common::PixelFormat::RGB_565:
            return ANDROID_BITMAP_FORMAT_RGB_565;
        case PIXEL_FORMAT_RGBA_1010102:
        case aidl::android::hardware::graphics::common::PixelFormat::RGBA_1010102:
            return ANDROID_BITMAP_FORMAT_RGBA_1010102;
        case aidl::android::hardware::graphics::common::PixelFormat::BGRA_1010102:
            return ANDROID_BITMAP_FORMAT_BGRA_1010102;
        default:
            return ANDROID_BITMAP_FORMAT_RGBA_8888;
    }
@@ -205,7 +208,9 @@ status_t saveImage(const char* fn, std::optional<AndroidBitmapCompressFormat> fo

    if (format) {
        AndroidBitmapInfo info;
        info.format = flinger2bitmapFormat(buffer->getPixelFormat());
        info.format = flinger2bitmapFormat(
                static_cast<aidl::android::hardware::graphics::common::PixelFormat>(
                        buffer->getPixelFormat()));
        info.flags = ANDROID_BITMAP_FLAGS_ALPHA_PREMUL;
        info.width = buffer->getWidth();
        info.height = buffer->getHeight();
+13 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <utils/Color.h>

#include "GraphicsJNI.h"
#include "SkColorType.h"
#include "TypeCast.h"
#include "android/graphics/bitmap.h"

@@ -64,6 +65,8 @@ static uint32_t getFormat(const SkImageInfo& info) {
            return ANDROID_BITMAP_FORMAT_RGBA_1010102;
        case kBGRA_8888_SkColorType:
            return ANDROID_BITMAP_FORMAT_BGRA_8888;
        case kBGRA_1010102_SkColorType:
            return ANDROID_BITMAP_FORMAT_BGRA_1010102;
        default:
            return ANDROID_BITMAP_FORMAT_NONE;
    }
@@ -85,6 +88,8 @@ static SkColorType getColorType(uint32_t format) {
            return kRGBA_1010102_SkColorType;
        case ANDROID_BITMAP_FORMAT_BGRA_8888:
            return kBGRA_8888_SkColorType;
        case ANDROID_BITMAP_FORMAT_BGRA_1010102:
            return kBGRA_1010102_SkColorType;
        default:
            return kUnknown_SkColorType;
    }
@@ -219,6 +224,11 @@ private:
int ABitmap_compress(const AndroidBitmapInfo* info, ADataSpace dataSpace, const void* pixels,
                     AndroidBitmapCompressFormat inFormat, int32_t quality, void* userContext,
                     AndroidBitmap_CompressWriteFunc fn) {
    // BGRA_1010102 isn't in the public bitmap api.
    if (info->format == ANDROID_BITMAP_FORMAT_BGRA_1010102) {
        ALOGE("%s: bad format %d", __func__, info->format);
        return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
    }
    return ABitmap_compressWithGainmap(info, dataSpace, pixels, nullptr, -1.f, inFormat, quality,
                                       userContext, fn);
}
@@ -272,6 +282,9 @@ int ABitmap_compressWithGainmap(const AndroidBitmapInfo* info, ADataSpace dataSp
        case ANDROID_BITMAP_FORMAT_RGBA_1010102:
            colorType = kRGBA_1010102_SkColorType;
            break;
        case ANDROID_BITMAP_FORMAT_BGRA_1010102:
            colorType = kBGRA_1010102_SkColorType;
            break;
        default:
            ALOGE("%s: bad format %d", __func__, info->format);
            return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
+1 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ __END_DECLS
// Internal extension to AndroidBitmapFormat.
enum {
    ANDROID_BITMAP_FORMAT_BGRA_8888 = 5,
    ANDROID_BITMAP_FORMAT_BGRA_1010102 = 6,
};

namespace android {
+2 −0
Original line number Diff line number Diff line
@@ -214,6 +214,8 @@ static SkColorType getColorType(uint32_t format) {
            return kRGBA_1010102_SkColorType;
        case ANDROID_BITMAP_FORMAT_BGRA_8888:
            return kBGRA_8888_SkColorType;
        case ANDROID_BITMAP_FORMAT_BGRA_1010102:
            return kBGRA_1010102_SkColorType;
        default:
            return kUnknown_SkColorType;
    }