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 #ifndef MALI_GRALLOC_BUFFERALLOCATION_H_ 19 #define MALI_GRALLOC_BUFFERALLOCATION_H_ 20 21 #include <hardware/hardware.h> 22 #include "mali_gralloc_buffer.h" 23 #include "core/mali_gralloc_bufferdescriptor.h" 24 25 /* Compression scheme */ 26 enum class AllocBaseType 27 { 28 /* 29 * No compression scheme 30 */ 31 UNCOMPRESSED, 32 33 /* 34 * Arm Framebuffer Compression 35 */ 36 AFBC, /* 16 x 16 block size */ 37 AFBC_WIDEBLK, /* 32 x 8 block size */ 38 AFBC_EXTRAWIDEBLK, /* 64 x 4 block size */ 39 40 }; 41 42 /* 43 * Allocation type. 44 * 45 * Allocation-specific properties of format modifiers 46 * described by MALI_GRALLOC_INTFMT_*. 47 */ 48 struct AllocType 49 { 50 /* 51 * The compression scheme in use 52 * 53 * For AFBC formats, this describes: 54 * - the block size for single plane base formats, or 55 * - the block size of the first/luma plane for multi-plane base formats. 56 */ 57 AllocBaseType primary_type{AllocBaseType::UNCOMPRESSED}; 58 59 /* 60 * Multi-plane AFBC format. AFBC chroma-only plane(s) are 61 * always compressed with superblock type 'AFBC_EXTRAWIDEBLK'. 62 */ 63 bool is_multi_plane{}; 64 65 /* 66 * Allocate tiled AFBC headers. 67 */ 68 bool is_tiled{}; 69 70 /* 71 * Pad AFBC header stride to 64-byte alignment 72 * (multiple of 4x16B headers). 73 */ 74 bool is_padded{}; 75 76 /* 77 * Front-buffer rendering safe AFBC allocations include an 78 * additional 4kB-aligned body buffer. 79 */ 80 bool is_frontbuffer_safe{}; 81 is_afbcAllocType82 bool is_afbc() const 83 { 84 switch (primary_type) 85 { 86 case AllocBaseType::AFBC: 87 case AllocBaseType::AFBC_WIDEBLK: 88 case AllocBaseType::AFBC_EXTRAWIDEBLK: 89 return true; 90 default: 91 return false; 92 } 93 } 94 95 }; 96 97 using alloc_type_t = AllocType; 98 99 int mali_gralloc_derive_format_and_size(buffer_descriptor_t * const bufDescriptor); 100 101 int mali_gralloc_buffer_allocate(const gralloc_buffer_descriptor_t *descriptors, 102 uint32_t numDescriptors, buffer_handle_t *pHandle, bool *shared_backend, 103 int fd = -1); 104 105 int mali_gralloc_buffer_free(buffer_handle_t pHandle); 106 107 void init_afbc(uint8_t *buf, uint64_t internal_format, const bool is_multi_plane, int w, int h); 108 109 uint32_t lcm(uint32_t a, uint32_t b); 110 111 bool get_alloc_type(const uint64_t format_ext, 112 const uint32_t format_idx, 113 const uint64_t usage, 114 alloc_type_t * const alloc_type); 115 116 #endif /* MALI_GRALLOC_BUFFERALLOCATION_H_ */ 117