external/gbm_gralloc
Revisão | 82c0082b4e88b0770e3517fce76d72adfc32e499 (tree) |
---|---|
Hora | 2018-07-03 07:43:28 |
Autor | Rob Herring <robh@kern...> |
Commiter | Rob Herring |
Move gralloc_gbm_handle_t accesses into gralloc_gbm.cpp
The only access to the gralloc_gbm_handle_t in gralloc.cpp is to set the
stride of allocated buffers. Move this into gralloc_gbm.cpp to isolate
accesses to the struct in one place.
Signed-off-by: Rob Herring <robh@kernel.org>
@@ -38,7 +38,6 @@ | ||
38 | 38 | |
39 | 39 | #include "gralloc_drm.h" |
40 | 40 | #include "gralloc_gbm_priv.h" |
41 | -#include "gralloc_drm_handle.h" | |
42 | 41 | |
43 | 42 | struct gbm_module_t { |
44 | 43 | gralloc_module_t base; |
@@ -47,37 +46,6 @@ struct gbm_module_t { | ||
47 | 46 | struct gbm_device *gbm; |
48 | 47 | }; |
49 | 48 | |
50 | -static inline int gralloc_gbm_get_bpp(int format) | |
51 | -{ | |
52 | - int bpp; | |
53 | - | |
54 | - switch (format) { | |
55 | - case HAL_PIXEL_FORMAT_RGBA_8888: | |
56 | - case HAL_PIXEL_FORMAT_RGBX_8888: | |
57 | - case HAL_PIXEL_FORMAT_BGRA_8888: | |
58 | - bpp = 4; | |
59 | - break; | |
60 | - case HAL_PIXEL_FORMAT_RGB_888: | |
61 | - bpp = 3; | |
62 | - break; | |
63 | - case HAL_PIXEL_FORMAT_RGB_565: | |
64 | - case HAL_PIXEL_FORMAT_YCbCr_422_I: | |
65 | - bpp = 2; | |
66 | - break; | |
67 | - /* planar; only Y is considered */ | |
68 | - case HAL_PIXEL_FORMAT_YV12: | |
69 | - case HAL_PIXEL_FORMAT_YCbCr_422_SP: | |
70 | - case HAL_PIXEL_FORMAT_YCrCb_420_SP: | |
71 | - bpp = 1; | |
72 | - break; | |
73 | - default: | |
74 | - bpp = 0; | |
75 | - break; | |
76 | - } | |
77 | - | |
78 | - return bpp; | |
79 | -} | |
80 | - | |
81 | 49 | /* |
82 | 50 | * Initialize the DRM device object |
83 | 51 | */ |
@@ -217,23 +185,15 @@ static int gbm_mod_alloc_gpu0(alloc_device_t *dev, | ||
217 | 185 | buffer_handle_t *handle, int *stride) |
218 | 186 | { |
219 | 187 | struct gbm_module_t *dmod = (struct gbm_module_t *) dev->common.module; |
220 | - struct gralloc_gbm_handle_t *gbm_handle; | |
221 | 188 | int err = 0; |
222 | 189 | |
223 | 190 | pthread_mutex_lock(&dmod->mutex); |
224 | 191 | |
225 | - gbm_handle = gralloc_gbm_bo_create(dmod->gbm, w, h, format, usage); | |
226 | - if (!gbm_handle) { | |
192 | + *handle = gralloc_gbm_bo_create(dmod->gbm, w, h, format, usage, stride); | |
193 | + if (!*handle) | |
227 | 194 | err = -errno; |
228 | - goto unlock; | |
229 | - } | |
230 | - | |
231 | - *handle = &gbm_handle->base; | |
232 | - /* in pixels */ | |
233 | - *stride = gbm_handle->stride / gralloc_gbm_get_bpp(format); | |
234 | 195 | |
235 | 196 | ALOGV("buffer %p usage = %08x", *handle, usage); |
236 | -unlock: | |
237 | 197 | pthread_mutex_unlock(&dmod->mutex); |
238 | 198 | return err; |
239 | 199 | } |
@@ -100,6 +100,37 @@ static uint32_t get_gbm_format(int format) | ||
100 | 100 | return fmt; |
101 | 101 | } |
102 | 102 | |
103 | +static int gralloc_gbm_get_bpp(int format) | |
104 | +{ | |
105 | + int bpp; | |
106 | + | |
107 | + switch (format) { | |
108 | + case HAL_PIXEL_FORMAT_RGBA_8888: | |
109 | + case HAL_PIXEL_FORMAT_RGBX_8888: | |
110 | + case HAL_PIXEL_FORMAT_BGRA_8888: | |
111 | + bpp = 4; | |
112 | + break; | |
113 | + case HAL_PIXEL_FORMAT_RGB_888: | |
114 | + bpp = 3; | |
115 | + break; | |
116 | + case HAL_PIXEL_FORMAT_RGB_565: | |
117 | + case HAL_PIXEL_FORMAT_YCbCr_422_I: | |
118 | + bpp = 2; | |
119 | + break; | |
120 | + /* planar; only Y is considered */ | |
121 | + case HAL_PIXEL_FORMAT_YV12: | |
122 | + case HAL_PIXEL_FORMAT_YCbCr_422_SP: | |
123 | + case HAL_PIXEL_FORMAT_YCrCb_420_SP: | |
124 | + bpp = 1; | |
125 | + break; | |
126 | + default: | |
127 | + bpp = 0; | |
128 | + break; | |
129 | + } | |
130 | + | |
131 | + return bpp; | |
132 | +} | |
133 | + | |
103 | 134 | static unsigned int get_pipe_bind(int usage) |
104 | 135 | { |
105 | 136 | unsigned int bind = 0; |
@@ -359,8 +390,8 @@ static struct gralloc_gbm_handle_t *create_bo_handle(int width, | ||
359 | 390 | /* |
360 | 391 | * Create a bo. |
361 | 392 | */ |
362 | -struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm, | |
363 | - int width, int height, int format, int usage) | |
393 | +buffer_handle_t gralloc_gbm_bo_create(struct gbm_device *gbm, | |
394 | + int width, int height, int format, int usage, int *stride) | |
364 | 395 | { |
365 | 396 | struct gbm_bo *bo; |
366 | 397 | struct gralloc_gbm_handle_t *handle; |
@@ -378,7 +409,10 @@ struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm, | ||
378 | 409 | handle->data_owner = getpid(); |
379 | 410 | handle->data = bo; |
380 | 411 | |
381 | - return handle; | |
412 | + /* in pixels */ | |
413 | + *stride = handle->stride / gralloc_gbm_get_bpp(format); | |
414 | + | |
415 | + return &handle->base; | |
382 | 416 | } |
383 | 417 | |
384 | 418 | /* |
@@ -38,8 +38,8 @@ struct gbm_bo; | ||
38 | 38 | int gralloc_gbm_handle_register(buffer_handle_t handle, struct gbm_device *gbm); |
39 | 39 | int gralloc_gbm_handle_unregister(buffer_handle_t handle); |
40 | 40 | |
41 | -struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm, | |
42 | - int width, int height, int format, int usage); | |
41 | +buffer_handle_t gralloc_gbm_bo_create(struct gbm_device *gbm, | |
42 | + int width, int height, int format, int usage, int *stride); | |
43 | 43 | void gbm_free(buffer_handle_t handle); |
44 | 44 | |
45 | 45 | struct gbm_bo *gralloc_gbm_bo_from_handle(buffer_handle_t handle); |