• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 Samsung Electronics Co. Ltd.
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 #ifndef VENDOR_GRAPHIC_BUFFER_H_
18 #define VENDOR_GRAPHIC_BUFFER_H_
19 
20 #include <cstdint>
21 #include <ui/GraphicTypes.h>
22 #include <ui/GraphicBufferMapper.h>
23 #include <ui/GraphicBufferAllocator.h>
24 #include <ui/Rect.h>
25 #include <ui/PixelFormat.h>
26 
27 /* Gralloc1 usages enum is provided here to ensure backward compatibility
28  * This enum will be deprecated in Android S so please consider switching to
29  * BufferUsage::<USAGE> found in
30  * hardware/interfaces/1.0(or 1.1, 1.2)/types.hal
31  */
32 #include <hardware/gralloc1.h>
33 
34 namespace vendor {
35 namespace graphics {
36 
37 /* Android default usages */
38 typedef android::hardware::graphics::common::V1_2::BufferUsage BufferUsage;
39 
40 enum VendorGraphicBufferUsage {
41 /* S.LSI specific usages */
42 	NO_AFBC                         = 1ULL << 29,
43 	MFC                             = 1ULL << 50,  /* identical to GRALLOC_USAGE_GOOGLE_IP_MFC */
44 	BW                              = 1ULL << 51,  /* identical to GRALLOC_USAGE_GOOGLE_IP_BW */
45 	ROIINFO                         = 1ULL << 52,
46 	AFBC_PADDING                    = 1ULL << 53,
47 	FORCE_BACKBUFFER                = 1ULL << 54,
48 	FRONTBUFFER                     = 1ULL << 55,
49 	NOZEROED                        = 1ULL << 58,
50 	PRIVATE_NONSECURE               = 1ULL << 59,
51 	VIDEO_PRIVATE_DATA              = 1ULL << 60,
52 /* Google-specific usages */
53 	CAMERA_STATS                    = 1ULL << 30,
54 	TPU_OUTPUT                      = 1ULL << 31,
55 	TPU_INPUT                       = 1ULL << 62
56 };
57 
58 
59 /* A wrapper class to gralloc private handle */
60 class VendorGraphicBufferMeta {
61 private:
VendorGraphicBufferMeta()62 	VendorGraphicBufferMeta() {};
63 
64 public:
65 	enum
66 	{
67 		PRIV_FLAGS_USES_2PRIVATE_DATA = 1U << 4,
68 		PRIV_FLAGS_USES_3PRIVATE_DATA = 1U << 5,
69 	};
70 
71 	union {
72 		int fds[3];
73 
74 		struct {
75 			int fd  = -1;
76 			int fd1 = -1;
77 			int fd2 = -1;
78 		};
79 	};
80 
81 	union {
82 		int sizes[3];
83 
84 		struct {
85 			int size  = 0;
86 			int size1 = 0;
87 			int size2 = 0;
88 		};
89 	};
90 
91 	union {
92 		uint32_t offsets[3];
93 
94 		struct {
95 			uint32_t offset  = 0;
96 			uint32_t offset1 = 0;
97 			uint32_t offset2 = 0;
98 		};
99 	};
100 
101 	union
102 	{
103 		uint32_t format;
104 		uint64_t internal_format = 0llu;
105 	};
106 	int frameworkFormat = 0;
107 
108 	int width  = 0;
109 	int height = 0;
110 	uint32_t stride  = 0;
111 	uint32_t vstride = 0;
112 
113 	uint64_t producer_usage = 0llu;
114 	uint64_t consumer_usage = 0llu;
115 
116 	int flags = 0;
117 
118 	uint64_t unique_id = 0;
119 
120 	VendorGraphicBufferMeta(const buffer_handle_t handle);
121 
122 	void init(const buffer_handle_t handle);
123 
124 	static int get_fd(buffer_handle_t, int num);
125 	static int get_size(buffer_handle_t, int num);
126 	static uint32_t get_format(buffer_handle_t);
127 	static uint64_t get_internal_format(buffer_handle_t);
128 	static uint64_t get_frameworkFormat(buffer_handle_t);
129 	static int get_width(buffer_handle_t);
130 	static int get_height(buffer_handle_t);
131 	static uint32_t get_stride(buffer_handle_t);
132 	static uint32_t get_stride_in_bytes(buffer_handle_t);
133 	static uint32_t get_vstride(buffer_handle_t);
134 	static uint64_t get_producer_usage(buffer_handle_t);
135 	static uint64_t get_consumer_usage(buffer_handle_t);
136 	static uint64_t get_flags(buffer_handle_t);
137 
138 	static uint64_t get_usage(buffer_handle_t);
139 	static int is_afbc(buffer_handle_t);
140 	static int is_sbwc(buffer_handle_t);
141 	static void* get_video_metadata(buffer_handle_t);
142 
143 	static uint32_t get_format_fourcc(buffer_handle_t);
144 	static uint64_t get_format_modifier(buffer_handle_t);
145 
146 	/* get_video_metadata_roiinfo is only supported with gralloc4
147 	 * When gralloc3 is used, will always return nullptr
148 	 */
149 	static void* get_video_metadata_roiinfo(buffer_handle_t);
150 	static int get_dataspace(buffer_handle_t);
151 	static int set_dataspace(buffer_handle_t hnd, android_dataspace_t dataspace);
152 
153 	// There should be no users of this function. It'll generate a trap.
154 	static int get_video_metadata_fd(buffer_handle_t);
155 
156 	static buffer_handle_t import_buffer(buffer_handle_t);
157 	static int free_buffer(buffer_handle_t);
158 };
159 
160 typedef class android::GraphicBufferMapper VendorGraphicBufferMapper;
161 typedef class android::GraphicBufferAllocator VendorGraphicBufferAllocator;
162 
163 } /* namespace graphics */
164 } /* namespace vendor */
165 
166 #endif /* GRALLOC_PRIV_INTERFACE_H_ */
167