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 | #ifdef __cplusplus |
michael@0 | 26 | extern "C" { |
michael@0 | 27 | #endif |
michael@0 | 28 | |
michael@0 | 29 | /*****************************************************************************/ |
michael@0 | 30 | |
michael@0 | 31 | #define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \ |
michael@0 | 32 | (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d)) |
michael@0 | 33 | |
michael@0 | 34 | #define ANDROID_NATIVE_WINDOW_MAGIC \ |
michael@0 | 35 | ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d') |
michael@0 | 36 | |
michael@0 | 37 | #define ANDROID_NATIVE_BUFFER_MAGIC \ |
michael@0 | 38 | ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r') |
michael@0 | 39 | |
michael@0 | 40 | // --------------------------------------------------------------------------- |
michael@0 | 41 | |
michael@0 | 42 | struct android_native_buffer_t; |
michael@0 | 43 | |
michael@0 | 44 | // --------------------------------------------------------------------------- |
michael@0 | 45 | |
michael@0 | 46 | typedef struct android_native_base_t |
michael@0 | 47 | { |
michael@0 | 48 | /* a magic value defined by the actual EGL native type */ |
michael@0 | 49 | int magic; |
michael@0 | 50 | |
michael@0 | 51 | /* the sizeof() of the actual EGL native type */ |
michael@0 | 52 | int version; |
michael@0 | 53 | |
michael@0 | 54 | void* reserved[4]; |
michael@0 | 55 | |
michael@0 | 56 | /* reference-counting interface */ |
michael@0 | 57 | void (*incRef)(struct android_native_base_t* base); |
michael@0 | 58 | void (*decRef)(struct android_native_base_t* base); |
michael@0 | 59 | } android_native_base_t; |
michael@0 | 60 | |
michael@0 | 61 | // --------------------------------------------------------------------------- |
michael@0 | 62 | |
michael@0 | 63 | /* attributes queriable with query() */ |
michael@0 | 64 | enum { |
michael@0 | 65 | NATIVE_WINDOW_WIDTH = 0, |
michael@0 | 66 | NATIVE_WINDOW_HEIGHT = 1, |
michael@0 | 67 | NATIVE_WINDOW_FORMAT = 2, |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | /* valid operations for the (*perform)() hook */ |
michael@0 | 71 | enum { |
michael@0 | 72 | NATIVE_WINDOW_SET_USAGE = 0, |
michael@0 | 73 | NATIVE_WINDOW_CONNECT = 1, |
michael@0 | 74 | NATIVE_WINDOW_DISCONNECT = 2 |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | /* parameter for NATIVE_WINDOW_[DIS]CONNECT */ |
michael@0 | 78 | enum { |
michael@0 | 79 | NATIVE_WINDOW_API_EGL = 1 |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | typedef struct android_native_window_t |
michael@0 | 83 | { |
michael@0 | 84 | #ifdef __cplusplus |
michael@0 | 85 | android_native_window_t() |
michael@0 | 86 | : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0) |
michael@0 | 87 | { |
michael@0 | 88 | common.magic = ANDROID_NATIVE_WINDOW_MAGIC; |
michael@0 | 89 | common.version = sizeof(android_native_window_t); |
michael@0 | 90 | memset(common.reserved, 0, sizeof(common.reserved)); |
michael@0 | 91 | } |
michael@0 | 92 | #endif |
michael@0 | 93 | |
michael@0 | 94 | struct android_native_base_t common; |
michael@0 | 95 | |
michael@0 | 96 | /* flags describing some attributes of this surface or its updater */ |
michael@0 | 97 | const uint32_t flags; |
michael@0 | 98 | |
michael@0 | 99 | /* min swap interval supported by this updated */ |
michael@0 | 100 | const int minSwapInterval; |
michael@0 | 101 | |
michael@0 | 102 | /* max swap interval supported by this updated */ |
michael@0 | 103 | const int maxSwapInterval; |
michael@0 | 104 | |
michael@0 | 105 | /* horizontal and vertical resolution in DPI */ |
michael@0 | 106 | const float xdpi; |
michael@0 | 107 | const float ydpi; |
michael@0 | 108 | |
michael@0 | 109 | /* Some storage reserved for the OEM's driver. */ |
michael@0 | 110 | intptr_t oem[4]; |
michael@0 | 111 | |
michael@0 | 112 | |
michael@0 | 113 | /* |
michael@0 | 114 | * Set the swap interval for this surface. |
michael@0 | 115 | * |
michael@0 | 116 | * Returns 0 on success or -errno on error. |
michael@0 | 117 | */ |
michael@0 | 118 | int (*setSwapInterval)(struct android_native_window_t* window, |
michael@0 | 119 | int interval); |
michael@0 | 120 | |
michael@0 | 121 | /* |
michael@0 | 122 | * hook called by EGL to acquire a buffer. After this call, the buffer |
michael@0 | 123 | * is not locked, so its content cannot be modified. |
michael@0 | 124 | * this call may block if no buffers are available. |
michael@0 | 125 | * |
michael@0 | 126 | * Returns 0 on success or -errno on error. |
michael@0 | 127 | */ |
michael@0 | 128 | int (*dequeueBuffer)(struct android_native_window_t* window, |
michael@0 | 129 | struct android_native_buffer_t** buffer); |
michael@0 | 130 | |
michael@0 | 131 | /* |
michael@0 | 132 | * hook called by EGL to lock a buffer. This MUST be called before modifying |
michael@0 | 133 | * the content of a buffer. The buffer must have been acquired with |
michael@0 | 134 | * dequeueBuffer first. |
michael@0 | 135 | * |
michael@0 | 136 | * Returns 0 on success or -errno on error. |
michael@0 | 137 | */ |
michael@0 | 138 | int (*lockBuffer)(struct android_native_window_t* window, |
michael@0 | 139 | struct android_native_buffer_t* buffer); |
michael@0 | 140 | /* |
michael@0 | 141 | * hook called by EGL when modifications to the render buffer are done. |
michael@0 | 142 | * This unlocks and post the buffer. |
michael@0 | 143 | * |
michael@0 | 144 | * Buffers MUST be queued in the same order than they were dequeued. |
michael@0 | 145 | * |
michael@0 | 146 | * Returns 0 on success or -errno on error. |
michael@0 | 147 | */ |
michael@0 | 148 | int (*queueBuffer)(struct android_native_window_t* window, |
michael@0 | 149 | struct android_native_buffer_t* buffer); |
michael@0 | 150 | |
michael@0 | 151 | /* |
michael@0 | 152 | * hook used to retrieve information about the native window. |
michael@0 | 153 | * |
michael@0 | 154 | * Returns 0 on success or -errno on error. |
michael@0 | 155 | */ |
michael@0 | 156 | int (*query)(struct android_native_window_t* window, |
michael@0 | 157 | int what, int* value); |
michael@0 | 158 | |
michael@0 | 159 | /* |
michael@0 | 160 | * hook used to perform various operations on the surface. |
michael@0 | 161 | * (*perform)() is a generic mechanism to add functionality to |
michael@0 | 162 | * android_native_window_t while keeping backward binary compatibility. |
michael@0 | 163 | * |
michael@0 | 164 | * This hook should not be called directly, instead use the helper functions |
michael@0 | 165 | * defined below. |
michael@0 | 166 | * |
michael@0 | 167 | * (*perform)() returns -ENOENT if the 'what' parameter is not supported |
michael@0 | 168 | * by the surface's implementation. |
michael@0 | 169 | * |
michael@0 | 170 | * The valid operations are: |
michael@0 | 171 | * NATIVE_WINDOW_SET_USAGE |
michael@0 | 172 | * NATIVE_WINDOW_CONNECT |
michael@0 | 173 | * NATIVE_WINDOW_DISCONNECT |
michael@0 | 174 | * |
michael@0 | 175 | */ |
michael@0 | 176 | |
michael@0 | 177 | int (*perform)(struct android_native_window_t* window, |
michael@0 | 178 | int operation, ... ); |
michael@0 | 179 | |
michael@0 | 180 | void* reserved_proc[3]; |
michael@0 | 181 | } android_native_window_t; |
michael@0 | 182 | |
michael@0 | 183 | |
michael@0 | 184 | /* |
michael@0 | 185 | * native_window_set_usage() sets the intended usage flags for the next |
michael@0 | 186 | * buffers acquired with (*lockBuffer)() and on. |
michael@0 | 187 | * By default (if this function is never called), a usage of |
michael@0 | 188 | * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE |
michael@0 | 189 | * is assumed. |
michael@0 | 190 | * Calling this function will usually cause following buffers to be |
michael@0 | 191 | * reallocated. |
michael@0 | 192 | */ |
michael@0 | 193 | |
michael@0 | 194 | static inline int native_window_set_usage( |
michael@0 | 195 | android_native_window_t* window, int usage) |
michael@0 | 196 | { |
michael@0 | 197 | return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | /* |
michael@0 | 201 | * native_window_connect(..., NATIVE_WINDOW_API_EGL) must be called |
michael@0 | 202 | * by EGL when the window is made current. |
michael@0 | 203 | * Returns -EINVAL if for some reason the window cannot be connected, which |
michael@0 | 204 | * can happen if it's connected to some other API. |
michael@0 | 205 | */ |
michael@0 | 206 | static inline int native_window_connect( |
michael@0 | 207 | android_native_window_t* window, int api) |
michael@0 | 208 | { |
michael@0 | 209 | return window->perform(window, NATIVE_WINDOW_CONNECT, api); |
michael@0 | 210 | } |
michael@0 | 211 | |
michael@0 | 212 | /* |
michael@0 | 213 | * native_window_disconnect(..., NATIVE_WINDOW_API_EGL) must be called |
michael@0 | 214 | * by EGL when the window is made not current. |
michael@0 | 215 | * An error is returned if for instance the window wasn't connected in the |
michael@0 | 216 | * first place. |
michael@0 | 217 | */ |
michael@0 | 218 | static inline int native_window_disconnect( |
michael@0 | 219 | android_native_window_t* window, int api) |
michael@0 | 220 | { |
michael@0 | 221 | return window->perform(window, NATIVE_WINDOW_DISCONNECT, api); |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | |
michael@0 | 225 | // --------------------------------------------------------------------------- |
michael@0 | 226 | |
michael@0 | 227 | /* FIXME: this is legacy for pixmaps */ |
michael@0 | 228 | typedef struct egl_native_pixmap_t |
michael@0 | 229 | { |
michael@0 | 230 | int32_t version; /* must be 32 */ |
michael@0 | 231 | int32_t width; |
michael@0 | 232 | int32_t height; |
michael@0 | 233 | int32_t stride; |
michael@0 | 234 | uint8_t* data; |
michael@0 | 235 | uint8_t format; |
michael@0 | 236 | uint8_t rfu[3]; |
michael@0 | 237 | union { |
michael@0 | 238 | uint32_t compressedFormat; |
michael@0 | 239 | int32_t vstride; |
michael@0 | 240 | }; |
michael@0 | 241 | int32_t reserved; |
michael@0 | 242 | } egl_native_pixmap_t; |
michael@0 | 243 | |
michael@0 | 244 | /*****************************************************************************/ |
michael@0 | 245 | |
michael@0 | 246 | #ifdef __cplusplus |
michael@0 | 247 | } |
michael@0 | 248 | #endif |
michael@0 | 249 | |
michael@0 | 250 | |
michael@0 | 251 | /*****************************************************************************/ |
michael@0 | 252 | |
michael@0 | 253 | #ifdef __cplusplus |
michael@0 | 254 | |
michael@0 | 255 | #include <utils/RefBase.h> |
michael@0 | 256 | |
michael@0 | 257 | namespace android { |
michael@0 | 258 | |
michael@0 | 259 | /* |
michael@0 | 260 | * This helper class turns an EGL android_native_xxx type into a C++ |
michael@0 | 261 | * reference-counted object; with proper type conversions. |
michael@0 | 262 | */ |
michael@0 | 263 | template <typename NATIVE_TYPE, typename TYPE, typename REF> |
michael@0 | 264 | class EGLNativeBase : public NATIVE_TYPE, public REF |
michael@0 | 265 | { |
michael@0 | 266 | protected: |
michael@0 | 267 | typedef EGLNativeBase<NATIVE_TYPE, TYPE, REF> BASE; |
michael@0 | 268 | EGLNativeBase() : NATIVE_TYPE(), REF() { |
michael@0 | 269 | NATIVE_TYPE::common.incRef = incRef; |
michael@0 | 270 | NATIVE_TYPE::common.decRef = decRef; |
michael@0 | 271 | } |
michael@0 | 272 | static inline TYPE* getSelf(NATIVE_TYPE* self) { |
michael@0 | 273 | return static_cast<TYPE*>(self); |
michael@0 | 274 | } |
michael@0 | 275 | static inline TYPE const* getSelf(NATIVE_TYPE const* self) { |
michael@0 | 276 | return static_cast<TYPE const *>(self); |
michael@0 | 277 | } |
michael@0 | 278 | static inline TYPE* getSelf(android_native_base_t* base) { |
michael@0 | 279 | return getSelf(reinterpret_cast<NATIVE_TYPE*>(base)); |
michael@0 | 280 | } |
michael@0 | 281 | static inline TYPE const * getSelf(android_native_base_t const* base) { |
michael@0 | 282 | return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base)); |
michael@0 | 283 | } |
michael@0 | 284 | static void incRef(android_native_base_t* base) { |
michael@0 | 285 | EGLNativeBase* self = getSelf(base); |
michael@0 | 286 | self->incStrong(self); |
michael@0 | 287 | } |
michael@0 | 288 | static void decRef(android_native_base_t* base) { |
michael@0 | 289 | EGLNativeBase* self = getSelf(base); |
michael@0 | 290 | self->decStrong(self); |
michael@0 | 291 | } |
michael@0 | 292 | }; |
michael@0 | 293 | |
michael@0 | 294 | } // namespace android |
michael@0 | 295 | #endif // __cplusplus |
michael@0 | 296 | |
michael@0 | 297 | /*****************************************************************************/ |
michael@0 | 298 | |
michael@0 | 299 | #endif /* ANDROID_ANDROID_NATIVES_H */ |