Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 1 | /* |
| 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 Huemiller | 45e2371 | 2010-12-01 12:25:00 -0800 | [diff] [blame] | 23 | #include <hardware/gralloc.h> |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 24 | #include <hardware/hardware.h> |
| 25 | #include <cutils/native_handle.h> |
| 26 | |
Mathias Agopian | e291f71 | 2012-05-13 22:49:06 -0700 | [diff] [blame] | 27 | #include <hardware/hwcomposer_defs.h> |
| 28 | |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 29 | __BEGIN_DECLS |
| 30 | |
| 31 | /*****************************************************************************/ |
Erik Gilling | e995204 | 2010-12-07 18:46:04 -0800 | [diff] [blame] | 32 | |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 33 | /* for compatibility */ |
Mathias Agopian | b08d45d | 2012-03-24 15:56:29 -0700 | [diff] [blame] | 34 | #define HWC_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1 |
| 35 | #define HWC_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1 |
Mathias Agopian | 81c323d | 2012-03-25 01:09:35 -0700 | [diff] [blame] | 36 | #define HWC_API_VERSION HWC_DEVICE_API_VERSION |
Erik Gilling | e995204 | 2010-12-07 18:46:04 -0800 | [diff] [blame] | 37 | |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 38 | /*****************************************************************************/ |
| 39 | |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 40 | /** |
| 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 Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 50 | typedef struct hwc_rect { |
| 51 | int left; |
| 52 | int top; |
| 53 | int right; |
| 54 | int bottom; |
| 55 | } hwc_rect_t; |
| 56 | |
| 57 | typedef struct hwc_region { |
| 58 | size_t numRects; |
| 59 | hwc_rect_t const* rects; |
| 60 | } hwc_region_t; |
| 61 | |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 62 | typedef struct hwc_color { |
| 63 | uint8_t r; |
| 64 | uint8_t g; |
| 65 | uint8_t b; |
| 66 | uint8_t a; |
| 67 | } hwc_color_t; |
| 68 | |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 69 | typedef struct hwc_layer_1 { |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 70 | /* |
Mathias Agopian | 48697f6 | 2012-11-20 15:23:25 -0800 | [diff] [blame] | 71 | * compositionType is used to specify this layer's type and is set by either |
| 72 | * the hardware composer implementation, or by the caller (see below). |
Jesse Hall | d18c83f | 2012-08-16 16:21:13 -0700 | [diff] [blame] | 73 | * |
Mathias Agopian | 48697f6 | 2012-11-20 15:23:25 -0800 | [diff] [blame] | 74 | * This field is always reset to HWC_BACKGROUND or HWC_FRAMEBUFFER |
| 75 | * before (*prepare)() is called when the HWC_GEOMETRY_CHANGED flag is |
| 76 | * also set, otherwise, this field is preserved between (*prepare)() |
| 77 | * calls. |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 78 | * |
| 79 | * HWC_BACKGROUND |
Mathias Agopian | 48697f6 | 2012-11-20 15:23:25 -0800 | [diff] [blame] | 80 | * Always set by the caller before calling (*prepare)(), this value |
| 81 | * indicates this is a special "background" layer. The only valid field |
| 82 | * is backgroundColor. |
| 83 | * The HWC can toggle this value to HWC_FRAMEBUFFER to indicate it CANNOT |
| 84 | * handle the background color. |
| 85 | * |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 86 | * |
Jesse Hall | d18c83f | 2012-08-16 16:21:13 -0700 | [diff] [blame] | 87 | * HWC_FRAMEBUFFER_TARGET |
Mathias Agopian | 48697f6 | 2012-11-20 15:23:25 -0800 | [diff] [blame] | 88 | * Always set by the caller before calling (*prepare)(), this value |
| 89 | * indicates this layer is the framebuffer surface used as the target of |
Jesse Hall | d18c83f | 2012-08-16 16:21:13 -0700 | [diff] [blame] | 90 | * OpenGL ES composition. If the HWC sets all other layers to HWC_OVERLAY |
| 91 | * or HWC_BACKGROUND, then no OpenGL ES composition will be done, and |
Jesse Hall | 6b01e2e | 2012-09-14 17:21:22 -0700 | [diff] [blame] | 92 | * this layer should be ignored during set(). |
Jesse Hall | d18c83f | 2012-08-16 16:21:13 -0700 | [diff] [blame] | 93 | * |
| 94 | * This flag (and the framebuffer surface layer) will only be used if the |
| 95 | * HWC version is HWC_DEVICE_API_VERSION_1_1 or higher. In older versions, |
| 96 | * the OpenGL ES target surface is communicated by the (dpy, sur) fields |
| 97 | * in hwc_compositor_device_1_t. |
Mathias Agopian | 48697f6 | 2012-11-20 15:23:25 -0800 | [diff] [blame] | 98 | * |
| 99 | * This value cannot be set by the HWC implementation. |
| 100 | * |
| 101 | * |
| 102 | * HWC_FRAMEBUFFER |
| 103 | * Set by the caller before calling (*prepare)() ONLY when the |
| 104 | * HWC_GEOMETRY_CHANGED flag is also set. |
| 105 | * |
| 106 | * Set by the HWC implementation during (*prepare)(), this indicates |
| 107 | * that the layer will be drawn into the framebuffer using OpenGL ES. |
| 108 | * The HWC can toggle this value to HWC_OVERLAY to indicate it will |
| 109 | * handle the layer. |
| 110 | * |
| 111 | * |
| 112 | * HWC_OVERLAY |
| 113 | * Set by the HWC implementation during (*prepare)(), this indicates |
| 114 | * that the layer will be handled by the HWC (ie: it must not be |
| 115 | * composited with OpenGL ES). |
| 116 | * |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 117 | */ |
| 118 | int32_t compositionType; |
| 119 | |
Mathias Agopian | 48697f6 | 2012-11-20 15:23:25 -0800 | [diff] [blame] | 120 | /* |
| 121 | * hints is bit mask set by the HWC implementation during (*prepare)(). |
| 122 | * It is preserved between (*prepare)() calls, unless the |
| 123 | * HWC_GEOMETRY_CHANGED flag is set, in which case it is reset to 0. |
| 124 | * |
| 125 | * see hwc_layer_t::hints |
| 126 | */ |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 127 | uint32_t hints; |
| 128 | |
Mathias Agopian | 48697f6 | 2012-11-20 15:23:25 -0800 | [diff] [blame] | 129 | /* see hwc_layer_t::flags */ |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 130 | uint32_t flags; |
| 131 | |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 132 | union { |
| 133 | /* color of the background. hwc_color_t.a is ignored */ |
| 134 | hwc_color_t backgroundColor; |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 135 | |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 136 | struct { |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 137 | /* handle of buffer to compose. This handle is guaranteed to have been |
| 138 | * allocated from gralloc using the GRALLOC_USAGE_HW_COMPOSER usage flag. If |
| 139 | * the layer's handle is unchanged across two consecutive prepare calls and |
| 140 | * the HWC_GEOMETRY_CHANGED flag is not set for the second call then the |
| 141 | * HWComposer implementation may assume that the contents of the buffer have |
| 142 | * not changed. */ |
| 143 | buffer_handle_t handle; |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 144 | |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 145 | /* transformation to apply to the buffer during composition */ |
| 146 | uint32_t transform; |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 147 | |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 148 | /* blending to apply during composition */ |
| 149 | int32_t blending; |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 150 | |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 151 | /* area of the source to consider, the origin is the top-left corner of |
| 152 | * the buffer */ |
| 153 | hwc_rect_t sourceCrop; |
| 154 | |
| 155 | /* where to composite the sourceCrop onto the display. The sourceCrop |
| 156 | * is scaled using linear filtering to the displayFrame. The origin is the |
| 157 | * top-left corner of the screen. |
| 158 | */ |
| 159 | hwc_rect_t displayFrame; |
| 160 | |
| 161 | /* visible region in screen space. The origin is the |
| 162 | * top-left corner of the screen. |
| 163 | * The visible region INCLUDES areas overlapped by a translucent layer. |
| 164 | */ |
| 165 | hwc_region_t visibleRegionScreen; |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 166 | |
| 167 | /* Sync fence object that will be signaled when the buffer's |
| 168 | * contents are available. May be -1 if the contents are already |
| 169 | * available. This field is only valid during set(), and should be |
| 170 | * ignored during prepare(). The set() call must not wait for the |
| 171 | * fence to be signaled before returning, but the HWC must wait for |
| 172 | * all buffers to be signaled before reading from them. |
| 173 | * |
Jesse Hall | 0a0a416 | 2012-08-21 12:06:28 -0700 | [diff] [blame] | 174 | * HWC_FRAMEBUFFER layers will never have an acquire fence, since |
| 175 | * reads from them are complete before the framebuffer is ready for |
| 176 | * display. |
| 177 | * |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 178 | * The HWC takes ownership of the acquireFenceFd and is responsible |
| 179 | * for closing it when no longer needed. |
| 180 | */ |
| 181 | int acquireFenceFd; |
| 182 | |
| 183 | /* During set() the HWC must set this field to a file descriptor for |
| 184 | * a sync fence object that will signal after the HWC has finished |
| 185 | * reading from the buffer. The field is ignored by prepare(). Each |
| 186 | * layer should have a unique file descriptor, even if more than one |
| 187 | * refer to the same underlying fence object; this allows each to be |
| 188 | * closed independently. |
| 189 | * |
| 190 | * If buffer reads can complete at significantly different times, |
| 191 | * then using independent fences is preferred. For example, if the |
| 192 | * HWC handles some layers with a blit engine and others with |
| 193 | * overlays, then the blit layers can be reused immediately after |
| 194 | * the blit completes, but the overlay layers can't be reused until |
| 195 | * a subsequent frame has been displayed. |
| 196 | * |
Jesse Hall | 0a0a416 | 2012-08-21 12:06:28 -0700 | [diff] [blame] | 197 | * Since HWC doesn't read from HWC_FRAMEBUFFER layers, it shouldn't |
| 198 | * produce a release fence for them. The releaseFenceFd will be -1 |
| 199 | * for these layers when set() is called. |
| 200 | * |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 201 | * The HWC client taks ownership of the releaseFenceFd and is |
| 202 | * responsible for closing it when no longer needed. |
| 203 | */ |
| 204 | int releaseFenceFd; |
Mathias Agopian | e3e0a57 | 2013-01-29 18:57:48 -0800 | [diff] [blame] | 205 | |
| 206 | /* |
| 207 | * Availability: HWC_DEVICE_API_VERSION_1_2 |
| 208 | * |
| 209 | * Alpha value applied to the whole layer. The effective |
| 210 | * value of each pixel is computed as: |
| 211 | * |
| 212 | * if (blending == HWC_BLENDING_PREMULT) |
| 213 | * pixel.rgb = pixel.rgb * planeAlpha / 255 |
| 214 | * pixel.a = pixel.a * planeAlpha / 255 |
| 215 | * |
| 216 | * Then blending proceeds as usual according to the "blending" |
| 217 | * field above. |
| 218 | * |
| 219 | * NOTE: planeAlpha applies to YUV layers as well: |
| 220 | * |
| 221 | * pixel.rgb = yuv_to_rgb(pixel.yuv) |
| 222 | * if (blending == HWC_BLENDING_PREMULT) |
| 223 | * pixel.rgb = pixel.rgb * planeAlpha / 255 |
| 224 | * pixel.a = planeAlpha |
| 225 | * |
| 226 | * |
| 227 | * IMPLEMENTATION NOTE: |
| 228 | * |
| 229 | * If the source image doesn't have an alpha channel, then |
| 230 | * the h/w can use the HWC_BLENDING_COVERAGE equations instead of |
| 231 | * HWC_BLENDING_PREMULT and simply set the alpha channel to |
| 232 | * planeAlpha. |
| 233 | * |
| 234 | * e.g.: |
| 235 | * |
| 236 | * if (blending == HWC_BLENDING_PREMULT) |
| 237 | * blending = HWC_BLENDING_COVERAGE; |
| 238 | * pixel.a = planeAlpha; |
| 239 | * |
| 240 | */ |
| 241 | uint8_t planeAlpha; |
| 242 | |
| 243 | /* reserved for future use */ |
| 244 | uint8_t _pad[3]; |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 245 | }; |
| 246 | }; |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 247 | |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 248 | /* Allow for expansion w/o breaking binary compatibility. |
| 249 | * Pad layer to 96 bytes, assuming 32-bit pointers. |
| 250 | */ |
Mathias Agopian | e3e0a57 | 2013-01-29 18:57:48 -0800 | [diff] [blame] | 251 | int32_t reserved[24 - 19]; |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 252 | |
| 253 | } hwc_layer_1_t; |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 254 | |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 255 | /* This represents a display, typically an EGLDisplay object */ |
| 256 | typedef void* hwc_display_t; |
| 257 | |
| 258 | /* This represents a surface, typically an EGLSurface object */ |
| 259 | typedef void* hwc_surface_t; |
| 260 | |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 261 | /* |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 262 | * hwc_display_contents_1_t::flags values |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 263 | */ |
| 264 | enum { |
| 265 | /* |
| 266 | * HWC_GEOMETRY_CHANGED is set by SurfaceFlinger to indicate that the list |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 267 | * passed to (*prepare)() has changed by more than just the buffer handles |
| 268 | * and acquire fences. |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 269 | */ |
| 270 | HWC_GEOMETRY_CHANGED = 0x00000001, |
| 271 | }; |
| 272 | |
Louis Huemiller | 871815b | 2010-10-25 17:00:52 -0700 | [diff] [blame] | 273 | /* |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 274 | * Description of the contents to output on a display. |
| 275 | * |
| 276 | * This is the top-level structure passed to the prepare and set calls to |
| 277 | * negotiate and commit the composition of a display image. |
Louis Huemiller | 871815b | 2010-10-25 17:00:52 -0700 | [diff] [blame] | 278 | */ |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 279 | typedef struct hwc_display_contents_1 { |
| 280 | /* File descriptor referring to a Sync HAL fence object which will signal |
Jesse Hall | 7cb03d7 | 2012-09-06 16:57:12 -0700 | [diff] [blame] | 281 | * when this composition is retired. For a physical display, a composition |
| 282 | * is retired when it has been replaced on-screen by a subsequent set. For |
| 283 | * a virtual display, the composition is retired when the writes to |
| 284 | * outputBuffer are complete and can be read. The fence object is created |
| 285 | * and returned by the set call; this field will be -1 on entry to prepare |
| 286 | * and set. SurfaceFlinger will close the returned file descriptor. |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 287 | */ |
Jesse Hall | 7cb03d7 | 2012-09-06 16:57:12 -0700 | [diff] [blame] | 288 | int retireFenceFd; |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 289 | |
Jesse Hall | 7cb03d7 | 2012-09-06 16:57:12 -0700 | [diff] [blame] | 290 | union { |
| 291 | /* Fields only relevant for HWC_DEVICE_VERSION_1_0. */ |
| 292 | struct { |
| 293 | /* (dpy, sur) is the target of SurfaceFlinger's OpenGL ES |
| 294 | * composition for HWC_DEVICE_VERSION_1_0. They aren't relevant to |
| 295 | * prepare. The set call should commit this surface atomically to |
| 296 | * the display along with any overlay layers. |
| 297 | */ |
| 298 | hwc_display_t dpy; |
| 299 | hwc_surface_t sur; |
| 300 | }; |
| 301 | |
Jesse Hall | 380f45d | 2013-03-20 10:11:10 -0700 | [diff] [blame] | 302 | /* WARNING: These fields are for experimental virtual display support, |
| 303 | * and are not currently used. */ |
Jesse Hall | 7cb03d7 | 2012-09-06 16:57:12 -0700 | [diff] [blame] | 304 | struct { |
| 305 | /* outbuf is the buffer that receives the composed image for |
| 306 | * virtual displays. Writes to the outbuf must wait until |
| 307 | * outbufAcquireFenceFd signals. A fence that will signal when |
| 308 | * writes to outbuf are complete should be returned in |
| 309 | * retireFenceFd. |
| 310 | * |
Jesse Hall | 380f45d | 2013-03-20 10:11:10 -0700 | [diff] [blame] | 311 | * This field will not be updated until after prepare(). If |
| 312 | * prepare() sets all non-FB layers to OVERLAY or sets all non-FB |
| 313 | * layers to FRAMEBUFFER, then the FRAMEBUFFER_TARGET buffer and |
| 314 | * the output buffer may be the same. In mixed OVERLAY/FRAMEBUFFER |
| 315 | * configurations they will have different buffers so the |
| 316 | * h/w composer does not have to read and write the same buffer. |
| 317 | * |
Jesse Hall | 7cb03d7 | 2012-09-06 16:57:12 -0700 | [diff] [blame] | 318 | * For physical displays, outbuf will be NULL. |
| 319 | */ |
| 320 | buffer_handle_t outbuf; |
| 321 | |
| 322 | /* File descriptor for a fence that will signal when outbuf is |
| 323 | * ready to be written. The h/w composer is responsible for closing |
| 324 | * this when no longer needed. |
| 325 | * |
| 326 | * Will be -1 whenever outbuf is NULL, or when the outbuf can be |
| 327 | * written immediately. |
| 328 | */ |
| 329 | int outbufAcquireFenceFd; |
| 330 | }; |
| 331 | }; |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 332 | |
| 333 | /* List of layers that will be composed on the display. The buffer handles |
Jesse Hall | ac3f7e1 | 2012-07-31 15:18:32 -0700 | [diff] [blame] | 334 | * in the list will be unique. If numHwLayers is 0, all composition will be |
| 335 | * performed by SurfaceFlinger. |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 336 | */ |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 337 | uint32_t flags; |
| 338 | size_t numHwLayers; |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 339 | hwc_layer_1_t hwLayers[0]; |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 340 | |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 341 | } hwc_display_contents_1_t; |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 342 | |
Mathias Agopian | d6afef6 | 2011-08-01 16:34:42 -0700 | [diff] [blame] | 343 | /* see hwc_composer_device::registerProcs() |
Jesse Hall | 0a0a416 | 2012-08-21 12:06:28 -0700 | [diff] [blame] | 344 | * All of the callbacks are required and non-NULL unless otherwise noted. |
Mathias Agopian | d6afef6 | 2011-08-01 16:34:42 -0700 | [diff] [blame] | 345 | */ |
| 346 | typedef struct hwc_procs { |
| 347 | /* |
| 348 | * (*invalidate)() triggers a screen refresh, in particular prepare and set |
| 349 | * will be called shortly after this call is made. Note that there is |
| 350 | * NO GUARANTEE that the screen refresh will happen after invalidate() |
| 351 | * returns (in particular, it could happen before). |
| 352 | * invalidate() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL and |
| 353 | * it is safe to call invalidate() from any of hwc_composer_device |
| 354 | * hooks, unless noted otherwise. |
| 355 | */ |
Jesse Hall | 0a0a416 | 2012-08-21 12:06:28 -0700 | [diff] [blame] | 356 | void (*invalidate)(const struct hwc_procs* procs); |
Mathias Agopian | b08d45d | 2012-03-24 15:56:29 -0700 | [diff] [blame] | 357 | |
| 358 | /* |
| 359 | * (*vsync)() is called by the h/w composer HAL when a vsync event is |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 360 | * received and HWC_EVENT_VSYNC is enabled on a display |
| 361 | * (see: hwc_event_control). |
Mathias Agopian | b08d45d | 2012-03-24 15:56:29 -0700 | [diff] [blame] | 362 | * |
Jesse Hall | 2c13759 | 2012-08-29 10:37:37 -0700 | [diff] [blame] | 363 | * the "disp" parameter indicates which display the vsync event is for. |
Jamie Gennis | 6b7adef | 2012-04-30 12:57:11 -0700 | [diff] [blame] | 364 | * the "timestamp" parameter is the system monotonic clock timestamp in |
| 365 | * nanosecond of when the vsync event happened. |
Mathias Agopian | b08d45d | 2012-03-24 15:56:29 -0700 | [diff] [blame] | 366 | * |
| 367 | * vsync() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL. |
| 368 | * |
| 369 | * It is expected that vsync() is called from a thread of at least |
Mathias Agopian | eb67160 | 2012-04-24 15:42:37 -0700 | [diff] [blame] | 370 | * HAL_PRIORITY_URGENT_DISPLAY with as little latency as possible, |
Mathias Agopian | b08d45d | 2012-03-24 15:56:29 -0700 | [diff] [blame] | 371 | * typically less than 0.5 ms. |
| 372 | * |
Mathias Agopian | 6d3fec7 | 2012-04-10 21:22:28 -0700 | [diff] [blame] | 373 | * It is a (silent) error to have HWC_EVENT_VSYNC enabled when calling |
| 374 | * hwc_composer_device.set(..., 0, 0, 0) (screen off). The implementation |
| 375 | * can either stop or continue to process VSYNC events, but must not |
| 376 | * crash or cause other problems. |
Mathias Agopian | b08d45d | 2012-03-24 15:56:29 -0700 | [diff] [blame] | 377 | */ |
Jesse Hall | 2c13759 | 2012-08-29 10:37:37 -0700 | [diff] [blame] | 378 | void (*vsync)(const struct hwc_procs* procs, int disp, int64_t timestamp); |
| 379 | |
| 380 | /* |
| 381 | * (*hotplug)() is called by the h/w composer HAL when a display is |
| 382 | * connected or disconnected. The PRIMARY display is always connected and |
| 383 | * the hotplug callback should not be called for it. |
| 384 | * |
| 385 | * The disp parameter indicates which display type this event is for. |
| 386 | * The connected parameter indicates whether the display has just been |
| 387 | * connected (1) or disconnected (0). |
| 388 | * |
| 389 | * The hotplug() callback may call back into the h/w composer on the same |
| 390 | * thread to query refresh rate and dpi for the display. Additionally, |
| 391 | * other threads may be calling into the h/w composer while the callback |
| 392 | * is in progress. |
| 393 | * |
Jesse Hall | d91697a | 2012-09-19 22:53:30 -0700 | [diff] [blame] | 394 | * The h/w composer must serialize calls to the hotplug callback; only |
| 395 | * one thread may call it at a time. |
| 396 | * |
Jesse Hall | 2c13759 | 2012-08-29 10:37:37 -0700 | [diff] [blame] | 397 | * This callback will be NULL if the h/w composer is using |
| 398 | * HWC_DEVICE_API_VERSION_1_0. |
| 399 | */ |
| 400 | void (*hotplug)(const struct hwc_procs* procs, int disp, int connected); |
| 401 | |
Mathias Agopian | d6afef6 | 2011-08-01 16:34:42 -0700 | [diff] [blame] | 402 | } hwc_procs_t; |
| 403 | |
| 404 | |
| 405 | /*****************************************************************************/ |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 406 | |
| 407 | typedef struct hwc_module { |
| 408 | struct hw_module_t common; |
| 409 | } hwc_module_t; |
| 410 | |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 411 | typedef struct hwc_composer_device_1 { |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 412 | struct hw_device_t common; |
| 413 | |
| 414 | /* |
| 415 | * (*prepare)() is called for each frame before composition and is used by |
| 416 | * SurfaceFlinger to determine what composition steps the HWC can handle. |
| 417 | * |
| 418 | * (*prepare)() can be called more than once, the last call prevails. |
| 419 | * |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 420 | * The HWC responds by setting the compositionType field in each layer to |
| 421 | * either HWC_FRAMEBUFFER or HWC_OVERLAY. In the former case, the |
| 422 | * composition for the layer is handled by SurfaceFlinger with OpenGL ES, |
| 423 | * in the later case, the HWC will have to handle the layer's composition. |
Mathias Agopian | 48697f6 | 2012-11-20 15:23:25 -0800 | [diff] [blame] | 424 | * compositionType and hints are preserved between (*prepare)() calles |
| 425 | * unless the HWC_GEOMETRY_CHANGED flag is set. |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 426 | * |
| 427 | * (*prepare)() is called with HWC_GEOMETRY_CHANGED to indicate that the |
| 428 | * list's geometry has changed, that is, when more than just the buffer's |
| 429 | * handles have been updated. Typically this happens (but is not limited to) |
Mathias Agopian | 48697f6 | 2012-11-20 15:23:25 -0800 | [diff] [blame] | 430 | * when a window is added, removed, resized or moved. In this case |
| 431 | * compositionType and hints are reset to their default value. |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 432 | * |
Jesse Hall | 43b51d9 | 2012-08-22 11:42:57 -0700 | [diff] [blame] | 433 | * For HWC 1.0, numDisplays will always be one, and displays[0] will be |
| 434 | * non-NULL. |
| 435 | * |
| 436 | * For HWC 1.1, numDisplays will always be HWC_NUM_DISPLAY_TYPES. Entries |
| 437 | * for unsupported or disabled/disconnected display types will be NULL. |
| 438 | * |
Jesse Hall | 380f45d | 2013-03-20 10:11:10 -0700 | [diff] [blame] | 439 | * In a future version, numDisplays may be larger than |
| 440 | * HWC_NUM_DISPLAY_TYPES. The extra entries correspond to enabled virtual |
| 441 | * displays, and will be non-NULL. |
Jesse Hall | ac3f7e1 | 2012-07-31 15:18:32 -0700 | [diff] [blame] | 442 | * |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 443 | * returns: 0 on success. An negative error code on error. If an error is |
| 444 | * returned, SurfaceFlinger will assume that none of the layer will be |
| 445 | * handled by the HWC. |
| 446 | */ |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 447 | int (*prepare)(struct hwc_composer_device_1 *dev, |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 448 | size_t numDisplays, hwc_display_contents_1_t** displays); |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 449 | |
| 450 | /* |
| 451 | * (*set)() is used in place of eglSwapBuffers(), and assumes the same |
| 452 | * functionality, except it also commits the work list atomically with |
| 453 | * the actual eglSwapBuffers(). |
| 454 | * |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 455 | * The layer lists are guaranteed to be the same as the ones returned from |
| 456 | * the last call to (*prepare)(). |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 457 | * |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 458 | * When this call returns the caller assumes that the displays will be |
| 459 | * updated in the near future with the content of their work lists, without |
| 460 | * artifacts during the transition from the previous frame. |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 461 | * |
Jesse Hall | ac3f7e1 | 2012-07-31 15:18:32 -0700 | [diff] [blame] | 462 | * A display with zero layers indicates that the entire composition has |
| 463 | * been handled by SurfaceFlinger with OpenGL ES. In this case, (*set)() |
| 464 | * behaves just like eglSwapBuffers(). |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 465 | * |
Jesse Hall | 43b51d9 | 2012-08-22 11:42:57 -0700 | [diff] [blame] | 466 | * For HWC 1.0, numDisplays will always be one, and displays[0] will be |
| 467 | * non-NULL. |
| 468 | * |
| 469 | * For HWC 1.1, numDisplays will always be HWC_NUM_DISPLAY_TYPES. Entries |
| 470 | * for unsupported or disabled/disconnected display types will be NULL. |
| 471 | * |
Jesse Hall | 380f45d | 2013-03-20 10:11:10 -0700 | [diff] [blame] | 472 | * In a future version, numDisplays may be larger than |
| 473 | * HWC_NUM_DISPLAY_TYPES. The extra entries correspond to enabled virtual |
| 474 | * displays, and will be non-NULL. |
Mathias Agopian | 71212e3 | 2011-11-21 17:35:15 -0800 | [diff] [blame] | 475 | * |
Jamie Gennis | c754518 | 2012-10-08 19:23:56 -0700 | [diff] [blame] | 476 | * IMPORTANT NOTE: There is an implicit layer containing opaque black |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 477 | * pixels behind all the layers in the list. It is the responsibility of |
| 478 | * the hwcomposer module to make sure black pixels are output (or blended |
| 479 | * from). |
Mathias Agopian | fb41036 | 2011-11-15 21:27:52 -0800 | [diff] [blame] | 480 | * |
Jamie Gennis | c754518 | 2012-10-08 19:23:56 -0700 | [diff] [blame] | 481 | * IMPORTANT NOTE: In the event of an error this call *MUST* still cause |
| 482 | * any fences returned in the previous call to set to eventually become |
| 483 | * signaled. The caller may have already issued wait commands on these |
| 484 | * fences, and having set return without causing those fences to signal |
| 485 | * will likely result in a deadlock. |
| 486 | * |
| 487 | * returns: 0 on success. A negative error code on error: |
| 488 | * HWC_EGL_ERROR: eglGetError() will provide the proper error code (only |
| 489 | * allowed prior to HWComposer 1.1) |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 490 | * Another code for non EGL errors. |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 491 | */ |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 492 | int (*set)(struct hwc_composer_device_1 *dev, |
Jesse Hall | f9d6cd7 | 2012-07-31 14:29:00 -0700 | [diff] [blame] | 493 | size_t numDisplays, hwc_display_contents_1_t** displays); |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 494 | |
Erik Gilling | 158549c | 2010-12-01 16:34:08 -0800 | [diff] [blame] | 495 | /* |
Jesse Hall | 0a0a416 | 2012-08-21 12:06:28 -0700 | [diff] [blame] | 496 | * eventControl(..., event, enabled) |
| 497 | * Enables or disables h/w composer events for a display. |
Erik Gilling | 158549c | 2010-12-01 16:34:08 -0800 | [diff] [blame] | 498 | * |
Jesse Hall | 0a0a416 | 2012-08-21 12:06:28 -0700 | [diff] [blame] | 499 | * eventControl can be called from any thread and takes effect |
| 500 | * immediately. |
| 501 | * |
| 502 | * Supported events are: |
| 503 | * HWC_EVENT_VSYNC |
| 504 | * |
| 505 | * returns -EINVAL if the "event" parameter is not one of the value above |
| 506 | * or if the "enabled" parameter is not 0 or 1. |
Erik Gilling | 158549c | 2010-12-01 16:34:08 -0800 | [diff] [blame] | 507 | */ |
Jesse Hall | 2c13759 | 2012-08-29 10:37:37 -0700 | [diff] [blame] | 508 | int (*eventControl)(struct hwc_composer_device_1* dev, int disp, |
Jesse Hall | 0a0a416 | 2012-08-21 12:06:28 -0700 | [diff] [blame] | 509 | int event, int enabled); |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 510 | |
Mathias Agopian | d6afef6 | 2011-08-01 16:34:42 -0700 | [diff] [blame] | 511 | /* |
Jesse Hall | 0a0a416 | 2012-08-21 12:06:28 -0700 | [diff] [blame] | 512 | * blank(..., blank) |
| 513 | * Blanks or unblanks a display's screen. |
Mathias Agopian | d6afef6 | 2011-08-01 16:34:42 -0700 | [diff] [blame] | 514 | * |
Jesse Hall | 0a0a416 | 2012-08-21 12:06:28 -0700 | [diff] [blame] | 515 | * Turns the screen off when blank is nonzero, on when blank is zero. |
| 516 | * Multiple sequential calls with the same blank value must be supported. |
| 517 | * The screen state transition must be be complete when the function |
| 518 | * returns. |
Mathias Agopian | d6afef6 | 2011-08-01 16:34:42 -0700 | [diff] [blame] | 519 | * |
Jesse Hall | 0a0a416 | 2012-08-21 12:06:28 -0700 | [diff] [blame] | 520 | * returns 0 on success, negative on error. |
Mathias Agopian | d6afef6 | 2011-08-01 16:34:42 -0700 | [diff] [blame] | 521 | */ |
Jesse Hall | 2c13759 | 2012-08-29 10:37:37 -0700 | [diff] [blame] | 522 | int (*blank)(struct hwc_composer_device_1* dev, int disp, int blank); |
Mathias Agopian | d6afef6 | 2011-08-01 16:34:42 -0700 | [diff] [blame] | 523 | |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 524 | /* |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 525 | * Used to retrieve information about the h/w composer |
| 526 | * |
| 527 | * Returns 0 on success or -errno on error. |
| 528 | */ |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 529 | int (*query)(struct hwc_composer_device_1* dev, int what, int* value); |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 530 | |
Mathias Agopian | b08d45d | 2012-03-24 15:56:29 -0700 | [diff] [blame] | 531 | /* |
Jesse Hall | 0a0a416 | 2012-08-21 12:06:28 -0700 | [diff] [blame] | 532 | * (*registerProcs)() registers callbacks that the h/w composer HAL can |
| 533 | * later use. It will be called immediately after the composer device is |
| 534 | * opened with non-NULL procs. It is FORBIDDEN to call any of the callbacks |
| 535 | * from within registerProcs(). registerProcs() must save the hwc_procs_t |
| 536 | * pointer which is needed when calling a registered callback. |
| 537 | */ |
| 538 | void (*registerProcs)(struct hwc_composer_device_1* dev, |
| 539 | hwc_procs_t const* procs); |
| 540 | |
| 541 | /* |
| 542 | * This field is OPTIONAL and can be NULL. |
| 543 | * |
| 544 | * If non NULL it will be called by SurfaceFlinger on dumpsys |
| 545 | */ |
| 546 | void (*dump)(struct hwc_composer_device_1* dev, char *buff, int buff_len); |
| 547 | |
| 548 | /* |
Jesse Hall | 2c13759 | 2012-08-29 10:37:37 -0700 | [diff] [blame] | 549 | * (*getDisplayConfigs)() returns handles for the configurations available |
| 550 | * on the connected display. These handles must remain valid as long as the |
| 551 | * display is connected. |
| 552 | * |
| 553 | * Configuration handles are written to configs. The number of entries |
| 554 | * allocated by the caller is passed in *numConfigs; getDisplayConfigs must |
| 555 | * not try to write more than this number of config handles. On return, the |
| 556 | * total number of configurations available for the display is returned in |
| 557 | * *numConfigs. If *numConfigs is zero on entry, then configs may be NULL. |
| 558 | * |
| 559 | * HWC_DEVICE_API_VERSION_1_1 does not provide a way to choose a config. |
| 560 | * For displays that support multiple configurations, the h/w composer |
| 561 | * implementation should choose one and report it as the first config in |
| 562 | * the list. Reporting the not-chosen configs is not required. |
| 563 | * |
Jesse Hall | d91697a | 2012-09-19 22:53:30 -0700 | [diff] [blame] | 564 | * Returns 0 on success or -errno on error. If disp is a hotpluggable |
| 565 | * display type and no display is connected, an error should be returned. |
Jesse Hall | 2c13759 | 2012-08-29 10:37:37 -0700 | [diff] [blame] | 566 | * |
| 567 | * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_1 and later. |
| 568 | * It should be NULL for previous versions. |
| 569 | */ |
| 570 | int (*getDisplayConfigs)(struct hwc_composer_device_1* dev, int disp, |
| 571 | uint32_t* configs, size_t* numConfigs); |
| 572 | |
| 573 | /* |
| 574 | * (*getDisplayAttributes)() returns attributes for a specific config of a |
| 575 | * connected display. The config parameter is one of the config handles |
| 576 | * returned by getDisplayConfigs. |
| 577 | * |
| 578 | * The list of attributes to return is provided in the attributes |
| 579 | * parameter, terminated by HWC_DISPLAY_NO_ATTRIBUTE. The value for each |
| 580 | * requested attribute is written in order to the values array. The |
| 581 | * HWC_DISPLAY_NO_ATTRIBUTE attribute does not have a value, so the values |
| 582 | * array will have one less value than the attributes array. |
| 583 | * |
| 584 | * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_1 and later. |
| 585 | * It should be NULL for previous versions. |
Jesse Hall | d91697a | 2012-09-19 22:53:30 -0700 | [diff] [blame] | 586 | * |
| 587 | * If disp is a hotpluggable display type and no display is connected, |
| 588 | * or if config is not a valid configuration for the display, a negative |
| 589 | * value should be returned. |
Jesse Hall | 2c13759 | 2012-08-29 10:37:37 -0700 | [diff] [blame] | 590 | */ |
Jesse Hall | d91697a | 2012-09-19 22:53:30 -0700 | [diff] [blame] | 591 | int (*getDisplayAttributes)(struct hwc_composer_device_1* dev, int disp, |
Jesse Hall | 2c13759 | 2012-08-29 10:37:37 -0700 | [diff] [blame] | 592 | uint32_t config, const uint32_t* attributes, int32_t* values); |
| 593 | |
| 594 | /* |
Mathias Agopian | b08d45d | 2012-03-24 15:56:29 -0700 | [diff] [blame] | 595 | * Reserved for future use. Must be NULL. |
| 596 | */ |
| 597 | void* reserved_proc[4]; |
Mathias Agopian | eb8fb50 | 2012-02-03 15:54:11 -0800 | [diff] [blame] | 598 | |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 599 | } hwc_composer_device_1_t; |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 600 | |
| 601 | /** convenience API for opening and closing a device */ |
| 602 | |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 603 | static inline int hwc_open_1(const struct hw_module_t* module, |
| 604 | hwc_composer_device_1_t** device) { |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 605 | return module->methods->open(module, |
| 606 | HWC_HARDWARE_COMPOSER, (struct hw_device_t**)device); |
| 607 | } |
| 608 | |
Jesse Hall | d479ad2 | 2012-06-05 23:41:37 -0700 | [diff] [blame] | 609 | static inline int hwc_close_1(hwc_composer_device_1_t* device) { |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 610 | return device->common.close(&device->common); |
| 611 | } |
| 612 | |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 613 | /*****************************************************************************/ |
| 614 | |
Mathias Agopian | 5d3de30 | 2010-08-05 15:24:35 -0700 | [diff] [blame] | 615 | __END_DECLS |
| 616 | |
| 617 | #endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H */ |