Merge "[HWUI] remove libui from HWUI's dependencies"

This commit is contained in:
TreeHugger Robot
2020-03-05 02:39:02 +00:00
committed by Android (Google) Code Review
17 changed files with 213 additions and 139 deletions

View File

@@ -53,8 +53,6 @@ cc_defaults {
host: {
include_dirs: [
"external/vulkan-headers/include",
"frameworks/native/libs/math/include",
"frameworks/native/libs/ui/include",
],
cflags: [
"-Wno-unused-variable",
@@ -71,6 +69,10 @@ cc_defaults {
"libminikin",
],
static_libs: [
"libui-types",
],
target: {
android: {
shared_libs: [
@@ -83,7 +85,6 @@ cc_defaults {
"libGLESv2",
"libGLESv3",
"libvulkan",
"libui",
"libnativedisplay",
"libnativewindow",
"libprotobuf-cpp-lite",
@@ -460,6 +461,7 @@ cc_defaults {
"service/GraphicsStatsService.cpp",
"thread/CommonPool.cpp",
"utils/GLUtils.cpp",
"utils/NdkUtils.cpp",
"utils/StringUtils.cpp",
"AutoBackendTextureRelease.cpp",
"DeferredLayerUpdater.cpp",
@@ -519,6 +521,7 @@ cc_defaults {
android: {
shared_libs: [
"libgui",
"libui",
],
}
},

View File

@@ -22,7 +22,6 @@
#include <SkGradientShader.h>
#include <SkPaint.h>
#include <SkShader.h>
#include <ui/ColorSpace.h>
#include <algorithm>
#include <cmath>

View File

@@ -16,12 +16,7 @@
#include "HardwareBitmapUploader.h"
#include "hwui/Bitmap.h"
#include "renderthread/EglManager.h"
#include "renderthread/VulkanManager.h"
#include "thread/ThreadBase.h"
#include "utils/TimeUtils.h"
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
@@ -29,11 +24,20 @@
#include <GrContext.h>
#include <SkCanvas.h>
#include <SkImage.h>
#include <private/android/AHardwareBufferHelpers.h>
#include <utils/GLUtils.h>
#include <utils/NdkUtils.h>
#include <utils/Trace.h>
#include <utils/TraceUtils.h>
#include <thread>
#include "hwui/Bitmap.h"
#include "renderthread/EglManager.h"
#include "renderthread/VulkanManager.h"
#include "thread/ThreadBase.h"
#include "utils/TimeUtils.h"
namespace android::uirenderer {
class AHBUploader;
@@ -42,7 +46,7 @@ class AHBUploader;
static sp<AHBUploader> sUploader = nullptr;
struct FormatInfo {
PixelFormat pixelFormat;
AHardwareBuffer_Format bufferFormat;
GLint format, type;
VkFormat vkFormat;
bool isSupported = false;
@@ -71,10 +75,10 @@ public:
}
bool uploadHardwareBitmap(const SkBitmap& bitmap, const FormatInfo& format,
sp<GraphicBuffer> graphicBuffer) {
AHardwareBuffer* ahb) {
ATRACE_CALL();
beginUpload();
bool result = onUploadHardwareBitmap(bitmap, format, graphicBuffer);
bool result = onUploadHardwareBitmap(bitmap, format, ahb);
endUpload();
return result;
}
@@ -93,7 +97,7 @@ private:
virtual void onDestroy() = 0;
virtual bool onUploadHardwareBitmap(const SkBitmap& bitmap, const FormatInfo& format,
sp<GraphicBuffer> graphicBuffer) = 0;
AHardwareBuffer* ahb) = 0;
virtual void onBeginUpload() = 0;
bool shouldTimeOutLocked() {
@@ -165,16 +169,16 @@ private:
}
bool onUploadHardwareBitmap(const SkBitmap& bitmap, const FormatInfo& format,
sp<GraphicBuffer> graphicBuffer) override {
AHardwareBuffer* ahb) override {
ATRACE_CALL();
EGLDisplay display = getUploadEglDisplay();
LOG_ALWAYS_FATAL_IF(display == EGL_NO_DISPLAY, "Failed to get EGL_DEFAULT_DISPLAY! err=%s",
uirenderer::renderthread::EglManager::eglErrorString());
// We use an EGLImage to access the content of the GraphicBuffer
// We use an EGLImage to access the content of the buffer
// The EGL image is later bound to a 2D texture
EGLClientBuffer clientBuffer = (EGLClientBuffer)graphicBuffer->getNativeBuffer();
EGLClientBuffer clientBuffer = (EGLClientBuffer)AHardwareBuffer_to_ANativeWindowBuffer(ahb);
AutoEglImage autoImage(display, clientBuffer);
if (autoImage.image == EGL_NO_IMAGE_KHR) {
ALOGW("Could not create EGL image, err =%s",
@@ -272,13 +276,13 @@ private:
}
bool onUploadHardwareBitmap(const SkBitmap& bitmap, const FormatInfo& format,
sp<GraphicBuffer> graphicBuffer) override {
AHardwareBuffer* ahb) override {
ATRACE_CALL();
std::lock_guard _lock{mLock};
sk_sp<SkImage> image = SkImage::MakeFromAHardwareBufferWithData(mGrContext.get(),
bitmap.pixmap(), reinterpret_cast<AHardwareBuffer*>(graphicBuffer.get()));
sk_sp<SkImage> image =
SkImage::MakeFromAHardwareBufferWithData(mGrContext.get(), bitmap.pixmap(), ahb);
return (image.get() != nullptr);
}
@@ -294,13 +298,17 @@ bool HardwareBitmapUploader::hasFP16Support() {
// 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, []() {
sp<GraphicBuffer> buffer = new GraphicBuffer(1, 1, PIXEL_FORMAT_RGBA_FP16,
GraphicBuffer::USAGE_HW_TEXTURE |
GraphicBuffer::USAGE_SW_WRITE_NEVER |
GraphicBuffer::USAGE_SW_READ_NEVER,
"tempFp16Buffer");
status_t error = buffer->initCheck();
hasFP16Support = !error;
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 |
AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE,
};
UniqueAHardwareBuffer buffer = allocateAHardwareBuffer(desc);
hasFP16Support = buffer != nullptr;
});
return hasFP16Support;
@@ -314,7 +322,7 @@ static FormatInfo determineFormat(const SkBitmap& skBitmap, bool usingGL) {
[[fallthrough]];
// ARGB_4444 is upconverted to RGBA_8888
case kARGB_4444_SkColorType:
formatInfo.pixelFormat = PIXEL_FORMAT_RGBA_8888;
formatInfo.bufferFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
formatInfo.format = GL_RGBA;
formatInfo.type = GL_UNSIGNED_BYTE;
formatInfo.vkFormat = VK_FORMAT_R8G8B8A8_UNORM;
@@ -323,25 +331,25 @@ static FormatInfo determineFormat(const SkBitmap& skBitmap, bool usingGL) {
formatInfo.isSupported = HardwareBitmapUploader::hasFP16Support();
if (formatInfo.isSupported) {
formatInfo.type = GL_HALF_FLOAT;
formatInfo.pixelFormat = PIXEL_FORMAT_RGBA_FP16;
formatInfo.bufferFormat = AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT;
formatInfo.vkFormat = VK_FORMAT_R16G16B16A16_SFLOAT;
} else {
formatInfo.type = GL_UNSIGNED_BYTE;
formatInfo.pixelFormat = PIXEL_FORMAT_RGBA_8888;
formatInfo.bufferFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
formatInfo.vkFormat = VK_FORMAT_R8G8B8A8_UNORM;
}
formatInfo.format = GL_RGBA;
break;
case kRGB_565_SkColorType:
formatInfo.isSupported = true;
formatInfo.pixelFormat = PIXEL_FORMAT_RGB_565;
formatInfo.bufferFormat = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM;
formatInfo.format = GL_RGB;
formatInfo.type = GL_UNSIGNED_SHORT_5_6_5;
formatInfo.vkFormat = VK_FORMAT_R5G6B5_UNORM_PACK16;
break;
case kGray_8_SkColorType:
formatInfo.isSupported = usingGL;
formatInfo.pixelFormat = PIXEL_FORMAT_RGBA_8888;
formatInfo.bufferFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
formatInfo.format = GL_LUMINANCE;
formatInfo.type = GL_UNSIGNED_BYTE;
formatInfo.vkFormat = VK_FORMAT_R8G8B8A8_UNORM;
@@ -394,28 +402,27 @@ sk_sp<Bitmap> HardwareBitmapUploader::allocateHardwareBitmap(const SkBitmap& sou
}
SkBitmap bitmap = makeHwCompatible(format, sourceBitmap);
sp<GraphicBuffer> buffer = new GraphicBuffer(
static_cast<uint32_t>(bitmap.width()), static_cast<uint32_t>(bitmap.height()),
format.pixelFormat,
GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_WRITE_NEVER |
GraphicBuffer::USAGE_SW_READ_NEVER,
std::string("Bitmap::allocateHardwareBitmap pid [") + std::to_string(getpid()) +
"]");
status_t error = buffer->initCheck();
if (error < 0) {
ALOGW("createGraphicBuffer() failed in GraphicBuffer.create()");
AHardwareBuffer_Desc desc = {
.width = static_cast<uint32_t>(bitmap.width()),
.height = static_cast<uint32_t>(bitmap.height()),
.layers = 1,
.format = format.bufferFormat,
.usage = AHARDWAREBUFFER_USAGE_CPU_READ_NEVER | AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER |
AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE,
};
UniqueAHardwareBuffer ahb = allocateAHardwareBuffer(desc);
if (!ahb) {
ALOGW("allocateHardwareBitmap() failed in AHardwareBuffer_allocate()");
return nullptr;
}
};
createUploader(usingGL);
if (!sUploader->uploadHardwareBitmap(bitmap, format, buffer)) {
if (!sUploader->uploadHardwareBitmap(bitmap, format, ahb.get())) {
return nullptr;
}
return Bitmap::createFrom(buffer->toAHardwareBuffer(), bitmap.colorType(),
bitmap.refColorSpace(), bitmap.alphaType(),
Bitmap::computePalette(bitmap));
return Bitmap::createFrom(ahb.get(), bitmap.colorType(), bitmap.refColorSpace(),
bitmap.alphaType(), Bitmap::computePalette(bitmap));
}
void HardwareBitmapUploader::initialize() {

View File

@@ -18,7 +18,6 @@
#include <sync/sync.h>
#include <system/window.h>
#include <ui/GraphicBuffer.h>
#include "DeferredLayerUpdater.h"
#include "Properties.h"
@@ -28,6 +27,7 @@
#include "renderthread/VulkanManager.h"
#include "utils/Color.h"
#include "utils/MathUtils.h"
#include "utils/NdkUtils.h"
#include "utils/TraceUtils.h"
using namespace android::uirenderer::renderthread;
@@ -54,8 +54,7 @@ CopyResult Readback::copySurfaceInto(ANativeWindow* window, const Rect& srcRect,
return CopyResult::SourceEmpty;
}
std::unique_ptr<AHardwareBuffer, decltype(&AHardwareBuffer_release)> sourceBuffer(
rawSourceBuffer, AHardwareBuffer_release);
UniqueAHardwareBuffer sourceBuffer{rawSourceBuffer};
AHardwareBuffer_Desc description;
AHardwareBuffer_describe(sourceBuffer.get(), &description);
if (description.usage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT) {

View File

@@ -33,7 +33,6 @@
#ifndef _WIN32
#include <binder/IServiceManager.h>
#endif
#include <ui/PixelFormat.h>
#include <SkCanvas.h>
#include <SkImagePriv.h>

View File

@@ -19,7 +19,6 @@
#include "FunctorDrawable.h"
#include <SkImageInfo.h>
#include <ui/GraphicBuffer.h>
#include <utils/RefBase.h>
namespace android {

View File

@@ -15,22 +15,24 @@
*/
#include "VkInteropFunctorDrawable.h"
#include <private/hwui/DrawGlInfo.h>
#include <utils/Color.h>
#include <utils/Trace.h>
#include <utils/TraceUtils.h>
#include <thread>
#include "renderthread/EglManager.h"
#include "thread/ThreadBase.h"
#include "utils/TimeUtils.h"
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES3/gl3.h>
#include <private/android/AHardwareBufferHelpers.h>
#include <private/hwui/DrawGlInfo.h>
#include <utils/Color.h>
#include <utils/GLUtils.h>
#include <utils/Trace.h>
#include <utils/TraceUtils.h>
#include <thread>
#include "renderthread/EglManager.h"
#include "thread/ThreadBase.h"
#include "utils/TimeUtils.h"
namespace android {
namespace uirenderer {
@@ -75,20 +77,23 @@ void VkInteropFunctorDrawable::onDraw(SkCanvas* canvas) {
SkImageInfo surfaceInfo = canvas->imageInfo();
if (!mFrameBuffer.get() || mFBInfo != surfaceInfo) {
if (mFrameBuffer == nullptr || mFBInfo != surfaceInfo) {
// Buffer will be used as an OpenGL ES render target.
mFrameBuffer = new GraphicBuffer(
// TODO: try to reduce the size of the buffer: possibly by using clip bounds.
static_cast<uint32_t>(surfaceInfo.width()),
static_cast<uint32_t>(surfaceInfo.height()),
ColorTypeToPixelFormat(surfaceInfo.colorType()),
GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_WRITE_NEVER |
GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_HW_RENDER,
std::string("VkInteropFunctorDrawable::onDraw pid [") + std::to_string(getpid()) +
"]");
status_t error = mFrameBuffer->initCheck();
if (error < 0) {
ALOGW("VkInteropFunctorDrawable::onDraw() failed in GraphicBuffer.create()");
AHardwareBuffer_Desc desc = {
.width = static_cast<uint32_t>(surfaceInfo.width()),
.height = static_cast<uint32_t>(surfaceInfo.height()),
.layers = 1,
.format = ColorTypeToBufferFormat(surfaceInfo.colorType()),
.usage = AHARDWAREBUFFER_USAGE_CPU_READ_NEVER |
AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER |
AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER,
};
mFrameBuffer = allocateAHardwareBuffer(desc);
if (!mFrameBuffer) {
ALOGW("VkInteropFunctorDrawable::onDraw() failed in AHardwareBuffer_allocate()");
return;
}
@@ -106,7 +111,8 @@ void VkInteropFunctorDrawable::onDraw(SkCanvas* canvas) {
uirenderer::renderthread::EglManager::eglErrorString());
// We use an EGLImage to access the content of the GraphicBuffer
// The EGL image is later bound to a 2D texture
EGLClientBuffer clientBuffer = (EGLClientBuffer)mFrameBuffer->getNativeBuffer();
EGLClientBuffer clientBuffer =
(EGLClientBuffer)AHardwareBuffer_to_ANativeWindowBuffer(mFrameBuffer.get());
AutoEglImage autoImage(display, clientBuffer);
if (autoImage.image == EGL_NO_IMAGE_KHR) {
ALOGW("Could not create EGL image, err =%s",
@@ -179,9 +185,9 @@ void VkInteropFunctorDrawable::onDraw(SkCanvas* canvas) {
// drawing into the offscreen surface, so we need to reset it here.
canvas->resetMatrix();
auto functorImage = SkImage::MakeFromAHardwareBuffer(
reinterpret_cast<AHardwareBuffer*>(mFrameBuffer.get()), kPremul_SkAlphaType,
canvas->imageInfo().refColorSpace(), kBottomLeft_GrSurfaceOrigin);
auto functorImage = SkImage::MakeFromAHardwareBuffer(mFrameBuffer.get(), kPremul_SkAlphaType,
canvas->imageInfo().refColorSpace(),
kBottomLeft_GrSurfaceOrigin);
canvas->drawImage(functorImage, 0, 0, &paint);
canvas->restore();
}

View File

@@ -16,11 +16,12 @@
#pragma once
#include "FunctorDrawable.h"
#include <ui/GraphicBuffer.h>
#include <android/hardware_buffer.h>
#include <utils/NdkUtils.h>
#include <utils/RefBase.h>
#include "FunctorDrawable.h"
namespace android {
namespace uirenderer {
@@ -45,7 +46,7 @@ protected:
private:
// Variables below describe/store temporary offscreen buffer used for Vulkan pipeline.
sp<GraphicBuffer> mFrameBuffer;
UniqueAHardwareBuffer mFrameBuffer;
SkImageInfo mFBInfo;
};

View File

@@ -21,7 +21,6 @@
#include <SkImageInfo.h>
#include <SkRect.h>
#include <cutils/compiler.h>
#include <ui/GraphicBuffer.h>
#include <utils/StrongPointer.h>
#include "IRenderPipeline.h"

View File

@@ -143,21 +143,25 @@ ANativeWindowBuffer* ReliableSurface::acquireFallbackBuffer(int error) {
return AHardwareBuffer_to_ANativeWindowBuffer(mScratchBuffer.get());
}
AHardwareBuffer_Desc desc;
desc.usage = mUsage;
desc.format = mFormat;
desc.width = 1;
desc.height = 1;
desc.layers = 1;
desc.rfu0 = 0;
desc.rfu1 = 0;
AHardwareBuffer* newBuffer = nullptr;
int err = AHardwareBuffer_allocate(&desc, &newBuffer);
if (err) {
AHardwareBuffer_Desc desc = AHardwareBuffer_Desc{
.usage = mUsage,
.format = mFormat,
.width = 1,
.height = 1,
.layers = 1,
.rfu0 = 0,
.rfu1 = 0,
};
AHardwareBuffer* newBuffer;
int result = AHardwareBuffer_allocate(&desc, &newBuffer);
if (result != NO_ERROR) {
// Allocate failed, that sucks
ALOGW("Failed to allocate scratch buffer, error=%d", err);
ALOGW("Failed to allocate scratch buffer, error=%d", result);
return nullptr;
}
mScratchBuffer.reset(newBuffer);
return AHardwareBuffer_to_ANativeWindowBuffer(newBuffer);
}

View File

@@ -20,6 +20,7 @@
#include <apex/window.h>
#include <utils/Errors.h>
#include <utils/Macros.h>
#include <utils/NdkUtils.h>
#include <utils/StrongPointer.h>
#include <memory>
@@ -56,8 +57,7 @@ private:
uint64_t mUsage = AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER;
AHardwareBuffer_Format mFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
std::unique_ptr<AHardwareBuffer, void (*)(AHardwareBuffer*)> mScratchBuffer{
nullptr, AHardwareBuffer_release};
UniqueAHardwareBuffer mScratchBuffer;
ANativeWindowBuffer* mReservedBuffer = nullptr;
base::unique_fd mReservedFenceFd;
bool mHasDequeuedBuffer = false;

View File

@@ -207,9 +207,9 @@ bool VulkanSurface::InitializeWindowInfoStruct(ANativeWindow* window, ColorMode
}
}
outWindowInfo->pixelFormat = ColorTypeToPixelFormat(colorType);
outWindowInfo->bufferFormat = ColorTypeToBufferFormat(colorType);
VkFormat vkPixelFormat = VK_FORMAT_R8G8B8A8_UNORM;
if (outWindowInfo->pixelFormat == PIXEL_FORMAT_RGBA_FP16) {
if (outWindowInfo->bufferFormat == AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT) {
vkPixelFormat = VK_FORMAT_R16G16B16A16_SFLOAT;
}
@@ -263,10 +263,10 @@ bool VulkanSurface::InitializeWindowInfoStruct(ANativeWindow* window, ColorMode
bool VulkanSurface::UpdateWindow(ANativeWindow* window, const WindowInfo& windowInfo) {
ATRACE_CALL();
int err = native_window_set_buffers_format(window, windowInfo.pixelFormat);
int err = native_window_set_buffers_format(window, windowInfo.bufferFormat);
if (err != 0) {
ALOGE("VulkanSurface::UpdateWindow() native_window_set_buffers_format(%d) failed: %s (%d)",
windowInfo.pixelFormat, strerror(-err), err);
windowInfo.bufferFormat, strerror(-err), err);
return false;
}

View File

@@ -17,8 +17,6 @@
#include <system/graphics.h>
#include <system/window.h>
#include <ui/BufferQueueDefs.h>
#include <ui/PixelFormat.h>
#include <vulkan/vulkan.h>
#include <SkRefCnt.h>
@@ -91,7 +89,7 @@ private:
struct WindowInfo {
SkISize size;
PixelFormat pixelFormat;
uint32_t bufferFormat;
android_dataspace dataspace;
int transform;
size_t bufferCount;
@@ -111,8 +109,13 @@ private:
static bool UpdateWindow(ANativeWindow* window, const WindowInfo& windowInfo);
void releaseBuffers();
// TODO: This number comes from ui/BufferQueueDefs. We're not pulling the
// header in so that we don't need to depend on libui, but we should share
// this constant somewhere. But right now it's okay to keep here because we
// can't safely change the slot count anyways.
static constexpr size_t kNumBufferSlots = 64;
// TODO: Just use a vector?
NativeBufferInfo mNativeBuffers[android::BufferQueueDefs::NUM_BUFFER_SLOTS];
NativeBufferInfo mNativeBuffers[kNumBufferSlots];
sp<ANativeWindow> mNativeWindow;
WindowInfo mWindowInfo;

View File

@@ -16,8 +16,8 @@
#include "Color.h"
#include <utils/Log.h>
#include <ui/ColorSpace.h>
#include <utils/Log.h>
#ifdef __ANDROID__ // Layoutlib does not support hardware buffers or native windows
#include <android/hardware_buffer.h>
@@ -72,41 +72,29 @@ SkImageInfo BufferDescriptionToImageInfo(const AHardwareBuffer_Desc& bufferDesc,
sk_sp<SkColorSpace> colorSpace) {
return createImageInfo(bufferDesc.width, bufferDesc.height, bufferDesc.format, colorSpace);
}
#endif
android::PixelFormat ColorTypeToPixelFormat(SkColorType colorType) {
uint32_t ColorTypeToBufferFormat(SkColorType colorType) {
switch (colorType) {
case kRGBA_8888_SkColorType:
return PIXEL_FORMAT_RGBA_8888;
return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
case kRGBA_F16_SkColorType:
return PIXEL_FORMAT_RGBA_FP16;
return AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT;
case kRGB_565_SkColorType:
return PIXEL_FORMAT_RGB_565;
return AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM;
case kRGB_888x_SkColorType:
return PIXEL_FORMAT_RGBX_8888;
return AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM;
case kRGBA_1010102_SkColorType:
return PIXEL_FORMAT_RGBA_1010102;
return AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM;
case kARGB_4444_SkColorType:
return PIXEL_FORMAT_RGBA_4444;
// Hardcoding the value from android::PixelFormat
static constexpr uint64_t kRGBA4444 = 7;
return kRGBA4444;
default:
ALOGV("Unsupported colorType: %d, return RGBA_8888 by default", (int)colorType);
return PIXEL_FORMAT_RGBA_8888;
}
}
SkColorType PixelFormatToColorType(android::PixelFormat format) {
switch (format) {
case PIXEL_FORMAT_RGBX_8888: return kRGB_888x_SkColorType;
case PIXEL_FORMAT_RGBA_8888: return kRGBA_8888_SkColorType;
case PIXEL_FORMAT_RGBA_FP16: return kRGBA_F16_SkColorType;
case PIXEL_FORMAT_RGB_565: return kRGB_565_SkColorType;
case PIXEL_FORMAT_RGBA_1010102: return kRGBA_1010102_SkColorType;
case PIXEL_FORMAT_RGBA_4444: return kARGB_4444_SkColorType;
default:
ALOGV("Unsupported PixelFormat: %d, return kUnknown_SkColorType by default", format);
return kUnknown_SkColorType;
return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
}
}
#endif
namespace {
static constexpr skcms_TransferFunction k2Dot6 = {2.6f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};

View File

@@ -16,14 +16,12 @@
#ifndef COLOR_H
#define COLOR_H
#include <math.h>
#include <cutils/compiler.h>
#include <system/graphics.h>
#include <ui/PixelFormat.h>
#include <SkColor.h>
#include <SkColorSpace.h>
#include <SkImageInfo.h>
#include <cutils/compiler.h>
#include <math.h>
#include <system/graphics.h>
struct ANativeWindow_Buffer;
struct AHardwareBuffer_Desc;
@@ -98,10 +96,9 @@ ANDROID_API SkImageInfo ANativeWindowToImageInfo(const ANativeWindow_Buffer& buf
SkImageInfo BufferDescriptionToImageInfo(const AHardwareBuffer_Desc& bufferDesc,
sk_sp<SkColorSpace> colorSpace);
#endif
android::PixelFormat ColorTypeToPixelFormat(SkColorType colorType);
ANDROID_API SkColorType PixelFormatToColorType(android::PixelFormat format);
uint32_t ColorTypeToBufferFormat(SkColorType colorType);
#endif
ANDROID_API sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace);

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2020 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.
*/
#include <utils/NdkUtils.h>
namespace android {
namespace uirenderer {
UniqueAHardwareBuffer allocateAHardwareBuffer(const AHardwareBuffer_Desc& desc) {
AHardwareBuffer* buffer;
if (AHardwareBuffer_allocate(&desc, &buffer) != 0) {
return nullptr;
} else {
return UniqueAHardwareBuffer{buffer};
}
}
} // namespace uirenderer
} // namespace android

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2020 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 <android/hardware_buffer.h>
#include <memory>
namespace android {
namespace uirenderer {
// Deleter for an AHardwareBuffer, to be passed to an std::unique_ptr.
struct AHardwareBuffer_deleter {
void operator()(AHardwareBuffer* ahb) const { AHardwareBuffer_release(ahb); }
};
using UniqueAHardwareBuffer = std::unique_ptr<AHardwareBuffer, AHardwareBuffer_deleter>;
// Allocates a UniqueAHardwareBuffer with the provided buffer description.
// Returns nullptr if allocation did not succeed.
UniqueAHardwareBuffer allocateAHardwareBuffer(const AHardwareBuffer_Desc& desc);
} // namespace uirenderer
} // namespace android