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