• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 #pragma once
17 #include <stdint.h>
18 #include <stdbool.h>
19 #include <string.h>
20 #include <sys/cdefs.h>
21 #include <system/graphics-base.h>
22 #include <cutils/native_handle.h>
23 __BEGIN_DECLS
24 #ifdef __cplusplus
25 #define ANDROID_NATIVE_UNSIGNED_CAST(x) static_cast<unsigned int>(x)
26 #else
27 #define ANDROID_NATIVE_UNSIGNED_CAST(x) ((unsigned int)(x))
28 #endif
29 #define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d)  \
30     ((ANDROID_NATIVE_UNSIGNED_CAST(a) << 24) | \
31      (ANDROID_NATIVE_UNSIGNED_CAST(b) << 16) | \
32      (ANDROID_NATIVE_UNSIGNED_CAST(c) <<  8) | \
33      (ANDROID_NATIVE_UNSIGNED_CAST(d)))
34 #define ANDROID_NATIVE_BUFFER_MAGIC     ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r')
35 typedef struct android_native_base_t
36 {
37     /* a magic value defined by the actual EGL native type */
38     int magic;
39     /* the sizeof() of the actual EGL native type */
40     int version;
41     void* reserved[4];
42     /* reference-counting interface */
43     void (*incRef)(struct android_native_base_t* base);
44     void (*decRef)(struct android_native_base_t* base);
45 } android_native_base_t;
46 typedef struct android_native_rect_t
47 {
48     int32_t left;
49     int32_t top;
50     int32_t right;
51     int32_t bottom;
52 } android_native_rect_t;
53 typedef struct ANativeWindowBuffer
54 {
55 #ifdef __cplusplus
ANativeWindowBufferANativeWindowBuffer56     ANativeWindowBuffer() {
57         common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
58         common.version = sizeof(ANativeWindowBuffer);
59         memset(common.reserved, 0, sizeof(common.reserved));
60     }
61     // Implement the methods that sp<ANativeWindowBuffer> expects so that it
62     // can be used to automatically refcount ANativeWindowBuffer's.
incStrongANativeWindowBuffer63     void incStrong(const void* /*id*/) const {
64         common.incRef(const_cast<android_native_base_t*>(&common));
65     }
decStrongANativeWindowBuffer66     void decStrong(const void* /*id*/) const {
67         common.decRef(const_cast<android_native_base_t*>(&common));
68     }
69 #endif
70     struct android_native_base_t common;
71     int width;
72     int height;
73     int stride;
74     int format;
75     int usage_deprecated;
76     uintptr_t layerCount;
77     void* reserved[1];
78     const native_handle_t* handle;
79     uint64_t usage;
80     // we needed extra space for storing the 64-bits usage flags
81     // the number of slots to use from reserved_proc depends on the
82     // architecture.
83     void* reserved_proc[8 - (sizeof(uint64_t) / sizeof(void*))];
84 } ANativeWindowBuffer_t;
85 typedef struct ANativeWindowBuffer ANativeWindowBuffer;
86 // Old typedef for backwards compatibility.
87 typedef ANativeWindowBuffer_t android_native_buffer_t;
88 __END_DECLS
89