external/gbm_gralloc
Revision | ff66db2e495ee96a82aaf55dfbb058ebb7df2c95 (tree) |
---|---|
Time | 2016-12-14 00:43:50 |
Author | Rob Herring <robh@kern...> |
Commiter | Rob Herring |
Add YV12 pixel format support
GBM doesn't support YV12 and we need a single buffer, so request GR88 from
GBM instead and adjust the width and height. GR88 also ensures (hopefully)
that the GPU texture alignment requirements are met.
Signed-off-by: Rob Herring <robh@kernel.org>
@@ -83,6 +83,9 @@ static uint32_t get_gbm_format(int format) | ||
83 | 83 | fmt = GBM_FORMAT_ARGB8888; |
84 | 84 | break; |
85 | 85 | case HAL_PIXEL_FORMAT_YV12: |
86 | + /* YV12 is planar, but must be a single buffer so ask for GR88 */ | |
87 | + fmt = GBM_FORMAT_GR88; | |
88 | + break; | |
86 | 89 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
87 | 90 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
88 | 91 | default: |
@@ -131,6 +134,12 @@ static struct gralloc_gbm_bo_t *gbm_import(struct gbm_device *gbm, | ||
131 | 134 | data.stride = handle->stride; |
132 | 135 | data.format = format; |
133 | 136 | |
137 | + /* Adjust the width and height for a GBM GR88 buffer */ | |
138 | + if (handle->format == HAL_PIXEL_FORMAT_YV12) { | |
139 | + data.width /= 2; | |
140 | + data.height += handle->height / 2; | |
141 | + } | |
142 | + | |
134 | 143 | buf->bo = gbm_bo_import(gbm, GBM_BO_IMPORT_FD, &data, 0); |
135 | 144 | if (!buf->bo) { |
136 | 145 | delete buf; |
@@ -162,6 +171,15 @@ static struct gralloc_gbm_bo_t *gbm_alloc(struct gbm_device *gbm, | ||
162 | 171 | height = 64; |
163 | 172 | } |
164 | 173 | |
174 | + /* | |
175 | + * For YV12, we request GR88, so halve the width since we're getting | |
176 | + * 16bpp. Then increase the height by 1.5 for the U and V planes. | |
177 | + */ | |
178 | + if (handle->format == HAL_PIXEL_FORMAT_YV12) { | |
179 | + width /= 2; | |
180 | + height += handle->height / 2; | |
181 | + } | |
182 | + | |
165 | 183 | ALOGD("create BO, size=%dx%d, fmt=%d, usage=%x", |
166 | 184 | handle->width, handle->height, handle->format, usage); |
167 | 185 | buf->bo = gbm_bo_create(gbm, width, height, format, usage); |
@@ -199,6 +217,13 @@ static int gbm_map(struct gralloc_gbm_bo_t *bo, int x, int y, int w, int h, | ||
199 | 217 | if (bo->map_data) |
200 | 218 | return -EINVAL; |
201 | 219 | |
220 | + if (bo->handle->format == HAL_PIXEL_FORMAT_YV12) { | |
221 | + if (x || y) | |
222 | + ALOGE("can't map with offset for planar %p - fmt %x", bo, bo->handle->format); | |
223 | + w /= 2; | |
224 | + h += h / 2; | |
225 | + } | |
226 | + | |
202 | 227 | if (enable_write) |
203 | 228 | flags |= GBM_BO_TRANSFER_WRITE; |
204 | 229 |