1bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/* Copyright (c) Imagination Technologies Ltd.
2bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil *
3bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * The contents of this file are subject to the MIT license as set out below.
4bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil *
5bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * Permission is hereby granted, free of charge, to any person obtaining a copy
6bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * of this software and associated documentation files (the "Software"), to deal
7bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * in the Software without restriction, including without limitation the rights
8bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * copies of the Software, and to permit persons to whom the Software is
10bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * furnished to do so, subject to the following conditions:
11bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil *
12bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * The above copyright notice and this permission notice shall be included in
13bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * all copies or substantial portions of the Software.
14bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil *
15bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * THE SOFTWARE.
22bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil */
23bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
24bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#ifndef HAL_PUBLIC_H
25bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_PUBLIC_H
26bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
27bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/* Authors of third party hardware composer (HWC) modules will need to include
28bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * this header to access functionality in the gralloc HAL.
29bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil */
30bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
31bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#include <hardware/gralloc.h>
32bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
33bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define ALIGN(x,a)	(((x) + (a) - 1L) & ~((a) - 1L))
34bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HW_ALIGN	32
35bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
36bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/* Use bits [0-3] of "vendor format" bits as real format. Customers should
37bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * use *only* the unassigned bits below for custom pixel formats, YUV or RGB.
38bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil *
39bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * If there are no bits set in this part of the field, or other bits are set
40bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * in the format outside of the "vendor format" mask, the non-extension format
41bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * is used instead. Reserve 0 for this purpose.
42bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil */
43bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
44bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_PIXEL_FORMAT_VENDOR_EXT(fmt) (0x100 | (fmt & 0xF))
45bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
46bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/*      Reserved ** DO NOT USE **    HAL_PIXEL_FORMAT_VENDOR_EXT(0) */
47bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_PIXEL_FORMAT_BGRX_8888   HAL_PIXEL_FORMAT_VENDOR_EXT(1)
48bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_PIXEL_FORMAT_sBGR_A_8888 HAL_PIXEL_FORMAT_VENDOR_EXT(2)
49bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_PIXEL_FORMAT_sBGR_X_8888 HAL_PIXEL_FORMAT_VENDOR_EXT(3)
50bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/*      HAL_PIXEL_FORMAT_RGB_565     HAL_PIXEL_FORMAT_VENDOR_EXT(4) */
51bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/*      HAL_PIXEL_FORMAT_BGRA_8888   HAL_PIXEL_FORMAT_VENDOR_EXT(5) */
52bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_PIXEL_FORMAT_NV12        HAL_PIXEL_FORMAT_VENDOR_EXT(6)
53bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(7) */
54bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(8) */
55bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(9) */
56bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(10) */
57bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(11) */
58bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(12) */
59bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(13) */
60bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(14) */
61bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(15) */
62bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
63bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/* One of the below compression modes is OR'ed into bits [4-6] of the 8 bit
64bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * "vendor format" field. If no bits are set in this "compression mask", the
65bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * normal memory format for the pixel format is used. Otherwise the pixel
66bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * data will be compressed in memory with the Rogue framebuffer compressor.
67bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil */
68bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
69bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_FB_COMPRESSION_NONE                0
70bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_FB_COMPRESSION_DIRECT_8x8          1
71bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_FB_COMPRESSION_DIRECT_16x4         2
72bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_FB_COMPRESSION_DIRECT_32x2         3
73bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_FB_COMPRESSION_INDIRECT_8x8        4
74bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_FB_COMPRESSION_INDIRECT_16x4       5
75bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_FB_COMPRESSION_INDIRECT_4TILE_8x8  6
76bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_FB_COMPRESSION_INDIRECT_4TILE_16x4 7
77bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
78bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/* The memory layout is OR'ed into bit 7 (top bit) of the 8 bit "vendor
79bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * format" field. Only STRIDED and TWIDDLED are supported; there is no space
80bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * for PAGETILED.
81bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil */
82bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_FB_MEMLAYOUT_STRIDED               0
83bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define HAL_FB_MEMLAYOUT_TWIDDLED              1
84bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
85bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/* This can be tuned down as appropriate for the SOC.
86bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil *
87bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * IMG formats are usually a single sub-alloc.
88bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * Some OEM video formats are two sub-allocs (Y, UV planes).
89bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * Future OEM video formats might be three sub-allocs (Y, U, V planes).
90bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil */
91bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define MAX_SUB_ALLOCS (3)
92bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
93bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramveliltypedef struct
94bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil{
95bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	native_handle_t base;
96bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
97bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* These fields can be sent cross process. They are also valid
98bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * to duplicate within the same process.
99bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 *
100bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * A table is stored within psPrivateData on gralloc_module_t (this
101bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * is obviously per-process) which maps stamps to a mapped
102bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * PVRSRV_MEMDESC in that process. Each map entry has a lock
103bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * count associated with it, satisfying the requirements of the
104bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * Android API. This also prevents us from leaking maps/allocations.
105bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 *
106bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * This table has entries inserted either by alloc()
107bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * (alloc_device_t) or map() (gralloc_module_t). Entries are removed
108bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * by free() (alloc_device_t) and unmap() (gralloc_module_t).
109bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 */
110bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
111bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define IMG_NATIVE_HANDLE_NUMFDS (MAX_SUB_ALLOCS)
112bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* The `fd' field is used to "export" a meminfo to another process.
113bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * Therefore, it is allocated by alloc_device_t, and consumed by
114bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * gralloc_module_t.
115bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 */
116bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int fd[IMG_NATIVE_HANDLE_NUMFDS];
117bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
118bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* This define should represent the number of packed 'int's required to
119bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * represent the fields following it. If you add a data type that is
120bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * 64-bit, for example using 'unsigned long long', you should write that
121bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * as "sizeof(unsigned long long) / sizeof(int)". Please keep the order
122bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * of the additions the same as the defined field order.
123bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 */
124bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define IMG_NATIVE_HANDLE_NUMINTS \
125bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	(sizeof(unsigned long long) / sizeof(int) + \
126bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 6 + MAX_SUB_ALLOCS + MAX_SUB_ALLOCS + \
127bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 sizeof(unsigned long long) / sizeof(int) * MAX_SUB_ALLOCS + \
128bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 1)
129bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* A KERNEL unique identifier for any exported kernel meminfo. Each
130bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * exported kernel meminfo will have a unique stamp, but note that in
131bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * userspace, several meminfos across multiple processes could have
132bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * the same stamp. As the native_handle can be dup(2)'d, there could be
133bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * multiple handles with the same stamp but different file descriptors.
134bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 */
135bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	unsigned long long ui64Stamp;
136bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
137bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* This is used for buffer usage validation */
138bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int usage;
139bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
140bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* In order to do efficient cache flushes we need the buffer dimensions,
141bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * format and bits per pixel. There are ANativeWindow queries for the
142bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * width, height and format, but the graphics HAL might have remapped the
143bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * request to different values at allocation time. These are the 'true'
144bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * values of the buffer allocation.
145bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 */
146bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int iWidth;
147bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int iHeight;
148bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int iFormat;
149bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	unsigned int uiBpp;
150bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
151bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* Planes are not the same as the `fd' suballocs. A multi-planar YUV
152bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * allocation has different planes (interleaved = 1, semi-planar = 2,
153bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * fully-planar = 3) but might be spread across 1, 2 or 3 independent
154bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * memory allocations (or not).
155bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 */
156bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int iPlanes;
157bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
158bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* For multi-planar allocations, there will be multiple hstrides */
159bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int aiStride[MAX_SUB_ALLOCS];
160bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
161bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* For multi-planar allocations, there will be multiple vstrides */
162bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int aiVStride[MAX_SUB_ALLOCS];
163bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
164bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* These byte offsets are reconciled with the number of sub-allocs used
165bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * for a multi-planar allocation. If there is a 1:1 mapping between the
166bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * number of planes and the number of sub-allocs, these will all be zero.
167bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 *
168bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * Otherwise, normally the zeroth entry will be zero, and the latter
169bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * entries will be non-zero.
170bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 */
171bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	unsigned long long aulPlaneOffset[MAX_SUB_ALLOCS];
172bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
173bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* This records the number of MAX_SUB_ALLOCS fds actually used by the
174bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * buffer allocation. File descriptors up to fd[iNumSubAllocs - 1] are
175bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * guaranteed to be valid. (This does not have any bearing on the aiStride,
176bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * aiVStride or aulPlaneOffset fields, as `iPlanes' of those arrays should
177bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * be initialized, not `iNumSubAllocs'.)
178bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 */
179bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int iNumSubAllocs;
180bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil}
181bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil__attribute__((aligned(sizeof(int)),packed)) IMG_native_handle_t;
182bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
183bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramveliltypedef struct
184bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil{
185bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int l, t, w, h;
186bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil}
187bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil CheeramvelilIMG_write_lock_rect_t;
188bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
189bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define IMG_BFF_YUV					(1 << 0)
190bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define IMG_BFF_UVCbCrORDERING		(1 << 1)
191bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define IMG_BFF_CPU_CLEAR			(1 << 2)
192bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define IMG_BFF_DONT_GPU_CLEAR		(1 << 3)
193bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define IMG_BFF_PARTIAL_ALLOC		(1 << 4)
194bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define IMG_BFF_NEVER_COMPRESS		(1 << 5)
195bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
196bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/* Keep this in sync with SGX */
197bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramveliltypedef struct IMG_buffer_format_public_t
198bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil{
199bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* Buffer formats are returned as a linked list */
200bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	struct IMG_buffer_format_public_t *psNext;
201bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
202bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* HAL_PIXEL_FORMAT_... enumerant */
203bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int iHalPixelFormat;
204bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
205bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* IMG_PIXFMT_... enumerant */
206bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int iIMGPixelFormat;
207bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
208bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* Friendly name for format */
209bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	const char *const szName;
210bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
211bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* Bits (not bytes) per pixel */
212bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	unsigned int uiBpp;
213bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
214bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* Supported HW usage bits. If this is GRALLOC_USAGE_HW_MASK, all usages
215bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 * are supported. Used for HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED.
216bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	 */
217bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int iSupportedUsage;
218bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
219bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* Allocation description flags */
220bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	unsigned int uiFlags;
221bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil}
222bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil CheeramvelilIMG_buffer_format_public_t;
223bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
224bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/* NOTE: This interface is deprecated. Use module->perform() instead. */
225bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramveliltypedef struct IMG_gralloc_module_public_t
226bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil{
227bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	gralloc_module_t base;
228bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
229bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* Gets the head of the linked list of all registered formats */
230bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	const IMG_buffer_format_public_t *(*GetBufferFormats)(void);
231bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
232bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* Custom-blit components in lieu of overlay hardware */
233bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int (*Blit)(struct IMG_gralloc_module_public_t const *module,
234bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil				 buffer_handle_t src, buffer_handle_t dest,
235bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil				 int w, int h, int x, int y, int transform,
236bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil				 int iInputFenceFd, int *piOutputFenceFd);
237bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
238bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	int (*Blit3)(struct IMG_gralloc_module_public_t const *module,
239bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil				 unsigned long long ui64SrcStamp, int iSrcWidth,
240bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil				 int iSrcHeight, int iSrcFormat, int iSrcStrideInPixels,
241bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil				 int eSrcRotation, buffer_handle_t dest, int eDestRotation,
242bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil				 int iInputFenceFd, int *piOutputFenceFd);
243bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
244bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	/* Walk the above list and return only the specified format */
245bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	const IMG_buffer_format_public_t *(*GetBufferFormat)(int iFormat);
246bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil}
247bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil CheeramvelilIMG_gralloc_module_public_t;
248bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
249bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil/* Helpers for using the non-type-safe perform() extension functions. Use
250bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil * these helpers instead of calling perform() directly in your application.
251bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil */
252bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
253bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define GRALLOC_MODULE_GET_BUFFER_FORMAT_IMG     1
254bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define GRALLOC_MODULE_GET_BUFFER_FORMATS_IMG    2
255bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define GRALLOC_MODULE_BLIT_HANDLE_TO_HANDLE_IMG 3
256bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#define GRALLOC_MODULE_BLIT_STAMP_TO_HANDLE_IMG  4
257bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
258bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelilstatic inline int
259bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelilgralloc_module_get_buffer_format_img(const gralloc_module_t *module,
260bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil									 int format,
261bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil									 const IMG_buffer_format_public_t **v)
262bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil{
263bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	return module->perform(module, GRALLOC_MODULE_GET_BUFFER_FORMAT_IMG,
264bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil						   format, v);
265bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil}
266bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
267bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelilstatic inline int
268bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelilgralloc_module_get_buffer_formats_img(const gralloc_module_t *module,
269bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil									  const IMG_buffer_format_public_t **v)
270bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil{
271bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	return module->perform(module, GRALLOC_MODULE_GET_BUFFER_FORMATS_IMG, v);
272bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil}
273bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
274bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelilstatic inline int
275bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelilgralloc_module_blit_handle_to_handle_img(const gralloc_module_t *module,
276bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil										 buffer_handle_t src,
277bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil										 buffer_handle_t dest,
278bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil										 int w, int h, int x, int y,
279bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil										 int transform, int input_fence,
280bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil										 int *output_fence)
281bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil{
282bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	return module->perform(module, GRALLOC_MODULE_BLIT_HANDLE_TO_HANDLE_IMG,
283bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil						   src, dest, w, h, x, y, transform, input_fence,
284bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil						   output_fence);
285bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil}
286bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
287bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelilstatic inline int
288bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelilgralloc_module_blit_stamp_to_handle(const gralloc_module_t *module,
289bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil									unsigned long long src_stamp,
290bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil									int src_width, int src_height,
291bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil									int src_format, int src_stride_in_pixels,
292bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil									int src_rotation, buffer_handle_t dest,
293bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil									int dest_rotation, int input_fence,
294bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil									int *output_fence)
295bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil{
296bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil	return module->perform(module, GRALLOC_MODULE_BLIT_STAMP_TO_HANDLE_IMG,
297bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil						   src_stamp, src_width, src_height, src_format,
298bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil						   src_stride_in_pixels, src_rotation, dest,
299bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil						   dest_rotation, input_fence, output_fence);
300bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil}
301bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil
302bacdfbde97131d12c92bf832ce9d7db6de4598d8Vinil Cheeramvelil#endif /* HAL_PUBLIC_H */
303