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 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
| 29 | /*****************************************************************************/ |
| 30 | |
| 31 | #define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \ |
| 32 | (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d)) |
| 33 | |
| 34 | #define ANDROID_NATIVE_WINDOW_MAGIC \ |
| 35 | ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d') |
| 36 | |
| 37 | #define ANDROID_NATIVE_BUFFER_MAGIC \ |
| 38 | ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r') |
| 39 | |
| 40 | // --------------------------------------------------------------------------- |
| 41 | |
| 42 | struct android_native_buffer_t; |
| 43 | |
| 44 | enum { |
| 45 | /* attributes of this surface or its updater */ |
| 46 | SURFACE_FLAG_PRESERVE_CONTENT = FRAMEBUFFER_RESERVED0, |
| 47 | SURFACE_FLAG_MAPPED = FRAMEBUFFER_FLAG_MAPPED, |
| 48 | }; |
| 49 | |
| 50 | |
| 51 | // --------------------------------------------------------------------------- |
| 52 | |
| 53 | struct android_native_base_t |
| 54 | { |
| 55 | /* a magic value defined by the actual EGL native type */ |
| 56 | int magic; |
| 57 | |
| 58 | /* the sizeof() of the actual EGL native type */ |
| 59 | int version; |
| 60 | |
| 61 | void* reserved[4]; |
| 62 | |
| 63 | /* reference-counting interface */ |
| 64 | void (*incRef)(struct android_native_base_t* base); |
| 65 | void (*decRef)(struct android_native_base_t* base); |
| 66 | }; |
| 67 | |
| 68 | |
| 69 | struct android_native_window_t |
| 70 | { |
| 71 | #ifdef __cplusplus |
| 72 | android_native_window_t() |
| 73 | : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0) |
| 74 | { |
| 75 | common.magic = ANDROID_NATIVE_WINDOW_MAGIC; |
| 76 | common.version = sizeof(android_native_window_t); |
| 77 | memset(common.reserved, 0, sizeof(common.reserved)); |
| 78 | } |
| 79 | #endif |
| 80 | |
| 81 | struct android_native_base_t common; |
| 82 | |
| 83 | /* flags describing some attributes of this surface or its updater */ |
| 84 | const uint32_t flags; |
| 85 | |
| 86 | /* min swap interval supported by this updated */ |
| 87 | const int minSwapInterval; |
| 88 | |
| 89 | /* max swap interval supported by this updated */ |
| 90 | const int maxSwapInterval; |
| 91 | |
| 92 | /* horizontal and vertical resolution in DPI */ |
| 93 | const float xdpi; |
| 94 | const float ydpi; |
| 95 | |
| 96 | /* Some storage reserved for the OEM's driver. */ |
| 97 | intptr_t oem[4]; |
| 98 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 99 | |
| 100 | /* |
| 101 | * Set the swap interval for this surface. |
| 102 | * |
| 103 | * Returns 0 on success or -errno on error. |
| 104 | */ |
| 105 | int (*setSwapInterval)(struct android_native_window_t* window, |
| 106 | int interval); |
| 107 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 108 | /* |
| 109 | * hook called by EGL to acquire a buffer. After this call, the buffer |
| 110 | * is not locked, so its content cannot be modified. |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame^] | 111 | * this call may block if no buffers are available. |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 112 | * |
| 113 | * Returns 0 on success or -errno on error. |
| 114 | */ |
| 115 | int (*dequeueBuffer)(struct android_native_window_t* window, |
| 116 | struct android_native_buffer_t** buffer); |
| 117 | |
| 118 | /* |
| 119 | * hook called by EGL to lock a buffer. This MUST be called before modifying |
| 120 | * the content of a buffer. The buffer must have been acquired with |
| 121 | * dequeueBuffer first. |
| 122 | * |
| 123 | * Returns 0 on success or -errno on error. |
| 124 | */ |
| 125 | int (*lockBuffer)(struct android_native_window_t* window, |
| 126 | struct android_native_buffer_t* buffer); |
| 127 | /* |
| 128 | * hook called by EGL when modifications to the render buffer are done. |
| 129 | * This unlocks and post the buffer. |
| 130 | * |
| 131 | * Buffers MUST be queued in the same order than they were dequeued. |
| 132 | * |
| 133 | * Returns 0 on success or -errno on error. |
| 134 | */ |
| 135 | int (*queueBuffer)(struct android_native_window_t* window, |
| 136 | struct android_native_buffer_t* buffer); |
| 137 | |
| 138 | |
| 139 | void* reserved_proc[5]; |
| 140 | }; |
| 141 | |
| 142 | |
| 143 | struct android_native_buffer_t |
| 144 | { |
| 145 | #ifdef __cplusplus |
| 146 | android_native_buffer_t() { |
| 147 | common.magic = ANDROID_NATIVE_BUFFER_MAGIC; |
| 148 | common.version = sizeof(android_native_buffer_t); |
| 149 | memset(common.reserved, 0, sizeof(common.reserved)); |
| 150 | } |
| 151 | #endif |
| 152 | |
| 153 | struct android_native_base_t common; |
| 154 | |
| 155 | int width; |
| 156 | int height; |
| 157 | int stride; |
| 158 | int format; |
| 159 | int usage; |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame^] | 160 | void* bits; // non-zero if buffer is locked for sw usage |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 161 | |
| 162 | void* reserved[2]; |
| 163 | |
| 164 | int (*getHandle)(struct android_native_buffer_t const * base, |
| 165 | buffer_handle_t* handle); |
| 166 | |
| 167 | void* reserved_proc[7]; |
| 168 | }; |
| 169 | |
| 170 | |
| 171 | /* FIXME: this is legacy for pixmaps */ |
| 172 | struct egl_native_pixmap_t |
| 173 | { |
| 174 | int32_t version; /* must be 32 */ |
| 175 | int32_t width; |
| 176 | int32_t height; |
| 177 | int32_t stride; |
| 178 | uint8_t* data; |
| 179 | uint8_t format; |
| 180 | uint8_t rfu[3]; |
| 181 | union { |
| 182 | uint32_t compressedFormat; |
| 183 | int32_t vstride; |
| 184 | }; |
| 185 | int32_t reserved; |
| 186 | }; |
| 187 | |
| 188 | /*****************************************************************************/ |
| 189 | |
| 190 | #ifdef __cplusplus |
| 191 | } |
| 192 | #endif |
| 193 | |
| 194 | |
| 195 | /*****************************************************************************/ |
| 196 | |
| 197 | #ifdef __cplusplus |
| 198 | |
| 199 | #include <utils/RefBase.h> |
| 200 | |
| 201 | namespace android { |
| 202 | |
| 203 | /* |
| 204 | * This helper class turns an EGL android_native_xxx type into a C++ |
| 205 | * reference-counted object; with proper type conversions. |
| 206 | */ |
| 207 | template <typename NATIVE_TYPE, typename TYPE, typename REF> |
| 208 | class EGLNativeBase : public NATIVE_TYPE, public REF |
| 209 | { |
| 210 | protected: |
| 211 | typedef EGLNativeBase<NATIVE_TYPE, TYPE, REF> BASE; |
| 212 | EGLNativeBase() : NATIVE_TYPE(), REF() { |
| 213 | NATIVE_TYPE::common.incRef = incRef; |
| 214 | NATIVE_TYPE::common.decRef = decRef; |
| 215 | } |
| 216 | static inline TYPE* getSelf(NATIVE_TYPE* self) { |
| 217 | return static_cast<TYPE*>(self); |
| 218 | } |
| 219 | static inline TYPE const* getSelf(NATIVE_TYPE const* self) { |
| 220 | return static_cast<TYPE const *>(self); |
| 221 | } |
| 222 | static inline TYPE* getSelf(android_native_base_t* base) { |
| 223 | return getSelf(reinterpret_cast<NATIVE_TYPE*>(base)); |
| 224 | } |
| 225 | static inline TYPE const * getSelf(android_native_base_t const* base) { |
| 226 | return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base)); |
| 227 | } |
| 228 | static void incRef(android_native_base_t* base) { |
| 229 | EGLNativeBase* self = getSelf(base); |
| 230 | self->incStrong(self); |
| 231 | } |
| 232 | static void decRef(android_native_base_t* base) { |
| 233 | EGLNativeBase* self = getSelf(base); |
| 234 | self->decStrong(self); |
| 235 | } |
| 236 | }; |
| 237 | |
| 238 | } // namespace android |
| 239 | #endif // __cplusplus |
| 240 | |
| 241 | /*****************************************************************************/ |
| 242 | |
| 243 | #endif /* ANDROID_ANDROID_NATIVES_H */ |