Loading graphics/java/android/graphics/Bitmap.java +27 −0 Original line number Diff line number Diff line Loading @@ -93,6 +93,7 @@ public final class Bitmap implements Parcelable { private boolean mRecycled; private ColorSpace mColorSpace; private Gainmap mGainmap; /*package*/ int mDensity = getDefaultDensity(); Loading Loading @@ -1896,6 +1897,27 @@ public final class Bitmap implements Parcelable { } } /** * Returns whether or not this Bitmap contains a Gainmap. * @hide */ public boolean hasGainmap() { checkRecycled("Bitmap is recycled"); return nativeHasGainmap(mNativePtr); } /** * Returns the gainmap or null if the bitmap doesn't contain a gainmap * @hide */ public @Nullable Gainmap getGainmap() { checkRecycled("Bitmap is recycled"); if (mGainmap == null) { mGainmap = nativeExtractGainmap(mNativePtr); } return mGainmap; } /** * Fills the bitmap's pixels with the specified {@link Color}. * Loading Loading @@ -2380,6 +2402,8 @@ public final class Bitmap implements Parcelable { private static native void nativeSetImmutable(long nativePtr); private static native Gainmap nativeExtractGainmap(long nativePtr); // ---------------- @CriticalNative ------------------- @CriticalNative Loading @@ -2387,4 +2411,7 @@ public final class Bitmap implements Parcelable { @CriticalNative private static native boolean nativeIsBackedByAshmem(long nativePtr); @CriticalNative private static native boolean nativeHasGainmap(long nativePtr); } graphics/java/android/graphics/Gainmap.java 0 → 100644 +127 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.graphics; import android.annotation.NonNull; import libcore.util.NativeAllocationRegistry; /** * Gainmap represents a mechanism for augmenting an SDR image to produce an HDR one with variable * display adjustment capability. * * It is a combination of a set of metadata describing the gainmap, as well as either a 1 or 3 * channel Bitmap that represents the gainmap data itself. * * @hide */ public class Gainmap { private final long mNativePtr; private final Bitmap mGainmapImage; // called from JNI and Bitmap_Delegate. private Gainmap(Bitmap gainmapImage, long nativeGainmap, int allocationByteCount, boolean fromMalloc) { if (nativeGainmap == 0) { throw new RuntimeException("internal error: native gainmap is 0"); } mGainmapImage = gainmapImage; mNativePtr = nativeGainmap; final NativeAllocationRegistry registry; if (fromMalloc) { registry = NativeAllocationRegistry.createMalloced( Bitmap.class.getClassLoader(), nGetFinalizer(), allocationByteCount); } else { registry = NativeAllocationRegistry.createNonmalloced( Bitmap.class.getClassLoader(), nGetFinalizer(), allocationByteCount); } registry.registerNativeAllocation(this, nativeGainmap); } /** * Returns the image data of the gainmap represented as a Bitmap * @return */ @NonNull public Bitmap getGainmapImage() { return mGainmapImage; } /** * Sets the gainmap max metadata. For single-plane gainmaps, r, g, and b should be the same. */ @NonNull public void setGainmapMax(float r, float g, float b) { nSetGainmapMax(mNativePtr, r, g, b); } /** * Gets the gainmap max metadata. For single-plane gainmaps, all 3 components should be the * same. The components are in r, g, b order. */ @NonNull public float[] getGainmapMax() { float[] ret = new float[3]; nGetGainmapMax(mNativePtr, ret); return ret; } /** * Sets the maximum HDR ratio for the gainmap */ @NonNull public void setHdrRatioMax(float max) { nSetHdrRatioMax(mNativePtr, max); } /** * Gets the maximum HDR ratio for the gainmap */ @NonNull public float getHdrRatioMax() { return nGetHdrRatioMax(mNativePtr); } /** * Sets the maximum HDR ratio for the gainmap */ @NonNull public void setHdrRatioMin(float min) { nSetHdrRatioMin(mNativePtr, min); } /** * Gets the maximum HDR ratio for the gainmap */ @NonNull public float getHdrRatioMin() { return nGetHdrRatioMin(mNativePtr); } private static native long nGetFinalizer(); private static native void nSetGainmapMax(long ptr, float r, float g, float b); private static native void nGetGainmapMax(long ptr, float[] components); private static native void nSetHdrRatioMax(long ptr, float max); private static native float nGetHdrRatioMax(long ptr); private static native void nSetHdrRatioMin(long ptr, float min); private static native float nGetHdrRatioMin(long ptr); } libs/hwui/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -347,6 +347,7 @@ cc_defaults { "jni/CreateJavaOutputStreamAdaptor.cpp", "jni/FontFamily.cpp", "jni/FontUtils.cpp", "jni/Gainmap.cpp", "jni/Graphics.cpp", "jni/ImageDecoder.cpp", "jni/Interpolator.cpp", Loading libs/hwui/Gainmap.h 0 → 100644 +32 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <SkGainmapInfo.h> #include <SkImage.h> #include <hwui/Bitmap.h> #include <utils/LightRefBase.h> namespace android::uirenderer { class Gainmap : public LightRefBase<Gainmap> { public: SkGainmapInfo info; sk_sp<Bitmap> bitmap; }; } // namespace android::uirenderer libs/hwui/apex/jni_runtime.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ extern int register_android_graphics_ColorFilter(JNIEnv* env); extern int register_android_graphics_ColorSpace(JNIEnv* env); extern int register_android_graphics_DrawFilter(JNIEnv* env); extern int register_android_graphics_FontFamily(JNIEnv* env); extern int register_android_graphics_Gainmap(JNIEnv* env); extern int register_android_graphics_HardwareRendererObserver(JNIEnv* env); extern int register_android_graphics_Matrix(JNIEnv* env); extern int register_android_graphics_Paint(JNIEnv* env); Loading Loading @@ -114,6 +115,7 @@ extern int register_android_graphics_HardwareBufferRenderer(JNIEnv* env); REG_JNI(register_android_graphics_ColorFilter), REG_JNI(register_android_graphics_DrawFilter), REG_JNI(register_android_graphics_FontFamily), REG_JNI(register_android_graphics_Gainmap), REG_JNI(register_android_graphics_HardwareRendererObserver), REG_JNI(register_android_graphics_ImageDecoder), REG_JNI(register_android_graphics_drawable_AnimatedImageDrawable), Loading Loading
graphics/java/android/graphics/Bitmap.java +27 −0 Original line number Diff line number Diff line Loading @@ -93,6 +93,7 @@ public final class Bitmap implements Parcelable { private boolean mRecycled; private ColorSpace mColorSpace; private Gainmap mGainmap; /*package*/ int mDensity = getDefaultDensity(); Loading Loading @@ -1896,6 +1897,27 @@ public final class Bitmap implements Parcelable { } } /** * Returns whether or not this Bitmap contains a Gainmap. * @hide */ public boolean hasGainmap() { checkRecycled("Bitmap is recycled"); return nativeHasGainmap(mNativePtr); } /** * Returns the gainmap or null if the bitmap doesn't contain a gainmap * @hide */ public @Nullable Gainmap getGainmap() { checkRecycled("Bitmap is recycled"); if (mGainmap == null) { mGainmap = nativeExtractGainmap(mNativePtr); } return mGainmap; } /** * Fills the bitmap's pixels with the specified {@link Color}. * Loading Loading @@ -2380,6 +2402,8 @@ public final class Bitmap implements Parcelable { private static native void nativeSetImmutable(long nativePtr); private static native Gainmap nativeExtractGainmap(long nativePtr); // ---------------- @CriticalNative ------------------- @CriticalNative Loading @@ -2387,4 +2411,7 @@ public final class Bitmap implements Parcelable { @CriticalNative private static native boolean nativeIsBackedByAshmem(long nativePtr); @CriticalNative private static native boolean nativeHasGainmap(long nativePtr); }
graphics/java/android/graphics/Gainmap.java 0 → 100644 +127 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.graphics; import android.annotation.NonNull; import libcore.util.NativeAllocationRegistry; /** * Gainmap represents a mechanism for augmenting an SDR image to produce an HDR one with variable * display adjustment capability. * * It is a combination of a set of metadata describing the gainmap, as well as either a 1 or 3 * channel Bitmap that represents the gainmap data itself. * * @hide */ public class Gainmap { private final long mNativePtr; private final Bitmap mGainmapImage; // called from JNI and Bitmap_Delegate. private Gainmap(Bitmap gainmapImage, long nativeGainmap, int allocationByteCount, boolean fromMalloc) { if (nativeGainmap == 0) { throw new RuntimeException("internal error: native gainmap is 0"); } mGainmapImage = gainmapImage; mNativePtr = nativeGainmap; final NativeAllocationRegistry registry; if (fromMalloc) { registry = NativeAllocationRegistry.createMalloced( Bitmap.class.getClassLoader(), nGetFinalizer(), allocationByteCount); } else { registry = NativeAllocationRegistry.createNonmalloced( Bitmap.class.getClassLoader(), nGetFinalizer(), allocationByteCount); } registry.registerNativeAllocation(this, nativeGainmap); } /** * Returns the image data of the gainmap represented as a Bitmap * @return */ @NonNull public Bitmap getGainmapImage() { return mGainmapImage; } /** * Sets the gainmap max metadata. For single-plane gainmaps, r, g, and b should be the same. */ @NonNull public void setGainmapMax(float r, float g, float b) { nSetGainmapMax(mNativePtr, r, g, b); } /** * Gets the gainmap max metadata. For single-plane gainmaps, all 3 components should be the * same. The components are in r, g, b order. */ @NonNull public float[] getGainmapMax() { float[] ret = new float[3]; nGetGainmapMax(mNativePtr, ret); return ret; } /** * Sets the maximum HDR ratio for the gainmap */ @NonNull public void setHdrRatioMax(float max) { nSetHdrRatioMax(mNativePtr, max); } /** * Gets the maximum HDR ratio for the gainmap */ @NonNull public float getHdrRatioMax() { return nGetHdrRatioMax(mNativePtr); } /** * Sets the maximum HDR ratio for the gainmap */ @NonNull public void setHdrRatioMin(float min) { nSetHdrRatioMin(mNativePtr, min); } /** * Gets the maximum HDR ratio for the gainmap */ @NonNull public float getHdrRatioMin() { return nGetHdrRatioMin(mNativePtr); } private static native long nGetFinalizer(); private static native void nSetGainmapMax(long ptr, float r, float g, float b); private static native void nGetGainmapMax(long ptr, float[] components); private static native void nSetHdrRatioMax(long ptr, float max); private static native float nGetHdrRatioMax(long ptr); private static native void nSetHdrRatioMin(long ptr, float min); private static native float nGetHdrRatioMin(long ptr); }
libs/hwui/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -347,6 +347,7 @@ cc_defaults { "jni/CreateJavaOutputStreamAdaptor.cpp", "jni/FontFamily.cpp", "jni/FontUtils.cpp", "jni/Gainmap.cpp", "jni/Graphics.cpp", "jni/ImageDecoder.cpp", "jni/Interpolator.cpp", Loading
libs/hwui/Gainmap.h 0 → 100644 +32 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <SkGainmapInfo.h> #include <SkImage.h> #include <hwui/Bitmap.h> #include <utils/LightRefBase.h> namespace android::uirenderer { class Gainmap : public LightRefBase<Gainmap> { public: SkGainmapInfo info; sk_sp<Bitmap> bitmap; }; } // namespace android::uirenderer
libs/hwui/apex/jni_runtime.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ extern int register_android_graphics_ColorFilter(JNIEnv* env); extern int register_android_graphics_ColorSpace(JNIEnv* env); extern int register_android_graphics_DrawFilter(JNIEnv* env); extern int register_android_graphics_FontFamily(JNIEnv* env); extern int register_android_graphics_Gainmap(JNIEnv* env); extern int register_android_graphics_HardwareRendererObserver(JNIEnv* env); extern int register_android_graphics_Matrix(JNIEnv* env); extern int register_android_graphics_Paint(JNIEnv* env); Loading Loading @@ -114,6 +115,7 @@ extern int register_android_graphics_HardwareBufferRenderer(JNIEnv* env); REG_JNI(register_android_graphics_ColorFilter), REG_JNI(register_android_graphics_DrawFilter), REG_JNI(register_android_graphics_FontFamily), REG_JNI(register_android_graphics_Gainmap), REG_JNI(register_android_graphics_HardwareRendererObserver), REG_JNI(register_android_graphics_ImageDecoder), REG_JNI(register_android_graphics_drawable_AnimatedImageDrawable), Loading