blob: 3f549036abc52ab062866dbdef8bba1d49bf4ba7 [file] [log] [blame]
Daniel Vetter57d7db82014-03-26 09:06:11 +01001/*
2 * Copyright © 2013,2014 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 * Authors:
24 * Daniel Vetter <daniel.vetter@ffwll.ch>
25 * Damien Lespiau <damien.lespiau@intel.com>
26 */
27
28#ifndef __IGT_FB_H__
29#define __IGT_FB_H__
30
Tim Gore41cbe362014-05-12 13:39:00 +010031/* cairo is assumed available on linux. On Android we check for ANDROID_HAS_CAIRO */
32#if (!defined(ANDROID)) || (defined(ANDROID) && ANDROID_HAS_CAIRO)
Daniel Vetter57d7db82014-03-26 09:06:11 +010033#include <cairo.h>
tgore22bc1a22014-03-31 11:55:40 +010034#else
35typedef struct _cairo_surface cairo_surface_t;
36typedef struct _cairo cairo_t;
37#endif
Daniel Vetter57d7db82014-03-26 09:06:11 +010038
Thomas Woodd96490a2014-06-16 16:21:35 +010039#include <stddef.h>
40#include <stdbool.h>
Daniel Vetter57d7db82014-03-26 09:06:11 +010041#include <drm_fourcc.h>
42#include <xf86drmMode.h>
43
Damien Lespiau378e61e2014-06-23 14:53:24 +010044#include <i915_drm.h>
45
Daniel Vetter45cbdbc2016-07-27 13:54:06 +020046/**
47 * igt_fb_t:
48 * @fb_id: KMS ID of the framebuffer
49 * @fd: DRM device fd this framebuffer is created on
50 * @gem_handle: GEM handler of the underlying backing storage
51 * @is_dumb: Whether this framebuffer was allocated using the dumb buffer API
52 * @drm_format: DRM FOURCC code
53 * @width: width in pixels
54 * @height: height in pixels
55 * @stride: line stride in bytes
56 * @tiling: tiling mode as a DRM framebuffer modifier
57 * @size: size in bytes of the underlying backing storage
58 * @cairo_surface: optionally attached cairo drawing surface
59 * @domain: current domain for cache flushing tracking on i915.ko
60 *
61 * Tracking structure for KMS framebuffer objects.
62 */
63typedef struct igt_fb {
Daniel Vetter57d7db82014-03-26 09:06:11 +010064 uint32_t fb_id;
Tomeu Vizoso89b3ffe2016-02-24 09:04:41 +010065 int fd;
Daniel Vetter57d7db82014-03-26 09:06:11 +010066 uint32_t gem_handle;
Tomeu Vizoso8a1a3862016-02-24 09:04:04 +010067 bool is_dumb;
Daniel Vetter57d7db82014-03-26 09:06:11 +010068 uint32_t drm_format;
69 int width;
70 int height;
Daniel Vetter45cbdbc2016-07-27 13:54:06 +020071 unsigned int stride;
Tvrtko Ursuline36091d2015-03-03 14:11:01 +000072 uint64_t tiling;
Daniel Vetter45cbdbc2016-07-27 13:54:06 +020073 unsigned int size;
Daniel Vetter57d7db82014-03-26 09:06:11 +010074 cairo_surface_t *cairo_surface;
Daniel Vetter45cbdbc2016-07-27 13:54:06 +020075 unsigned int domain;
76} igt_fb_t;
Daniel Vetter57d7db82014-03-26 09:06:11 +010077
Daniel Vetter45cbdbc2016-07-27 13:54:06 +020078/**
79 * igt_text_align:
80 * @align_left: align left
81 * @align_right: align right
82 * @align_bottom: align bottom
83 * @align_top: align top
84 * @align_vcenter: align vcenter
85 * @align_hcenter: align hcenter
86 *
87 * Alignment mode for text drawing using igt_cairo_printf_line().
88 */
Daniel Vetter9aea7ae2014-03-26 09:18:11 +010089enum igt_text_align {
Daniel Vetter57d7db82014-03-26 09:06:11 +010090 align_left,
91 align_bottom = align_left,
92 align_right = 0x01,
93 align_top = 0x02,
94 align_vcenter = 0x04,
95 align_hcenter = 0x08,
96};
97
Praveen Paneri4bb45412017-07-18 22:52:56 +053098void igt_get_fb_tile_size(int fd, uint64_t tiling, int fb_bpp,
99 unsigned *width_ret, unsigned *height_ret);
Paulo Zanonibe6f3fa2015-11-27 12:13:41 -0200100void igt_calc_fb_size(int fd, int width, int height, int bpp, uint64_t tiling,
101 unsigned *size_ret, unsigned *stride_ret);
Damien Lespiau378e61e2014-06-23 14:53:24 +0100102unsigned int
103igt_create_fb_with_bo_size(int fd, int width, int height,
Tvrtko Ursuline36091d2015-03-03 14:11:01 +0000104 uint32_t format, uint64_t tiling,
Paulo Zanonid6341372015-11-05 16:39:00 -0200105 struct igt_fb *fb, unsigned bo_size,
106 unsigned bo_stride);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100107unsigned int igt_create_fb(int fd, int width, int height, uint32_t format,
Tvrtko Ursuline36091d2015-03-03 14:11:01 +0000108 uint64_t tiling, struct igt_fb *fb);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100109unsigned int igt_create_color_fb(int fd, int width, int height,
Tvrtko Ursuline36091d2015-03-03 14:11:01 +0000110 uint32_t format, uint64_t tiling,
Damien Lespiau378e61e2014-06-23 14:53:24 +0100111 double r, double g, double b,
112 struct igt_fb *fb /* out */);
Ville Syrjälä5b113d32015-12-17 01:39:31 +0200113unsigned int igt_create_pattern_fb(int fd, int width, int height,
114 uint32_t format, uint64_t tiling,
115 struct igt_fb *fb /* out */);
116unsigned int igt_create_color_pattern_fb(int fd, int width, int height,
117 uint32_t format, uint64_t tiling,
118 double r, double g, double b,
119 struct igt_fb *fb /* out */);
120unsigned int igt_create_image_fb(int drm_fd, int width, int height,
121 uint32_t format, uint64_t tiling,
122 const char *filename,
123 struct igt_fb *fb /* out */);
Thomas Wood4cb19462014-08-04 16:14:51 +0100124unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode,
Tvrtko Ursuline36091d2015-03-03 14:11:01 +0000125 uint32_t format, uint64_t tiling);
Daniel Vetter3d9e63f2014-03-26 16:37:15 +0100126void igt_remove_fb(int fd, struct igt_fb *fb);
Tomeu Vizosoa2d5b342016-03-07 16:25:43 +0100127int igt_dirty_fb(int fd, struct igt_fb *fb);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100128
Tomeu Vizoso8a1a3862016-02-24 09:04:04 +0100129int igt_create_bo_with_dimensions(int fd, int width, int height, uint32_t format,
130 uint64_t modifier, unsigned stride,
Daniel Vetter45cbdbc2016-07-27 13:54:06 +0200131 unsigned *stride_ret, unsigned *size_ret,
Tomeu Vizoso8a1a3862016-02-24 09:04:04 +0100132 bool *is_dumb);
133
Tomeu Vizosoae649632016-11-10 10:25:24 +0100134uint64_t igt_fb_mod_to_tiling(uint64_t modifier);
Praveen Paneri4437e212017-07-18 22:52:57 +0530135uint64_t igt_fb_tiling_to_mod(uint64_t tiling);
Tomeu Vizosoae649632016-11-10 10:25:24 +0100136
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100137/* cairo-based painting */
Paul Kocialkowskib4ad3972017-07-19 16:46:04 +0300138cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb);
Ville Syrjälä75f320c2017-09-21 15:39:23 +0300139cairo_surface_t *igt_cairo_image_surface_create_from_png(const char *filename);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100140cairo_t *igt_get_cairo_ctx(int fd, struct igt_fb *fb);
141void igt_paint_color(cairo_t *cr, int x, int y, int w, int h,
Daniel Vetter57d7db82014-03-26 09:06:11 +0100142 double r, double g, double b);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100143void igt_paint_color_alpha(cairo_t *cr, int x, int y, int w, int h,
Daniel Vetter57d7db82014-03-26 09:06:11 +0100144 double r, double g, double b, double a);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100145void igt_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
Daniel Vetter57d7db82014-03-26 09:06:11 +0100146 int r, int g, int b);
Lionel Landwerlina5113102016-03-18 17:33:02 +0000147void igt_paint_color_gradient_range(cairo_t *cr, int x, int y, int w, int h,
148 double sr, double sg, double sb,
149 double er, double eg, double eb);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100150void igt_paint_test_pattern(cairo_t *cr, int width, int height);
151void igt_paint_image(cairo_t *cr, const char *filename,
Daniel Vetter57d7db82014-03-26 09:06:11 +0100152 int dst_x, int dst_y, int dst_width, int dst_height);
Daniel Vetter3d9e63f2014-03-26 16:37:15 +0100153int igt_cairo_printf_line(cairo_t *cr, enum igt_text_align align,
154 double yspacing, const char *fmt, ...)
155 __attribute__((format (printf, 4, 5)));
Daniel Vetter57d7db82014-03-26 09:06:11 +0100156
157/* helpers to handle drm fourcc codes */
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100158uint32_t igt_bpp_depth_to_drm_format(int bpp, int depth);
159uint32_t igt_drm_format_to_bpp(uint32_t drm_format);
160const char *igt_format_str(uint32_t drm_format);
Paulo Zanoni7ca55f42016-01-26 10:52:29 -0200161void igt_get_all_cairo_formats(const uint32_t **formats, int *format_count);
Daniel Vetter57d7db82014-03-26 09:06:11 +0100162
163#endif /* __IGT_FB_H__ */
164