blob: 76e850fa279abace05d5eb5977982686ba641594 [file] [log] [blame]
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001/*
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 Malchevec10d232011-05-02 09:29:44 -070024#include <system/window.h>
Mathias Agopian5f2165f2012-02-24 18:25:41 -080025
Mathias Agopianaa8c0ff2009-05-05 18:29:35 -070026// ---------------------------------------------------------------------------
Mathias Agopian076b1cc2009-04-10 14:24:30 -070027
Mathias Agopian076b1cc2009-04-10 14:24:30 -070028/* FIXME: this is legacy for pixmaps */
Mathias Agopian238a66e2009-08-13 17:57:53 -070029typedef struct egl_native_pixmap_t
Mathias Agopian076b1cc2009-04-10 14:24:30 -070030{
31 int32_t version; /* must be 32 */
32 int32_t width;
33 int32_t height;
34 int32_t stride;
35 uint8_t* data;
36 uint8_t format;
37 uint8_t rfu[3];
38 union {
39 uint32_t compressedFormat;
40 int32_t vstride;
41 };
42 int32_t reserved;
Mathias Agopian238a66e2009-08-13 17:57:53 -070043} egl_native_pixmap_t;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070044
45/*****************************************************************************/
46
47#ifdef __cplusplus
Mathias Agopian076b1cc2009-04-10 14:24:30 -070048
49#include <utils/RefBase.h>
50
51namespace android {
52
53/*
Mathias Agopian5f2165f2012-02-24 18:25:41 -080054 * This helper class turns a ANativeXXX object type into a C++
Mathias Agopian076b1cc2009-04-10 14:24:30 -070055 * reference-counted object; with proper type conversions.
56 */
57template <typename NATIVE_TYPE, typename TYPE, typename REF>
Mathias Agopian5f2165f2012-02-24 18:25:41 -080058class ANativeObjectBase : public NATIVE_TYPE, public REF
Mathias Agopian076b1cc2009-04-10 14:24:30 -070059{
Jamie Gennis5e67f872010-05-10 17:33:32 -070060public:
61 // Disambiguate between the incStrong in REF and NATIVE_TYPE
62 void incStrong(const void* id) const {
63 REF::incStrong(id);
64 }
65 void decStrong(const void* id) const {
66 REF::decStrong(id);
67 }
68
Mathias Agopian076b1cc2009-04-10 14:24:30 -070069protected:
Mathias Agopian5f2165f2012-02-24 18:25:41 -080070 typedef ANativeObjectBase<NATIVE_TYPE, TYPE, REF> BASE;
71 ANativeObjectBase() : NATIVE_TYPE(), REF() {
Mathias Agopian076b1cc2009-04-10 14:24:30 -070072 NATIVE_TYPE::common.incRef = incRef;
73 NATIVE_TYPE::common.decRef = decRef;
74 }
75 static inline TYPE* getSelf(NATIVE_TYPE* self) {
76 return static_cast<TYPE*>(self);
77 }
78 static inline TYPE const* getSelf(NATIVE_TYPE const* self) {
79 return static_cast<TYPE const *>(self);
80 }
81 static inline TYPE* getSelf(android_native_base_t* base) {
82 return getSelf(reinterpret_cast<NATIVE_TYPE*>(base));
83 }
84 static inline TYPE const * getSelf(android_native_base_t const* base) {
85 return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base));
86 }
87 static void incRef(android_native_base_t* base) {
Mathias Agopian5f2165f2012-02-24 18:25:41 -080088 ANativeObjectBase* self = getSelf(base);
Mathias Agopian076b1cc2009-04-10 14:24:30 -070089 self->incStrong(self);
90 }
91 static void decRef(android_native_base_t* base) {
Mathias Agopian5f2165f2012-02-24 18:25:41 -080092 ANativeObjectBase* self = getSelf(base);
Mathias Agopian076b1cc2009-04-10 14:24:30 -070093 self->decStrong(self);
94 }
95};
96
97} // namespace android
98#endif // __cplusplus
99
100/*****************************************************************************/
101
102#endif /* ANDROID_ANDROID_NATIVES_H */