[Mesa-dev] [PATCH v2 6/7] egl/android: Add support for YV12 pixel format (v2)
Rob Herring
robh at kernel.org
Mon Aug 8 20:58:24 UTC 2016
On Mon, Aug 8, 2016 at 1:39 PM, Chad Versace <chad at kiwitree.net> wrote:
> On 08/02/2016 04:07 AM, Tomasz Figa wrote:
>>
>> This patch adds support for YV12 pixel format to the Android platform
>> backend. Only creating EGL images is supported, it is not added to the
>> list of available visuals.
>>
>> v2: Use const array defined just for YV12 instead of trying to be overly
>> generic.
>>
>> Signed-off-by: Tomasz Figa <tfiga at chromium.org>
>> Signed-off-by: Kalyan Kondapally <kalyan.kondapally at intel.com>
>> ---
>> src/egl/drivers/dri2/platform_android.c | 56
>> +++++++++++++++++++++++++++++----
>> 1 file changed, 50 insertions(+), 6 deletions(-)
>
>
>
>
>> @@ -512,22 +518,60 @@ static _EGLImage *
>> droid_create_image_from_prime_fd(_EGLDisplay *disp, _EGLContext *ctx,
>> struct ANativeWindowBuffer *buf, int fd)
>> {
>> + unsigned int offsets[3] = { 0, 0, 0 };
>> + unsigned int pitches[3] = { 0, 0, 0 };
>> +
>> const int fourcc = get_fourcc(buf->format);
>> - const int pitch = buf->stride * get_format_bpp(buf->format);
>> + if (fourcc == -1) {
>> + _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
>> + return NULL;
>> + }
>>
>> - const EGLint attr_list[14] = {
>> + pitches[0] = buf->stride * get_format_bpp(buf->format);
>> + if (pitches[0] == 0) {
>> + _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
>> + return NULL;
>> + }
>> +
>> + switch (buf->format) {
>> + case HAL_PIXEL_FORMAT_YV12:
>> + /* Y plane is assumed to be at offset 0. */
>> + /* Cr plane is located after Y plane */
>> + offsets[1] = offsets[0] + pitches[0] * buf->height;
>> + pitches[1] = ALIGN(pitches[0] / 2, 16);
>> + /* Cb plane is located after Cr plane */
>> + offsets[2] = offsets[1] + pitches[1] * buf->height / 2;
>
>
> I believe the above should be
> offsets[2] = offsets[1] + pitches[1] * ALIGN(buf->height, 2) / 2;
> to accommodate buffers with odd height.
Android defines this format is even height and width with a stride
multiple of 16 pixels:
/*
* Android YUV format:
*
* This format is exposed outside of the HAL to software decoders and
* applications. EGLImageKHR must support it in conjunction with the
* OES_EGL_image_external extension.
*
* YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
* by (W/2) x (H/2) Cr and Cb planes.
*
* This format assumes
* - an even width
* - an even height
* - a horizontal stride multiple of 16 pixels
* - a vertical stride equal to the height
*
* y_size = stride * height
* c_stride = ALIGN(stride/2, 16)
* c_size = c_stride * height/2
* size = y_size + c_size * 2
* cr_offset = y_size
* cb_offset = y_size + c_size
*
* When used with ANativeWindow, the dataSpace field describes the color
* space of the buffer.
*/
Rob
More information about the mesa-dev
mailing list