gralloc: Support camera and video encoder flags

- Set private flags for these formats so that the camera HAL
can differentiate between the allocated buffers.
- Usage flags define format

Change-Id: Ib3cfad12ab2ba79662207609138633769b1504e6
This commit is contained in:
Naseer Ahmed
2012-08-21 17:03:27 -04:00
committed by Iliyan Malchev
parent 3be78d9816
commit 59802500bc
3 changed files with 30 additions and 9 deletions

View File

@@ -152,6 +152,18 @@ int gpu_context_t::gralloc_alloc_buffer(size_t size, int usage,
} }
} }
if (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER ) {
flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER;
}
if (usage & GRALLOC_USAGE_HW_CAMERA_WRITE) {
flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE;
}
if (usage & GRALLOC_USAGE_HW_CAMERA_READ) {
flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ;
}
if (err == 0) { if (err == 0) {
flags |= data.allocType; flags |= data.allocType;
private_handle_t* hnd = new private_handle_t(data.fd, size, flags, private_handle_t* hnd = new private_handle_t(data.fd, size, flags,
@@ -168,19 +180,15 @@ int gpu_context_t::gralloc_alloc_buffer(size_t size, int usage,
} }
void gpu_context_t::getGrallocInformationFromFormat(int inputFormat, void gpu_context_t::getGrallocInformationFromFormat(int inputFormat,
int *colorFormat,
int *bufferType) int *bufferType)
{ {
*bufferType = BUFFER_TYPE_VIDEO; *bufferType = BUFFER_TYPE_VIDEO;
*colorFormat = inputFormat;
if (inputFormat < 0x7) { if (inputFormat < 0x7) {
// RGB formats // RGB formats
*colorFormat = inputFormat;
*bufferType = BUFFER_TYPE_UI; *bufferType = BUFFER_TYPE_UI;
} else if ((inputFormat == HAL_PIXEL_FORMAT_R_8) || } else if ((inputFormat == HAL_PIXEL_FORMAT_R_8) ||
(inputFormat == HAL_PIXEL_FORMAT_RG_88)) { (inputFormat == HAL_PIXEL_FORMAT_RG_88)) {
*colorFormat = inputFormat;
*bufferType = BUFFER_TYPE_UI; *bufferType = BUFFER_TYPE_UI;
} }
} }
@@ -193,9 +201,20 @@ int gpu_context_t::alloc_impl(int w, int h, int format, int usage,
size_t size; size_t size;
int alignedw, alignedh; int alignedw, alignedh;
int colorFormat, bufferType; int grallocFormat = format;
getGrallocInformationFromFormat(format, &colorFormat, &bufferType); int bufferType;
size = getBufferSizeAndDimensions(w, h, colorFormat, alignedw, alignedh); getGrallocInformationFromFormat(format, &bufferType);
//XXX: This should only be done if format is
// HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED
if(usage & GRALLOC_USAGE_HW_VIDEO_ENCODER)
grallocFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP; //NV12
if(usage & GRALLOC_USAGE_HW_CAMERA_READ)
grallocFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; //NV21
if(usage & GRALLOC_USAGE_HW_CAMERA_WRITE)
grallocFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; //NV21
size = getBufferSizeAndDimensions(w, h, grallocFormat, alignedw, alignedh);
if ((ssize_t)size <= 0) if ((ssize_t)size <= 0)
return -EINVAL; return -EINVAL;
@@ -213,7 +232,7 @@ int gpu_context_t::alloc_impl(int w, int h, int format, int usage,
err = gralloc_alloc_framebuffer(size, usage, pHandle); err = gralloc_alloc_framebuffer(size, usage, pHandle);
} else { } else {
err = gralloc_alloc_buffer(size, usage, pHandle, bufferType, err = gralloc_alloc_buffer(size, usage, pHandle, bufferType,
format, alignedw, alignedh); grallocFormat, alignedw, alignedh);
} }
if (err < 0) { if (err < 0) {

View File

@@ -70,7 +70,6 @@ class gpu_context_t : public alloc_device_t {
private: private:
IAllocController* mAllocCtrl; IAllocController* mAllocCtrl;
void getGrallocInformationFromFormat(int inputFormat, void getGrallocInformationFromFormat(int inputFormat,
int *colorFormat,
int *bufferType); int *bufferType);
}; };
} }

View File

@@ -157,6 +157,9 @@ struct private_handle_t : public native_handle {
PRIV_FLAGS_EXTERNAL_BLOCK = 0x00004000, PRIV_FLAGS_EXTERNAL_BLOCK = 0x00004000,
// Display this buffer on external as close caption // Display this buffer on external as close caption
PRIV_FLAGS_EXTERNAL_CC = 0x00008000, PRIV_FLAGS_EXTERNAL_CC = 0x00008000,
PRIV_FLAGS_VIDEO_ENCODER = 0x00010000,
PRIV_FLAGS_CAMERA_WRITE = 0x00020000,
PRIV_FLAGS_CAMERA_READ = 0x00040000,
}; };
// file-descriptors // file-descriptors