• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017-2020 ARM Limited. All rights reserved.
3  *
4  * Copyright (C) 2008 The Android Open Source Project
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef MALI_GRALLOC_USAGES_H_
20 #define MALI_GRALLOC_USAGES_H_
21 
22 #define GRALLOC_USAGE_PRIVATE_MASK (0xffff0000f0000000U)
23 #define GRALLOC_USAGE_PUBLIC_MASK  ((uint64_t) ~GRALLOC_USAGE_PRIVATE_MASK)
24 
25 /*
26  * MALI_GRALLOC_USAGE_AFBC_PADDING is only valid if MALI_GRALLOC_USAGE_NO_AFBC
27  * is not present.
28  */
29 
30 #include <aidl/android/hardware/graphics/common/BufferUsage.h>
31 #include <android/hardware/graphics/common/1.2/types.h>
32 #include <pixel-gralloc/usage.h>
33 
34 /* BufferUsage is not defined in 1.2/types.h as there are no changes from previous version */
35 namespace hidl_common = android::hardware::graphics::common::V1_1;
36 namespace aidl_common = aidl::android::hardware::graphics::common;
37 
38 /* Local macro definitions to emulate Gralloc 1.0 usage interface */
39 #define GRALLOC_USAGE_PRIVATE_0 1ULL << 28
40 #define GRALLOC_USAGE_PRIVATE_1 1ULL << 29
41 #define GRALLOC_USAGE_PRIVATE_2 1ULL << 30
42 #define GRALLOC_USAGE_PRIVATE_3 1ULL << 31
43 #define GRALLOC_USAGE_PRIVATE_4 1ULL << 63
44 #define GRALLOC_USAGE_PRIVATE_5 1ULL << 62
45 #define GRALLOC_USAGE_PRIVATE_6 1ULL << 61
46 #define GRALLOC_USAGE_PRIVATE_7 1ULL << 60
47 #define GRALLOC_USAGE_PRIVATE_8 1ULL << 59
48 #define GRALLOC_USAGE_PRIVATE_9 1ULL << 58
49 #define GRALLOC_USAGE_PRIVATE_10 1ULL << 57
50 #define GRALLOC_USAGE_PRIVATE_11 1ULL << 56
51 #define GRALLOC_USAGE_PRIVATE_12 1ULL << 55
52 #define GRALLOC_USAGE_PRIVATE_13 1ULL << 54
53 #define GRALLOC_USAGE_PRIVATE_14 1ULL << 53
54 #define GRALLOC_USAGE_PRIVATE_15 1ULL << 52
55 #define GRALLOC_USAGE_PRIVATE_16 1ULL << 51
56 #define GRALLOC_USAGE_PRIVATE_17 1ULL << 50
57 #define GRALLOC_USAGE_PRIVATE_18 1ULL << 49
58 #define GRALLOC_USAGE_PRIVATE_19 1ULL << 48
59 
60 // TODO(b/183478446): Cleanup usage flags redefinition
61 typedef enum
62 {
63 	DEPRECATED_MALI_GRALLOC_USAGE_FRONTBUFFER = GRALLOC_USAGE_PRIVATE_12,
64 	MALI_GRALLOC_USAGE_FORCE_BACKBUFFER = GRALLOC_USAGE_PRIVATE_13,
65 	MALI_GRALLOC_USAGE_NO_AFBC = GRALLOC_USAGE_PRIVATE_1,
66 	MALI_GRALLOC_USAGE_AFBC_PADDING = GRALLOC_USAGE_PRIVATE_14,
67 
68 	/* SLSI specific usages */
69 	GRALLOC_USAGE_PRIVATE_NONSECURE                        = GRALLOC_USAGE_PRIVATE_8,
70 	GRALLOC_USAGE_NOZEROED                                 = GRALLOC_USAGE_PRIVATE_9,
71 
72 	GRALLOC_USAGE_VIDEO_PRIVATE_DATA                       = GRALLOC_USAGE_PRIVATE_7,
73 
74 	GRALLOC_USAGE_ROIINFO                                  = GRALLOC_USAGE_PRIVATE_15,
75 
76 	/* Google specific usages */
77 	GRALLOC_USAGE_GOOGLE_IP_BO                             = GRALLOC_USAGE_PRIVATE_16,
78 	GRALLOC_USAGE_GOOGLE_IP_BW                             = GRALLOC_USAGE_PRIVATE_16, /* Alias to BO */
79 	GRALLOC_USAGE_GOOGLE_IP_BIG                            = GRALLOC_USAGE_PRIVATE_16, /* Alias to BO/BW */
80 	GRALLOC_USAGE_GOOGLE_IP_MFC                            = GRALLOC_USAGE_PRIVATE_17,
81 	GRALLOC_USAGE_PLACEHOLDER_BUFFER                       = ::pixel::graphics::Usage::PLACEHOLDER_BUFFER,
82 
83 	/* FaceAuth specific usages. */
84 	GS101_GRALLOC_USAGE_TPU_INPUT                          = GRALLOC_USAGE_PRIVATE_5,
85 	GS101_GRALLOC_USAGE_TPU_OUTPUT                         = GRALLOC_USAGE_PRIVATE_3,
86 	GS101_GRALLOC_USAGE_CAMERA_STATS                       = GRALLOC_USAGE_PRIVATE_2,
87 
88 	GS101_GRALLOC_USAGE_FACEAUTH_RAW_EVAL                  = ::pixel::graphics::Usage::FACEAUTH_RAW_EVAL,
89 } mali_gralloc_usage_type;
90 
91 #define GRALLOC_USAGE_SW_WRITE_RARELY static_cast<uint64_t>(hidl_common::BufferUsage::CPU_WRITE_RARELY)
92 #define GRALLOC_USAGE_SW_WRITE_OFTEN static_cast<uint64_t>(hidl_common::BufferUsage::CPU_WRITE_OFTEN)
93 #define GRALLOC_USAGE_SW_READ_RARELY static_cast<uint64_t>(hidl_common::BufferUsage::CPU_READ_RARELY)
94 #define GRALLOC_USAGE_SW_READ_OFTEN static_cast<uint64_t>(hidl_common::BufferUsage::CPU_READ_OFTEN)
95 #define GRALLOC_USAGE_RENDERSCRIPT static_cast<uint64_t>(hidl_common::BufferUsage::RENDERSCRIPT)
96 #define GRALLOC_USAGE_HW_FB static_cast<uint64_t>(hidl_common::BufferUsage::COMPOSER_CLIENT_TARGET)
97 
98 /* Bit 10 must be zero as per Gralloc 2.x interface specification. Used, however, for backward compatibility */
99 #define GRALLOC_USAGE_HW_2D  static_cast<uint64_t>(0x00000400)
100 
101 #define GRALLOC_USAGE_SW_WRITE_MASK static_cast<uint64_t>(hidl_common::BufferUsage::CPU_WRITE_MASK)
102 #define GRALLOC_USAGE_SW_READ_MASK static_cast<uint64_t>(hidl_common::BufferUsage::CPU_READ_MASK)
103 #define GRALLOC_USAGE_PROTECTED static_cast<uint64_t>(hidl_common::BufferUsage::PROTECTED)
104 #define GRALLOC_USAGE_CURSOR static_cast<uint64_t>(hidl_common::BufferUsage::COMPOSER_CURSOR)
105 #define GRALLOC_USAGE_HW_RENDER static_cast<uint64_t>(hidl_common::BufferUsage::GPU_RENDER_TARGET)
106 #define GRALLOC_USAGE_HW_CAMERA_WRITE static_cast<uint64_t>(hidl_common::BufferUsage::CAMERA_OUTPUT)
107 #define GRALLOC_USAGE_HW_CAMERA_READ static_cast<uint64_t>(hidl_common::BufferUsage::CAMERA_INPUT)
108 #define GRALLOC_USAGE_HW_TEXTURE static_cast<uint64_t>(hidl_common::BufferUsage::GPU_TEXTURE)
109 #define GRALLOC_USAGE_HW_VIDEO_ENCODER static_cast<uint64_t>(hidl_common::BufferUsage::VIDEO_ENCODER)
110 #define GRALLOC_USAGE_HW_VIDEO_DECODER static_cast<uint64_t>(hidl_common::BufferUsage::VIDEO_DECODER)
111 #define GRALLOC_USAGE_HW_COMPOSER static_cast<uint64_t>(hidl_common::BufferUsage::COMPOSER_OVERLAY)
112 #define GRALLOC_USAGE_EXTERNAL_DISP  static_cast<uint64_t>(0x00002000)
113 
114 #define GRALLOC_USAGE_SENSOR_DIRECT_DATA static_cast<uint64_t>(hidl_common::BufferUsage::SENSOR_DIRECT_DATA)
115 #define GRALLOC_USAGE_GPU_DATA_BUFFER static_cast<uint64_t>(hidl_common::BufferUsage::GPU_DATA_BUFFER)
116 #define GRALLOC_USAGE_FRONT_BUFFER static_cast<uint64_t>(aidl_common::BufferUsage::FRONT_BUFFER)
117 
118 #define UNSUPPORTED_MALI_GRALLOC_USAGE_CUBE_MAP static_cast<uint64_t>(aidl_common::BufferUsage::GPU_CUBE_MAP)
119 #define UNSUPPORTED_MALI_GRALLOC_USAGE_MIPMAP_COMPLETE static_cast<uint64_t>(aidl_common::BufferUsage::GPU_MIPMAP_COMPLETE)
120 
121 
122 /* Originally (Gralloc 0.x), Android did not provide an explicit DECODER usage. This was rectified in Android N-MR1/7.1
123  * when Gralloc 1.0 defined GRALLOC1_PRODUCER_USAGE_VIDEO_DECODER. However, libstagefright continues
124  * (currently, Android P/9.0) to use this old combination of flags to indicate decoder producer
125  */
126 #define GRALLOC_USAGE_DECODER (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_EXTERNAL_DISP)
127 
128 static const uint64_t VALID_USAGE =
129     GRALLOC_USAGE_SW_READ_MASK |            /* 0x0FU */
130     GRALLOC_USAGE_SW_WRITE_MASK |           /* 0xF0U */
131     GRALLOC_USAGE_HW_TEXTURE |              /* 1U << 8 */
132     GRALLOC_USAGE_HW_RENDER |               /* 1U << 9 */
133     GRALLOC_USAGE_HW_2D |                   /* 1U << 10 */
134     GRALLOC_USAGE_HW_COMPOSER |             /* 1U << 11 */
135     GRALLOC_USAGE_HW_FB |                   /* 1U << 12 */
136     GRALLOC_USAGE_EXTERNAL_DISP |           /* 1U << 13 */
137     GRALLOC_USAGE_PROTECTED |               /* 1U << 14 */
138     GRALLOC_USAGE_CURSOR |                  /* 1U << 15 */
139     GRALLOC_USAGE_HW_VIDEO_ENCODER |        /* 1U << 16 */
140     GRALLOC_USAGE_HW_CAMERA_WRITE |         /* 1U << 17 */
141     GRALLOC_USAGE_HW_CAMERA_READ |          /* 1U << 18 */
142     GRALLOC_USAGE_RENDERSCRIPT |            /* 1U << 20 */
143     GRALLOC_USAGE_HW_VIDEO_DECODER |        /* 1U << 22 */
144     /* Producer and consumer usage are combined, but on Gralloc version 1 there is no way to differentiate these as they
145      * are mapped to the same value (1U << 23). */
146     GRALLOC_USAGE_SENSOR_DIRECT_DATA |      /* 1U << 23 */
147     GRALLOC_USAGE_GPU_DATA_BUFFER |         /* 1U << 24 */
148     GRALLOC_USAGE_FRONT_BUFFER |            /* 1U << 32 */
149 
150     /* Google specific usages */
151     GRALLOC_USAGE_GOOGLE_IP_BIG |           /* 1U << 51 */
152     GRALLOC_USAGE_GOOGLE_IP_MFC |           /* 1U << 50 */
153 
154     GS101_GRALLOC_USAGE_TPU_INPUT |         /* 1U << 62 */
155     GS101_GRALLOC_USAGE_TPU_OUTPUT |        /* 1U << 31 */
156     GS101_GRALLOC_USAGE_FACEAUTH_RAW_EVAL | /* 1U << 63 */
157     GS101_GRALLOC_USAGE_CAMERA_STATS |      /* 1U << 30 */
158 
159     GRALLOC_USAGE_ROIINFO |                 /* 1U << 52 */
160     MALI_GRALLOC_USAGE_AFBC_PADDING |       /* 1U << 53 */
161     MALI_GRALLOC_USAGE_FORCE_BACKBUFFER |   /* 1U << 54 */
162     MALI_GRALLOC_USAGE_NO_AFBC |            /* 1U << 29 */
163     0;
164 
165 #endif /*MALI_GRALLOC_USAGES_H_*/
166