gralloc1: Add support for layered buffers
Implements the gralloc1 capability GRALLOC1_CAPABILITY_LAYERED_BUFFERS. CRs-Fixed: 2025988 Change-Id: I80c8ef6aa18844e33ecd8b019c6f4cf08872afb5
This commit is contained in:
@@ -65,6 +65,8 @@ class BufferDescriptor {
|
|||||||
|
|
||||||
void SetColorFormat(int format) { format_ = format; }
|
void SetColorFormat(int format) { format_ = format; }
|
||||||
|
|
||||||
|
void SetLayerCount(uint32_t layer_count) { layer_count_ = layer_count; }
|
||||||
|
|
||||||
gralloc1_consumer_usage_t GetConsumerUsage() const { return consumer_usage_; }
|
gralloc1_consumer_usage_t GetConsumerUsage() const { return consumer_usage_; }
|
||||||
|
|
||||||
gralloc1_producer_usage_t GetProducerUsage() const { return producer_usage_; }
|
gralloc1_producer_usage_t GetProducerUsage() const { return producer_usage_; }
|
||||||
@@ -75,12 +77,15 @@ class BufferDescriptor {
|
|||||||
|
|
||||||
int GetFormat() const { return format_; }
|
int GetFormat() const { return format_; }
|
||||||
|
|
||||||
|
uint32_t GetLayerCount() const { return layer_count_; }
|
||||||
|
|
||||||
gralloc1_buffer_descriptor_t GetId() const { return id_; }
|
gralloc1_buffer_descriptor_t GetId() const { return id_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int width_ = -1;
|
int width_ = -1;
|
||||||
int height_ = -1;
|
int height_ = -1;
|
||||||
int format_ = -1;
|
int format_ = -1;
|
||||||
|
uint32_t layer_count_ = 1;
|
||||||
gralloc1_producer_usage_t producer_usage_ = GRALLOC1_PRODUCER_USAGE_NONE;
|
gralloc1_producer_usage_t producer_usage_ = GRALLOC1_PRODUCER_USAGE_NONE;
|
||||||
gralloc1_consumer_usage_t consumer_usage_ = GRALLOC1_CONSUMER_USAGE_NONE;
|
gralloc1_consumer_usage_t consumer_usage_ = GRALLOC1_CONSUMER_USAGE_NONE;
|
||||||
const gralloc1_buffer_descriptor_t id_;
|
const gralloc1_buffer_descriptor_t id_;
|
||||||
|
|||||||
@@ -469,6 +469,7 @@ int BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_han
|
|||||||
int format = descriptor.GetFormat();
|
int format = descriptor.GetFormat();
|
||||||
gralloc1_producer_usage_t prod_usage = descriptor.GetProducerUsage();
|
gralloc1_producer_usage_t prod_usage = descriptor.GetProducerUsage();
|
||||||
gralloc1_consumer_usage_t cons_usage = descriptor.GetConsumerUsage();
|
gralloc1_consumer_usage_t cons_usage = descriptor.GetConsumerUsage();
|
||||||
|
uint32_t layer_count = descriptor.GetLayerCount();
|
||||||
|
|
||||||
// Get implementation defined format
|
// Get implementation defined format
|
||||||
int gralloc_format = allocator_->GetImplDefinedFormat(prod_usage, cons_usage, format);
|
int gralloc_format = allocator_->GetImplDefinedFormat(prod_usage, cons_usage, format);
|
||||||
@@ -478,6 +479,7 @@ int BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_han
|
|||||||
int buffer_type = GetBufferType(gralloc_format);
|
int buffer_type = GetBufferType(gralloc_format);
|
||||||
allocator_->GetBufferSizeAndDimensions(descriptor, &size, &alignedw, &alignedh);
|
allocator_->GetBufferSizeAndDimensions(descriptor, &size, &alignedw, &alignedh);
|
||||||
size = (bufferSize >= size) ? bufferSize : size;
|
size = (bufferSize >= size) ? bufferSize : size;
|
||||||
|
size = size * layer_count;
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
@@ -528,6 +530,7 @@ int BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_han
|
|||||||
hnd->id = ++next_id_;
|
hnd->id = ++next_id_;
|
||||||
hnd->base = 0;
|
hnd->base = 0;
|
||||||
hnd->base_metadata = 0;
|
hnd->base_metadata = 0;
|
||||||
|
hnd->layer_count = layer_count;
|
||||||
|
|
||||||
ColorSpace_t colorSpace = ITU_R_601;
|
ColorSpace_t colorSpace = ITU_R_601;
|
||||||
setMetaData(hnd, UPDATE_COLOR_SPACE, reinterpret_cast<void *>(&colorSpace));
|
setMetaData(hnd, UPDATE_COLOR_SPACE, reinterpret_cast<void *>(&colorSpace));
|
||||||
|
|||||||
@@ -103,10 +103,11 @@ int GrallocImpl::CloseDevice(hw_device_t *device __unused) {
|
|||||||
void GrallocImpl::GetCapabilities(struct gralloc1_device *device, uint32_t *out_count,
|
void GrallocImpl::GetCapabilities(struct gralloc1_device *device, uint32_t *out_count,
|
||||||
int32_t /*gralloc1_capability_t*/ *out_capabilities) {
|
int32_t /*gralloc1_capability_t*/ *out_capabilities) {
|
||||||
if (device != nullptr) {
|
if (device != nullptr) {
|
||||||
if (out_capabilities != nullptr && *out_count > 0) {
|
if (out_capabilities != nullptr && *out_count >= 2) {
|
||||||
out_capabilities[0] = GRALLOC1_CAPABILITY_TEST_ALLOCATE;
|
out_capabilities[0] = GRALLOC1_CAPABILITY_TEST_ALLOCATE;
|
||||||
|
out_capabilities[1] = GRALLOC1_CAPABILITY_LAYERED_BUFFERS;
|
||||||
}
|
}
|
||||||
*out_count = 1;
|
*out_count = 2;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -129,6 +130,8 @@ gralloc1_function_pointer_t GrallocImpl::GetFunction(gralloc1_device_t *device,
|
|||||||
return reinterpret_cast<gralloc1_function_pointer_t>(SetBufferDimensions);
|
return reinterpret_cast<gralloc1_function_pointer_t>(SetBufferDimensions);
|
||||||
case GRALLOC1_FUNCTION_SET_FORMAT:
|
case GRALLOC1_FUNCTION_SET_FORMAT:
|
||||||
return reinterpret_cast<gralloc1_function_pointer_t>(SetColorFormat);
|
return reinterpret_cast<gralloc1_function_pointer_t>(SetColorFormat);
|
||||||
|
case GRALLOC1_FUNCTION_SET_LAYER_COUNT:
|
||||||
|
return reinterpret_cast<gralloc1_function_pointer_t>(SetLayerCount);
|
||||||
case GRALLOC1_FUNCTION_SET_PRODUCER_USAGE:
|
case GRALLOC1_FUNCTION_SET_PRODUCER_USAGE:
|
||||||
return reinterpret_cast<gralloc1_function_pointer_t>(SetProducerUsage);
|
return reinterpret_cast<gralloc1_function_pointer_t>(SetProducerUsage);
|
||||||
case GRALLOC1_FUNCTION_GET_BACKING_STORE:
|
case GRALLOC1_FUNCTION_GET_BACKING_STORE:
|
||||||
@@ -139,6 +142,8 @@ gralloc1_function_pointer_t GrallocImpl::GetFunction(gralloc1_device_t *device,
|
|||||||
return reinterpret_cast<gralloc1_function_pointer_t>(GetBufferDimensions);
|
return reinterpret_cast<gralloc1_function_pointer_t>(GetBufferDimensions);
|
||||||
case GRALLOC1_FUNCTION_GET_FORMAT:
|
case GRALLOC1_FUNCTION_GET_FORMAT:
|
||||||
return reinterpret_cast<gralloc1_function_pointer_t>(GetColorFormat);
|
return reinterpret_cast<gralloc1_function_pointer_t>(GetColorFormat);
|
||||||
|
case GRALLOC1_FUNCTION_GET_LAYER_COUNT:
|
||||||
|
return reinterpret_cast<gralloc1_function_pointer_t>(GetLayerCount);
|
||||||
case GRALLOC1_FUNCTION_GET_PRODUCER_USAGE:
|
case GRALLOC1_FUNCTION_GET_PRODUCER_USAGE:
|
||||||
return reinterpret_cast<gralloc1_function_pointer_t>(GetProducerUsage);
|
return reinterpret_cast<gralloc1_function_pointer_t>(GetProducerUsage);
|
||||||
case GRALLOC1_FUNCTION_GET_STRIDE:
|
case GRALLOC1_FUNCTION_GET_STRIDE:
|
||||||
@@ -257,6 +262,19 @@ gralloc1_error_t GrallocImpl::SetColorFormat(gralloc1_device_t *device,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gralloc1_error_t GrallocImpl::SetLayerCount(gralloc1_device_t *device,
|
||||||
|
gralloc1_buffer_descriptor_t descriptor,
|
||||||
|
uint32_t layer_count) {
|
||||||
|
if (!device) {
|
||||||
|
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
||||||
|
} else {
|
||||||
|
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
||||||
|
return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
|
||||||
|
&BufferDescriptor::SetLayerCount,
|
||||||
|
layer_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gralloc1_error_t GrallocImpl::SetProducerUsage(gralloc1_device_t *device,
|
gralloc1_error_t GrallocImpl::SetProducerUsage(gralloc1_device_t *device,
|
||||||
gralloc1_buffer_descriptor_t descriptor,
|
gralloc1_buffer_descriptor_t descriptor,
|
||||||
gralloc1_producer_usage_t usage) {
|
gralloc1_producer_usage_t usage) {
|
||||||
@@ -313,6 +331,16 @@ gralloc1_error_t GrallocImpl::GetColorFormat(gralloc1_device_t *device, buffer_h
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gralloc1_error_t GrallocImpl::GetLayerCount(gralloc1_device_t *device, buffer_handle_t buffer,
|
||||||
|
uint32_t *outLayerCount) {
|
||||||
|
gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
|
||||||
|
if (status == GRALLOC1_ERROR_NONE) {
|
||||||
|
*outLayerCount = PRIV_HANDLE_CONST(buffer)->GetLayerCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
gralloc1_error_t GrallocImpl::GetProducerUsage(gralloc1_device_t *device, buffer_handle_t buffer,
|
gralloc1_error_t GrallocImpl::GetProducerUsage(gralloc1_device_t *device, buffer_handle_t buffer,
|
||||||
gralloc1_producer_usage_t *outUsage) {
|
gralloc1_producer_usage_t *outUsage) {
|
||||||
gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
|
gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ class GrallocImpl : public gralloc1_device_t {
|
|||||||
uint32_t width, uint32_t height);
|
uint32_t width, uint32_t height);
|
||||||
static gralloc1_error_t SetColorFormat(gralloc1_device_t *device,
|
static gralloc1_error_t SetColorFormat(gralloc1_device_t *device,
|
||||||
gralloc1_buffer_descriptor_t descriptor, int32_t format);
|
gralloc1_buffer_descriptor_t descriptor, int32_t format);
|
||||||
|
static gralloc1_error_t SetLayerCount(gralloc1_device_t *device,
|
||||||
|
gralloc1_buffer_descriptor_t descriptor,
|
||||||
|
uint32_t layer_count);
|
||||||
static gralloc1_error_t SetProducerUsage(gralloc1_device_t *device,
|
static gralloc1_error_t SetProducerUsage(gralloc1_device_t *device,
|
||||||
gralloc1_buffer_descriptor_t descriptor,
|
gralloc1_buffer_descriptor_t descriptor,
|
||||||
gralloc1_producer_usage_t usage);
|
gralloc1_producer_usage_t usage);
|
||||||
@@ -87,6 +90,8 @@ class GrallocImpl : public gralloc1_device_t {
|
|||||||
uint32_t *out_width, uint32_t *out_height);
|
uint32_t *out_width, uint32_t *out_height);
|
||||||
static gralloc1_error_t GetColorFormat(gralloc1_device_t *device, buffer_handle_t descriptor,
|
static gralloc1_error_t GetColorFormat(gralloc1_device_t *device, buffer_handle_t descriptor,
|
||||||
int32_t *outFormat);
|
int32_t *outFormat);
|
||||||
|
static gralloc1_error_t GetLayerCount(gralloc1_device_t *device, buffer_handle_t buffer,
|
||||||
|
uint32_t *out_layer_count);
|
||||||
static gralloc1_error_t GetProducerUsage(gralloc1_device_t *device, buffer_handle_t buffer,
|
static gralloc1_error_t GetProducerUsage(gralloc1_device_t *device, buffer_handle_t buffer,
|
||||||
gralloc1_producer_usage_t *out_usage);
|
gralloc1_producer_usage_t *out_usage);
|
||||||
static gralloc1_error_t GetBufferStride(gralloc1_device_t *device, buffer_handle_t buffer,
|
static gralloc1_error_t GetBufferStride(gralloc1_device_t *device, buffer_handle_t buffer,
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ struct private_handle_t : public native_handle_t {
|
|||||||
uint64_t id __attribute__((aligned(8)));
|
uint64_t id __attribute__((aligned(8)));
|
||||||
gralloc1_producer_usage_t producer_usage __attribute__((aligned(8)));
|
gralloc1_producer_usage_t producer_usage __attribute__((aligned(8)));
|
||||||
gralloc1_consumer_usage_t consumer_usage __attribute__((aligned(8)));
|
gralloc1_consumer_usage_t consumer_usage __attribute__((aligned(8)));
|
||||||
|
unsigned int layer_count;
|
||||||
|
|
||||||
static const int kNumFds = 2;
|
static const int kNumFds = 2;
|
||||||
static const int kMagic = 'gmsm';
|
static const int kMagic = 'gmsm';
|
||||||
@@ -123,7 +124,8 @@ struct private_handle_t : public native_handle_t {
|
|||||||
gpuaddr(0),
|
gpuaddr(0),
|
||||||
id(0),
|
id(0),
|
||||||
producer_usage(prod_usage),
|
producer_usage(prod_usage),
|
||||||
consumer_usage(cons_usage) {
|
consumer_usage(cons_usage),
|
||||||
|
layer_count(1) {
|
||||||
version = static_cast<int>(sizeof(native_handle));
|
version = static_cast<int>(sizeof(native_handle));
|
||||||
numInts = NumInts();
|
numInts = NumInts();
|
||||||
numFds = kNumFds;
|
numFds = kNumFds;
|
||||||
@@ -162,11 +164,11 @@ struct private_handle_t : public native_handle_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Dump(const private_handle_t *hnd) {
|
static void Dump(const private_handle_t *hnd) {
|
||||||
ALOGD("handle id:%" PRIu64 " wxh:%dx%d uwxuh:%dx%d size: %d fd:%d fd_meta:%d flags:0x%x"
|
ALOGD("handle id:%" PRIu64 " wxh:%dx%d uwxuh:%dx%d size: %d fd:%d fd_meta:%d flags:0x%x "
|
||||||
"prod_usage:0x%" PRIx64" cons_usage:0x%" PRIx64 "format:0x%x",
|
"prod_usage:0x%" PRIx64" cons_usage:0x%" PRIx64 " format:0x%x layer_count: %d",
|
||||||
hnd->id, hnd->width, hnd->height, hnd->unaligned_width, hnd->unaligned_height, hnd->size,
|
hnd->id, hnd->width, hnd->height, hnd->unaligned_width, hnd->unaligned_height, hnd->size,
|
||||||
hnd->fd, hnd->fd_metadata, hnd->flags, hnd->producer_usage, hnd->consumer_usage,
|
hnd->fd, hnd->fd_metadata, hnd->flags, hnd->producer_usage, hnd->consumer_usage,
|
||||||
hnd->format);
|
hnd->format, hnd->layer_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetUnalignedWidth() const { return unaligned_width; }
|
int GetUnalignedWidth() const { return unaligned_width; }
|
||||||
@@ -175,6 +177,8 @@ struct private_handle_t : public native_handle_t {
|
|||||||
|
|
||||||
int GetColorFormat() const { return format; }
|
int GetColorFormat() const { return format; }
|
||||||
|
|
||||||
|
unsigned int GetLayerCount() const { return layer_count; }
|
||||||
|
|
||||||
int GetStride() const {
|
int GetStride() const {
|
||||||
// In handle we currently store aligned width after allocation.
|
// In handle we currently store aligned width after allocation.
|
||||||
return width;
|
return width;
|
||||||
|
|||||||
Reference in New Issue
Block a user