17ec681f3Smrg/* 27ec681f3Smrg * Copyright (C) 2017 The Android Open Source Project 37ec681f3Smrg * 47ec681f3Smrg * Licensed under the Apache License, Version 2.0 (the "License"); 57ec681f3Smrg * you may not use this file except in compliance with the License. 67ec681f3Smrg * You may obtain a copy of the License at 77ec681f3Smrg * 87ec681f3Smrg * http://www.apache.org/licenses/LICENSE-2.0 97ec681f3Smrg * 107ec681f3Smrg * Unless required by applicable law or agreed to in writing, software 117ec681f3Smrg * distributed under the License is distributed on an "AS IS" BASIS, 127ec681f3Smrg * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137ec681f3Smrg * See the License for the specific language governing permissions and 147ec681f3Smrg * limitations under the License. 157ec681f3Smrg */ 167ec681f3Smrg 177ec681f3Smrg#pragma once 187ec681f3Smrg 197ec681f3Smrg#include <stdint.h> 207ec681f3Smrg#include <stdbool.h> 217ec681f3Smrg#include <string.h> 227ec681f3Smrg#include <sys/cdefs.h> 237ec681f3Smrg#include <system/graphics-base.h> 247ec681f3Smrg#include <cutils/native_handle.h> 257ec681f3Smrg 267ec681f3Smrg__BEGIN_DECLS 277ec681f3Smrg 287ec681f3Smrg#ifdef __cplusplus 297ec681f3Smrg#define ANDROID_NATIVE_UNSIGNED_CAST(x) static_cast<unsigned int>(x) 307ec681f3Smrg#else 317ec681f3Smrg#define ANDROID_NATIVE_UNSIGNED_CAST(x) ((unsigned int)(x)) 327ec681f3Smrg#endif 337ec681f3Smrg 347ec681f3Smrg#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \ 357ec681f3Smrg ((ANDROID_NATIVE_UNSIGNED_CAST(a) << 24) | \ 367ec681f3Smrg (ANDROID_NATIVE_UNSIGNED_CAST(b) << 16) | \ 377ec681f3Smrg (ANDROID_NATIVE_UNSIGNED_CAST(c) << 8) | \ 387ec681f3Smrg (ANDROID_NATIVE_UNSIGNED_CAST(d))) 397ec681f3Smrg 407ec681f3Smrg#define ANDROID_NATIVE_BUFFER_MAGIC ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r') 417ec681f3Smrg 427ec681f3Smrg 437ec681f3Smrgtypedef struct android_native_base_t 447ec681f3Smrg{ 457ec681f3Smrg /* a magic value defined by the actual EGL native type */ 467ec681f3Smrg int magic; 477ec681f3Smrg 487ec681f3Smrg /* the sizeof() of the actual EGL native type */ 497ec681f3Smrg int version; 507ec681f3Smrg 517ec681f3Smrg void* reserved[4]; 527ec681f3Smrg 537ec681f3Smrg /* reference-counting interface */ 547ec681f3Smrg void (*incRef)(struct android_native_base_t* base); 557ec681f3Smrg void (*decRef)(struct android_native_base_t* base); 567ec681f3Smrg} android_native_base_t; 577ec681f3Smrg 587ec681f3Smrgtypedef struct android_native_rect_t 597ec681f3Smrg{ 607ec681f3Smrg int32_t left; 617ec681f3Smrg int32_t top; 627ec681f3Smrg int32_t right; 637ec681f3Smrg int32_t bottom; 647ec681f3Smrg} android_native_rect_t; 657ec681f3Smrg 667ec681f3Smrgtypedef struct ANativeWindowBuffer 677ec681f3Smrg{ 687ec681f3Smrg#ifdef __cplusplus 697ec681f3Smrg ANativeWindowBuffer() { 707ec681f3Smrg common.magic = ANDROID_NATIVE_BUFFER_MAGIC; 717ec681f3Smrg common.version = sizeof(ANativeWindowBuffer); 727ec681f3Smrg memset(common.reserved, 0, sizeof(common.reserved)); 737ec681f3Smrg } 747ec681f3Smrg 757ec681f3Smrg // Implement the methods that sp<ANativeWindowBuffer> expects so that it 767ec681f3Smrg // can be used to automatically refcount ANativeWindowBuffer's. 777ec681f3Smrg void incStrong(const void* /*id*/) const { 787ec681f3Smrg common.incRef(const_cast<android_native_base_t*>(&common)); 797ec681f3Smrg } 807ec681f3Smrg void decStrong(const void* /*id*/) const { 817ec681f3Smrg common.decRef(const_cast<android_native_base_t*>(&common)); 827ec681f3Smrg } 837ec681f3Smrg#endif 847ec681f3Smrg 857ec681f3Smrg struct android_native_base_t common; 867ec681f3Smrg 877ec681f3Smrg int width; 887ec681f3Smrg int height; 897ec681f3Smrg int stride; 907ec681f3Smrg int format; 917ec681f3Smrg int usage_deprecated; 927ec681f3Smrg uintptr_t layerCount; 937ec681f3Smrg 947ec681f3Smrg void* reserved[1]; 957ec681f3Smrg 967ec681f3Smrg const native_handle_t* handle; 977ec681f3Smrg uint64_t usage; 987ec681f3Smrg 997ec681f3Smrg // we needed extra space for storing the 64-bits usage flags 1007ec681f3Smrg // the number of slots to use from reserved_proc depends on the 1017ec681f3Smrg // architecture. 1027ec681f3Smrg void* reserved_proc[8 - (sizeof(uint64_t) / sizeof(void*))]; 1037ec681f3Smrg} ANativeWindowBuffer_t; 1047ec681f3Smrg 1057ec681f3Smrgtypedef struct ANativeWindowBuffer ANativeWindowBuffer; 1067ec681f3Smrg 1077ec681f3Smrg// Old typedef for backwards compatibility. 1087ec681f3Smrgtypedef ANativeWindowBuffer_t android_native_buffer_t; 1097ec681f3Smrg 1107ec681f3Smrg__END_DECLS 111