1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/omx-plugin/include/froyo/ui/egl/android_natives.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,299 @@ 1.4 +/* 1.5 + * Copyright (C) 2009 The Android Open Source Project 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +#ifndef ANDROID_ANDROID_NATIVES_H 1.21 +#define ANDROID_ANDROID_NATIVES_H 1.22 + 1.23 +#include <sys/types.h> 1.24 +#include <string.h> 1.25 + 1.26 +#include <hardware/gralloc.h> 1.27 + 1.28 +#ifdef __cplusplus 1.29 +extern "C" { 1.30 +#endif 1.31 + 1.32 +/*****************************************************************************/ 1.33 + 1.34 +#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \ 1.35 + (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d)) 1.36 + 1.37 +#define ANDROID_NATIVE_WINDOW_MAGIC \ 1.38 + ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d') 1.39 + 1.40 +#define ANDROID_NATIVE_BUFFER_MAGIC \ 1.41 + ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r') 1.42 + 1.43 +// --------------------------------------------------------------------------- 1.44 + 1.45 +struct android_native_buffer_t; 1.46 + 1.47 +// --------------------------------------------------------------------------- 1.48 + 1.49 +typedef struct android_native_base_t 1.50 +{ 1.51 + /* a magic value defined by the actual EGL native type */ 1.52 + int magic; 1.53 + 1.54 + /* the sizeof() of the actual EGL native type */ 1.55 + int version; 1.56 + 1.57 + void* reserved[4]; 1.58 + 1.59 + /* reference-counting interface */ 1.60 + void (*incRef)(struct android_native_base_t* base); 1.61 + void (*decRef)(struct android_native_base_t* base); 1.62 +} android_native_base_t; 1.63 + 1.64 +// --------------------------------------------------------------------------- 1.65 + 1.66 +/* attributes queriable with query() */ 1.67 +enum { 1.68 + NATIVE_WINDOW_WIDTH = 0, 1.69 + NATIVE_WINDOW_HEIGHT = 1, 1.70 + NATIVE_WINDOW_FORMAT = 2, 1.71 +}; 1.72 + 1.73 +/* valid operations for the (*perform)() hook */ 1.74 +enum { 1.75 + NATIVE_WINDOW_SET_USAGE = 0, 1.76 + NATIVE_WINDOW_CONNECT = 1, 1.77 + NATIVE_WINDOW_DISCONNECT = 2 1.78 +}; 1.79 + 1.80 +/* parameter for NATIVE_WINDOW_[DIS]CONNECT */ 1.81 +enum { 1.82 + NATIVE_WINDOW_API_EGL = 1 1.83 +}; 1.84 + 1.85 +typedef struct android_native_window_t 1.86 +{ 1.87 +#ifdef __cplusplus 1.88 + android_native_window_t() 1.89 + : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0) 1.90 + { 1.91 + common.magic = ANDROID_NATIVE_WINDOW_MAGIC; 1.92 + common.version = sizeof(android_native_window_t); 1.93 + memset(common.reserved, 0, sizeof(common.reserved)); 1.94 + } 1.95 +#endif 1.96 + 1.97 + struct android_native_base_t common; 1.98 + 1.99 + /* flags describing some attributes of this surface or its updater */ 1.100 + const uint32_t flags; 1.101 + 1.102 + /* min swap interval supported by this updated */ 1.103 + const int minSwapInterval; 1.104 + 1.105 + /* max swap interval supported by this updated */ 1.106 + const int maxSwapInterval; 1.107 + 1.108 + /* horizontal and vertical resolution in DPI */ 1.109 + const float xdpi; 1.110 + const float ydpi; 1.111 + 1.112 + /* Some storage reserved for the OEM's driver. */ 1.113 + intptr_t oem[4]; 1.114 + 1.115 + 1.116 + /* 1.117 + * Set the swap interval for this surface. 1.118 + * 1.119 + * Returns 0 on success or -errno on error. 1.120 + */ 1.121 + int (*setSwapInterval)(struct android_native_window_t* window, 1.122 + int interval); 1.123 + 1.124 + /* 1.125 + * hook called by EGL to acquire a buffer. After this call, the buffer 1.126 + * is not locked, so its content cannot be modified. 1.127 + * this call may block if no buffers are available. 1.128 + * 1.129 + * Returns 0 on success or -errno on error. 1.130 + */ 1.131 + int (*dequeueBuffer)(struct android_native_window_t* window, 1.132 + struct android_native_buffer_t** buffer); 1.133 + 1.134 + /* 1.135 + * hook called by EGL to lock a buffer. This MUST be called before modifying 1.136 + * the content of a buffer. The buffer must have been acquired with 1.137 + * dequeueBuffer first. 1.138 + * 1.139 + * Returns 0 on success or -errno on error. 1.140 + */ 1.141 + int (*lockBuffer)(struct android_native_window_t* window, 1.142 + struct android_native_buffer_t* buffer); 1.143 + /* 1.144 + * hook called by EGL when modifications to the render buffer are done. 1.145 + * This unlocks and post the buffer. 1.146 + * 1.147 + * Buffers MUST be queued in the same order than they were dequeued. 1.148 + * 1.149 + * Returns 0 on success or -errno on error. 1.150 + */ 1.151 + int (*queueBuffer)(struct android_native_window_t* window, 1.152 + struct android_native_buffer_t* buffer); 1.153 + 1.154 + /* 1.155 + * hook used to retrieve information about the native window. 1.156 + * 1.157 + * Returns 0 on success or -errno on error. 1.158 + */ 1.159 + int (*query)(struct android_native_window_t* window, 1.160 + int what, int* value); 1.161 + 1.162 + /* 1.163 + * hook used to perform various operations on the surface. 1.164 + * (*perform)() is a generic mechanism to add functionality to 1.165 + * android_native_window_t while keeping backward binary compatibility. 1.166 + * 1.167 + * This hook should not be called directly, instead use the helper functions 1.168 + * defined below. 1.169 + * 1.170 + * (*perform)() returns -ENOENT if the 'what' parameter is not supported 1.171 + * by the surface's implementation. 1.172 + * 1.173 + * The valid operations are: 1.174 + * NATIVE_WINDOW_SET_USAGE 1.175 + * NATIVE_WINDOW_CONNECT 1.176 + * NATIVE_WINDOW_DISCONNECT 1.177 + * 1.178 + */ 1.179 + 1.180 + int (*perform)(struct android_native_window_t* window, 1.181 + int operation, ... ); 1.182 + 1.183 + void* reserved_proc[3]; 1.184 +} android_native_window_t; 1.185 + 1.186 + 1.187 +/* 1.188 + * native_window_set_usage() sets the intended usage flags for the next 1.189 + * buffers acquired with (*lockBuffer)() and on. 1.190 + * By default (if this function is never called), a usage of 1.191 + * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE 1.192 + * is assumed. 1.193 + * Calling this function will usually cause following buffers to be 1.194 + * reallocated. 1.195 + */ 1.196 + 1.197 +static inline int native_window_set_usage( 1.198 + android_native_window_t* window, int usage) 1.199 +{ 1.200 + return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage); 1.201 +} 1.202 + 1.203 +/* 1.204 + * native_window_connect(..., NATIVE_WINDOW_API_EGL) must be called 1.205 + * by EGL when the window is made current. 1.206 + * Returns -EINVAL if for some reason the window cannot be connected, which 1.207 + * can happen if it's connected to some other API. 1.208 + */ 1.209 +static inline int native_window_connect( 1.210 + android_native_window_t* window, int api) 1.211 +{ 1.212 + return window->perform(window, NATIVE_WINDOW_CONNECT, api); 1.213 +} 1.214 + 1.215 +/* 1.216 + * native_window_disconnect(..., NATIVE_WINDOW_API_EGL) must be called 1.217 + * by EGL when the window is made not current. 1.218 + * An error is returned if for instance the window wasn't connected in the 1.219 + * first place. 1.220 + */ 1.221 +static inline int native_window_disconnect( 1.222 + android_native_window_t* window, int api) 1.223 +{ 1.224 + return window->perform(window, NATIVE_WINDOW_DISCONNECT, api); 1.225 +} 1.226 + 1.227 + 1.228 +// --------------------------------------------------------------------------- 1.229 + 1.230 +/* FIXME: this is legacy for pixmaps */ 1.231 +typedef struct egl_native_pixmap_t 1.232 +{ 1.233 + int32_t version; /* must be 32 */ 1.234 + int32_t width; 1.235 + int32_t height; 1.236 + int32_t stride; 1.237 + uint8_t* data; 1.238 + uint8_t format; 1.239 + uint8_t rfu[3]; 1.240 + union { 1.241 + uint32_t compressedFormat; 1.242 + int32_t vstride; 1.243 + }; 1.244 + int32_t reserved; 1.245 +} egl_native_pixmap_t; 1.246 + 1.247 +/*****************************************************************************/ 1.248 + 1.249 +#ifdef __cplusplus 1.250 +} 1.251 +#endif 1.252 + 1.253 + 1.254 +/*****************************************************************************/ 1.255 + 1.256 +#ifdef __cplusplus 1.257 + 1.258 +#include <utils/RefBase.h> 1.259 + 1.260 +namespace android { 1.261 + 1.262 +/* 1.263 + * This helper class turns an EGL android_native_xxx type into a C++ 1.264 + * reference-counted object; with proper type conversions. 1.265 + */ 1.266 +template <typename NATIVE_TYPE, typename TYPE, typename REF> 1.267 +class EGLNativeBase : public NATIVE_TYPE, public REF 1.268 +{ 1.269 +protected: 1.270 + typedef EGLNativeBase<NATIVE_TYPE, TYPE, REF> BASE; 1.271 + EGLNativeBase() : NATIVE_TYPE(), REF() { 1.272 + NATIVE_TYPE::common.incRef = incRef; 1.273 + NATIVE_TYPE::common.decRef = decRef; 1.274 + } 1.275 + static inline TYPE* getSelf(NATIVE_TYPE* self) { 1.276 + return static_cast<TYPE*>(self); 1.277 + } 1.278 + static inline TYPE const* getSelf(NATIVE_TYPE const* self) { 1.279 + return static_cast<TYPE const *>(self); 1.280 + } 1.281 + static inline TYPE* getSelf(android_native_base_t* base) { 1.282 + return getSelf(reinterpret_cast<NATIVE_TYPE*>(base)); 1.283 + } 1.284 + static inline TYPE const * getSelf(android_native_base_t const* base) { 1.285 + return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base)); 1.286 + } 1.287 + static void incRef(android_native_base_t* base) { 1.288 + EGLNativeBase* self = getSelf(base); 1.289 + self->incStrong(self); 1.290 + } 1.291 + static void decRef(android_native_base_t* base) { 1.292 + EGLNativeBase* self = getSelf(base); 1.293 + self->decStrong(self); 1.294 + } 1.295 +}; 1.296 + 1.297 +} // namespace android 1.298 +#endif // __cplusplus 1.299 + 1.300 +/*****************************************************************************/ 1.301 + 1.302 +#endif /* ANDROID_ANDROID_NATIVES_H */