2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <sys/cdefs.h>
23 #include <system/graphics-base.h>
24 #include <cutils/native_handle.h>
29 #define ANDROID_NATIVE_UNSIGNED_CAST(x) static_cast<unsigned int>(x)
31 #define ANDROID_NATIVE_UNSIGNED_CAST(x) ((unsigned int)(x))
34 #define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \
35 ((ANDROID_NATIVE_UNSIGNED_CAST(a) << 24) | \
36 (ANDROID_NATIVE_UNSIGNED_CAST(b) << 16) | \
37 (ANDROID_NATIVE_UNSIGNED_CAST(c) << 8) | \
38 (ANDROID_NATIVE_UNSIGNED_CAST(d)))
40 #define ANDROID_NATIVE_BUFFER_MAGIC ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r')
43 typedef struct android_native_base_t
45 /* a magic value defined by the actual EGL native type */
48 /* the sizeof() of the actual EGL native type */
53 /* reference-counting interface */
54 void (*incRef
)(struct android_native_base_t
* base
);
55 void (*decRef
)(struct android_native_base_t
* base
);
56 } android_native_base_t
;
58 typedef struct android_native_rect_t
64 } android_native_rect_t
;
66 typedef struct ANativeWindowBuffer
69 ANativeWindowBuffer() {
70 common
.magic
= ANDROID_NATIVE_BUFFER_MAGIC
;
71 common
.version
= sizeof(ANativeWindowBuffer
);
72 memset(common
.reserved
, 0, sizeof(common
.reserved
));
75 // Implement the methods that sp<ANativeWindowBuffer> expects so that it
76 // can be used to automatically refcount ANativeWindowBuffer's.
77 void incStrong(const void* /*id*/) const {
78 common
.incRef(const_cast<android_native_base_t
*>(&common
));
80 void decStrong(const void* /*id*/) const {
81 common
.decRef(const_cast<android_native_base_t
*>(&common
));
85 struct android_native_base_t common
;
96 const native_handle_t
* handle
;
99 // we needed extra space for storing the 64-bits usage flags
100 // the number of slots to use from reserved_proc depends on the
102 void* reserved_proc
[8 - (sizeof(uint64_t) / sizeof(void*))];
103 } ANativeWindowBuffer_t
;
105 typedef struct ANativeWindowBuffer ANativeWindowBuffer
;
107 // Old typedef for backwards compatibility.
108 typedef ANativeWindowBuffer_t android_native_buffer_t
;