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