blob: b78746c31dd17f57670e5a4d7b38c9be418f13e2 [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 Agopianeb8fb502012-02-03 15:54:11 -080031#define HWC_API_VERSION HARDWARE_DEVICE_API_VERSION(0,2)
Erik Gillinge9952042010-12-07 18:46:04 -080032
Mathias Agopian5d3de302010-08-05 15:24:35 -070033/**
34 * The id of this module
35 */
36#define HWC_HARDWARE_MODULE_ID "hwcomposer"
37
38/**
39 * Name of the sensors device to open
40 */
41#define HWC_HARDWARE_COMPOSER "composer"
42
43
44enum {
45 /* hwc_composer_device_t::set failed in EGL */
46 HWC_EGL_ERROR = -1
47};
48
49/*
50 * hwc_layer_t::hints values
51 * Hints are set by the HAL and read by SurfaceFlinger
52 */
53enum {
54 /*
Mathias Agopiancdd44a02010-08-12 15:04:58 -070055 * HWC can set the HWC_HINT_TRIPLE_BUFFER hint to indicate to SurfaceFlinger
Mathias Agopian5d3de302010-08-05 15:24:35 -070056 * that it should triple buffer this layer. Typically HWC does this when
57 * the layer will be unavailable for use for an extended period of time,
58 * e.g. if the display will be fetching data directly from the layer and
59 * the layer can not be modified until after the next set().
60 */
Mathias Agopiancdd44a02010-08-12 15:04:58 -070061 HWC_HINT_TRIPLE_BUFFER = 0x00000001,
62
63 /*
64 * HWC sets HWC_HINT_CLEAR_FB to tell SurfaceFlinger that it should clear the
65 * framebuffer with transparent pixels where this layer would be.
66 * SurfaceFlinger will only honor this flag when the layer has no blending
67 *
68 */
69 HWC_HINT_CLEAR_FB = 0x00000002
Mathias Agopian5d3de302010-08-05 15:24:35 -070070};
71
72/*
73 * hwc_layer_t::flags values
74 * Flags are set by SurfaceFlinger and read by the HAL
75 */
76enum {
77 /*
78 * HWC_SKIP_LAYER is set by SurfaceFlnger to indicate that the HAL
79 * shall not consider this layer for composition as it will be handled
80 * by SurfaceFlinger (just as if compositionType was set to HWC_OVERLAY).
81 */
82 HWC_SKIP_LAYER = 0x00000001,
83};
84
85/*
86 * hwc_layer_t::compositionType values
87 */
88enum {
89 /* this layer is to be drawn into the framebuffer by SurfaceFlinger */
90 HWC_FRAMEBUFFER = 0,
91
92 /* this layer will be handled in the HWC */
93 HWC_OVERLAY = 1,
Mathias Agopianeb8fb502012-02-03 15:54:11 -080094
95 /* this is the background layer. it's used to set the background color.
96 * there is only a single background layer */
97 HWC_BACKGROUND = 2,
Mathias Agopian5d3de302010-08-05 15:24:35 -070098};
99
100/*
101 * hwc_layer_t::blending values
102 */
103enum {
104 /* no blending */
105 HWC_BLENDING_NONE = 0x0100,
106
107 /* ONE / ONE_MINUS_SRC_ALPHA */
108 HWC_BLENDING_PREMULT = 0x0105,
109
110 /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
111 HWC_BLENDING_COVERAGE = 0x0405
112};
113
114/*
115 * hwc_layer_t::transform values
116 */
117enum {
118 /* flip source image horizontally */
119 HWC_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
120 /* flip source image vertically */
121 HWC_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
122 /* rotate source image 90 degrees clock-wise */
123 HWC_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
124 /* rotate source image 180 degrees */
125 HWC_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
126 /* rotate source image 270 degrees clock-wise */
127 HWC_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
128};
129
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800130/* attributes queriable with query() */
131enum {
132 /* must return 1 if the background layer is supported, 0 otherwise */
133 HWC_BACKGROUND_LAYER_SUPPORTED = 0,
134};
135
Mathias Agopian5d3de302010-08-05 15:24:35 -0700136typedef struct hwc_rect {
137 int left;
138 int top;
139 int right;
140 int bottom;
141} hwc_rect_t;
142
143typedef struct hwc_region {
144 size_t numRects;
145 hwc_rect_t const* rects;
146} hwc_region_t;
147
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800148typedef struct hwc_color {
149 uint8_t r;
150 uint8_t g;
151 uint8_t b;
152 uint8_t a;
153} hwc_color_t;
154
Mathias Agopian5d3de302010-08-05 15:24:35 -0700155typedef struct hwc_layer {
156 /*
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800157 * initially set to HWC_FRAMEBUFFER or HWC_BACKGROUND.
158 * HWC_FRAMEBUFFER
159 * indicates the layer will be drawn into the framebuffer
160 * using OpenGL ES.
161 * The HWC can toggle this value to HWC_OVERLAY, to indicate
162 * it will handle the layer.
163 *
164 * HWC_BACKGROUND
165 * indicates this is a special "background" layer. The only valid
166 * field is backgroundColor. HWC_BACKGROUND can only be used with
167 * HWC_API_VERSION >= 0.2
168 * The HWC can toggle this value to HWC_FRAMEBUFFER, to indicate
169 * it CANNOT handle the background color
170 *
Mathias Agopian5d3de302010-08-05 15:24:35 -0700171 */
172 int32_t compositionType;
173
174 /* see hwc_layer_t::hints above */
175 uint32_t hints;
176
177 /* see hwc_layer_t::flags above */
178 uint32_t flags;
179
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800180 union {
181 /* color of the background. hwc_color_t.a is ignored */
182 hwc_color_t backgroundColor;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700183
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800184 struct {
Mathias Agopian5d3de302010-08-05 15:24:35 -0700185
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800186 /* handle of buffer to compose. This handle is guaranteed to have been
187 * allocated from gralloc using the GRALLOC_USAGE_HW_COMPOSER usage flag. If
188 * the layer's handle is unchanged across two consecutive prepare calls and
189 * the HWC_GEOMETRY_CHANGED flag is not set for the second call then the
190 * HWComposer implementation may assume that the contents of the buffer have
191 * not changed. */
192 buffer_handle_t handle;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700193
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800194 /* transformation to apply to the buffer during composition */
195 uint32_t transform;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700196
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800197 /* blending to apply during composition */
198 int32_t blending;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700199
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800200 /* area of the source to consider, the origin is the top-left corner of
201 * the buffer */
202 hwc_rect_t sourceCrop;
203
204 /* where to composite the sourceCrop onto the display. The sourceCrop
205 * is scaled using linear filtering to the displayFrame. The origin is the
206 * top-left corner of the screen.
207 */
208 hwc_rect_t displayFrame;
209
210 /* visible region in screen space. The origin is the
211 * top-left corner of the screen.
212 * The visible region INCLUDES areas overlapped by a translucent layer.
213 */
214 hwc_region_t visibleRegionScreen;
215 };
216 };
Mathias Agopian5d3de302010-08-05 15:24:35 -0700217} hwc_layer_t;
218
219
220/*
221 * hwc_layer_list_t::flags values
222 */
223enum {
224 /*
225 * HWC_GEOMETRY_CHANGED is set by SurfaceFlinger to indicate that the list
226 * passed to (*prepare)() has changed by more than just the buffer handles.
227 */
228 HWC_GEOMETRY_CHANGED = 0x00000001,
229};
230
Louis Huemiller871815b2010-10-25 17:00:52 -0700231/*
232 * List of layers.
233 * The handle members of hwLayers elements must be unique.
234 */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700235typedef struct hwc_layer_list {
236 uint32_t flags;
237 size_t numHwLayers;
238 hwc_layer_t hwLayers[0];
239} hwc_layer_list_t;
240
241/* This represents a display, typically an EGLDisplay object */
242typedef void* hwc_display_t;
243
244/* This represents a surface, typically an EGLSurface object */
245typedef void* hwc_surface_t;
246
Mathias Agopian5d3de302010-08-05 15:24:35 -0700247
Mathias Agopiand6afef62011-08-01 16:34:42 -0700248/* see hwc_composer_device::registerProcs()
249 * Any of the callbacks can be NULL, in which case the corresponding
250 * functionality is not supported.
251 */
252typedef struct hwc_procs {
253 /*
254 * (*invalidate)() triggers a screen refresh, in particular prepare and set
255 * will be called shortly after this call is made. Note that there is
256 * NO GUARANTEE that the screen refresh will happen after invalidate()
257 * returns (in particular, it could happen before).
258 * invalidate() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL and
259 * it is safe to call invalidate() from any of hwc_composer_device
260 * hooks, unless noted otherwise.
261 */
262 void (*invalidate)(struct hwc_procs* procs);
263} hwc_procs_t;
264
265
266/*****************************************************************************/
Mathias Agopian5d3de302010-08-05 15:24:35 -0700267
268typedef struct hwc_module {
269 struct hw_module_t common;
270} hwc_module_t;
271
272
273typedef struct hwc_composer_device {
274 struct hw_device_t common;
275
276 /*
277 * (*prepare)() is called for each frame before composition and is used by
278 * SurfaceFlinger to determine what composition steps the HWC can handle.
279 *
280 * (*prepare)() can be called more than once, the last call prevails.
281 *
282 * The HWC responds by setting the compositionType field to either
283 * HWC_FRAMEBUFFER or HWC_OVERLAY. In the former case, the composition for
284 * this layer is handled by SurfaceFlinger with OpenGL ES, in the later
285 * case, the HWC will have to handle this layer's composition.
286 *
287 * (*prepare)() is called with HWC_GEOMETRY_CHANGED to indicate that the
288 * list's geometry has changed, that is, when more than just the buffer's
289 * handles have been updated. Typically this happens (but is not limited to)
290 * when a window is added, removed, resized or moved.
291 *
292 * a NULL list parameter or a numHwLayers of zero indicates that the
293 * entire composition will be handled by SurfaceFlinger with OpenGL ES.
294 *
295 * returns: 0 on success. An negative error code on error. If an error is
296 * returned, SurfaceFlinger will assume that none of the layer will be
297 * handled by the HWC.
298 */
299 int (*prepare)(struct hwc_composer_device *dev, hwc_layer_list_t* list);
300
301
302 /*
303 * (*set)() is used in place of eglSwapBuffers(), and assumes the same
304 * functionality, except it also commits the work list atomically with
305 * the actual eglSwapBuffers().
306 *
307 * The list parameter is guaranteed to be the same as the one returned
308 * from the last call to (*prepare)().
309 *
310 * When this call returns the caller assumes that:
311 *
312 * - the display will be updated in the near future with the content
313 * of the work list, without artifacts during the transition from the
314 * previous frame.
315 *
316 * - all objects are available for immediate access or destruction, in
317 * particular, hwc_region_t::rects data and hwc_layer_t::layer's buffer.
318 * Note that this means that immediately accessing (potentially from a
319 * different process) a buffer used in this call will not result in
320 * screen corruption, the driver must apply proper synchronization or
321 * scheduling (eg: block the caller, such as gralloc_module_t::lock(),
322 * OpenGL ES, Camera, Codecs, etc..., or schedule the caller's work
323 * after the buffer is freed from the actual composition).
324 *
325 * a NULL list parameter or a numHwLayers of zero indicates that the
326 * entire composition has been handled by SurfaceFlinger with OpenGL ES.
327 * In this case, (*set)() behaves just like eglSwapBuffers().
328 *
Mathias Agopian71212e32011-11-21 17:35:15 -0800329 * dpy, sur, and list are set to NULL to indicate that the screen is
330 * turning off. This happens WITHOUT prepare() being called first.
331 * This is a good time to free h/w resources and/or power
332 * the relevant h/w blocks down.
333 *
Mathias Agopianfb410362011-11-15 21:27:52 -0800334 * IMPORTANT NOTE: there is an implicit layer containing opaque black
335 * pixels behind all the layers in the list.
336 * It is the responsibility of the hwcomposer module to make
337 * sure black pixels are output (or blended from).
338 *
Mathias Agopian5d3de302010-08-05 15:24:35 -0700339 * returns: 0 on success. An negative error code on error:
340 * HWC_EGL_ERROR: eglGetError() will provide the proper error code
341 * Another code for non EGL errors.
342 *
343 */
344 int (*set)(struct hwc_composer_device *dev,
345 hwc_display_t dpy,
346 hwc_surface_t sur,
347 hwc_layer_list_t* list);
Erik Gilling158549c2010-12-01 16:34:08 -0800348 /*
349 * This hook is OPTIONAL.
350 *
Mathias Agopiand6afef62011-08-01 16:34:42 -0700351 * If non NULL it will be called by SurfaceFlinger on dumpsys
Erik Gilling158549c2010-12-01 16:34:08 -0800352 */
353 void (*dump)(struct hwc_composer_device* dev, char *buff, int buff_len);
Mathias Agopian5d3de302010-08-05 15:24:35 -0700354
Mathias Agopiand6afef62011-08-01 16:34:42 -0700355 /*
356 * This hook is OPTIONAL.
357 *
358 * (*registerProcs)() registers a set of callbacks the h/w composer HAL
359 * can later use. It is FORBIDDEN to call any of the callbacks from
360 * within registerProcs(). registerProcs() must save the hwc_procs_t pointer
361 * which is needed when calling a registered callback.
362 * Each call to registerProcs replaces the previous set of callbacks.
363 * registerProcs is called with NULL to unregister all callbacks.
364 *
365 * Any of the callbacks can be NULL, in which case the corresponding
366 * functionality is not supported.
367 */
368 void (*registerProcs)(struct hwc_composer_device* dev,
369 hwc_procs_t const* procs);
370
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800371 /*
372 * This hook is OPTIONAL.
373 *
374 * Used to retrieve information about the h/w composer
375 *
376 * Returns 0 on success or -errno on error.
377 */
378 int (*query)(struct hwc_composer_device* dev, int what, int* value);
379
380
381 void* reserved_proc[5];
Erik Gillinge9952042010-12-07 18:46:04 -0800382
Mathias Agopian5d3de302010-08-05 15:24:35 -0700383} hwc_composer_device_t;
384
385
386/** convenience API for opening and closing a device */
387
388static inline int hwc_open(const struct hw_module_t* module,
389 hwc_composer_device_t** device) {
390 return module->methods->open(module,
391 HWC_HARDWARE_COMPOSER, (struct hw_device_t**)device);
392}
393
394static inline int hwc_close(hwc_composer_device_t* device) {
395 return device->common.close(&device->common);
396}
397
398
399/*****************************************************************************/
400
401__END_DECLS
402
403#endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H */