1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2017 The Android Open Source Project 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 5bf215546Sopenharmony_ci * you may not use this file except in compliance with the License. 6bf215546Sopenharmony_ci * You may obtain a copy of the License at 7bf215546Sopenharmony_ci * 8bf215546Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 9bf215546Sopenharmony_ci * 10bf215546Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 11bf215546Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 12bf215546Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bf215546Sopenharmony_ci * See the License for the specific language governing permissions and 14bf215546Sopenharmony_ci * limitations under the License. 15bf215546Sopenharmony_ci */ 16bf215546Sopenharmony_ci 17bf215546Sopenharmony_ci#pragma once 18bf215546Sopenharmony_ci 19bf215546Sopenharmony_ci#include <stdint.h> 20bf215546Sopenharmony_ci#include <stdbool.h> 21bf215546Sopenharmony_ci#include <string.h> 22bf215546Sopenharmony_ci#include <sys/cdefs.h> 23bf215546Sopenharmony_ci#include <system/graphics-base.h> 24bf215546Sopenharmony_ci#include <cutils/native_handle.h> 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci__BEGIN_DECLS 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#ifdef __cplusplus 29bf215546Sopenharmony_ci#define ANDROID_NATIVE_UNSIGNED_CAST(x) static_cast<unsigned int>(x) 30bf215546Sopenharmony_ci#else 31bf215546Sopenharmony_ci#define ANDROID_NATIVE_UNSIGNED_CAST(x) ((unsigned int)(x)) 32bf215546Sopenharmony_ci#endif 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \ 35bf215546Sopenharmony_ci ((ANDROID_NATIVE_UNSIGNED_CAST(a) << 24) | \ 36bf215546Sopenharmony_ci (ANDROID_NATIVE_UNSIGNED_CAST(b) << 16) | \ 37bf215546Sopenharmony_ci (ANDROID_NATIVE_UNSIGNED_CAST(c) << 8) | \ 38bf215546Sopenharmony_ci (ANDROID_NATIVE_UNSIGNED_CAST(d))) 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ci#define ANDROID_NATIVE_BUFFER_MAGIC ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r') 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_citypedef struct android_native_base_t 44bf215546Sopenharmony_ci{ 45bf215546Sopenharmony_ci /* a magic value defined by the actual EGL native type */ 46bf215546Sopenharmony_ci int magic; 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci /* the sizeof() of the actual EGL native type */ 49bf215546Sopenharmony_ci int version; 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci void* reserved[4]; 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ci /* reference-counting interface */ 54bf215546Sopenharmony_ci void (*incRef)(struct android_native_base_t* base); 55bf215546Sopenharmony_ci void (*decRef)(struct android_native_base_t* base); 56bf215546Sopenharmony_ci} android_native_base_t; 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_citypedef struct android_native_rect_t 59bf215546Sopenharmony_ci{ 60bf215546Sopenharmony_ci int32_t left; 61bf215546Sopenharmony_ci int32_t top; 62bf215546Sopenharmony_ci int32_t right; 63bf215546Sopenharmony_ci int32_t bottom; 64bf215546Sopenharmony_ci} android_native_rect_t; 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_citypedef struct ANativeWindowBuffer 67bf215546Sopenharmony_ci{ 68bf215546Sopenharmony_ci#ifdef __cplusplus 69bf215546Sopenharmony_ci ANativeWindowBuffer() { 70bf215546Sopenharmony_ci common.magic = ANDROID_NATIVE_BUFFER_MAGIC; 71bf215546Sopenharmony_ci common.version = sizeof(ANativeWindowBuffer); 72bf215546Sopenharmony_ci memset(common.reserved, 0, sizeof(common.reserved)); 73bf215546Sopenharmony_ci } 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci // Implement the methods that sp<ANativeWindowBuffer> expects so that it 76bf215546Sopenharmony_ci // can be used to automatically refcount ANativeWindowBuffer's. 77bf215546Sopenharmony_ci void incStrong(const void* /*id*/) const { 78bf215546Sopenharmony_ci common.incRef(const_cast<android_native_base_t*>(&common)); 79bf215546Sopenharmony_ci } 80bf215546Sopenharmony_ci void decStrong(const void* /*id*/) const { 81bf215546Sopenharmony_ci common.decRef(const_cast<android_native_base_t*>(&common)); 82bf215546Sopenharmony_ci } 83bf215546Sopenharmony_ci#endif 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci struct android_native_base_t common; 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_ci int width; 88bf215546Sopenharmony_ci int height; 89bf215546Sopenharmony_ci int stride; 90bf215546Sopenharmony_ci int format; 91bf215546Sopenharmony_ci int usage_deprecated; 92bf215546Sopenharmony_ci uintptr_t layerCount; 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_ci void* reserved[1]; 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci const native_handle_t* handle; 97bf215546Sopenharmony_ci uint64_t usage; 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_ci // we needed extra space for storing the 64-bits usage flags 100bf215546Sopenharmony_ci // the number of slots to use from reserved_proc depends on the 101bf215546Sopenharmony_ci // architecture. 102bf215546Sopenharmony_ci void* reserved_proc[8 - (sizeof(uint64_t) / sizeof(void*))]; 103bf215546Sopenharmony_ci} ANativeWindowBuffer_t; 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_citypedef struct ANativeWindowBuffer ANativeWindowBuffer; 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ci// Old typedef for backwards compatibility. 108bf215546Sopenharmony_citypedef ANativeWindowBuffer_t android_native_buffer_t; 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci__END_DECLS 111