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