diff options
author | 2019-07-31 15:18:47 -0400 | |
---|---|---|
committer | 2019-08-09 11:41:51 -0400 | |
commit | e78f7c9f48a4c8be118f250c397e5e034ef2e4de (patch) | |
tree | f55593b5a9a9b5c0d3a139dafb7dfcee39b1cbfb | |
parent | 982a2f28dad6ea6386e7e4756e1ccb9b46e321d6 (diff) |
Move GraphicBuffer back into libandroid_runtime.
Update Bitmap to store AHardwareBuffer instead of GraphicBuffer and
begin removing references to GraphicBuffer from the graphics JNI code
Test: CtsUiRenderingTestCases
Bug: 137655431
Change-Id: If533b6d87a87ae7e94a9b6f16fc52043714087df
-rw-r--r-- | core/jni/Android.bp | 2 | ||||
-rwxr-xr-x | core/jni/android/graphics/Bitmap.cpp | 16 | ||||
-rw-r--r-- | core/jni/android_graphics_GraphicBuffer.cpp (renamed from core/jni/android/graphics/GraphicBuffer.cpp) | 10 | ||||
-rw-r--r-- | core/jni/android_hardware_HardwareBuffer.cpp | 5 | ||||
-rw-r--r-- | core/jni/android_view_Surface.cpp | 10 | ||||
-rw-r--r-- | core/jni/android_view_ThreadedRenderer.cpp | 3 | ||||
-rw-r--r-- | core/jni/include/android_runtime/android_graphics_GraphicBuffer.h (renamed from core/jni/android/graphics/GraphicBuffer.h) | 9 | ||||
-rw-r--r-- | libs/hwui/Android.bp | 1 | ||||
-rw-r--r-- | libs/hwui/HardwareBitmapUploader.cpp | 5 | ||||
-rw-r--r-- | libs/hwui/hwui/Bitmap.cpp | 35 | ||||
-rw-r--r-- | libs/hwui/hwui/Bitmap.h | 19 | ||||
-rw-r--r-- | libs/hwui/renderthread/VulkanSurface.h | 1 | ||||
-rw-r--r-- | libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/utils/Color.cpp | 38 | ||||
-rw-r--r-- | libs/hwui/utils/Color.h | 5 |
15 files changed, 114 insertions, 47 deletions
diff --git a/core/jni/Android.bp b/core/jni/Android.bp index 844a89862d5a..a54247572b80 100644 --- a/core/jni/Android.bp +++ b/core/jni/Android.bp @@ -104,6 +104,7 @@ cc_library_shared { "android_database_SQLiteConnection.cpp", "android_database_SQLiteGlobal.cpp", "android_database_SQLiteDebug.cpp", + "android_graphics_GraphicBuffer.cpp", "android_view_CompositionSamplingListener.cpp", "android_view_DisplayEventReceiver.cpp", "android_view_InputChannel.cpp", @@ -421,7 +422,6 @@ cc_library_static { "android_view_ThreadedRenderer.cpp", "android/graphics/BitmapRegionDecoder.cpp", "android/graphics/GIFMovie.cpp", - "android/graphics/GraphicBuffer.cpp", "android/graphics/Movie.cpp", "android/graphics/MovieImpl.cpp", "android/graphics/SurfaceTexture.cpp", diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp index f3abcf1901c1..78e8e1322db2 100755 --- a/core/jni/android/graphics/Bitmap.cpp +++ b/core/jni/android/graphics/Bitmap.cpp @@ -19,11 +19,10 @@ #include <utils/Color.h> #ifdef __ANDROID__ // Layoutlib does not support graphic buffer, parcel or render thread -#include "GraphicBuffer.h" #include <binder/Parcel.h> #include <renderthread/RenderProxy.h> +#include <android_runtime/android_graphics_GraphicBuffer.h> #include <android_runtime/android_hardware_HardwareBuffer.h> - #include <private/android/AHardwareBufferHelpers.h> #endif @@ -1129,12 +1128,10 @@ static jobject Bitmap_copyPreserveInternalConfig(JNIEnv* env, jobject, jlong bit static jobject Bitmap_wrapHardwareBufferBitmap(JNIEnv* env, jobject, jobject hardwareBuffer, jlong colorSpacePtr) { #ifdef __ANDROID__ // Layoutlib does not support graphic buffer - AHardwareBuffer* hwBuf = android_hardware_HardwareBuffer_getNativeHardwareBuffer(env, + AHardwareBuffer* buffer = android_hardware_HardwareBuffer_getNativeHardwareBuffer(env, hardwareBuffer); - sp<GraphicBuffer> buffer(AHardwareBuffer_to_GraphicBuffer(hwBuf)); - SkColorType ct = uirenderer::PixelFormatToColorType(buffer->getPixelFormat()); - sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer, ct, - GraphicsJNI::getNativeColorSpace(colorSpacePtr)); + sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer, + GraphicsJNI::getNativeColorSpace(colorSpacePtr)); if (!bitmap.get()) { ALOGW("failed to create hardware bitmap from hardware buffer"); return NULL; @@ -1151,9 +1148,8 @@ static jobject Bitmap_createGraphicBufferHandle(JNIEnv* env, jobject, jlong bitm LOG_ALWAYS_FATAL_IF(!bitmapHandle->isHardware(), "Hardware config is only supported config in Bitmap_getGraphicBuffer"); - Bitmap& hwuiBitmap = bitmapHandle->bitmap(); - sp<GraphicBuffer> buffer(hwuiBitmap.graphicBuffer()); - return createJavaGraphicBuffer(env, buffer); + Bitmap& bitmap = bitmapHandle->bitmap(); + return android_graphics_GraphicBuffer_createFromAHardwareBuffer(env, bitmap.hardwareBuffer()); #else return NULL; #endif diff --git a/core/jni/android/graphics/GraphicBuffer.cpp b/core/jni/android_graphics_GraphicBuffer.cpp index 344e22c2ed69..bb9254c62c4d 100644 --- a/core/jni/android/graphics/GraphicBuffer.cpp +++ b/core/jni/android_graphics_GraphicBuffer.cpp @@ -21,10 +21,10 @@ #include <inttypes.h> #include "android_os_Parcel.h" -#include "GraphicBuffer.h" -#include "GraphicsJNI.h" +#include "android/graphics/GraphicsJNI.h" #include <android_runtime/AndroidRuntime.h> +#include <android_runtime/android_graphics_GraphicBuffer.h> #include <binder/Parcel.h> @@ -266,7 +266,7 @@ static jlong android_graphics_GraphicBuffer_read(JNIEnv* env, jobject clazz, // External helpers // ---------------------------------------------------------------------------- -sp<GraphicBuffer> graphicBufferForJavaObject(JNIEnv* env, jobject obj) { +sp<GraphicBuffer> android_graphics_GraphicBuffer_getNativeGraphicsBuffer(JNIEnv* env, jobject obj) { if (obj) { jlong nativeObject = env->GetLongField(obj, gGraphicBufferClassInfo.mNativeObject); GraphicBufferWrapper* wrapper = (GraphicBufferWrapper*) nativeObject; @@ -278,7 +278,9 @@ sp<GraphicBuffer> graphicBufferForJavaObject(JNIEnv* env, jobject obj) { return NULL; } -jobject createJavaGraphicBuffer(JNIEnv* env, const sp<GraphicBuffer>& buffer) { +jobject android_graphics_GraphicBuffer_createFromAHardwareBuffer(JNIEnv* env, + AHardwareBuffer* hardwareBuffer) { + GraphicBuffer* buffer = GraphicBuffer::fromAHardwareBuffer(hardwareBuffer); GraphicBufferWrapper* wrapper = new GraphicBufferWrapper(buffer); jobject obj = env->NewObject(gGraphicBufferClassInfo.mClass, gGraphicBufferClassInfo.mConstructorMethodID, buffer->getWidth(), buffer->getHeight(), diff --git a/core/jni/android_hardware_HardwareBuffer.cpp b/core/jni/android_hardware_HardwareBuffer.cpp index 706a2b8c8ad5..e78e08e4f170 100644 --- a/core/jni/android_hardware_HardwareBuffer.cpp +++ b/core/jni/android_hardware_HardwareBuffer.cpp @@ -20,9 +20,9 @@ #include <nativehelper/JNIHelp.h> #include "android_os_Parcel.h" -#include "android/graphics/GraphicBuffer.h" #include <android/hardware_buffer.h> +#include <android_runtime/android_graphics_GraphicBuffer.h> #include <android_runtime/android_hardware_HardwareBuffer.h> #include <android_runtime/AndroidRuntime.h> #include <android_runtime/Log.h> @@ -97,7 +97,8 @@ static jlong android_hardware_HardwareBuffer_create(JNIEnv* env, jobject clazz, } static jlong android_hardware_HardwareBuffer_createFromGraphicBuffer(JNIEnv* env, jobject clazz, jobject graphicBuffer) { - sp<GraphicBuffer> buffer(graphicBufferForJavaObject(env, graphicBuffer)); + sp<GraphicBuffer> buffer(android_graphics_GraphicBuffer_getNativeGraphicsBuffer(env, + graphicBuffer)); GraphicBufferWrapper* wrapper = new GraphicBufferWrapper(buffer); return reinterpret_cast<jlong>(wrapper); } diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index 8eb9c9abecff..d65e2522a83c 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -21,12 +21,12 @@ #include "jni.h" #include <nativehelper/JNIHelp.h> #include "android_os_Parcel.h" -#include "android/graphics/GraphicBuffer.h" #include "android/graphics/GraphicsJNI.h" #include "core_jni_helpers.h" -#include <android_runtime/android_view_Surface.h> +#include <android_runtime/android_graphics_GraphicBuffer.h> #include <android_runtime/android_graphics_SurfaceTexture.h> +#include <android_runtime/android_view_Surface.h> #include <android_runtime/Log.h> #include <binder/Parcel.h> @@ -35,6 +35,7 @@ #include <gui/view/Surface.h> #include <gui/SurfaceControl.h> +#include <ui/GraphicBuffer.h> #include <ui/Rect.h> #include <ui/Region.h> @@ -432,8 +433,9 @@ static jint nativeForceScopedDisconnect(JNIEnv *env, jclass clazz, jlong nativeO static jint nativeAttachAndQueueBufferWithColorSpace(JNIEnv *env, jclass clazz, jlong nativeObject, jobject graphicBuffer, jint colorSpaceId) { Surface* surface = reinterpret_cast<Surface*>(nativeObject); - sp<GraphicBuffer> bp = graphicBufferForJavaObject(env, graphicBuffer); - int err = Surface::attachAndQueueBufferWithDataspace(surface, bp, + sp<GraphicBuffer> gb(android_graphics_GraphicBuffer_getNativeGraphicsBuffer(env, + graphicBuffer)); + int err = Surface::attachAndQueueBufferWithDataspace(surface, gb, fromNamedColorSpaceValueToDataspace(colorSpaceId)); return err; } diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp index b0443a850550..dd3a4d0c5699 100644 --- a/core/jni/android_view_ThreadedRenderer.cpp +++ b/core/jni/android_view_ThreadedRenderer.cpp @@ -520,14 +520,13 @@ static jobject android_view_ThreadedRenderer_createHardwareBitmapFromRenderNode( // Continue I guess? } - SkColorType ct = uirenderer::PixelFormatToColorType(buffer->getPixelFormat()); sk_sp<SkColorSpace> cs = uirenderer::DataSpaceToColorSpace(bufferItem.mDataSpace); if (cs == nullptr) { // nullptr is treated as SRGB in Skia, thus explicitly use SRGB in order to make sure // the returned bitmap has a color space. cs = SkColorSpace::MakeSRGB(); } - sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer, ct, cs); + sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer->toAHardwareBuffer(), cs); return bitmap::createBitmap(env, bitmap.release(), android::bitmap::kBitmapCreateFlag_Premultiplied); } diff --git a/core/jni/android/graphics/GraphicBuffer.h b/core/jni/include/android_runtime/android_graphics_GraphicBuffer.h index 0d7266942748..5f15faacfd50 100644 --- a/core/jni/android/graphics/GraphicBuffer.h +++ b/core/jni/include/android_runtime/android_graphics_GraphicBuffer.h @@ -14,16 +14,19 @@ * limitations under the License. */ -#include <ui/GraphicBuffer.h> +#include <android/hardware_buffer.h> #include "jni.h" namespace android { +class GraphicBuffer; + // This function does not perform any type checking, the specified // object must be an instance of android.view.GraphicBuffer -extern sp<GraphicBuffer> graphicBufferForJavaObject(JNIEnv* env, jobject obj); +sp<GraphicBuffer> android_graphics_GraphicBuffer_getNativeGraphicsBuffer(JNIEnv* env, jobject obj); -jobject createJavaGraphicBuffer(JNIEnv* env, const sp<GraphicBuffer>& buffer); +extern jobject android_graphics_GraphicBuffer_createFromAHardwareBuffer(JNIEnv* env, + AHardwareBuffer* buffer); } diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp index 0d837f2c7fed..ae90f117d448 100644 --- a/libs/hwui/Android.bp +++ b/libs/hwui/Android.bp @@ -88,6 +88,7 @@ cc_defaults { "libvulkan", "libui", "libgui", + "libnativewindow", "libprotobuf-cpp-lite", "libft2", "libandroidfw", diff --git a/libs/hwui/HardwareBitmapUploader.cpp b/libs/hwui/HardwareBitmapUploader.cpp index 9bb6031b76ac..40bff88b7512 100644 --- a/libs/hwui/HardwareBitmapUploader.cpp +++ b/libs/hwui/HardwareBitmapUploader.cpp @@ -403,8 +403,9 @@ sk_sp<Bitmap> HardwareBitmapUploader::allocateHardwareBitmap(const SkBitmap& sou if (!sUploader->uploadHardwareBitmap(bitmap, format, buffer)) { return nullptr; } - return Bitmap::createFrom(buffer, bitmap.colorType(), bitmap.refColorSpace(), - bitmap.alphaType(), Bitmap::computePalette(bitmap)); + return Bitmap::createFrom(buffer->toAHardwareBuffer(), bitmap.colorType(), + bitmap.refColorSpace(), bitmap.alphaType(), + Bitmap::computePalette(bitmap)); } void HardwareBitmapUploader::initialize() { diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp index 4c2f0ad102bd..a1be5b72a5c5 100644 --- a/libs/hwui/hwui/Bitmap.cpp +++ b/libs/hwui/hwui/Bitmap.cpp @@ -148,12 +148,26 @@ sk_sp<Bitmap> Bitmap::createFrom(const SkImageInfo& info, SkPixelRef& pixelRef) #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration -sk_sp<Bitmap> Bitmap::createFrom(sp<GraphicBuffer> graphicBuffer, SkColorType colorType, +sk_sp<Bitmap> Bitmap::createFrom(AHardwareBuffer* hardwareBuffer, sk_sp<SkColorSpace> colorSpace, + BitmapPalette palette) { + AHardwareBuffer_Desc bufferDesc; + AHardwareBuffer_describe(hardwareBuffer, &bufferDesc); + SkImageInfo info = uirenderer::BufferDescriptionToImageInfo(bufferDesc, colorSpace); + + const size_t rowBytes = info.bytesPerPixel() * bufferDesc.stride; + return sk_sp<Bitmap>(new Bitmap(hardwareBuffer, info, rowBytes, palette)); +} + +sk_sp<Bitmap> Bitmap::createFrom(AHardwareBuffer* hardwareBuffer, SkColorType colorType, sk_sp<SkColorSpace> colorSpace, SkAlphaType alphaType, BitmapPalette palette) { - SkImageInfo info = SkImageInfo::Make(graphicBuffer->getWidth(), graphicBuffer->getHeight(), + AHardwareBuffer_Desc bufferDesc; + AHardwareBuffer_describe(hardwareBuffer, &bufferDesc); + SkImageInfo info = SkImageInfo::Make(bufferDesc.width, bufferDesc.height, colorType, alphaType, colorSpace); - return sk_sp<Bitmap>(new Bitmap(graphicBuffer.get(), info, palette)); + + const size_t rowBytes = info.bytesPerPixel() * bufferDesc.stride; + return sk_sp<Bitmap>(new Bitmap(hardwareBuffer, info, rowBytes, palette)); } #endif @@ -238,18 +252,17 @@ Bitmap::Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info } #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration -Bitmap::Bitmap(GraphicBuffer* buffer, const SkImageInfo& info, BitmapPalette palette) - : SkPixelRef(info.width(), info.height(), nullptr, - bytesPerPixel(buffer->getPixelFormat()) * buffer->getStride()) +Bitmap::Bitmap(AHardwareBuffer* buffer, const SkImageInfo& info, size_t rowBytes, + BitmapPalette palette) + : SkPixelRef(info.width(), info.height(), nullptr, rowBytes) , mInfo(validateAlpha(info)) , mPixelStorageType(PixelStorageType::Hardware) , mPalette(palette) , mPaletteGenerationId(getGenerationID()) { mPixelStorage.hardware.buffer = buffer; - buffer->incStrong(buffer); + AHardwareBuffer_acquire(buffer); setImmutable(); // HW bitmaps are always immutable - mImage = SkImage::MakeFromAHardwareBuffer(reinterpret_cast<AHardwareBuffer*>(buffer), - mInfo.alphaType(), mInfo.refColorSpace()); + mImage = SkImage::MakeFromAHardwareBuffer(buffer, mInfo.alphaType(), mInfo.refColorSpace()); } #endif @@ -274,7 +287,7 @@ Bitmap::~Bitmap() { case PixelStorageType::Hardware: #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration auto buffer = mPixelStorage.hardware.buffer; - buffer->decStrong(buffer); + AHardwareBuffer_release(buffer); mPixelStorage.hardware.buffer = nullptr; #endif break; @@ -352,7 +365,7 @@ void Bitmap::getBounds(SkRect* bounds) const { } #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration -GraphicBuffer* Bitmap::graphicBuffer() { +AHardwareBuffer* Bitmap::hardwareBuffer() { if (isHardware()) { return mPixelStorage.hardware.buffer; } diff --git a/libs/hwui/hwui/Bitmap.h b/libs/hwui/hwui/Bitmap.h index c7e18d10de96..00733c6b245b 100644 --- a/libs/hwui/hwui/Bitmap.h +++ b/libs/hwui/hwui/Bitmap.h @@ -24,7 +24,7 @@ #include <SkPixelRef.h> #include <cutils/compiler.h> #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration -#include <ui/GraphicBuffer.h> +#include <android/hardware_buffer.h> #endif namespace android { @@ -74,11 +74,15 @@ public: * memory that is provided as an input param. */ #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration - static sk_sp<Bitmap> createFrom(sp<GraphicBuffer> graphicBuffer, - SkColorType colorType, + static sk_sp<Bitmap> createFrom(AHardwareBuffer* hardwareBuffer, sk_sp<SkColorSpace> colorSpace, - SkAlphaType alphaType = kPremul_SkAlphaType, BitmapPalette palette = BitmapPalette::Unknown); + + static sk_sp<Bitmap> createFrom(AHardwareBuffer* hardwareBuffer, + SkColorType colorType, + sk_sp<SkColorSpace> colorSpace, + SkAlphaType alphaType, + BitmapPalette palette); #endif static sk_sp<Bitmap> createFrom(const SkImageInfo& info, size_t rowBytes, int fd, void* addr, size_t size, bool readOnly); @@ -110,7 +114,7 @@ public: PixelStorageType pixelStorageType() const { return mPixelStorageType; } #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration - GraphicBuffer* graphicBuffer(); + AHardwareBuffer* hardwareBuffer(); #endif /** @@ -143,7 +147,8 @@ private: size_t rowBytes); Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info, size_t rowBytes); #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration - Bitmap(GraphicBuffer* buffer, const SkImageInfo& info, BitmapPalette palette); + Bitmap(AHardwareBuffer* buffer, const SkImageInfo& info, size_t rowBytes, + BitmapPalette palette); #endif virtual ~Bitmap(); @@ -175,7 +180,7 @@ private: } heap; #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration struct { - GraphicBuffer* buffer; + AHardwareBuffer* buffer; } hardware; #endif } mPixelStorage; diff --git a/libs/hwui/renderthread/VulkanSurface.h b/libs/hwui/renderthread/VulkanSurface.h index 5717bb3afe5b..bd2362612a13 100644 --- a/libs/hwui/renderthread/VulkanSurface.h +++ b/libs/hwui/renderthread/VulkanSurface.h @@ -18,6 +18,7 @@ #include <system/graphics.h> #include <system/window.h> #include <ui/BufferQueueDefs.h> +#include <ui/PixelFormat.h> #include <vulkan/vulkan.h> #include <SkRefCnt.h> diff --git a/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp b/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp index 3d0a2b2474bf..5886ea39acce 100644 --- a/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp +++ b/libs/hwui/tests/common/scenes/HwBitmapInCompositeShader.cpp @@ -50,7 +50,7 @@ public: pixels[4000 + 4 * i + 3] = 255; } buffer->unlock(); - sk_sp<Bitmap> hardwareBitmap(Bitmap::createFrom(buffer, kRGBA_8888_SkColorType, + sk_sp<Bitmap> hardwareBitmap(Bitmap::createFrom(buffer->toAHardwareBuffer(), SkColorSpace::MakeSRGB())); sk_sp<SkShader> hardwareShader(createBitmapShader(*hardwareBitmap)); diff --git a/libs/hwui/utils/Color.cpp b/libs/hwui/utils/Color.cpp index cc7725b7b9de..9a27f28154e0 100644 --- a/libs/hwui/utils/Color.cpp +++ b/libs/hwui/utils/Color.cpp @@ -19,12 +19,50 @@ #include <utils/Log.h> #include <ui/ColorSpace.h> +#ifdef __ANDROID__ // Layoutlib does not support hardware buffers or native windows +#include <android/hardware_buffer.h> +#endif + #include <algorithm> #include <cmath> namespace android { namespace uirenderer { +#ifdef __ANDROID__ // Layoutlib does not support hardware buffers or native windows +SkImageInfo BufferDescriptionToImageInfo(const AHardwareBuffer_Desc& bufferDesc, + sk_sp<SkColorSpace> colorSpace) { + SkColorType colorType = kUnknown_SkColorType; + SkAlphaType alphaType = kOpaque_SkAlphaType; + switch (bufferDesc.format) { + case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM: + colorType = kN32_SkColorType; + alphaType = kPremul_SkAlphaType; + break; + case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM: + colorType = kN32_SkColorType; + alphaType = kOpaque_SkAlphaType; + break; + case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM: + colorType = kRGB_565_SkColorType; + alphaType = kOpaque_SkAlphaType; + break; + case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM: + colorType = kRGBA_1010102_SkColorType; + alphaType = kPremul_SkAlphaType; + break; + case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT: + colorType = kRGBA_F16_SkColorType; + alphaType = kPremul_SkAlphaType; + break; + default: + ALOGV("Unsupported format: %d, return unknown by default", bufferDesc.format); + break; + } + return SkImageInfo::Make(bufferDesc.width, bufferDesc.height, colorType, alphaType, colorSpace); +} +#endif + android::PixelFormat ColorTypeToPixelFormat(SkColorType colorType) { switch (colorType) { case kRGBA_8888_SkColorType: diff --git a/libs/hwui/utils/Color.h b/libs/hwui/utils/Color.h index 79400de08ee0..7c2378a5aeb3 100644 --- a/libs/hwui/utils/Color.h +++ b/libs/hwui/utils/Color.h @@ -25,6 +25,8 @@ #include <SkColorSpace.h> #include <SkImageInfo.h> +struct AHardwareBuffer_Desc; + namespace android { namespace uirenderer { namespace Color { @@ -89,6 +91,9 @@ static constexpr float EOCF_sRGB(float srgb) { return srgb <= 0.04045f ? srgb / 12.92f : powf((srgb + 0.055f) / 1.055f, 2.4f); } +SkImageInfo BufferDescriptionToImageInfo(const AHardwareBuffer_Desc& bufferDesc, + sk_sp<SkColorSpace> colorSpace); + android::PixelFormat ColorTypeToPixelFormat(SkColorType colorType); ANDROID_API SkColorType PixelFormatToColorType(android::PixelFormat format); |