aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Foss2017-12-06 12:28:13 -0600
committerRobert Foss2018-02-14 10:33:57 -0600
commita4b6fd651f1b34f13eb3a3bc101a34adfa3b54a5 (patch)
treea4a049fe69846b28414746a78c9db6f684ca9230 /android
parent03f80b9f6a6f28e4942b1685a205a9484b2a0d63 (diff)
downloadexternal-libgbm-a4b6fd651f1b34f13eb3a3bc101a34adfa3b54a5.tar.gz
external-libgbm-a4b6fd651f1b34f13eb3a3bc101a34adfa3b54a5.tar.xz
external-libgbm-a4b6fd651f1b34f13eb3a3bc101a34adfa3b54a5.zip
android: Move gralloc handle struct to libdrm
This struct is used in mesa and drm_hwcomposer. Versions of if have been implemented in several grallocs: drm_gralloc, gbm_gralloc, minigbm and intel-minigbm. Other than the 1:1 move of the struct a new generic name has been chosen and variables have had comments added to them. Signed-off-by: Robert Foss <robert.foss@collabora.com> Reviewed-by: Rob Herring <robh@kernel.org>
Diffstat (limited to 'android')
-rw-r--r--android/gralloc_handle.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/android/gralloc_handle.h b/android/gralloc_handle.h
new file mode 100644
index 00000000..45b9f2e9
--- /dev/null
+++ b/android/gralloc_handle.h
@@ -0,0 +1,101 @@
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 * Copyright (C) 2018 Collabora, Robert Foss <robert.foss@collabora.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26#ifndef __ANDROID_GRALLOC_HANDLE_H__
27#define __ANDROID_GRALLOC_HANDLE_H__
28
29#include <cutils/native_handle.h>
30
31/* support users of drm_gralloc/gbm_gralloc */
32#define gralloc_gbm_handle_t gralloc_handle_t
33#define gralloc_drm_handle_t gralloc_handle_t
34
35struct gralloc_handle_t {
36 native_handle_t base;
37
38 /* dma-buf file descriptor
39 * Must be located first since, native_handle_t is allocated
40 * using native_handle_create(), which allocates space for
41 * sizeof(native_handle_t) + sizeof(int) * (numFds + numInts)
42 * numFds = GRALLOC_HANDLE_NUM_FDS
43 * numInts = GRALLOC_HANDLE_NUM_INTS
44 * Where numFds represents the number of FDs and
45 * numInts represents the space needed for the
46 * remainder of this struct.
47 * And the FDs are expected to be found first following
48 * native_handle_t.
49 */
50 int prime_fd;
51
52 int magic; /* differentiate between allocator impls */
53
54 int width; /* width of buffer in pixels */
55 int height; /* height of buffer in pixels */
56 int format; /* pixel format (Android) */
57 int usage; /* android libhardware usage flags */
58
59 int name; /* the name of the bo */
60 int stride; /* the stride in bytes */
61 uint64_t modifier; /* buffer modifiers */
62
63 int data_owner; /* owner of data (for validation) */
64 union {
65 void *data; /* pointer to struct gralloc_gbm_bo_t */
66 uint64_t reserved;
67 } __attribute__((aligned(8)));
68};
69
70#define GRALLOC_HANDLE_MAGIC 0x60585350
71#define GRALLOC_HANDLE_NUM_FDS 1
72#define GRALLOC_HANDLE_NUM_INTS ( \
73 ((sizeof(struct alloc_handle_t) - sizeof(native_handle_t))/sizeof(int)) \
74 - GRALLOC_HANDLE_NUM_FDS)
75
76/**
77 * Create a buffer handle.
78 */
79static struct gralloc_handle_t gralloc_handle_create(int width, int height,
80 int format, int usage)
81{
82 struct gralloc_handle_t handle = { .magic = GRALLOC_HANDLE_MAGIC };
83
84 native_handle_t *nhandle = native_handle_create(GRALLOC_HANDLE_NUM_FDS,
85 GRALLOC_HANDLE_NUM_INTS);
86 handle.base = *nhandle;
87 native_handle_delete(nhandle);
88
89 handle.width = width;
90 handle.height = height;
91 handle.format = format;
92 handle.usage = usage;
93 handle.prime_fd = -1;
94
95 handle->data_owner = getpid();
96 handle->data = bo;
97
98 return handle;
99}
100
101#endif