1 /* 2 * Copyright (C) 2016-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_BUFFERDESCRIPTOR_H_ 20 #define MALI_GRALLOC_BUFFERDESCRIPTOR_H_ 21 22 #include "mali_gralloc_buffer.h" 23 #include "mali_gralloc_formats.h" 24 #include <string> 25 #include <aidl/android/hardware/graphics/common/ExtendableType.h> 26 27 typedef uint64_t gralloc_buffer_descriptor_t; 28 29 std::string describe_usage(uint64_t usage); 30 31 /* A buffer_descriptor contains the requested parameters for the buffer 32 * as well as the calculated parameters that are passed to the allocator. 33 */ 34 struct buffer_descriptor_t 35 { 36 /* For validation. */ 37 uint32_t signature; 38 39 /* Requested parameters from IAllocator. */ 40 uint32_t width; 41 uint32_t height; 42 uint64_t producer_usage; 43 uint64_t consumer_usage; 44 uint64_t hal_format; 45 uint32_t layer_count; 46 mali_gralloc_format_type format_type; 47 std::string name; 48 uint64_t reserved_size; 49 std::vector<::aidl::android::hardware::graphics::common::ExtendableType> additional_options; 50 51 /* 52 * Calculated values that will be passed to the allocator in order to 53 * allocate the buffer. 54 */ 55 uint64_t alloc_sizes[MAX_PLANES]; 56 uint64_t pixel_stride; 57 uint64_t alloc_format; 58 uint32_t fd_count; 59 uint32_t plane_count; 60 plane_info_t plane_info[MAX_PLANES]; 61 buffer_descriptor_tbuffer_descriptor_t62 buffer_descriptor_t() : 63 signature(0), 64 width(0), 65 height(0), 66 producer_usage(0), 67 consumer_usage(0), 68 hal_format(0), 69 layer_count(0), 70 format_type(MALI_GRALLOC_FORMAT_TYPE_USAGE), 71 reserved_size(0), 72 pixel_stride(0), 73 alloc_format(0), 74 fd_count(1), 75 plane_count(1) 76 { 77 memset(plane_info, 0, sizeof(plane_info_t) * MAX_PLANES); 78 memset(alloc_sizes, 0, sizeof(alloc_sizes)); 79 } 80 dumpbuffer_descriptor_t81 void dump(const std::string &str) const { 82 ALOGI("buffer_descriptor: %s " 83 "wh(%u %u) " 84 "usage_pc(%s 0x%" PRIx64 " %s 0x%" PRIx64 ") " 85 "hal_format(0x%" PRIx64 ") " 86 "layer_count(%u) " 87 "format_type(%u) " 88 "name(%s)" 89 "reserved_size(%" PRIu64 ") " 90 "alloc_sizes(%" PRIu64 ", %" PRIu64 ", %" PRIu64 ")" 91 "pixel_stride(%" PRIu64 ") alloc_format(0x%" PRIx64 ") fd_count(%d) " 92 "plane_count(%u) " 93 "plane[0](offset %" PRId64 ", idx %u, size %" PRIu64 " byte_stride %" PRIu64 ", wh %" PRIu64 " %" PRIu64 ")" 94 "plane[1](offset %" PRId64 ", idx %u, size %" PRIu64 " byte_stride %" PRIu64 ", wh %" PRIu64 " %" PRIu64 ")" 95 "plane[2](offset %" PRId64 ", idx %u, size %" PRIu64 " byte_stride %" PRIu64 ", wh %" PRIu64 " %" PRIu64 ")" 96 "\n", 97 str.c_str(), 98 width, height, 99 describe_usage(producer_usage).c_str(), producer_usage, 100 describe_usage(consumer_usage).c_str(), consumer_usage, 101 hal_format, 102 layer_count, 103 format_type, 104 name.c_str(), 105 reserved_size, 106 alloc_sizes[0], alloc_sizes[1], alloc_sizes[2], 107 pixel_stride, alloc_format, fd_count, 108 plane_count, 109 plane_info[0].offset, plane_info[0].fd_idx, plane_info[0].size, plane_info[0].byte_stride, plane_info[0].alloc_width, plane_info[0].alloc_height, 110 plane_info[1].offset, plane_info[1].fd_idx, plane_info[1].size, plane_info[1].byte_stride, plane_info[1].alloc_width, plane_info[1].alloc_height, 111 plane_info[2].offset, plane_info[2].fd_idx, plane_info[2].size, plane_info[2].byte_stride, plane_info[2].alloc_width, plane_info[2].alloc_height 112 ); 113 } 114 }; 115 116 #endif /* MALI_GRALLOC_BUFFERDESCRIPTOR_H_ */ 117