xref: /aosp_15_r20/external/igt-gpu-tools/lib/igt_fb.h (revision d83cc019efdc2edc6c4b16e9034a3ceb8d35d77c)
1*d83cc019SAndroid Build Coastguard Worker /*
2*d83cc019SAndroid Build Coastguard Worker  * Copyright © 2013,2014 Intel Corporation
3*d83cc019SAndroid Build Coastguard Worker  *
4*d83cc019SAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a
5*d83cc019SAndroid Build Coastguard Worker  * copy of this software and associated documentation files (the "Software"),
6*d83cc019SAndroid Build Coastguard Worker  * to deal in the Software without restriction, including without limitation
7*d83cc019SAndroid Build Coastguard Worker  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*d83cc019SAndroid Build Coastguard Worker  * and/or sell copies of the Software, and to permit persons to whom the
9*d83cc019SAndroid Build Coastguard Worker  * Software is furnished to do so, subject to the following conditions:
10*d83cc019SAndroid Build Coastguard Worker  *
11*d83cc019SAndroid Build Coastguard Worker  * The above copyright notice and this permission notice (including the next
12*d83cc019SAndroid Build Coastguard Worker  * paragraph) shall be included in all copies or substantial portions of the
13*d83cc019SAndroid Build Coastguard Worker  * Software.
14*d83cc019SAndroid Build Coastguard Worker  *
15*d83cc019SAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*d83cc019SAndroid Build Coastguard Worker  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*d83cc019SAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*d83cc019SAndroid Build Coastguard Worker  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*d83cc019SAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*d83cc019SAndroid Build Coastguard Worker  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21*d83cc019SAndroid Build Coastguard Worker  * IN THE SOFTWARE.
22*d83cc019SAndroid Build Coastguard Worker  *
23*d83cc019SAndroid Build Coastguard Worker  * Authors:
24*d83cc019SAndroid Build Coastguard Worker  * 	Daniel Vetter <[email protected]>
25*d83cc019SAndroid Build Coastguard Worker  * 	Damien Lespiau <[email protected]>
26*d83cc019SAndroid Build Coastguard Worker  */
27*d83cc019SAndroid Build Coastguard Worker 
28*d83cc019SAndroid Build Coastguard Worker #ifndef __IGT_FB_H__
29*d83cc019SAndroid Build Coastguard Worker #define __IGT_FB_H__
30*d83cc019SAndroid Build Coastguard Worker 
31*d83cc019SAndroid Build Coastguard Worker #include <cairo.h>
32*d83cc019SAndroid Build Coastguard Worker #include <stddef.h>
33*d83cc019SAndroid Build Coastguard Worker #include <stdbool.h>
34*d83cc019SAndroid Build Coastguard Worker #include <drm_fourcc.h>
35*d83cc019SAndroid Build Coastguard Worker #include <xf86drmMode.h>
36*d83cc019SAndroid Build Coastguard Worker 
37*d83cc019SAndroid Build Coastguard Worker #include <i915_drm.h>
38*d83cc019SAndroid Build Coastguard Worker 
39*d83cc019SAndroid Build Coastguard Worker #include "igt_color_encoding.h"
40*d83cc019SAndroid Build Coastguard Worker #include "igt_debugfs.h"
41*d83cc019SAndroid Build Coastguard Worker 
42*d83cc019SAndroid Build Coastguard Worker #if !defined(ANDROID)
43*d83cc019SAndroid Build Coastguard Worker #define USE_AMD
44*d83cc019SAndroid Build Coastguard Worker #define USE_INTEL
45*d83cc019SAndroid Build Coastguard Worker #define USE_VC4
46*d83cc019SAndroid Build Coastguard Worker #endif
47*d83cc019SAndroid Build Coastguard Worker 
48*d83cc019SAndroid Build Coastguard Worker #ifdef __cplusplus
49*d83cc019SAndroid Build Coastguard Worker extern "C" {
50*d83cc019SAndroid Build Coastguard Worker #endif
51*d83cc019SAndroid Build Coastguard Worker 
52*d83cc019SAndroid Build Coastguard Worker /*
53*d83cc019SAndroid Build Coastguard Worker  * Internal format to denote a buffer compatible with pixman's
54*d83cc019SAndroid Build Coastguard Worker  * floating point format. Range [0-1].
55*d83cc019SAndroid Build Coastguard Worker  */
56*d83cc019SAndroid Build Coastguard Worker #define IGT_FORMAT_FLOAT fourcc_code('I', 'G', 'F', 'x')
57*d83cc019SAndroid Build Coastguard Worker 
58*d83cc019SAndroid Build Coastguard Worker #define IGT_FORMAT_FMT "%c%c%c%c(0x%08x)"
59*d83cc019SAndroid Build Coastguard Worker #define IGT_FORMAT_ARGS(f) ((f) >> 0) & 0xff, ((f) >> 8) & 0xff, \
60*d83cc019SAndroid Build Coastguard Worker 		((f) >> 16) & 0xff, ((f) >> 24) & 0xff, (f)
61*d83cc019SAndroid Build Coastguard Worker 
62*d83cc019SAndroid Build Coastguard Worker /**
63*d83cc019SAndroid Build Coastguard Worker  * igt_fb_t:
64*d83cc019SAndroid Build Coastguard Worker  * @fb_id: KMS ID of the framebuffer
65*d83cc019SAndroid Build Coastguard Worker  * @fd: DRM device fd this framebuffer is created on
66*d83cc019SAndroid Build Coastguard Worker  * @gem_handle: GEM handler of the underlying backing storage
67*d83cc019SAndroid Build Coastguard Worker  * @is_dumb: Whether this framebuffer was allocated using the dumb buffer API
68*d83cc019SAndroid Build Coastguard Worker  * @drm_format: DRM FOURCC code
69*d83cc019SAndroid Build Coastguard Worker  * @width: width in pixels
70*d83cc019SAndroid Build Coastguard Worker  * @height: height in pixels
71*d83cc019SAndroid Build Coastguard Worker  * @modifier: tiling mode as a DRM framebuffer modifier
72*d83cc019SAndroid Build Coastguard Worker  * @size: size in bytes of the underlying backing storage
73*d83cc019SAndroid Build Coastguard Worker  * @cairo_surface: optionally attached cairo drawing surface
74*d83cc019SAndroid Build Coastguard Worker  * @domain: current domain for cache flushing tracking on i915.ko
75*d83cc019SAndroid Build Coastguard Worker  * @num_planes: Amount of planes on this fb. >1 for planar formats.
76*d83cc019SAndroid Build Coastguard Worker  * @strides: line stride for each plane in bytes
77*d83cc019SAndroid Build Coastguard Worker  * @offsets: Offset for each plane in bytes.
78*d83cc019SAndroid Build Coastguard Worker  * @plane_bpp: The bpp for each plane.
79*d83cc019SAndroid Build Coastguard Worker  * @plane_width: The width for each plane.
80*d83cc019SAndroid Build Coastguard Worker  * @plane_height: The height for each plane.
81*d83cc019SAndroid Build Coastguard Worker  *
82*d83cc019SAndroid Build Coastguard Worker  * Tracking structure for KMS framebuffer objects.
83*d83cc019SAndroid Build Coastguard Worker  */
84*d83cc019SAndroid Build Coastguard Worker typedef struct igt_fb {
85*d83cc019SAndroid Build Coastguard Worker 	uint32_t fb_id;
86*d83cc019SAndroid Build Coastguard Worker 	int fd;
87*d83cc019SAndroid Build Coastguard Worker 	uint32_t gem_handle;
88*d83cc019SAndroid Build Coastguard Worker 	bool is_dumb;
89*d83cc019SAndroid Build Coastguard Worker 	uint32_t drm_format;
90*d83cc019SAndroid Build Coastguard Worker 	int width;
91*d83cc019SAndroid Build Coastguard Worker 	int height;
92*d83cc019SAndroid Build Coastguard Worker 	enum igt_color_encoding color_encoding;
93*d83cc019SAndroid Build Coastguard Worker 	enum igt_color_range color_range;
94*d83cc019SAndroid Build Coastguard Worker 	uint64_t modifier;
95*d83cc019SAndroid Build Coastguard Worker 	uint64_t size;
96*d83cc019SAndroid Build Coastguard Worker 	cairo_surface_t *cairo_surface;
97*d83cc019SAndroid Build Coastguard Worker 	unsigned int domain;
98*d83cc019SAndroid Build Coastguard Worker 	unsigned int num_planes;
99*d83cc019SAndroid Build Coastguard Worker 	uint32_t strides[4];
100*d83cc019SAndroid Build Coastguard Worker 	uint32_t offsets[4];
101*d83cc019SAndroid Build Coastguard Worker 	unsigned int plane_bpp[4];
102*d83cc019SAndroid Build Coastguard Worker 	unsigned int plane_width[4];
103*d83cc019SAndroid Build Coastguard Worker 	unsigned int plane_height[4];
104*d83cc019SAndroid Build Coastguard Worker } igt_fb_t;
105*d83cc019SAndroid Build Coastguard Worker 
106*d83cc019SAndroid Build Coastguard Worker /**
107*d83cc019SAndroid Build Coastguard Worker  * igt_text_align:
108*d83cc019SAndroid Build Coastguard Worker  * @align_left: align left
109*d83cc019SAndroid Build Coastguard Worker  * @align_right: align right
110*d83cc019SAndroid Build Coastguard Worker  * @align_bottom: align bottom
111*d83cc019SAndroid Build Coastguard Worker  * @align_top: align top
112*d83cc019SAndroid Build Coastguard Worker  * @align_vcenter: align vcenter
113*d83cc019SAndroid Build Coastguard Worker  * @align_hcenter: align hcenter
114*d83cc019SAndroid Build Coastguard Worker  *
115*d83cc019SAndroid Build Coastguard Worker  * Alignment mode for text drawing using igt_cairo_printf_line().
116*d83cc019SAndroid Build Coastguard Worker  */
117*d83cc019SAndroid Build Coastguard Worker enum igt_text_align {
118*d83cc019SAndroid Build Coastguard Worker 	align_left,
119*d83cc019SAndroid Build Coastguard Worker 	align_bottom	= align_left,
120*d83cc019SAndroid Build Coastguard Worker 	align_right	= 0x01,
121*d83cc019SAndroid Build Coastguard Worker 	align_top	= 0x02,
122*d83cc019SAndroid Build Coastguard Worker 	align_vcenter	= 0x04,
123*d83cc019SAndroid Build Coastguard Worker 	align_hcenter	= 0x08,
124*d83cc019SAndroid Build Coastguard Worker };
125*d83cc019SAndroid Build Coastguard Worker 
126*d83cc019SAndroid Build Coastguard Worker void igt_get_fb_tile_size(int fd, uint64_t modifier, int fb_bpp,
127*d83cc019SAndroid Build Coastguard Worker 			  unsigned *width_ret, unsigned *height_ret);
128*d83cc019SAndroid Build Coastguard Worker void igt_calc_fb_size(int fd, int width, int height, uint32_t format, uint64_t modifier,
129*d83cc019SAndroid Build Coastguard Worker 		      uint64_t *size_ret, unsigned *stride_ret);
130*d83cc019SAndroid Build Coastguard Worker void igt_init_fb(struct igt_fb *fb, int fd, int width, int height,
131*d83cc019SAndroid Build Coastguard Worker 		 uint32_t drm_format, uint64_t modifier,
132*d83cc019SAndroid Build Coastguard Worker 		 enum igt_color_encoding color_encoding,
133*d83cc019SAndroid Build Coastguard Worker 		 enum igt_color_range color_range);
134*d83cc019SAndroid Build Coastguard Worker unsigned int
135*d83cc019SAndroid Build Coastguard Worker igt_create_fb_with_bo_size(int fd, int width, int height,
136*d83cc019SAndroid Build Coastguard Worker 			   uint32_t format, uint64_t modifier,
137*d83cc019SAndroid Build Coastguard Worker 			   enum igt_color_encoding color_encoding,
138*d83cc019SAndroid Build Coastguard Worker 			   enum igt_color_range color_range,
139*d83cc019SAndroid Build Coastguard Worker 			   struct igt_fb *fb, uint64_t bo_size,
140*d83cc019SAndroid Build Coastguard Worker 			   unsigned bo_stride);
141*d83cc019SAndroid Build Coastguard Worker unsigned int igt_create_fb(int fd, int width, int height, uint32_t format,
142*d83cc019SAndroid Build Coastguard Worker 			   uint64_t modifier, struct igt_fb *fb);
143*d83cc019SAndroid Build Coastguard Worker unsigned int igt_create_color_fb(int fd, int width, int height,
144*d83cc019SAndroid Build Coastguard Worker 				 uint32_t format, uint64_t modifier,
145*d83cc019SAndroid Build Coastguard Worker 				 double r, double g, double b,
146*d83cc019SAndroid Build Coastguard Worker 				 struct igt_fb *fb /* out */);
147*d83cc019SAndroid Build Coastguard Worker unsigned int igt_create_pattern_fb(int fd, int width, int height,
148*d83cc019SAndroid Build Coastguard Worker 				   uint32_t format, uint64_t modifier,
149*d83cc019SAndroid Build Coastguard Worker 				   struct igt_fb *fb /* out */);
150*d83cc019SAndroid Build Coastguard Worker unsigned int igt_create_color_pattern_fb(int fd, int width, int height,
151*d83cc019SAndroid Build Coastguard Worker 					 uint32_t format, uint64_t modifier,
152*d83cc019SAndroid Build Coastguard Worker 					 double r, double g, double b,
153*d83cc019SAndroid Build Coastguard Worker 					 struct igt_fb *fb /* out */);
154*d83cc019SAndroid Build Coastguard Worker unsigned int igt_create_image_fb(int drm_fd,  int width, int height,
155*d83cc019SAndroid Build Coastguard Worker 				 uint32_t format, uint64_t modifier,
156*d83cc019SAndroid Build Coastguard Worker 				 const char *filename,
157*d83cc019SAndroid Build Coastguard Worker 				 struct igt_fb *fb /* out */);
158*d83cc019SAndroid Build Coastguard Worker unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode,
159*d83cc019SAndroid Build Coastguard Worker 				  uint32_t format, uint64_t modifier);
160*d83cc019SAndroid Build Coastguard Worker unsigned int igt_fb_convert_with_stride(struct igt_fb *dst, struct igt_fb *src,
161*d83cc019SAndroid Build Coastguard Worker 					uint32_t dst_fourcc,
162*d83cc019SAndroid Build Coastguard Worker 					uint64_t dst_modifier,
163*d83cc019SAndroid Build Coastguard Worker 					unsigned int stride);
164*d83cc019SAndroid Build Coastguard Worker unsigned int igt_fb_convert(struct igt_fb *dst, struct igt_fb *src,
165*d83cc019SAndroid Build Coastguard Worker 			    uint32_t dst_fourcc, uint64_t dst_modifier);
166*d83cc019SAndroid Build Coastguard Worker void igt_remove_fb(int fd, struct igt_fb *fb);
167*d83cc019SAndroid Build Coastguard Worker int igt_dirty_fb(int fd, struct igt_fb *fb);
168*d83cc019SAndroid Build Coastguard Worker void *igt_fb_map_buffer(int fd, struct igt_fb *fb);
169*d83cc019SAndroid Build Coastguard Worker void igt_fb_unmap_buffer(struct igt_fb *fb, void *buffer);
170*d83cc019SAndroid Build Coastguard Worker 
171*d83cc019SAndroid Build Coastguard Worker void igt_create_bo_for_fb(int fd, int width, int height,
172*d83cc019SAndroid Build Coastguard Worker 			  uint32_t format, uint64_t modifier,
173*d83cc019SAndroid Build Coastguard Worker 			  struct igt_fb *fb);
174*d83cc019SAndroid Build Coastguard Worker int igt_create_bo_with_dimensions(int fd, int width, int height, uint32_t format,
175*d83cc019SAndroid Build Coastguard Worker 				  uint64_t modifier, unsigned stride,
176*d83cc019SAndroid Build Coastguard Worker 				  uint64_t *size_ret, unsigned *stride_ret,
177*d83cc019SAndroid Build Coastguard Worker 				  bool *is_dumb);
178*d83cc019SAndroid Build Coastguard Worker void igt_fb_calc_crc(struct igt_fb *fb, igt_crc_t *crc);
179*d83cc019SAndroid Build Coastguard Worker 
180*d83cc019SAndroid Build Coastguard Worker uint64_t igt_fb_mod_to_tiling(uint64_t modifier);
181*d83cc019SAndroid Build Coastguard Worker uint64_t igt_fb_tiling_to_mod(uint64_t tiling);
182*d83cc019SAndroid Build Coastguard Worker 
183*d83cc019SAndroid Build Coastguard Worker /* cairo-based painting */
184*d83cc019SAndroid Build Coastguard Worker cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb);
185*d83cc019SAndroid Build Coastguard Worker cairo_surface_t *igt_cairo_image_surface_create_from_png(const char *filename);
186*d83cc019SAndroid Build Coastguard Worker cairo_t *igt_get_cairo_ctx(int fd, struct igt_fb *fb);
187*d83cc019SAndroid Build Coastguard Worker void igt_put_cairo_ctx(int fd, struct igt_fb *fb, cairo_t *cr);
188*d83cc019SAndroid Build Coastguard Worker void igt_paint_color(cairo_t *cr, int x, int y, int w, int h,
189*d83cc019SAndroid Build Coastguard Worker 			 double r, double g, double b);
190*d83cc019SAndroid Build Coastguard Worker void igt_paint_color_alpha(cairo_t *cr, int x, int y, int w, int h,
191*d83cc019SAndroid Build Coastguard Worker 			       double r, double g, double b, double a);
192*d83cc019SAndroid Build Coastguard Worker void igt_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
193*d83cc019SAndroid Build Coastguard Worker 				  int r, int g, int b);
194*d83cc019SAndroid Build Coastguard Worker void igt_paint_color_gradient_range(cairo_t *cr, int x, int y, int w, int h,
195*d83cc019SAndroid Build Coastguard Worker 				    double sr, double sg, double sb,
196*d83cc019SAndroid Build Coastguard Worker 				    double er, double eg, double eb);
197*d83cc019SAndroid Build Coastguard Worker void igt_paint_test_pattern(cairo_t *cr, int width, int height);
198*d83cc019SAndroid Build Coastguard Worker void igt_paint_image(cairo_t *cr, const char *filename,
199*d83cc019SAndroid Build Coastguard Worker 			 int dst_x, int dst_y, int dst_width, int dst_height);
200*d83cc019SAndroid Build Coastguard Worker int igt_cairo_printf_line(cairo_t *cr, enum igt_text_align align,
201*d83cc019SAndroid Build Coastguard Worker 			       double yspacing, const char *fmt, ...)
202*d83cc019SAndroid Build Coastguard Worker 			       __attribute__((format (printf, 4, 5)));
203*d83cc019SAndroid Build Coastguard Worker 
204*d83cc019SAndroid Build Coastguard Worker /* helpers to handle drm fourcc codes */
205*d83cc019SAndroid Build Coastguard Worker uint32_t igt_bpp_depth_to_drm_format(int bpp, int depth);
206*d83cc019SAndroid Build Coastguard Worker uint32_t igt_drm_format_to_bpp(uint32_t drm_format);
207*d83cc019SAndroid Build Coastguard Worker const char *igt_format_str(uint32_t drm_format);
208*d83cc019SAndroid Build Coastguard Worker bool igt_fb_supported_format(uint32_t drm_format);
209*d83cc019SAndroid Build Coastguard Worker bool igt_format_is_yuv(uint32_t drm_format);
210*d83cc019SAndroid Build Coastguard Worker bool igt_format_is_fp16(uint32_t drm_format);
211*d83cc019SAndroid Build Coastguard Worker int igt_format_plane_bpp(uint32_t drm_format, int plane);
212*d83cc019SAndroid Build Coastguard Worker void igt_format_array_fill(uint32_t **formats_array, unsigned int *count,
213*d83cc019SAndroid Build Coastguard Worker 			   bool allow_yuv);
214*d83cc019SAndroid Build Coastguard Worker 
215*d83cc019SAndroid Build Coastguard Worker #ifdef __cplusplus
216*d83cc019SAndroid Build Coastguard Worker }
217*d83cc019SAndroid Build Coastguard Worker #endif
218*d83cc019SAndroid Build Coastguard Worker 
219*d83cc019SAndroid Build Coastguard Worker #endif /* __IGT_FB_H__ */
220*d83cc019SAndroid Build Coastguard Worker 
221