Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "C2AllocatorGralloc" |
| 19 | #include <utils/Log.h> |
| 20 | |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 21 | #include <mutex> |
| 22 | |
Praveen Chavan | 34493f1 | 2021-02-18 00:51:50 -0800 | [diff] [blame^] | 23 | #include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h> |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 24 | #include <android/hardware/graphics/common/1.2/types.h> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 25 | #include <cutils/native_handle.h> |
Praveen Chavan | 34493f1 | 2021-02-18 00:51:50 -0800 | [diff] [blame^] | 26 | #include <gralloctypes/Gralloc4.h> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 27 | #include <hardware/gralloc.h> |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 28 | #include <ui/GraphicBufferAllocator.h> |
| 29 | #include <ui/GraphicBufferMapper.h> |
Chih-Yu Huang | 486aa5d | 2020-10-13 16:22:58 +0900 | [diff] [blame] | 30 | #include <ui/Rect.h> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 31 | |
| 32 | #include <C2AllocatorGralloc.h> |
| 33 | #include <C2Buffer.h> |
Praveen Chavan | 34493f1 | 2021-02-18 00:51:50 -0800 | [diff] [blame^] | 34 | #include <C2Debug.h> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 35 | #include <C2PlatformSupport.h> |
| 36 | |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 37 | using ::android::hardware::hidl_handle; |
| 38 | using PixelFormat4 = ::android::hardware::graphics::common::V1_2::PixelFormat; |
| 39 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 40 | namespace android { |
| 41 | |
Pawin Vongmasa | d032f2d | 2019-05-15 08:42:44 -0700 | [diff] [blame] | 42 | namespace /* unnamed */ { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 43 | enum : uint64_t { |
| 44 | /** |
| 45 | * Usage mask that is passed through from gralloc to Codec 2.0 usage. |
| 46 | */ |
| 47 | PASSTHROUGH_USAGE_MASK = |
Charlie Chen | 49d3fe7 | 2021-03-25 20:02:37 +0800 | [diff] [blame] | 48 | ~static_cast<uint64_t>(GRALLOC_USAGE_SW_READ_MASK | |
| 49 | GRALLOC_USAGE_SW_WRITE_MASK | |
| 50 | GRALLOC_USAGE_PROTECTED) |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | // verify that passthrough mask is within the platform mask |
| 54 | static_assert((~C2MemoryUsage::PLATFORM_MASK & PASSTHROUGH_USAGE_MASK) == 0, ""); |
Pawin Vongmasa | d032f2d | 2019-05-15 08:42:44 -0700 | [diff] [blame] | 55 | } // unnamed |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 56 | |
| 57 | C2MemoryUsage C2AndroidMemoryUsage::FromGrallocUsage(uint64_t usage) { |
| 58 | // gralloc does not support WRITE_PROTECTED |
| 59 | return C2MemoryUsage( |
| 60 | ((usage & GRALLOC_USAGE_SW_READ_MASK) ? C2MemoryUsage::CPU_READ : 0) | |
| 61 | ((usage & GRALLOC_USAGE_SW_WRITE_MASK) ? C2MemoryUsage::CPU_WRITE : 0) | |
| 62 | ((usage & GRALLOC_USAGE_PROTECTED) ? C2MemoryUsage::READ_PROTECTED : 0) | |
| 63 | (usage & PASSTHROUGH_USAGE_MASK)); |
| 64 | } |
| 65 | |
| 66 | uint64_t C2AndroidMemoryUsage::asGrallocUsage() const { |
| 67 | // gralloc does not support WRITE_PROTECTED |
| 68 | return (((expected & C2MemoryUsage::CPU_READ) ? GRALLOC_USAGE_SW_READ_OFTEN : 0) | |
| 69 | ((expected & C2MemoryUsage::CPU_WRITE) ? GRALLOC_USAGE_SW_WRITE_OFTEN : 0) | |
| 70 | ((expected & C2MemoryUsage::READ_PROTECTED) ? GRALLOC_USAGE_PROTECTED : 0) | |
| 71 | (expected & PASSTHROUGH_USAGE_MASK)); |
| 72 | } |
| 73 | |
Pawin Vongmasa | d032f2d | 2019-05-15 08:42:44 -0700 | [diff] [blame] | 74 | namespace /* unnamed */ { |
| 75 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 76 | /* ===================================== GRALLOC ALLOCATION ==================================== */ |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 77 | bool native_handle_is_invalid(const native_handle_t *const handle) { |
| 78 | // perform basic validation of a native handle |
| 79 | if (handle == nullptr) { |
| 80 | // null handle is considered valid |
| 81 | return false; |
| 82 | } |
| 83 | return ((size_t)handle->version != sizeof(native_handle_t) || |
| 84 | handle->numFds < 0 || |
| 85 | handle->numInts < 0 || |
| 86 | // for sanity assume handles must occupy less memory than INT_MAX bytes |
| 87 | handle->numFds > int((INT_MAX - handle->version) / sizeof(int)) - handle->numInts); |
| 88 | } |
| 89 | |
| 90 | class C2HandleGralloc : public C2Handle { |
| 91 | private: |
| 92 | struct ExtraData { |
| 93 | uint32_t width; |
| 94 | uint32_t height; |
| 95 | uint32_t format; |
| 96 | uint32_t usage_lo; |
| 97 | uint32_t usage_hi; |
| 98 | uint32_t stride; |
| 99 | uint32_t generation; |
| 100 | uint32_t igbp_id_lo; |
| 101 | uint32_t igbp_id_hi; |
| 102 | uint32_t igbp_slot; |
| 103 | uint32_t magic; |
| 104 | }; |
| 105 | |
| 106 | enum { |
| 107 | NUM_INTS = sizeof(ExtraData) / sizeof(int), |
| 108 | }; |
| 109 | const static uint32_t MAGIC = '\xc2gr\x00'; |
| 110 | |
| 111 | static |
John Stultz | 653ddd1 | 2020-09-19 05:26:24 +0000 | [diff] [blame] | 112 | const ExtraData* GetExtraData(const C2Handle *const handle) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 113 | if (handle == nullptr |
| 114 | || native_handle_is_invalid(handle) |
| 115 | || handle->numInts < NUM_INTS) { |
| 116 | return nullptr; |
| 117 | } |
| 118 | return reinterpret_cast<const ExtraData*>( |
| 119 | &handle->data[handle->numFds + handle->numInts - NUM_INTS]); |
| 120 | } |
| 121 | |
| 122 | static |
John Stultz | 653ddd1 | 2020-09-19 05:26:24 +0000 | [diff] [blame] | 123 | ExtraData *GetExtraData(C2Handle *const handle) { |
| 124 | return const_cast<ExtraData *>(GetExtraData(const_cast<const C2Handle *const>(handle))); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | public: |
| 128 | void getIgbpData(uint32_t *generation, uint64_t *igbp_id, uint32_t *igbp_slot) const { |
John Stultz | 653ddd1 | 2020-09-19 05:26:24 +0000 | [diff] [blame] | 129 | const ExtraData *ed = GetExtraData(this); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 130 | *generation = ed->generation; |
| 131 | *igbp_id = unsigned(ed->igbp_id_lo) | uint64_t(unsigned(ed->igbp_id_hi)) << 32; |
| 132 | *igbp_slot = ed->igbp_slot; |
| 133 | } |
| 134 | |
John Stultz | 653ddd1 | 2020-09-19 05:26:24 +0000 | [diff] [blame] | 135 | static bool IsValid(const C2Handle *const o) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 136 | if (o == nullptr) { // null handle is always valid |
| 137 | return true; |
| 138 | } |
John Stultz | 653ddd1 | 2020-09-19 05:26:24 +0000 | [diff] [blame] | 139 | const ExtraData *xd = GetExtraData(o); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 140 | // we cannot validate width/height/format/usage without accessing gralloc driver |
| 141 | return xd != nullptr && xd->magic == MAGIC; |
| 142 | } |
| 143 | |
Sungtak Lee | a4d13be | 2019-01-23 15:24:46 -0800 | [diff] [blame] | 144 | static C2HandleGralloc* WrapAndMoveNativeHandle( |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 145 | const native_handle_t *const handle, |
| 146 | uint32_t width, uint32_t height, uint32_t format, uint64_t usage, |
| 147 | uint32_t stride, uint32_t generation, uint64_t igbp_id = 0, uint32_t igbp_slot = 0) { |
| 148 | //CHECK(handle != nullptr); |
| 149 | if (native_handle_is_invalid(handle) || |
| 150 | handle->numInts > int((INT_MAX - handle->version) / sizeof(int)) - NUM_INTS - handle->numFds) { |
| 151 | return nullptr; |
| 152 | } |
| 153 | ExtraData xd = { |
| 154 | width, height, format, uint32_t(usage & 0xFFFFFFFF), uint32_t(usage >> 32), |
| 155 | stride, generation, uint32_t(igbp_id & 0xFFFFFFFF), uint32_t(igbp_id >> 32), |
| 156 | igbp_slot, MAGIC |
| 157 | }; |
| 158 | native_handle_t *res = native_handle_create(handle->numFds, handle->numInts + NUM_INTS); |
| 159 | if (res != nullptr) { |
| 160 | memcpy(&res->data, &handle->data, sizeof(int) * (handle->numFds + handle->numInts)); |
John Stultz | 653ddd1 | 2020-09-19 05:26:24 +0000 | [diff] [blame] | 161 | *GetExtraData(res) = xd; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 162 | } |
| 163 | return reinterpret_cast<C2HandleGralloc *>(res); |
| 164 | } |
| 165 | |
Sungtak Lee | a4d13be | 2019-01-23 15:24:46 -0800 | [diff] [blame] | 166 | static C2HandleGralloc* WrapNativeHandle( |
| 167 | const native_handle_t *const handle, |
| 168 | uint32_t width, uint32_t height, uint32_t format, uint64_t usage, |
| 169 | uint32_t stride, uint32_t generation, uint64_t igbp_id = 0, uint32_t igbp_slot = 0) { |
| 170 | if (handle == nullptr) { |
| 171 | return nullptr; |
| 172 | } |
| 173 | native_handle_t *clone = native_handle_clone(handle); |
| 174 | if (clone == nullptr) { |
| 175 | return nullptr; |
| 176 | } |
| 177 | C2HandleGralloc *res = WrapAndMoveNativeHandle( |
| 178 | clone, width, height, format, usage, stride, generation, igbp_id, igbp_slot); |
| 179 | if (res == nullptr) { |
| 180 | native_handle_close(clone); |
| 181 | } |
| 182 | native_handle_delete(clone); |
| 183 | return res; |
| 184 | } |
| 185 | |
Sungtak Lee | 0851581 | 2019-06-05 11:16:32 -0700 | [diff] [blame] | 186 | static bool MigrateNativeHandle( |
| 187 | native_handle_t *handle, |
| 188 | uint32_t generation, uint64_t igbp_id, uint32_t igbp_slot) { |
John Stultz | 653ddd1 | 2020-09-19 05:26:24 +0000 | [diff] [blame] | 189 | if (handle == nullptr || !IsValid(handle)) { |
Sungtak Lee | 0851581 | 2019-06-05 11:16:32 -0700 | [diff] [blame] | 190 | return false; |
| 191 | } |
John Stultz | 653ddd1 | 2020-09-19 05:26:24 +0000 | [diff] [blame] | 192 | ExtraData *ed = GetExtraData(handle); |
Sungtak Lee | 0851581 | 2019-06-05 11:16:32 -0700 | [diff] [blame] | 193 | if (!ed) return false; |
| 194 | ed->generation = generation; |
| 195 | ed->igbp_id_lo = uint32_t(igbp_id & 0xFFFFFFFF); |
| 196 | ed->igbp_id_hi = uint32_t(igbp_id >> 32); |
| 197 | ed->igbp_slot = igbp_slot; |
| 198 | return true; |
| 199 | } |
| 200 | |
| 201 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 202 | static native_handle_t* UnwrapNativeHandle( |
| 203 | const C2Handle *const handle) { |
John Stultz | 653ddd1 | 2020-09-19 05:26:24 +0000 | [diff] [blame] | 204 | const ExtraData *xd = GetExtraData(handle); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 205 | if (xd == nullptr || xd->magic != MAGIC) { |
| 206 | return nullptr; |
| 207 | } |
| 208 | native_handle_t *res = native_handle_create(handle->numFds, handle->numInts - NUM_INTS); |
| 209 | if (res != nullptr) { |
| 210 | memcpy(&res->data, &handle->data, sizeof(int) * (res->numFds + res->numInts)); |
| 211 | } |
| 212 | return res; |
| 213 | } |
| 214 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 215 | static const C2HandleGralloc* Import( |
| 216 | const C2Handle *const handle, |
| 217 | uint32_t *width, uint32_t *height, uint32_t *format, |
| 218 | uint64_t *usage, uint32_t *stride, |
| 219 | uint32_t *generation, uint64_t *igbp_id, uint32_t *igbp_slot) { |
John Stultz | 653ddd1 | 2020-09-19 05:26:24 +0000 | [diff] [blame] | 220 | const ExtraData *xd = GetExtraData(handle); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 221 | if (xd == nullptr) { |
| 222 | return nullptr; |
| 223 | } |
| 224 | *width = xd->width; |
| 225 | *height = xd->height; |
| 226 | *format = xd->format; |
| 227 | *usage = xd->usage_lo | (uint64_t(xd->usage_hi) << 32); |
| 228 | *stride = xd->stride; |
| 229 | *generation = xd->generation; |
| 230 | *igbp_id = xd->igbp_id_lo | (uint64_t(xd->igbp_id_hi) << 32); |
| 231 | *igbp_slot = xd->igbp_slot; |
| 232 | return reinterpret_cast<const C2HandleGralloc *>(handle); |
| 233 | } |
| 234 | }; |
| 235 | |
Praveen Chavan | 34493f1 | 2021-02-18 00:51:50 -0800 | [diff] [blame^] | 236 | static |
| 237 | c2_status_t Gralloc4Mapper_lock(native_handle_t *handle, uint64_t usage, const Rect& bounds, |
| 238 | C2PlanarLayout *layout, uint8_t **addr) { |
| 239 | GraphicBufferMapper &mapper = GraphicBufferMapper::get(); |
| 240 | |
| 241 | std::vector<ui::PlaneLayout> planes; |
| 242 | // this method is only supported on Gralloc 4 or later |
| 243 | status_t err = mapper.getPlaneLayouts(handle, &planes); |
| 244 | if (err != NO_ERROR || planes.empty()) { |
| 245 | return C2_CANNOT_DO; |
| 246 | } |
| 247 | |
| 248 | uint8_t *pointer = nullptr; |
| 249 | err = mapper.lock(handle, usage, bounds, (void **)&pointer, nullptr, nullptr); |
| 250 | if (err != NO_ERROR || pointer == nullptr) { |
| 251 | return C2_CORRUPTED; |
| 252 | } |
| 253 | |
| 254 | using aidl::android::hardware::graphics::common::PlaneLayoutComponentType; |
| 255 | using aidl::android::hardware::graphics::common::PlaneLayoutComponent; |
| 256 | |
| 257 | layout->type = C2PlanarLayout::TYPE_YUV; |
| 258 | layout->numPlanes = 0; |
| 259 | layout->rootPlanes = 0; |
| 260 | |
| 261 | for (const ui::PlaneLayout &plane : planes) { |
| 262 | layout->rootPlanes++; |
| 263 | uint32_t lastOffsetInBits = 0; |
| 264 | uint32_t rootIx = 0; |
| 265 | |
| 266 | for (const PlaneLayoutComponent &component : plane.components) { |
| 267 | if (!gralloc4::isStandardPlaneLayoutComponentType(component.type)) { |
| 268 | return C2_CANNOT_DO; |
| 269 | } |
| 270 | |
| 271 | uint32_t rightShiftBits = component.offsetInBits - lastOffsetInBits; |
| 272 | uint32_t allocatedDepthInBits = component.sizeInBits + rightShiftBits; |
| 273 | C2PlanarLayout::plane_index_t planeId; |
| 274 | C2PlaneInfo::channel_t channel; |
| 275 | |
| 276 | switch (static_cast<PlaneLayoutComponentType>(component.type.value)) { |
| 277 | case PlaneLayoutComponentType::Y: |
| 278 | planeId = C2PlanarLayout::PLANE_Y; |
| 279 | channel = C2PlaneInfo::CHANNEL_Y; |
| 280 | break; |
| 281 | case PlaneLayoutComponentType::CB: |
| 282 | planeId = C2PlanarLayout::PLANE_U; |
| 283 | channel = C2PlaneInfo::CHANNEL_CB; |
| 284 | break; |
| 285 | case PlaneLayoutComponentType::CR: |
| 286 | planeId = C2PlanarLayout::PLANE_V; |
| 287 | channel = C2PlaneInfo::CHANNEL_CR; |
| 288 | break; |
| 289 | default: |
| 290 | return C2_CORRUPTED; |
| 291 | } |
| 292 | |
| 293 | addr[planeId] = pointer + plane.offsetInBytes + (component.offsetInBits / 8); |
| 294 | layout->planes[planeId] = { |
| 295 | channel, // channel |
| 296 | static_cast<int32_t>(plane.sampleIncrementInBits / 8), // colInc |
| 297 | static_cast<int32_t>(plane.strideInBytes), // rowInc |
| 298 | static_cast<uint32_t>(plane.horizontalSubsampling), // mColSampling |
| 299 | static_cast<uint32_t>(plane.verticalSubsampling), // mRowSampling |
| 300 | allocatedDepthInBits, // allocatedDepth (bits) |
| 301 | static_cast<uint32_t>(component.sizeInBits), // bitDepth (bits) |
| 302 | rightShiftBits, // rightShift (bits) |
| 303 | C2PlaneInfo::NATIVE, // endianness |
| 304 | rootIx, // rootIx |
| 305 | static_cast<uint32_t>(component.offsetInBits / 8), // offset (bytes) |
| 306 | }; |
| 307 | |
| 308 | layout->numPlanes++; |
| 309 | lastOffsetInBits = component.offsetInBits + component.sizeInBits; |
| 310 | rootIx++; |
| 311 | } |
| 312 | } |
| 313 | return C2_OK; |
| 314 | } |
| 315 | |
Pawin Vongmasa | d032f2d | 2019-05-15 08:42:44 -0700 | [diff] [blame] | 316 | } // unnamed namespace |
| 317 | |
Praveen Chavan | 34493f1 | 2021-02-18 00:51:50 -0800 | [diff] [blame^] | 318 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 319 | native_handle_t *UnwrapNativeCodec2GrallocHandle(const C2Handle *const handle) { |
| 320 | return C2HandleGralloc::UnwrapNativeHandle(handle); |
| 321 | } |
| 322 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 323 | C2Handle *WrapNativeCodec2GrallocHandle( |
| 324 | const native_handle_t *const handle, |
| 325 | uint32_t width, uint32_t height, uint32_t format, uint64_t usage, uint32_t stride, |
| 326 | uint32_t generation, uint64_t igbp_id, uint32_t igbp_slot) { |
| 327 | return C2HandleGralloc::WrapNativeHandle(handle, width, height, format, usage, stride, |
| 328 | generation, igbp_id, igbp_slot); |
| 329 | } |
| 330 | |
Sungtak Lee | 0851581 | 2019-06-05 11:16:32 -0700 | [diff] [blame] | 331 | bool MigrateNativeCodec2GrallocHandle( |
| 332 | native_handle_t *handle, |
| 333 | uint32_t generation, uint64_t igbp_id, uint32_t igbp_slot) { |
| 334 | return C2HandleGralloc::MigrateNativeHandle(handle, generation, igbp_id, igbp_slot); |
| 335 | } |
| 336 | |
| 337 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 338 | class C2AllocationGralloc : public C2GraphicAllocation { |
| 339 | public: |
| 340 | virtual ~C2AllocationGralloc() override; |
| 341 | |
| 342 | virtual c2_status_t map( |
Chih-Yu Huang | 486aa5d | 2020-10-13 16:22:58 +0900 | [diff] [blame] | 343 | C2Rect c2Rect, C2MemoryUsage usage, C2Fence *fence, |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 344 | C2PlanarLayout *layout /* nonnull */, uint8_t **addr /* nonnull */) override; |
| 345 | virtual c2_status_t unmap( |
| 346 | uint8_t **addr /* nonnull */, C2Rect rect, C2Fence *fence /* nullable */) override; |
| 347 | virtual C2Allocator::id_t getAllocatorId() const override { return mAllocatorId; } |
| 348 | virtual const C2Handle *handle() const override { return mLockedHandle ? : mHandle; } |
| 349 | virtual bool equals(const std::shared_ptr<const C2GraphicAllocation> &other) const override; |
| 350 | |
| 351 | // internal methods |
| 352 | // |handle| will be moved. |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 353 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 354 | C2AllocationGralloc( |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 355 | uint32_t width, uint32_t height, |
| 356 | uint32_t format, uint32_t layerCount, |
| 357 | uint64_t grallocUsage, uint32_t stride, |
Marissa Wall | 8806edc | 2019-06-21 09:50:47 -0700 | [diff] [blame] | 358 | hidl_handle &hidlHandle, |
| 359 | const C2HandleGralloc *const handle, |
| 360 | C2Allocator::id_t allocatorId); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 361 | int dup() const; |
| 362 | c2_status_t status() const; |
| 363 | |
| 364 | private: |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 365 | const uint32_t mWidth; |
| 366 | const uint32_t mHeight; |
| 367 | const uint32_t mFormat; |
| 368 | const uint32_t mLayerCount; |
| 369 | const uint64_t mGrallocUsage; |
| 370 | const uint32_t mStride; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 371 | const hidl_handle mHidlHandle; |
| 372 | const C2HandleGralloc *mHandle; |
| 373 | buffer_handle_t mBuffer; |
| 374 | const C2HandleGralloc *mLockedHandle; |
| 375 | bool mLocked; |
| 376 | C2Allocator::id_t mAllocatorId; |
| 377 | std::mutex mMappedLock; |
| 378 | }; |
| 379 | |
| 380 | C2AllocationGralloc::C2AllocationGralloc( |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 381 | uint32_t width, uint32_t height, |
| 382 | uint32_t format, uint32_t layerCount, |
| 383 | uint64_t grallocUsage, uint32_t stride, |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 384 | hidl_handle &hidlHandle, |
| 385 | const C2HandleGralloc *const handle, |
| 386 | C2Allocator::id_t allocatorId) |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 387 | : C2GraphicAllocation(width, height), |
| 388 | mWidth(width), |
| 389 | mHeight(height), |
| 390 | mFormat(format), |
| 391 | mLayerCount(layerCount), |
| 392 | mGrallocUsage(grallocUsage), |
| 393 | mStride(stride), |
Marissa Wall | 8806edc | 2019-06-21 09:50:47 -0700 | [diff] [blame] | 394 | mHidlHandle(std::move(hidlHandle)), |
| 395 | mHandle(handle), |
| 396 | mBuffer(nullptr), |
| 397 | mLockedHandle(nullptr), |
| 398 | mLocked(false), |
| 399 | mAllocatorId(allocatorId) { |
| 400 | } |
| 401 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 402 | C2AllocationGralloc::~C2AllocationGralloc() { |
Yichi Chen | fa94a3b | 2018-12-08 00:06:25 +0800 | [diff] [blame] | 403 | if (mBuffer && mLocked) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 404 | // implementation ignores addresss and rect |
| 405 | uint8_t* addr[C2PlanarLayout::MAX_NUM_PLANES] = {}; |
| 406 | unmap(addr, C2Rect(), nullptr); |
| 407 | } |
Yichi Chen | fa94a3b | 2018-12-08 00:06:25 +0800 | [diff] [blame] | 408 | if (mBuffer) { |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 409 | status_t err = GraphicBufferMapper::get().freeBuffer(mBuffer); |
| 410 | if (err) { |
| 411 | ALOGE("failed transaction: freeBuffer"); |
Pawin Vongmasa | d032f2d | 2019-05-15 08:42:44 -0700 | [diff] [blame] | 412 | } |
Yichi Chen | fa94a3b | 2018-12-08 00:06:25 +0800 | [diff] [blame] | 413 | } |
| 414 | if (mHandle) { |
| 415 | native_handle_delete( |
| 416 | const_cast<native_handle_t *>(reinterpret_cast<const native_handle_t *>(mHandle))); |
| 417 | } |
Sungtak Lee | 2729dcf | 2019-01-18 13:15:07 -0800 | [diff] [blame] | 418 | if (mLockedHandle) { |
| 419 | native_handle_delete( |
| 420 | const_cast<native_handle_t *>( |
| 421 | reinterpret_cast<const native_handle_t *>(mLockedHandle))); |
| 422 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | c2_status_t C2AllocationGralloc::map( |
Chih-Yu Huang | 486aa5d | 2020-10-13 16:22:58 +0900 | [diff] [blame] | 426 | C2Rect c2Rect, C2MemoryUsage usage, C2Fence *fence, |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 427 | C2PlanarLayout *layout /* nonnull */, uint8_t **addr /* nonnull */) { |
Chih-Yu Huang | 486aa5d | 2020-10-13 16:22:58 +0900 | [diff] [blame] | 428 | const Rect rect{(int32_t)c2Rect.left, (int32_t)c2Rect.top, |
| 429 | (int32_t)(c2Rect.left + c2Rect.width) /* right */, |
| 430 | (int32_t)(c2Rect.top + c2Rect.height) /* bottom */}; |
| 431 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 432 | uint64_t grallocUsage = static_cast<C2AndroidMemoryUsage>(usage).asGrallocUsage(); |
| 433 | ALOGV("mapping buffer with usage %#llx => %#llx", |
| 434 | (long long)usage.expected, (long long)grallocUsage); |
| 435 | |
| 436 | // TODO |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 437 | (void)fence; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 438 | |
| 439 | std::lock_guard<std::mutex> lock(mMappedLock); |
| 440 | if (mBuffer && mLocked) { |
| 441 | ALOGD("already mapped"); |
| 442 | return C2_DUPLICATE; |
| 443 | } |
| 444 | if (!layout || !addr) { |
| 445 | ALOGD("wrong param"); |
| 446 | return C2_BAD_VALUE; |
| 447 | } |
| 448 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 449 | if (!mBuffer) { |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 450 | status_t err = GraphicBufferMapper::get().importBuffer( |
| 451 | mHidlHandle.getNativeHandle(), mWidth, mHeight, mLayerCount, |
| 452 | mFormat, mGrallocUsage, mStride, &mBuffer); |
| 453 | if (err) { |
| 454 | ALOGE("failed transaction: importBuffer"); |
| 455 | return C2_CORRUPTED; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 456 | } |
| 457 | if (mBuffer == nullptr) { |
| 458 | ALOGD("importBuffer returned null buffer"); |
| 459 | return C2_CORRUPTED; |
| 460 | } |
| 461 | uint32_t generation = 0; |
| 462 | uint64_t igbp_id = 0; |
| 463 | uint32_t igbp_slot = 0; |
| 464 | if (mHandle) { |
| 465 | mHandle->getIgbpData(&generation, &igbp_id, &igbp_slot); |
| 466 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 467 | |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 468 | mLockedHandle = C2HandleGralloc::WrapAndMoveNativeHandle( |
| 469 | mBuffer, mWidth, mHeight, mFormat, mGrallocUsage, |
| 470 | mStride, generation, igbp_id, igbp_slot); |
Marissa Wall | 8806edc | 2019-06-21 09:50:47 -0700 | [diff] [blame] | 471 | } |
Praveen Chavan | 34493f1 | 2021-02-18 00:51:50 -0800 | [diff] [blame^] | 472 | |
| 473 | // 'NATIVE' on Android means LITTLE_ENDIAN |
| 474 | constexpr C2PlaneInfo::endianness_t kEndianness = C2PlaneInfo::NATIVE; |
| 475 | |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 476 | switch (mFormat) { |
| 477 | case static_cast<uint32_t>(PixelFormat4::RGBA_1010102): { |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 478 | // TRICKY: this is used for media as YUV444 in the case when it is queued directly to a |
| 479 | // Surface. In all other cases it is RGBA. We don't know which case it is here, so |
| 480 | // default to YUV for now. |
| 481 | void *pointer = nullptr; |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 482 | // TODO: fence |
| 483 | status_t err = GraphicBufferMapper::get().lock( |
Chih-Yu Huang | 486aa5d | 2020-10-13 16:22:58 +0900 | [diff] [blame] | 484 | const_cast<native_handle_t *>(mBuffer), grallocUsage, rect, &pointer); |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 485 | if (err) { |
| 486 | ALOGE("failed transaction: lock(RGBA_1010102)"); |
| 487 | return C2_CORRUPTED; |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 488 | } |
| 489 | // treat as 32-bit values |
| 490 | addr[C2PlanarLayout::PLANE_Y] = (uint8_t *)pointer; |
| 491 | addr[C2PlanarLayout::PLANE_U] = (uint8_t *)pointer; |
| 492 | addr[C2PlanarLayout::PLANE_V] = (uint8_t *)pointer; |
| 493 | addr[C2PlanarLayout::PLANE_A] = (uint8_t *)pointer; |
| 494 | layout->type = C2PlanarLayout::TYPE_YUVA; |
| 495 | layout->numPlanes = 4; |
| 496 | layout->rootPlanes = 1; |
| 497 | layout->planes[C2PlanarLayout::PLANE_Y] = { |
| 498 | C2PlaneInfo::CHANNEL_Y, // channel |
| 499 | 4, // colInc |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 500 | static_cast<int32_t>(4 * mStride), // rowInc |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 501 | 1, // mColSampling |
| 502 | 1, // mRowSampling |
| 503 | 32, // allocatedDepth |
| 504 | 10, // bitDepth |
| 505 | 10, // rightShift |
| 506 | C2PlaneInfo::LITTLE_END, // endianness |
| 507 | C2PlanarLayout::PLANE_Y, // rootIx |
| 508 | 0, // offset |
| 509 | }; |
| 510 | layout->planes[C2PlanarLayout::PLANE_U] = { |
| 511 | C2PlaneInfo::CHANNEL_CB, // channel |
| 512 | 4, // colInc |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 513 | static_cast<int32_t>(4 * mStride), // rowInc |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 514 | 1, // mColSampling |
| 515 | 1, // mRowSampling |
| 516 | 32, // allocatedDepth |
| 517 | 10, // bitDepth |
| 518 | 0, // rightShift |
| 519 | C2PlaneInfo::LITTLE_END, // endianness |
| 520 | C2PlanarLayout::PLANE_Y, // rootIx |
| 521 | 0, // offset |
| 522 | }; |
| 523 | layout->planes[C2PlanarLayout::PLANE_V] = { |
| 524 | C2PlaneInfo::CHANNEL_CR, // channel |
| 525 | 4, // colInc |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 526 | static_cast<int32_t>(4 * mStride), // rowInc |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 527 | 1, // mColSampling |
| 528 | 1, // mRowSampling |
| 529 | 32, // allocatedDepth |
| 530 | 10, // bitDepth |
| 531 | 20, // rightShift |
| 532 | C2PlaneInfo::LITTLE_END, // endianness |
| 533 | C2PlanarLayout::PLANE_Y, // rootIx |
| 534 | 0, // offset |
| 535 | }; |
| 536 | layout->planes[C2PlanarLayout::PLANE_A] = { |
| 537 | C2PlaneInfo::CHANNEL_A, // channel |
| 538 | 4, // colInc |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 539 | static_cast<int32_t>(4 * mStride), // rowInc |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 540 | 1, // mColSampling |
| 541 | 1, // mRowSampling |
| 542 | 32, // allocatedDepth |
| 543 | 2, // bitDepth |
| 544 | 30, // rightShift |
| 545 | C2PlaneInfo::LITTLE_END, // endianness |
| 546 | C2PlanarLayout::PLANE_Y, // rootIx |
| 547 | 0, // offset |
| 548 | }; |
| 549 | break; |
| 550 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 551 | |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 552 | case static_cast<uint32_t>(PixelFormat4::RGBA_8888): |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 553 | // TODO: alpha channel |
| 554 | // fall-through |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 555 | case static_cast<uint32_t>(PixelFormat4::RGBX_8888): { |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 556 | void *pointer = nullptr; |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 557 | // TODO: fence |
| 558 | status_t err = GraphicBufferMapper::get().lock( |
Chih-Yu Huang | 486aa5d | 2020-10-13 16:22:58 +0900 | [diff] [blame] | 559 | const_cast<native_handle_t*>(mBuffer), grallocUsage, rect, &pointer); |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 560 | if (err) { |
| 561 | ALOGE("failed transaction: lock(RGBA_8888)"); |
| 562 | return C2_CORRUPTED; |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 563 | } |
| 564 | addr[C2PlanarLayout::PLANE_R] = (uint8_t *)pointer; |
| 565 | addr[C2PlanarLayout::PLANE_G] = (uint8_t *)pointer + 1; |
| 566 | addr[C2PlanarLayout::PLANE_B] = (uint8_t *)pointer + 2; |
| 567 | layout->type = C2PlanarLayout::TYPE_RGB; |
| 568 | layout->numPlanes = 3; |
| 569 | layout->rootPlanes = 1; |
| 570 | layout->planes[C2PlanarLayout::PLANE_R] = { |
| 571 | C2PlaneInfo::CHANNEL_R, // channel |
| 572 | 4, // colInc |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 573 | static_cast<int32_t>(4 * mStride), // rowInc |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 574 | 1, // mColSampling |
| 575 | 1, // mRowSampling |
| 576 | 8, // allocatedDepth |
| 577 | 8, // bitDepth |
| 578 | 0, // rightShift |
| 579 | C2PlaneInfo::NATIVE, // endianness |
| 580 | C2PlanarLayout::PLANE_R, // rootIx |
| 581 | 0, // offset |
| 582 | }; |
| 583 | layout->planes[C2PlanarLayout::PLANE_G] = { |
| 584 | C2PlaneInfo::CHANNEL_G, // channel |
| 585 | 4, // colInc |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 586 | static_cast<int32_t>(4 * mStride), // rowInc |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 587 | 1, // mColSampling |
| 588 | 1, // mRowSampling |
| 589 | 8, // allocatedDepth |
| 590 | 8, // bitDepth |
| 591 | 0, // rightShift |
| 592 | C2PlaneInfo::NATIVE, // endianness |
| 593 | C2PlanarLayout::PLANE_R, // rootIx |
| 594 | 1, // offset |
| 595 | }; |
| 596 | layout->planes[C2PlanarLayout::PLANE_B] = { |
| 597 | C2PlaneInfo::CHANNEL_B, // channel |
| 598 | 4, // colInc |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 599 | static_cast<int32_t>(4 * mStride), // rowInc |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 600 | 1, // mColSampling |
| 601 | 1, // mRowSampling |
| 602 | 8, // allocatedDepth |
| 603 | 8, // bitDepth |
| 604 | 0, // rightShift |
| 605 | C2PlaneInfo::NATIVE, // endianness |
| 606 | C2PlanarLayout::PLANE_R, // rootIx |
| 607 | 2, // offset |
| 608 | }; |
| 609 | break; |
| 610 | } |
| 611 | |
David Stevens | 1cadc75d | 2020-04-03 10:50:51 +0900 | [diff] [blame] | 612 | case static_cast<uint32_t>(PixelFormat4::BLOB): { |
| 613 | void *pointer = nullptr; |
| 614 | // TODO: fence |
| 615 | status_t err = GraphicBufferMapper::get().lock( |
Chih-Yu Huang | 486aa5d | 2020-10-13 16:22:58 +0900 | [diff] [blame] | 616 | const_cast<native_handle_t*>(mBuffer), grallocUsage, rect, &pointer); |
David Stevens | 1cadc75d | 2020-04-03 10:50:51 +0900 | [diff] [blame] | 617 | if (err) { |
| 618 | ALOGE("failed transaction: lock(BLOB)"); |
| 619 | return C2_CORRUPTED; |
| 620 | } |
| 621 | *addr = (uint8_t *)pointer; |
| 622 | break; |
| 623 | } |
| 624 | |
Wonsik Kim | 29e3c4d | 2020-09-02 12:19:44 -0700 | [diff] [blame] | 625 | case static_cast<uint32_t>(PixelFormat4::YCBCR_422_SP): |
| 626 | // fall-through |
| 627 | case static_cast<uint32_t>(PixelFormat4::YCRCB_420_SP): |
| 628 | // fall-through |
| 629 | case static_cast<uint32_t>(PixelFormat4::YCBCR_422_I): |
| 630 | // fall-through |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 631 | case static_cast<uint32_t>(PixelFormat4::YCBCR_420_888): |
Lajos Molnar | 35d36cb | 2018-10-12 15:10:56 -0700 | [diff] [blame] | 632 | // fall-through |
Wonsik Kim | 29e3c4d | 2020-09-02 12:19:44 -0700 | [diff] [blame] | 633 | case static_cast<uint32_t>(PixelFormat4::YV12): { |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 634 | android_ycbcr ycbcrLayout; |
| 635 | |
| 636 | status_t err = GraphicBufferMapper::get().lockYCbCr( |
Chih-Yu Huang | 486aa5d | 2020-10-13 16:22:58 +0900 | [diff] [blame] | 637 | const_cast<native_handle_t*>(mBuffer), grallocUsage, rect, &ycbcrLayout); |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 638 | if (err) { |
Wonsik Kim | d91f3fb | 2021-02-24 12:35:31 -0800 | [diff] [blame] | 639 | ALOGE("failed transaction: lockYCbCr (err=%d)", err); |
| 640 | return C2_CORRUPTED; |
| 641 | } |
| 642 | if (!ycbcrLayout.y || !ycbcrLayout.cb || !ycbcrLayout.cr |
| 643 | || ycbcrLayout.ystride == 0 |
| 644 | || ycbcrLayout.cstride == 0 |
| 645 | || ycbcrLayout.chroma_step == 0) { |
| 646 | ALOGE("invalid layout: lockYCbCr (y=%s cb=%s cr=%s " |
| 647 | "ystride=%zu cstride=%zu chroma_step=%zu)", |
| 648 | ycbcrLayout.y ? "(non-null)" : "(null)", |
| 649 | ycbcrLayout.cb ? "(non-null)" : "(null)", |
| 650 | ycbcrLayout.cr ? "(non-null)" : "(null)", |
| 651 | ycbcrLayout.ystride, ycbcrLayout.cstride, ycbcrLayout.chroma_step); |
Marissa Wall | 469b90a | 2019-11-06 10:12:43 -0800 | [diff] [blame] | 652 | return C2_CORRUPTED; |
Pawin Vongmasa | d032f2d | 2019-05-15 08:42:44 -0700 | [diff] [blame] | 653 | } |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 654 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 655 | addr[C2PlanarLayout::PLANE_Y] = (uint8_t *)ycbcrLayout.y; |
| 656 | addr[C2PlanarLayout::PLANE_U] = (uint8_t *)ycbcrLayout.cb; |
| 657 | addr[C2PlanarLayout::PLANE_V] = (uint8_t *)ycbcrLayout.cr; |
| 658 | layout->type = C2PlanarLayout::TYPE_YUV; |
| 659 | layout->numPlanes = 3; |
| 660 | layout->rootPlanes = 3; |
| 661 | layout->planes[C2PlanarLayout::PLANE_Y] = { |
| 662 | C2PlaneInfo::CHANNEL_Y, // channel |
| 663 | 1, // colInc |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 664 | (int32_t)ycbcrLayout.ystride, // rowInc |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 665 | 1, // mColSampling |
| 666 | 1, // mRowSampling |
| 667 | 8, // allocatedDepth |
| 668 | 8, // bitDepth |
| 669 | 0, // rightShift |
| 670 | C2PlaneInfo::NATIVE, // endianness |
| 671 | C2PlanarLayout::PLANE_Y, // rootIx |
| 672 | 0, // offset |
| 673 | }; |
| 674 | layout->planes[C2PlanarLayout::PLANE_U] = { |
| 675 | C2PlaneInfo::CHANNEL_CB, // channel |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 676 | (int32_t)ycbcrLayout.chroma_step, // colInc |
| 677 | (int32_t)ycbcrLayout.cstride, // rowInc |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 678 | 2, // mColSampling |
| 679 | 2, // mRowSampling |
| 680 | 8, // allocatedDepth |
| 681 | 8, // bitDepth |
| 682 | 0, // rightShift |
| 683 | C2PlaneInfo::NATIVE, // endianness |
| 684 | C2PlanarLayout::PLANE_U, // rootIx |
| 685 | 0, // offset |
| 686 | }; |
| 687 | layout->planes[C2PlanarLayout::PLANE_V] = { |
| 688 | C2PlaneInfo::CHANNEL_CR, // channel |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 689 | (int32_t)ycbcrLayout.chroma_step, // colInc |
| 690 | (int32_t)ycbcrLayout.cstride, // rowInc |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 691 | 2, // mColSampling |
| 692 | 2, // mRowSampling |
| 693 | 8, // allocatedDepth |
| 694 | 8, // bitDepth |
| 695 | 0, // rightShift |
| 696 | C2PlaneInfo::NATIVE, // endianness |
| 697 | C2PlanarLayout::PLANE_V, // rootIx |
| 698 | 0, // offset |
| 699 | }; |
| 700 | // handle interleaved formats |
| 701 | intptr_t uvOffset = addr[C2PlanarLayout::PLANE_V] - addr[C2PlanarLayout::PLANE_U]; |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 702 | if (uvOffset > 0 && uvOffset < (intptr_t)ycbcrLayout.chroma_step) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 703 | layout->rootPlanes = 2; |
| 704 | layout->planes[C2PlanarLayout::PLANE_V].rootIx = C2PlanarLayout::PLANE_U; |
| 705 | layout->planes[C2PlanarLayout::PLANE_V].offset = uvOffset; |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 706 | } else if (uvOffset < 0 && uvOffset > -(intptr_t)ycbcrLayout.chroma_step) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 707 | layout->rootPlanes = 2; |
| 708 | layout->planes[C2PlanarLayout::PLANE_U].rootIx = C2PlanarLayout::PLANE_V; |
| 709 | layout->planes[C2PlanarLayout::PLANE_U].offset = -uvOffset; |
| 710 | } |
| 711 | break; |
| 712 | } |
Wonsik Kim | 29e3c4d | 2020-09-02 12:19:44 -0700 | [diff] [blame] | 713 | |
| 714 | case static_cast<uint32_t>(PixelFormat4::YCBCR_P010): { |
| 715 | void *pointer = nullptr; |
| 716 | status_t err = GraphicBufferMapper::get().lock( |
| 717 | const_cast<native_handle_t *>(mBuffer), grallocUsage, rect, &pointer); |
| 718 | if (err) { |
| 719 | ALOGE("failed transaction: lock(YCBCR_P010)"); |
| 720 | return C2_CORRUPTED; |
| 721 | } |
| 722 | addr[C2PlanarLayout::PLANE_Y] = (uint8_t *)pointer; |
| 723 | addr[C2PlanarLayout::PLANE_U] = (uint8_t *)pointer + mStride * 2 * rect.height(); |
| 724 | addr[C2PlanarLayout::PLANE_V] = addr[C2PlanarLayout::PLANE_U] + 2; |
| 725 | layout->type = C2PlanarLayout::TYPE_YUV; |
| 726 | layout->numPlanes = 3; |
| 727 | layout->rootPlanes = 2; |
| 728 | layout->planes[C2PlanarLayout::PLANE_Y] = { |
| 729 | C2PlaneInfo::CHANNEL_Y, // channel |
| 730 | 2, // colInc |
| 731 | static_cast<int32_t>(2 * mStride), // rowInc |
| 732 | 1, // mColSampling |
| 733 | 1, // mRowSampling |
| 734 | 16, // allocatedDepth |
| 735 | 10, // bitDepth |
| 736 | 6, // rightShift |
Praveen Chavan | 34493f1 | 2021-02-18 00:51:50 -0800 | [diff] [blame^] | 737 | kEndianness, // endianness |
Wonsik Kim | 29e3c4d | 2020-09-02 12:19:44 -0700 | [diff] [blame] | 738 | C2PlanarLayout::PLANE_Y, // rootIx |
| 739 | 0, // offset |
| 740 | }; |
| 741 | layout->planes[C2PlanarLayout::PLANE_U] = { |
| 742 | C2PlaneInfo::CHANNEL_CB, // channel |
| 743 | 4, // colInc |
| 744 | static_cast<int32_t>(2 * mStride), // rowInc |
| 745 | 2, // mColSampling |
| 746 | 2, // mRowSampling |
| 747 | 16, // allocatedDepth |
| 748 | 10, // bitDepth |
| 749 | 6, // rightShift |
Praveen Chavan | 34493f1 | 2021-02-18 00:51:50 -0800 | [diff] [blame^] | 750 | kEndianness, // endianness |
Wonsik Kim | 29e3c4d | 2020-09-02 12:19:44 -0700 | [diff] [blame] | 751 | C2PlanarLayout::PLANE_U, // rootIx |
| 752 | 0, // offset |
| 753 | }; |
| 754 | layout->planes[C2PlanarLayout::PLANE_V] = { |
| 755 | C2PlaneInfo::CHANNEL_CR, // channel |
| 756 | 4, // colInc |
| 757 | static_cast<int32_t>(2 * mStride), // rowInc |
| 758 | 2, // mColSampling |
| 759 | 2, // mRowSampling |
| 760 | 16, // allocatedDepth |
| 761 | 10, // bitDepth |
| 762 | 6, // rightShift |
Praveen Chavan | 34493f1 | 2021-02-18 00:51:50 -0800 | [diff] [blame^] | 763 | kEndianness, // endianness |
Wonsik Kim | 29e3c4d | 2020-09-02 12:19:44 -0700 | [diff] [blame] | 764 | C2PlanarLayout::PLANE_U, // rootIx |
| 765 | 2, // offset |
| 766 | }; |
| 767 | break; |
| 768 | } |
| 769 | |
| 770 | default: { |
Praveen Chavan | 34493f1 | 2021-02-18 00:51:50 -0800 | [diff] [blame^] | 771 | // We don't know what it is, let's try to lock it with gralloc4 |
Wonsik Kim | 29e3c4d | 2020-09-02 12:19:44 -0700 | [diff] [blame] | 772 | android_ycbcr ycbcrLayout; |
Praveen Chavan | 34493f1 | 2021-02-18 00:51:50 -0800 | [diff] [blame^] | 773 | c2_status_t status = Gralloc4Mapper_lock( |
| 774 | const_cast<native_handle_t*>(mBuffer), grallocUsage, rect, layout, addr); |
| 775 | if (status == C2_OK) { |
| 776 | break; |
| 777 | } |
Wonsik Kim | 29e3c4d | 2020-09-02 12:19:44 -0700 | [diff] [blame] | 778 | |
Praveen Chavan | 34493f1 | 2021-02-18 00:51:50 -0800 | [diff] [blame^] | 779 | // fallback to lockYCbCr |
Wonsik Kim | 29e3c4d | 2020-09-02 12:19:44 -0700 | [diff] [blame] | 780 | status_t err = GraphicBufferMapper::get().lockYCbCr( |
| 781 | const_cast<native_handle_t*>(mBuffer), grallocUsage, rect, &ycbcrLayout); |
Wonsik Kim | d91f3fb | 2021-02-24 12:35:31 -0800 | [diff] [blame] | 782 | if (err == OK && ycbcrLayout.y && ycbcrLayout.cb && ycbcrLayout.cr |
| 783 | && ycbcrLayout.ystride > 0 |
| 784 | && ycbcrLayout.cstride > 0 |
| 785 | && ycbcrLayout.chroma_step > 0) { |
Wonsik Kim | 29e3c4d | 2020-09-02 12:19:44 -0700 | [diff] [blame] | 786 | addr[C2PlanarLayout::PLANE_Y] = (uint8_t *)ycbcrLayout.y; |
| 787 | addr[C2PlanarLayout::PLANE_U] = (uint8_t *)ycbcrLayout.cb; |
| 788 | addr[C2PlanarLayout::PLANE_V] = (uint8_t *)ycbcrLayout.cr; |
| 789 | layout->type = C2PlanarLayout::TYPE_YUV; |
| 790 | layout->numPlanes = 3; |
| 791 | layout->rootPlanes = 3; |
| 792 | layout->planes[C2PlanarLayout::PLANE_Y] = { |
| 793 | C2PlaneInfo::CHANNEL_Y, // channel |
| 794 | 1, // colInc |
| 795 | (int32_t)ycbcrLayout.ystride, // rowInc |
| 796 | 1, // mColSampling |
| 797 | 1, // mRowSampling |
| 798 | 8, // allocatedDepth |
| 799 | 8, // bitDepth |
| 800 | 0, // rightShift |
| 801 | C2PlaneInfo::NATIVE, // endianness |
| 802 | C2PlanarLayout::PLANE_Y, // rootIx |
| 803 | 0, // offset |
| 804 | }; |
| 805 | layout->planes[C2PlanarLayout::PLANE_U] = { |
| 806 | C2PlaneInfo::CHANNEL_CB, // channel |
| 807 | (int32_t)ycbcrLayout.chroma_step, // colInc |
| 808 | (int32_t)ycbcrLayout.cstride, // rowInc |
| 809 | 2, // mColSampling |
| 810 | 2, // mRowSampling |
| 811 | 8, // allocatedDepth |
| 812 | 8, // bitDepth |
| 813 | 0, // rightShift |
| 814 | C2PlaneInfo::NATIVE, // endianness |
| 815 | C2PlanarLayout::PLANE_U, // rootIx |
| 816 | 0, // offset |
| 817 | }; |
| 818 | layout->planes[C2PlanarLayout::PLANE_V] = { |
| 819 | C2PlaneInfo::CHANNEL_CR, // channel |
| 820 | (int32_t)ycbcrLayout.chroma_step, // colInc |
| 821 | (int32_t)ycbcrLayout.cstride, // rowInc |
| 822 | 2, // mColSampling |
| 823 | 2, // mRowSampling |
| 824 | 8, // allocatedDepth |
| 825 | 8, // bitDepth |
| 826 | 0, // rightShift |
| 827 | C2PlaneInfo::NATIVE, // endianness |
| 828 | C2PlanarLayout::PLANE_V, // rootIx |
| 829 | 0, // offset |
| 830 | }; |
| 831 | // handle interleaved formats |
| 832 | intptr_t uvOffset = addr[C2PlanarLayout::PLANE_V] - addr[C2PlanarLayout::PLANE_U]; |
| 833 | if (uvOffset > 0 && uvOffset < (intptr_t)ycbcrLayout.chroma_step) { |
| 834 | layout->rootPlanes = 2; |
| 835 | layout->planes[C2PlanarLayout::PLANE_V].rootIx = C2PlanarLayout::PLANE_U; |
| 836 | layout->planes[C2PlanarLayout::PLANE_V].offset = uvOffset; |
| 837 | } else if (uvOffset < 0 && uvOffset > -(intptr_t)ycbcrLayout.chroma_step) { |
| 838 | layout->rootPlanes = 2; |
| 839 | layout->planes[C2PlanarLayout::PLANE_U].rootIx = C2PlanarLayout::PLANE_V; |
| 840 | layout->planes[C2PlanarLayout::PLANE_U].offset = -uvOffset; |
| 841 | } |
| 842 | break; |
| 843 | } |
| 844 | |
| 845 | // We really don't know what this is; lock the buffer and pass it through --- |
| 846 | // the client may know how to interpret it. |
Lajos Molnar | 8faebbc | 2021-06-30 17:07:42 -0700 | [diff] [blame] | 847 | |
| 848 | // unlock previous allocation if it was successful |
| 849 | if (err == OK) { |
| 850 | err = GraphicBufferMapper::get().unlock(mBuffer); |
| 851 | if (err) { |
| 852 | ALOGE("failed transaction: unlock"); |
| 853 | return C2_CORRUPTED; |
| 854 | } |
| 855 | } |
| 856 | |
Wonsik Kim | 29e3c4d | 2020-09-02 12:19:44 -0700 | [diff] [blame] | 857 | void *pointer = nullptr; |
| 858 | err = GraphicBufferMapper::get().lock( |
| 859 | const_cast<native_handle_t *>(mBuffer), grallocUsage, rect, &pointer); |
| 860 | if (err) { |
| 861 | ALOGE("failed transaction: lock(??? %x)", mFormat); |
| 862 | return C2_CORRUPTED; |
| 863 | } |
| 864 | addr[0] = (uint8_t *)pointer; |
| 865 | layout->type = C2PlanarLayout::TYPE_UNKNOWN; |
| 866 | layout->numPlanes = 1; |
| 867 | layout->rootPlanes = 1; |
| 868 | layout->planes[0] = { |
| 869 | // TODO: CHANNEL_UNKNOWN? |
| 870 | C2PlaneInfo::channel_t(0xFF), // channel |
| 871 | 1, // colInc |
| 872 | int32_t(mStride), // rowInc |
| 873 | 1, // mColSampling |
| 874 | 1, // mRowSampling |
| 875 | 8, // allocatedDepth |
| 876 | 8, // bitDepth |
| 877 | 0, // rightShift |
| 878 | C2PlaneInfo::NATIVE, // endianness |
| 879 | 0, // rootIx |
| 880 | 0, // offset |
| 881 | }; |
| 882 | break; |
| 883 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 884 | } |
| 885 | mLocked = true; |
| 886 | |
| 887 | return C2_OK; |
| 888 | } |
| 889 | |
| 890 | c2_status_t C2AllocationGralloc::unmap( |
| 891 | uint8_t **addr, C2Rect rect, C2Fence *fence /* nullable */) { |
| 892 | // TODO: check addr and size, use fence |
| 893 | (void)addr; |
| 894 | (void)rect; |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 895 | (void)fence; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 896 | |
| 897 | std::lock_guard<std::mutex> lock(mMappedLock); |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 898 | // TODO: fence |
| 899 | status_t err = GraphicBufferMapper::get().unlock(mBuffer); |
| 900 | if (err) { |
| 901 | ALOGE("failed transaction: unlock"); |
| 902 | return C2_CORRUPTED; |
Pawin Vongmasa | d032f2d | 2019-05-15 08:42:44 -0700 | [diff] [blame] | 903 | } |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 904 | |
| 905 | mLocked = false; |
| 906 | return C2_OK; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | bool C2AllocationGralloc::equals(const std::shared_ptr<const C2GraphicAllocation> &other) const { |
| 910 | return other && other->handle() == handle(); |
| 911 | } |
| 912 | |
| 913 | /* ===================================== GRALLOC ALLOCATOR ==================================== */ |
| 914 | class C2AllocatorGralloc::Impl { |
| 915 | public: |
| 916 | Impl(id_t id, bool bufferQueue); |
| 917 | |
| 918 | id_t getId() const { |
| 919 | return mTraits->id; |
| 920 | } |
| 921 | |
| 922 | C2String getName() const { |
| 923 | return mTraits->name; |
| 924 | } |
| 925 | |
| 926 | std::shared_ptr<const C2Allocator::Traits> getTraits() const { |
| 927 | return mTraits; |
| 928 | } |
| 929 | |
| 930 | c2_status_t newGraphicAllocation( |
| 931 | uint32_t width, uint32_t height, uint32_t format, const C2MemoryUsage &usage, |
| 932 | std::shared_ptr<C2GraphicAllocation> *allocation); |
| 933 | |
| 934 | c2_status_t priorGraphicAllocation( |
| 935 | const C2Handle *handle, |
| 936 | std::shared_ptr<C2GraphicAllocation> *allocation); |
| 937 | |
| 938 | c2_status_t status() const { return mInit; } |
| 939 | |
| 940 | private: |
| 941 | std::shared_ptr<C2Allocator::Traits> mTraits; |
| 942 | c2_status_t mInit; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 943 | const bool mBufferQueue; |
| 944 | }; |
| 945 | |
| 946 | void _UnwrapNativeCodec2GrallocMetadata( |
| 947 | const C2Handle *const handle, |
| 948 | uint32_t *width, uint32_t *height, uint32_t *format,uint64_t *usage, uint32_t *stride, |
| 949 | uint32_t *generation, uint64_t *igbp_id, uint32_t *igbp_slot) { |
| 950 | (void)C2HandleGralloc::Import(handle, width, height, format, usage, stride, |
| 951 | generation, igbp_id, igbp_slot); |
| 952 | } |
| 953 | |
| 954 | C2AllocatorGralloc::Impl::Impl(id_t id, bool bufferQueue) |
| 955 | : mInit(C2_OK), mBufferQueue(bufferQueue) { |
| 956 | // TODO: get this from allocator |
| 957 | C2MemoryUsage minUsage = { 0, 0 }, maxUsage = { ~(uint64_t)0, ~(uint64_t)0 }; |
| 958 | Traits traits = { "android.allocator.gralloc", id, C2Allocator::GRAPHIC, minUsage, maxUsage }; |
| 959 | mTraits = std::make_shared<C2Allocator::Traits>(traits); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | c2_status_t C2AllocatorGralloc::Impl::newGraphicAllocation( |
| 963 | uint32_t width, uint32_t height, uint32_t format, const C2MemoryUsage &usage, |
| 964 | std::shared_ptr<C2GraphicAllocation> *allocation) { |
| 965 | uint64_t grallocUsage = static_cast<C2AndroidMemoryUsage>(usage).asGrallocUsage(); |
| 966 | ALOGV("allocating buffer with usage %#llx => %#llx", |
| 967 | (long long)usage.expected, (long long)grallocUsage); |
| 968 | |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 969 | buffer_handle_t buffer; |
Pawin Vongmasa | d032f2d | 2019-05-15 08:42:44 -0700 | [diff] [blame] | 970 | |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 971 | uint32_t stride = 0; |
Pawin Vongmasa | d032f2d | 2019-05-15 08:42:44 -0700 | [diff] [blame] | 972 | |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 973 | status_t err = GraphicBufferAllocator::get().allocateRawHandle(width, height, format, |
| 974 | 1u /* layer count */, grallocUsage, &buffer, &stride, "C2GrallocAllocation"); |
| 975 | if (err) { |
| 976 | ALOGE("failed transaction: allocate"); |
| 977 | return C2_CORRUPTED; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 978 | } |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 979 | |
| 980 | hidl_handle hidlHandle; |
| 981 | hidlHandle.setTo(const_cast<native_handle_t*>(buffer), true); |
| 982 | |
| 983 | allocation->reset(new C2AllocationGralloc( |
| 984 | width, height, format, 1u /* layer count */, grallocUsage, stride, hidlHandle, |
| 985 | C2HandleGralloc::WrapAndMoveNativeHandle( |
| 986 | hidlHandle, width, height, |
| 987 | format, grallocUsage, stride, |
| 988 | 0, 0, mBufferQueue ? ~0 : 0), |
| 989 | mTraits->id)); |
| 990 | return C2_OK; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | c2_status_t C2AllocatorGralloc::Impl::priorGraphicAllocation( |
| 994 | const C2Handle *handle, |
| 995 | std::shared_ptr<C2GraphicAllocation> *allocation) { |
Pawin Vongmasa | d032f2d | 2019-05-15 08:42:44 -0700 | [diff] [blame] | 996 | |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 997 | uint32_t generation; |
| 998 | uint64_t igbp_id; |
| 999 | uint32_t igbp_slot; |
Pawin Vongmasa | d032f2d | 2019-05-15 08:42:44 -0700 | [diff] [blame] | 1000 | |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 1001 | uint32_t width; |
| 1002 | uint32_t height; |
| 1003 | uint32_t format; |
| 1004 | uint32_t layerCount = 1; |
| 1005 | uint64_t grallocUsage; |
| 1006 | uint32_t stride; |
Pawin Vongmasa | d032f2d | 2019-05-15 08:42:44 -0700 | [diff] [blame] | 1007 | |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 1008 | const C2HandleGralloc *grallocHandle = C2HandleGralloc::Import( |
| 1009 | handle, &width, &height, &format, &grallocUsage, &stride, |
| 1010 | &generation, &igbp_id, &igbp_slot); |
| 1011 | if (grallocHandle == nullptr) { |
| 1012 | return C2_BAD_VALUE; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1013 | } |
Marissa Wall | 2a24a30 | 2019-11-25 11:19:18 -0800 | [diff] [blame] | 1014 | |
| 1015 | hidl_handle hidlHandle; |
| 1016 | hidlHandle.setTo(C2HandleGralloc::UnwrapNativeHandle(grallocHandle), true); |
| 1017 | |
| 1018 | allocation->reset(new C2AllocationGralloc( |
| 1019 | width, height, format, layerCount, |
| 1020 | grallocUsage, stride, hidlHandle, grallocHandle, mTraits->id)); |
| 1021 | return C2_OK; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | C2AllocatorGralloc::C2AllocatorGralloc(id_t id, bool bufferQueue) |
| 1025 | : mImpl(new Impl(id, bufferQueue)) {} |
| 1026 | |
| 1027 | C2AllocatorGralloc::~C2AllocatorGralloc() { delete mImpl; } |
| 1028 | |
| 1029 | C2Allocator::id_t C2AllocatorGralloc::getId() const { |
| 1030 | return mImpl->getId(); |
| 1031 | } |
| 1032 | |
| 1033 | C2String C2AllocatorGralloc::getName() const { |
| 1034 | return mImpl->getName(); |
| 1035 | } |
| 1036 | |
| 1037 | std::shared_ptr<const C2Allocator::Traits> C2AllocatorGralloc::getTraits() const { |
| 1038 | return mImpl->getTraits(); |
| 1039 | } |
| 1040 | |
| 1041 | c2_status_t C2AllocatorGralloc::newGraphicAllocation( |
| 1042 | uint32_t width, uint32_t height, uint32_t format, C2MemoryUsage usage, |
| 1043 | std::shared_ptr<C2GraphicAllocation> *allocation) { |
| 1044 | return mImpl->newGraphicAllocation(width, height, format, usage, allocation); |
| 1045 | } |
| 1046 | |
| 1047 | c2_status_t C2AllocatorGralloc::priorGraphicAllocation( |
| 1048 | const C2Handle *handle, |
| 1049 | std::shared_ptr<C2GraphicAllocation> *allocation) { |
| 1050 | return mImpl->priorGraphicAllocation(handle, allocation); |
| 1051 | } |
| 1052 | |
| 1053 | c2_status_t C2AllocatorGralloc::status() const { |
| 1054 | return mImpl->status(); |
| 1055 | } |
| 1056 | |
John Stultz | 653ddd1 | 2020-09-19 05:26:24 +0000 | [diff] [blame] | 1057 | // static |
| 1058 | bool C2AllocatorGralloc::CheckHandle(const C2Handle* const o) { |
| 1059 | return C2HandleGralloc::IsValid(o); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | } // namespace android |