blob: 827cea12658124caf1e22ae984ddf8e6b542418f [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
27__BEGIN_DECLS
28
29/*****************************************************************************/
Erik Gillinge9952042010-12-07 18:46:04 -080030
Mathias Agopianb08d45d2012-03-24 15:56:29 -070031#define HWC_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
32
33#define HWC_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1)
34#define HWC_DEVICE_API_VERSION_0_2 HARDWARE_DEVICE_API_VERSION(0, 2)
35#define HWC_DEVICE_API_VERSION_0_3 HARDWARE_DEVICE_API_VERSION(0, 3)
36
Mathias Agopian81c323d2012-03-25 01:09:35 -070037// for compatibility
Mathias Agopianb08d45d2012-03-24 15:56:29 -070038#define HWC_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1
39#define HWC_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1
Mathias Agopian81c323d2012-03-25 01:09:35 -070040#define HWC_API_VERSION HWC_DEVICE_API_VERSION
Erik Gillinge9952042010-12-07 18:46:04 -080041
Mathias Agopian5d3de302010-08-05 15:24:35 -070042/**
43 * The id of this module
44 */
45#define HWC_HARDWARE_MODULE_ID "hwcomposer"
46
47/**
48 * Name of the sensors device to open
49 */
50#define HWC_HARDWARE_COMPOSER "composer"
51
52
53enum {
54 /* hwc_composer_device_t::set failed in EGL */
55 HWC_EGL_ERROR = -1
56};
57
58/*
59 * hwc_layer_t::hints values
60 * Hints are set by the HAL and read by SurfaceFlinger
61 */
62enum {
63 /*
Mathias Agopiancdd44a02010-08-12 15:04:58 -070064 * HWC can set the HWC_HINT_TRIPLE_BUFFER hint to indicate to SurfaceFlinger
Mathias Agopian5d3de302010-08-05 15:24:35 -070065 * that it should triple buffer this layer. Typically HWC does this when
66 * the layer will be unavailable for use for an extended period of time,
67 * e.g. if the display will be fetching data directly from the layer and
68 * the layer can not be modified until after the next set().
69 */
Mathias Agopiancdd44a02010-08-12 15:04:58 -070070 HWC_HINT_TRIPLE_BUFFER = 0x00000001,
71
72 /*
73 * HWC sets HWC_HINT_CLEAR_FB to tell SurfaceFlinger that it should clear the
74 * framebuffer with transparent pixels where this layer would be.
75 * SurfaceFlinger will only honor this flag when the layer has no blending
76 *
77 */
78 HWC_HINT_CLEAR_FB = 0x00000002
Mathias Agopian5d3de302010-08-05 15:24:35 -070079};
80
81/*
82 * hwc_layer_t::flags values
83 * Flags are set by SurfaceFlinger and read by the HAL
84 */
85enum {
86 /*
87 * HWC_SKIP_LAYER is set by SurfaceFlnger to indicate that the HAL
88 * shall not consider this layer for composition as it will be handled
89 * by SurfaceFlinger (just as if compositionType was set to HWC_OVERLAY).
90 */
91 HWC_SKIP_LAYER = 0x00000001,
92};
93
94/*
95 * hwc_layer_t::compositionType values
96 */
97enum {
98 /* this layer is to be drawn into the framebuffer by SurfaceFlinger */
99 HWC_FRAMEBUFFER = 0,
100
101 /* this layer will be handled in the HWC */
102 HWC_OVERLAY = 1,
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800103
104 /* this is the background layer. it's used to set the background color.
105 * there is only a single background layer */
106 HWC_BACKGROUND = 2,
Mathias Agopian5d3de302010-08-05 15:24:35 -0700107};
108
109/*
110 * hwc_layer_t::blending values
111 */
112enum {
113 /* no blending */
114 HWC_BLENDING_NONE = 0x0100,
115
116 /* ONE / ONE_MINUS_SRC_ALPHA */
117 HWC_BLENDING_PREMULT = 0x0105,
118
119 /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
120 HWC_BLENDING_COVERAGE = 0x0405
121};
122
123/*
124 * hwc_layer_t::transform values
125 */
126enum {
127 /* flip source image horizontally */
128 HWC_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
129 /* flip source image vertically */
130 HWC_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
131 /* rotate source image 90 degrees clock-wise */
132 HWC_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
133 /* rotate source image 180 degrees */
134 HWC_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
135 /* rotate source image 270 degrees clock-wise */
136 HWC_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
137};
138
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800139/* attributes queriable with query() */
140enum {
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700141 /*
142 * availability: HWC_DEVICE_API_VERSION_0_2
143 * must return 1 if the background layer is supported, 0 otherwise
144 */
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800145 HWC_BACKGROUND_LAYER_SUPPORTED = 0,
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700146
147 /*
148 * availability: HWC_DEVICE_API_VERSION_0_3
149 * returns the vsync period in nanosecond
150 */
151 HWC_VSYNC_PERIOD = 1,
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800152};
153
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700154/* Allowed events for hwc_methods::eventControl() */
155enum {
156 HWC_EVENT_VSYNC = 0
157};
158
159struct hwc_composer_device;
160
161/*
162 * availability: HWC_DEVICE_API_VERSION_0_3
163 *
164 * struct hwc_methods cannot be embedded in other structures as
165 * sizeof(struct hwc_methods) cannot be relied upon.
166 *
167 */
168typedef struct hwc_methods {
169
170 /*************************************************************************
171 * HWC_DEVICE_API_VERSION_0_3
172 *************************************************************************/
173
174 /*
175 * eventControl(..., event, enabled)
176 * Enables or disables h/w composer events.
177 *
178 * eventControl can be called from any thread and takes effect
179 * immediately.
180 *
181 * Supported events are:
182 * HWC_EVENT_VSYNC
183 *
184 * returns -EINVAL if the "event" parameter is not one of the value above
185 * or if the "enabled" parameter is not 0 or 1.
186 */
187
188 int (*eventControl)(
189 struct hwc_composer_device* dev, int event, int enabled);
190
191} hwc_methods_t;
192
Mathias Agopian5d3de302010-08-05 15:24:35 -0700193typedef struct hwc_rect {
194 int left;
195 int top;
196 int right;
197 int bottom;
198} hwc_rect_t;
199
200typedef struct hwc_region {
201 size_t numRects;
202 hwc_rect_t const* rects;
203} hwc_region_t;
204
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800205typedef struct hwc_color {
206 uint8_t r;
207 uint8_t g;
208 uint8_t b;
209 uint8_t a;
210} hwc_color_t;
211
Mathias Agopian5d3de302010-08-05 15:24:35 -0700212typedef struct hwc_layer {
213 /*
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800214 * initially set to HWC_FRAMEBUFFER or HWC_BACKGROUND.
215 * HWC_FRAMEBUFFER
216 * indicates the layer will be drawn into the framebuffer
217 * using OpenGL ES.
218 * The HWC can toggle this value to HWC_OVERLAY, to indicate
219 * it will handle the layer.
220 *
221 * HWC_BACKGROUND
222 * indicates this is a special "background" layer. The only valid
223 * field is backgroundColor. HWC_BACKGROUND can only be used with
224 * HWC_API_VERSION >= 0.2
225 * The HWC can toggle this value to HWC_FRAMEBUFFER, to indicate
226 * it CANNOT handle the background color
227 *
Mathias Agopian5d3de302010-08-05 15:24:35 -0700228 */
229 int32_t compositionType;
230
231 /* see hwc_layer_t::hints above */
232 uint32_t hints;
233
234 /* see hwc_layer_t::flags above */
235 uint32_t flags;
236
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800237 union {
238 /* color of the background. hwc_color_t.a is ignored */
239 hwc_color_t backgroundColor;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700240
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800241 struct {
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800242 /* handle of buffer to compose. This handle is guaranteed to have been
243 * allocated from gralloc using the GRALLOC_USAGE_HW_COMPOSER usage flag. If
244 * the layer's handle is unchanged across two consecutive prepare calls and
245 * the HWC_GEOMETRY_CHANGED flag is not set for the second call then the
246 * HWComposer implementation may assume that the contents of the buffer have
247 * not changed. */
248 buffer_handle_t handle;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700249
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800250 /* transformation to apply to the buffer during composition */
251 uint32_t transform;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700252
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800253 /* blending to apply during composition */
254 int32_t blending;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700255
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800256 /* area of the source to consider, the origin is the top-left corner of
257 * the buffer */
258 hwc_rect_t sourceCrop;
259
260 /* where to composite the sourceCrop onto the display. The sourceCrop
261 * is scaled using linear filtering to the displayFrame. The origin is the
262 * top-left corner of the screen.
263 */
264 hwc_rect_t displayFrame;
265
266 /* visible region in screen space. The origin is the
267 * top-left corner of the screen.
268 * The visible region INCLUDES areas overlapped by a translucent layer.
269 */
270 hwc_region_t visibleRegionScreen;
271 };
272 };
Mathias Agopian5d3de302010-08-05 15:24:35 -0700273} hwc_layer_t;
274
275
276/*
277 * hwc_layer_list_t::flags values
278 */
279enum {
280 /*
281 * HWC_GEOMETRY_CHANGED is set by SurfaceFlinger to indicate that the list
282 * passed to (*prepare)() has changed by more than just the buffer handles.
283 */
284 HWC_GEOMETRY_CHANGED = 0x00000001,
285};
286
Louis Huemiller871815b2010-10-25 17:00:52 -0700287/*
288 * List of layers.
289 * The handle members of hwLayers elements must be unique.
290 */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700291typedef struct hwc_layer_list {
292 uint32_t flags;
293 size_t numHwLayers;
294 hwc_layer_t hwLayers[0];
295} hwc_layer_list_t;
296
297/* This represents a display, typically an EGLDisplay object */
298typedef void* hwc_display_t;
299
300/* This represents a surface, typically an EGLSurface object */
301typedef void* hwc_surface_t;
302
Mathias Agopian5d3de302010-08-05 15:24:35 -0700303
Mathias Agopiand6afef62011-08-01 16:34:42 -0700304/* see hwc_composer_device::registerProcs()
305 * Any of the callbacks can be NULL, in which case the corresponding
306 * functionality is not supported.
307 */
308typedef struct hwc_procs {
309 /*
310 * (*invalidate)() triggers a screen refresh, in particular prepare and set
311 * will be called shortly after this call is made. Note that there is
312 * NO GUARANTEE that the screen refresh will happen after invalidate()
313 * returns (in particular, it could happen before).
314 * invalidate() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL and
315 * it is safe to call invalidate() from any of hwc_composer_device
316 * hooks, unless noted otherwise.
317 */
318 void (*invalidate)(struct hwc_procs* procs);
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700319
320 /*
321 * (*vsync)() is called by the h/w composer HAL when a vsync event is
322 * received and HWC_EVENT_VSYNC is enabled (see: hwc_event_control).
323 *
324 * the "zero" parameter must always be 0.
325 * the "timestamp" parameter is the timestamp in nanosecond of when the
326 * vsync event happened.
327 *
328 * vsync() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL.
329 *
330 * It is expected that vsync() is called from a thread of at least
331 * ANDROID_URGENT_DISPLAY_PRIORITY with as little latency as possible,
332 * typically less than 0.5 ms.
333 *
Mathias Agopian6d3fec72012-04-10 21:22:28 -0700334 * It is a (silent) error to have HWC_EVENT_VSYNC enabled when calling
335 * hwc_composer_device.set(..., 0, 0, 0) (screen off). The implementation
336 * can either stop or continue to process VSYNC events, but must not
337 * crash or cause other problems.
338 *
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700339 */
340 void (*vsync)(struct hwc_procs* procs, int zero, int64_t timestamp);
Mathias Agopiand6afef62011-08-01 16:34:42 -0700341} hwc_procs_t;
342
343
344/*****************************************************************************/
Mathias Agopian5d3de302010-08-05 15:24:35 -0700345
346typedef struct hwc_module {
347 struct hw_module_t common;
348} hwc_module_t;
349
350
351typedef struct hwc_composer_device {
352 struct hw_device_t common;
353
354 /*
355 * (*prepare)() is called for each frame before composition and is used by
356 * SurfaceFlinger to determine what composition steps the HWC can handle.
357 *
358 * (*prepare)() can be called more than once, the last call prevails.
359 *
360 * The HWC responds by setting the compositionType field to either
361 * HWC_FRAMEBUFFER or HWC_OVERLAY. In the former case, the composition for
362 * this layer is handled by SurfaceFlinger with OpenGL ES, in the later
363 * case, the HWC will have to handle this layer's composition.
364 *
365 * (*prepare)() is called with HWC_GEOMETRY_CHANGED to indicate that the
366 * list's geometry has changed, that is, when more than just the buffer's
367 * handles have been updated. Typically this happens (but is not limited to)
368 * when a window is added, removed, resized or moved.
369 *
370 * a NULL list parameter or a numHwLayers of zero indicates that the
371 * entire composition will be handled by SurfaceFlinger with OpenGL ES.
372 *
373 * returns: 0 on success. An negative error code on error. If an error is
374 * returned, SurfaceFlinger will assume that none of the layer will be
375 * handled by the HWC.
376 */
377 int (*prepare)(struct hwc_composer_device *dev, hwc_layer_list_t* list);
378
379
380 /*
381 * (*set)() is used in place of eglSwapBuffers(), and assumes the same
382 * functionality, except it also commits the work list atomically with
383 * the actual eglSwapBuffers().
384 *
385 * The list parameter is guaranteed to be the same as the one returned
386 * from the last call to (*prepare)().
387 *
388 * When this call returns the caller assumes that:
389 *
390 * - the display will be updated in the near future with the content
391 * of the work list, without artifacts during the transition from the
392 * previous frame.
393 *
394 * - all objects are available for immediate access or destruction, in
395 * particular, hwc_region_t::rects data and hwc_layer_t::layer's buffer.
396 * Note that this means that immediately accessing (potentially from a
397 * different process) a buffer used in this call will not result in
398 * screen corruption, the driver must apply proper synchronization or
399 * scheduling (eg: block the caller, such as gralloc_module_t::lock(),
400 * OpenGL ES, Camera, Codecs, etc..., or schedule the caller's work
401 * after the buffer is freed from the actual composition).
402 *
403 * a NULL list parameter or a numHwLayers of zero indicates that the
404 * entire composition has been handled by SurfaceFlinger with OpenGL ES.
405 * In this case, (*set)() behaves just like eglSwapBuffers().
406 *
Mathias Agopian71212e32011-11-21 17:35:15 -0800407 * dpy, sur, and list are set to NULL to indicate that the screen is
408 * turning off. This happens WITHOUT prepare() being called first.
409 * This is a good time to free h/w resources and/or power
410 * the relevant h/w blocks down.
411 *
Mathias Agopianfb410362011-11-15 21:27:52 -0800412 * IMPORTANT NOTE: there is an implicit layer containing opaque black
413 * pixels behind all the layers in the list.
414 * It is the responsibility of the hwcomposer module to make
415 * sure black pixels are output (or blended from).
416 *
Mathias Agopian5d3de302010-08-05 15:24:35 -0700417 * returns: 0 on success. An negative error code on error:
418 * HWC_EGL_ERROR: eglGetError() will provide the proper error code
419 * Another code for non EGL errors.
420 *
421 */
422 int (*set)(struct hwc_composer_device *dev,
423 hwc_display_t dpy,
424 hwc_surface_t sur,
425 hwc_layer_list_t* list);
Erik Gilling158549c2010-12-01 16:34:08 -0800426 /*
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700427 * This field is OPTIONAL and can be NULL.
Erik Gilling158549c2010-12-01 16:34:08 -0800428 *
Mathias Agopiand6afef62011-08-01 16:34:42 -0700429 * If non NULL it will be called by SurfaceFlinger on dumpsys
Erik Gilling158549c2010-12-01 16:34:08 -0800430 */
431 void (*dump)(struct hwc_composer_device* dev, char *buff, int buff_len);
Mathias Agopian5d3de302010-08-05 15:24:35 -0700432
Mathias Agopiand6afef62011-08-01 16:34:42 -0700433 /*
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700434 * This field is OPTIONAL and can be NULL.
Mathias Agopiand6afef62011-08-01 16:34:42 -0700435 *
436 * (*registerProcs)() registers a set of callbacks the h/w composer HAL
437 * can later use. It is FORBIDDEN to call any of the callbacks from
438 * within registerProcs(). registerProcs() must save the hwc_procs_t pointer
439 * which is needed when calling a registered callback.
440 * Each call to registerProcs replaces the previous set of callbacks.
441 * registerProcs is called with NULL to unregister all callbacks.
442 *
443 * Any of the callbacks can be NULL, in which case the corresponding
444 * functionality is not supported.
445 */
446 void (*registerProcs)(struct hwc_composer_device* dev,
447 hwc_procs_t const* procs);
448
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800449 /*
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700450 * This field is OPTIONAL and can be NULL.
451 * availability: HWC_DEVICE_API_VERSION_0_2
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800452 *
453 * Used to retrieve information about the h/w composer
454 *
455 * Returns 0 on success or -errno on error.
456 */
457 int (*query)(struct hwc_composer_device* dev, int what, int* value);
458
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700459 /*
460 * Reserved for future use. Must be NULL.
461 */
462 void* reserved_proc[4];
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800463
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700464 /*
465 * This field is OPTIONAL and can be NULL.
466 * availability: HWC_DEVICE_API_VERSION_0_3
467 */
468 hwc_methods_t const *methods;
Erik Gillinge9952042010-12-07 18:46:04 -0800469
Mathias Agopian5d3de302010-08-05 15:24:35 -0700470} hwc_composer_device_t;
471
472
473/** convenience API for opening and closing a device */
474
475static inline int hwc_open(const struct hw_module_t* module,
476 hwc_composer_device_t** device) {
477 return module->methods->open(module,
478 HWC_HARDWARE_COMPOSER, (struct hw_device_t**)device);
479}
480
481static inline int hwc_close(hwc_composer_device_t* device) {
482 return device->common.close(&device->common);
483}
484
485
486/*****************************************************************************/
487
488__END_DECLS
489
490#endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H */