1 /*
2  * Copyright (C) 2016-2019 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_module.h"
23 #include "mali_gralloc_private_interface_types.h"
24 #include "mali_gralloc_buffer.h"
25 #include "mali_gralloc_bufferdescriptor.h"
26 
27 /*
28  * AFBC superblock type.
29  */
30 enum AllocBaseType
31 {
32 	UNCOMPRESSED,       /* No compression. */
33 	AFBC,               /* AFBC basic (16x16). */
34 	AFBC_WIDEBLK,       /* AFBC wide-block (32x8). */
35 	AFBC_EXTRAWIDEBLK,  /* AFBC extra-wide-block (64x4). */
36 };
37 
38 /*
39  * Allocation type.
40  *
41  * Allocation-specific properties of the AFBC format modifiers
42  * described by MALI_GRALLOC_INTFMT_*.
43  *
44  */
45 typedef struct {
46 
47 	/*
48 	 * AFBC superblock type for either:
49 	 * - single plane AFBC format or
50 	 * - first/luma plane of multi-plane AFBC format.
51 	 */
52 	AllocBaseType primary_type;
53 
54 	/*
55 	 * Multi-plane AFBC format. AFBC chroma-only plane(s) are
56 	 * always compressed with superblock type 'AFBC_EXTRAWIDEBLK'.
57 	 */
58 	bool is_multi_plane;
59 
60 	/*
61 	 * Allocate tiled AFBC headers.
62 	 */
63 	bool is_tiled;
64 
65 	/*
66 	 * Pad AFBC header stride to 64-byte alignment
67 	 * (multiple of 4x16B headers).
68 	 */
69 	bool is_padded;
70 
71 	/*
72 	 * Front-buffer rendering safe AFBC allocations include an
73 	 * additional 4kB-aligned body buffer.
74 	 */
75 	bool is_frontbuffer_safe;
76 
is_afbc__anon4bcb00cd010877 	bool is_afbc() const
78 	{
79 		return primary_type != UNCOMPRESSED;
80 	}
81 } alloc_type_t;
82 
83 
84 
85 int mali_gralloc_derive_format_and_size(mali_gralloc_module *m,
86                                         buffer_descriptor_t * const bufDescriptor);
87 
88 int mali_gralloc_buffer_allocate(mali_gralloc_module *m, const gralloc_buffer_descriptor_t *descriptors,
89                                  uint32_t numDescriptors, buffer_handle_t *pHandle, bool *shared_backend);
90 
91 int mali_gralloc_buffer_free(buffer_handle_t pHandle);
92 
93 void init_afbc(uint8_t *buf, uint64_t internal_format, const bool is_multi_plane, int w, int h);
94 
95 uint32_t lcm(uint32_t a, uint32_t b);
96 
97 bool get_alloc_type(const uint64_t format_ext,
98                     const uint32_t format_idx,
99                     const uint64_t usage,
100                     alloc_type_t * const alloc_type);
101 
102 #endif /* MALI_GRALLOC_BUFFERALLOCATION_H_ */
103