1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/omx-plugin/include/gb/ui/egl/android_natives.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,423 @@ 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 +#include <android/native_window.h> 1.29 + 1.30 +#ifdef __cplusplus 1.31 +extern "C" { 1.32 +#endif 1.33 + 1.34 +/*****************************************************************************/ 1.35 + 1.36 +#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \ 1.37 + (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d)) 1.38 + 1.39 +#define ANDROID_NATIVE_WINDOW_MAGIC \ 1.40 + ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d') 1.41 + 1.42 +#define ANDROID_NATIVE_BUFFER_MAGIC \ 1.43 + ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r') 1.44 + 1.45 +// --------------------------------------------------------------------------- 1.46 + 1.47 +struct android_native_buffer_t; 1.48 + 1.49 +typedef struct android_native_rect_t 1.50 +{ 1.51 + int32_t left; 1.52 + int32_t top; 1.53 + int32_t right; 1.54 + int32_t bottom; 1.55 +} android_native_rect_t; 1.56 + 1.57 +// --------------------------------------------------------------------------- 1.58 + 1.59 +typedef struct android_native_base_t 1.60 +{ 1.61 + /* a magic value defined by the actual EGL native type */ 1.62 + int magic; 1.63 + 1.64 + /* the sizeof() of the actual EGL native type */ 1.65 + int version; 1.66 + 1.67 + void* reserved[4]; 1.68 + 1.69 + /* reference-counting interface */ 1.70 + void (*incRef)(struct android_native_base_t* base); 1.71 + void (*decRef)(struct android_native_base_t* base); 1.72 +} android_native_base_t; 1.73 + 1.74 +// --------------------------------------------------------------------------- 1.75 + 1.76 +/* attributes queriable with query() */ 1.77 +enum { 1.78 + NATIVE_WINDOW_WIDTH = 0, 1.79 + NATIVE_WINDOW_HEIGHT, 1.80 + NATIVE_WINDOW_FORMAT, 1.81 +}; 1.82 + 1.83 +/* valid operations for the (*perform)() hook */ 1.84 +enum { 1.85 + NATIVE_WINDOW_SET_USAGE = 0, 1.86 + NATIVE_WINDOW_CONNECT, 1.87 + NATIVE_WINDOW_DISCONNECT, 1.88 + NATIVE_WINDOW_SET_CROP, 1.89 + NATIVE_WINDOW_SET_BUFFER_COUNT, 1.90 + NATIVE_WINDOW_SET_BUFFERS_GEOMETRY, 1.91 + NATIVE_WINDOW_SET_BUFFERS_TRANSFORM, 1.92 +}; 1.93 + 1.94 +/* parameter for NATIVE_WINDOW_[DIS]CONNECT */ 1.95 +enum { 1.96 + NATIVE_WINDOW_API_EGL = 1 1.97 +}; 1.98 + 1.99 +/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */ 1.100 +enum { 1.101 + /* flip source image horizontally */ 1.102 + NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H , 1.103 + /* flip source image vertically */ 1.104 + NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, 1.105 + /* rotate source image 90 degrees clock-wise */ 1.106 + NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, 1.107 + /* rotate source image 180 degrees */ 1.108 + NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, 1.109 + /* rotate source image 270 degrees clock-wise */ 1.110 + NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, 1.111 +}; 1.112 + 1.113 +struct ANativeWindow 1.114 +{ 1.115 +#ifdef __cplusplus 1.116 + ANativeWindow() 1.117 + : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0) 1.118 + { 1.119 + common.magic = ANDROID_NATIVE_WINDOW_MAGIC; 1.120 + common.version = sizeof(ANativeWindow); 1.121 + memset(common.reserved, 0, sizeof(common.reserved)); 1.122 + } 1.123 + 1.124 + // Implement the methods that sp<ANativeWindow> expects so that it 1.125 + // can be used to automatically refcount ANativeWindow's. 1.126 + void incStrong(const void* id) const { 1.127 + common.incRef(const_cast<android_native_base_t*>(&common)); 1.128 + } 1.129 + void decStrong(const void* id) const { 1.130 + common.decRef(const_cast<android_native_base_t*>(&common)); 1.131 + } 1.132 +#endif 1.133 + 1.134 + struct android_native_base_t common; 1.135 + 1.136 + /* flags describing some attributes of this surface or its updater */ 1.137 + const uint32_t flags; 1.138 + 1.139 + /* min swap interval supported by this updated */ 1.140 + const int minSwapInterval; 1.141 + 1.142 + /* max swap interval supported by this updated */ 1.143 + const int maxSwapInterval; 1.144 + 1.145 + /* horizontal and vertical resolution in DPI */ 1.146 + const float xdpi; 1.147 + const float ydpi; 1.148 + 1.149 + /* Some storage reserved for the OEM's driver. */ 1.150 + intptr_t oem[4]; 1.151 + 1.152 + 1.153 + /* 1.154 + * Set the swap interval for this surface. 1.155 + * 1.156 + * Returns 0 on success or -errno on error. 1.157 + */ 1.158 + int (*setSwapInterval)(struct ANativeWindow* window, 1.159 + int interval); 1.160 + 1.161 + /* 1.162 + * hook called by EGL to acquire a buffer. After this call, the buffer 1.163 + * is not locked, so its content cannot be modified. 1.164 + * this call may block if no buffers are available. 1.165 + * 1.166 + * Returns 0 on success or -errno on error. 1.167 + */ 1.168 + int (*dequeueBuffer)(struct ANativeWindow* window, 1.169 + struct android_native_buffer_t** buffer); 1.170 + 1.171 + /* 1.172 + * hook called by EGL to lock a buffer. This MUST be called before modifying 1.173 + * the content of a buffer. The buffer must have been acquired with 1.174 + * dequeueBuffer first. 1.175 + * 1.176 + * Returns 0 on success or -errno on error. 1.177 + */ 1.178 + int (*lockBuffer)(struct ANativeWindow* window, 1.179 + struct android_native_buffer_t* buffer); 1.180 + /* 1.181 + * hook called by EGL when modifications to the render buffer are done. 1.182 + * This unlocks and post the buffer. 1.183 + * 1.184 + * Buffers MUST be queued in the same order than they were dequeued. 1.185 + * 1.186 + * Returns 0 on success or -errno on error. 1.187 + */ 1.188 + int (*queueBuffer)(struct ANativeWindow* window, 1.189 + struct android_native_buffer_t* buffer); 1.190 + 1.191 + /* 1.192 + * hook used to retrieve information about the native window. 1.193 + * 1.194 + * Returns 0 on success or -errno on error. 1.195 + */ 1.196 + int (*query)(struct ANativeWindow* window, 1.197 + int what, int* value); 1.198 + 1.199 + /* 1.200 + * hook used to perform various operations on the surface. 1.201 + * (*perform)() is a generic mechanism to add functionality to 1.202 + * ANativeWindow while keeping backward binary compatibility. 1.203 + * 1.204 + * This hook should not be called directly, instead use the helper functions 1.205 + * defined below. 1.206 + * 1.207 + * (*perform)() returns -ENOENT if the 'what' parameter is not supported 1.208 + * by the surface's implementation. 1.209 + * 1.210 + * The valid operations are: 1.211 + * NATIVE_WINDOW_SET_USAGE 1.212 + * NATIVE_WINDOW_CONNECT 1.213 + * NATIVE_WINDOW_DISCONNECT 1.214 + * NATIVE_WINDOW_SET_CROP 1.215 + * NATIVE_WINDOW_SET_BUFFER_COUNT 1.216 + * NATIVE_WINDOW_SET_BUFFERS_GEOMETRY 1.217 + * NATIVE_WINDOW_SET_BUFFERS_TRANSFORM 1.218 + * 1.219 + */ 1.220 + 1.221 + int (*perform)(struct ANativeWindow* window, 1.222 + int operation, ... ); 1.223 + 1.224 + /* 1.225 + * hook used to cancel a buffer that has been dequeued. 1.226 + * No synchronization is performed between dequeue() and cancel(), so 1.227 + * either external synchronization is needed, or these functions must be 1.228 + * called from the same thread. 1.229 + */ 1.230 + int (*cancelBuffer)(struct ANativeWindow* window, 1.231 + struct android_native_buffer_t* buffer); 1.232 + 1.233 + 1.234 + void* reserved_proc[2]; 1.235 +}; 1.236 + 1.237 +// Backwards compatibility... please switch to ANativeWindow. 1.238 +typedef struct ANativeWindow android_native_window_t; 1.239 + 1.240 +/* 1.241 + * native_window_set_usage(..., usage) 1.242 + * Sets the intended usage flags for the next buffers 1.243 + * acquired with (*lockBuffer)() and on. 1.244 + * By default (if this function is never called), a usage of 1.245 + * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE 1.246 + * is assumed. 1.247 + * Calling this function will usually cause following buffers to be 1.248 + * reallocated. 1.249 + */ 1.250 + 1.251 +static inline int native_window_set_usage( 1.252 + ANativeWindow* window, int usage) 1.253 +{ 1.254 + return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage); 1.255 +} 1.256 + 1.257 +/* 1.258 + * native_window_connect(..., NATIVE_WINDOW_API_EGL) 1.259 + * Must be called by EGL when the window is made current. 1.260 + * Returns -EINVAL if for some reason the window cannot be connected, which 1.261 + * can happen if it's connected to some other API. 1.262 + */ 1.263 +static inline int native_window_connect( 1.264 + ANativeWindow* window, int api) 1.265 +{ 1.266 + return window->perform(window, NATIVE_WINDOW_CONNECT, api); 1.267 +} 1.268 + 1.269 +/* 1.270 + * native_window_disconnect(..., NATIVE_WINDOW_API_EGL) 1.271 + * Must be called by EGL when the window is made not current. 1.272 + * An error is returned if for instance the window wasn't connected in the 1.273 + * first place. 1.274 + */ 1.275 +static inline int native_window_disconnect( 1.276 + ANativeWindow* window, int api) 1.277 +{ 1.278 + return window->perform(window, NATIVE_WINDOW_DISCONNECT, api); 1.279 +} 1.280 + 1.281 +/* 1.282 + * native_window_set_crop(..., crop) 1.283 + * Sets which region of the next queued buffers needs to be considered. 1.284 + * A buffer's crop region is scaled to match the surface's size. 1.285 + * 1.286 + * The specified crop region applies to all buffers queued after it is called. 1.287 + * 1.288 + * if 'crop' is NULL, subsequently queued buffers won't be cropped. 1.289 + * 1.290 + * An error is returned if for instance the crop region is invalid, 1.291 + * out of the buffer's bound or if the window is invalid. 1.292 + */ 1.293 +static inline int native_window_set_crop( 1.294 + ANativeWindow* window, 1.295 + android_native_rect_t const * crop) 1.296 +{ 1.297 + return window->perform(window, NATIVE_WINDOW_SET_CROP, crop); 1.298 +} 1.299 + 1.300 +/* 1.301 + * native_window_set_buffer_count(..., count) 1.302 + * Sets the number of buffers associated with this native window. 1.303 + */ 1.304 +static inline int native_window_set_buffer_count( 1.305 + ANativeWindow* window, 1.306 + size_t bufferCount) 1.307 +{ 1.308 + return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount); 1.309 +} 1.310 + 1.311 +/* 1.312 + * native_window_set_buffers_geometry(..., int w, int h, int format) 1.313 + * All buffers dequeued after this call will have the geometry specified. 1.314 + * In particular, all buffers will have a fixed-size, independent form the 1.315 + * native-window size. They will be appropriately scaled to the window-size 1.316 + * upon composition. 1.317 + * 1.318 + * If all parameters are 0, the normal behavior is restored. That is, 1.319 + * dequeued buffers following this call will be sized to the window's size. 1.320 + * 1.321 + */ 1.322 +static inline int native_window_set_buffers_geometry( 1.323 + ANativeWindow* window, 1.324 + int w, int h, int format) 1.325 +{ 1.326 + return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY, 1.327 + w, h, format); 1.328 +} 1.329 + 1.330 +/* 1.331 + * native_window_set_buffers_transform(..., int transform) 1.332 + * All buffers queued after this call will be displayed transformed according 1.333 + * to the transform parameter specified. 1.334 + */ 1.335 +static inline int native_window_set_buffers_transform( 1.336 + ANativeWindow* window, 1.337 + int transform) 1.338 +{ 1.339 + return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM, 1.340 + transform); 1.341 +} 1.342 + 1.343 +// --------------------------------------------------------------------------- 1.344 + 1.345 +/* FIXME: this is legacy for pixmaps */ 1.346 +typedef struct egl_native_pixmap_t 1.347 +{ 1.348 + int32_t version; /* must be 32 */ 1.349 + int32_t width; 1.350 + int32_t height; 1.351 + int32_t stride; 1.352 + uint8_t* data; 1.353 + uint8_t format; 1.354 + uint8_t rfu[3]; 1.355 + union { 1.356 + uint32_t compressedFormat; 1.357 + int32_t vstride; 1.358 + }; 1.359 + int32_t reserved; 1.360 +} egl_native_pixmap_t; 1.361 + 1.362 +/*****************************************************************************/ 1.363 + 1.364 +#ifdef __cplusplus 1.365 +} 1.366 +#endif 1.367 + 1.368 + 1.369 +/*****************************************************************************/ 1.370 + 1.371 +#ifdef __cplusplus 1.372 + 1.373 +#include <utils/RefBase.h> 1.374 + 1.375 +namespace android { 1.376 + 1.377 +/* 1.378 + * This helper class turns an EGL android_native_xxx type into a C++ 1.379 + * reference-counted object; with proper type conversions. 1.380 + */ 1.381 +template <typename NATIVE_TYPE, typename TYPE, typename REF> 1.382 +class EGLNativeBase : public NATIVE_TYPE, public REF 1.383 +{ 1.384 +public: 1.385 + // Disambiguate between the incStrong in REF and NATIVE_TYPE 1.386 + void incStrong(const void* id) const { 1.387 + REF::incStrong(id); 1.388 + } 1.389 + void decStrong(const void* id) const { 1.390 + REF::decStrong(id); 1.391 + } 1.392 + 1.393 +protected: 1.394 + typedef EGLNativeBase<NATIVE_TYPE, TYPE, REF> BASE; 1.395 + EGLNativeBase() : NATIVE_TYPE(), REF() { 1.396 + NATIVE_TYPE::common.incRef = incRef; 1.397 + NATIVE_TYPE::common.decRef = decRef; 1.398 + } 1.399 + static inline TYPE* getSelf(NATIVE_TYPE* self) { 1.400 + return static_cast<TYPE*>(self); 1.401 + } 1.402 + static inline TYPE const* getSelf(NATIVE_TYPE const* self) { 1.403 + return static_cast<TYPE const *>(self); 1.404 + } 1.405 + static inline TYPE* getSelf(android_native_base_t* base) { 1.406 + return getSelf(reinterpret_cast<NATIVE_TYPE*>(base)); 1.407 + } 1.408 + static inline TYPE const * getSelf(android_native_base_t const* base) { 1.409 + return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base)); 1.410 + } 1.411 + static void incRef(android_native_base_t* base) { 1.412 + EGLNativeBase* self = getSelf(base); 1.413 + self->incStrong(self); 1.414 + } 1.415 + static void decRef(android_native_base_t* base) { 1.416 + EGLNativeBase* self = getSelf(base); 1.417 + self->decStrong(self); 1.418 + } 1.419 +}; 1.420 + 1.421 +} // namespace android 1.422 +#endif // __cplusplus 1.423 + 1.424 +/*****************************************************************************/ 1.425 + 1.426 +#endif /* ANDROID_ANDROID_NATIVES_H */