blob: 4af5c69f3d7c615cf629cad0aac97c0f77c47345 [file] [log] [blame]
Mathias Agopian5d3de302010-08-05 15:24:35 -07001/*
2 * Copyright (C) 2010 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#ifndef ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H
18#define ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H
19
20#include <stdint.h>
21#include <sys/cdefs.h>
22
Louis Huemiller45e23712010-12-01 12:25:00 -080023#include <hardware/gralloc.h>
Mathias Agopian5d3de302010-08-05 15:24:35 -070024#include <hardware/hardware.h>
25#include <cutils/native_handle.h>
26
Mathias Agopiane291f712012-05-13 22:49:06 -070027#include <hardware/hwcomposer_defs.h>
28
Mathias Agopian5d3de302010-08-05 15:24:35 -070029__BEGIN_DECLS
30
31/*****************************************************************************/
Erik Gillinge9952042010-12-07 18:46:04 -080032
Jesse Halld479ad22012-06-05 23:41:37 -070033/* for compatibility */
Mathias Agopianb08d45d2012-03-24 15:56:29 -070034#define HWC_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1
35#define HWC_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1
Mathias Agopian81c323d2012-03-25 01:09:35 -070036#define HWC_API_VERSION HWC_DEVICE_API_VERSION
Erik Gillinge9952042010-12-07 18:46:04 -080037
Jesse Halld479ad22012-06-05 23:41:37 -070038/* Users of this header can define HWC_REMOVE_DEPRECATED_VERSIONS to test that
39 * they still work with just the current version declared, before the
40 * deprecated versions are actually removed.
41 *
42 * To find code that still depends on the old versions, set the #define to 1
43 * here. Code that explicitly sets it to zero (rather than simply not defining
44 * it) will still see the old versions.
45 */
46#if !defined(HWC_REMOVE_DEPRECATED_VERSIONS)
47#define HWC_REMOVE_DEPRECATED_VERSIONS 0
48#endif
49
50/*****************************************************************************/
51
Mathias Agopian5d3de302010-08-05 15:24:35 -070052/**
53 * The id of this module
54 */
55#define HWC_HARDWARE_MODULE_ID "hwcomposer"
56
57/**
58 * Name of the sensors device to open
59 */
60#define HWC_HARDWARE_COMPOSER "composer"
61
Jesse Halld479ad22012-06-05 23:41:37 -070062struct hwc_composer_device_1;
63typedef struct hwc_methods_1 {
Mathias Agopianb08d45d2012-03-24 15:56:29 -070064
65 /*
66 * eventControl(..., event, enabled)
67 * Enables or disables h/w composer events.
68 *
69 * eventControl can be called from any thread and takes effect
70 * immediately.
71 *
72 * Supported events are:
73 * HWC_EVENT_VSYNC
74 *
75 * returns -EINVAL if the "event" parameter is not one of the value above
76 * or if the "enabled" parameter is not 0 or 1.
77 */
78
79 int (*eventControl)(
Jesse Halld479ad22012-06-05 23:41:37 -070080 struct hwc_composer_device_1* dev, int event, int enabled);
Mathias Agopianb08d45d2012-03-24 15:56:29 -070081
Jesse Halld479ad22012-06-05 23:41:37 -070082} hwc_methods_1_t;
Mathias Agopianb08d45d2012-03-24 15:56:29 -070083
Mathias Agopian5d3de302010-08-05 15:24:35 -070084typedef struct hwc_rect {
85 int left;
86 int top;
87 int right;
88 int bottom;
89} hwc_rect_t;
90
91typedef struct hwc_region {
92 size_t numRects;
93 hwc_rect_t const* rects;
94} hwc_region_t;
95
Mathias Agopianeb8fb502012-02-03 15:54:11 -080096typedef struct hwc_color {
97 uint8_t r;
98 uint8_t g;
99 uint8_t b;
100 uint8_t a;
101} hwc_color_t;
102
Jesse Halld479ad22012-06-05 23:41:37 -0700103typedef struct hwc_layer_1 {
Mathias Agopian5d3de302010-08-05 15:24:35 -0700104 /*
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800105 * initially set to HWC_FRAMEBUFFER or HWC_BACKGROUND.
106 * HWC_FRAMEBUFFER
107 * indicates the layer will be drawn into the framebuffer
108 * using OpenGL ES.
109 * The HWC can toggle this value to HWC_OVERLAY, to indicate
110 * it will handle the layer.
111 *
112 * HWC_BACKGROUND
113 * indicates this is a special "background" layer. The only valid
114 * field is backgroundColor. HWC_BACKGROUND can only be used with
115 * HWC_API_VERSION >= 0.2
116 * The HWC can toggle this value to HWC_FRAMEBUFFER, to indicate
117 * it CANNOT handle the background color
118 *
Mathias Agopian5d3de302010-08-05 15:24:35 -0700119 */
120 int32_t compositionType;
121
122 /* see hwc_layer_t::hints above */
123 uint32_t hints;
124
125 /* see hwc_layer_t::flags above */
126 uint32_t flags;
127
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800128 union {
129 /* color of the background. hwc_color_t.a is ignored */
130 hwc_color_t backgroundColor;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700131
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800132 struct {
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800133 /* handle of buffer to compose. This handle is guaranteed to have been
134 * allocated from gralloc using the GRALLOC_USAGE_HW_COMPOSER usage flag. If
135 * the layer's handle is unchanged across two consecutive prepare calls and
136 * the HWC_GEOMETRY_CHANGED flag is not set for the second call then the
137 * HWComposer implementation may assume that the contents of the buffer have
138 * not changed. */
139 buffer_handle_t handle;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700140
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800141 /* transformation to apply to the buffer during composition */
142 uint32_t transform;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700143
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800144 /* blending to apply during composition */
145 int32_t blending;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700146
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800147 /* area of the source to consider, the origin is the top-left corner of
148 * the buffer */
149 hwc_rect_t sourceCrop;
150
151 /* where to composite the sourceCrop onto the display. The sourceCrop
152 * is scaled using linear filtering to the displayFrame. The origin is the
153 * top-left corner of the screen.
154 */
155 hwc_rect_t displayFrame;
156
157 /* visible region in screen space. The origin is the
158 * top-left corner of the screen.
159 * The visible region INCLUDES areas overlapped by a translucent layer.
160 */
161 hwc_region_t visibleRegionScreen;
Jesse Halld479ad22012-06-05 23:41:37 -0700162
163 /* Sync fence object that will be signaled when the buffer's
164 * contents are available. May be -1 if the contents are already
165 * available. This field is only valid during set(), and should be
166 * ignored during prepare(). The set() call must not wait for the
167 * fence to be signaled before returning, but the HWC must wait for
168 * all buffers to be signaled before reading from them.
169 *
170 * The HWC takes ownership of the acquireFenceFd and is responsible
171 * for closing it when no longer needed.
172 */
173 int acquireFenceFd;
174
175 /* During set() the HWC must set this field to a file descriptor for
176 * a sync fence object that will signal after the HWC has finished
177 * reading from the buffer. The field is ignored by prepare(). Each
178 * layer should have a unique file descriptor, even if more than one
179 * refer to the same underlying fence object; this allows each to be
180 * closed independently.
181 *
182 * If buffer reads can complete at significantly different times,
183 * then using independent fences is preferred. For example, if the
184 * HWC handles some layers with a blit engine and others with
185 * overlays, then the blit layers can be reused immediately after
186 * the blit completes, but the overlay layers can't be reused until
187 * a subsequent frame has been displayed.
188 *
189 * The HWC client taks ownership of the releaseFenceFd and is
190 * responsible for closing it when no longer needed.
191 */
192 int releaseFenceFd;
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800193 };
194 };
Mathias Agopian5d3de302010-08-05 15:24:35 -0700195
Jesse Halld479ad22012-06-05 23:41:37 -0700196 /* Allow for expansion w/o breaking binary compatibility.
197 * Pad layer to 96 bytes, assuming 32-bit pointers.
198 */
199 int32_t reserved[24 - 18];
200
201} hwc_layer_1_t;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700202
203/*
204 * hwc_layer_list_t::flags values
205 */
206enum {
207 /*
208 * HWC_GEOMETRY_CHANGED is set by SurfaceFlinger to indicate that the list
Jesse Halld479ad22012-06-05 23:41:37 -0700209 * passed to (*prepare)() has changed by more than just the buffer handles
210 * and acquire fences.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700211 */
212 HWC_GEOMETRY_CHANGED = 0x00000001,
213};
214
Louis Huemiller871815b2010-10-25 17:00:52 -0700215/*
216 * List of layers.
217 * The handle members of hwLayers elements must be unique.
218 */
Jesse Halld479ad22012-06-05 23:41:37 -0700219typedef struct hwc_layer_list_1 {
Mathias Agopian5d3de302010-08-05 15:24:35 -0700220 uint32_t flags;
221 size_t numHwLayers;
Jesse Halld479ad22012-06-05 23:41:37 -0700222 hwc_layer_1_t hwLayers[0];
223} hwc_layer_list_1_t;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700224
225/* This represents a display, typically an EGLDisplay object */
226typedef void* hwc_display_t;
227
228/* This represents a surface, typically an EGLSurface object */
229typedef void* hwc_surface_t;
230
Mathias Agopian5d3de302010-08-05 15:24:35 -0700231
Mathias Agopiand6afef62011-08-01 16:34:42 -0700232/* see hwc_composer_device::registerProcs()
233 * Any of the callbacks can be NULL, in which case the corresponding
234 * functionality is not supported.
235 */
236typedef struct hwc_procs {
237 /*
238 * (*invalidate)() triggers a screen refresh, in particular prepare and set
239 * will be called shortly after this call is made. Note that there is
240 * NO GUARANTEE that the screen refresh will happen after invalidate()
241 * returns (in particular, it could happen before).
242 * invalidate() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL and
243 * it is safe to call invalidate() from any of hwc_composer_device
244 * hooks, unless noted otherwise.
245 */
246 void (*invalidate)(struct hwc_procs* procs);
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700247
248 /*
249 * (*vsync)() is called by the h/w composer HAL when a vsync event is
250 * received and HWC_EVENT_VSYNC is enabled (see: hwc_event_control).
251 *
252 * the "zero" parameter must always be 0.
Jamie Gennis6b7adef2012-04-30 12:57:11 -0700253 * the "timestamp" parameter is the system monotonic clock timestamp in
254 * nanosecond of when the vsync event happened.
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700255 *
256 * vsync() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL.
257 *
258 * It is expected that vsync() is called from a thread of at least
Mathias Agopianeb671602012-04-24 15:42:37 -0700259 * HAL_PRIORITY_URGENT_DISPLAY with as little latency as possible,
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700260 * typically less than 0.5 ms.
261 *
Mathias Agopian6d3fec72012-04-10 21:22:28 -0700262 * It is a (silent) error to have HWC_EVENT_VSYNC enabled when calling
263 * hwc_composer_device.set(..., 0, 0, 0) (screen off). The implementation
264 * can either stop or continue to process VSYNC events, but must not
265 * crash or cause other problems.
266 *
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700267 */
268 void (*vsync)(struct hwc_procs* procs, int zero, int64_t timestamp);
Mathias Agopiand6afef62011-08-01 16:34:42 -0700269} hwc_procs_t;
270
271
272/*****************************************************************************/
Mathias Agopian5d3de302010-08-05 15:24:35 -0700273
274typedef struct hwc_module {
275 struct hw_module_t common;
276} hwc_module_t;
277
Jesse Halld479ad22012-06-05 23:41:37 -0700278typedef struct hwc_composer_device_1 {
Mathias Agopian5d3de302010-08-05 15:24:35 -0700279 struct hw_device_t common;
280
281 /*
282 * (*prepare)() is called for each frame before composition and is used by
283 * SurfaceFlinger to determine what composition steps the HWC can handle.
284 *
285 * (*prepare)() can be called more than once, the last call prevails.
286 *
287 * The HWC responds by setting the compositionType field to either
288 * HWC_FRAMEBUFFER or HWC_OVERLAY. In the former case, the composition for
289 * this layer is handled by SurfaceFlinger with OpenGL ES, in the later
290 * case, the HWC will have to handle this layer's composition.
291 *
292 * (*prepare)() is called with HWC_GEOMETRY_CHANGED to indicate that the
293 * list's geometry has changed, that is, when more than just the buffer's
294 * handles have been updated. Typically this happens (but is not limited to)
295 * when a window is added, removed, resized or moved.
296 *
297 * a NULL list parameter or a numHwLayers of zero indicates that the
298 * entire composition will be handled by SurfaceFlinger with OpenGL ES.
299 *
300 * returns: 0 on success. An negative error code on error. If an error is
301 * returned, SurfaceFlinger will assume that none of the layer will be
302 * handled by the HWC.
303 */
Jesse Halld479ad22012-06-05 23:41:37 -0700304 int (*prepare)(struct hwc_composer_device_1 *dev,
305 hwc_layer_list_1_t* list);
Mathias Agopian5d3de302010-08-05 15:24:35 -0700306
307 /*
308 * (*set)() is used in place of eglSwapBuffers(), and assumes the same
309 * functionality, except it also commits the work list atomically with
310 * the actual eglSwapBuffers().
311 *
312 * The list parameter is guaranteed to be the same as the one returned
313 * from the last call to (*prepare)().
314 *
315 * When this call returns the caller assumes that:
316 *
317 * - the display will be updated in the near future with the content
318 * of the work list, without artifacts during the transition from the
319 * previous frame.
320 *
321 * - all objects are available for immediate access or destruction, in
322 * particular, hwc_region_t::rects data and hwc_layer_t::layer's buffer.
323 * Note that this means that immediately accessing (potentially from a
324 * different process) a buffer used in this call will not result in
325 * screen corruption, the driver must apply proper synchronization or
326 * scheduling (eg: block the caller, such as gralloc_module_t::lock(),
327 * OpenGL ES, Camera, Codecs, etc..., or schedule the caller's work
328 * after the buffer is freed from the actual composition).
329 *
330 * a NULL list parameter or a numHwLayers of zero indicates that the
331 * entire composition has been handled by SurfaceFlinger with OpenGL ES.
332 * In this case, (*set)() behaves just like eglSwapBuffers().
333 *
Mathias Agopian71212e32011-11-21 17:35:15 -0800334 * dpy, sur, and list are set to NULL to indicate that the screen is
335 * turning off. This happens WITHOUT prepare() being called first.
336 * This is a good time to free h/w resources and/or power
337 * the relevant h/w blocks down.
338 *
Mathias Agopianfb410362011-11-15 21:27:52 -0800339 * IMPORTANT NOTE: there is an implicit layer containing opaque black
340 * pixels behind all the layers in the list.
341 * It is the responsibility of the hwcomposer module to make
342 * sure black pixels are output (or blended from).
343 *
Mathias Agopian5d3de302010-08-05 15:24:35 -0700344 * returns: 0 on success. An negative error code on error:
345 * HWC_EGL_ERROR: eglGetError() will provide the proper error code
346 * Another code for non EGL errors.
347 *
348 */
Jesse Halld479ad22012-06-05 23:41:37 -0700349 int (*set)(struct hwc_composer_device_1 *dev,
Mathias Agopian5d3de302010-08-05 15:24:35 -0700350 hwc_display_t dpy,
351 hwc_surface_t sur,
Jesse Halld479ad22012-06-05 23:41:37 -0700352 hwc_layer_list_1_t* list);
353
Erik Gilling158549c2010-12-01 16:34:08 -0800354 /*
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700355 * This field is OPTIONAL and can be NULL.
Erik Gilling158549c2010-12-01 16:34:08 -0800356 *
Mathias Agopiand6afef62011-08-01 16:34:42 -0700357 * If non NULL it will be called by SurfaceFlinger on dumpsys
Erik Gilling158549c2010-12-01 16:34:08 -0800358 */
Jesse Halld479ad22012-06-05 23:41:37 -0700359 void (*dump)(struct hwc_composer_device_1* dev, char *buff, int buff_len);
Mathias Agopian5d3de302010-08-05 15:24:35 -0700360
Mathias Agopiand6afef62011-08-01 16:34:42 -0700361 /*
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700362 * This field is OPTIONAL and can be NULL.
Mathias Agopiand6afef62011-08-01 16:34:42 -0700363 *
364 * (*registerProcs)() registers a set of callbacks the h/w composer HAL
365 * can later use. It is FORBIDDEN to call any of the callbacks from
366 * within registerProcs(). registerProcs() must save the hwc_procs_t pointer
367 * which is needed when calling a registered callback.
368 * Each call to registerProcs replaces the previous set of callbacks.
369 * registerProcs is called with NULL to unregister all callbacks.
370 *
371 * Any of the callbacks can be NULL, in which case the corresponding
372 * functionality is not supported.
373 */
Jesse Halld479ad22012-06-05 23:41:37 -0700374 void (*registerProcs)(struct hwc_composer_device_1* dev,
Mathias Agopiand6afef62011-08-01 16:34:42 -0700375 hwc_procs_t const* procs);
376
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800377 /*
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700378 * This field is OPTIONAL and can be NULL.
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800379 *
380 * Used to retrieve information about the h/w composer
381 *
382 * Returns 0 on success or -errno on error.
383 */
Jesse Halld479ad22012-06-05 23:41:37 -0700384 int (*query)(struct hwc_composer_device_1* dev, int what, int* value);
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800385
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700386 /*
387 * Reserved for future use. Must be NULL.
388 */
389 void* reserved_proc[4];
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800390
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700391 /*
392 * This field is OPTIONAL and can be NULL.
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700393 */
Jesse Halld479ad22012-06-05 23:41:37 -0700394 hwc_methods_1_t const *methods;
Erik Gillinge9952042010-12-07 18:46:04 -0800395
Jesse Halld479ad22012-06-05 23:41:37 -0700396} hwc_composer_device_1_t;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700397
398/** convenience API for opening and closing a device */
399
Jesse Halld479ad22012-06-05 23:41:37 -0700400static inline int hwc_open_1(const struct hw_module_t* module,
401 hwc_composer_device_1_t** device) {
Mathias Agopian5d3de302010-08-05 15:24:35 -0700402 return module->methods->open(module,
403 HWC_HARDWARE_COMPOSER, (struct hw_device_t**)device);
404}
405
Jesse Halld479ad22012-06-05 23:41:37 -0700406static inline int hwc_close_1(hwc_composer_device_1_t* device) {
Mathias Agopian5d3de302010-08-05 15:24:35 -0700407 return device->common.close(&device->common);
408}
409
Mathias Agopian5d3de302010-08-05 15:24:35 -0700410/*****************************************************************************/
411
Jesse Halld479ad22012-06-05 23:41:37 -0700412#if !HWC_REMOVE_DEPRECATED_VERSIONS
413#include <hardware/hwcomposer_v0.h>
414#endif
415
Mathias Agopian5d3de302010-08-05 15:24:35 -0700416__END_DECLS
417
418#endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H */