blob: 9d6a7602d63c3521564ae53ef3562ce7108f9f0b [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
23#include <hardware/hardware.h>
24#include <cutils/native_handle.h>
25
26__BEGIN_DECLS
27
28/*****************************************************************************/
29/**
30 * The id of this module
31 */
32#define HWC_HARDWARE_MODULE_ID "hwcomposer"
33
34/**
35 * Name of the sensors device to open
36 */
37#define HWC_HARDWARE_COMPOSER "composer"
38
39
40enum {
41 /* hwc_composer_device_t::set failed in EGL */
42 HWC_EGL_ERROR = -1
43};
44
45/*
46 * hwc_layer_t::hints values
47 * Hints are set by the HAL and read by SurfaceFlinger
48 */
49enum {
50 /*
51 * HWC can set the HWC_TRIPLE_BUFFER hint to indicate to SurfaceFlinger
52 * that it should triple buffer this layer. Typically HWC does this when
53 * the layer will be unavailable for use for an extended period of time,
54 * e.g. if the display will be fetching data directly from the layer and
55 * the layer can not be modified until after the next set().
56 */
57 HWC_TRIPLE_BUFFER_HINT = 0x00000001,
58};
59
60/*
61 * hwc_layer_t::flags values
62 * Flags are set by SurfaceFlinger and read by the HAL
63 */
64enum {
65 /*
66 * HWC_SKIP_LAYER is set by SurfaceFlnger to indicate that the HAL
67 * shall not consider this layer for composition as it will be handled
68 * by SurfaceFlinger (just as if compositionType was set to HWC_OVERLAY).
69 */
70 HWC_SKIP_LAYER = 0x00000001,
71};
72
73/*
74 * hwc_layer_t::compositionType values
75 */
76enum {
77 /* this layer is to be drawn into the framebuffer by SurfaceFlinger */
78 HWC_FRAMEBUFFER = 0,
79
80 /* this layer will be handled in the HWC */
81 HWC_OVERLAY = 1,
82};
83
84/*
85 * hwc_layer_t::blending values
86 */
87enum {
88 /* no blending */
89 HWC_BLENDING_NONE = 0x0100,
90
91 /* ONE / ONE_MINUS_SRC_ALPHA */
92 HWC_BLENDING_PREMULT = 0x0105,
93
94 /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
95 HWC_BLENDING_COVERAGE = 0x0405
96};
97
98/*
99 * hwc_layer_t::transform values
100 */
101enum {
102 /* flip source image horizontally */
103 HWC_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
104 /* flip source image vertically */
105 HWC_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
106 /* rotate source image 90 degrees clock-wise */
107 HWC_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
108 /* rotate source image 180 degrees */
109 HWC_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
110 /* rotate source image 270 degrees clock-wise */
111 HWC_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
112};
113
114typedef struct hwc_rect {
115 int left;
116 int top;
117 int right;
118 int bottom;
119} hwc_rect_t;
120
121typedef struct hwc_region {
122 size_t numRects;
123 hwc_rect_t const* rects;
124} hwc_region_t;
125
126typedef struct hwc_layer {
127 /*
128 * initially set to HWC_FRAMEBUFFER, indicates the layer will
129 * be drawn into the framebuffer using OpenGL ES.
130 * The HWC can toggle this value to HWC_OVERLAY, to indicate
131 * it will handle the layer.
132 */
133 int32_t compositionType;
134
135 /* see hwc_layer_t::hints above */
136 uint32_t hints;
137
138 /* see hwc_layer_t::flags above */
139 uint32_t flags;
140
141 /* handle of buffer to compose. this handle is guaranteed to have been
142 * allocated with gralloc */
143 native_handle_t* handle;
144
145 /* transformation to apply to the buffer during composition */
146 uint32_t transform;
147
148 /* blending to apply during composition */
149 int32_t blending;
150
151 /* area of the source to consider, the origin is the top-left corner of
152 * the buffer */
153 hwc_rect_t sourceCrop;
154
155 /* where to composite the sourceCrop onto the display. The sourceCrop
156 * is scaled using linear filtering to the displayFrame. The origin is the
157 * top-left corner of the screen.
158 */
159 hwc_rect_t displayFrame;
160
161 /* visible region in screen space. The origin is the
162 * top-left corner of the screen.
163 * The visible region INCLUDES areas overlapped by a translucent layer.
164 */
165 hwc_region_t visibleRegionScreen;
166} hwc_layer_t;
167
168
169/*
170 * hwc_layer_list_t::flags values
171 */
172enum {
173 /*
174 * HWC_GEOMETRY_CHANGED is set by SurfaceFlinger to indicate that the list
175 * passed to (*prepare)() has changed by more than just the buffer handles.
176 */
177 HWC_GEOMETRY_CHANGED = 0x00000001,
178};
179
180typedef struct hwc_layer_list {
181 uint32_t flags;
182 size_t numHwLayers;
183 hwc_layer_t hwLayers[0];
184} hwc_layer_list_t;
185
186/* This represents a display, typically an EGLDisplay object */
187typedef void* hwc_display_t;
188
189/* This represents a surface, typically an EGLSurface object */
190typedef void* hwc_surface_t;
191
192/*****************************************************************************/
193
194
195typedef struct hwc_module {
196 struct hw_module_t common;
197} hwc_module_t;
198
199
200typedef struct hwc_composer_device {
201 struct hw_device_t common;
202
203 /*
204 * (*prepare)() is called for each frame before composition and is used by
205 * SurfaceFlinger to determine what composition steps the HWC can handle.
206 *
207 * (*prepare)() can be called more than once, the last call prevails.
208 *
209 * The HWC responds by setting the compositionType field to either
210 * HWC_FRAMEBUFFER or HWC_OVERLAY. In the former case, the composition for
211 * this layer is handled by SurfaceFlinger with OpenGL ES, in the later
212 * case, the HWC will have to handle this layer's composition.
213 *
214 * (*prepare)() is called with HWC_GEOMETRY_CHANGED to indicate that the
215 * list's geometry has changed, that is, when more than just the buffer's
216 * handles have been updated. Typically this happens (but is not limited to)
217 * when a window is added, removed, resized or moved.
218 *
219 * a NULL list parameter or a numHwLayers of zero indicates that the
220 * entire composition will be handled by SurfaceFlinger with OpenGL ES.
221 *
222 * returns: 0 on success. An negative error code on error. If an error is
223 * returned, SurfaceFlinger will assume that none of the layer will be
224 * handled by the HWC.
225 */
226 int (*prepare)(struct hwc_composer_device *dev, hwc_layer_list_t* list);
227
228
229 /*
230 * (*set)() is used in place of eglSwapBuffers(), and assumes the same
231 * functionality, except it also commits the work list atomically with
232 * the actual eglSwapBuffers().
233 *
234 * The list parameter is guaranteed to be the same as the one returned
235 * from the last call to (*prepare)().
236 *
237 * When this call returns the caller assumes that:
238 *
239 * - the display will be updated in the near future with the content
240 * of the work list, without artifacts during the transition from the
241 * previous frame.
242 *
243 * - all objects are available for immediate access or destruction, in
244 * particular, hwc_region_t::rects data and hwc_layer_t::layer's buffer.
245 * Note that this means that immediately accessing (potentially from a
246 * different process) a buffer used in this call will not result in
247 * screen corruption, the driver must apply proper synchronization or
248 * scheduling (eg: block the caller, such as gralloc_module_t::lock(),
249 * OpenGL ES, Camera, Codecs, etc..., or schedule the caller's work
250 * after the buffer is freed from the actual composition).
251 *
252 * a NULL list parameter or a numHwLayers of zero indicates that the
253 * entire composition has been handled by SurfaceFlinger with OpenGL ES.
254 * In this case, (*set)() behaves just like eglSwapBuffers().
255 *
256 * returns: 0 on success. An negative error code on error:
257 * HWC_EGL_ERROR: eglGetError() will provide the proper error code
258 * Another code for non EGL errors.
259 *
260 */
261 int (*set)(struct hwc_composer_device *dev,
262 hwc_display_t dpy,
263 hwc_surface_t sur,
264 hwc_layer_list_t* list);
265
266} hwc_composer_device_t;
267
268
269/** convenience API for opening and closing a device */
270
271static inline int hwc_open(const struct hw_module_t* module,
272 hwc_composer_device_t** device) {
273 return module->methods->open(module,
274 HWC_HARDWARE_COMPOSER, (struct hw_device_t**)device);
275}
276
277static inline int hwc_close(hwc_composer_device_t* device) {
278 return device->common.close(&device->common);
279}
280
281
282/*****************************************************************************/
283
284__END_DECLS
285
286#endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H */