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
17#pragma once
18
19#include <stdint.h>
20#include <stdbool.h>
21#include <string.h>
22#include <sys/cdefs.h>
23#include <system/graphics-base.h>
24#include <cutils/native_handle.h>
25
26__BEGIN_DECLS
27
28#ifdef __cplusplus
29#define ANDROID_NATIVE_UNSIGNED_CAST(x) static_cast<unsigned int>(x)
30#else
31#define ANDROID_NATIVE_UNSIGNED_CAST(x) ((unsigned int)(x))
32#endif
33
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)))
39
40#define ANDROID_NATIVE_BUFFER_MAGIC     ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r')
41
42
43typedef struct android_native_base_t
44{
45    /* a magic value defined by the actual EGL native type */
46    int magic;
47
48    /* the sizeof() of the actual EGL native type */
49    int version;
50
51    void* reserved[4];
52
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;
57
58typedef struct android_native_rect_t
59{
60    int32_t left;
61    int32_t top;
62    int32_t right;
63    int32_t bottom;
64} android_native_rect_t;
65
66typedef struct ANativeWindowBuffer
67{
68#ifdef __cplusplus
69    ANativeWindowBuffer() {
70        common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
71        common.version = sizeof(ANativeWindowBuffer);
72        memset(common.reserved, 0, sizeof(common.reserved));
73    }
74
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));
79    }
80    void decStrong(const void* /*id*/) const {
81        common.decRef(const_cast<android_native_base_t*>(&common));
82    }
83#endif
84
85    struct android_native_base_t common;
86
87    int width;
88    int height;
89    int stride;
90    int format;
91    int usage_deprecated;
92    uintptr_t layerCount;
93
94    void* reserved[1];
95
96    const native_handle_t* handle;
97    uint64_t usage;
98
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
101    // architecture.
102    void* reserved_proc[8 - (sizeof(uint64_t) / sizeof(void*))];
103} ANativeWindowBuffer_t;
104
105typedef struct ANativeWindowBuffer ANativeWindowBuffer;
106
107// Old typedef for backwards compatibility.
108typedef ANativeWindowBuffer_t android_native_buffer_t;
109
110__END_DECLS
111