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