Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2009 The Android Open Source Project |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #ifndef ANDROID_ANDROID_NATIVES_H |
michael@0 | 18 | #define ANDROID_ANDROID_NATIVES_H |
michael@0 | 19 | |
michael@0 | 20 | #include <sys/types.h> |
michael@0 | 21 | #include <string.h> |
michael@0 | 22 | |
michael@0 | 23 | #include <hardware/gralloc.h> |
michael@0 | 24 | |
michael@0 | 25 | #include <android/native_window.h> |
michael@0 | 26 | |
michael@0 | 27 | #ifdef __cplusplus |
michael@0 | 28 | extern "C" { |
michael@0 | 29 | #endif |
michael@0 | 30 | |
michael@0 | 31 | /*****************************************************************************/ |
michael@0 | 32 | |
michael@0 | 33 | #define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \ |
michael@0 | 34 | (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d)) |
michael@0 | 35 | |
michael@0 | 36 | #define ANDROID_NATIVE_WINDOW_MAGIC \ |
michael@0 | 37 | ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d') |
michael@0 | 38 | |
michael@0 | 39 | #define ANDROID_NATIVE_BUFFER_MAGIC \ |
michael@0 | 40 | ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r') |
michael@0 | 41 | |
michael@0 | 42 | // --------------------------------------------------------------------------- |
michael@0 | 43 | |
michael@0 | 44 | struct android_native_buffer_t; |
michael@0 | 45 | |
michael@0 | 46 | typedef struct android_native_rect_t |
michael@0 | 47 | { |
michael@0 | 48 | int32_t left; |
michael@0 | 49 | int32_t top; |
michael@0 | 50 | int32_t right; |
michael@0 | 51 | int32_t bottom; |
michael@0 | 52 | } android_native_rect_t; |
michael@0 | 53 | |
michael@0 | 54 | // --------------------------------------------------------------------------- |
michael@0 | 55 | |
michael@0 | 56 | typedef struct android_native_base_t |
michael@0 | 57 | { |
michael@0 | 58 | /* a magic value defined by the actual EGL native type */ |
michael@0 | 59 | int magic; |
michael@0 | 60 | |
michael@0 | 61 | /* the sizeof() of the actual EGL native type */ |
michael@0 | 62 | int version; |
michael@0 | 63 | |
michael@0 | 64 | void* reserved[4]; |
michael@0 | 65 | |
michael@0 | 66 | /* reference-counting interface */ |
michael@0 | 67 | void (*incRef)(struct android_native_base_t* base); |
michael@0 | 68 | void (*decRef)(struct android_native_base_t* base); |
michael@0 | 69 | } android_native_base_t; |
michael@0 | 70 | |
michael@0 | 71 | // --------------------------------------------------------------------------- |
michael@0 | 72 | |
michael@0 | 73 | /* attributes queriable with query() */ |
michael@0 | 74 | enum { |
michael@0 | 75 | NATIVE_WINDOW_WIDTH = 0, |
michael@0 | 76 | NATIVE_WINDOW_HEIGHT, |
michael@0 | 77 | NATIVE_WINDOW_FORMAT, |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | /* valid operations for the (*perform)() hook */ |
michael@0 | 81 | enum { |
michael@0 | 82 | NATIVE_WINDOW_SET_USAGE = 0, |
michael@0 | 83 | NATIVE_WINDOW_CONNECT, |
michael@0 | 84 | NATIVE_WINDOW_DISCONNECT, |
michael@0 | 85 | NATIVE_WINDOW_SET_CROP, |
michael@0 | 86 | NATIVE_WINDOW_SET_BUFFER_COUNT, |
michael@0 | 87 | NATIVE_WINDOW_SET_BUFFERS_GEOMETRY, |
michael@0 | 88 | NATIVE_WINDOW_SET_BUFFERS_TRANSFORM, |
michael@0 | 89 | }; |
michael@0 | 90 | |
michael@0 | 91 | /* parameter for NATIVE_WINDOW_[DIS]CONNECT */ |
michael@0 | 92 | enum { |
michael@0 | 93 | NATIVE_WINDOW_API_EGL = 1 |
michael@0 | 94 | }; |
michael@0 | 95 | |
michael@0 | 96 | /* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */ |
michael@0 | 97 | enum { |
michael@0 | 98 | /* flip source image horizontally */ |
michael@0 | 99 | NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H , |
michael@0 | 100 | /* flip source image vertically */ |
michael@0 | 101 | NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, |
michael@0 | 102 | /* rotate source image 90 degrees clock-wise */ |
michael@0 | 103 | NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, |
michael@0 | 104 | /* rotate source image 180 degrees */ |
michael@0 | 105 | NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, |
michael@0 | 106 | /* rotate source image 270 degrees clock-wise */ |
michael@0 | 107 | NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, |
michael@0 | 108 | }; |
michael@0 | 109 | |
michael@0 | 110 | struct ANativeWindow |
michael@0 | 111 | { |
michael@0 | 112 | #ifdef __cplusplus |
michael@0 | 113 | ANativeWindow() |
michael@0 | 114 | : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0) |
michael@0 | 115 | { |
michael@0 | 116 | common.magic = ANDROID_NATIVE_WINDOW_MAGIC; |
michael@0 | 117 | common.version = sizeof(ANativeWindow); |
michael@0 | 118 | memset(common.reserved, 0, sizeof(common.reserved)); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | // Implement the methods that sp<ANativeWindow> expects so that it |
michael@0 | 122 | // can be used to automatically refcount ANativeWindow's. |
michael@0 | 123 | void incStrong(const void* id) const { |
michael@0 | 124 | common.incRef(const_cast<android_native_base_t*>(&common)); |
michael@0 | 125 | } |
michael@0 | 126 | void decStrong(const void* id) const { |
michael@0 | 127 | common.decRef(const_cast<android_native_base_t*>(&common)); |
michael@0 | 128 | } |
michael@0 | 129 | #endif |
michael@0 | 130 | |
michael@0 | 131 | struct android_native_base_t common; |
michael@0 | 132 | |
michael@0 | 133 | /* flags describing some attributes of this surface or its updater */ |
michael@0 | 134 | const uint32_t flags; |
michael@0 | 135 | |
michael@0 | 136 | /* min swap interval supported by this updated */ |
michael@0 | 137 | const int minSwapInterval; |
michael@0 | 138 | |
michael@0 | 139 | /* max swap interval supported by this updated */ |
michael@0 | 140 | const int maxSwapInterval; |
michael@0 | 141 | |
michael@0 | 142 | /* horizontal and vertical resolution in DPI */ |
michael@0 | 143 | const float xdpi; |
michael@0 | 144 | const float ydpi; |
michael@0 | 145 | |
michael@0 | 146 | /* Some storage reserved for the OEM's driver. */ |
michael@0 | 147 | intptr_t oem[4]; |
michael@0 | 148 | |
michael@0 | 149 | |
michael@0 | 150 | /* |
michael@0 | 151 | * Set the swap interval for this surface. |
michael@0 | 152 | * |
michael@0 | 153 | * Returns 0 on success or -errno on error. |
michael@0 | 154 | */ |
michael@0 | 155 | int (*setSwapInterval)(struct ANativeWindow* window, |
michael@0 | 156 | int interval); |
michael@0 | 157 | |
michael@0 | 158 | /* |
michael@0 | 159 | * hook called by EGL to acquire a buffer. After this call, the buffer |
michael@0 | 160 | * is not locked, so its content cannot be modified. |
michael@0 | 161 | * this call may block if no buffers are available. |
michael@0 | 162 | * |
michael@0 | 163 | * Returns 0 on success or -errno on error. |
michael@0 | 164 | */ |
michael@0 | 165 | int (*dequeueBuffer)(struct ANativeWindow* window, |
michael@0 | 166 | struct android_native_buffer_t** buffer); |
michael@0 | 167 | |
michael@0 | 168 | /* |
michael@0 | 169 | * hook called by EGL to lock a buffer. This MUST be called before modifying |
michael@0 | 170 | * the content of a buffer. The buffer must have been acquired with |
michael@0 | 171 | * dequeueBuffer first. |
michael@0 | 172 | * |
michael@0 | 173 | * Returns 0 on success or -errno on error. |
michael@0 | 174 | */ |
michael@0 | 175 | int (*lockBuffer)(struct ANativeWindow* window, |
michael@0 | 176 | struct android_native_buffer_t* buffer); |
michael@0 | 177 | /* |
michael@0 | 178 | * hook called by EGL when modifications to the render buffer are done. |
michael@0 | 179 | * This unlocks and post the buffer. |
michael@0 | 180 | * |
michael@0 | 181 | * Buffers MUST be queued in the same order than they were dequeued. |
michael@0 | 182 | * |
michael@0 | 183 | * Returns 0 on success or -errno on error. |
michael@0 | 184 | */ |
michael@0 | 185 | int (*queueBuffer)(struct ANativeWindow* window, |
michael@0 | 186 | struct android_native_buffer_t* buffer); |
michael@0 | 187 | |
michael@0 | 188 | /* |
michael@0 | 189 | * hook used to retrieve information about the native window. |
michael@0 | 190 | * |
michael@0 | 191 | * Returns 0 on success or -errno on error. |
michael@0 | 192 | */ |
michael@0 | 193 | int (*query)(struct ANativeWindow* window, |
michael@0 | 194 | int what, int* value); |
michael@0 | 195 | |
michael@0 | 196 | /* |
michael@0 | 197 | * hook used to perform various operations on the surface. |
michael@0 | 198 | * (*perform)() is a generic mechanism to add functionality to |
michael@0 | 199 | * ANativeWindow while keeping backward binary compatibility. |
michael@0 | 200 | * |
michael@0 | 201 | * This hook should not be called directly, instead use the helper functions |
michael@0 | 202 | * defined below. |
michael@0 | 203 | * |
michael@0 | 204 | * (*perform)() returns -ENOENT if the 'what' parameter is not supported |
michael@0 | 205 | * by the surface's implementation. |
michael@0 | 206 | * |
michael@0 | 207 | * The valid operations are: |
michael@0 | 208 | * NATIVE_WINDOW_SET_USAGE |
michael@0 | 209 | * NATIVE_WINDOW_CONNECT |
michael@0 | 210 | * NATIVE_WINDOW_DISCONNECT |
michael@0 | 211 | * NATIVE_WINDOW_SET_CROP |
michael@0 | 212 | * NATIVE_WINDOW_SET_BUFFER_COUNT |
michael@0 | 213 | * NATIVE_WINDOW_SET_BUFFERS_GEOMETRY |
michael@0 | 214 | * NATIVE_WINDOW_SET_BUFFERS_TRANSFORM |
michael@0 | 215 | * |
michael@0 | 216 | */ |
michael@0 | 217 | |
michael@0 | 218 | int (*perform)(struct ANativeWindow* window, |
michael@0 | 219 | int operation, ... ); |
michael@0 | 220 | |
michael@0 | 221 | /* |
michael@0 | 222 | * hook used to cancel a buffer that has been dequeued. |
michael@0 | 223 | * No synchronization is performed between dequeue() and cancel(), so |
michael@0 | 224 | * either external synchronization is needed, or these functions must be |
michael@0 | 225 | * called from the same thread. |
michael@0 | 226 | */ |
michael@0 | 227 | int (*cancelBuffer)(struct ANativeWindow* window, |
michael@0 | 228 | struct android_native_buffer_t* buffer); |
michael@0 | 229 | |
michael@0 | 230 | |
michael@0 | 231 | void* reserved_proc[2]; |
michael@0 | 232 | }; |
michael@0 | 233 | |
michael@0 | 234 | // Backwards compatibility... please switch to ANativeWindow. |
michael@0 | 235 | typedef struct ANativeWindow android_native_window_t; |
michael@0 | 236 | |
michael@0 | 237 | /* |
michael@0 | 238 | * native_window_set_usage(..., usage) |
michael@0 | 239 | * Sets the intended usage flags for the next buffers |
michael@0 | 240 | * acquired with (*lockBuffer)() and on. |
michael@0 | 241 | * By default (if this function is never called), a usage of |
michael@0 | 242 | * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE |
michael@0 | 243 | * is assumed. |
michael@0 | 244 | * Calling this function will usually cause following buffers to be |
michael@0 | 245 | * reallocated. |
michael@0 | 246 | */ |
michael@0 | 247 | |
michael@0 | 248 | static inline int native_window_set_usage( |
michael@0 | 249 | ANativeWindow* window, int usage) |
michael@0 | 250 | { |
michael@0 | 251 | return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage); |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | /* |
michael@0 | 255 | * native_window_connect(..., NATIVE_WINDOW_API_EGL) |
michael@0 | 256 | * Must be called by EGL when the window is made current. |
michael@0 | 257 | * Returns -EINVAL if for some reason the window cannot be connected, which |
michael@0 | 258 | * can happen if it's connected to some other API. |
michael@0 | 259 | */ |
michael@0 | 260 | static inline int native_window_connect( |
michael@0 | 261 | ANativeWindow* window, int api) |
michael@0 | 262 | { |
michael@0 | 263 | return window->perform(window, NATIVE_WINDOW_CONNECT, api); |
michael@0 | 264 | } |
michael@0 | 265 | |
michael@0 | 266 | /* |
michael@0 | 267 | * native_window_disconnect(..., NATIVE_WINDOW_API_EGL) |
michael@0 | 268 | * Must be called by EGL when the window is made not current. |
michael@0 | 269 | * An error is returned if for instance the window wasn't connected in the |
michael@0 | 270 | * first place. |
michael@0 | 271 | */ |
michael@0 | 272 | static inline int native_window_disconnect( |
michael@0 | 273 | ANativeWindow* window, int api) |
michael@0 | 274 | { |
michael@0 | 275 | return window->perform(window, NATIVE_WINDOW_DISCONNECT, api); |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | /* |
michael@0 | 279 | * native_window_set_crop(..., crop) |
michael@0 | 280 | * Sets which region of the next queued buffers needs to be considered. |
michael@0 | 281 | * A buffer's crop region is scaled to match the surface's size. |
michael@0 | 282 | * |
michael@0 | 283 | * The specified crop region applies to all buffers queued after it is called. |
michael@0 | 284 | * |
michael@0 | 285 | * if 'crop' is NULL, subsequently queued buffers won't be cropped. |
michael@0 | 286 | * |
michael@0 | 287 | * An error is returned if for instance the crop region is invalid, |
michael@0 | 288 | * out of the buffer's bound or if the window is invalid. |
michael@0 | 289 | */ |
michael@0 | 290 | static inline int native_window_set_crop( |
michael@0 | 291 | ANativeWindow* window, |
michael@0 | 292 | android_native_rect_t const * crop) |
michael@0 | 293 | { |
michael@0 | 294 | return window->perform(window, NATIVE_WINDOW_SET_CROP, crop); |
michael@0 | 295 | } |
michael@0 | 296 | |
michael@0 | 297 | /* |
michael@0 | 298 | * native_window_set_buffer_count(..., count) |
michael@0 | 299 | * Sets the number of buffers associated with this native window. |
michael@0 | 300 | */ |
michael@0 | 301 | static inline int native_window_set_buffer_count( |
michael@0 | 302 | ANativeWindow* window, |
michael@0 | 303 | size_t bufferCount) |
michael@0 | 304 | { |
michael@0 | 305 | return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount); |
michael@0 | 306 | } |
michael@0 | 307 | |
michael@0 | 308 | /* |
michael@0 | 309 | * native_window_set_buffers_geometry(..., int w, int h, int format) |
michael@0 | 310 | * All buffers dequeued after this call will have the geometry specified. |
michael@0 | 311 | * In particular, all buffers will have a fixed-size, independent form the |
michael@0 | 312 | * native-window size. They will be appropriately scaled to the window-size |
michael@0 | 313 | * upon composition. |
michael@0 | 314 | * |
michael@0 | 315 | * If all parameters are 0, the normal behavior is restored. That is, |
michael@0 | 316 | * dequeued buffers following this call will be sized to the window's size. |
michael@0 | 317 | * |
michael@0 | 318 | */ |
michael@0 | 319 | static inline int native_window_set_buffers_geometry( |
michael@0 | 320 | ANativeWindow* window, |
michael@0 | 321 | int w, int h, int format) |
michael@0 | 322 | { |
michael@0 | 323 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY, |
michael@0 | 324 | w, h, format); |
michael@0 | 325 | } |
michael@0 | 326 | |
michael@0 | 327 | /* |
michael@0 | 328 | * native_window_set_buffers_transform(..., int transform) |
michael@0 | 329 | * All buffers queued after this call will be displayed transformed according |
michael@0 | 330 | * to the transform parameter specified. |
michael@0 | 331 | */ |
michael@0 | 332 | static inline int native_window_set_buffers_transform( |
michael@0 | 333 | ANativeWindow* window, |
michael@0 | 334 | int transform) |
michael@0 | 335 | { |
michael@0 | 336 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM, |
michael@0 | 337 | transform); |
michael@0 | 338 | } |
michael@0 | 339 | |
michael@0 | 340 | // --------------------------------------------------------------------------- |
michael@0 | 341 | |
michael@0 | 342 | /* FIXME: this is legacy for pixmaps */ |
michael@0 | 343 | typedef struct egl_native_pixmap_t |
michael@0 | 344 | { |
michael@0 | 345 | int32_t version; /* must be 32 */ |
michael@0 | 346 | int32_t width; |
michael@0 | 347 | int32_t height; |
michael@0 | 348 | int32_t stride; |
michael@0 | 349 | uint8_t* data; |
michael@0 | 350 | uint8_t format; |
michael@0 | 351 | uint8_t rfu[3]; |
michael@0 | 352 | union { |
michael@0 | 353 | uint32_t compressedFormat; |
michael@0 | 354 | int32_t vstride; |
michael@0 | 355 | }; |
michael@0 | 356 | int32_t reserved; |
michael@0 | 357 | } egl_native_pixmap_t; |
michael@0 | 358 | |
michael@0 | 359 | /*****************************************************************************/ |
michael@0 | 360 | |
michael@0 | 361 | #ifdef __cplusplus |
michael@0 | 362 | } |
michael@0 | 363 | #endif |
michael@0 | 364 | |
michael@0 | 365 | |
michael@0 | 366 | /*****************************************************************************/ |
michael@0 | 367 | |
michael@0 | 368 | #ifdef __cplusplus |
michael@0 | 369 | |
michael@0 | 370 | #include <utils/RefBase.h> |
michael@0 | 371 | |
michael@0 | 372 | namespace android { |
michael@0 | 373 | |
michael@0 | 374 | /* |
michael@0 | 375 | * This helper class turns an EGL android_native_xxx type into a C++ |
michael@0 | 376 | * reference-counted object; with proper type conversions. |
michael@0 | 377 | */ |
michael@0 | 378 | template <typename NATIVE_TYPE, typename TYPE, typename REF> |
michael@0 | 379 | class EGLNativeBase : public NATIVE_TYPE, public REF |
michael@0 | 380 | { |
michael@0 | 381 | public: |
michael@0 | 382 | // Disambiguate between the incStrong in REF and NATIVE_TYPE |
michael@0 | 383 | void incStrong(const void* id) const { |
michael@0 | 384 | REF::incStrong(id); |
michael@0 | 385 | } |
michael@0 | 386 | void decStrong(const void* id) const { |
michael@0 | 387 | REF::decStrong(id); |
michael@0 | 388 | } |
michael@0 | 389 | |
michael@0 | 390 | protected: |
michael@0 | 391 | typedef EGLNativeBase<NATIVE_TYPE, TYPE, REF> BASE; |
michael@0 | 392 | EGLNativeBase() : NATIVE_TYPE(), REF() { |
michael@0 | 393 | NATIVE_TYPE::common.incRef = incRef; |
michael@0 | 394 | NATIVE_TYPE::common.decRef = decRef; |
michael@0 | 395 | } |
michael@0 | 396 | static inline TYPE* getSelf(NATIVE_TYPE* self) { |
michael@0 | 397 | return static_cast<TYPE*>(self); |
michael@0 | 398 | } |
michael@0 | 399 | static inline TYPE const* getSelf(NATIVE_TYPE const* self) { |
michael@0 | 400 | return static_cast<TYPE const *>(self); |
michael@0 | 401 | } |
michael@0 | 402 | static inline TYPE* getSelf(android_native_base_t* base) { |
michael@0 | 403 | return getSelf(reinterpret_cast<NATIVE_TYPE*>(base)); |
michael@0 | 404 | } |
michael@0 | 405 | static inline TYPE const * getSelf(android_native_base_t const* base) { |
michael@0 | 406 | return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base)); |
michael@0 | 407 | } |
michael@0 | 408 | static void incRef(android_native_base_t* base) { |
michael@0 | 409 | EGLNativeBase* self = getSelf(base); |
michael@0 | 410 | self->incStrong(self); |
michael@0 | 411 | } |
michael@0 | 412 | static void decRef(android_native_base_t* base) { |
michael@0 | 413 | EGLNativeBase* self = getSelf(base); |
michael@0 | 414 | self->decStrong(self); |
michael@0 | 415 | } |
michael@0 | 416 | }; |
michael@0 | 417 | |
michael@0 | 418 | } // namespace android |
michael@0 | 419 | #endif // __cplusplus |
michael@0 | 420 | |
michael@0 | 421 | /*****************************************************************************/ |
michael@0 | 422 | |
michael@0 | 423 | #endif /* ANDROID_ANDROID_NATIVES_H */ |