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