lib/display: Add support for the cursor plane
[platform/upstream/intel-gpu-tools.git] / lib / igt_kms.h
1 /*
2  * Copyright © 2013 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  */
24
25 #ifndef __IGT_KMS_H__
26 #define __IGT_KMS_H__
27
28 #include <stdbool.h>
29
30 #include <cairo.h>
31
32 #include <igt_display.h>
33
34 struct kmstest_connector_config {
35         drmModeCrtc *crtc;
36         drmModeConnector *connector;
37         drmModeEncoder *encoder;
38         drmModeModeInfo default_mode;
39         int crtc_idx;
40         int pipe;
41 };
42
43 int kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,
44                                       drmModeModeInfo *mode);
45 int kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
46                                  unsigned long crtc_idx_mask,
47                                  struct kmstest_connector_config *config);
48 void kmstest_free_connector_config(struct kmstest_connector_config *config);
49
50 /* helpers to create nice-looking framebuffers */
51 struct kmstest_fb {
52         uint32_t fb_id;
53         uint32_t gem_handle;
54         uint32_t drm_format;
55         int width;
56         int height;
57         int depth;
58         unsigned stride;
59         unsigned tiling;
60         unsigned size;
61         cairo_surface_t *cairo_surface;
62 };
63
64 enum kmstest_text_align {
65         align_left,
66         align_bottom    = align_left,
67         align_right     = 0x01,
68         align_top       = 0x02,
69         align_vcenter   = 0x04,
70         align_hcenter   = 0x08,
71 };
72
73 int kmstest_cairo_printf_line(cairo_t *cr, enum kmstest_text_align align,
74                                double yspacing, const char *fmt, ...)
75                                __attribute__((format (printf, 4, 5)));
76
77 unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
78                                int depth, bool tiled,
79                                struct kmstest_fb *fb_info);
80 unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format,
81                                 bool tiled, struct kmstest_fb *fb);
82 void kmstest_remove_fb(int fd, struct kmstest_fb *fb_info);
83 cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb);
84 cairo_surface_t *kmstest_get_cairo_surface(int fd, struct kmstest_fb *fb);
85 void kmstest_paint_color(cairo_t *cr, int x, int y, int w, int h,
86                          double r, double g, double b);
87 void kmstest_paint_color_alpha(cairo_t *cr, int x, int y, int w, int h,
88                                double r, double g, double b, double a);
89 void kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
90                                   int r, int g, int b);
91 void kmstest_paint_test_pattern(cairo_t *cr, int width, int height);
92 void kmstest_paint_image(cairo_t *cr, const char *filename,
93                          int dst_x, int dst_y, int dst_width, int dst_height);
94 void kmstest_write_fb(int fd, struct kmstest_fb *fb, const char *filename);
95 void kmstest_dump_mode(drmModeModeInfo *mode);
96 int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
97 const char *kmstest_format_str(uint32_t drm_format);
98 const char *kmstest_pipe_str(int pipe);
99 void kmstest_get_all_formats(const uint32_t **formats, int *format_count);
100 const char *kmstest_encoder_type_str(int type);
101 const char *kmstest_connector_status_str(int type);
102 const char *kmstest_connector_type_str(int type);
103
104 uint32_t drm_format_to_bpp(uint32_t drm_format);
105
106 /*
107  * A small modeset API
108  */
109
110 typedef struct igt_display igt_display_t;
111 typedef struct igt_pipe igt_pipe_t;
112 typedef uint32_t igt_fixed_t;                   /* 16.16 fixed point */
113
114 typedef struct {
115         igt_pipe_t *pipe;
116         int index;
117         unsigned int is_primary       : 1;
118         unsigned int is_cursor        : 1;
119         unsigned int position_changed : 1;
120         struct kmstest_fb *fb;
121         /* position within pipe_src_w x pipe_src_h */
122         int crtc_x, crtc_y;
123 } igt_plane_t;
124
125 struct igt_pipe {
126         igt_display_t *display;
127         enum pipe pipe;
128         unsigned int need_set_crtc   : 1;
129         unsigned int need_set_cursor : 1;
130 #define IGT_MAX_PLANES  4
131         int n_planes;
132         igt_plane_t planes[IGT_MAX_PLANES];
133 };
134
135 typedef struct {
136         igt_display_t *display;
137         uint32_t id;                                    /* KMS id */
138         struct kmstest_connector_config config;
139         char *name;
140         bool valid;
141         unsigned long pending_crtc_idx_mask;
142 } igt_output_t;
143
144 struct igt_display {
145         int drm_fd;
146         unsigned int verbose : 1;
147         int log_shift;
148         int n_pipes;
149         int n_outputs;
150         unsigned long pipes_in_use;
151         igt_output_t *outputs;
152         igt_pipe_t pipes[I915_MAX_PIPES];
153 };
154
155 void igt_display_init(igt_display_t *display, int drm_fd);
156 void igt_display_fini(igt_display_t *display);
157 int  igt_display_commit(igt_display_t *display);
158 void igt_display_set_verbose(igt_display_t *display, bool verbose);
159 int  igt_display_get_n_pipes(igt_display_t *display);
160
161 const char *igt_output_name(igt_output_t *output);
162 drmModeModeInfo *igt_output_get_mode(igt_output_t *output);
163 void igt_output_set_pipe(igt_output_t *output, enum pipe pipe);
164 igt_plane_t *igt_ouput_get_plane(igt_output_t *output, enum igt_plane plane);
165
166 void igt_plane_set_fb(igt_plane_t *plane, struct kmstest_fb *fb);
167 void igt_plane_set_position(igt_plane_t *plane, int x, int y);
168
169 #define for_each_connected_output(display, output)              \
170         for (int i__ = 0;  i__ < (display)->n_outputs; i__++)   \
171                 if ((output = &(display)->outputs[i__]), output->valid)
172
173 #define IGT_FIXED(i,f)  ((i) << 16 | (f))
174
175 #endif /* __IGT_KMS_H__ */
176