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

Commit 6193b1f6 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Expose 1010102 config for bitmap"

parents 7d6a9240 1efd0a5d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13988,6 +13988,7 @@ package android.graphics {
    enum_constant @Deprecated public static final android.graphics.Bitmap.Config ARGB_4444;
    enum_constant public static final android.graphics.Bitmap.Config ARGB_8888;
    enum_constant public static final android.graphics.Bitmap.Config HARDWARE;
    enum_constant public static final android.graphics.Bitmap.Config RGBA_1010102;
    enum_constant public static final android.graphics.Bitmap.Config RGBA_F16;
    enum_constant public static final android.graphics.Bitmap.Config RGB_565;
  }
+6 −0
Original line number Diff line number Diff line
@@ -643,6 +643,8 @@ static bool checkInternalFormat(int32_t bitmapFormat, int internalformat, int ty
            return (type == GL_UNSIGNED_SHORT_5_6_5 && internalformat == GL_RGB);
        case ANDROID_BITMAP_FORMAT_RGBA_F16:
            return (type == GL_HALF_FLOAT && internalformat == GL_RGBA16F);
        case ANDROID_BITMAP_FORMAT_RGBA_1010102:
            return (type == GL_UNSIGNED_INT_2_10_10_10_REV && internalformat == GL_RGB10_A2);
        default:
            break;
    }
@@ -676,6 +678,8 @@ static int getInternalFormat(int32_t bitmapFormat) {
            return GL_RGB;
        case ANDROID_BITMAP_FORMAT_RGBA_F16:
            return GL_RGBA16F;
        case ANDROID_BITMAP_FORMAT_RGBA_1010102:
            return GL_RGB10_A2;
        default:
            return -1;
    }
@@ -693,6 +697,8 @@ static int getType(int32_t bitmapFormat) {
            return GL_UNSIGNED_SHORT_5_6_5;
        case ANDROID_BITMAP_FORMAT_RGBA_F16:
            return GL_HALF_FLOAT;
        case ANDROID_BITMAP_FORMAT_RGBA_1010102:
            return GL_UNSIGNED_INT_2_10_10_10_REV;
        default:
            return -1;
    }
+32 −16
Original line number Diff line number Diff line
@@ -519,7 +519,7 @@ public final class Bitmap implements Parcelable {
        ARGB_8888(5),

        /**
         * Each pixels is stored on 8 bytes. Each channel (RGB and alpha
         * Each pixel is stored on 8 bytes. Each channel (RGB and alpha
         * for translucency) is stored as a
         * {@link android.util.Half half-precision floating point value}.
         *
@@ -540,13 +540,29 @@ public final class Bitmap implements Parcelable {
         * It is optimal for cases, when the only operation with the bitmap is to draw it on a
         * screen.
         */
        HARDWARE    (7);
        HARDWARE(7),

        /**
         * Each pixel is stored on 4 bytes. Each RGB channel is stored with 10 bits of precision
         * (1024 possible values). There is an additional alpha channel that is stored with 2 bits
         * of precision (4 possible values).
         *
         * This configuration is suited for wide-gamut and HDR content which does not require alpha
         * blending, such that the memory cost is the same as ARGB_8888 while enabling higher color
         * precision.
         *
         * <p>Use this formula to pack into 32 bits:</p>
         * <pre class="prettyprint">
         * int color = (A & 0x3) << 30 | (B & 0x3ff) << 20 | (G & 0x3ff) << 10 | (R & 0x3ff);
         * </pre>
         */
        RGBA_1010102(8);

        @UnsupportedAppUsage
        final int nativeInt;

        private static Config sConfigs[] = {
            null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888, RGBA_F16, HARDWARE
            null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888, RGBA_F16, HARDWARE, RGBA_1010102
        };

        Config(int ni) {
@@ -1000,8 +1016,8 @@ public final class Bitmap implements Parcelable {
     * @param width    The width of the bitmap
     * @param height   The height of the bitmap
     * @param config   The bitmap config to create.
     * @param hasAlpha If the bitmap is ARGB_8888 or RGBA_16F this flag can be used to
     *                 mark the bitmap as opaque. Doing so will clear the bitmap in black
     * @param hasAlpha If the bitmap is ARGB_8888, RGBA_16F, or RGBA_1010102 this flag can be
     *                 used to mark the bitmap as opaque. Doing so will clear the bitmap in black
     *                 instead of transparent.
     *
     * @throws IllegalArgumentException if the width or height are <= 0, or if
@@ -1019,8 +1035,8 @@ public final class Bitmap implements Parcelable {
     * @param width    The width of the bitmap
     * @param height   The height of the bitmap
     * @param config   The bitmap config to create.
     * @param hasAlpha If the bitmap is ARGB_8888 or RGBA_16F this flag can be used to
     *                 mark the bitmap as opaque. Doing so will clear the bitmap in black
     * @param hasAlpha If the bitmap is ARGB_8888, RGBA_16F, or RGBA_1010102 this flag can be
     *                 used to mark the bitmap as opaque. Doing so will clear the bitmap in black
     *                 instead of transparent.
     * @param colorSpace The color space of the bitmap. If the config is {@link Config#RGBA_F16}
     *                   and {@link ColorSpace.Named#SRGB sRGB} or
@@ -1050,8 +1066,8 @@ public final class Bitmap implements Parcelable {
     * @param width    The width of the bitmap
     * @param height   The height of the bitmap
     * @param config   The bitmap config to create.
     * @param hasAlpha If the bitmap is ARGB_8888 or RGBA_16F this flag can be used to
     *                 mark the bitmap as opaque. Doing so will clear the bitmap in black
     * @param hasAlpha If the bitmap is ARGB_8888, RGBA_16F, or RGBA_1010102 this flag can be
     *                 used to mark the bitmap as opaque. Doing so will clear the bitmap in black
     *                 instead of transparent.
     *
     * @throws IllegalArgumentException if the width or height are <= 0, or if
@@ -1074,8 +1090,8 @@ public final class Bitmap implements Parcelable {
     * @param width    The width of the bitmap
     * @param height   The height of the bitmap
     * @param config   The bitmap config to create.
     * @param hasAlpha If the bitmap is ARGB_8888 or RGBA_16F this flag can be used to
     *                 mark the bitmap as opaque. Doing so will clear the bitmap in black
     * @param hasAlpha If the bitmap is ARGB_8888, RGBA_16F, or RGBA_1010102 this flag can be
     *                 used to mark the bitmap as opaque. Doing so will clear the bitmap in black
     *                 instead of transparent.
     * @param colorSpace The color space of the bitmap. If the config is {@link Config#RGBA_F16}
     *                   and {@link ColorSpace.Named#SRGB sRGB} or
+32 −19
Original line number Diff line number Diff line
@@ -287,29 +287,29 @@ private:
    std::mutex mVkLock;
};

bool HardwareBitmapUploader::hasFP16Support() {
    static std::once_flag sOnce;
    static bool hasFP16Support = false;

    // Gralloc shouldn't let us create a USAGE_HW_TEXTURE if GLES is unable to consume it, so
    // we don't need to double-check the GLES version/extension.
    std::call_once(sOnce, []() {
static bool checkSupport(AHardwareBuffer_Format format) {
    AHardwareBuffer_Desc desc = {
            .width = 1,
            .height = 1,
            .layers = 1,
                .format = AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT,
                .usage = AHARDWAREBUFFER_USAGE_CPU_READ_NEVER |
                         AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER |
            .format = format,
            .usage = AHARDWAREBUFFER_USAGE_CPU_READ_NEVER | AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER |
                     AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE,
    };
    UniqueAHardwareBuffer buffer = allocateAHardwareBuffer(desc);
        hasFP16Support = buffer != nullptr;
    });
    return buffer != nullptr;
}

bool HardwareBitmapUploader::hasFP16Support() {
    static bool hasFP16Support = checkSupport(AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT);
    return hasFP16Support;
}

bool HardwareBitmapUploader::has1010102Support() {
    static bool has101012Support = checkSupport(AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM);
    return has101012Support;
}

static FormatInfo determineFormat(const SkBitmap& skBitmap, bool usingGL) {
    FormatInfo formatInfo;
    switch (skBitmap.info().colorType()) {
@@ -350,6 +350,19 @@ static FormatInfo determineFormat(const SkBitmap& skBitmap, bool usingGL) {
            formatInfo.type = GL_UNSIGNED_BYTE;
            formatInfo.vkFormat = VK_FORMAT_R8G8B8A8_UNORM;
            break;
        case kRGBA_1010102_SkColorType:
            formatInfo.isSupported = HardwareBitmapUploader::has1010102Support();
            if (formatInfo.isSupported) {
                formatInfo.type = GL_UNSIGNED_INT_2_10_10_10_REV;
                formatInfo.bufferFormat = AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM;
                formatInfo.vkFormat = VK_FORMAT_A2B10G10R10_UNORM_PACK32;
            } else {
                formatInfo.type = GL_UNSIGNED_BYTE;
                formatInfo.bufferFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
                formatInfo.vkFormat = VK_FORMAT_R8G8B8A8_UNORM;
            }
            formatInfo.format = GL_RGBA;
            break;
        default:
            ALOGW("unable to create hardware bitmap of colortype: %d", skBitmap.info().colorType());
            formatInfo.valid = false;
+2 −0
Original line number Diff line number Diff line
@@ -29,10 +29,12 @@ public:

#ifdef __ANDROID__
    static bool hasFP16Support();
    static bool has1010102Support();
#else
    static bool hasFP16Support() {
        return true;
    }
    static bool has1010102Support() { return true; }
#endif
};

Loading