OSDN Git Service

gralloc: add enter/leave vt
[android-x86/hardware-libhardware.git] / include / hardware / gralloc.h
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #ifndef ANDROID_GRALLOC_INTERFACE_H
19 #define ANDROID_GRALLOC_INTERFACE_H
20
21 #include <cutils/native_handle.h>
22
23 #include <hardware/hardware.h>
24
25 #include <stdint.h>
26 #include <sys/cdefs.h>
27 #include <sys/types.h>
28
29 __BEGIN_DECLS
30
31 #define GRALLOC_API_VERSION 1
32
33 /**
34  * The id of this module
35  */
36 #define GRALLOC_HARDWARE_MODULE_ID "gralloc"
37
38 /**
39  * Name of the graphics device to open
40  */
41
42 #define GRALLOC_HARDWARE_FB0 "fb0"
43 #define GRALLOC_HARDWARE_GPU0 "gpu0"
44
45 enum {
46     /* buffer is never read in software */
47     GRALLOC_USAGE_SW_READ_NEVER   = 0x00000000,
48     /* buffer is rarely read in software */
49     GRALLOC_USAGE_SW_READ_RARELY  = 0x00000002,
50     /* buffer is often read in software */
51     GRALLOC_USAGE_SW_READ_OFTEN   = 0x00000003,
52     /* mask for the software read values */
53     GRALLOC_USAGE_SW_READ_MASK    = 0x0000000F,
54     
55     /* buffer is never written in software */
56     GRALLOC_USAGE_SW_WRITE_NEVER  = 0x00000000,
57     /* buffer is never written in software */
58     GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020,
59     /* buffer is never written in software */
60     GRALLOC_USAGE_SW_WRITE_OFTEN  = 0x00000030,
61     /* mask for the software write values */
62     GRALLOC_USAGE_SW_WRITE_MASK   = 0x000000F0,
63
64     /* buffer will be used as an OpenGL ES texture */
65     GRALLOC_USAGE_HW_TEXTURE      = 0x00000100,
66     /* buffer will be used as an OpenGL ES render target */
67     GRALLOC_USAGE_HW_RENDER       = 0x00000200,
68     /* buffer will be used by the 2D hardware blitter */
69     GRALLOC_USAGE_HW_2D           = 0x00000400,
70     /* buffer will be used with the framebuffer device */
71     GRALLOC_USAGE_HW_FB           = 0x00001000,
72     /* mask for the software usage bit-mask */
73     GRALLOC_USAGE_HW_MASK         = 0x00001F00,
74
75     /* buffer should be displayed full-screen on an external display when
76      * possible
77      */
78     GRALLOC_USAGE_EXTERNAL_DISP   = 0x00002000,
79
80     /* Must have a hardware-protected path to external display sink for
81      * this buffer.  If a hardware-protected path is not available, then
82      * either don't composite only this buffer (preferred) to the
83      * external sink, or (less desirable) do not route the entire
84      * composition to the external sink.
85      */
86     GRALLOC_USAGE_PROTECTED       = 0x00004000,
87
88     /* implementation-specific private usage flags */
89     GRALLOC_USAGE_PRIVATE_0       = 0x10000000,
90     GRALLOC_USAGE_PRIVATE_1       = 0x20000000,
91     GRALLOC_USAGE_PRIVATE_2       = 0x40000000,
92     GRALLOC_USAGE_PRIVATE_3       = 0x80000000,
93     GRALLOC_USAGE_PRIVATE_MASK    = 0xF0000000,
94 };
95
96 /*****************************************************************************/
97
98 typedef const native_handle* buffer_handle_t;
99
100 enum {
101     /* FIXME: this only exists to work-around some issues with
102      * the video and camera frameworks. don't implement unless
103      * you know what you're doing.
104      */
105     GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER = 0x080000001,
106
107     GRALLOC_MODULE_PERFORM_GET_DRM_FD                = 0x080000002,
108     GRALLOC_MODULE_PERFORM_GET_DRM_MAGIC             = 0x080000003,
109     GRALLOC_MODULE_PERFORM_AUTH_DRM_MAGIC            = 0x080000004,
110
111     GRALLOC_MODULE_PERFORM_ENTER_VT                  = 0x080000005,
112     GRALLOC_MODULE_PERFORM_LEAVE_VT                  = 0x080000006,
113 };
114
115 /**
116  * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
117  * and the fields of this data structure must begin with hw_module_t
118  * followed by module specific information.
119  */
120 typedef struct gralloc_module_t {
121     struct hw_module_t common;
122     
123     /*
124      * (*registerBuffer)() must be called before a buffer_handle_t that has not
125      * been created with (*alloc_device_t::alloc)() can be used.
126      * 
127      * This is intended to be used with buffer_handle_t's that have been
128      * received in this process through IPC.
129      * 
130      * This function checks that the handle is indeed a valid one and prepares
131      * it for use with (*lock)() and (*unlock)().
132      * 
133      * It is not necessary to call (*registerBuffer)() on a handle created 
134      * with (*alloc_device_t::alloc)().
135      * 
136      * returns an error if this buffer_handle_t is not valid.
137      */
138     int (*registerBuffer)(struct gralloc_module_t const* module,
139             buffer_handle_t handle);
140
141     /*
142      * (*unregisterBuffer)() is called once this handle is no longer needed in
143      * this process. After this call, it is an error to call (*lock)(),
144      * (*unlock)(), or (*registerBuffer)().
145      * 
146      * This function doesn't close or free the handle itself; this is done
147      * by other means, usually through libcutils's native_handle_close() and
148      * native_handle_free(). 
149      * 
150      * It is an error to call (*unregisterBuffer)() on a buffer that wasn't
151      * explicitly registered first.
152      */
153     int (*unregisterBuffer)(struct gralloc_module_t const* module,
154             buffer_handle_t handle);
155     
156     /*
157      * The (*lock)() method is called before a buffer is accessed for the 
158      * specified usage. This call may block, for instance if the h/w needs
159      * to finish rendering or if CPU caches need to be synchronized.
160      * 
161      * The caller promises to modify only pixels in the area specified 
162      * by (l,t,w,h).
163      * 
164      * The content of the buffer outside of the specified area is NOT modified
165      * by this call.
166      *
167      * If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address
168      * of the buffer in virtual memory.
169      *
170      * THREADING CONSIDERATIONS:
171      *
172      * It is legal for several different threads to lock a buffer from 
173      * read access, none of the threads are blocked.
174      * 
175      * However, locking a buffer simultaneously for write or read/write is
176      * undefined, but:
177      * - shall not result in termination of the process
178      * - shall not block the caller
179      * It is acceptable to return an error or to leave the buffer's content
180      * into an indeterminate state.
181      *
182      * If the buffer was created with a usage mask incompatible with the
183      * requested usage flags here, -EINVAL is returned. 
184      * 
185      */
186     
187     int (*lock)(struct gralloc_module_t const* module,
188             buffer_handle_t handle, int usage,
189             int l, int t, int w, int h,
190             void** vaddr);
191
192     
193     /*
194      * The (*unlock)() method must be called after all changes to the buffer
195      * are completed.
196      */
197     
198     int (*unlock)(struct gralloc_module_t const* module,
199             buffer_handle_t handle);
200
201
202     /* reserved for future use */
203     int (*perform)(struct gralloc_module_t const* module,
204             int operation, ... );
205
206     /* reserved for future use */
207     void* reserved_proc[7];
208 } gralloc_module_t;
209
210 /*****************************************************************************/
211
212 /**
213  * Every device data structure must begin with hw_device_t
214  * followed by module specific public methods and attributes.
215  */
216
217 typedef struct alloc_device_t {
218     struct hw_device_t common;
219
220     /* 
221      * (*alloc)() Allocates a buffer in graphic memory with the requested
222      * parameters and returns a buffer_handle_t and the stride in pixels to
223      * allow the implementation to satisfy hardware constraints on the width
224      * of a pixmap (eg: it may have to be multiple of 8 pixels). 
225      * The CALLER TAKES OWNERSHIP of the buffer_handle_t.
226      * 
227      * Returns 0 on success or -errno on error.
228      */
229     
230     int (*alloc)(struct alloc_device_t* dev,
231             int w, int h, int format, int usage,
232             buffer_handle_t* handle, int* stride);
233
234     /*
235      * (*free)() Frees a previously allocated buffer. 
236      * Behavior is undefined if the buffer is still mapped in any process,
237      * but shall not result in termination of the program or security breaches
238      * (allowing a process to get access to another process' buffers).
239      * THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes
240      * invalid after the call. 
241      * 
242      * Returns 0 on success or -errno on error.
243      */
244     int (*free)(struct alloc_device_t* dev,
245             buffer_handle_t handle);
246
247     /* This hook is OPTIONAL.
248      *
249      * If non NULL it will be caused by SurfaceFlinger on dumpsys
250      */
251     void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len);
252
253     void* reserved_proc[7];
254 } alloc_device_t;
255
256
257 typedef struct framebuffer_device_t {
258     struct hw_device_t common;
259
260     /* flags describing some attributes of the framebuffer */
261     const uint32_t  flags;
262     
263     /* dimensions of the framebuffer in pixels */
264     const uint32_t  width;
265     const uint32_t  height;
266
267     /* frambuffer stride in pixels */
268     const int       stride;
269     
270     /* framebuffer pixel format */
271     const int       format;
272     
273     /* resolution of the framebuffer's display panel in pixel per inch*/
274     const float     xdpi;
275     const float     ydpi;
276
277     /* framebuffer's display panel refresh rate in frames per second */
278     const float     fps;
279
280     /* min swap interval supported by this framebuffer */
281     const int       minSwapInterval;
282
283     /* max swap interval supported by this framebuffer */
284     const int       maxSwapInterval;
285
286     int reserved[8];
287     
288     /* 
289      * requests a specific swap-interval (same definition than EGL) 
290      * 
291      * Returns 0 on success or -errno on error.
292      */
293     int (*setSwapInterval)(struct framebuffer_device_t* window,
294             int interval);
295
296     /*
297      * This hook is OPTIONAL.
298      * 
299      * It is non NULL If the framebuffer driver supports "update-on-demand" 
300      * and the given rectangle is the area of the screen that gets 
301      * updated during (*post)().
302      * 
303      * This is useful on devices that are able to DMA only a portion of
304      * the screen to the display panel, upon demand -- as opposed to
305      * constantly refreshing the panel 60 times per second, for instance.
306      * 
307      * Only the area defined by this rectangle is guaranteed to be valid, that
308      * is, the driver is not allowed to post anything outside of this
309      * rectangle. 
310      * 
311      * The rectangle evaluated during (*post)() and specifies which area
312      * of the buffer passed in (*post)() shall to be posted.
313      * 
314      * return -EINVAL if width or height <=0, or if left or top < 0 
315      */
316     int (*setUpdateRect)(struct framebuffer_device_t* window,
317             int left, int top, int width, int height);
318     
319     /*
320      * Post <buffer> to the display (display it on the screen)
321      * The buffer must have been allocated with the 
322      *   GRALLOC_USAGE_HW_FB usage flag.
323      * buffer must be the same width and height as the display and must NOT
324      * be locked.
325      * 
326      * The buffer is shown during the next VSYNC. 
327      * 
328      * If the same buffer is posted again (possibly after some other buffer),
329      * post() will block until the the first post is completed.
330      *
331      * Internally, post() is expected to lock the buffer so that a 
332      * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or
333      * USAGE_*_WRITE will block until it is safe; that is typically once this
334      * buffer is shown and another buffer has been posted.
335      *
336      * Returns 0 on success or -errno on error.
337      */
338     int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer);
339
340
341     /*
342      * The (*compositionComplete)() method must be called after the
343      * compositor has finished issuing GL commands for client buffers.
344      */
345
346     int (*compositionComplete)(struct framebuffer_device_t* dev);
347
348     /*
349      * This hook is OPTIONAL.
350      *
351      * If non NULL it will be caused by SurfaceFlinger on dumpsys
352      */
353     void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len);
354
355     void* reserved_proc[7];
356
357 } framebuffer_device_t;
358
359
360 /** convenience API for opening and closing a supported device */
361
362 static inline int gralloc_open(const struct hw_module_t* module, 
363         struct alloc_device_t** device) {
364     return module->methods->open(module, 
365             GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device);
366 }
367
368 static inline int gralloc_close(struct alloc_device_t* device) {
369     return device->common.close(&device->common);
370 }
371
372
373 static inline int framebuffer_open(const struct hw_module_t* module, 
374         struct framebuffer_device_t** device) {
375     return module->methods->open(module, 
376             GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device);
377 }
378
379 static inline int framebuffer_close(struct framebuffer_device_t* device) {
380     return device->common.close(&device->common);
381 }
382
383
384 __END_DECLS
385
386 #endif  // ANDROID_ALLOC_INTERFACE_H