1 /*
2  * Copyright (C) 2016-2018 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 <hardware/hardware.h>
23 #include "gralloc_priv.h"
24 #include "mali_gralloc_module.h"
25 #include "mali_gralloc_formats.h"
26 
27 #if GRALLOC_VERSION_MAJOR == 1
28 #include <hardware/gralloc1.h>
29 #elif GRALLOC_VERSION_MAJOR == 0
30 #include <hardware/gralloc.h>
31 #endif
32 
33 typedef uint64_t gralloc_buffer_descriptor_t;
34 
35 typedef struct buffer_descriptor
36 {
37 	uint32_t signature;
38 
39 	uint32_t width;
40 	uint32_t height;
41 	uint64_t producer_usage;
42 	uint64_t consumer_usage;
43 	uint64_t hal_format;
44 	uint32_t layer_count;
45 
46 	mali_gralloc_format_type format_type;
47 	union
48 	{
49 		size_t size;
50 		size_t sizes[3];
51 		uint64_t padding[3];
52 	};
53 	int pixel_stride;
54 	uint64_t internal_format;
55 	uint64_t alloc_format;
56 	int fd_count;
57 	int alloc_video_private_data;
58 	plane_info_t plane_info[MAX_PLANES];
59 	int plane_count;
60 
61 #ifdef __cplusplus
buffer_descriptorbuffer_descriptor62 	buffer_descriptor() :
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 		pixel_stride(0),
72 	    internal_format(0),
73 	    alloc_format(0),
74 		fd_count(1),
75 		alloc_video_private_data(0),
76 		plane_count(0)
77 
78 	{
79 		sizes[0] = sizes[1] = sizes[2] = 0;
80 		memset(plane_info, 0, sizeof(plane_info_t) * MAX_PLANES);
81 	}
82 #endif
83 
dumpbuffer_descriptor84 	void dump() const
85 	{
86 		ALOGI("buffer_descriptor: "
87 				"wh(%u %u) "
88 				"usage_pc(0x%" PRIx64 " 0x%" PRIx64 ") "
89 				"hal_format(0x%" PRIx64 ") "
90 				"layer_count(%u) sizes(%zu %zu %zu) "
91 				"strde(%d) byte_stride(%d) alloc_wh(%d %d) "
92 				"internal_format(0x%" PRIx64 ") alloc_format(0x%" PRIx64 ") "
93 				"fd_count(%d) plane_count(%d)"
94 				"\n",
95 				width, height, producer_usage, consumer_usage, hal_format,
96 				layer_count, sizes[0], sizes[1], sizes[2],
97 				pixel_stride, plane_info[0].byte_stride, plane_info[0].alloc_width, plane_info[0].alloc_height,
98 				internal_format, alloc_format, fd_count, plane_count
99 			);
100 	}
101 } buffer_descriptor_t;
102 
103 #if GRALLOC_VERSION_MAJOR == 1
104 int mali_gralloc_create_descriptor_internal(gralloc1_buffer_descriptor_t *outDescriptor);
105 int mali_gralloc_destroy_descriptor_internal(gralloc1_buffer_descriptor_t descriptor);
106 int mali_gralloc_set_dimensions_internal(gralloc1_buffer_descriptor_t descriptor, uint32_t width, uint32_t height);
107 int mali_gralloc_set_format_internal(gralloc1_buffer_descriptor_t descriptor, int32_t format);
108 int mali_gralloc_set_producerusage_internal(gralloc1_buffer_descriptor_t descriptor, uint64_t usage);
109 int mali_gralloc_set_consumerusage_internal(gralloc1_buffer_descriptor_t descriptor, uint64_t usage);
110 
111 int mali_gralloc_get_backing_store_internal(buffer_handle_t buffer, gralloc1_backing_store_t *outStore);
112 int mali_gralloc_get_consumer_usage_internal(buffer_handle_t buffer, uint64_t *outUsage);
113 int mali_gralloc_get_dimensions_internal(buffer_handle_t buffer, uint32_t *outWidth, uint32_t *outHeight);
114 int mali_gralloc_get_format_internal(buffer_handle_t buffer, int32_t *outFormat);
115 int mali_gralloc_get_producer_usage_internal(buffer_handle_t buffer, uint64_t *outUsage);
116 #if PLATFORM_SDK_VERSION >= 26
117 int mali_gralloc_set_layer_count_internal(gralloc1_buffer_descriptor_t descriptor, uint32_t layerCount);
118 int mali_gralloc_get_layer_count_internal(buffer_handle_t buffer, uint32_t *outLayerCount);
119 #endif
120 #endif
121 int mali_gralloc_query_getstride(buffer_handle_t handle, int *pixelStride);
122 
123 #endif /* MALI_GRALLOC_BUFFERDESCRIPTOR_H_ */
124