| 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> | 
| Iliyan Malchev | ec10d23 | 2011-05-02 09:29:44 -0700 | [diff] [blame] | 24 | #include <system/window.h> | 
|  | 25 | // FIXME: remove this header, it's for legacy use.  native_window is pulled from frameworks/base/native/include/android/ | 
| Dianne Hackborn | 4b5e91e | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 26 | #include <android/native_window.h> | 
| Mathias Agopian | aa8c0ff | 2009-05-05 18:29:35 -0700 | [diff] [blame] | 27 | // --------------------------------------------------------------------------- | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 28 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 29 | /* FIXME: this is legacy for pixmaps */ | 
| Mathias Agopian | 238a66e | 2009-08-13 17:57:53 -0700 | [diff] [blame] | 30 | typedef struct egl_native_pixmap_t | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 31 | { | 
|  | 32 | int32_t     version;    /* must be 32 */ | 
|  | 33 | int32_t     width; | 
|  | 34 | int32_t     height; | 
|  | 35 | int32_t     stride; | 
|  | 36 | uint8_t*    data; | 
|  | 37 | uint8_t     format; | 
|  | 38 | uint8_t     rfu[3]; | 
|  | 39 | union { | 
|  | 40 | uint32_t    compressedFormat; | 
|  | 41 | int32_t     vstride; | 
|  | 42 | }; | 
|  | 43 | int32_t     reserved; | 
| Mathias Agopian | 238a66e | 2009-08-13 17:57:53 -0700 | [diff] [blame] | 44 | } egl_native_pixmap_t; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 45 |  | 
|  | 46 | /*****************************************************************************/ | 
|  | 47 |  | 
|  | 48 | #ifdef __cplusplus | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 49 |  | 
|  | 50 | #include <utils/RefBase.h> | 
|  | 51 |  | 
|  | 52 | namespace android { | 
|  | 53 |  | 
|  | 54 | /* | 
|  | 55 | * This helper class turns an EGL android_native_xxx type into a C++ | 
|  | 56 | * reference-counted object; with proper type conversions. | 
|  | 57 | */ | 
|  | 58 | template <typename NATIVE_TYPE, typename TYPE, typename REF> | 
|  | 59 | class EGLNativeBase : public NATIVE_TYPE, public REF | 
|  | 60 | { | 
| Jamie Gennis | 5e67f87 | 2010-05-10 17:33:32 -0700 | [diff] [blame] | 61 | public: | 
|  | 62 | // Disambiguate between the incStrong in REF and NATIVE_TYPE | 
|  | 63 | void incStrong(const void* id) const { | 
|  | 64 | REF::incStrong(id); | 
|  | 65 | } | 
|  | 66 | void decStrong(const void* id) const { | 
|  | 67 | REF::decStrong(id); | 
|  | 68 | } | 
|  | 69 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 70 | protected: | 
|  | 71 | typedef EGLNativeBase<NATIVE_TYPE, TYPE, REF> BASE; | 
|  | 72 | EGLNativeBase() : NATIVE_TYPE(), REF() { | 
|  | 73 | NATIVE_TYPE::common.incRef = incRef; | 
|  | 74 | NATIVE_TYPE::common.decRef = decRef; | 
|  | 75 | } | 
|  | 76 | static inline TYPE* getSelf(NATIVE_TYPE* self) { | 
|  | 77 | return static_cast<TYPE*>(self); | 
|  | 78 | } | 
|  | 79 | static inline TYPE const* getSelf(NATIVE_TYPE const* self) { | 
|  | 80 | return static_cast<TYPE const *>(self); | 
|  | 81 | } | 
|  | 82 | static inline TYPE* getSelf(android_native_base_t* base) { | 
|  | 83 | return getSelf(reinterpret_cast<NATIVE_TYPE*>(base)); | 
|  | 84 | } | 
|  | 85 | static inline TYPE const * getSelf(android_native_base_t const* base) { | 
|  | 86 | return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base)); | 
|  | 87 | } | 
|  | 88 | static void incRef(android_native_base_t* base) { | 
|  | 89 | EGLNativeBase* self = getSelf(base); | 
|  | 90 | self->incStrong(self); | 
|  | 91 | } | 
|  | 92 | static void decRef(android_native_base_t* base) { | 
|  | 93 | EGLNativeBase* self = getSelf(base); | 
|  | 94 | self->decStrong(self); | 
|  | 95 | } | 
|  | 96 | }; | 
|  | 97 |  | 
|  | 98 | } // namespace android | 
|  | 99 | #endif // __cplusplus | 
|  | 100 |  | 
|  | 101 | /*****************************************************************************/ | 
|  | 102 |  | 
|  | 103 | #endif /* ANDROID_ANDROID_NATIVES_H */ |