• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // clang-format off
2 /*
3  * Copyright (C) 2010 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H
19 #define ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H
20 
21 #include <stdint.h>
22 #include <sys/cdefs.h>
23 
24 #include <hardware/gralloc.h>
25 #include <hardware/hardware.h>
26 #include <cutils/native_handle.h>
27 
28 #include <hardware/hwcomposer_defs.h>
29 
30 __BEGIN_DECLS
31 
32 /*****************************************************************************/
33 
34 /* for compatibility */
35 #define HWC_MODULE_API_VERSION      HWC_MODULE_API_VERSION_0_1
36 #define HWC_DEVICE_API_VERSION      HWC_DEVICE_API_VERSION_0_1
37 #define HWC_API_VERSION             HWC_DEVICE_API_VERSION
38 
39 /*****************************************************************************/
40 
41 typedef struct hwc_layer_1 {
42     /*
43      * compositionType is used to specify this layer's type and is set by either
44      * the hardware composer implementation, or by the caller (see below).
45      *
46      *  This field is always reset to HWC_BACKGROUND or HWC_FRAMEBUFFER
47      *  before (*prepare)() is called when the HWC_GEOMETRY_CHANGED flag is
48      *  also set, otherwise, this field is preserved between (*prepare)()
49      *  calls.
50      *
51      * HWC_BACKGROUND
52      *   Always set by the caller before calling (*prepare)(), this value
53      *   indicates this is a special "background" layer. The only valid field
54      *   is backgroundColor.
55      *   The HWC can toggle this value to HWC_FRAMEBUFFER to indicate it CANNOT
56      *   handle the background color.
57      *
58      *
59      * HWC_FRAMEBUFFER_TARGET
60      *   Always set by the caller before calling (*prepare)(), this value
61      *   indicates this layer is the framebuffer surface used as the target of
62      *   OpenGL ES composition. If the HWC sets all other layers to HWC_OVERLAY
63      *   or HWC_BACKGROUND, then no OpenGL ES composition will be done, and
64      *   this layer should be ignored during set().
65      *
66      *   This flag (and the framebuffer surface layer) will only be used if the
67      *   HWC version is HWC_DEVICE_API_VERSION_1_1 or higher. In older versions,
68      *   the OpenGL ES target surface is communicated by the (dpy, sur) fields
69      *   in hwc_compositor_device_1_t.
70      *
71      *   This value cannot be set by the HWC implementation.
72      *
73      *
74      * HWC_FRAMEBUFFER
75      *   Set by the caller before calling (*prepare)() ONLY when the
76      *   HWC_GEOMETRY_CHANGED flag is also set.
77      *
78      *   Set by the HWC implementation during (*prepare)(), this indicates
79      *   that the layer will be drawn into the framebuffer using OpenGL ES.
80      *   The HWC can toggle this value to HWC_OVERLAY to indicate it will
81      *   handle the layer.
82      *
83      *
84      * HWC_OVERLAY
85      *   Set by the HWC implementation during (*prepare)(), this indicates
86      *   that the layer will be handled by the HWC (ie: it must not be
87      *   composited with OpenGL ES).
88      *
89      *
90      * HWC_SIDEBAND
91      *   Set by the caller before calling (*prepare)(), this value indicates
92      *   the contents of this layer come from a sideband video stream.
93      *
94      *   The h/w composer is responsible for receiving new image buffers from
95      *   the stream at the appropriate time (e.g. synchronized to a separate
96      *   audio stream), compositing them with the current contents of other
97      *   layers, and displaying the resulting image. This happens
98      *   independently of the normal prepare/set cycle. The prepare/set calls
99      *   only happen when other layers change, or when properties of the
100      *   sideband layer such as position or size change.
101      *
102      *   If the h/w composer can't handle the layer as a sideband stream for
103      *   some reason (e.g. unsupported scaling/blending/rotation, or too many
104      *   sideband layers) it can set compositionType to HWC_FRAMEBUFFER in
105      *   (*prepare)(). However, doing so will result in the layer being shown
106      *   as a solid color since the platform is not currently able to composite
107      *   sideband layers with the GPU. This may be improved in future
108      *   versions of the platform.
109      *
110      *
111      * HWC_CURSOR_OVERLAY
112      *   Set by the HWC implementation during (*prepare)(), this value
113      *   indicates the layer's composition will now be handled by the HWC.
114      *   Additionally, the client can now asynchronously update the on-screen
115      *   position of this layer using the setCursorPositionAsync() api.
116      */
117     int32_t compositionType;
118 
119     /*
120      * hints is bit mask set by the HWC implementation during (*prepare)().
121      * It is preserved between (*prepare)() calls, unless the
122      * HWC_GEOMETRY_CHANGED flag is set, in which case it is reset to 0.
123      *
124      * see hwc_layer_t::hints
125      */
126     uint32_t hints;
127 
128     /* see hwc_layer_t::flags */
129     uint32_t flags;
130 
131     union {
132         /* color of the background.  hwc_color_t.a is ignored */
133         hwc_color_t backgroundColor;
134 
135         struct {
136             union {
137                 /* When compositionType is HWC_FRAMEBUFFER, HWC_OVERLAY,
138                  * HWC_FRAMEBUFFER_TARGET, this is the handle of the buffer to
139                  * compose. This handle is guaranteed to have been allocated
140                  * from gralloc using the GRALLOC_USAGE_HW_COMPOSER usage flag.
141                  * If the layer's handle is unchanged across two consecutive
142                  * prepare calls and the HWC_GEOMETRY_CHANGED flag is not set
143                  * for the second call then the HWComposer implementation may
144                  * assume that the contents of the buffer have not changed. */
145                 buffer_handle_t handle;
146 
147                 /* When compositionType is HWC_SIDEBAND, this is the handle
148                  * of the sideband video stream to compose. */
149                 const native_handle_t* sidebandStream;
150             };
151 
152             /* transformation to apply to the buffer during composition */
153             uint32_t transform;
154 
155             /* blending to apply during composition */
156             int32_t blending;
157 
158             /* area of the source to consider, the origin is the top-left corner of
159              * the buffer. As of HWC_DEVICE_API_VERSION_1_3, sourceRect uses floats.
160              * If the h/w can't support a non-integer source crop rectangle, it should
161              * punt to OpenGL ES composition.
162              */
163             union {
164                 // crop rectangle in integer (pre HWC_DEVICE_API_VERSION_1_3)
165                 hwc_rect_t sourceCropi;
166                 hwc_rect_t sourceCrop; // just for source compatibility
167                 // crop rectangle in floats (as of HWC_DEVICE_API_VERSION_1_3)
168                 hwc_frect_t sourceCropf;
169             };
170 
171             /* where to composite the sourceCrop onto the display. The sourceCrop
172              * is scaled using linear filtering to the displayFrame. The origin is the
173              * top-left corner of the screen.
174              */
175             hwc_rect_t displayFrame;
176 
177             /* visible region in screen space. The origin is the
178              * top-left corner of the screen.
179              * The visible region INCLUDES areas overlapped by a translucent layer.
180              */
181             hwc_region_t visibleRegionScreen;
182 
183             /* Sync fence object that will be signaled when the buffer's
184              * contents are available. May be -1 if the contents are already
185              * available. This field is only valid during set(), and should be
186              * ignored during prepare(). The set() call must not wait for the
187              * fence to be signaled before returning, but the HWC must wait for
188              * all buffers to be signaled before reading from them.
189              *
190              * HWC_FRAMEBUFFER layers will never have an acquire fence, since
191              * reads from them are complete before the framebuffer is ready for
192              * display.
193              *
194              * HWC_SIDEBAND layers will never have an acquire fence, since
195              * synchronization is handled through implementation-defined
196              * sideband mechanisms.
197              *
198              * The HWC takes ownership of the acquireFenceFd and is responsible
199              * for closing it when no longer needed.
200              */
201             int acquireFenceFd;
202 
203             /* During set() the HWC must set this field to a file descriptor for
204              * a sync fence object that will signal after the HWC has finished
205              * reading from the buffer. The field is ignored by prepare(). Each
206              * layer should have a unique file descriptor, even if more than one
207              * refer to the same underlying fence object; this allows each to be
208              * closed independently.
209              *
210              * If buffer reads can complete at significantly different times,
211              * then using independent fences is preferred. For example, if the
212              * HWC handles some layers with a blit engine and others with
213              * overlays, then the blit layers can be reused immediately after
214              * the blit completes, but the overlay layers can't be reused until
215              * a subsequent frame has been displayed.
216              *
217              * Since HWC doesn't read from HWC_FRAMEBUFFER layers, it shouldn't
218              * produce a release fence for them. The releaseFenceFd will be -1
219              * for these layers when set() is called.
220              *
221              * Since HWC_SIDEBAND buffers don't pass through the HWC client,
222              * the HWC shouldn't produce a release fence for them. The
223              * releaseFenceFd will be -1 for these layers when set() is called.
224              *
225              * The HWC client taks ownership of the releaseFenceFd and is
226              * responsible for closing it when no longer needed.
227              */
228             int releaseFenceFd;
229 
230             /*
231              * Availability: HWC_DEVICE_API_VERSION_1_2
232              *
233              * Alpha value applied to the whole layer. The effective
234              * value of each pixel is computed as:
235              *
236              *   if (blending == HWC_BLENDING_PREMULT)
237              *      pixel.rgb = pixel.rgb * planeAlpha / 255
238              *   pixel.a = pixel.a * planeAlpha / 255
239              *
240              * Then blending proceeds as usual according to the "blending"
241              * field above.
242              *
243              * NOTE: planeAlpha applies to YUV layers as well:
244              *
245              *   pixel.rgb = yuv_to_rgb(pixel.yuv)
246              *   if (blending == HWC_BLENDING_PREMULT)
247              *      pixel.rgb = pixel.rgb * planeAlpha / 255
248              *   pixel.a = planeAlpha
249              *
250              *
251              * IMPLEMENTATION NOTE:
252              *
253              * If the source image doesn't have an alpha channel, then
254              * the h/w can use the HWC_BLENDING_COVERAGE equations instead of
255              * HWC_BLENDING_PREMULT and simply set the alpha channel to
256              * planeAlpha.
257              *
258              * e.g.:
259              *
260              *   if (blending == HWC_BLENDING_PREMULT)
261              *      blending = HWC_BLENDING_COVERAGE;
262              *   pixel.a = planeAlpha;
263              *
264              */
265             uint8_t planeAlpha;
266 
267             /* Pad to 32 bits */
268             uint8_t _pad[3];
269 
270             /*
271              * Availability: HWC_DEVICE_API_VERSION_1_5
272              *
273              * This defines the region of the source buffer that has been
274              * modified since the last frame.
275              *
276              * If surfaceDamage.numRects > 0, then it may be assumed that any
277              * portion of the source buffer not covered by one of the rects has
278              * not been modified this frame. If surfaceDamage.numRects == 0,
279              * then the whole source buffer must be treated as if it had been
280              * modified.
281              *
282              * If the layer's contents are not modified relative to the prior
283              * prepare/set cycle, surfaceDamage will contain exactly one empty
284              * rect ([0, 0, 0, 0]).
285              *
286              * The damage rects are relative to the pre-transformed buffer, and
287              * their origin is the top-left corner.
288              */
289             hwc_region_t surfaceDamage;
290         };
291     };
292 
293 #ifdef __LP64__
294     /*
295      * For 64-bit mode, this struct is 120 bytes (and 8-byte aligned), and needs
296      * to be padded as such to maintain binary compatibility.
297      */
298     uint8_t reserved[120 - 112];
299 #else
300     /*
301      * For 32-bit mode, this struct is 96 bytes, and needs to be padded as such
302      * to maintain binary compatibility.
303      */
304     uint8_t reserved[96 - 84];
305 #endif
306 
307 } hwc_layer_1_t;
308 
309 /* This represents a display, typically an EGLDisplay object */
310 typedef void* hwc_display_t;
311 
312 /* This represents a surface, typically an EGLSurface object  */
313 typedef void* hwc_surface_t;
314 
315 /*
316  * hwc_display_contents_1_t::flags values
317  */
318 enum {
319     /*
320      * HWC_GEOMETRY_CHANGED is set by SurfaceFlinger to indicate that the list
321      * passed to (*prepare)() has changed by more than just the buffer handles
322      * and acquire fences.
323      */
324     HWC_GEOMETRY_CHANGED = 0x00000001,
325 };
326 
327 /*
328  * Description of the contents to output on a display.
329  *
330  * This is the top-level structure passed to the prepare and set calls to
331  * negotiate and commit the composition of a display image.
332  */
333 typedef struct hwc_display_contents_1 {
334     /* File descriptor referring to a Sync HAL fence object which will signal
335      * when this composition is retired. For a physical display, a composition
336      * is retired when it has been replaced on-screen by a subsequent set. For
337      * a virtual display, the composition is retired when the writes to
338      * outputBuffer are complete and can be read. The fence object is created
339      * and returned by the set call; this field will be -1 on entry to prepare
340      * and set. SurfaceFlinger will close the returned file descriptor.
341      */
342     int retireFenceFd;
343 
344     union {
345         /* Fields only relevant for HWC_DEVICE_VERSION_1_0. */
346         struct {
347             /* (dpy, sur) is the target of SurfaceFlinger's OpenGL ES
348              * composition for HWC_DEVICE_VERSION_1_0. They aren't relevant to
349              * prepare. The set call should commit this surface atomically to
350              * the display along with any overlay layers.
351              */
352             hwc_display_t dpy;
353             hwc_surface_t sur;
354         };
355 
356         /* These fields are used for virtual displays when the h/w composer
357          * version is at least HWC_DEVICE_VERSION_1_3. */
358         struct {
359             /* outbuf is the buffer that receives the composed image for
360              * virtual displays. Writes to the outbuf must wait until
361              * outbufAcquireFenceFd signals. A fence that will signal when
362              * writes to outbuf are complete should be returned in
363              * retireFenceFd.
364              *
365              * This field is set before prepare(), so properties of the buffer
366              * can be used to decide which layers can be handled by h/w
367              * composer.
368              *
369              * If prepare() sets all layers to FRAMEBUFFER, then GLES
370              * composition will happen directly to the output buffer. In this
371              * case, both outbuf and the FRAMEBUFFER_TARGET layer's buffer will
372              * be the same, and set() has no work to do besides managing fences.
373              *
374              * If the TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS board config
375              * variable is defined (not the default), then this behavior is
376              * changed: if all layers are marked for FRAMEBUFFER, GLES
377              * composition will take place to a scratch framebuffer, and
378              * h/w composer must copy it to the output buffer. This allows the
379              * h/w composer to do format conversion if there are cases where
380              * that is more desirable than doing it in the GLES driver or at the
381              * virtual display consumer.
382              *
383              * If some or all layers are marked OVERLAY, then the framebuffer
384              * and output buffer will be different. As with physical displays,
385              * the framebuffer handle will not change between frames if all
386              * layers are marked for OVERLAY.
387              */
388             buffer_handle_t outbuf;
389 
390             /* File descriptor for a fence that will signal when outbuf is
391              * ready to be written. The h/w composer is responsible for closing
392              * this when no longer needed.
393              *
394              * Will be -1 whenever outbuf is NULL, or when the outbuf can be
395              * written immediately.
396              */
397             int outbufAcquireFenceFd;
398         };
399     };
400 
401     /* List of layers that will be composed on the display. The buffer handles
402      * in the list will be unique. If numHwLayers is 0, all composition will be
403      * performed by SurfaceFlinger.
404      */
405     uint32_t flags;
406     size_t numHwLayers;
407     hwc_layer_1_t hwLayers[0];
408 
409 } hwc_display_contents_1_t;
410 
411 /* see hwc_composer_device::registerProcs()
412  * All of the callbacks are required and non-NULL unless otherwise noted.
413  */
414 typedef struct hwc_procs {
415     /*
416      * (*invalidate)() triggers a screen refresh, in particular prepare and set
417      * will be called shortly after this call is made. Note that there is
418      * NO GUARANTEE that the screen refresh will happen after invalidate()
419      * returns (in particular, it could happen before).
420      * invalidate() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL and
421      * it is safe to call invalidate() from any of hwc_composer_device
422      * hooks, unless noted otherwise.
423      */
424     void (*invalidate)(const struct hwc_procs* procs);
425 
426     /*
427      * (*vsync)() is called by the h/w composer HAL when a vsync event is
428      * received and HWC_EVENT_VSYNC is enabled on a display
429      * (see: hwc_event_control).
430      *
431      * the "disp" parameter indicates which display the vsync event is for.
432      * the "timestamp" parameter is the system monotonic clock timestamp in
433      *   nanosecond of when the vsync event happened.
434      *
435      * vsync() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL.
436      *
437      * It is expected that vsync() is called from a thread of at least
438      * HAL_PRIORITY_URGENT_DISPLAY with as little latency as possible,
439      * typically less than 0.5 ms.
440      *
441      * It is a (silent) error to have HWC_EVENT_VSYNC enabled when calling
442      * hwc_composer_device.set(..., 0, 0, 0) (screen off). The implementation
443      * can either stop or continue to process VSYNC events, but must not
444      * crash or cause other problems.
445      */
446     void (*vsync)(const struct hwc_procs* procs, int disp, int64_t timestamp);
447 
448     /*
449      * (*hotplug)() is called by the h/w composer HAL when a display is
450      * connected or disconnected. The PRIMARY display is always connected and
451      * the hotplug callback should not be called for it.
452      *
453      * The disp parameter indicates which display type this event is for.
454      * The connected parameter indicates whether the display has just been
455      *   connected (1) or disconnected (0).
456      *
457      * The hotplug() callback may call back into the h/w composer on the same
458      * thread to query refresh rate and dpi for the display. Additionally,
459      * other threads may be calling into the h/w composer while the callback
460      * is in progress.
461      *
462      * The h/w composer must serialize calls to the hotplug callback; only
463      * one thread may call it at a time.
464      *
465      * This callback will be NULL if the h/w composer is using
466      * HWC_DEVICE_API_VERSION_1_0.
467      */
468     void (*hotplug)(const struct hwc_procs* procs, int disp, int connected);
469 
470 } hwc_procs_t;
471 
472 
473 /*****************************************************************************/
474 
475 typedef struct hwc_module {
476     /**
477      * Common methods of the hardware composer module.  This *must* be the first member of
478      * hwc_module as users of this structure will cast a hw_module_t to
479      * hwc_module pointer in contexts where it's known the hw_module_t references a
480      * hwc_module.
481      */
482     struct hw_module_t common;
483 } hwc_module_t;
484 
485 #define HWC_ERROR (-1)
486 typedef struct hwc_composer_device_1 {
487     /**
488      * Common methods of the hardware composer device.  This *must* be the first member of
489      * hwc_composer_device_1 as users of this structure will cast a hw_device_t to
490      * hwc_composer_device_1 pointer in contexts where it's known the hw_device_t references a
491      * hwc_composer_device_1.
492      */
493     struct hw_device_t common;
494 
495     /*
496      * (*prepare)() is called for each frame before composition and is used by
497      * SurfaceFlinger to determine what composition steps the HWC can handle.
498      *
499      * (*prepare)() can be called more than once, the last call prevails.
500      *
501      * The HWC responds by setting the compositionType field in each layer to
502      * either HWC_FRAMEBUFFER, HWC_OVERLAY, or HWC_CURSOR_OVERLAY. For the
503      * HWC_FRAMEBUFFER type, composition for the layer is handled by
504      * SurfaceFlinger with OpenGL ES. For the latter two overlay types,
505      * the HWC will have to handle the layer's composition. compositionType
506      * and hints are preserved between (*prepare)() calles unless the
507      * HWC_GEOMETRY_CHANGED flag is set.
508      *
509      * (*prepare)() is called with HWC_GEOMETRY_CHANGED to indicate that the
510      * list's geometry has changed, that is, when more than just the buffer's
511      * handles have been updated. Typically this happens (but is not limited to)
512      * when a window is added, removed, resized or moved. In this case
513      * compositionType and hints are reset to their default value.
514      *
515      * For HWC 1.0, numDisplays will always be one, and displays[0] will be
516      * non-NULL.
517      *
518      * For HWC 1.1, numDisplays will always be HWC_NUM_PHYSICAL_DISPLAY_TYPES.
519      * Entries for unsupported or disabled/disconnected display types will be
520      * NULL.
521      *
522      * In HWC 1.3, numDisplays may be up to HWC_NUM_DISPLAY_TYPES. The extra
523      * entries correspond to enabled virtual displays, and will be non-NULL.
524      *
525      * returns: 0 on success. An negative error code on error. If an error is
526      * returned, SurfaceFlinger will assume that none of the layer will be
527      * handled by the HWC.
528      */
529     int (*prepare)(struct hwc_composer_device_1 *dev,
530                     size_t numDisplays, hwc_display_contents_1_t** displays);
531 
532     /*
533      * (*set)() is used in place of eglSwapBuffers(), and assumes the same
534      * functionality, except it also commits the work list atomically with
535      * the actual eglSwapBuffers().
536      *
537      * The layer lists are guaranteed to be the same as the ones returned from
538      * the last call to (*prepare)().
539      *
540      * When this call returns the caller assumes that the displays will be
541      * updated in the near future with the content of their work lists, without
542      * artifacts during the transition from the previous frame.
543      *
544      * A display with zero layers indicates that the entire composition has
545      * been handled by SurfaceFlinger with OpenGL ES. In this case, (*set)()
546      * behaves just like eglSwapBuffers().
547      *
548      * For HWC 1.0, numDisplays will always be one, and displays[0] will be
549      * non-NULL.
550      *
551      * For HWC 1.1, numDisplays will always be HWC_NUM_PHYSICAL_DISPLAY_TYPES.
552      * Entries for unsupported or disabled/disconnected display types will be
553      * NULL.
554      *
555      * In HWC 1.3, numDisplays may be up to HWC_NUM_DISPLAY_TYPES. The extra
556      * entries correspond to enabled virtual displays, and will be non-NULL.
557      *
558      * IMPORTANT NOTE: There is an implicit layer containing opaque black
559      * pixels behind all the layers in the list. It is the responsibility of
560      * the hwcomposer module to make sure black pixels are output (or blended
561      * from).
562      *
563      * IMPORTANT NOTE: In the event of an error this call *MUST* still cause
564      * any fences returned in the previous call to set to eventually become
565      * signaled.  The caller may have already issued wait commands on these
566      * fences, and having set return without causing those fences to signal
567      * will likely result in a deadlock.
568      *
569      * returns: 0 on success. A negative error code on error:
570      *    HWC_EGL_ERROR: eglGetError() will provide the proper error code (only
571      *        allowed prior to HWComposer 1.1)
572      *    Another code for non EGL errors.
573      */
574     int (*set)(struct hwc_composer_device_1 *dev,
575                 size_t numDisplays, hwc_display_contents_1_t** displays);
576 
577     /*
578      * eventControl(..., event, enabled)
579      * Enables or disables h/w composer events for a display.
580      *
581      * eventControl can be called from any thread and takes effect
582      * immediately.
583      *
584      *  Supported events are:
585      *      HWC_EVENT_VSYNC
586      *
587      * returns -EINVAL if the "event" parameter is not one of the value above
588      * or if the "enabled" parameter is not 0 or 1.
589      */
590     int (*eventControl)(struct hwc_composer_device_1* dev, int disp,
591             int event, int enabled);
592 
593     union {
594         /*
595          * For HWC 1.3 and earlier, the blank() interface is used.
596          *
597          * blank(..., blank)
598          * Blanks or unblanks a display's screen.
599          *
600          * Turns the screen off when blank is nonzero, on when blank is zero.
601          * Multiple sequential calls with the same blank value must be
602          * supported.
603          * The screen state transition must be be complete when the function
604          * returns.
605          *
606          * returns 0 on success, negative on error.
607          */
608         int (*blank)(struct hwc_composer_device_1* dev, int disp, int blank);
609 
610         /*
611          * For HWC 1.4 and above, setPowerMode() will be used in place of
612          * blank().
613          *
614          * setPowerMode(..., mode)
615          * Sets the display screen's power state.
616          *
617          * Refer to the documentation of the HWC_POWER_MODE_* constants
618          * for information about each power mode.
619          *
620          * The functionality is similar to the blank() command in previous
621          * versions of HWC, but with support for more power states.
622          *
623          * The display driver is expected to retain and restore the low power
624          * state of the display while entering and exiting from suspend.
625          *
626          * Multiple sequential calls with the same mode value must be supported.
627          *
628          * The screen state transition must be be complete when the function
629          * returns.
630          *
631          * returns 0 on success, negative on error.
632          */
633         int (*setPowerMode)(struct hwc_composer_device_1* dev, int disp,
634                 int mode);
635     };
636 
637     /*
638      * Used to retrieve information about the h/w composer
639      *
640      * Returns 0 on success or -errno on error.
641      */
642     int (*query)(struct hwc_composer_device_1* dev, int what, int* value);
643 
644     /*
645      * (*registerProcs)() registers callbacks that the h/w composer HAL can
646      * later use. It will be called immediately after the composer device is
647      * opened with non-NULL procs. It is FORBIDDEN to call any of the callbacks
648      * from within registerProcs(). registerProcs() must save the hwc_procs_t
649      * pointer which is needed when calling a registered callback.
650      */
651     void (*registerProcs)(struct hwc_composer_device_1* dev,
652             hwc_procs_t const* procs);
653 
654     /*
655      * This field is OPTIONAL and can be NULL.
656      *
657      * If non NULL it will be called by SurfaceFlinger on dumpsys
658      */
659     void (*dump)(struct hwc_composer_device_1* dev, char *buff, int buff_len);
660 
661     /*
662      * (*getDisplayConfigs)() returns handles for the configurations available
663      * on the connected display. These handles must remain valid as long as the
664      * display is connected.
665      *
666      * Configuration handles are written to configs. The number of entries
667      * allocated by the caller is passed in *numConfigs; getDisplayConfigs must
668      * not try to write more than this number of config handles. On return, the
669      * total number of configurations available for the display is returned in
670      * *numConfigs. If *numConfigs is zero on entry, then configs may be NULL.
671      *
672      * Hardware composers implementing HWC_DEVICE_API_VERSION_1_3 or prior
673      * shall choose one configuration to activate and report it as the first
674      * entry in the returned list. Reporting the inactive configurations is not
675      * required.
676      *
677      * HWC_DEVICE_API_VERSION_1_4 and later provide configuration management
678      * through SurfaceFlinger, and hardware composers implementing these APIs
679      * must also provide getActiveConfig and setActiveConfig. Hardware composers
680      * implementing these API versions may choose not to activate any
681      * configuration, leaving configuration selection to higher levels of the
682      * framework.
683      *
684      * Returns 0 on success or a negative error code on error. If disp is a
685      * hotpluggable display type and no display is connected, an error shall be
686      * returned.
687      *
688      * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_1 and later.
689      * It shall be NULL for previous versions.
690      */
691     int (*getDisplayConfigs)(struct hwc_composer_device_1* dev, int disp,
692             uint32_t* configs, size_t* numConfigs);
693 
694     /*
695      * (*getDisplayAttributes)() returns attributes for a specific config of a
696      * connected display. The config parameter is one of the config handles
697      * returned by getDisplayConfigs.
698      *
699      * The list of attributes to return is provided in the attributes
700      * parameter, terminated by HWC_DISPLAY_NO_ATTRIBUTE. The value for each
701      * requested attribute is written in order to the values array. The
702      * HWC_DISPLAY_NO_ATTRIBUTE attribute does not have a value, so the values
703      * array will have one less value than the attributes array.
704      *
705      * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_1 and later.
706      * It shall be NULL for previous versions.
707      *
708      * If disp is a hotpluggable display type and no display is connected,
709      * or if config is not a valid configuration for the display, a negative
710      * error code shall be returned.
711      */
712     int (*getDisplayAttributes)(struct hwc_composer_device_1* dev, int disp,
713             uint32_t config, const uint32_t* attributes, int32_t* values);
714 
715     /*
716      * (*getActiveConfig)() returns the index of the configuration that is
717      * currently active on the connected display. The index is relative to
718      * the list of configuration handles returned by getDisplayConfigs. If there
719      * is no active configuration, HWC_ERROR shall be returned.
720      *
721      * Returns the configuration index on success or HWC_ERROR on error.
722      *
723      * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_4 and later.
724      * It shall be NULL for previous versions.
725      */
726     int (*getActiveConfig)(struct hwc_composer_device_1* dev, int disp);
727 
728     /*
729      * (*setActiveConfig)() instructs the hardware composer to switch to the
730      * display configuration at the given index in the list of configuration
731      * handles returned by getDisplayConfigs.
732      *
733      * If this function returns without error, any subsequent calls to
734      * getActiveConfig shall return the index set by this function until one
735      * of the following occurs:
736      *   1) Another successful call of this function
737      *   2) The display is disconnected
738      *
739      * Returns 0 on success or a negative error code on error. If disp is a
740      * hotpluggable display type and no display is connected, or if index is
741      * outside of the range of hardware configurations returned by
742      * getDisplayConfigs, an error shall be returned.
743      *
744      * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_4 and later.
745      * It shall be NULL for previous versions.
746      */
747     int (*setActiveConfig)(struct hwc_composer_device_1* dev, int disp,
748             int index);
749     /*
750      * Asynchronously update the location of the cursor layer.
751      *
752      * Within the standard prepare()/set() composition loop, the client
753      * (surfaceflinger) can request that a given layer uses dedicated cursor
754      * composition hardware by specifiying the HWC_IS_CURSOR_LAYER flag. Only
755      * one layer per display can have this flag set. If the layer is suitable
756      * for the platform's cursor hardware, hwcomposer will return from prepare()
757      * a composition type of HWC_CURSOR_OVERLAY for that layer. This indicates
758      * not only that the client is not responsible for compositing that layer,
759      * but also that the client can continue to update the position of that layer
760      * after a call to set(). This can reduce the visible latency of mouse
761      * movement to visible, on-screen cursor updates. Calls to
762      * setCursorPositionAsync() may be made from a different thread doing the
763      * prepare()/set() composition loop, but care must be taken to not interleave
764      * calls of setCursorPositionAsync() between calls of set()/prepare().
765      *
766      * Notes:
767      * - Only one layer per display can be specified as a cursor layer with
768      *   HWC_IS_CURSOR_LAYER.
769      * - hwcomposer will only return one layer per display as HWC_CURSOR_OVERLAY
770      * - This returns 0 on success or -errno on error.
771      * - This field is optional for HWC_DEVICE_API_VERSION_1_4 and later. It
772      *   should be null for previous versions.
773      */
774     int (*setCursorPositionAsync)(struct hwc_composer_device_1 *dev, int disp, int x_pos, int y_pos);
775 
776     /*
777      * Reserved for future use. Must be NULL.
778      */
779     void* reserved_proc[1];
780 
781 } hwc_composer_device_1_t;
782 
783 /** convenience API for opening and closing a device */
784 
hwc_open_1(const struct hw_module_t * module,hwc_composer_device_1_t ** device)785 static inline int hwc_open_1(const struct hw_module_t* module,
786         hwc_composer_device_1_t** device) {
787     return module->methods->open(module,
788             HWC_HARDWARE_COMPOSER, TO_HW_DEVICE_T_OPEN(device));
789 }
790 
hwc_close_1(hwc_composer_device_1_t * device)791 static inline int hwc_close_1(hwc_composer_device_1_t* device) {
792     return device->common.close(&device->common);
793 }
794 
795 /*****************************************************************************/
796 
797 __END_DECLS
798 
799 #endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H */
800