• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoapythonrubywindowsphpgameguibathyscaphec翻訳omegatframework計画中(planning stage)twitterdombtronvb.nettestarduinodirectxpreviewerゲームエンジン

external/gbm_gralloc


Commit MetaInfo

Revision5ddecb14af4da0dda3f3817be23f1b3c54514aec (tree)
Time2018-11-02 16:56:54
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

Merge remote-tracking branch 'origin/master' into oreo-x86

Conflicts:
gralloc_drm_handle.h

Change Summary

Incremental Difference

--- a/Android.mk
+++ b/Android.mk
@@ -27,6 +27,7 @@ LOCAL_SRC_FILES := \
2727 gralloc.cpp
2828
2929 LOCAL_SHARED_LIBRARIES := \
30+ libdrm \
3031 libgbm \
3132 liblog \
3233 libcutils
--- a/gralloc.cpp
+++ b/gralloc.cpp
@@ -38,7 +38,6 @@
3838
3939 #include "gralloc_drm.h"
4040 #include "gralloc_gbm_priv.h"
41-#include "gralloc_drm_handle.h"
4241
4342 struct gbm_module_t {
4443 gralloc_module_t base;
@@ -47,37 +46,6 @@ struct gbm_module_t {
4746 struct gbm_device *gbm;
4847 };
4948
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-
8149 /*
8250 * Initialize the DRM device object
8351 */
@@ -116,12 +84,6 @@ static int gbm_mod_perform(const struct gralloc_module_t *mod, int op, ...)
11684 err = 0;
11785 }
11886 break;
119- /* TODO: This is a stub and should be implemented fully */
120- case GRALLOC_MODULE_PERFORM_GET_USAGE:
121- {
122- err = 0;
123- }
124- break;
12587 default:
12688 err = -EINVAL;
12789 break;
@@ -217,23 +179,15 @@ static int gbm_mod_alloc_gpu0(alloc_device_t *dev,
217179 buffer_handle_t *handle, int *stride)
218180 {
219181 struct gbm_module_t *dmod = (struct gbm_module_t *) dev->common.module;
220- struct gralloc_gbm_handle_t *gbm_handle;
221182 int err = 0;
222183
223184 pthread_mutex_lock(&dmod->mutex);
224185
225- gbm_handle = gralloc_gbm_bo_create(dmod->gbm, w, h, format, usage);
226- if (!gbm_handle) {
186+ *handle = gralloc_gbm_bo_create(dmod->gbm, w, h, format, usage, stride);
187+ if (!*handle)
227188 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);
234189
235190 ALOGV("buffer %p usage = %08x", *handle, usage);
236-unlock:
237191 pthread_mutex_unlock(&dmod->mutex);
238192 return err;
239193 }
--- a/gralloc_drm.h
+++ b/gralloc_drm.h
@@ -34,13 +34,6 @@ enum {
3434 * int *fd);
3535 */
3636 GRALLOC_MODULE_PERFORM_GET_DRM_FD = 0x40000002,
37-
38- /* perform(const struct gralloc_module_t *mod,
39- * int op,
40- * buffer_handle_t buffer,
41- * int *usage);
42- */
43- GRALLOC_MODULE_PERFORM_GET_USAGE = 0xffeeff03,
4437 };
4538
4639 #ifdef __cplusplus
--- a/gralloc_drm_handle.h
+++ /dev/null
@@ -1,93 +0,0 @@
1-/*
2- * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
3- * Copyright (C) 2010-2011 LunarG Inc.
4- * Copyright (C) 2016 Linaro, Ltd., Rob Herring <robh@kernel.org>
5- *
6- * Permission is hereby granted, free of charge, to any person obtaining a
7- * copy of this software and associated documentation files (the "Software"),
8- * to deal in the Software without restriction, including without limitation
9- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10- * and/or sell copies of the Software, and to permit persons to whom the
11- * Software is furnished to do so, subject to the following conditions:
12- *
13- * The above copyright notice and this permission notice shall be included
14- * in all copies or substantial portions of the Software.
15- *
16- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22- * DEALINGS IN THE SOFTWARE.
23- */
24-
25-#ifndef _GRALLOC_DRM_HANDLE_H_
26-#define _GRALLOC_DRM_HANDLE_H_
27-
28-#include <cutils/log.h>
29-#include <cutils/native_handle.h>
30-#include <system/graphics.h>
31-
32-#ifdef __cplusplus
33-extern "C" {
34-#endif
35-
36-struct gralloc_drm_handle_t {
37- native_handle_t base;
38-
39- /* file descriptors */
40- int prime_fd;
41-
42- /* integers */
43- int magic;
44-
45- int width;
46- int height;
47- int format;
48- int usage;
49-
50- int name; /* the name of the bo */
51- int stride; /* the stride in bytes */
52- int data_owner; /* owner of data (for validation) */
53-
54- uint64_t modifier __attribute__((aligned(8))); /* buffer modifiers */
55- union {
56- void *data; /* pointer to struct gralloc_gbm_bo_t */
57- uint64_t reserved;
58- } __attribute__((aligned(8)));
59-};
60-#define GRALLOC_GBM_HANDLE_MAGIC 0x5f47424d
61-#define GRALLOC_GBM_HANDLE_NUM_FDS 1
62-#define GRALLOC_GBM_HANDLE_NUM_INTS ( \
63- ((sizeof(struct gralloc_drm_handle_t) - sizeof(native_handle_t))/sizeof(int)) \
64- - GRALLOC_GBM_HANDLE_NUM_FDS)
65-
66-static inline struct gralloc_drm_handle_t *gralloc_drm_handle(buffer_handle_t _handle)
67-{
68- struct gralloc_drm_handle_t *handle =
69- (struct gralloc_drm_handle_t *) _handle;
70-
71- if (handle && (handle->base.version != sizeof(handle->base) ||
72- handle->base.numInts != GRALLOC_GBM_HANDLE_NUM_INTS ||
73- handle->base.numFds != GRALLOC_GBM_HANDLE_NUM_FDS ||
74- handle->magic != GRALLOC_GBM_HANDLE_MAGIC)) {
75- ALOGE("invalid handle: version=%d, numInts=%d, numFds=%d, magic=%x",
76- handle->base.version, handle->base.numInts,
77- handle->base.numFds, handle->magic);
78- handle = NULL;
79- }
80-
81- return handle;
82-}
83-
84-static inline int gralloc_drm_get_prime_fd(buffer_handle_t _handle)
85-{
86- struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle);
87- return (handle) ? handle->prime_fd : -1;
88-}
89-
90-#ifdef __cplusplus
91-}
92-#endif
93-#endif /* _GRALLOC_DRM_HANDLE_H_ */
--- a/gralloc_gbm.cpp
+++ b/gralloc_gbm.cpp
@@ -41,12 +41,16 @@
4141 #include <gbm.h>
4242
4343 #include "gralloc_gbm_priv.h"
44-#include "gralloc_drm_handle.h"
44+#include <android/gralloc_handle.h>
45+
46+#include <unordered_map>
4547
4648 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
4749
4850 #define unlikely(x) __builtin_expect(!!(x), 0)
4951
52+static std::unordered_map<buffer_handle_t, struct gbm_bo *> gbm_bo_handle_map;
53+
5054 struct bo_data_t {
5155 void *map_data;
5256 int lock_count;
@@ -100,6 +104,37 @@ static uint32_t get_gbm_format(int format)
100104 return fmt;
101105 }
102106
107+static int gralloc_gbm_get_bpp(int format)
108+{
109+ int bpp;
110+
111+ switch (format) {
112+ case HAL_PIXEL_FORMAT_RGBA_8888:
113+ case HAL_PIXEL_FORMAT_RGBX_8888:
114+ case HAL_PIXEL_FORMAT_BGRA_8888:
115+ bpp = 4;
116+ break;
117+ case HAL_PIXEL_FORMAT_RGB_888:
118+ bpp = 3;
119+ break;
120+ case HAL_PIXEL_FORMAT_RGB_565:
121+ case HAL_PIXEL_FORMAT_YCbCr_422_I:
122+ bpp = 2;
123+ break;
124+ /* planar; only Y is considered */
125+ case HAL_PIXEL_FORMAT_YV12:
126+ case HAL_PIXEL_FORMAT_YCbCr_422_SP:
127+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
128+ bpp = 1;
129+ break;
130+ default:
131+ bpp = 0;
132+ break;
133+ }
134+
135+ return bpp;
136+}
137+
103138 static unsigned int get_pipe_bind(int usage)
104139 {
105140 unsigned int bind = 0;
@@ -112,14 +147,17 @@ static unsigned int get_pipe_bind(int usage)
112147 bind |= GBM_BO_USE_RENDERING;
113148 if (usage & GRALLOC_USAGE_HW_FB)
114149 bind |= GBM_BO_USE_SCANOUT;
150+ if (usage & GRALLOC_USAGE_HW_COMPOSER)
151+ bind |= GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
115152
116153 return bind;
117154 }
118155
119156 static struct gbm_bo *gbm_import(struct gbm_device *gbm,
120- struct gralloc_gbm_handle_t *handle)
157+ buffer_handle_t _handle)
121158 {
122159 struct gbm_bo *bo;
160+ struct gralloc_handle_t *handle = gralloc_handle(_handle);
123161 #ifdef GBM_BO_IMPORT_FD_MODIFIER
124162 struct gbm_import_fd_modifier_data data;
125163 #else
@@ -156,9 +194,10 @@ static struct gbm_bo *gbm_import(struct gbm_device *gbm,
156194 }
157195
158196 static struct gbm_bo *gbm_alloc(struct gbm_device *gbm,
159- struct gralloc_gbm_handle_t *handle)
197+ buffer_handle_t _handle)
160198 {
161199 struct gbm_bo *bo;
200+ struct gralloc_handle_t *handle = gralloc_handle(_handle);
162201 int format = get_gbm_format(handle->format);
163202 int usage = get_pipe_bind(handle->usage);
164203 int width, height;
@@ -206,6 +245,7 @@ void gbm_free(buffer_handle_t handle)
206245 if (!bo)
207246 return;
208247
248+ gbm_bo_handle_map.erase(handle);
209249 gbm_bo_destroy(bo);
210250 }
211251
@@ -214,18 +254,7 @@ void gbm_free(buffer_handle_t handle)
214254 */
215255 struct gbm_bo *gralloc_gbm_bo_from_handle(buffer_handle_t handle)
216256 {
217- int pid = getpid();
218- struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
219-
220- if (!gbm_handle)
221- return NULL;
222-
223- /* the buffer handle is passed to a new process */
224- ALOGV("data_owner=%d gralloc_pid=%d data=%p\n", gbm_handle->data_owner, pid, gbm_handle->data);
225- if (gbm_handle->data_owner == pid)
226- return (struct gbm_bo *)gbm_handle->data;
227-
228- return NULL;
257+ return gbm_bo_handle_map[handle];
229258 }
230259
231260 static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h,
@@ -233,7 +262,7 @@ static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h,
233262 {
234263 int err = 0;
235264 int flags = GBM_BO_TRANSFER_READ;
236- struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
265+ struct gralloc_gbm_handle_t *gbm_handle = gralloc_handle(handle);
237266 struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle);
238267 struct bo_data_t *bo_data = gbm_bo_data(bo);
239268 uint32_t stride;
@@ -243,7 +272,7 @@ static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h,
243272
244273 if (gbm_handle->format == HAL_PIXEL_FORMAT_YV12) {
245274 if (x || y)
246- ALOGE("can't map with offset for planar %p - fmt %x", bo, gbm_handle->format);
275+ ALOGE("can't map with offset for planar %p", bo);
247276 w /= 2;
248277 h += h / 2;
249278 }
@@ -305,17 +334,18 @@ struct gbm_device *gbm_dev_create(void)
305334 int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm)
306335 {
307336 struct gbm_bo *bo;
308- struct gralloc_gbm_handle_t *handle = gralloc_gbm_handle(_handle);
309337
310- if (!handle)
338+ if (!_handle)
311339 return -EINVAL;
312340
313- bo = gbm_import(gbm, handle);
341+ if (gbm_bo_handle_map.count(_handle))
342+ return -EINVAL;
343+
344+ bo = gbm_import(gbm, _handle);
314345 if (!bo)
315346 return -EINVAL;
316347
317- handle->data_owner = getpid();
318- handle->data = bo;
348+ gbm_bo_handle_map.emplace(_handle, bo);
319349
320350 return 0;
321351 }
@@ -325,58 +355,34 @@ int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm)
325355 */
326356 int gralloc_gbm_handle_unregister(buffer_handle_t handle)
327357 {
328- struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
329-
330358 gbm_free(handle);
331- gbm_handle->data_owner = 0;
332- gbm_handle->data = NULL;
333359
334360 return 0;
335361 }
336362
337363 /*
338- * Create a buffer handle.
339- */
340-static struct gralloc_gbm_handle_t *create_bo_handle(int width,
341- int height, int format, int usage)
342-{
343- struct gralloc_gbm_handle_t *handle;
344-
345- handle = (gralloc_gbm_handle_t *)native_handle_create(GRALLOC_GBM_HANDLE_NUM_FDS, GRALLOC_GBM_HANDLE_NUM_INTS);
346- if (!handle)
347- return NULL;
348-
349- handle->magic = GRALLOC_GBM_HANDLE_MAGIC;
350- handle->width = width;
351- handle->height = height;
352- handle->format = format;
353- handle->usage = usage;
354- handle->prime_fd = -1;
355-
356- return handle;
357-}
358-
359-/*
360364 * Create a bo.
361365 */
362-struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm,
363- int width, int height, int format, int usage)
366+buffer_handle_t gralloc_gbm_bo_create(struct gbm_device *gbm,
367+ int width, int height, int format, int usage, int *stride)
364368 {
365369 struct gbm_bo *bo;
366- struct gralloc_gbm_handle_t *handle;
370+ native_handle_t *handle;
367371
368- handle = create_bo_handle(width, height, format, usage);
372+ handle = gralloc_handle_create(width, height, format, usage);
369373 if (!handle)
370374 return NULL;
371375
372376 bo = gbm_alloc(gbm, handle);
373377 if (!bo) {
374- native_handle_delete(&handle->base);
378+ native_handle_delete(handle);
375379 return NULL;
376380 }
377381
378- handle->data_owner = getpid();
379- handle->data = bo;
382+ gbm_bo_handle_map.emplace(handle, bo);
383+
384+ /* in pixels */
385+ *stride = gralloc_handle(handle)->stride / gralloc_gbm_get_bpp(format);
380386
381387 return handle;
382388 }
@@ -388,14 +394,14 @@ int gralloc_gbm_bo_lock(buffer_handle_t handle,
388394 int usage, int x, int y, int w, int h,
389395 void **addr)
390396 {
391- struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
397+ struct gralloc_handle_t *gbm_handle = gralloc_handle(handle);
392398 struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle);
393399 struct bo_data_t *bo_data;
394400
395401 if (!bo)
396402 return -EINVAL;
397403
398- if ((gbm_handle->usage & usage) != usage) {
404+ if ((gbm_handle->usage & usage) != (uint32_t)usage) {
399405 /* make FB special for testing software renderer with */
400406
401407 if (!(gbm_handle->usage & GRALLOC_USAGE_SW_READ_OFTEN) &&
--- a/gralloc_gbm_priv.h
+++ b/gralloc_gbm_priv.h
@@ -32,14 +32,11 @@ extern "C" {
3232 struct gbm_device;
3333 struct gbm_bo;
3434
35-#define gralloc_gbm_handle_t gralloc_drm_handle_t
36-#define gralloc_gbm_handle gralloc_drm_handle
37-
3835 int gralloc_gbm_handle_register(buffer_handle_t handle, struct gbm_device *gbm);
3936 int gralloc_gbm_handle_unregister(buffer_handle_t handle);
4037
41-struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm,
42- int width, int height, int format, int usage);
38+buffer_handle_t gralloc_gbm_bo_create(struct gbm_device *gbm,
39+ int width, int height, int format, int usage, int *stride);
4340 void gbm_free(buffer_handle_t handle);
4441
4542 struct gbm_bo *gralloc_gbm_bo_from_handle(buffer_handle_t handle);