1 /*
2  * Copyright (C) 2018 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 <cutils/native_handle.h>
20 
21 #include <cstdint>
22 #include <cstring>
23 
24 // clang-format off
25 #define ANDROID_NATIVE_MAKE_CONSTANT(a, b, c, d) \
26     ((static_cast<unsigned int>(a) << 24) | \
27      (static_cast<unsigned int>(b) << 16) | \
28      (static_cast<unsigned int>(c) <<  8) | \
29      (static_cast<unsigned int>(d) <<  0))
30 // clang-format on
31 
32 struct android_native_base_t {
33     int magic;
34     int version;
35     void* reserved[4];
36     void (*incRef)(android_native_base_t*);
37     void (*decRef)(android_native_base_t*);
38 };
39 
40 #define ANDROID_NATIVE_BUFFER_MAGIC ANDROID_NATIVE_MAKE_CONSTANT('_', 'b', 'f', 'r')
41 
42 struct ANativeWindowBuffer {
ANativeWindowBufferANativeWindowBuffer43     ANativeWindowBuffer() {
44         common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
45         common.version = sizeof(ANativeWindowBuffer);
46         memset(common.reserved, 0, sizeof(common.reserved));
47     }
48 
49     android_native_base_t common;
50 
51     int width;
52     int height;
53     int stride;
54     int format;
55     int usage_deprecated;
56     uintptr_t layerCount;
57 
58     void* reserved[1];
59 
60     const native_handle_t* handle;
61     uint64_t usage;
62 
63     void* reserved_proc[8 - (sizeof(uint64_t) / sizeof(void*))];
64 };
65