Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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_ANDROID_NATIVES_H |
| 18 | #define ANDROID_ANDROID_NATIVES_H |
| 19 | |
| 20 | #include <sys/types.h> |
| 21 | #include <string.h> |
| 22 | |
| 23 | #include <hardware/gralloc.h> |
| 24 | |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 25 | #include <android/native_window.h> |
| 26 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
| 29 | #endif |
| 30 | |
| 31 | /*****************************************************************************/ |
| 32 | |
| 33 | #define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \ |
| 34 | (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d)) |
| 35 | |
| 36 | #define ANDROID_NATIVE_WINDOW_MAGIC \ |
| 37 | ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d') |
| 38 | |
| 39 | #define ANDROID_NATIVE_BUFFER_MAGIC \ |
| 40 | ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r') |
| 41 | |
| 42 | // --------------------------------------------------------------------------- |
| 43 | |
| 44 | struct android_native_buffer_t; |
| 45 | |
Mathias Agopian | 16a86ee | 2010-04-15 18:48:26 -0700 | [diff] [blame] | 46 | typedef struct android_native_rect_t |
| 47 | { |
| 48 | int32_t left; |
| 49 | int32_t top; |
| 50 | int32_t right; |
| 51 | int32_t bottom; |
| 52 | } android_native_rect_t; |
| 53 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 54 | // --------------------------------------------------------------------------- |
| 55 | |
Mathias Agopian | f233915 | 2009-08-13 17:57:53 -0700 | [diff] [blame] | 56 | typedef struct android_native_base_t |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 57 | { |
| 58 | /* a magic value defined by the actual EGL native type */ |
| 59 | int magic; |
| 60 | |
| 61 | /* the sizeof() of the actual EGL native type */ |
| 62 | int version; |
| 63 | |
| 64 | void* reserved[4]; |
| 65 | |
| 66 | /* reference-counting interface */ |
Mathias Agopian | 2b89548 | 2009-08-17 12:33:20 -0700 | [diff] [blame] | 67 | void (*incRef)(struct android_native_base_t* base); |
| 68 | void (*decRef)(struct android_native_base_t* base); |
Mathias Agopian | f233915 | 2009-08-13 17:57:53 -0700 | [diff] [blame] | 69 | } android_native_base_t; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 70 | |
Mathias Agopian | 9bd5da4 | 2009-05-05 18:29:35 -0700 | [diff] [blame] | 71 | // --------------------------------------------------------------------------- |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 72 | |
Mathias Agopian | 5b5c914 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 73 | /* attributes queriable with query() */ |
| 74 | enum { |
| 75 | NATIVE_WINDOW_WIDTH = 0, |
Mathias Agopian | 16a86ee | 2010-04-15 18:48:26 -0700 | [diff] [blame] | 76 | NATIVE_WINDOW_HEIGHT, |
| 77 | NATIVE_WINDOW_FORMAT, |
Jamie Gennis | 96dcc97 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 78 | |
| 79 | /* The minimum number of buffers that must remain un-dequeued after a buffer |
| 80 | * has been queued. This value applies only if set_buffer_count was used to |
| 81 | * override the number of buffers and if a buffer has since been queued. |
| 82 | * Users of the set_buffer_count ANativeWindow method should query this |
| 83 | * value before calling set_buffer_count. If it is necessary to have N |
| 84 | * buffers simultaneously dequeued as part of the steady-state operation, |
| 85 | * and this query returns M then N+M buffers should be requested via |
| 86 | * native_window_set_buffer_count. |
| 87 | * |
| 88 | * Note that this value does NOT apply until a single buffer has been |
| 89 | * queued. In particular this means that it is possible to: |
| 90 | * |
| 91 | * 1. Query M = min undequeued buffers |
| 92 | * 2. Set the buffer count to N + M |
| 93 | * 3. Dequeue all N + M buffers |
| 94 | * 4. Cancel M buffers |
| 95 | * 5. Queue, dequeue, queue, dequeue, ad infinitum |
| 96 | */ |
| 97 | NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 98 | |
| 99 | /* Check whether queueBuffer operations on the ANativeWindow send the buffer |
| 100 | * to the window compositor. The query sets the returned 'value' argument |
| 101 | * to 1 if the ANativeWindow DOES send queued buffers directly to the window |
| 102 | * compositor and 0 if the buffers do not go directly to the window |
| 103 | * compositor. |
| 104 | * |
| 105 | * This can be used to determine whether protected buffer content should be |
| 106 | * sent to the ANativeWindow. Note, however, that a result of 1 does NOT |
| 107 | * indicate that queued buffers will be protected from applications or users |
| 108 | * capturing their contents. If that behavior is desired then some other |
| 109 | * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in |
| 110 | * conjunction with this query. |
| 111 | */ |
| 112 | NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER, |
Jamie Gennis | c4ca7c5 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 113 | |
| 114 | /* Get the concrete type of a ANativeWindow. See below for the list of |
| 115 | * possible return values. |
| 116 | * |
| 117 | * This query should not be used outside the Android framework and will |
| 118 | * likely be removed in the near future. |
| 119 | */ |
| 120 | NATIVE_WINDOW_CONCRETE_TYPE, |
Mathias Agopian | 5b5c914 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 123 | /* valid operations for the (*perform)() hook */ |
| 124 | enum { |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 125 | NATIVE_WINDOW_SET_USAGE = 0, |
Mathias Agopian | 16a86ee | 2010-04-15 18:48:26 -0700 | [diff] [blame] | 126 | NATIVE_WINDOW_CONNECT, |
| 127 | NATIVE_WINDOW_DISCONNECT, |
| 128 | NATIVE_WINDOW_SET_CROP, |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 129 | NATIVE_WINDOW_SET_BUFFER_COUNT, |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 130 | NATIVE_WINDOW_SET_BUFFERS_GEOMETRY, |
Mathias Agopian | e96aa3e | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 131 | NATIVE_WINDOW_SET_BUFFERS_TRANSFORM, |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | /* parameter for NATIVE_WINDOW_[DIS]CONNECT */ |
| 135 | enum { |
| 136 | NATIVE_WINDOW_API_EGL = 1 |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
Mathias Agopian | e96aa3e | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 139 | /* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */ |
| 140 | enum { |
| 141 | /* flip source image horizontally */ |
| 142 | NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H , |
| 143 | /* flip source image vertically */ |
| 144 | NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, |
| 145 | /* rotate source image 90 degrees clock-wise */ |
| 146 | NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, |
| 147 | /* rotate source image 180 degrees */ |
| 148 | NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, |
| 149 | /* rotate source image 270 degrees clock-wise */ |
| 150 | NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, |
| 151 | }; |
| 152 | |
Jamie Gennis | c4ca7c5 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 153 | /* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */ |
| 154 | enum { |
| 155 | NATIVE_WINDOW_FRAMEBUFFER, // FramebufferNativeWindow |
| 156 | NATIVE_WINDOW_SURFACE, // Surface |
| 157 | NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT, // SurfaceTextureClient |
| 158 | }; |
| 159 | |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 160 | struct ANativeWindow |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 161 | { |
| 162 | #ifdef __cplusplus |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 163 | ANativeWindow() |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 164 | : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0) |
| 165 | { |
| 166 | common.magic = ANDROID_NATIVE_WINDOW_MAGIC; |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 167 | common.version = sizeof(ANativeWindow); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 168 | memset(common.reserved, 0, sizeof(common.reserved)); |
| 169 | } |
Jamie Gennis | 505cef3 | 2010-05-10 17:33:32 -0700 | [diff] [blame] | 170 | |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 171 | // Implement the methods that sp<ANativeWindow> expects so that it |
| 172 | // can be used to automatically refcount ANativeWindow's. |
Jamie Gennis | 505cef3 | 2010-05-10 17:33:32 -0700 | [diff] [blame] | 173 | void incStrong(const void* id) const { |
| 174 | common.incRef(const_cast<android_native_base_t*>(&common)); |
| 175 | } |
| 176 | void decStrong(const void* id) const { |
| 177 | common.decRef(const_cast<android_native_base_t*>(&common)); |
| 178 | } |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 179 | #endif |
| 180 | |
| 181 | struct android_native_base_t common; |
| 182 | |
| 183 | /* flags describing some attributes of this surface or its updater */ |
| 184 | const uint32_t flags; |
| 185 | |
| 186 | /* min swap interval supported by this updated */ |
| 187 | const int minSwapInterval; |
| 188 | |
| 189 | /* max swap interval supported by this updated */ |
| 190 | const int maxSwapInterval; |
| 191 | |
| 192 | /* horizontal and vertical resolution in DPI */ |
| 193 | const float xdpi; |
| 194 | const float ydpi; |
| 195 | |
| 196 | /* Some storage reserved for the OEM's driver. */ |
| 197 | intptr_t oem[4]; |
| 198 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 199 | |
| 200 | /* |
| 201 | * Set the swap interval for this surface. |
| 202 | * |
| 203 | * Returns 0 on success or -errno on error. |
| 204 | */ |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 205 | int (*setSwapInterval)(struct ANativeWindow* window, |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 206 | int interval); |
| 207 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 208 | /* |
| 209 | * hook called by EGL to acquire a buffer. After this call, the buffer |
| 210 | * is not locked, so its content cannot be modified. |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 211 | * this call may block if no buffers are available. |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 212 | * |
| 213 | * Returns 0 on success or -errno on error. |
| 214 | */ |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 215 | int (*dequeueBuffer)(struct ANativeWindow* window, |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 216 | struct android_native_buffer_t** buffer); |
| 217 | |
| 218 | /* |
| 219 | * hook called by EGL to lock a buffer. This MUST be called before modifying |
| 220 | * the content of a buffer. The buffer must have been acquired with |
| 221 | * dequeueBuffer first. |
| 222 | * |
| 223 | * Returns 0 on success or -errno on error. |
| 224 | */ |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 225 | int (*lockBuffer)(struct ANativeWindow* window, |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 226 | struct android_native_buffer_t* buffer); |
| 227 | /* |
| 228 | * hook called by EGL when modifications to the render buffer are done. |
| 229 | * This unlocks and post the buffer. |
| 230 | * |
| 231 | * Buffers MUST be queued in the same order than they were dequeued. |
| 232 | * |
| 233 | * Returns 0 on success or -errno on error. |
| 234 | */ |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 235 | int (*queueBuffer)(struct ANativeWindow* window, |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 236 | struct android_native_buffer_t* buffer); |
| 237 | |
Mathias Agopian | 5b5c914 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 238 | /* |
| 239 | * hook used to retrieve information about the native window. |
| 240 | * |
| 241 | * Returns 0 on success or -errno on error. |
| 242 | */ |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 243 | int (*query)(struct ANativeWindow* window, |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 244 | int what, int* value); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 245 | |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 246 | /* |
| 247 | * hook used to perform various operations on the surface. |
| 248 | * (*perform)() is a generic mechanism to add functionality to |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 249 | * ANativeWindow while keeping backward binary compatibility. |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 250 | * |
| 251 | * This hook should not be called directly, instead use the helper functions |
| 252 | * defined below. |
| 253 | * |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 254 | * (*perform)() returns -ENOENT if the 'what' parameter is not supported |
| 255 | * by the surface's implementation. |
| 256 | * |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 257 | * The valid operations are: |
| 258 | * NATIVE_WINDOW_SET_USAGE |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 259 | * NATIVE_WINDOW_CONNECT |
| 260 | * NATIVE_WINDOW_DISCONNECT |
Mathias Agopian | 16a86ee | 2010-04-15 18:48:26 -0700 | [diff] [blame] | 261 | * NATIVE_WINDOW_SET_CROP |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 262 | * NATIVE_WINDOW_SET_BUFFER_COUNT |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 263 | * NATIVE_WINDOW_SET_BUFFERS_GEOMETRY |
Mathias Agopian | e96aa3e | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 264 | * NATIVE_WINDOW_SET_BUFFERS_TRANSFORM |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 265 | * |
| 266 | */ |
| 267 | |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 268 | int (*perform)(struct ANativeWindow* window, |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 269 | int operation, ... ); |
| 270 | |
Mathias Agopian | 8ddd2c7 | 2010-10-01 16:22:41 -0700 | [diff] [blame] | 271 | /* |
| 272 | * hook used to cancel a buffer that has been dequeued. |
| 273 | * No synchronization is performed between dequeue() and cancel(), so |
| 274 | * either external synchronization is needed, or these functions must be |
| 275 | * called from the same thread. |
| 276 | */ |
| 277 | int (*cancelBuffer)(struct ANativeWindow* window, |
| 278 | struct android_native_buffer_t* buffer); |
| 279 | |
| 280 | |
| 281 | void* reserved_proc[2]; |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 282 | }; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 283 | |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 284 | // Backwards compatibility... please switch to ANativeWindow. |
| 285 | typedef struct ANativeWindow android_native_window_t; |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 286 | |
| 287 | /* |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 288 | * native_window_set_usage(..., usage) |
| 289 | * Sets the intended usage flags for the next buffers |
| 290 | * acquired with (*lockBuffer)() and on. |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 291 | * By default (if this function is never called), a usage of |
| 292 | * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE |
| 293 | * is assumed. |
| 294 | * Calling this function will usually cause following buffers to be |
| 295 | * reallocated. |
| 296 | */ |
| 297 | |
Dima Zavin | 8db9338 | 2009-08-13 16:50:54 -0700 | [diff] [blame] | 298 | static inline int native_window_set_usage( |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 299 | ANativeWindow* window, int usage) |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 300 | { |
| 301 | return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage); |
| 302 | } |
| 303 | |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 304 | /* |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 305 | * native_window_connect(..., NATIVE_WINDOW_API_EGL) |
| 306 | * Must be called by EGL when the window is made current. |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 307 | * Returns -EINVAL if for some reason the window cannot be connected, which |
| 308 | * can happen if it's connected to some other API. |
| 309 | */ |
| 310 | static inline int native_window_connect( |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 311 | ANativeWindow* window, int api) |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 312 | { |
| 313 | return window->perform(window, NATIVE_WINDOW_CONNECT, api); |
| 314 | } |
| 315 | |
| 316 | /* |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 317 | * native_window_disconnect(..., NATIVE_WINDOW_API_EGL) |
| 318 | * Must be called by EGL when the window is made not current. |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 319 | * An error is returned if for instance the window wasn't connected in the |
| 320 | * first place. |
| 321 | */ |
| 322 | static inline int native_window_disconnect( |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 323 | ANativeWindow* window, int api) |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 324 | { |
| 325 | return window->perform(window, NATIVE_WINDOW_DISCONNECT, api); |
| 326 | } |
| 327 | |
Mathias Agopian | 16a86ee | 2010-04-15 18:48:26 -0700 | [diff] [blame] | 328 | /* |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 329 | * native_window_set_crop(..., crop) |
| 330 | * Sets which region of the next queued buffers needs to be considered. |
Mathias Agopian | 16a86ee | 2010-04-15 18:48:26 -0700 | [diff] [blame] | 331 | * A buffer's crop region is scaled to match the surface's size. |
| 332 | * |
| 333 | * The specified crop region applies to all buffers queued after it is called. |
| 334 | * |
| 335 | * if 'crop' is NULL, subsequently queued buffers won't be cropped. |
| 336 | * |
| 337 | * An error is returned if for instance the crop region is invalid, |
| 338 | * out of the buffer's bound or if the window is invalid. |
| 339 | */ |
| 340 | static inline int native_window_set_crop( |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 341 | ANativeWindow* window, |
Mathias Agopian | 16a86ee | 2010-04-15 18:48:26 -0700 | [diff] [blame] | 342 | android_native_rect_t const * crop) |
| 343 | { |
| 344 | return window->perform(window, NATIVE_WINDOW_SET_CROP, crop); |
| 345 | } |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 346 | |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 347 | /* |
| 348 | * native_window_set_buffer_count(..., count) |
| 349 | * Sets the number of buffers associated with this native window. |
| 350 | */ |
| 351 | static inline int native_window_set_buffer_count( |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 352 | ANativeWindow* window, |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 353 | size_t bufferCount) |
| 354 | { |
| 355 | return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount); |
| 356 | } |
| 357 | |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 358 | /* |
| 359 | * native_window_set_buffers_geometry(..., int w, int h, int format) |
| 360 | * All buffers dequeued after this call will have the geometry specified. |
| 361 | * In particular, all buffers will have a fixed-size, independent form the |
| 362 | * native-window size. They will be appropriately scaled to the window-size |
| 363 | * upon composition. |
| 364 | * |
| 365 | * If all parameters are 0, the normal behavior is restored. That is, |
| 366 | * dequeued buffers following this call will be sized to the window's size. |
| 367 | * |
Jamie Gennis | 2ece4cd | 2011-01-28 18:21:54 -0800 | [diff] [blame] | 368 | * Calling this function will reset the window crop to a NULL value, which |
| 369 | * disables cropping of the buffers. |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 370 | */ |
| 371 | static inline int native_window_set_buffers_geometry( |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 372 | ANativeWindow* window, |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 373 | int w, int h, int format) |
| 374 | { |
| 375 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY, |
| 376 | w, h, format); |
| 377 | } |
| 378 | |
Mathias Agopian | e96aa3e | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 379 | /* |
| 380 | * native_window_set_buffers_transform(..., int transform) |
| 381 | * All buffers queued after this call will be displayed transformed according |
| 382 | * to the transform parameter specified. |
| 383 | */ |
| 384 | static inline int native_window_set_buffers_transform( |
| 385 | ANativeWindow* window, |
| 386 | int transform) |
| 387 | { |
| 388 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM, |
| 389 | transform); |
| 390 | } |
| 391 | |
Mathias Agopian | 9bd5da4 | 2009-05-05 18:29:35 -0700 | [diff] [blame] | 392 | // --------------------------------------------------------------------------- |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 393 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 394 | /* FIXME: this is legacy for pixmaps */ |
Mathias Agopian | f233915 | 2009-08-13 17:57:53 -0700 | [diff] [blame] | 395 | typedef struct egl_native_pixmap_t |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 396 | { |
| 397 | int32_t version; /* must be 32 */ |
| 398 | int32_t width; |
| 399 | int32_t height; |
| 400 | int32_t stride; |
| 401 | uint8_t* data; |
| 402 | uint8_t format; |
| 403 | uint8_t rfu[3]; |
| 404 | union { |
| 405 | uint32_t compressedFormat; |
| 406 | int32_t vstride; |
| 407 | }; |
| 408 | int32_t reserved; |
Mathias Agopian | f233915 | 2009-08-13 17:57:53 -0700 | [diff] [blame] | 409 | } egl_native_pixmap_t; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 410 | |
| 411 | /*****************************************************************************/ |
| 412 | |
| 413 | #ifdef __cplusplus |
| 414 | } |
| 415 | #endif |
| 416 | |
| 417 | |
| 418 | /*****************************************************************************/ |
| 419 | |
| 420 | #ifdef __cplusplus |
| 421 | |
| 422 | #include <utils/RefBase.h> |
| 423 | |
| 424 | namespace android { |
| 425 | |
| 426 | /* |
| 427 | * This helper class turns an EGL android_native_xxx type into a C++ |
| 428 | * reference-counted object; with proper type conversions. |
| 429 | */ |
| 430 | template <typename NATIVE_TYPE, typename TYPE, typename REF> |
| 431 | class EGLNativeBase : public NATIVE_TYPE, public REF |
| 432 | { |
Jamie Gennis | 505cef3 | 2010-05-10 17:33:32 -0700 | [diff] [blame] | 433 | public: |
| 434 | // Disambiguate between the incStrong in REF and NATIVE_TYPE |
| 435 | void incStrong(const void* id) const { |
| 436 | REF::incStrong(id); |
| 437 | } |
| 438 | void decStrong(const void* id) const { |
| 439 | REF::decStrong(id); |
| 440 | } |
| 441 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 442 | protected: |
| 443 | typedef EGLNativeBase<NATIVE_TYPE, TYPE, REF> BASE; |
| 444 | EGLNativeBase() : NATIVE_TYPE(), REF() { |
| 445 | NATIVE_TYPE::common.incRef = incRef; |
| 446 | NATIVE_TYPE::common.decRef = decRef; |
| 447 | } |
| 448 | static inline TYPE* getSelf(NATIVE_TYPE* self) { |
| 449 | return static_cast<TYPE*>(self); |
| 450 | } |
| 451 | static inline TYPE const* getSelf(NATIVE_TYPE const* self) { |
| 452 | return static_cast<TYPE const *>(self); |
| 453 | } |
| 454 | static inline TYPE* getSelf(android_native_base_t* base) { |
| 455 | return getSelf(reinterpret_cast<NATIVE_TYPE*>(base)); |
| 456 | } |
| 457 | static inline TYPE const * getSelf(android_native_base_t const* base) { |
| 458 | return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base)); |
| 459 | } |
| 460 | static void incRef(android_native_base_t* base) { |
| 461 | EGLNativeBase* self = getSelf(base); |
| 462 | self->incStrong(self); |
| 463 | } |
| 464 | static void decRef(android_native_base_t* base) { |
| 465 | EGLNativeBase* self = getSelf(base); |
| 466 | self->decStrong(self); |
| 467 | } |
| 468 | }; |
| 469 | |
| 470 | } // namespace android |
| 471 | #endif // __cplusplus |
| 472 | |
| 473 | /*****************************************************************************/ |
| 474 | |
| 475 | #endif /* ANDROID_ANDROID_NATIVES_H */ |