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