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 #ifndef ANDROID_PRIVATE_NATIVE_AHARDWARE_BUFFER_HELPERS_H
18 #define ANDROID_PRIVATE_NATIVE_AHARDWARE_BUFFER_HELPERS_H
19 
20 /*
21  * This file contains utility functions related to AHardwareBuffer, mostly to
22  * convert to/from HAL formats.
23  *
24  * These are PRIVATE methods, so this file can NEVER appear in a public NDK
25  * header. They are used by higher level libraries such as core/jni.
26  */
27 
28 #include <stdint.h>
29 
30 struct AHardwareBuffer;
31 struct AHardwareBuffer_Desc;
32 struct ANativeWindowBuffer;
33 
34 namespace android {
35 
36 // Validates whether the passed description does not have conflicting
37 // parameters. Note: this does not verify any platform-specific contraints.
38 bool AHardwareBuffer_isValidDescription(const AHardwareBuffer_Desc* desc, bool log);
39 
40 // whether this AHardwareBuffer format is valid
41 bool AHardwareBuffer_isValidPixelFormat(uint32_t ahardwarebuffer_format);
42 
43 // whether this is a YUV type format
44 bool AHardwareBuffer_formatIsYuv(uint32_t format);
45 
46 // number of bytes per pixel or 0 if unknown or multi-planar
47 uint32_t AHardwareBuffer_bytesPerPixel(uint32_t format);
48 
49 // convert AHardwareBuffer format to HAL format (note: this is a no-op)
50 uint32_t AHardwareBuffer_convertFromPixelFormat(uint32_t format);
51 
52 // convert HAL format to AHardwareBuffer format (note: this is a no-op)
53 uint32_t AHardwareBuffer_convertToPixelFormat(uint32_t format);
54 
55 // convert AHardwareBuffer usage bits to HAL usage bits (note: this is a no-op)
56 uint64_t AHardwareBuffer_convertFromGrallocUsageBits(uint64_t usage);
57 
58 // convert HAL usage bits to AHardwareBuffer usage bits  (note: this is a no-op)
59 uint64_t AHardwareBuffer_convertToGrallocUsageBits(uint64_t usage);
60 
61 class GraphicBuffer;
62 const GraphicBuffer* AHardwareBuffer_to_GraphicBuffer(const AHardwareBuffer* buffer);
63 GraphicBuffer* AHardwareBuffer_to_GraphicBuffer(AHardwareBuffer* buffer);
64 
65 const ANativeWindowBuffer* AHardwareBuffer_to_ANativeWindowBuffer(const AHardwareBuffer* buffer);
66 ANativeWindowBuffer* AHardwareBuffer_to_ANativeWindowBuffer(AHardwareBuffer* buffer);
67 
68 AHardwareBuffer* AHardwareBuffer_from_GraphicBuffer(GraphicBuffer* buffer);
69 } // namespace android
70 
71 #endif // ANDROID_PRIVATE_NATIVE_AHARDWARE_BUFFER_HELPERS_H
72