blob: 4818d0bb108e8de499a136407588b2f546f09f4d [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
Mathias Agopiane291f712012-05-13 22:49:06 -070027#include <hardware/hwcomposer_defs.h>
28
Mathias Agopian5d3de302010-08-05 15:24:35 -070029__BEGIN_DECLS
30
31/*****************************************************************************/
Erik Gillinge9952042010-12-07 18:46:04 -080032
Jesse Halld479ad22012-06-05 23:41:37 -070033/* for compatibility */
Mathias Agopianb08d45d2012-03-24 15:56:29 -070034#define HWC_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1
35#define HWC_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1
Mathias Agopian81c323d2012-03-25 01:09:35 -070036#define HWC_API_VERSION HWC_DEVICE_API_VERSION
Erik Gillinge9952042010-12-07 18:46:04 -080037
Jesse Halld479ad22012-06-05 23:41:37 -070038/*****************************************************************************/
39
Mathias Agopian5d3de302010-08-05 15:24:35 -070040/**
41 * The id of this module
42 */
43#define HWC_HARDWARE_MODULE_ID "hwcomposer"
44
45/**
46 * Name of the sensors device to open
47 */
48#define HWC_HARDWARE_COMPOSER "composer"
49
Mathias Agopian5d3de302010-08-05 15:24:35 -070050typedef struct hwc_rect {
51 int left;
52 int top;
53 int right;
54 int bottom;
55} hwc_rect_t;
56
Mathias Agopian3b4732c2013-07-09 19:55:41 -070057typedef struct hwc_frect {
58 float left;
59 float top;
60 float right;
61 float bottom;
62} hwc_frect_t;
63
Mathias Agopian5d3de302010-08-05 15:24:35 -070064typedef struct hwc_region {
65 size_t numRects;
66 hwc_rect_t const* rects;
67} hwc_region_t;
68
Mathias Agopianeb8fb502012-02-03 15:54:11 -080069typedef struct hwc_color {
70 uint8_t r;
71 uint8_t g;
72 uint8_t b;
73 uint8_t a;
74} hwc_color_t;
75
Jesse Halld479ad22012-06-05 23:41:37 -070076typedef struct hwc_layer_1 {
Mathias Agopian5d3de302010-08-05 15:24:35 -070077 /*
Mathias Agopian48697f62012-11-20 15:23:25 -080078 * compositionType is used to specify this layer's type and is set by either
79 * the hardware composer implementation, or by the caller (see below).
Jesse Halld18c83f2012-08-16 16:21:13 -070080 *
Mathias Agopian48697f62012-11-20 15:23:25 -080081 * This field is always reset to HWC_BACKGROUND or HWC_FRAMEBUFFER
82 * before (*prepare)() is called when the HWC_GEOMETRY_CHANGED flag is
83 * also set, otherwise, this field is preserved between (*prepare)()
84 * calls.
Mathias Agopianeb8fb502012-02-03 15:54:11 -080085 *
86 * HWC_BACKGROUND
Mathias Agopian48697f62012-11-20 15:23:25 -080087 * Always set by the caller before calling (*prepare)(), this value
88 * indicates this is a special "background" layer. The only valid field
89 * is backgroundColor.
90 * The HWC can toggle this value to HWC_FRAMEBUFFER to indicate it CANNOT
91 * handle the background color.
92 *
Mathias Agopianeb8fb502012-02-03 15:54:11 -080093 *
Jesse Halld18c83f2012-08-16 16:21:13 -070094 * HWC_FRAMEBUFFER_TARGET
Mathias Agopian48697f62012-11-20 15:23:25 -080095 * Always set by the caller before calling (*prepare)(), this value
96 * indicates this layer is the framebuffer surface used as the target of
Jesse Halld18c83f2012-08-16 16:21:13 -070097 * OpenGL ES composition. If the HWC sets all other layers to HWC_OVERLAY
98 * or HWC_BACKGROUND, then no OpenGL ES composition will be done, and
Jesse Hall6b01e2e2012-09-14 17:21:22 -070099 * this layer should be ignored during set().
Jesse Halld18c83f2012-08-16 16:21:13 -0700100 *
101 * This flag (and the framebuffer surface layer) will only be used if the
102 * HWC version is HWC_DEVICE_API_VERSION_1_1 or higher. In older versions,
103 * the OpenGL ES target surface is communicated by the (dpy, sur) fields
104 * in hwc_compositor_device_1_t.
Mathias Agopian48697f62012-11-20 15:23:25 -0800105 *
106 * This value cannot be set by the HWC implementation.
107 *
108 *
109 * HWC_FRAMEBUFFER
110 * Set by the caller before calling (*prepare)() ONLY when the
111 * HWC_GEOMETRY_CHANGED flag is also set.
112 *
113 * Set by the HWC implementation during (*prepare)(), this indicates
114 * that the layer will be drawn into the framebuffer using OpenGL ES.
115 * The HWC can toggle this value to HWC_OVERLAY to indicate it will
116 * handle the layer.
117 *
118 *
119 * HWC_OVERLAY
120 * Set by the HWC implementation during (*prepare)(), this indicates
121 * that the layer will be handled by the HWC (ie: it must not be
122 * composited with OpenGL ES).
123 *
Jesse Hall8c79c082014-02-13 15:38:56 -0800124 *
125 * HWC_SIDEBAND
126 * Set by the caller before calling (*prepare)(), this value indicates
127 * the contents of this layer come from a sideband video stream.
128 *
129 * The h/w composer is responsible for receiving new image buffers from
130 * the stream at the appropriate time (e.g. synchronized to a separate
131 * audio stream), compositing them with the current contents of other
132 * layers, and displaying the resulting image. This happens
133 * independently of the normal prepare/set cycle. The prepare/set calls
134 * only happen when other layers change, or when properties of the
135 * sideband layer such as position or size change.
136 *
137 * If the h/w composer can't handle the layer as a sideband stream for
138 * some reason (e.g. unsupported scaling/blending/rotation, or too many
139 * sideband layers) it can set compositionType to HWC_FRAMEBUFFER in
140 * (*prepare)(). However, doing so will result in the layer being shown
141 * as a solid color since the platform is not currently able to composite
142 * sideband layers with the GPU. This may be improved in future
143 * versions of the platform.
Riley Andrews4a6788b2014-06-30 15:55:55 -0700144 *
145 *
146 * HWC_CURSOR_OVERLAY
147 * Set by the HWC implementation during (*prepare)(), this value
148 * indicates the layer's composition will now be handled by the HWC.
149 * Additionally, the client can now asynchronously update the on-screen
150 * position of this layer using the setCursorPositionAsync() api.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700151 */
152 int32_t compositionType;
153
Mathias Agopian48697f62012-11-20 15:23:25 -0800154 /*
155 * hints is bit mask set by the HWC implementation during (*prepare)().
156 * It is preserved between (*prepare)() calls, unless the
157 * HWC_GEOMETRY_CHANGED flag is set, in which case it is reset to 0.
158 *
159 * see hwc_layer_t::hints
160 */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700161 uint32_t hints;
162
Mathias Agopian48697f62012-11-20 15:23:25 -0800163 /* see hwc_layer_t::flags */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700164 uint32_t flags;
165
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800166 union {
167 /* color of the background. hwc_color_t.a is ignored */
168 hwc_color_t backgroundColor;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700169
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800170 struct {
Jesse Hall8c79c082014-02-13 15:38:56 -0800171 union {
172 /* When compositionType is HWC_FRAMEBUFFER, HWC_OVERLAY,
173 * HWC_FRAMEBUFFER_TARGET, this is the handle of the buffer to
174 * compose. This handle is guaranteed to have been allocated
175 * from gralloc using the GRALLOC_USAGE_HW_COMPOSER usage flag.
176 * If the layer's handle is unchanged across two consecutive
177 * prepare calls and the HWC_GEOMETRY_CHANGED flag is not set
178 * for the second call then the HWComposer implementation may
179 * assume that the contents of the buffer have not changed. */
180 buffer_handle_t handle;
181
182 /* When compositionType is HWC_SIDEBAND, this is the handle
183 * of the sideband video stream to compose. */
184 const native_handle_t* sidebandStream;
185 };
Mathias Agopian5d3de302010-08-05 15:24:35 -0700186
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800187 /* transformation to apply to the buffer during composition */
188 uint32_t transform;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700189
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800190 /* blending to apply during composition */
191 int32_t blending;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700192
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800193 /* area of the source to consider, the origin is the top-left corner of
Mathias Agopian3b4732c2013-07-09 19:55:41 -0700194 * the buffer. As of HWC_DEVICE_API_VERSION_1_3, sourceRect uses floats.
195 * If the h/w can't support a non-integer source crop rectangle, it should
196 * punt to OpenGL ES composition.
197 */
198 union {
199 // crop rectangle in integer (pre HWC_DEVICE_API_VERSION_1_3)
200 hwc_rect_t sourceCropi;
201 hwc_rect_t sourceCrop; // just for source compatibility
202 // crop rectangle in floats (as of HWC_DEVICE_API_VERSION_1_3)
203 hwc_frect_t sourceCropf;
204 };
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800205
206 /* where to composite the sourceCrop onto the display. The sourceCrop
207 * is scaled using linear filtering to the displayFrame. The origin is the
208 * top-left corner of the screen.
209 */
210 hwc_rect_t displayFrame;
211
212 /* visible region in screen space. The origin is the
213 * top-left corner of the screen.
214 * The visible region INCLUDES areas overlapped by a translucent layer.
215 */
216 hwc_region_t visibleRegionScreen;
Jesse Halld479ad22012-06-05 23:41:37 -0700217
Xiaoming Zhoub6f04e42014-05-23 15:18:23 -0400218 /* Region of the layer changed in the source buffer since
219 * previous frame */
220 hwc_rect_t dirtyRect;
221
Jesse Halld479ad22012-06-05 23:41:37 -0700222 /* Sync fence object that will be signaled when the buffer's
223 * contents are available. May be -1 if the contents are already
224 * available. This field is only valid during set(), and should be
225 * ignored during prepare(). The set() call must not wait for the
226 * fence to be signaled before returning, but the HWC must wait for
227 * all buffers to be signaled before reading from them.
228 *
Jesse Hall0a0a4162012-08-21 12:06:28 -0700229 * HWC_FRAMEBUFFER layers will never have an acquire fence, since
230 * reads from them are complete before the framebuffer is ready for
231 * display.
232 *
Jesse Hall8c79c082014-02-13 15:38:56 -0800233 * HWC_SIDEBAND layers will never have an acquire fence, since
234 * synchronization is handled through implementation-defined
235 * sideband mechanisms.
236 *
Jesse Halld479ad22012-06-05 23:41:37 -0700237 * The HWC takes ownership of the acquireFenceFd and is responsible
238 * for closing it when no longer needed.
239 */
240 int acquireFenceFd;
241
242 /* During set() the HWC must set this field to a file descriptor for
243 * a sync fence object that will signal after the HWC has finished
244 * reading from the buffer. The field is ignored by prepare(). Each
245 * layer should have a unique file descriptor, even if more than one
246 * refer to the same underlying fence object; this allows each to be
247 * closed independently.
248 *
249 * If buffer reads can complete at significantly different times,
250 * then using independent fences is preferred. For example, if the
251 * HWC handles some layers with a blit engine and others with
252 * overlays, then the blit layers can be reused immediately after
253 * the blit completes, but the overlay layers can't be reused until
254 * a subsequent frame has been displayed.
255 *
Jesse Hall0a0a4162012-08-21 12:06:28 -0700256 * Since HWC doesn't read from HWC_FRAMEBUFFER layers, it shouldn't
257 * produce a release fence for them. The releaseFenceFd will be -1
258 * for these layers when set() is called.
259 *
Jesse Hall8c79c082014-02-13 15:38:56 -0800260 * Since HWC_SIDEBAND buffers don't pass through the HWC client,
261 * the HWC shouldn't produce a release fence for them. The
262 * releaseFenceFd will be -1 for these layers when set() is called.
263 *
Jesse Halld479ad22012-06-05 23:41:37 -0700264 * The HWC client taks ownership of the releaseFenceFd and is
265 * responsible for closing it when no longer needed.
266 */
267 int releaseFenceFd;
Mathias Agopiane3e0a572013-01-29 18:57:48 -0800268
269 /*
270 * Availability: HWC_DEVICE_API_VERSION_1_2
271 *
272 * Alpha value applied to the whole layer. The effective
273 * value of each pixel is computed as:
274 *
275 * if (blending == HWC_BLENDING_PREMULT)
276 * pixel.rgb = pixel.rgb * planeAlpha / 255
277 * pixel.a = pixel.a * planeAlpha / 255
278 *
279 * Then blending proceeds as usual according to the "blending"
280 * field above.
281 *
282 * NOTE: planeAlpha applies to YUV layers as well:
283 *
284 * pixel.rgb = yuv_to_rgb(pixel.yuv)
285 * if (blending == HWC_BLENDING_PREMULT)
286 * pixel.rgb = pixel.rgb * planeAlpha / 255
287 * pixel.a = planeAlpha
288 *
289 *
290 * IMPLEMENTATION NOTE:
291 *
292 * If the source image doesn't have an alpha channel, then
293 * the h/w can use the HWC_BLENDING_COVERAGE equations instead of
294 * HWC_BLENDING_PREMULT and simply set the alpha channel to
295 * planeAlpha.
296 *
297 * e.g.:
298 *
299 * if (blending == HWC_BLENDING_PREMULT)
300 * blending = HWC_BLENDING_COVERAGE;
301 * pixel.a = planeAlpha;
302 *
303 */
304 uint8_t planeAlpha;
305
306 /* reserved for future use */
307 uint8_t _pad[3];
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800308 };
309 };
Mathias Agopian5d3de302010-08-05 15:24:35 -0700310
Dan Stoza91699a82014-06-04 15:21:22 -0700311#ifdef __LP64__
312 /*
313 * For 64-bit mode, this struct is 120 bytes (and 8-byte aligned), and needs
314 * to be padded as such to maintain binary compatibility.
Jesse Halld479ad22012-06-05 23:41:37 -0700315 */
Dan Stoza91699a82014-06-04 15:21:22 -0700316 uint8_t reserved[120 - 96];
317#else
318 /*
319 * For 32-bit mode, this struct is 96 bytes, and needs to be padded as such
320 * to maintain binary compatibility.
321 */
322 uint8_t reserved[96 - 76];
323#endif
Jesse Halld479ad22012-06-05 23:41:37 -0700324
325} hwc_layer_1_t;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700326
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700327/* This represents a display, typically an EGLDisplay object */
328typedef void* hwc_display_t;
329
330/* This represents a surface, typically an EGLSurface object */
331typedef void* hwc_surface_t;
332
Mathias Agopian5d3de302010-08-05 15:24:35 -0700333/*
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700334 * hwc_display_contents_1_t::flags values
Mathias Agopian5d3de302010-08-05 15:24:35 -0700335 */
336enum {
337 /*
338 * HWC_GEOMETRY_CHANGED is set by SurfaceFlinger to indicate that the list
Jesse Halld479ad22012-06-05 23:41:37 -0700339 * passed to (*prepare)() has changed by more than just the buffer handles
340 * and acquire fences.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700341 */
342 HWC_GEOMETRY_CHANGED = 0x00000001,
343};
344
Louis Huemiller871815b2010-10-25 17:00:52 -0700345/*
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700346 * Description of the contents to output on a display.
347 *
348 * This is the top-level structure passed to the prepare and set calls to
349 * negotiate and commit the composition of a display image.
Louis Huemiller871815b2010-10-25 17:00:52 -0700350 */
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700351typedef struct hwc_display_contents_1 {
352 /* File descriptor referring to a Sync HAL fence object which will signal
Jesse Hall7cb03d72012-09-06 16:57:12 -0700353 * when this composition is retired. For a physical display, a composition
354 * is retired when it has been replaced on-screen by a subsequent set. For
355 * a virtual display, the composition is retired when the writes to
356 * outputBuffer are complete and can be read. The fence object is created
357 * and returned by the set call; this field will be -1 on entry to prepare
358 * and set. SurfaceFlinger will close the returned file descriptor.
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700359 */
Jesse Hall7cb03d72012-09-06 16:57:12 -0700360 int retireFenceFd;
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700361
Jesse Hall7cb03d72012-09-06 16:57:12 -0700362 union {
363 /* Fields only relevant for HWC_DEVICE_VERSION_1_0. */
364 struct {
365 /* (dpy, sur) is the target of SurfaceFlinger's OpenGL ES
366 * composition for HWC_DEVICE_VERSION_1_0. They aren't relevant to
367 * prepare. The set call should commit this surface atomically to
368 * the display along with any overlay layers.
369 */
370 hwc_display_t dpy;
371 hwc_surface_t sur;
372 };
373
Jesse Hall7ccf1482013-11-13 14:48:15 -0800374 /* These fields are used for virtual displays when the h/w composer
375 * version is at least HWC_DEVICE_VERSION_1_3. */
Jesse Hall7cb03d72012-09-06 16:57:12 -0700376 struct {
377 /* outbuf is the buffer that receives the composed image for
378 * virtual displays. Writes to the outbuf must wait until
379 * outbufAcquireFenceFd signals. A fence that will signal when
380 * writes to outbuf are complete should be returned in
381 * retireFenceFd.
382 *
Jesse Hall7ccf1482013-11-13 14:48:15 -0800383 * This field is set before prepare(), so properties of the buffer
384 * can be used to decide which layers can be handled by h/w
385 * composer.
Jesse Hall380f45d2013-03-20 10:11:10 -0700386 *
Jesse Hall7ccf1482013-11-13 14:48:15 -0800387 * If prepare() sets all layers to FRAMEBUFFER, then GLES
388 * composition will happen directly to the output buffer. In this
389 * case, both outbuf and the FRAMEBUFFER_TARGET layer's buffer will
390 * be the same, and set() has no work to do besides managing fences.
391 *
392 * If the TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS board config
393 * variable is defined (not the default), then this behavior is
394 * changed: if all layers are marked for FRAMEBUFFER, GLES
395 * composition will take place to a scratch framebuffer, and
396 * h/w composer must copy it to the output buffer. This allows the
397 * h/w composer to do format conversion if there are cases where
398 * that is more desirable than doing it in the GLES driver or at the
399 * virtual display consumer.
400 *
401 * If some or all layers are marked OVERLAY, then the framebuffer
402 * and output buffer will be different. As with physical displays,
403 * the framebuffer handle will not change between frames if all
404 * layers are marked for OVERLAY.
Jesse Hall7cb03d72012-09-06 16:57:12 -0700405 */
406 buffer_handle_t outbuf;
407
408 /* File descriptor for a fence that will signal when outbuf is
409 * ready to be written. The h/w composer is responsible for closing
410 * this when no longer needed.
411 *
412 * Will be -1 whenever outbuf is NULL, or when the outbuf can be
413 * written immediately.
414 */
415 int outbufAcquireFenceFd;
416 };
417 };
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700418
419 /* List of layers that will be composed on the display. The buffer handles
Jesse Hallac3f7e12012-07-31 15:18:32 -0700420 * in the list will be unique. If numHwLayers is 0, all composition will be
421 * performed by SurfaceFlinger.
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700422 */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700423 uint32_t flags;
424 size_t numHwLayers;
Jesse Halld479ad22012-06-05 23:41:37 -0700425 hwc_layer_1_t hwLayers[0];
Mathias Agopian5d3de302010-08-05 15:24:35 -0700426
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700427} hwc_display_contents_1_t;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700428
Mathias Agopiand6afef62011-08-01 16:34:42 -0700429/* see hwc_composer_device::registerProcs()
Jesse Hall0a0a4162012-08-21 12:06:28 -0700430 * All of the callbacks are required and non-NULL unless otherwise noted.
Mathias Agopiand6afef62011-08-01 16:34:42 -0700431 */
432typedef struct hwc_procs {
433 /*
434 * (*invalidate)() triggers a screen refresh, in particular prepare and set
435 * will be called shortly after this call is made. Note that there is
436 * NO GUARANTEE that the screen refresh will happen after invalidate()
437 * returns (in particular, it could happen before).
438 * invalidate() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL and
439 * it is safe to call invalidate() from any of hwc_composer_device
440 * hooks, unless noted otherwise.
441 */
Jesse Hall0a0a4162012-08-21 12:06:28 -0700442 void (*invalidate)(const struct hwc_procs* procs);
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700443
444 /*
445 * (*vsync)() is called by the h/w composer HAL when a vsync event is
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700446 * received and HWC_EVENT_VSYNC is enabled on a display
447 * (see: hwc_event_control).
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700448 *
Jesse Hall2c137592012-08-29 10:37:37 -0700449 * the "disp" parameter indicates which display the vsync event is for.
Jamie Gennis6b7adef2012-04-30 12:57:11 -0700450 * the "timestamp" parameter is the system monotonic clock timestamp in
451 * nanosecond of when the vsync event happened.
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700452 *
453 * vsync() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL.
454 *
455 * It is expected that vsync() is called from a thread of at least
Mathias Agopianeb671602012-04-24 15:42:37 -0700456 * HAL_PRIORITY_URGENT_DISPLAY with as little latency as possible,
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700457 * typically less than 0.5 ms.
458 *
Mathias Agopian6d3fec72012-04-10 21:22:28 -0700459 * It is a (silent) error to have HWC_EVENT_VSYNC enabled when calling
460 * hwc_composer_device.set(..., 0, 0, 0) (screen off). The implementation
461 * can either stop or continue to process VSYNC events, but must not
462 * crash or cause other problems.
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700463 */
Jesse Hall2c137592012-08-29 10:37:37 -0700464 void (*vsync)(const struct hwc_procs* procs, int disp, int64_t timestamp);
465
466 /*
467 * (*hotplug)() is called by the h/w composer HAL when a display is
468 * connected or disconnected. The PRIMARY display is always connected and
469 * the hotplug callback should not be called for it.
470 *
471 * The disp parameter indicates which display type this event is for.
472 * The connected parameter indicates whether the display has just been
473 * connected (1) or disconnected (0).
474 *
475 * The hotplug() callback may call back into the h/w composer on the same
476 * thread to query refresh rate and dpi for the display. Additionally,
477 * other threads may be calling into the h/w composer while the callback
478 * is in progress.
479 *
Jesse Halld91697a2012-09-19 22:53:30 -0700480 * The h/w composer must serialize calls to the hotplug callback; only
481 * one thread may call it at a time.
482 *
Jesse Hall2c137592012-08-29 10:37:37 -0700483 * This callback will be NULL if the h/w composer is using
484 * HWC_DEVICE_API_VERSION_1_0.
485 */
486 void (*hotplug)(const struct hwc_procs* procs, int disp, int connected);
487
Mathias Agopiand6afef62011-08-01 16:34:42 -0700488} hwc_procs_t;
489
490
491/*****************************************************************************/
Mathias Agopian5d3de302010-08-05 15:24:35 -0700492
493typedef struct hwc_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700494 /**
495 * Common methods of the hardware composer module. This *must* be the first member of
496 * hwc_module as users of this structure will cast a hw_module_t to
497 * hwc_module pointer in contexts where it's known the hw_module_t references a
498 * hwc_module.
499 */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700500 struct hw_module_t common;
501} hwc_module_t;
502
Jesse Halld479ad22012-06-05 23:41:37 -0700503typedef struct hwc_composer_device_1 {
Stewart Miles84d35492014-05-01 09:03:27 -0700504 /**
505 * Common methods of the hardware composer device. This *must* be the first member of
506 * hwc_composer_device_1 as users of this structure will cast a hw_device_t to
507 * hwc_composer_device_1 pointer in contexts where it's known the hw_device_t references a
508 * hwc_composer_device_1.
509 */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700510 struct hw_device_t common;
511
512 /*
513 * (*prepare)() is called for each frame before composition and is used by
514 * SurfaceFlinger to determine what composition steps the HWC can handle.
515 *
516 * (*prepare)() can be called more than once, the last call prevails.
517 *
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700518 * The HWC responds by setting the compositionType field in each layer to
Riley Andrews4a6788b2014-06-30 15:55:55 -0700519 * either HWC_FRAMEBUFFER, HWC_OVERLAY, or HWC_CURSOR_OVERLAY. For the
520 * HWC_FRAMEBUFFER type, composition for the layer is handled by
521 * SurfaceFlinger with OpenGL ES. For the latter two overlay types,
522 * the HWC will have to handle the layer's composition. compositionType
523 * and hints are preserved between (*prepare)() calles unless the
524 * HWC_GEOMETRY_CHANGED flag is set.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700525 *
526 * (*prepare)() is called with HWC_GEOMETRY_CHANGED to indicate that the
527 * list's geometry has changed, that is, when more than just the buffer's
528 * handles have been updated. Typically this happens (but is not limited to)
Mathias Agopian48697f62012-11-20 15:23:25 -0800529 * when a window is added, removed, resized or moved. In this case
530 * compositionType and hints are reset to their default value.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700531 *
Jesse Hall43b51d92012-08-22 11:42:57 -0700532 * For HWC 1.0, numDisplays will always be one, and displays[0] will be
533 * non-NULL.
534 *
Jesse Hallfc0ff2a2013-08-16 11:13:36 -0700535 * For HWC 1.1, numDisplays will always be HWC_NUM_PHYSICAL_DISPLAY_TYPES.
536 * Entries for unsupported or disabled/disconnected display types will be
537 * NULL.
Jesse Hall43b51d92012-08-22 11:42:57 -0700538 *
Jesse Hallfc0ff2a2013-08-16 11:13:36 -0700539 * In HWC 1.3, numDisplays may be up to HWC_NUM_DISPLAY_TYPES. The extra
540 * entries correspond to enabled virtual displays, and will be non-NULL.
Jesse Hallac3f7e12012-07-31 15:18:32 -0700541 *
Mathias Agopian5d3de302010-08-05 15:24:35 -0700542 * returns: 0 on success. An negative error code on error. If an error is
543 * returned, SurfaceFlinger will assume that none of the layer will be
544 * handled by the HWC.
545 */
Jesse Halld479ad22012-06-05 23:41:37 -0700546 int (*prepare)(struct hwc_composer_device_1 *dev,
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700547 size_t numDisplays, hwc_display_contents_1_t** displays);
Mathias Agopian5d3de302010-08-05 15:24:35 -0700548
549 /*
550 * (*set)() is used in place of eglSwapBuffers(), and assumes the same
551 * functionality, except it also commits the work list atomically with
552 * the actual eglSwapBuffers().
553 *
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700554 * The layer lists are guaranteed to be the same as the ones returned from
555 * the last call to (*prepare)().
Mathias Agopian5d3de302010-08-05 15:24:35 -0700556 *
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700557 * When this call returns the caller assumes that the displays will be
558 * updated in the near future with the content of their work lists, without
559 * artifacts during the transition from the previous frame.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700560 *
Jesse Hallac3f7e12012-07-31 15:18:32 -0700561 * A display with zero layers indicates that the entire composition has
562 * been handled by SurfaceFlinger with OpenGL ES. In this case, (*set)()
563 * behaves just like eglSwapBuffers().
Mathias Agopian5d3de302010-08-05 15:24:35 -0700564 *
Jesse Hall43b51d92012-08-22 11:42:57 -0700565 * For HWC 1.0, numDisplays will always be one, and displays[0] will be
566 * non-NULL.
567 *
Jesse Hallfc0ff2a2013-08-16 11:13:36 -0700568 * For HWC 1.1, numDisplays will always be HWC_NUM_PHYSICAL_DISPLAY_TYPES.
569 * Entries for unsupported or disabled/disconnected display types will be
570 * NULL.
Jesse Hall43b51d92012-08-22 11:42:57 -0700571 *
Jesse Hallfc0ff2a2013-08-16 11:13:36 -0700572 * In HWC 1.3, numDisplays may be up to HWC_NUM_DISPLAY_TYPES. The extra
573 * entries correspond to enabled virtual displays, and will be non-NULL.
Mathias Agopian71212e32011-11-21 17:35:15 -0800574 *
Jamie Gennisc7545182012-10-08 19:23:56 -0700575 * IMPORTANT NOTE: There is an implicit layer containing opaque black
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700576 * pixels behind all the layers in the list. It is the responsibility of
577 * the hwcomposer module to make sure black pixels are output (or blended
578 * from).
Mathias Agopianfb410362011-11-15 21:27:52 -0800579 *
Jamie Gennisc7545182012-10-08 19:23:56 -0700580 * IMPORTANT NOTE: In the event of an error this call *MUST* still cause
581 * any fences returned in the previous call to set to eventually become
582 * signaled. The caller may have already issued wait commands on these
583 * fences, and having set return without causing those fences to signal
584 * will likely result in a deadlock.
585 *
586 * returns: 0 on success. A negative error code on error:
587 * HWC_EGL_ERROR: eglGetError() will provide the proper error code (only
588 * allowed prior to HWComposer 1.1)
Mathias Agopian5d3de302010-08-05 15:24:35 -0700589 * Another code for non EGL errors.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700590 */
Jesse Halld479ad22012-06-05 23:41:37 -0700591 int (*set)(struct hwc_composer_device_1 *dev,
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700592 size_t numDisplays, hwc_display_contents_1_t** displays);
Jesse Halld479ad22012-06-05 23:41:37 -0700593
Erik Gilling158549c2010-12-01 16:34:08 -0800594 /*
Jesse Hall0a0a4162012-08-21 12:06:28 -0700595 * eventControl(..., event, enabled)
596 * Enables or disables h/w composer events for a display.
Erik Gilling158549c2010-12-01 16:34:08 -0800597 *
Jesse Hall0a0a4162012-08-21 12:06:28 -0700598 * eventControl can be called from any thread and takes effect
599 * immediately.
600 *
601 * Supported events are:
602 * HWC_EVENT_VSYNC
603 *
604 * returns -EINVAL if the "event" parameter is not one of the value above
605 * or if the "enabled" parameter is not 0 or 1.
Erik Gilling158549c2010-12-01 16:34:08 -0800606 */
Jesse Hall2c137592012-08-29 10:37:37 -0700607 int (*eventControl)(struct hwc_composer_device_1* dev, int disp,
Jesse Hall0a0a4162012-08-21 12:06:28 -0700608 int event, int enabled);
Mathias Agopian5d3de302010-08-05 15:24:35 -0700609
Prashant Malani02b31982014-05-25 20:41:20 -0700610 union {
611 /*
612 * For HWC 1.3 and earlier, the blank() interface is used.
613 *
614 * blank(..., blank)
615 * Blanks or unblanks a display's screen.
616 *
617 * Turns the screen off when blank is nonzero, on when blank is zero.
618 * Multiple sequential calls with the same blank value must be
619 * supported.
620 * The screen state transition must be be complete when the function
621 * returns.
622 *
623 * returns 0 on success, negative on error.
624 */
625 int (*blank)(struct hwc_composer_device_1* dev, int disp, int blank);
626
627 /*
628 * For HWC 1.4 and above, setPowerMode() will be used in place of
629 * blank().
630 *
631 * setPowerMode(..., mode)
632 * Sets the display screen's power state.
633 *
Jeff Brown842b9062014-07-17 20:01:59 -0700634 * Refer to the documentation of the HWC_POWER_MODE_* constants
635 * for information about each power mode.
Prashant Malani02b31982014-05-25 20:41:20 -0700636 *
637 * The functionality is similar to the blank() command in previous
638 * versions of HWC, but with support for more power states.
639 *
640 * The display driver is expected to retain and restore the low power
641 * state of the display while entering and exiting from suspend.
642 *
643 * Multiple sequential calls with the same mode value must be supported.
644 *
645 * The screen state transition must be be complete when the function
646 * returns.
647 *
648 * returns 0 on success, negative on error.
649 */
650 int (*setPowerMode)(struct hwc_composer_device_1* dev, int disp,
651 int mode);
652 };
Mathias Agopiand6afef62011-08-01 16:34:42 -0700653
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800654 /*
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800655 * Used to retrieve information about the h/w composer
656 *
657 * Returns 0 on success or -errno on error.
658 */
Jesse Halld479ad22012-06-05 23:41:37 -0700659 int (*query)(struct hwc_composer_device_1* dev, int what, int* value);
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800660
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700661 /*
Jesse Hall0a0a4162012-08-21 12:06:28 -0700662 * (*registerProcs)() registers callbacks that the h/w composer HAL can
663 * later use. It will be called immediately after the composer device is
664 * opened with non-NULL procs. It is FORBIDDEN to call any of the callbacks
665 * from within registerProcs(). registerProcs() must save the hwc_procs_t
666 * pointer which is needed when calling a registered callback.
667 */
668 void (*registerProcs)(struct hwc_composer_device_1* dev,
669 hwc_procs_t const* procs);
670
671 /*
672 * This field is OPTIONAL and can be NULL.
673 *
674 * If non NULL it will be called by SurfaceFlinger on dumpsys
675 */
676 void (*dump)(struct hwc_composer_device_1* dev, char *buff, int buff_len);
677
678 /*
Jesse Hall2c137592012-08-29 10:37:37 -0700679 * (*getDisplayConfigs)() returns handles for the configurations available
680 * on the connected display. These handles must remain valid as long as the
681 * display is connected.
682 *
683 * Configuration handles are written to configs. The number of entries
684 * allocated by the caller is passed in *numConfigs; getDisplayConfigs must
685 * not try to write more than this number of config handles. On return, the
686 * total number of configurations available for the display is returned in
687 * *numConfigs. If *numConfigs is zero on entry, then configs may be NULL.
688 *
Dan Stozae83d10c2014-05-06 15:56:59 -0700689 * Hardware composers implementing HWC_DEVICE_API_VERSION_1_3 or prior
690 * shall choose one configuration to activate and report it as the first
691 * entry in the returned list. Reporting the inactive configurations is not
692 * required.
Jesse Hall2c137592012-08-29 10:37:37 -0700693 *
Dan Stozae83d10c2014-05-06 15:56:59 -0700694 * HWC_DEVICE_API_VERSION_1_4 and later provide configuration management
695 * through SurfaceFlinger, and hardware composers implementing these APIs
696 * must also provide getActiveConfig and setActiveConfig. Hardware composers
697 * implementing these API versions may choose not to activate any
698 * configuration, leaving configuration selection to higher levels of the
699 * framework.
700 *
701 * Returns 0 on success or a negative error code on error. If disp is a
702 * hotpluggable display type and no display is connected, an error shall be
703 * returned.
Jesse Hall2c137592012-08-29 10:37:37 -0700704 *
705 * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_1 and later.
Dan Stozae83d10c2014-05-06 15:56:59 -0700706 * It shall be NULL for previous versions.
Jesse Hall2c137592012-08-29 10:37:37 -0700707 */
708 int (*getDisplayConfigs)(struct hwc_composer_device_1* dev, int disp,
709 uint32_t* configs, size_t* numConfigs);
710
711 /*
712 * (*getDisplayAttributes)() returns attributes for a specific config of a
713 * connected display. The config parameter is one of the config handles
714 * returned by getDisplayConfigs.
715 *
716 * The list of attributes to return is provided in the attributes
717 * parameter, terminated by HWC_DISPLAY_NO_ATTRIBUTE. The value for each
718 * requested attribute is written in order to the values array. The
719 * HWC_DISPLAY_NO_ATTRIBUTE attribute does not have a value, so the values
720 * array will have one less value than the attributes array.
721 *
722 * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_1 and later.
Dan Stozae83d10c2014-05-06 15:56:59 -0700723 * It shall be NULL for previous versions.
Jesse Halld91697a2012-09-19 22:53:30 -0700724 *
725 * If disp is a hotpluggable display type and no display is connected,
726 * or if config is not a valid configuration for the display, a negative
Dan Stozae83d10c2014-05-06 15:56:59 -0700727 * error code shall be returned.
Jesse Hall2c137592012-08-29 10:37:37 -0700728 */
Jesse Halld91697a2012-09-19 22:53:30 -0700729 int (*getDisplayAttributes)(struct hwc_composer_device_1* dev, int disp,
Jesse Hall2c137592012-08-29 10:37:37 -0700730 uint32_t config, const uint32_t* attributes, int32_t* values);
731
732 /*
Dan Stozae83d10c2014-05-06 15:56:59 -0700733 * (*getActiveConfig)() returns the index of the configuration that is
734 * currently active on the connected display. The index is relative to
735 * the list of configuration handles returned by getDisplayConfigs. If there
736 * is no active configuration, -1 shall be returned.
737 *
738 * Returns the configuration index on success or -1 on error.
739 *
740 * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_4 and later.
741 * It shall be NULL for previous versions.
742 */
743 int (*getActiveConfig)(struct hwc_composer_device_1* dev, int disp);
744
745 /*
746 * (*setActiveConfig)() instructs the hardware composer to switch to the
747 * display configuration at the given index in the list of configuration
748 * handles returned by getDisplayConfigs.
749 *
750 * If this function returns without error, any subsequent calls to
751 * getActiveConfig shall return the index set by this function until one
752 * of the following occurs:
753 * 1) Another successful call of this function
754 * 2) The display is disconnected
755 *
756 * Returns 0 on success or a negative error code on error. If disp is a
757 * hotpluggable display type and no display is connected, or if index is
758 * outside of the range of hardware configurations returned by
759 * getDisplayConfigs, an error shall be returned.
760 *
761 * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_4 and later.
762 * It shall be NULL for previous versions.
763 */
764 int (*setActiveConfig)(struct hwc_composer_device_1* dev, int disp,
765 int index);
Riley Andrews4a6788b2014-06-30 15:55:55 -0700766 /*
767 * Asynchronously update the location of the cursor layer.
768 *
769 * Within the standard prepare()/set() composition loop, the client
770 * (surfaceflinger) can request that a given layer uses dedicated cursor
771 * composition hardware by specifiying the HWC_IS_CURSOR_LAYER flag. Only
772 * one layer per display can have this flag set. If the layer is suitable
773 * for the platform's cursor hardware, hwcomposer will return from prepare()
774 * a composition type of HWC_CURSOR_OVERLAY for that layer. This indicates
775 * not only that the client is not responsible for compositing that layer,
776 * but also that the client can continue to update the position of that layer
777 * after a call to set(). This can reduce the visible latency of mouse
778 * movement to visible, on-screen cursor updates. Calls to
779 * setCursorPositionAsync() may be made from a different thread doing the
780 * prepare()/set() composition loop, but care must be taken to not interleave
781 * calls of setCursorPositionAsync() between calls of set()/prepare().
782 *
783 * Notes:
784 * - Only one layer per display can be specified as a cursor layer with
785 * HWC_IS_CURSOR_LAYER.
786 * - hwcomposer will only return one layer per display as HWC_CURSOR_OVERLAY
787 * - This returns 0 on success or -errno on error.
788 * - This field is optional for HWC_DEVICE_API_VERSION_1_4 and later. It
789 * should be null for previous versions.
790 */
791 int (*setCursorPositionAsync)(struct hwc_composer_device_1 *dev, int disp, int x_pos, int y_pos);
Dan Stozae83d10c2014-05-06 15:56:59 -0700792
793 /*
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700794 * Reserved for future use. Must be NULL.
795 */
Riley Andrews4a6788b2014-06-30 15:55:55 -0700796 void* reserved_proc[1];
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800797
Jesse Halld479ad22012-06-05 23:41:37 -0700798} hwc_composer_device_1_t;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700799
800/** convenience API for opening and closing a device */
801
Jesse Halld479ad22012-06-05 23:41:37 -0700802static inline int hwc_open_1(const struct hw_module_t* module,
803 hwc_composer_device_1_t** device) {
Mathias Agopian5d3de302010-08-05 15:24:35 -0700804 return module->methods->open(module,
805 HWC_HARDWARE_COMPOSER, (struct hw_device_t**)device);
806}
807
Jesse Halld479ad22012-06-05 23:41:37 -0700808static inline int hwc_close_1(hwc_composer_device_1_t* device) {
Mathias Agopian5d3de302010-08-05 15:24:35 -0700809 return device->common.close(&device->common);
810}
811
Mathias Agopian5d3de302010-08-05 15:24:35 -0700812/*****************************************************************************/
813
Mathias Agopian5d3de302010-08-05 15:24:35 -0700814__END_DECLS
815
816#endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H */