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