blob: 9eb1aafbed0c0cb4dbd5c71613c0dd179b4aead9 [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
Jesse Halld479ad22012-06-05 23:41:37 -070040typedef struct hwc_layer_1 {
Mathias Agopian5d3de302010-08-05 15:24:35 -070041 /*
Mathias Agopian48697f62012-11-20 15:23:25 -080042 * compositionType is used to specify this layer's type and is set by either
43 * the hardware composer implementation, or by the caller (see below).
Jesse Halld18c83f2012-08-16 16:21:13 -070044 *
Mathias Agopian48697f62012-11-20 15:23:25 -080045 * This field is always reset to HWC_BACKGROUND or HWC_FRAMEBUFFER
46 * before (*prepare)() is called when the HWC_GEOMETRY_CHANGED flag is
47 * also set, otherwise, this field is preserved between (*prepare)()
48 * calls.
Mathias Agopianeb8fb502012-02-03 15:54:11 -080049 *
50 * HWC_BACKGROUND
Mathias Agopian48697f62012-11-20 15:23:25 -080051 * Always set by the caller before calling (*prepare)(), this value
52 * indicates this is a special "background" layer. The only valid field
53 * is backgroundColor.
54 * The HWC can toggle this value to HWC_FRAMEBUFFER to indicate it CANNOT
55 * handle the background color.
56 *
Mathias Agopianeb8fb502012-02-03 15:54:11 -080057 *
Jesse Halld18c83f2012-08-16 16:21:13 -070058 * HWC_FRAMEBUFFER_TARGET
Mathias Agopian48697f62012-11-20 15:23:25 -080059 * Always set by the caller before calling (*prepare)(), this value
60 * indicates this layer is the framebuffer surface used as the target of
Jesse Halld18c83f2012-08-16 16:21:13 -070061 * OpenGL ES composition. If the HWC sets all other layers to HWC_OVERLAY
62 * or HWC_BACKGROUND, then no OpenGL ES composition will be done, and
Jesse Hall6b01e2e2012-09-14 17:21:22 -070063 * this layer should be ignored during set().
Jesse Halld18c83f2012-08-16 16:21:13 -070064 *
65 * This flag (and the framebuffer surface layer) will only be used if the
66 * HWC version is HWC_DEVICE_API_VERSION_1_1 or higher. In older versions,
67 * the OpenGL ES target surface is communicated by the (dpy, sur) fields
68 * in hwc_compositor_device_1_t.
Mathias Agopian48697f62012-11-20 15:23:25 -080069 *
70 * This value cannot be set by the HWC implementation.
71 *
72 *
73 * HWC_FRAMEBUFFER
74 * Set by the caller before calling (*prepare)() ONLY when the
75 * HWC_GEOMETRY_CHANGED flag is also set.
76 *
77 * Set by the HWC implementation during (*prepare)(), this indicates
78 * that the layer will be drawn into the framebuffer using OpenGL ES.
79 * The HWC can toggle this value to HWC_OVERLAY to indicate it will
80 * handle the layer.
81 *
82 *
83 * HWC_OVERLAY
84 * Set by the HWC implementation during (*prepare)(), this indicates
85 * that the layer will be handled by the HWC (ie: it must not be
86 * composited with OpenGL ES).
87 *
Jesse Hall8c79c082014-02-13 15:38:56 -080088 *
89 * HWC_SIDEBAND
90 * Set by the caller before calling (*prepare)(), this value indicates
91 * the contents of this layer come from a sideband video stream.
92 *
93 * The h/w composer is responsible for receiving new image buffers from
94 * the stream at the appropriate time (e.g. synchronized to a separate
95 * audio stream), compositing them with the current contents of other
96 * layers, and displaying the resulting image. This happens
97 * independently of the normal prepare/set cycle. The prepare/set calls
98 * only happen when other layers change, or when properties of the
99 * sideband layer such as position or size change.
100 *
101 * If the h/w composer can't handle the layer as a sideband stream for
102 * some reason (e.g. unsupported scaling/blending/rotation, or too many
103 * sideband layers) it can set compositionType to HWC_FRAMEBUFFER in
104 * (*prepare)(). However, doing so will result in the layer being shown
105 * as a solid color since the platform is not currently able to composite
106 * sideband layers with the GPU. This may be improved in future
107 * versions of the platform.
Riley Andrews4a6788b2014-06-30 15:55:55 -0700108 *
109 *
110 * HWC_CURSOR_OVERLAY
111 * Set by the HWC implementation during (*prepare)(), this value
112 * indicates the layer's composition will now be handled by the HWC.
113 * Additionally, the client can now asynchronously update the on-screen
114 * position of this layer using the setCursorPositionAsync() api.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700115 */
116 int32_t compositionType;
117
Mathias Agopian48697f62012-11-20 15:23:25 -0800118 /*
119 * hints is bit mask set by the HWC implementation during (*prepare)().
120 * It is preserved between (*prepare)() calls, unless the
121 * HWC_GEOMETRY_CHANGED flag is set, in which case it is reset to 0.
122 *
123 * see hwc_layer_t::hints
124 */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700125 uint32_t hints;
126
Mathias Agopian48697f62012-11-20 15:23:25 -0800127 /* see hwc_layer_t::flags */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700128 uint32_t flags;
129
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800130 union {
131 /* color of the background. hwc_color_t.a is ignored */
132 hwc_color_t backgroundColor;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700133
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800134 struct {
Jesse Hall8c79c082014-02-13 15:38:56 -0800135 union {
136 /* When compositionType is HWC_FRAMEBUFFER, HWC_OVERLAY,
137 * HWC_FRAMEBUFFER_TARGET, this is the handle of the buffer to
138 * compose. This handle is guaranteed to have been allocated
139 * from gralloc using the GRALLOC_USAGE_HW_COMPOSER usage flag.
140 * If the layer's handle is unchanged across two consecutive
141 * prepare calls and the HWC_GEOMETRY_CHANGED flag is not set
142 * for the second call then the HWComposer implementation may
143 * assume that the contents of the buffer have not changed. */
144 buffer_handle_t handle;
145
146 /* When compositionType is HWC_SIDEBAND, this is the handle
147 * of the sideband video stream to compose. */
148 const native_handle_t* sidebandStream;
149 };
Mathias Agopian5d3de302010-08-05 15:24:35 -0700150
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800151 /* transformation to apply to the buffer during composition */
152 uint32_t transform;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700153
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800154 /* blending to apply during composition */
155 int32_t blending;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700156
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800157 /* area of the source to consider, the origin is the top-left corner of
Mathias Agopian3b4732c2013-07-09 19:55:41 -0700158 * the buffer. As of HWC_DEVICE_API_VERSION_1_3, sourceRect uses floats.
159 * If the h/w can't support a non-integer source crop rectangle, it should
160 * punt to OpenGL ES composition.
161 */
162 union {
163 // crop rectangle in integer (pre HWC_DEVICE_API_VERSION_1_3)
164 hwc_rect_t sourceCropi;
165 hwc_rect_t sourceCrop; // just for source compatibility
166 // crop rectangle in floats (as of HWC_DEVICE_API_VERSION_1_3)
167 hwc_frect_t sourceCropf;
168 };
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800169
170 /* where to composite the sourceCrop onto the display. The sourceCrop
171 * is scaled using linear filtering to the displayFrame. The origin is the
172 * top-left corner of the screen.
173 */
174 hwc_rect_t displayFrame;
175
176 /* visible region in screen space. The origin is the
177 * top-left corner of the screen.
178 * The visible region INCLUDES areas overlapped by a translucent layer.
179 */
180 hwc_region_t visibleRegionScreen;
Jesse Halld479ad22012-06-05 23:41:37 -0700181
182 /* Sync fence object that will be signaled when the buffer's
183 * contents are available. May be -1 if the contents are already
184 * available. This field is only valid during set(), and should be
185 * ignored during prepare(). The set() call must not wait for the
186 * fence to be signaled before returning, but the HWC must wait for
187 * all buffers to be signaled before reading from them.
188 *
Jesse Hall0a0a4162012-08-21 12:06:28 -0700189 * HWC_FRAMEBUFFER layers will never have an acquire fence, since
190 * reads from them are complete before the framebuffer is ready for
191 * display.
192 *
Jesse Hall8c79c082014-02-13 15:38:56 -0800193 * HWC_SIDEBAND layers will never have an acquire fence, since
194 * synchronization is handled through implementation-defined
195 * sideband mechanisms.
196 *
Jesse Halld479ad22012-06-05 23:41:37 -0700197 * The HWC takes ownership of the acquireFenceFd and is responsible
198 * for closing it when no longer needed.
199 */
200 int acquireFenceFd;
201
202 /* During set() the HWC must set this field to a file descriptor for
203 * a sync fence object that will signal after the HWC has finished
204 * reading from the buffer. The field is ignored by prepare(). Each
205 * layer should have a unique file descriptor, even if more than one
206 * refer to the same underlying fence object; this allows each to be
207 * closed independently.
208 *
209 * If buffer reads can complete at significantly different times,
210 * then using independent fences is preferred. For example, if the
211 * HWC handles some layers with a blit engine and others with
212 * overlays, then the blit layers can be reused immediately after
213 * the blit completes, but the overlay layers can't be reused until
214 * a subsequent frame has been displayed.
215 *
Jesse Hall0a0a4162012-08-21 12:06:28 -0700216 * Since HWC doesn't read from HWC_FRAMEBUFFER layers, it shouldn't
217 * produce a release fence for them. The releaseFenceFd will be -1
218 * for these layers when set() is called.
219 *
Jesse Hall8c79c082014-02-13 15:38:56 -0800220 * Since HWC_SIDEBAND buffers don't pass through the HWC client,
221 * the HWC shouldn't produce a release fence for them. The
222 * releaseFenceFd will be -1 for these layers when set() is called.
223 *
Jesse Halld479ad22012-06-05 23:41:37 -0700224 * The HWC client taks ownership of the releaseFenceFd and is
225 * responsible for closing it when no longer needed.
226 */
227 int releaseFenceFd;
Mathias Agopiane3e0a572013-01-29 18:57:48 -0800228
229 /*
230 * Availability: HWC_DEVICE_API_VERSION_1_2
231 *
232 * Alpha value applied to the whole layer. The effective
233 * value of each pixel is computed as:
234 *
235 * if (blending == HWC_BLENDING_PREMULT)
236 * pixel.rgb = pixel.rgb * planeAlpha / 255
237 * pixel.a = pixel.a * planeAlpha / 255
238 *
239 * Then blending proceeds as usual according to the "blending"
240 * field above.
241 *
242 * NOTE: planeAlpha applies to YUV layers as well:
243 *
244 * pixel.rgb = yuv_to_rgb(pixel.yuv)
245 * if (blending == HWC_BLENDING_PREMULT)
246 * pixel.rgb = pixel.rgb * planeAlpha / 255
247 * pixel.a = planeAlpha
248 *
249 *
250 * IMPLEMENTATION NOTE:
251 *
252 * If the source image doesn't have an alpha channel, then
253 * the h/w can use the HWC_BLENDING_COVERAGE equations instead of
254 * HWC_BLENDING_PREMULT and simply set the alpha channel to
255 * planeAlpha.
256 *
257 * e.g.:
258 *
259 * if (blending == HWC_BLENDING_PREMULT)
260 * blending = HWC_BLENDING_COVERAGE;
261 * pixel.a = planeAlpha;
262 *
263 */
264 uint8_t planeAlpha;
265
Dan Stoza811445a2015-02-12 10:11:21 -0800266 /* Pad to 32 bits */
Mathias Agopiane3e0a572013-01-29 18:57:48 -0800267 uint8_t _pad[3];
Dan Stoza811445a2015-02-12 10:11:21 -0800268
269 /*
270 * Availability: HWC_DEVICE_API_VERSION_1_5
271 *
272 * This defines the region of the source buffer that has been
273 * modified since the last frame.
274 *
275 * If surfaceDamage.numRects > 0, then it may be assumed that any
276 * portion of the source buffer not covered by one of the rects has
277 * not been modified this frame. If surfaceDamage.numRects == 0,
278 * then the whole source buffer must be treated as if it had been
279 * modified.
280 *
281 * If the layer's contents are not modified relative to the prior
282 * prepare/set cycle, surfaceDamage will contain exactly one empty
283 * rect ([0, 0, 0, 0]).
284 *
285 * The damage rects are relative to the pre-transformed buffer, and
286 * their origin is the top-left corner.
287 */
288 hwc_region_t surfaceDamage;
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800289 };
290 };
Mathias Agopian5d3de302010-08-05 15:24:35 -0700291
Dan Stoza91699a82014-06-04 15:21:22 -0700292#ifdef __LP64__
293 /*
294 * For 64-bit mode, this struct is 120 bytes (and 8-byte aligned), and needs
295 * to be padded as such to maintain binary compatibility.
Jesse Halld479ad22012-06-05 23:41:37 -0700296 */
Dan Stoza811445a2015-02-12 10:11:21 -0800297 uint8_t reserved[120 - 112];
Dan Stoza91699a82014-06-04 15:21:22 -0700298#else
299 /*
300 * For 32-bit mode, this struct is 96 bytes, and needs to be padded as such
301 * to maintain binary compatibility.
302 */
Dan Stoza811445a2015-02-12 10:11:21 -0800303 uint8_t reserved[96 - 84];
Dan Stoza91699a82014-06-04 15:21:22 -0700304#endif
Jesse Halld479ad22012-06-05 23:41:37 -0700305
306} hwc_layer_1_t;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700307
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700308/* This represents a display, typically an EGLDisplay object */
309typedef void* hwc_display_t;
310
311/* This represents a surface, typically an EGLSurface object */
312typedef void* hwc_surface_t;
313
Mathias Agopian5d3de302010-08-05 15:24:35 -0700314/*
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700315 * hwc_display_contents_1_t::flags values
Mathias Agopian5d3de302010-08-05 15:24:35 -0700316 */
317enum {
318 /*
319 * HWC_GEOMETRY_CHANGED is set by SurfaceFlinger to indicate that the list
Jesse Halld479ad22012-06-05 23:41:37 -0700320 * passed to (*prepare)() has changed by more than just the buffer handles
321 * and acquire fences.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700322 */
323 HWC_GEOMETRY_CHANGED = 0x00000001,
324};
325
Louis Huemiller871815b2010-10-25 17:00:52 -0700326/*
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700327 * Description of the contents to output on a display.
328 *
329 * This is the top-level structure passed to the prepare and set calls to
330 * negotiate and commit the composition of a display image.
Louis Huemiller871815b2010-10-25 17:00:52 -0700331 */
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700332typedef struct hwc_display_contents_1 {
333 /* File descriptor referring to a Sync HAL fence object which will signal
Jesse Hall7cb03d72012-09-06 16:57:12 -0700334 * when this composition is retired. For a physical display, a composition
335 * is retired when it has been replaced on-screen by a subsequent set. For
336 * a virtual display, the composition is retired when the writes to
337 * outputBuffer are complete and can be read. The fence object is created
338 * and returned by the set call; this field will be -1 on entry to prepare
339 * and set. SurfaceFlinger will close the returned file descriptor.
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700340 */
Jesse Hall7cb03d72012-09-06 16:57:12 -0700341 int retireFenceFd;
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700342
Jesse Hall7cb03d72012-09-06 16:57:12 -0700343 union {
344 /* Fields only relevant for HWC_DEVICE_VERSION_1_0. */
345 struct {
346 /* (dpy, sur) is the target of SurfaceFlinger's OpenGL ES
347 * composition for HWC_DEVICE_VERSION_1_0. They aren't relevant to
348 * prepare. The set call should commit this surface atomically to
349 * the display along with any overlay layers.
350 */
351 hwc_display_t dpy;
352 hwc_surface_t sur;
353 };
354
Jesse Hall7ccf1482013-11-13 14:48:15 -0800355 /* These fields are used for virtual displays when the h/w composer
356 * version is at least HWC_DEVICE_VERSION_1_3. */
Jesse Hall7cb03d72012-09-06 16:57:12 -0700357 struct {
358 /* outbuf is the buffer that receives the composed image for
359 * virtual displays. Writes to the outbuf must wait until
360 * outbufAcquireFenceFd signals. A fence that will signal when
361 * writes to outbuf are complete should be returned in
362 * retireFenceFd.
363 *
Jesse Hall7ccf1482013-11-13 14:48:15 -0800364 * This field is set before prepare(), so properties of the buffer
365 * can be used to decide which layers can be handled by h/w
366 * composer.
Jesse Hall380f45d2013-03-20 10:11:10 -0700367 *
Jesse Hall7ccf1482013-11-13 14:48:15 -0800368 * If prepare() sets all layers to FRAMEBUFFER, then GLES
369 * composition will happen directly to the output buffer. In this
370 * case, both outbuf and the FRAMEBUFFER_TARGET layer's buffer will
371 * be the same, and set() has no work to do besides managing fences.
372 *
373 * If the TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS board config
374 * variable is defined (not the default), then this behavior is
375 * changed: if all layers are marked for FRAMEBUFFER, GLES
376 * composition will take place to a scratch framebuffer, and
377 * h/w composer must copy it to the output buffer. This allows the
378 * h/w composer to do format conversion if there are cases where
379 * that is more desirable than doing it in the GLES driver or at the
380 * virtual display consumer.
381 *
382 * If some or all layers are marked OVERLAY, then the framebuffer
383 * and output buffer will be different. As with physical displays,
384 * the framebuffer handle will not change between frames if all
385 * layers are marked for OVERLAY.
Jesse Hall7cb03d72012-09-06 16:57:12 -0700386 */
387 buffer_handle_t outbuf;
388
389 /* File descriptor for a fence that will signal when outbuf is
390 * ready to be written. The h/w composer is responsible for closing
391 * this when no longer needed.
392 *
393 * Will be -1 whenever outbuf is NULL, or when the outbuf can be
394 * written immediately.
395 */
396 int outbufAcquireFenceFd;
397 };
398 };
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700399
400 /* List of layers that will be composed on the display. The buffer handles
Jesse Hallac3f7e12012-07-31 15:18:32 -0700401 * in the list will be unique. If numHwLayers is 0, all composition will be
402 * performed by SurfaceFlinger.
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700403 */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700404 uint32_t flags;
405 size_t numHwLayers;
Jesse Halld479ad22012-06-05 23:41:37 -0700406 hwc_layer_1_t hwLayers[0];
Mathias Agopian5d3de302010-08-05 15:24:35 -0700407
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700408} hwc_display_contents_1_t;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700409
Mathias Agopiand6afef62011-08-01 16:34:42 -0700410/* see hwc_composer_device::registerProcs()
Jesse Hall0a0a4162012-08-21 12:06:28 -0700411 * All of the callbacks are required and non-NULL unless otherwise noted.
Mathias Agopiand6afef62011-08-01 16:34:42 -0700412 */
413typedef struct hwc_procs {
414 /*
415 * (*invalidate)() triggers a screen refresh, in particular prepare and set
416 * will be called shortly after this call is made. Note that there is
417 * NO GUARANTEE that the screen refresh will happen after invalidate()
418 * returns (in particular, it could happen before).
419 * invalidate() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL and
420 * it is safe to call invalidate() from any of hwc_composer_device
421 * hooks, unless noted otherwise.
422 */
Jesse Hall0a0a4162012-08-21 12:06:28 -0700423 void (*invalidate)(const struct hwc_procs* procs);
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700424
425 /*
426 * (*vsync)() is called by the h/w composer HAL when a vsync event is
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700427 * received and HWC_EVENT_VSYNC is enabled on a display
428 * (see: hwc_event_control).
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700429 *
Jesse Hall2c137592012-08-29 10:37:37 -0700430 * the "disp" parameter indicates which display the vsync event is for.
Jamie Gennis6b7adef2012-04-30 12:57:11 -0700431 * the "timestamp" parameter is the system monotonic clock timestamp in
432 * nanosecond of when the vsync event happened.
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700433 *
434 * vsync() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL.
435 *
436 * It is expected that vsync() is called from a thread of at least
Mathias Agopianeb671602012-04-24 15:42:37 -0700437 * HAL_PRIORITY_URGENT_DISPLAY with as little latency as possible,
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700438 * typically less than 0.5 ms.
439 *
Mathias Agopian6d3fec72012-04-10 21:22:28 -0700440 * It is a (silent) error to have HWC_EVENT_VSYNC enabled when calling
441 * hwc_composer_device.set(..., 0, 0, 0) (screen off). The implementation
442 * can either stop or continue to process VSYNC events, but must not
443 * crash or cause other problems.
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700444 */
Jesse Hall2c137592012-08-29 10:37:37 -0700445 void (*vsync)(const struct hwc_procs* procs, int disp, int64_t timestamp);
446
447 /*
448 * (*hotplug)() is called by the h/w composer HAL when a display is
449 * connected or disconnected. The PRIMARY display is always connected and
450 * the hotplug callback should not be called for it.
451 *
452 * The disp parameter indicates which display type this event is for.
453 * The connected parameter indicates whether the display has just been
454 * connected (1) or disconnected (0).
455 *
456 * The hotplug() callback may call back into the h/w composer on the same
457 * thread to query refresh rate and dpi for the display. Additionally,
458 * other threads may be calling into the h/w composer while the callback
459 * is in progress.
460 *
Jesse Halld91697a2012-09-19 22:53:30 -0700461 * The h/w composer must serialize calls to the hotplug callback; only
462 * one thread may call it at a time.
463 *
Jesse Hall2c137592012-08-29 10:37:37 -0700464 * This callback will be NULL if the h/w composer is using
465 * HWC_DEVICE_API_VERSION_1_0.
466 */
467 void (*hotplug)(const struct hwc_procs* procs, int disp, int connected);
468
Mathias Agopiand6afef62011-08-01 16:34:42 -0700469} hwc_procs_t;
470
471
472/*****************************************************************************/
Mathias Agopian5d3de302010-08-05 15:24:35 -0700473
474typedef struct hwc_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700475 /**
476 * Common methods of the hardware composer module. This *must* be the first member of
477 * hwc_module as users of this structure will cast a hw_module_t to
478 * hwc_module pointer in contexts where it's known the hw_module_t references a
479 * hwc_module.
480 */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700481 struct hw_module_t common;
482} hwc_module_t;
483
Fabien Sanglardf5068a82016-11-16 11:14:59 -0800484#define HWC_ERROR (-1)
Jesse Halld479ad22012-06-05 23:41:37 -0700485typedef struct hwc_composer_device_1 {
Stewart Miles84d35492014-05-01 09:03:27 -0700486 /**
487 * Common methods of the hardware composer device. This *must* be the first member of
488 * hwc_composer_device_1 as users of this structure will cast a hw_device_t to
489 * hwc_composer_device_1 pointer in contexts where it's known the hw_device_t references a
490 * hwc_composer_device_1.
491 */
Mathias Agopian5d3de302010-08-05 15:24:35 -0700492 struct hw_device_t common;
493
494 /*
495 * (*prepare)() is called for each frame before composition and is used by
496 * SurfaceFlinger to determine what composition steps the HWC can handle.
497 *
498 * (*prepare)() can be called more than once, the last call prevails.
499 *
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700500 * The HWC responds by setting the compositionType field in each layer to
Riley Andrews4a6788b2014-06-30 15:55:55 -0700501 * either HWC_FRAMEBUFFER, HWC_OVERLAY, or HWC_CURSOR_OVERLAY. For the
502 * HWC_FRAMEBUFFER type, composition for the layer is handled by
503 * SurfaceFlinger with OpenGL ES. For the latter two overlay types,
504 * the HWC will have to handle the layer's composition. compositionType
505 * and hints are preserved between (*prepare)() calles unless the
506 * HWC_GEOMETRY_CHANGED flag is set.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700507 *
508 * (*prepare)() is called with HWC_GEOMETRY_CHANGED to indicate that the
509 * list's geometry has changed, that is, when more than just the buffer's
510 * handles have been updated. Typically this happens (but is not limited to)
Mathias Agopian48697f62012-11-20 15:23:25 -0800511 * when a window is added, removed, resized or moved. In this case
512 * compositionType and hints are reset to their default value.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700513 *
Jesse Hall43b51d92012-08-22 11:42:57 -0700514 * For HWC 1.0, numDisplays will always be one, and displays[0] will be
515 * non-NULL.
516 *
Jesse Hallfc0ff2a2013-08-16 11:13:36 -0700517 * For HWC 1.1, numDisplays will always be HWC_NUM_PHYSICAL_DISPLAY_TYPES.
518 * Entries for unsupported or disabled/disconnected display types will be
519 * NULL.
Jesse Hall43b51d92012-08-22 11:42:57 -0700520 *
Jesse Hallfc0ff2a2013-08-16 11:13:36 -0700521 * In HWC 1.3, numDisplays may be up to HWC_NUM_DISPLAY_TYPES. The extra
522 * entries correspond to enabled virtual displays, and will be non-NULL.
Jesse Hallac3f7e12012-07-31 15:18:32 -0700523 *
Mathias Agopian5d3de302010-08-05 15:24:35 -0700524 * returns: 0 on success. An negative error code on error. If an error is
525 * returned, SurfaceFlinger will assume that none of the layer will be
526 * handled by the HWC.
527 */
Jesse Halld479ad22012-06-05 23:41:37 -0700528 int (*prepare)(struct hwc_composer_device_1 *dev,
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700529 size_t numDisplays, hwc_display_contents_1_t** displays);
Mathias Agopian5d3de302010-08-05 15:24:35 -0700530
531 /*
532 * (*set)() is used in place of eglSwapBuffers(), and assumes the same
533 * functionality, except it also commits the work list atomically with
534 * the actual eglSwapBuffers().
535 *
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700536 * The layer lists are guaranteed to be the same as the ones returned from
537 * the last call to (*prepare)().
Mathias Agopian5d3de302010-08-05 15:24:35 -0700538 *
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700539 * When this call returns the caller assumes that the displays will be
540 * updated in the near future with the content of their work lists, without
541 * artifacts during the transition from the previous frame.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700542 *
Jesse Hallac3f7e12012-07-31 15:18:32 -0700543 * A display with zero layers indicates that the entire composition has
544 * been handled by SurfaceFlinger with OpenGL ES. In this case, (*set)()
545 * behaves just like eglSwapBuffers().
Mathias Agopian5d3de302010-08-05 15:24:35 -0700546 *
Jesse Hall43b51d92012-08-22 11:42:57 -0700547 * For HWC 1.0, numDisplays will always be one, and displays[0] will be
548 * non-NULL.
549 *
Jesse Hallfc0ff2a2013-08-16 11:13:36 -0700550 * For HWC 1.1, numDisplays will always be HWC_NUM_PHYSICAL_DISPLAY_TYPES.
551 * Entries for unsupported or disabled/disconnected display types will be
552 * NULL.
Jesse Hall43b51d92012-08-22 11:42:57 -0700553 *
Jesse Hallfc0ff2a2013-08-16 11:13:36 -0700554 * In HWC 1.3, numDisplays may be up to HWC_NUM_DISPLAY_TYPES. The extra
555 * entries correspond to enabled virtual displays, and will be non-NULL.
Mathias Agopian71212e32011-11-21 17:35:15 -0800556 *
Jamie Gennisc7545182012-10-08 19:23:56 -0700557 * IMPORTANT NOTE: There is an implicit layer containing opaque black
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700558 * pixels behind all the layers in the list. It is the responsibility of
559 * the hwcomposer module to make sure black pixels are output (or blended
560 * from).
Mathias Agopianfb410362011-11-15 21:27:52 -0800561 *
Jamie Gennisc7545182012-10-08 19:23:56 -0700562 * IMPORTANT NOTE: In the event of an error this call *MUST* still cause
563 * any fences returned in the previous call to set to eventually become
564 * signaled. The caller may have already issued wait commands on these
565 * fences, and having set return without causing those fences to signal
566 * will likely result in a deadlock.
567 *
568 * returns: 0 on success. A negative error code on error:
569 * HWC_EGL_ERROR: eglGetError() will provide the proper error code (only
570 * allowed prior to HWComposer 1.1)
Mathias Agopian5d3de302010-08-05 15:24:35 -0700571 * Another code for non EGL errors.
Mathias Agopian5d3de302010-08-05 15:24:35 -0700572 */
Jesse Halld479ad22012-06-05 23:41:37 -0700573 int (*set)(struct hwc_composer_device_1 *dev,
Jesse Hallf9d6cd72012-07-31 14:29:00 -0700574 size_t numDisplays, hwc_display_contents_1_t** displays);
Jesse Halld479ad22012-06-05 23:41:37 -0700575
Erik Gilling158549c2010-12-01 16:34:08 -0800576 /*
Jesse Hall0a0a4162012-08-21 12:06:28 -0700577 * eventControl(..., event, enabled)
578 * Enables or disables h/w composer events for a display.
Erik Gilling158549c2010-12-01 16:34:08 -0800579 *
Jesse Hall0a0a4162012-08-21 12:06:28 -0700580 * eventControl can be called from any thread and takes effect
581 * immediately.
582 *
583 * Supported events are:
584 * HWC_EVENT_VSYNC
585 *
586 * returns -EINVAL if the "event" parameter is not one of the value above
587 * or if the "enabled" parameter is not 0 or 1.
Erik Gilling158549c2010-12-01 16:34:08 -0800588 */
Jesse Hall2c137592012-08-29 10:37:37 -0700589 int (*eventControl)(struct hwc_composer_device_1* dev, int disp,
Jesse Hall0a0a4162012-08-21 12:06:28 -0700590 int event, int enabled);
Mathias Agopian5d3de302010-08-05 15:24:35 -0700591
Prashant Malani02b31982014-05-25 20:41:20 -0700592 union {
593 /*
594 * For HWC 1.3 and earlier, the blank() interface is used.
595 *
596 * blank(..., blank)
597 * Blanks or unblanks a display's screen.
598 *
599 * Turns the screen off when blank is nonzero, on when blank is zero.
600 * Multiple sequential calls with the same blank value must be
601 * supported.
602 * The screen state transition must be be complete when the function
603 * returns.
604 *
605 * returns 0 on success, negative on error.
606 */
607 int (*blank)(struct hwc_composer_device_1* dev, int disp, int blank);
608
609 /*
610 * For HWC 1.4 and above, setPowerMode() will be used in place of
611 * blank().
612 *
613 * setPowerMode(..., mode)
614 * Sets the display screen's power state.
615 *
Jeff Brown842b9062014-07-17 20:01:59 -0700616 * Refer to the documentation of the HWC_POWER_MODE_* constants
617 * for information about each power mode.
Prashant Malani02b31982014-05-25 20:41:20 -0700618 *
619 * The functionality is similar to the blank() command in previous
620 * versions of HWC, but with support for more power states.
621 *
622 * The display driver is expected to retain and restore the low power
623 * state of the display while entering and exiting from suspend.
624 *
625 * Multiple sequential calls with the same mode value must be supported.
626 *
627 * The screen state transition must be be complete when the function
628 * returns.
629 *
630 * returns 0 on success, negative on error.
631 */
632 int (*setPowerMode)(struct hwc_composer_device_1* dev, int disp,
633 int mode);
634 };
Mathias Agopiand6afef62011-08-01 16:34:42 -0700635
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800636 /*
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800637 * Used to retrieve information about the h/w composer
638 *
639 * Returns 0 on success or -errno on error.
640 */
Jesse Halld479ad22012-06-05 23:41:37 -0700641 int (*query)(struct hwc_composer_device_1* dev, int what, int* value);
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800642
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700643 /*
Jesse Hall0a0a4162012-08-21 12:06:28 -0700644 * (*registerProcs)() registers callbacks that the h/w composer HAL can
645 * later use. It will be called immediately after the composer device is
646 * opened with non-NULL procs. It is FORBIDDEN to call any of the callbacks
647 * from within registerProcs(). registerProcs() must save the hwc_procs_t
648 * pointer which is needed when calling a registered callback.
649 */
650 void (*registerProcs)(struct hwc_composer_device_1* dev,
651 hwc_procs_t const* procs);
652
653 /*
654 * This field is OPTIONAL and can be NULL.
655 *
656 * If non NULL it will be called by SurfaceFlinger on dumpsys
657 */
658 void (*dump)(struct hwc_composer_device_1* dev, char *buff, int buff_len);
659
660 /*
Jesse Hall2c137592012-08-29 10:37:37 -0700661 * (*getDisplayConfigs)() returns handles for the configurations available
662 * on the connected display. These handles must remain valid as long as the
663 * display is connected.
664 *
665 * Configuration handles are written to configs. The number of entries
666 * allocated by the caller is passed in *numConfigs; getDisplayConfigs must
667 * not try to write more than this number of config handles. On return, the
668 * total number of configurations available for the display is returned in
669 * *numConfigs. If *numConfigs is zero on entry, then configs may be NULL.
670 *
Dan Stozae83d10c2014-05-06 15:56:59 -0700671 * Hardware composers implementing HWC_DEVICE_API_VERSION_1_3 or prior
672 * shall choose one configuration to activate and report it as the first
673 * entry in the returned list. Reporting the inactive configurations is not
674 * required.
Jesse Hall2c137592012-08-29 10:37:37 -0700675 *
Dan Stozae83d10c2014-05-06 15:56:59 -0700676 * HWC_DEVICE_API_VERSION_1_4 and later provide configuration management
677 * through SurfaceFlinger, and hardware composers implementing these APIs
678 * must also provide getActiveConfig and setActiveConfig. Hardware composers
679 * implementing these API versions may choose not to activate any
680 * configuration, leaving configuration selection to higher levels of the
681 * framework.
682 *
683 * Returns 0 on success or a negative error code on error. If disp is a
684 * hotpluggable display type and no display is connected, an error shall be
685 * returned.
Jesse Hall2c137592012-08-29 10:37:37 -0700686 *
687 * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_1 and later.
Dan Stozae83d10c2014-05-06 15:56:59 -0700688 * It shall be NULL for previous versions.
Jesse Hall2c137592012-08-29 10:37:37 -0700689 */
690 int (*getDisplayConfigs)(struct hwc_composer_device_1* dev, int disp,
691 uint32_t* configs, size_t* numConfigs);
692
693 /*
694 * (*getDisplayAttributes)() returns attributes for a specific config of a
695 * connected display. The config parameter is one of the config handles
696 * returned by getDisplayConfigs.
697 *
698 * The list of attributes to return is provided in the attributes
699 * parameter, terminated by HWC_DISPLAY_NO_ATTRIBUTE. The value for each
700 * requested attribute is written in order to the values array. The
701 * HWC_DISPLAY_NO_ATTRIBUTE attribute does not have a value, so the values
702 * array will have one less value than the attributes array.
703 *
704 * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_1 and later.
Dan Stozae83d10c2014-05-06 15:56:59 -0700705 * It shall be NULL for previous versions.
Jesse Halld91697a2012-09-19 22:53:30 -0700706 *
707 * If disp is a hotpluggable display type and no display is connected,
708 * or if config is not a valid configuration for the display, a negative
Dan Stozae83d10c2014-05-06 15:56:59 -0700709 * error code shall be returned.
Jesse Hall2c137592012-08-29 10:37:37 -0700710 */
Jesse Halld91697a2012-09-19 22:53:30 -0700711 int (*getDisplayAttributes)(struct hwc_composer_device_1* dev, int disp,
Jesse Hall2c137592012-08-29 10:37:37 -0700712 uint32_t config, const uint32_t* attributes, int32_t* values);
713
714 /*
Dan Stozae83d10c2014-05-06 15:56:59 -0700715 * (*getActiveConfig)() returns the index of the configuration that is
716 * currently active on the connected display. The index is relative to
717 * the list of configuration handles returned by getDisplayConfigs. If there
Fabien Sanglardf5068a82016-11-16 11:14:59 -0800718 * is no active configuration, HWC_ERROR shall be returned.
Dan Stozae83d10c2014-05-06 15:56:59 -0700719 *
Fabien Sanglardf5068a82016-11-16 11:14:59 -0800720 * Returns the configuration index on success or HWC_ERROR on error.
Dan Stozae83d10c2014-05-06 15:56:59 -0700721 *
722 * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_4 and later.
723 * It shall be NULL for previous versions.
724 */
725 int (*getActiveConfig)(struct hwc_composer_device_1* dev, int disp);
726
727 /*
728 * (*setActiveConfig)() instructs the hardware composer to switch to the
729 * display configuration at the given index in the list of configuration
730 * handles returned by getDisplayConfigs.
731 *
732 * If this function returns without error, any subsequent calls to
733 * getActiveConfig shall return the index set by this function until one
734 * of the following occurs:
735 * 1) Another successful call of this function
736 * 2) The display is disconnected
737 *
738 * Returns 0 on success or a negative error code on error. If disp is a
739 * hotpluggable display type and no display is connected, or if index is
740 * outside of the range of hardware configurations returned by
741 * getDisplayConfigs, an error shall be returned.
742 *
743 * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_4 and later.
744 * It shall be NULL for previous versions.
745 */
746 int (*setActiveConfig)(struct hwc_composer_device_1* dev, int disp,
747 int index);
Riley Andrews4a6788b2014-06-30 15:55:55 -0700748 /*
749 * Asynchronously update the location of the cursor layer.
750 *
751 * Within the standard prepare()/set() composition loop, the client
752 * (surfaceflinger) can request that a given layer uses dedicated cursor
753 * composition hardware by specifiying the HWC_IS_CURSOR_LAYER flag. Only
754 * one layer per display can have this flag set. If the layer is suitable
755 * for the platform's cursor hardware, hwcomposer will return from prepare()
756 * a composition type of HWC_CURSOR_OVERLAY for that layer. This indicates
757 * not only that the client is not responsible for compositing that layer,
758 * but also that the client can continue to update the position of that layer
759 * after a call to set(). This can reduce the visible latency of mouse
760 * movement to visible, on-screen cursor updates. Calls to
761 * setCursorPositionAsync() may be made from a different thread doing the
762 * prepare()/set() composition loop, but care must be taken to not interleave
763 * calls of setCursorPositionAsync() between calls of set()/prepare().
764 *
765 * Notes:
766 * - Only one layer per display can be specified as a cursor layer with
767 * HWC_IS_CURSOR_LAYER.
768 * - hwcomposer will only return one layer per display as HWC_CURSOR_OVERLAY
769 * - This returns 0 on success or -errno on error.
770 * - This field is optional for HWC_DEVICE_API_VERSION_1_4 and later. It
771 * should be null for previous versions.
772 */
773 int (*setCursorPositionAsync)(struct hwc_composer_device_1 *dev, int disp, int x_pos, int y_pos);
Dan Stozae83d10c2014-05-06 15:56:59 -0700774
775 /*
Mathias Agopianb08d45d2012-03-24 15:56:29 -0700776 * Reserved for future use. Must be NULL.
777 */
Riley Andrews4a6788b2014-06-30 15:55:55 -0700778 void* reserved_proc[1];
Mathias Agopianeb8fb502012-02-03 15:54:11 -0800779
Jesse Halld479ad22012-06-05 23:41:37 -0700780} hwc_composer_device_1_t;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700781
782/** convenience API for opening and closing a device */
783
Jesse Halld479ad22012-06-05 23:41:37 -0700784static inline int hwc_open_1(const struct hw_module_t* module,
785 hwc_composer_device_1_t** device) {
Mathias Agopian5d3de302010-08-05 15:24:35 -0700786 return module->methods->open(module,
Colin Crosscc8d9f92016-10-06 16:44:23 -0700787 HWC_HARDWARE_COMPOSER, TO_HW_DEVICE_T_OPEN(device));
Mathias Agopian5d3de302010-08-05 15:24:35 -0700788}
789
Jesse Halld479ad22012-06-05 23:41:37 -0700790static inline int hwc_close_1(hwc_composer_device_1_t* device) {
Mathias Agopian5d3de302010-08-05 15:24:35 -0700791 return device->common.close(&device->common);
792}
793
Mathias Agopian5d3de302010-08-05 15:24:35 -0700794/*****************************************************************************/
795
Mathias Agopian5d3de302010-08-05 15:24:35 -0700796__END_DECLS
797
798#endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H */