blob: f788e463f7b6e9cc608fa58e3aace0085db9d6d8 [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
31#define HWC_API_VERSION 1
32
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,
94};
95
96/*
97 * hwc_layer_t::blending values
98 */
99enum {
100 /* no blending */
101 HWC_BLENDING_NONE = 0x0100,
102
103 /* ONE / ONE_MINUS_SRC_ALPHA */
104 HWC_BLENDING_PREMULT = 0x0105,
105
106 /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
107 HWC_BLENDING_COVERAGE = 0x0405
108};
109
110/*
111 * hwc_layer_t::transform values
112 */
113enum {
114 /* flip source image horizontally */
115 HWC_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
116 /* flip source image vertically */
117 HWC_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
118 /* rotate source image 90 degrees clock-wise */
119 HWC_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
120 /* rotate source image 180 degrees */
121 HWC_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
122 /* rotate source image 270 degrees clock-wise */
123 HWC_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
124};
125
126typedef struct hwc_rect {
127 int left;
128 int top;
129 int right;
130 int bottom;
131} hwc_rect_t;
132
133typedef struct hwc_region {
134 size_t numRects;
135 hwc_rect_t const* rects;
136} hwc_region_t;
137
138typedef struct hwc_layer {
139 /*
140 * initially set to HWC_FRAMEBUFFER, indicates the layer will
141 * be drawn into the framebuffer using OpenGL ES.
142 * The HWC can toggle this value to HWC_OVERLAY, to indicate
143 * it will handle the layer.
144 */
145 int32_t compositionType;
146
147 /* see hwc_layer_t::hints above */
148 uint32_t hints;
149
150 /* see hwc_layer_t::flags above */
151 uint32_t flags;
152
Jamie Gennis9c5466b2011-12-20 14:33:52 -0800153 /* handle of buffer to compose. This handle is guaranteed to have been
154 * allocated from gralloc using the GRALLOC_USAGE_HW_COMPOSER usage flag. If
155 * the layer's handle is unchanged across two consecutive prepare calls and
156 * the HWC_GEOMETRY_CHANGED flag is not set for the second call then the
157 * HWComposer implementation may assume that the contents of the buffer have
158 * not changed. */
Louis Huemiller45e23712010-12-01 12:25:00 -0800159 buffer_handle_t handle;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700160
161 /* transformation to apply to the buffer during composition */
162 uint32_t transform;
163
164 /* blending to apply during composition */
165 int32_t blending;
166
167 /* area of the source to consider, the origin is the top-left corner of
168 * the buffer */
169 hwc_rect_t sourceCrop;
170
171 /* where to composite the sourceCrop onto the display. The sourceCrop
172 * is scaled using linear filtering to the displayFrame. The origin is the
173 * top-left corner of the screen.
174 */
175 hwc_rect_t displayFrame;
176
177 /* visible region in screen space. The origin is the
178 * top-left corner of the screen.
179 * The visible region INCLUDES areas overlapped by a translucent layer.
180 */
181 hwc_region_t visibleRegionScreen;
182} hwc_layer_t;
183
184
185/*
186 * hwc_layer_list_t::flags values
187 */
188enum {
189 /*
190 * HWC_GEOMETRY_CHANGED is set by SurfaceFlinger to indicate that the list
191 * passed to (*prepare)() has changed by more than just the buffer handles.
192 */
193 HWC_GEOMETRY_CHANGED = 0x00000001,
194};
195
Louis Huemiller871815b2010-10-25 17:00:52 -0700196/*
197 * List of layers.
198 * The handle members of hwLayers elements must be unique.
199 */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700200typedef struct hwc_layer_list {
201 uint32_t flags;
202 size_t numHwLayers;
203 hwc_layer_t hwLayers[0];
204} hwc_layer_list_t;
205
206/* This represents a display, typically an EGLDisplay object */
207typedef void* hwc_display_t;
208
209/* This represents a surface, typically an EGLSurface object */
210typedef void* hwc_surface_t;
211
Mathias Agopian5d3de302010-08-05 15:24:35 -0700212
Mathias Agopiand6afef62011-08-01 16:34:42 -0700213/* see hwc_composer_device::registerProcs()
214 * Any of the callbacks can be NULL, in which case the corresponding
215 * functionality is not supported.
216 */
217typedef struct hwc_procs {
218 /*
219 * (*invalidate)() triggers a screen refresh, in particular prepare and set
220 * will be called shortly after this call is made. Note that there is
221 * NO GUARANTEE that the screen refresh will happen after invalidate()
222 * returns (in particular, it could happen before).
223 * invalidate() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL and
224 * it is safe to call invalidate() from any of hwc_composer_device
225 * hooks, unless noted otherwise.
226 */
227 void (*invalidate)(struct hwc_procs* procs);
228} hwc_procs_t;
229
230
231/*****************************************************************************/
Mathias Agopian5d3de302010-08-05 15:24:35 -0700232
233typedef struct hwc_module {
234 struct hw_module_t common;
235} hwc_module_t;
236
237
238typedef struct hwc_composer_device {
239 struct hw_device_t common;
240
241 /*
242 * (*prepare)() is called for each frame before composition and is used by
243 * SurfaceFlinger to determine what composition steps the HWC can handle.
244 *
245 * (*prepare)() can be called more than once, the last call prevails.
246 *
247 * The HWC responds by setting the compositionType field to either
248 * HWC_FRAMEBUFFER or HWC_OVERLAY. In the former case, the composition for
249 * this layer is handled by SurfaceFlinger with OpenGL ES, in the later
250 * case, the HWC will have to handle this layer's composition.
251 *
252 * (*prepare)() is called with HWC_GEOMETRY_CHANGED to indicate that the
253 * list's geometry has changed, that is, when more than just the buffer's
254 * handles have been updated. Typically this happens (but is not limited to)
255 * when a window is added, removed, resized or moved.
256 *
257 * a NULL list parameter or a numHwLayers of zero indicates that the
258 * entire composition will be handled by SurfaceFlinger with OpenGL ES.
259 *
260 * returns: 0 on success. An negative error code on error. If an error is
261 * returned, SurfaceFlinger will assume that none of the layer will be
262 * handled by the HWC.
263 */
264 int (*prepare)(struct hwc_composer_device *dev, hwc_layer_list_t* list);
265
266
267 /*
268 * (*set)() is used in place of eglSwapBuffers(), and assumes the same
269 * functionality, except it also commits the work list atomically with
270 * the actual eglSwapBuffers().
271 *
272 * The list parameter is guaranteed to be the same as the one returned
273 * from the last call to (*prepare)().
274 *
275 * When this call returns the caller assumes that:
276 *
277 * - the display will be updated in the near future with the content
278 * of the work list, without artifacts during the transition from the
279 * previous frame.
280 *
281 * - all objects are available for immediate access or destruction, in
282 * particular, hwc_region_t::rects data and hwc_layer_t::layer's buffer.
283 * Note that this means that immediately accessing (potentially from a
284 * different process) a buffer used in this call will not result in
285 * screen corruption, the driver must apply proper synchronization or
286 * scheduling (eg: block the caller, such as gralloc_module_t::lock(),
287 * OpenGL ES, Camera, Codecs, etc..., or schedule the caller's work
288 * after the buffer is freed from the actual composition).
289 *
290 * a NULL list parameter or a numHwLayers of zero indicates that the
291 * entire composition has been handled by SurfaceFlinger with OpenGL ES.
292 * In this case, (*set)() behaves just like eglSwapBuffers().
293 *
Mathias Agopian71212e32011-11-21 17:35:15 -0800294 * dpy, sur, and list are set to NULL to indicate that the screen is
295 * turning off. This happens WITHOUT prepare() being called first.
296 * This is a good time to free h/w resources and/or power
297 * the relevant h/w blocks down.
298 *
Mathias Agopianfb410362011-11-15 21:27:52 -0800299 * IMPORTANT NOTE: there is an implicit layer containing opaque black
300 * pixels behind all the layers in the list.
301 * It is the responsibility of the hwcomposer module to make
302 * sure black pixels are output (or blended from).
303 *
Mathias Agopian5d3de302010-08-05 15:24:35 -0700304 * returns: 0 on success. An negative error code on error:
305 * HWC_EGL_ERROR: eglGetError() will provide the proper error code
306 * Another code for non EGL errors.
307 *
308 */
309 int (*set)(struct hwc_composer_device *dev,
310 hwc_display_t dpy,
311 hwc_surface_t sur,
312 hwc_layer_list_t* list);
Erik Gilling158549c2010-12-01 16:34:08 -0800313 /*
314 * This hook is OPTIONAL.
315 *
Mathias Agopiand6afef62011-08-01 16:34:42 -0700316 * If non NULL it will be called by SurfaceFlinger on dumpsys
Erik Gilling158549c2010-12-01 16:34:08 -0800317 */
318 void (*dump)(struct hwc_composer_device* dev, char *buff, int buff_len);
Mathias Agopian5d3de302010-08-05 15:24:35 -0700319
Mathias Agopiand6afef62011-08-01 16:34:42 -0700320 /*
321 * This hook is OPTIONAL.
322 *
323 * (*registerProcs)() registers a set of callbacks the h/w composer HAL
324 * can later use. It is FORBIDDEN to call any of the callbacks from
325 * within registerProcs(). registerProcs() must save the hwc_procs_t pointer
326 * which is needed when calling a registered callback.
327 * Each call to registerProcs replaces the previous set of callbacks.
328 * registerProcs is called with NULL to unregister all callbacks.
329 *
330 * Any of the callbacks can be NULL, in which case the corresponding
331 * functionality is not supported.
332 */
333 void (*registerProcs)(struct hwc_composer_device* dev,
334 hwc_procs_t const* procs);
335
336 void* reserved_proc[6];
Erik Gillinge9952042010-12-07 18:46:04 -0800337
Mathias Agopian5d3de302010-08-05 15:24:35 -0700338} hwc_composer_device_t;
339
340
341/** convenience API for opening and closing a device */
342
343static inline int hwc_open(const struct hw_module_t* module,
344 hwc_composer_device_t** device) {
345 return module->methods->open(module,
346 HWC_HARDWARE_COMPOSER, (struct hw_device_t**)device);
347}
348
349static inline int hwc_close(hwc_composer_device_t* device) {
350 return device->common.close(&device->common);
351}
352
353
354/*****************************************************************************/
355
356__END_DECLS
357
358#endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H */