michael@0: /* michael@0: * Copyright (C) 2009 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef ANDROID_ANDROID_NATIVES_H michael@0: #define ANDROID_ANDROID_NATIVES_H michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: michael@0: #ifdef __cplusplus michael@0: extern "C" { michael@0: #endif michael@0: michael@0: /*****************************************************************************/ michael@0: michael@0: #define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \ michael@0: (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d)) michael@0: michael@0: #define ANDROID_NATIVE_WINDOW_MAGIC \ michael@0: ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d') michael@0: michael@0: #define ANDROID_NATIVE_BUFFER_MAGIC \ michael@0: ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r') michael@0: michael@0: // --------------------------------------------------------------------------- michael@0: michael@0: struct android_native_buffer_t; michael@0: michael@0: // --------------------------------------------------------------------------- michael@0: michael@0: typedef struct android_native_base_t michael@0: { michael@0: /* a magic value defined by the actual EGL native type */ michael@0: int magic; michael@0: michael@0: /* the sizeof() of the actual EGL native type */ michael@0: int version; michael@0: michael@0: void* reserved[4]; michael@0: michael@0: /* reference-counting interface */ michael@0: void (*incRef)(struct android_native_base_t* base); michael@0: void (*decRef)(struct android_native_base_t* base); michael@0: } android_native_base_t; michael@0: michael@0: // --------------------------------------------------------------------------- michael@0: michael@0: /* attributes queriable with query() */ michael@0: enum { michael@0: NATIVE_WINDOW_WIDTH = 0, michael@0: NATIVE_WINDOW_HEIGHT = 1, michael@0: NATIVE_WINDOW_FORMAT = 2, michael@0: }; michael@0: michael@0: /* valid operations for the (*perform)() hook */ michael@0: enum { michael@0: NATIVE_WINDOW_SET_USAGE = 0, michael@0: NATIVE_WINDOW_CONNECT = 1, michael@0: NATIVE_WINDOW_DISCONNECT = 2 michael@0: }; michael@0: michael@0: /* parameter for NATIVE_WINDOW_[DIS]CONNECT */ michael@0: enum { michael@0: NATIVE_WINDOW_API_EGL = 1 michael@0: }; michael@0: michael@0: typedef struct android_native_window_t michael@0: { michael@0: #ifdef __cplusplus michael@0: android_native_window_t() michael@0: : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0) michael@0: { michael@0: common.magic = ANDROID_NATIVE_WINDOW_MAGIC; michael@0: common.version = sizeof(android_native_window_t); michael@0: memset(common.reserved, 0, sizeof(common.reserved)); michael@0: } michael@0: #endif michael@0: michael@0: struct android_native_base_t common; michael@0: michael@0: /* flags describing some attributes of this surface or its updater */ michael@0: const uint32_t flags; michael@0: michael@0: /* min swap interval supported by this updated */ michael@0: const int minSwapInterval; michael@0: michael@0: /* max swap interval supported by this updated */ michael@0: const int maxSwapInterval; michael@0: michael@0: /* horizontal and vertical resolution in DPI */ michael@0: const float xdpi; michael@0: const float ydpi; michael@0: michael@0: /* Some storage reserved for the OEM's driver. */ michael@0: intptr_t oem[4]; michael@0: michael@0: michael@0: /* michael@0: * Set the swap interval for this surface. michael@0: * michael@0: * Returns 0 on success or -errno on error. michael@0: */ michael@0: int (*setSwapInterval)(struct android_native_window_t* window, michael@0: int interval); michael@0: michael@0: /* michael@0: * hook called by EGL to acquire a buffer. After this call, the buffer michael@0: * is not locked, so its content cannot be modified. michael@0: * this call may block if no buffers are available. michael@0: * michael@0: * Returns 0 on success or -errno on error. michael@0: */ michael@0: int (*dequeueBuffer)(struct android_native_window_t* window, michael@0: struct android_native_buffer_t** buffer); michael@0: michael@0: /* michael@0: * hook called by EGL to lock a buffer. This MUST be called before modifying michael@0: * the content of a buffer. The buffer must have been acquired with michael@0: * dequeueBuffer first. michael@0: * michael@0: * Returns 0 on success or -errno on error. michael@0: */ michael@0: int (*lockBuffer)(struct android_native_window_t* window, michael@0: struct android_native_buffer_t* buffer); michael@0: /* michael@0: * hook called by EGL when modifications to the render buffer are done. michael@0: * This unlocks and post the buffer. michael@0: * michael@0: * Buffers MUST be queued in the same order than they were dequeued. michael@0: * michael@0: * Returns 0 on success or -errno on error. michael@0: */ michael@0: int (*queueBuffer)(struct android_native_window_t* window, michael@0: struct android_native_buffer_t* buffer); michael@0: michael@0: /* michael@0: * hook used to retrieve information about the native window. michael@0: * michael@0: * Returns 0 on success or -errno on error. michael@0: */ michael@0: int (*query)(struct android_native_window_t* window, michael@0: int what, int* value); michael@0: michael@0: /* michael@0: * hook used to perform various operations on the surface. michael@0: * (*perform)() is a generic mechanism to add functionality to michael@0: * android_native_window_t while keeping backward binary compatibility. michael@0: * michael@0: * This hook should not be called directly, instead use the helper functions michael@0: * defined below. michael@0: * michael@0: * (*perform)() returns -ENOENT if the 'what' parameter is not supported michael@0: * by the surface's implementation. michael@0: * michael@0: * The valid operations are: michael@0: * NATIVE_WINDOW_SET_USAGE michael@0: * NATIVE_WINDOW_CONNECT michael@0: * NATIVE_WINDOW_DISCONNECT michael@0: * michael@0: */ michael@0: michael@0: int (*perform)(struct android_native_window_t* window, michael@0: int operation, ... ); michael@0: michael@0: void* reserved_proc[3]; michael@0: } android_native_window_t; michael@0: michael@0: michael@0: /* michael@0: * native_window_set_usage() sets the intended usage flags for the next michael@0: * buffers acquired with (*lockBuffer)() and on. michael@0: * By default (if this function is never called), a usage of michael@0: * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE michael@0: * is assumed. michael@0: * Calling this function will usually cause following buffers to be michael@0: * reallocated. michael@0: */ michael@0: michael@0: static inline int native_window_set_usage( michael@0: android_native_window_t* window, int usage) michael@0: { michael@0: return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage); michael@0: } michael@0: michael@0: /* michael@0: * native_window_connect(..., NATIVE_WINDOW_API_EGL) must be called michael@0: * by EGL when the window is made current. michael@0: * Returns -EINVAL if for some reason the window cannot be connected, which michael@0: * can happen if it's connected to some other API. michael@0: */ michael@0: static inline int native_window_connect( michael@0: android_native_window_t* window, int api) michael@0: { michael@0: return window->perform(window, NATIVE_WINDOW_CONNECT, api); michael@0: } michael@0: michael@0: /* michael@0: * native_window_disconnect(..., NATIVE_WINDOW_API_EGL) must be called michael@0: * by EGL when the window is made not current. michael@0: * An error is returned if for instance the window wasn't connected in the michael@0: * first place. michael@0: */ michael@0: static inline int native_window_disconnect( michael@0: android_native_window_t* window, int api) michael@0: { michael@0: return window->perform(window, NATIVE_WINDOW_DISCONNECT, api); michael@0: } michael@0: michael@0: michael@0: // --------------------------------------------------------------------------- michael@0: michael@0: /* FIXME: this is legacy for pixmaps */ michael@0: typedef struct egl_native_pixmap_t michael@0: { michael@0: int32_t version; /* must be 32 */ michael@0: int32_t width; michael@0: int32_t height; michael@0: int32_t stride; michael@0: uint8_t* data; michael@0: uint8_t format; michael@0: uint8_t rfu[3]; michael@0: union { michael@0: uint32_t compressedFormat; michael@0: int32_t vstride; michael@0: }; michael@0: int32_t reserved; michael@0: } egl_native_pixmap_t; michael@0: michael@0: /*****************************************************************************/ michael@0: michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif michael@0: michael@0: michael@0: /*****************************************************************************/ michael@0: michael@0: #ifdef __cplusplus michael@0: michael@0: #include michael@0: michael@0: namespace android { michael@0: michael@0: /* michael@0: * This helper class turns an EGL android_native_xxx type into a C++ michael@0: * reference-counted object; with proper type conversions. michael@0: */ michael@0: template michael@0: class EGLNativeBase : public NATIVE_TYPE, public REF michael@0: { michael@0: protected: michael@0: typedef EGLNativeBase BASE; michael@0: EGLNativeBase() : NATIVE_TYPE(), REF() { michael@0: NATIVE_TYPE::common.incRef = incRef; michael@0: NATIVE_TYPE::common.decRef = decRef; michael@0: } michael@0: static inline TYPE* getSelf(NATIVE_TYPE* self) { michael@0: return static_cast(self); michael@0: } michael@0: static inline TYPE const* getSelf(NATIVE_TYPE const* self) { michael@0: return static_cast(self); michael@0: } michael@0: static inline TYPE* getSelf(android_native_base_t* base) { michael@0: return getSelf(reinterpret_cast(base)); michael@0: } michael@0: static inline TYPE const * getSelf(android_native_base_t const* base) { michael@0: return getSelf(reinterpret_cast(base)); michael@0: } michael@0: static void incRef(android_native_base_t* base) { michael@0: EGLNativeBase* self = getSelf(base); michael@0: self->incStrong(self); michael@0: } michael@0: static void decRef(android_native_base_t* base) { michael@0: EGLNativeBase* self = getSelf(base); michael@0: self->decStrong(self); michael@0: } michael@0: }; michael@0: michael@0: } // namespace android michael@0: #endif // __cplusplus michael@0: michael@0: /*****************************************************************************/ michael@0: michael@0: #endif /* ANDROID_ANDROID_NATIVES_H */