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; |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 60 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 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, |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 132 | NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP, |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | /* parameter for NATIVE_WINDOW_[DIS]CONNECT */ |
| 136 | enum { |
| 137 | NATIVE_WINDOW_API_EGL = 1 |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
Mathias Agopian | e96aa3e | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 140 | /* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */ |
| 141 | enum { |
| 142 | /* flip source image horizontally */ |
| 143 | NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H , |
| 144 | /* flip source image vertically */ |
| 145 | NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, |
| 146 | /* rotate source image 90 degrees clock-wise */ |
| 147 | NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, |
| 148 | /* rotate source image 180 degrees */ |
| 149 | NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, |
| 150 | /* rotate source image 270 degrees clock-wise */ |
| 151 | NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, |
| 152 | }; |
| 153 | |
Jamie Gennis | c4ca7c5 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 154 | /* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */ |
| 155 | enum { |
| 156 | NATIVE_WINDOW_FRAMEBUFFER, // FramebufferNativeWindow |
| 157 | NATIVE_WINDOW_SURFACE, // Surface |
| 158 | NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT, // SurfaceTextureClient |
| 159 | }; |
| 160 | |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 161 | /* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP |
| 162 | * |
| 163 | * Special timestamp value to indicate that timestamps should be auto-generated |
| 164 | * by the native window when queueBuffer is called. This is equal to INT64_MIN, |
| 165 | * defined directly to avoid problems with C99/C++ inclusion of stdint.h. |
| 166 | */ |
| 167 | const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1); |
| 168 | |
| 169 | struct ANativeWindow |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 170 | { |
| 171 | #ifdef __cplusplus |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 172 | ANativeWindow() |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 173 | : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0) |
| 174 | { |
| 175 | common.magic = ANDROID_NATIVE_WINDOW_MAGIC; |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 176 | common.version = sizeof(ANativeWindow); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 177 | memset(common.reserved, 0, sizeof(common.reserved)); |
| 178 | } |
Jamie Gennis | 505cef3 | 2010-05-10 17:33:32 -0700 | [diff] [blame] | 179 | |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 180 | // Implement the methods that sp<ANativeWindow> expects so that it |
| 181 | // can be used to automatically refcount ANativeWindow's. |
Jamie Gennis | 505cef3 | 2010-05-10 17:33:32 -0700 | [diff] [blame] | 182 | void incStrong(const void* id) const { |
| 183 | common.incRef(const_cast<android_native_base_t*>(&common)); |
| 184 | } |
| 185 | void decStrong(const void* id) const { |
| 186 | common.decRef(const_cast<android_native_base_t*>(&common)); |
| 187 | } |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 188 | #endif |
| 189 | |
| 190 | struct android_native_base_t common; |
| 191 | |
| 192 | /* flags describing some attributes of this surface or its updater */ |
| 193 | const uint32_t flags; |
| 194 | |
| 195 | /* min swap interval supported by this updated */ |
| 196 | const int minSwapInterval; |
| 197 | |
| 198 | /* max swap interval supported by this updated */ |
| 199 | const int maxSwapInterval; |
| 200 | |
| 201 | /* horizontal and vertical resolution in DPI */ |
| 202 | const float xdpi; |
| 203 | const float ydpi; |
| 204 | |
| 205 | /* Some storage reserved for the OEM's driver. */ |
| 206 | intptr_t oem[4]; |
| 207 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * Set the swap interval for this surface. |
| 211 | * |
| 212 | * Returns 0 on success or -errno on error. |
| 213 | */ |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 214 | int (*setSwapInterval)(struct ANativeWindow* window, |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 215 | int interval); |
| 216 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 217 | /* |
| 218 | * hook called by EGL to acquire a buffer. After this call, the buffer |
| 219 | * is not locked, so its content cannot be modified. |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 220 | * this call may block if no buffers are available. |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 221 | * |
| 222 | * Returns 0 on success or -errno on error. |
| 223 | */ |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 224 | int (*dequeueBuffer)(struct ANativeWindow* window, |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 225 | struct android_native_buffer_t** buffer); |
| 226 | |
| 227 | /* |
| 228 | * hook called by EGL to lock a buffer. This MUST be called before modifying |
| 229 | * the content of a buffer. The buffer must have been acquired with |
| 230 | * dequeueBuffer first. |
| 231 | * |
| 232 | * Returns 0 on success or -errno on error. |
| 233 | */ |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 234 | int (*lockBuffer)(struct ANativeWindow* window, |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 235 | struct android_native_buffer_t* buffer); |
| 236 | /* |
| 237 | * hook called by EGL when modifications to the render buffer are done. |
| 238 | * This unlocks and post the buffer. |
| 239 | * |
| 240 | * Buffers MUST be queued in the same order than they were dequeued. |
| 241 | * |
| 242 | * Returns 0 on success or -errno on error. |
| 243 | */ |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 244 | int (*queueBuffer)(struct ANativeWindow* window, |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 245 | struct android_native_buffer_t* buffer); |
| 246 | |
Mathias Agopian | 5b5c914 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 247 | /* |
| 248 | * hook used to retrieve information about the native window. |
| 249 | * |
| 250 | * Returns 0 on success or -errno on error. |
| 251 | */ |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 252 | int (*query)(struct ANativeWindow* window, |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 253 | int what, int* value); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 254 | |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 255 | /* |
| 256 | * hook used to perform various operations on the surface. |
| 257 | * (*perform)() is a generic mechanism to add functionality to |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 258 | * ANativeWindow while keeping backward binary compatibility. |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 259 | * |
| 260 | * This hook should not be called directly, instead use the helper functions |
| 261 | * defined below. |
| 262 | * |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 263 | * (*perform)() returns -ENOENT if the 'what' parameter is not supported |
| 264 | * by the surface's implementation. |
| 265 | * |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 266 | * The valid operations are: |
| 267 | * NATIVE_WINDOW_SET_USAGE |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 268 | * NATIVE_WINDOW_CONNECT |
| 269 | * NATIVE_WINDOW_DISCONNECT |
Mathias Agopian | 16a86ee | 2010-04-15 18:48:26 -0700 | [diff] [blame] | 270 | * NATIVE_WINDOW_SET_CROP |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 271 | * NATIVE_WINDOW_SET_BUFFER_COUNT |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 272 | * NATIVE_WINDOW_SET_BUFFERS_GEOMETRY |
Mathias Agopian | e96aa3e | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 273 | * NATIVE_WINDOW_SET_BUFFERS_TRANSFORM |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 274 | * NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP |
| 275 | * |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 276 | */ |
| 277 | |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 278 | int (*perform)(struct ANativeWindow* window, |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 279 | int operation, ... ); |
| 280 | |
Mathias Agopian | 8ddd2c7 | 2010-10-01 16:22:41 -0700 | [diff] [blame] | 281 | /* |
| 282 | * hook used to cancel a buffer that has been dequeued. |
| 283 | * No synchronization is performed between dequeue() and cancel(), so |
| 284 | * either external synchronization is needed, or these functions must be |
| 285 | * called from the same thread. |
| 286 | */ |
| 287 | int (*cancelBuffer)(struct ANativeWindow* window, |
| 288 | struct android_native_buffer_t* buffer); |
| 289 | |
| 290 | |
| 291 | void* reserved_proc[2]; |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 292 | }; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 293 | |
Mathias Agopian | 2c34190 | 2011-03-30 15:28:21 -0700 | [diff] [blame] | 294 | // Backwards compatibility... please switch to ANativeWindow. |
| 295 | typedef struct ANativeWindow android_native_window_t; |
| 296 | |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 297 | /* |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 298 | * native_window_set_usage(..., usage) |
| 299 | * Sets the intended usage flags for the next buffers |
| 300 | * acquired with (*lockBuffer)() and on. |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 301 | * By default (if this function is never called), a usage of |
| 302 | * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE |
| 303 | * is assumed. |
| 304 | * Calling this function will usually cause following buffers to be |
| 305 | * reallocated. |
| 306 | */ |
| 307 | |
Dima Zavin | 8db9338 | 2009-08-13 16:50:54 -0700 | [diff] [blame] | 308 | static inline int native_window_set_usage( |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 309 | ANativeWindow* window, int usage) |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 310 | { |
| 311 | return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage); |
| 312 | } |
| 313 | |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 314 | /* |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 315 | * native_window_connect(..., NATIVE_WINDOW_API_EGL) |
| 316 | * Must be called by EGL when the window is made current. |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 317 | * Returns -EINVAL if for some reason the window cannot be connected, which |
| 318 | * can happen if it's connected to some other API. |
| 319 | */ |
| 320 | static inline int native_window_connect( |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 321 | ANativeWindow* window, int api) |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 322 | { |
| 323 | return window->perform(window, NATIVE_WINDOW_CONNECT, api); |
| 324 | } |
| 325 | |
| 326 | /* |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 327 | * native_window_disconnect(..., NATIVE_WINDOW_API_EGL) |
| 328 | * Must be called by EGL when the window is made not current. |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 329 | * An error is returned if for instance the window wasn't connected in the |
| 330 | * first place. |
| 331 | */ |
| 332 | static inline int native_window_disconnect( |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 333 | ANativeWindow* window, int api) |
Mathias Agopian | f6331a4 | 2010-03-11 15:05:52 -0800 | [diff] [blame] | 334 | { |
| 335 | return window->perform(window, NATIVE_WINDOW_DISCONNECT, api); |
| 336 | } |
| 337 | |
Mathias Agopian | 16a86ee | 2010-04-15 18:48:26 -0700 | [diff] [blame] | 338 | /* |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 339 | * native_window_set_crop(..., crop) |
| 340 | * Sets which region of the next queued buffers needs to be considered. |
Mathias Agopian | 16a86ee | 2010-04-15 18:48:26 -0700 | [diff] [blame] | 341 | * A buffer's crop region is scaled to match the surface's size. |
| 342 | * |
| 343 | * The specified crop region applies to all buffers queued after it is called. |
| 344 | * |
| 345 | * if 'crop' is NULL, subsequently queued buffers won't be cropped. |
| 346 | * |
| 347 | * An error is returned if for instance the crop region is invalid, |
| 348 | * out of the buffer's bound or if the window is invalid. |
| 349 | */ |
| 350 | static inline int native_window_set_crop( |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 351 | ANativeWindow* window, |
Mathias Agopian | 16a86ee | 2010-04-15 18:48:26 -0700 | [diff] [blame] | 352 | android_native_rect_t const * crop) |
| 353 | { |
| 354 | return window->perform(window, NATIVE_WINDOW_SET_CROP, crop); |
| 355 | } |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 356 | |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 357 | /* |
| 358 | * native_window_set_buffer_count(..., count) |
| 359 | * Sets the number of buffers associated with this native window. |
| 360 | */ |
| 361 | static inline int native_window_set_buffer_count( |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 362 | ANativeWindow* window, |
Mathias Agopian | 25f0bda | 2010-05-21 14:19:50 -0700 | [diff] [blame] | 363 | size_t bufferCount) |
| 364 | { |
| 365 | return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount); |
| 366 | } |
| 367 | |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 368 | /* |
| 369 | * native_window_set_buffers_geometry(..., int w, int h, int format) |
| 370 | * All buffers dequeued after this call will have the geometry specified. |
| 371 | * In particular, all buffers will have a fixed-size, independent form the |
| 372 | * native-window size. They will be appropriately scaled to the window-size |
| 373 | * upon composition. |
| 374 | * |
| 375 | * If all parameters are 0, the normal behavior is restored. That is, |
| 376 | * dequeued buffers following this call will be sized to the window's size. |
| 377 | * |
Jamie Gennis | 2ece4cd | 2011-01-28 18:21:54 -0800 | [diff] [blame] | 378 | * Calling this function will reset the window crop to a NULL value, which |
| 379 | * disables cropping of the buffers. |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 380 | */ |
| 381 | static inline int native_window_set_buffers_geometry( |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 382 | ANativeWindow* window, |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 383 | int w, int h, int format) |
| 384 | { |
| 385 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY, |
| 386 | w, h, format); |
| 387 | } |
| 388 | |
Mathias Agopian | e96aa3e | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 389 | /* |
| 390 | * native_window_set_buffers_transform(..., int transform) |
| 391 | * All buffers queued after this call will be displayed transformed according |
| 392 | * to the transform parameter specified. |
| 393 | */ |
| 394 | static inline int native_window_set_buffers_transform( |
| 395 | ANativeWindow* window, |
| 396 | int transform) |
| 397 | { |
| 398 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM, |
| 399 | transform); |
| 400 | } |
| 401 | |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 402 | /* |
| 403 | * native_window_set_buffers_timestamp(..., int64_t timestamp) |
| 404 | * All buffers queued after this call will be associated with the timestamp |
| 405 | * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO |
| 406 | * (the default), timestamps will be generated automatically when queueBuffer is |
| 407 | * called. The timestamp is measured in nanoseconds, and must be monotonically |
| 408 | * increasing. |
| 409 | */ |
| 410 | static inline int native_window_set_buffers_timestamp( |
| 411 | ANativeWindow* window, |
| 412 | int64_t timestamp) |
| 413 | { |
| 414 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP, |
| 415 | timestamp); |
| 416 | } |
| 417 | |
Mathias Agopian | 9bd5da4 | 2009-05-05 18:29:35 -0700 | [diff] [blame] | 418 | // --------------------------------------------------------------------------- |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 419 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 420 | /* FIXME: this is legacy for pixmaps */ |
Mathias Agopian | f233915 | 2009-08-13 17:57:53 -0700 | [diff] [blame] | 421 | typedef struct egl_native_pixmap_t |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 422 | { |
| 423 | int32_t version; /* must be 32 */ |
| 424 | int32_t width; |
| 425 | int32_t height; |
| 426 | int32_t stride; |
| 427 | uint8_t* data; |
| 428 | uint8_t format; |
| 429 | uint8_t rfu[3]; |
| 430 | union { |
| 431 | uint32_t compressedFormat; |
| 432 | int32_t vstride; |
| 433 | }; |
| 434 | int32_t reserved; |
Mathias Agopian | f233915 | 2009-08-13 17:57:53 -0700 | [diff] [blame] | 435 | } egl_native_pixmap_t; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 436 | |
| 437 | /*****************************************************************************/ |
| 438 | |
| 439 | #ifdef __cplusplus |
| 440 | } |
| 441 | #endif |
| 442 | |
| 443 | |
| 444 | /*****************************************************************************/ |
| 445 | |
| 446 | #ifdef __cplusplus |
| 447 | |
| 448 | #include <utils/RefBase.h> |
| 449 | |
| 450 | namespace android { |
| 451 | |
| 452 | /* |
| 453 | * This helper class turns an EGL android_native_xxx type into a C++ |
| 454 | * reference-counted object; with proper type conversions. |
| 455 | */ |
| 456 | template <typename NATIVE_TYPE, typename TYPE, typename REF> |
| 457 | class EGLNativeBase : public NATIVE_TYPE, public REF |
| 458 | { |
Jamie Gennis | 505cef3 | 2010-05-10 17:33:32 -0700 | [diff] [blame] | 459 | public: |
| 460 | // Disambiguate between the incStrong in REF and NATIVE_TYPE |
| 461 | void incStrong(const void* id) const { |
| 462 | REF::incStrong(id); |
| 463 | } |
| 464 | void decStrong(const void* id) const { |
| 465 | REF::decStrong(id); |
| 466 | } |
| 467 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 468 | protected: |
| 469 | typedef EGLNativeBase<NATIVE_TYPE, TYPE, REF> BASE; |
| 470 | EGLNativeBase() : NATIVE_TYPE(), REF() { |
| 471 | NATIVE_TYPE::common.incRef = incRef; |
| 472 | NATIVE_TYPE::common.decRef = decRef; |
| 473 | } |
| 474 | static inline TYPE* getSelf(NATIVE_TYPE* self) { |
| 475 | return static_cast<TYPE*>(self); |
| 476 | } |
| 477 | static inline TYPE const* getSelf(NATIVE_TYPE const* self) { |
| 478 | return static_cast<TYPE const *>(self); |
| 479 | } |
| 480 | static inline TYPE* getSelf(android_native_base_t* base) { |
| 481 | return getSelf(reinterpret_cast<NATIVE_TYPE*>(base)); |
| 482 | } |
| 483 | static inline TYPE const * getSelf(android_native_base_t const* base) { |
| 484 | return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base)); |
| 485 | } |
| 486 | static void incRef(android_native_base_t* base) { |
| 487 | EGLNativeBase* self = getSelf(base); |
| 488 | self->incStrong(self); |
| 489 | } |
| 490 | static void decRef(android_native_base_t* base) { |
| 491 | EGLNativeBase* self = getSelf(base); |
| 492 | self->decStrong(self); |
| 493 | } |
| 494 | }; |
| 495 | |
| 496 | } // namespace android |
| 497 | #endif // __cplusplus |
| 498 | |
| 499 | /*****************************************************************************/ |
| 500 | |
| 501 | #endif /* ANDROID_ANDROID_NATIVES_H */ |