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 31 #include <android/hardware/graphics/common/1.2/types.h> 32 /* BufferUsage is not defined in 1.2/types.h as there are no changes from previous version */ 33 namespace hidl_common = android::hardware::graphics::common::V1_1; 34 35 36 /* Local macro definitions to emulate Gralloc 1.0 usage interface */ 37 #define GRALLOC_USAGE_PRIVATE_0 1ULL << 28 38 #define GRALLOC_USAGE_PRIVATE_1 1ULL << 29 39 #define GRALLOC_USAGE_PRIVATE_2 1ULL << 30 40 #define GRALLOC_USAGE_PRIVATE_3 1ULL << 31 41 #define GRALLOC_USAGE_PRIVATE_4 1ULL << 63 42 #define GRALLOC_USAGE_PRIVATE_5 1ULL << 62 43 #define GRALLOC_USAGE_PRIVATE_6 1ULL << 61 44 #define GRALLOC_USAGE_PRIVATE_7 1ULL << 60 45 #define GRALLOC_USAGE_PRIVATE_8 1ULL << 59 46 #define GRALLOC_USAGE_PRIVATE_9 1ULL << 58 47 #define GRALLOC_USAGE_PRIVATE_10 1ULL << 57 48 #define GRALLOC_USAGE_PRIVATE_11 1ULL << 56 49 #define GRALLOC_USAGE_PRIVATE_12 1ULL << 55 50 #define GRALLOC_USAGE_PRIVATE_13 1ULL << 54 51 #define GRALLOC_USAGE_PRIVATE_14 1ULL << 53 52 #define GRALLOC_USAGE_PRIVATE_15 1ULL << 52 53 #define GRALLOC_USAGE_PRIVATE_16 1ULL << 51 54 #define GRALLOC_USAGE_PRIVATE_17 1ULL << 50 55 #define GRALLOC_USAGE_PRIVATE_18 1ULL << 49 56 #define GRALLOC_USAGE_PRIVATE_19 1ULL << 48 57 58 // TODO(b/183478446): Cleanup usage flags redefinition 59 typedef enum 60 { 61 MALI_GRALLOC_USAGE_FRONTBUFFER = GRALLOC_USAGE_PRIVATE_12, 62 MALI_GRALLOC_USAGE_FORCE_BACKBUFFER = GRALLOC_USAGE_PRIVATE_13, 63 MALI_GRALLOC_USAGE_NO_AFBC = GRALLOC_USAGE_PRIVATE_1, 64 MALI_GRALLOC_USAGE_AFBC_PADDING = GRALLOC_USAGE_PRIVATE_14, 65 66 /* SLSI specific usages */ 67 GRALLOC_USAGE_PRIVATE_NONSECURE = GRALLOC_USAGE_PRIVATE_8, 68 GRALLOC_USAGE_NOZEROED = GRALLOC_USAGE_PRIVATE_9, 69 70 GRALLOC_USAGE_VIDEO_PRIVATE_DATA = GRALLOC_USAGE_PRIVATE_7, 71 72 GRALLOC_USAGE_ROIINFO = GRALLOC_USAGE_PRIVATE_15, 73 74 /* Google specific usages */ 75 GRALLOC_USAGE_GOOGLE_IP_BO = GRALLOC_USAGE_PRIVATE_16, 76 GRALLOC_USAGE_GOOGLE_IP_MFC = GRALLOC_USAGE_PRIVATE_17, 77 78 /* FaceAuth specific usages. */ 79 GS101_GRALLOC_USAGE_TPU_INPUT = GRALLOC_USAGE_PRIVATE_5, 80 GS101_GRALLOC_USAGE_TPU_OUTPUT = GRALLOC_USAGE_PRIVATE_3, 81 GS101_GRALLOC_USAGE_CAMERA_STATS = GRALLOC_USAGE_PRIVATE_2, 82 } mali_gralloc_usage_type; 83 84 #define GRALLOC_USAGE_SW_WRITE_RARELY static_cast<uint64_t>(hidl_common::BufferUsage::CPU_WRITE_RARELY) 85 #define GRALLOC_USAGE_SW_WRITE_OFTEN static_cast<uint64_t>(hidl_common::BufferUsage::CPU_WRITE_OFTEN) 86 #define GRALLOC_USAGE_SW_READ_RARELY static_cast<uint64_t>(hidl_common::BufferUsage::CPU_READ_RARELY) 87 #define GRALLOC_USAGE_SW_READ_OFTEN static_cast<uint64_t>(hidl_common::BufferUsage::CPU_READ_OFTEN) 88 #define GRALLOC_USAGE_RENDERSCRIPT static_cast<uint64_t>(hidl_common::BufferUsage::RENDERSCRIPT) 89 #define GRALLOC_USAGE_HW_FB static_cast<uint64_t>(hidl_common::BufferUsage::COMPOSER_CLIENT_TARGET) 90 91 /* Bit 10 must be zero as per Gralloc 2.x interface specification. Used, however, for backward compatibility */ 92 #define GRALLOC_USAGE_HW_2D static_cast<uint64_t>(0x00000400) 93 94 #define GRALLOC_USAGE_SW_WRITE_MASK static_cast<uint64_t>(hidl_common::BufferUsage::CPU_WRITE_MASK) 95 #define GRALLOC_USAGE_SW_READ_MASK static_cast<uint64_t>(hidl_common::BufferUsage::CPU_READ_MASK) 96 #define GRALLOC_USAGE_PROTECTED static_cast<uint64_t>(hidl_common::BufferUsage::PROTECTED) 97 #define GRALLOC_USAGE_CURSOR static_cast<uint64_t>(hidl_common::BufferUsage::COMPOSER_CURSOR) 98 #define GRALLOC_USAGE_HW_RENDER static_cast<uint64_t>(hidl_common::BufferUsage::GPU_RENDER_TARGET) 99 #define GRALLOC_USAGE_HW_CAMERA_WRITE static_cast<uint64_t>(hidl_common::BufferUsage::CAMERA_OUTPUT) 100 #define GRALLOC_USAGE_HW_CAMERA_READ static_cast<uint64_t>(hidl_common::BufferUsage::CAMERA_INPUT) 101 #define GRALLOC_USAGE_HW_TEXTURE static_cast<uint64_t>(hidl_common::BufferUsage::GPU_TEXTURE) 102 #define GRALLOC_USAGE_HW_VIDEO_ENCODER static_cast<uint64_t>(hidl_common::BufferUsage::VIDEO_ENCODER) 103 #define GRALLOC_USAGE_HW_VIDEO_DECODER static_cast<uint64_t>(hidl_common::BufferUsage::VIDEO_DECODER) 104 #define GRALLOC_USAGE_HW_COMPOSER static_cast<uint64_t>(hidl_common::BufferUsage::COMPOSER_OVERLAY) 105 #define GRALLOC_USAGE_EXTERNAL_DISP static_cast<uint64_t>(0x00002000) 106 107 #define GRALLOC_USAGE_SENSOR_DIRECT_DATA static_cast<uint64_t>(hidl_common::BufferUsage::SENSOR_DIRECT_DATA) 108 #define GRALLOC_USAGE_GPU_DATA_BUFFER static_cast<uint64_t>(hidl_common::BufferUsage::GPU_DATA_BUFFER) 109 110 111 /* Originally (Gralloc 0.x), Android did not provide an explicit DECODER usage. This was rectified in Android N-MR1/7.1 112 * when Gralloc 1.0 defined GRALLOC1_PRODUCER_USAGE_VIDEO_DECODER. However, libstagefright continues 113 * (currently, Android P/9.0) to use this old combination of flags to indicate decoder producer 114 */ 115 #define GRALLOC_USAGE_DECODER (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_EXTERNAL_DISP) 116 117 static const uint64_t VALID_USAGE = 118 GRALLOC_USAGE_SW_READ_MASK | /* 0x0FU */ 119 GRALLOC_USAGE_SW_WRITE_MASK | /* 0xF0U */ 120 GRALLOC_USAGE_HW_TEXTURE | /* 1U << 8 */ 121 GRALLOC_USAGE_HW_RENDER | /* 1U << 9 */ 122 GRALLOC_USAGE_HW_2D | /* 1U << 10 */ 123 GRALLOC_USAGE_HW_COMPOSER | /* 1U << 11 */ 124 GRALLOC_USAGE_HW_FB | /* 1U << 12 */ 125 GRALLOC_USAGE_EXTERNAL_DISP | /* 1U << 13 */ 126 GRALLOC_USAGE_PROTECTED | /* 1U << 14 */ 127 GRALLOC_USAGE_CURSOR | /* 1U << 15 */ 128 GRALLOC_USAGE_HW_VIDEO_ENCODER | /* 1U << 16 */ 129 GRALLOC_USAGE_HW_CAMERA_WRITE | /* 1U << 17 */ 130 GRALLOC_USAGE_HW_CAMERA_READ | /* 1U << 18 */ 131 GRALLOC_USAGE_RENDERSCRIPT | /* 1U << 20 */ 132 GRALLOC_USAGE_HW_VIDEO_DECODER | /* 1U << 22 */ 133 /* Producer and consumer usage are combined, but on Gralloc version 1 there is no way to differentiate these as they 134 * are mapped to the same value (1U << 23). */ 135 GRALLOC_USAGE_SENSOR_DIRECT_DATA | /* 1U << 23 */ 136 GRALLOC_USAGE_GPU_DATA_BUFFER | /* 1U << 24 */ 137 138 /* Google specific usages */ 139 GRALLOC_USAGE_GOOGLE_IP_BO | /* 1U << 51 */ 140 GRALLOC_USAGE_GOOGLE_IP_MFC | /* 1U << 50 */ 141 142 GS101_GRALLOC_USAGE_TPU_INPUT | /* 1U << 62 */ 143 GS101_GRALLOC_USAGE_TPU_OUTPUT | /* 1U << 31 */ 144 GS101_GRALLOC_USAGE_CAMERA_STATS | /* 1U << 30 */ 145 146 GRALLOC_USAGE_ROIINFO | /* 1U << 52 */ 147 MALI_GRALLOC_USAGE_AFBC_PADDING | /* 1U << 53 */ 148 MALI_GRALLOC_USAGE_FORCE_BACKBUFFER | /* 1U << 54 */ 149 MALI_GRALLOC_USAGE_NO_AFBC | /* 1U << 29 */ 150 0; 151 152 #endif /*MALI_GRALLOC_USAGES_H_*/ 153