Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 1 | /* |
| 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 Gore | 41cbe36 | 2014-05-12 13:39:00 +0100 | [diff] [blame] | 31 | /* cairo is assumed available on linux. On Android we check for ANDROID_HAS_CAIRO */ |
| 32 | #if (!defined(ANDROID)) || (defined(ANDROID) && ANDROID_HAS_CAIRO) |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 33 | #include <cairo.h> |
tgore | 22bc1a2 | 2014-03-31 11:55:40 +0100 | [diff] [blame] | 34 | #else |
| 35 | typedef struct _cairo_surface cairo_surface_t; |
| 36 | typedef struct _cairo cairo_t; |
| 37 | #endif |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 38 | |
Thomas Wood | d96490a | 2014-06-16 16:21:35 +0100 | [diff] [blame] | 39 | #include <stddef.h> |
| 40 | #include <stdbool.h> |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 41 | #include <drm_fourcc.h> |
| 42 | #include <xf86drmMode.h> |
| 43 | |
Damien Lespiau | 378e61e | 2014-06-23 14:53:24 +0100 | [diff] [blame] | 44 | #include <i915_drm.h> |
| 45 | |
Daniel Vetter | 45cbdbc | 2016-07-27 13:54:06 +0200 | [diff] [blame] | 46 | /** |
| 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 | */ |
| 63 | typedef struct igt_fb { |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 64 | uint32_t fb_id; |
Tomeu Vizoso | 89b3ffe | 2016-02-24 09:04:41 +0100 | [diff] [blame] | 65 | int fd; |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 66 | uint32_t gem_handle; |
Tomeu Vizoso | 8a1a386 | 2016-02-24 09:04:04 +0100 | [diff] [blame] | 67 | bool is_dumb; |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 68 | uint32_t drm_format; |
| 69 | int width; |
| 70 | int height; |
Daniel Vetter | 45cbdbc | 2016-07-27 13:54:06 +0200 | [diff] [blame] | 71 | unsigned int stride; |
Tvrtko Ursulin | e36091d | 2015-03-03 14:11:01 +0000 | [diff] [blame] | 72 | uint64_t tiling; |
Daniel Vetter | 45cbdbc | 2016-07-27 13:54:06 +0200 | [diff] [blame] | 73 | unsigned int size; |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 74 | cairo_surface_t *cairo_surface; |
Daniel Vetter | 45cbdbc | 2016-07-27 13:54:06 +0200 | [diff] [blame] | 75 | unsigned int domain; |
| 76 | } igt_fb_t; |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 77 | |
Daniel Vetter | 45cbdbc | 2016-07-27 13:54:06 +0200 | [diff] [blame] | 78 | /** |
| 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 Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 89 | enum igt_text_align { |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 90 | 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 Paneri | 4bb4541 | 2017-07-18 22:52:56 +0530 | [diff] [blame] | 98 | void igt_get_fb_tile_size(int fd, uint64_t tiling, int fb_bpp, |
| 99 | unsigned *width_ret, unsigned *height_ret); |
Paulo Zanoni | be6f3fa | 2015-11-27 12:13:41 -0200 | [diff] [blame] | 100 | void igt_calc_fb_size(int fd, int width, int height, int bpp, uint64_t tiling, |
| 101 | unsigned *size_ret, unsigned *stride_ret); |
Damien Lespiau | 378e61e | 2014-06-23 14:53:24 +0100 | [diff] [blame] | 102 | unsigned int |
| 103 | igt_create_fb_with_bo_size(int fd, int width, int height, |
Tvrtko Ursulin | e36091d | 2015-03-03 14:11:01 +0000 | [diff] [blame] | 104 | uint32_t format, uint64_t tiling, |
Paulo Zanoni | d634137 | 2015-11-05 16:39:00 -0200 | [diff] [blame] | 105 | struct igt_fb *fb, unsigned bo_size, |
| 106 | unsigned bo_stride); |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 107 | unsigned int igt_create_fb(int fd, int width, int height, uint32_t format, |
Tvrtko Ursulin | e36091d | 2015-03-03 14:11:01 +0000 | [diff] [blame] | 108 | uint64_t tiling, struct igt_fb *fb); |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 109 | unsigned int igt_create_color_fb(int fd, int width, int height, |
Tvrtko Ursulin | e36091d | 2015-03-03 14:11:01 +0000 | [diff] [blame] | 110 | uint32_t format, uint64_t tiling, |
Damien Lespiau | 378e61e | 2014-06-23 14:53:24 +0100 | [diff] [blame] | 111 | double r, double g, double b, |
| 112 | struct igt_fb *fb /* out */); |
Ville Syrjälä | 5b113d3 | 2015-12-17 01:39:31 +0200 | [diff] [blame] | 113 | unsigned int igt_create_pattern_fb(int fd, int width, int height, |
| 114 | uint32_t format, uint64_t tiling, |
| 115 | struct igt_fb *fb /* out */); |
| 116 | unsigned 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 */); |
| 120 | unsigned 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 Wood | 4cb1946 | 2014-08-04 16:14:51 +0100 | [diff] [blame] | 124 | unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode, |
Tvrtko Ursulin | e36091d | 2015-03-03 14:11:01 +0000 | [diff] [blame] | 125 | uint32_t format, uint64_t tiling); |
Daniel Vetter | 3d9e63f | 2014-03-26 16:37:15 +0100 | [diff] [blame] | 126 | void igt_remove_fb(int fd, struct igt_fb *fb); |
Tomeu Vizoso | a2d5b34 | 2016-03-07 16:25:43 +0100 | [diff] [blame] | 127 | int igt_dirty_fb(int fd, struct igt_fb *fb); |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 128 | |
Tomeu Vizoso | 8a1a386 | 2016-02-24 09:04:04 +0100 | [diff] [blame] | 129 | int igt_create_bo_with_dimensions(int fd, int width, int height, uint32_t format, |
| 130 | uint64_t modifier, unsigned stride, |
Daniel Vetter | 45cbdbc | 2016-07-27 13:54:06 +0200 | [diff] [blame] | 131 | unsigned *stride_ret, unsigned *size_ret, |
Tomeu Vizoso | 8a1a386 | 2016-02-24 09:04:04 +0100 | [diff] [blame] | 132 | bool *is_dumb); |
| 133 | |
Tomeu Vizoso | ae64963 | 2016-11-10 10:25:24 +0100 | [diff] [blame] | 134 | uint64_t igt_fb_mod_to_tiling(uint64_t modifier); |
Praveen Paneri | 4437e21 | 2017-07-18 22:52:57 +0530 | [diff] [blame^] | 135 | uint64_t igt_fb_tiling_to_mod(uint64_t tiling); |
Tomeu Vizoso | ae64963 | 2016-11-10 10:25:24 +0100 | [diff] [blame] | 136 | |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 137 | /* cairo-based painting */ |
Paul Kocialkowski | b4ad397 | 2017-07-19 16:46:04 +0300 | [diff] [blame] | 138 | cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb); |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 139 | cairo_t *igt_get_cairo_ctx(int fd, struct igt_fb *fb); |
| 140 | void igt_paint_color(cairo_t *cr, int x, int y, int w, int h, |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 141 | double r, double g, double b); |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 142 | void igt_paint_color_alpha(cairo_t *cr, int x, int y, int w, int h, |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 143 | double r, double g, double b, double a); |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 144 | void igt_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h, |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 145 | int r, int g, int b); |
Lionel Landwerlin | a511310 | 2016-03-18 17:33:02 +0000 | [diff] [blame] | 146 | void igt_paint_color_gradient_range(cairo_t *cr, int x, int y, int w, int h, |
| 147 | double sr, double sg, double sb, |
| 148 | double er, double eg, double eb); |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 149 | void igt_paint_test_pattern(cairo_t *cr, int width, int height); |
| 150 | void igt_paint_image(cairo_t *cr, const char *filename, |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 151 | int dst_x, int dst_y, int dst_width, int dst_height); |
Daniel Vetter | 3d9e63f | 2014-03-26 16:37:15 +0100 | [diff] [blame] | 152 | int igt_cairo_printf_line(cairo_t *cr, enum igt_text_align align, |
| 153 | double yspacing, const char *fmt, ...) |
| 154 | __attribute__((format (printf, 4, 5))); |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 155 | |
| 156 | /* helpers to handle drm fourcc codes */ |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 157 | uint32_t igt_bpp_depth_to_drm_format(int bpp, int depth); |
| 158 | uint32_t igt_drm_format_to_bpp(uint32_t drm_format); |
| 159 | const char *igt_format_str(uint32_t drm_format); |
Paulo Zanoni | 7ca55f4 | 2016-01-26 10:52:29 -0200 | [diff] [blame] | 160 | void igt_get_all_cairo_formats(const uint32_t **formats, int *format_count); |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 161 | |
| 162 | #endif /* __IGT_FB_H__ */ |
| 163 | |