Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * Copyright © 2013 Vasily Khoruzhick <anarsoul@gmail.com> |
Pekka Paalanen | 6764bbe | 2015-02-11 12:29:56 +0200 | [diff] [blame] | 4 | * Copyright © 2015 Collabora, Ltd. |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 5 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining |
| 7 | * a copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 13 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial |
| 16 | * portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 22 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 23 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 | * SOFTWARE. |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 26 | */ |
| 27 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 28 | #include "config.h" |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 29 | |
| 30 | #include <errno.h> |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 31 | #include <stdint.h> |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 32 | #include <stdlib.h> |
Pekka Paalanen | f75b6bb | 2015-03-04 16:12:04 +0200 | [diff] [blame] | 33 | #include <assert.h> |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 34 | |
| 35 | #include "pixman-renderer.h" |
Jon Cruz | 867d50e | 2015-06-15 15:37:10 -0700 | [diff] [blame] | 36 | #include "shared/helpers.h" |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 37 | |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 38 | #include <linux/input.h> |
| 39 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 40 | struct pixman_output_state { |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 41 | void *shadow_buffer; |
| 42 | pixman_image_t *shadow_image; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 43 | pixman_image_t *hw_buffer; |
Pekka Paalanen | acf50c3 | 2018-04-23 11:44:56 +0200 | [diff] [blame] | 44 | pixman_region32_t *hw_extra_damage; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | struct pixman_surface_state { |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 48 | struct weston_surface *surface; |
| 49 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 50 | pixman_image_t *image; |
| 51 | struct weston_buffer_reference buffer_ref; |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 52 | struct weston_buffer_release_reference buffer_release_ref; |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 53 | |
Lubomir Rintel | ddc2b1e | 2013-12-12 12:57:56 +0100 | [diff] [blame] | 54 | struct wl_listener buffer_destroy_listener; |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 55 | struct wl_listener surface_destroy_listener; |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 56 | struct wl_listener renderer_destroy_listener; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | struct pixman_renderer { |
| 60 | struct weston_renderer base; |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 61 | |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 62 | int repaint_debug; |
| 63 | pixman_image_t *debug_color; |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 64 | struct weston_binding *debug_binding; |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 65 | |
| 66 | struct wl_signal destroy_signal; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static inline struct pixman_output_state * |
| 70 | get_output_state(struct weston_output *output) |
| 71 | { |
| 72 | return (struct pixman_output_state *)output->renderer_state; |
| 73 | } |
| 74 | |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 75 | static int |
| 76 | pixman_renderer_create_surface(struct weston_surface *surface); |
| 77 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 78 | static inline struct pixman_surface_state * |
| 79 | get_surface_state(struct weston_surface *surface) |
| 80 | { |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 81 | if (!surface->renderer_state) |
| 82 | pixman_renderer_create_surface(surface); |
| 83 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 84 | return (struct pixman_surface_state *)surface->renderer_state; |
| 85 | } |
| 86 | |
| 87 | static inline struct pixman_renderer * |
| 88 | get_renderer(struct weston_compositor *ec) |
| 89 | { |
| 90 | return (struct pixman_renderer *)ec->renderer; |
| 91 | } |
| 92 | |
| 93 | static int |
| 94 | pixman_renderer_read_pixels(struct weston_output *output, |
| 95 | pixman_format_code_t format, void *pixels, |
| 96 | uint32_t x, uint32_t y, |
| 97 | uint32_t width, uint32_t height) |
| 98 | { |
| 99 | struct pixman_output_state *po = get_output_state(output); |
| 100 | pixman_image_t *out_buf; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 101 | |
| 102 | if (!po->hw_buffer) { |
| 103 | errno = ENODEV; |
| 104 | return -1; |
| 105 | } |
| 106 | |
| 107 | out_buf = pixman_image_create_bits(format, |
| 108 | width, |
| 109 | height, |
| 110 | pixels, |
| 111 | (PIXMAN_FORMAT_BPP(format) / 8) * width); |
| 112 | |
Alexander Larsson | 97af792 | 2013-05-29 12:01:33 +0200 | [diff] [blame] | 113 | pixman_image_composite32(PIXMAN_OP_SRC, |
| 114 | po->hw_buffer, /* src */ |
| 115 | NULL /* mask */, |
| 116 | out_buf, /* dest */ |
Stefan Agner | da2e574 | 2019-06-16 23:28:15 +0200 | [diff] [blame] | 117 | x, y, /* src_x, src_y */ |
Alexander Larsson | 97af792 | 2013-05-29 12:01:33 +0200 | [diff] [blame] | 118 | 0, 0, /* mask_x, mask_y */ |
| 119 | 0, 0, /* dest_x, dest_y */ |
| 120 | pixman_image_get_width (po->hw_buffer), /* width */ |
| 121 | pixman_image_get_height (po->hw_buffer) /* height */); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 122 | |
| 123 | pixman_image_unref(out_buf); |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
Vasily Khoruzhick | 031fc87 | 2013-01-29 14:58:14 +0300 | [diff] [blame] | 128 | static void |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 129 | region_global_to_output(struct weston_output *output, pixman_region32_t *region) |
| 130 | { |
Jason Ekstrand | 52c476a | 2015-11-18 16:32:29 -0600 | [diff] [blame] | 131 | if (output->zoom.active) { |
| 132 | weston_matrix_transform_region(region, &output->matrix, region); |
| 133 | } else { |
| 134 | pixman_region32_translate(region, -output->x, -output->y); |
| 135 | weston_transformed_region(output->width, output->height, |
| 136 | output->transform, |
| 137 | output->current_scale, |
| 138 | region, region); |
| 139 | } |
Vasily Khoruzhick | 031fc87 | 2013-01-29 14:58:14 +0300 | [diff] [blame] | 140 | } |
| 141 | |
Vasily Khoruzhick | f4a457f | 2013-01-28 22:40:29 +0300 | [diff] [blame] | 142 | #define D2F(v) pixman_double_to_fixed((double)v) |
| 143 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 144 | static void |
Jason Ekstrand | 8870a23 | 2014-05-20 15:53:19 -0500 | [diff] [blame] | 145 | weston_matrix_to_pixman_transform(pixman_transform_t *pt, |
| 146 | const struct weston_matrix *wm) |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 147 | { |
Jason Ekstrand | 8870a23 | 2014-05-20 15:53:19 -0500 | [diff] [blame] | 148 | /* Pixman supports only 2D transform matrix, but Weston uses 3D, * |
| 149 | * so we're omitting Z coordinate here. */ |
| 150 | pt->matrix[0][0] = pixman_double_to_fixed(wm->d[0]); |
| 151 | pt->matrix[0][1] = pixman_double_to_fixed(wm->d[4]); |
| 152 | pt->matrix[0][2] = pixman_double_to_fixed(wm->d[12]); |
| 153 | pt->matrix[1][0] = pixman_double_to_fixed(wm->d[1]); |
| 154 | pt->matrix[1][1] = pixman_double_to_fixed(wm->d[5]); |
| 155 | pt->matrix[1][2] = pixman_double_to_fixed(wm->d[13]); |
| 156 | pt->matrix[2][0] = pixman_double_to_fixed(wm->d[3]); |
| 157 | pt->matrix[2][1] = pixman_double_to_fixed(wm->d[7]); |
| 158 | pt->matrix[2][2] = pixman_double_to_fixed(wm->d[15]); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static void |
Pekka Paalanen | 6ea523b | 2015-03-04 14:18:39 +0200 | [diff] [blame] | 162 | pixman_renderer_compute_transform(pixman_transform_t *transform_out, |
| 163 | struct weston_view *ev, |
| 164 | struct weston_output *output) |
| 165 | { |
| 166 | struct weston_matrix matrix; |
| 167 | |
| 168 | /* Set up the source transformation based on the surface |
| 169 | position, the output position/transform/scale and the client |
| 170 | specified buffer transform/scale */ |
Derek Foreman | a5855ad | 2015-03-24 11:36:16 -0500 | [diff] [blame] | 171 | matrix = output->inverse_matrix; |
Pekka Paalanen | 6ea523b | 2015-03-04 14:18:39 +0200 | [diff] [blame] | 172 | |
| 173 | if (ev->transform.enabled) { |
| 174 | weston_matrix_multiply(&matrix, &ev->transform.inverse); |
| 175 | } else { |
| 176 | weston_matrix_translate(&matrix, |
| 177 | -ev->geometry.x, -ev->geometry.y, 0); |
| 178 | } |
| 179 | |
| 180 | weston_matrix_multiply(&matrix, &ev->surface->surface_to_buffer_matrix); |
| 181 | |
| 182 | weston_matrix_to_pixman_transform(transform_out, &matrix); |
| 183 | } |
| 184 | |
Pekka Paalanen | 23d4af5 | 2015-03-04 16:18:26 +0200 | [diff] [blame] | 185 | static bool |
| 186 | view_transformation_is_translation(struct weston_view *view) |
| 187 | { |
| 188 | if (!view->transform.enabled) |
| 189 | return true; |
| 190 | |
| 191 | if (view->transform.matrix.type <= WESTON_MATRIX_TRANSFORM_TRANSLATE) |
| 192 | return true; |
| 193 | |
| 194 | return false; |
| 195 | } |
| 196 | |
Pekka Paalanen | 6ea523b | 2015-03-04 14:18:39 +0200 | [diff] [blame] | 197 | static void |
Pekka Paalanen | f75b6bb | 2015-03-04 16:12:04 +0200 | [diff] [blame] | 198 | region_intersect_only_translation(pixman_region32_t *result_global, |
| 199 | pixman_region32_t *global, |
| 200 | pixman_region32_t *surf, |
| 201 | struct weston_view *view) |
| 202 | { |
| 203 | float view_x, view_y; |
| 204 | |
| 205 | assert(view_transformation_is_translation(view)); |
| 206 | |
| 207 | /* Convert from surface to global coordinates */ |
| 208 | pixman_region32_copy(result_global, surf); |
| 209 | weston_view_to_global_float(view, 0, 0, &view_x, &view_y); |
| 210 | pixman_region32_translate(result_global, (int)view_x, (int)view_y); |
| 211 | |
| 212 | pixman_region32_intersect(result_global, result_global, global); |
| 213 | } |
| 214 | |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 215 | static void |
| 216 | composite_whole(pixman_op_t op, |
| 217 | pixman_image_t *src, |
| 218 | pixman_image_t *mask, |
| 219 | pixman_image_t *dest, |
| 220 | const pixman_transform_t *transform, |
| 221 | pixman_filter_t filter) |
| 222 | { |
| 223 | int32_t dest_width; |
| 224 | int32_t dest_height; |
| 225 | |
| 226 | dest_width = pixman_image_get_width(dest); |
| 227 | dest_height = pixman_image_get_height(dest); |
| 228 | |
| 229 | pixman_image_set_transform(src, transform); |
| 230 | pixman_image_set_filter(src, filter, NULL, 0); |
| 231 | |
| 232 | pixman_image_composite32(op, src, mask, dest, |
| 233 | 0, 0, /* src_x, src_y */ |
| 234 | 0, 0, /* mask_x, mask_y */ |
| 235 | 0, 0, /* dest_x, dest_y */ |
| 236 | dest_width, dest_height); |
| 237 | } |
| 238 | |
| 239 | static void |
| 240 | composite_clipped(pixman_image_t *src, |
| 241 | pixman_image_t *mask, |
| 242 | pixman_image_t *dest, |
| 243 | const pixman_transform_t *transform, |
| 244 | pixman_filter_t filter, |
| 245 | pixman_region32_t *src_clip) |
| 246 | { |
| 247 | int n_box; |
| 248 | pixman_box32_t *boxes; |
| 249 | int32_t dest_width; |
| 250 | int32_t dest_height; |
| 251 | int src_stride; |
| 252 | int bitspp; |
| 253 | pixman_format_code_t src_format; |
| 254 | void *src_data; |
| 255 | int i; |
| 256 | |
| 257 | /* Hardcoded to use PIXMAN_OP_OVER, because sampling outside of |
| 258 | * a Pixman image produces (0,0,0,0) instead of discarding the |
| 259 | * fragment. |
| 260 | */ |
| 261 | |
| 262 | dest_width = pixman_image_get_width(dest); |
| 263 | dest_height = pixman_image_get_height(dest); |
| 264 | src_format = pixman_image_get_format(src); |
| 265 | src_stride = pixman_image_get_stride(src); |
| 266 | bitspp = PIXMAN_FORMAT_BPP(src_format); |
| 267 | src_data = pixman_image_get_data(src); |
| 268 | |
| 269 | assert(src_format); |
| 270 | |
| 271 | /* This would be massive overdraw, except when n_box is 1. */ |
| 272 | boxes = pixman_region32_rectangles(src_clip, &n_box); |
| 273 | for (i = 0; i < n_box; i++) { |
| 274 | uint8_t *ptr = src_data; |
| 275 | pixman_image_t *boximg; |
| 276 | pixman_transform_t adj = *transform; |
| 277 | |
| 278 | ptr += boxes[i].y1 * src_stride; |
| 279 | ptr += boxes[i].x1 * bitspp / 8; |
| 280 | boximg = pixman_image_create_bits_no_clear(src_format, |
| 281 | boxes[i].x2 - boxes[i].x1, |
| 282 | boxes[i].y2 - boxes[i].y1, |
| 283 | (uint32_t *)ptr, src_stride); |
| 284 | |
| 285 | pixman_transform_translate(&adj, NULL, |
| 286 | pixman_int_to_fixed(-boxes[i].x1), |
| 287 | pixman_int_to_fixed(-boxes[i].y1)); |
| 288 | pixman_image_set_transform(boximg, &adj); |
| 289 | |
| 290 | pixman_image_set_filter(boximg, filter, NULL, 0); |
| 291 | pixman_image_composite32(PIXMAN_OP_OVER, boximg, mask, dest, |
| 292 | 0, 0, /* src_x, src_y */ |
| 293 | 0, 0, /* mask_x, mask_y */ |
| 294 | 0, 0, /* dest_x, dest_y */ |
| 295 | dest_width, dest_height); |
| 296 | |
| 297 | pixman_image_unref(boximg); |
| 298 | } |
| 299 | |
| 300 | if (n_box > 1) { |
| 301 | static bool warned = false; |
| 302 | |
| 303 | if (!warned) |
| 304 | weston_log("Pixman-renderer warning: %dx overdraw\n", |
| 305 | n_box); |
| 306 | warned = true; |
| 307 | } |
| 308 | } |
| 309 | |
Pekka Paalanen | 11af0d9 | 2015-03-05 11:56:29 +0200 | [diff] [blame] | 310 | /** Paint an intersected region |
| 311 | * |
| 312 | * \param ev The view to be painted. |
| 313 | * \param output The output being painted. |
| 314 | * \param repaint_output The region to be painted in output coordinates. |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 315 | * \param source_clip The region of the source image to use, in source image |
| 316 | * coordinates. If NULL, use the whole source image. |
Pekka Paalanen | 11af0d9 | 2015-03-05 11:56:29 +0200 | [diff] [blame] | 317 | * \param pixman_op Compositing operator, either SRC or OVER. |
| 318 | */ |
Pekka Paalanen | f75b6bb | 2015-03-04 16:12:04 +0200 | [diff] [blame] | 319 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 320 | repaint_region(struct weston_view *ev, struct weston_output *output, |
Pekka Paalanen | 11af0d9 | 2015-03-05 11:56:29 +0200 | [diff] [blame] | 321 | pixman_region32_t *repaint_output, |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 322 | pixman_region32_t *source_clip, |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 323 | pixman_op_t pixman_op) |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 324 | { |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 325 | struct pixman_renderer *pr = |
| 326 | (struct pixman_renderer *) output->compositor->renderer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 327 | struct pixman_surface_state *ps = get_surface_state(ev->surface); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 328 | struct pixman_output_state *po = get_output_state(output); |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 329 | struct weston_buffer_viewport *vp = &ev->surface->buffer_viewport; |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 330 | pixman_image_t *target_image; |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 331 | pixman_transform_t transform; |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 332 | pixman_filter_t filter; |
Manuel Bachmann | 9c4ab66 | 2014-04-07 11:58:45 +0200 | [diff] [blame] | 333 | pixman_image_t *mask_image; |
| 334 | pixman_color_t mask = { 0, }; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 335 | |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 336 | if (po->shadow_image) |
| 337 | target_image = po->shadow_image; |
| 338 | else |
| 339 | target_image = po->hw_buffer; |
| 340 | |
| 341 | /* Clip rendering to the damaged output region */ |
| 342 | pixman_image_set_clip_region32(target_image, repaint_output); |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 343 | |
Pekka Paalanen | 6ea523b | 2015-03-04 14:18:39 +0200 | [diff] [blame] | 344 | pixman_renderer_compute_transform(&transform, ev, output); |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 345 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 346 | if (ev->transform.enabled || output->current_scale != vp->buffer.scale) |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 347 | filter = PIXMAN_FILTER_BILINEAR; |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 348 | else |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 349 | filter = PIXMAN_FILTER_NEAREST; |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 350 | |
Neil Roberts | e505171 | 2013-11-13 15:44:06 +0000 | [diff] [blame] | 351 | if (ps->buffer_ref.buffer) |
| 352 | wl_shm_buffer_begin_access(ps->buffer_ref.buffer->shm_buffer); |
| 353 | |
Manuel Bachmann | b1fff41 | 2014-04-05 05:31:37 +0200 | [diff] [blame] | 354 | if (ev->alpha < 1.0) { |
Manuel Bachmann | 9c4ab66 | 2014-04-07 11:58:45 +0200 | [diff] [blame] | 355 | mask.alpha = 0xffff * ev->alpha; |
Manuel Bachmann | b1fff41 | 2014-04-05 05:31:37 +0200 | [diff] [blame] | 356 | mask_image = pixman_image_create_solid_fill(&mask); |
Manuel Bachmann | 9c4ab66 | 2014-04-07 11:58:45 +0200 | [diff] [blame] | 357 | } else { |
Manuel Bachmann | b1fff41 | 2014-04-05 05:31:37 +0200 | [diff] [blame] | 358 | mask_image = NULL; |
Manuel Bachmann | 9c4ab66 | 2014-04-07 11:58:45 +0200 | [diff] [blame] | 359 | } |
Manuel Bachmann | b1fff41 | 2014-04-05 05:31:37 +0200 | [diff] [blame] | 360 | |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 361 | if (source_clip) |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 362 | composite_clipped(ps->image, mask_image, target_image, |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 363 | &transform, filter, source_clip); |
| 364 | else |
| 365 | composite_whole(pixman_op, ps->image, mask_image, |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 366 | target_image, &transform, filter); |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 367 | |
Manuel Bachmann | 9c4ab66 | 2014-04-07 11:58:45 +0200 | [diff] [blame] | 368 | if (mask_image) |
| 369 | pixman_image_unref(mask_image); |
| 370 | |
Neil Roberts | e505171 | 2013-11-13 15:44:06 +0000 | [diff] [blame] | 371 | if (ps->buffer_ref.buffer) |
| 372 | wl_shm_buffer_end_access(ps->buffer_ref.buffer->shm_buffer); |
| 373 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 374 | if (pr->repaint_debug) |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 375 | pixman_image_composite32(PIXMAN_OP_OVER, |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 376 | pr->debug_color, /* src */ |
| 377 | NULL /* mask */, |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 378 | target_image, /* dest */ |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 379 | 0, 0, /* src_x, src_y */ |
| 380 | 0, 0, /* mask_x, mask_y */ |
| 381 | 0, 0, /* dest_x, dest_y */ |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 382 | pixman_image_get_width (target_image), /* width */ |
| 383 | pixman_image_get_height (target_image) /* height */); |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 384 | |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 385 | pixman_image_set_clip_region32(target_image, NULL); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | static void |
Pekka Paalanen | ccf99ce | 2015-03-05 12:57:35 +0200 | [diff] [blame] | 389 | draw_view_translated(struct weston_view *view, struct weston_output *output, |
| 390 | pixman_region32_t *repaint_global) |
| 391 | { |
| 392 | struct weston_surface *surface = view->surface; |
| 393 | /* non-opaque region in surface coordinates: */ |
| 394 | pixman_region32_t surface_blend; |
| 395 | /* region to be painted in output coordinates: */ |
| 396 | pixman_region32_t repaint_output; |
| 397 | |
| 398 | pixman_region32_init(&repaint_output); |
| 399 | |
| 400 | /* Blended region is whole surface minus opaque region, |
| 401 | * unless surface alpha forces us to blend all. |
| 402 | */ |
| 403 | pixman_region32_init_rect(&surface_blend, 0, 0, |
| 404 | surface->width, surface->height); |
| 405 | |
| 406 | if (!(view->alpha < 1.0)) { |
| 407 | pixman_region32_subtract(&surface_blend, &surface_blend, |
| 408 | &surface->opaque); |
| 409 | |
| 410 | if (pixman_region32_not_empty(&surface->opaque)) { |
| 411 | region_intersect_only_translation(&repaint_output, |
| 412 | repaint_global, |
| 413 | &surface->opaque, |
| 414 | view); |
| 415 | region_global_to_output(output, &repaint_output); |
| 416 | |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 417 | repaint_region(view, output, &repaint_output, NULL, |
Pekka Paalanen | ccf99ce | 2015-03-05 12:57:35 +0200 | [diff] [blame] | 418 | PIXMAN_OP_SRC); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | if (pixman_region32_not_empty(&surface_blend)) { |
| 423 | region_intersect_only_translation(&repaint_output, |
| 424 | repaint_global, |
| 425 | &surface_blend, view); |
| 426 | region_global_to_output(output, &repaint_output); |
| 427 | |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 428 | repaint_region(view, output, &repaint_output, NULL, |
Pekka Paalanen | ccf99ce | 2015-03-05 12:57:35 +0200 | [diff] [blame] | 429 | PIXMAN_OP_OVER); |
| 430 | } |
| 431 | |
| 432 | pixman_region32_fini(&surface_blend); |
| 433 | pixman_region32_fini(&repaint_output); |
| 434 | } |
| 435 | |
| 436 | static void |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 437 | draw_view_source_clipped(struct weston_view *view, |
| 438 | struct weston_output *output, |
| 439 | pixman_region32_t *repaint_global) |
| 440 | { |
| 441 | struct weston_surface *surface = view->surface; |
| 442 | pixman_region32_t surf_region; |
| 443 | pixman_region32_t buffer_region; |
| 444 | pixman_region32_t repaint_output; |
| 445 | |
| 446 | /* Do not bother separating the opaque region from non-opaque. |
| 447 | * Source clipping requires PIXMAN_OP_OVER in all cases, so painting |
| 448 | * opaque separately has no benefit. |
| 449 | */ |
| 450 | |
| 451 | pixman_region32_init_rect(&surf_region, 0, 0, |
| 452 | surface->width, surface->height); |
Pekka Paalanen | c93782a | 2015-03-06 10:33:50 +0200 | [diff] [blame] | 453 | if (view->geometry.scissor_enabled) |
| 454 | pixman_region32_intersect(&surf_region, &surf_region, |
| 455 | &view->geometry.scissor); |
| 456 | |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 457 | pixman_region32_init(&buffer_region); |
| 458 | weston_surface_to_buffer_region(surface, &surf_region, &buffer_region); |
| 459 | |
| 460 | pixman_region32_init(&repaint_output); |
| 461 | pixman_region32_copy(&repaint_output, repaint_global); |
| 462 | region_global_to_output(output, &repaint_output); |
| 463 | |
| 464 | repaint_region(view, output, &repaint_output, &buffer_region, |
| 465 | PIXMAN_OP_OVER); |
| 466 | |
| 467 | pixman_region32_fini(&repaint_output); |
| 468 | pixman_region32_fini(&buffer_region); |
| 469 | pixman_region32_fini(&surf_region); |
| 470 | } |
| 471 | |
| 472 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 473 | draw_view(struct weston_view *ev, struct weston_output *output, |
| 474 | pixman_region32_t *damage) /* in global coordinates */ |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 475 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 476 | struct pixman_surface_state *ps = get_surface_state(ev->surface); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 477 | /* repaint bounding region in global coordinates: */ |
| 478 | pixman_region32_t repaint; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 479 | |
| 480 | /* No buffer attached */ |
| 481 | if (!ps->image) |
| 482 | return; |
| 483 | |
| 484 | pixman_region32_init(&repaint); |
| 485 | pixman_region32_intersect(&repaint, |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 486 | &ev->transform.boundingbox, damage); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 487 | pixman_region32_subtract(&repaint, &repaint, &ev->clip); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 488 | |
| 489 | if (!pixman_region32_not_empty(&repaint)) |
| 490 | goto out; |
| 491 | |
Pekka Paalanen | ccf99ce | 2015-03-05 12:57:35 +0200 | [diff] [blame] | 492 | if (view_transformation_is_translation(ev)) { |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 493 | /* The simple case: The surface regions opaque, non-opaque, |
| 494 | * etc. are convertible to global coordinate space. |
| 495 | * There is no need to use a source clip region. |
| 496 | * It is possible to paint opaque region as PIXMAN_OP_SRC. |
Pekka Paalanen | c93782a | 2015-03-06 10:33:50 +0200 | [diff] [blame] | 497 | * Also the boundingbox is accurate rather than an |
| 498 | * approximation. |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 499 | */ |
Pekka Paalanen | ccf99ce | 2015-03-05 12:57:35 +0200 | [diff] [blame] | 500 | draw_view_translated(ev, output, &repaint); |
| 501 | } else { |
Pekka Paalanen | d7ca6b0 | 2015-03-05 13:25:19 +0200 | [diff] [blame] | 502 | /* The complex case: the view transformation does not allow |
| 503 | * converting opaque etc. regions into global coordinate space. |
| 504 | * Therefore we need source clipping to avoid sampling from |
| 505 | * unwanted source image areas, unless the source image is |
| 506 | * to be used whole. Source clipping does not work with |
| 507 | * PIXMAN_OP_SRC. |
| 508 | */ |
| 509 | draw_view_source_clipped(ev, output, &repaint); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 510 | } |
| 511 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 512 | out: |
| 513 | pixman_region32_fini(&repaint); |
| 514 | } |
| 515 | static void |
| 516 | repaint_surfaces(struct weston_output *output, pixman_region32_t *damage) |
| 517 | { |
| 518 | struct weston_compositor *compositor = output->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 519 | struct weston_view *view; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 520 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 521 | wl_list_for_each_reverse(view, &compositor->view_list, link) |
| 522 | if (view->plane == &compositor->primary_plane) |
| 523 | draw_view(view, output, damage); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | static void |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 527 | copy_to_hw_buffer(struct weston_output *output, pixman_region32_t *region) |
| 528 | { |
| 529 | struct pixman_output_state *po = get_output_state(output); |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 530 | pixman_region32_t output_region; |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 531 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 532 | pixman_region32_init(&output_region); |
| 533 | pixman_region32_copy(&output_region, region); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 534 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 535 | region_global_to_output(output, &output_region); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 536 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 537 | pixman_image_set_clip_region32 (po->hw_buffer, &output_region); |
Ryo Munakata | 389d205 | 2014-09-04 01:56:53 +0900 | [diff] [blame] | 538 | pixman_region32_fini(&output_region); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 539 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 540 | pixman_image_composite32(PIXMAN_OP_SRC, |
| 541 | po->shadow_image, /* src */ |
| 542 | NULL /* mask */, |
| 543 | po->hw_buffer, /* dest */ |
| 544 | 0, 0, /* src_x, src_y */ |
| 545 | 0, 0, /* mask_x, mask_y */ |
| 546 | 0, 0, /* dest_x, dest_y */ |
| 547 | pixman_image_get_width (po->hw_buffer), /* width */ |
| 548 | pixman_image_get_height (po->hw_buffer) /* height */); |
| 549 | |
| 550 | pixman_image_set_clip_region32 (po->hw_buffer, NULL); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | static void |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 554 | pixman_renderer_repaint_output(struct weston_output *output, |
Pekka Paalanen | acf50c3 | 2018-04-23 11:44:56 +0200 | [diff] [blame] | 555 | pixman_region32_t *output_damage) |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 556 | { |
| 557 | struct pixman_output_state *po = get_output_state(output); |
Pekka Paalanen | acf50c3 | 2018-04-23 11:44:56 +0200 | [diff] [blame] | 558 | pixman_region32_t hw_damage; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 559 | |
Pekka Paalanen | acf50c3 | 2018-04-23 11:44:56 +0200 | [diff] [blame] | 560 | if (!po->hw_buffer) { |
| 561 | po->hw_extra_damage = NULL; |
| 562 | return; |
| 563 | } |
| 564 | |
| 565 | pixman_region32_init(&hw_damage); |
| 566 | if (po->hw_extra_damage) { |
| 567 | pixman_region32_union(&hw_damage, |
| 568 | po->hw_extra_damage, output_damage); |
| 569 | po->hw_extra_damage = NULL; |
| 570 | } else { |
| 571 | pixman_region32_copy(&hw_damage, output_damage); |
| 572 | } |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 573 | |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 574 | if (po->shadow_image) { |
| 575 | repaint_surfaces(output, output_damage); |
| 576 | copy_to_hw_buffer(output, &hw_damage); |
| 577 | } else { |
| 578 | repaint_surfaces(output, &hw_damage); |
| 579 | } |
Pekka Paalanen | acf50c3 | 2018-04-23 11:44:56 +0200 | [diff] [blame] | 580 | pixman_region32_fini(&hw_damage); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 581 | |
Stefan Agner | 0bb9447 | 2019-12-09 13:26:57 +0100 | [diff] [blame^] | 582 | wl_signal_emit(&output->frame_signal, output_damage); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 583 | |
| 584 | /* Actual flip should be done by caller */ |
| 585 | } |
| 586 | |
| 587 | static void |
| 588 | pixman_renderer_flush_damage(struct weston_surface *surface) |
| 589 | { |
| 590 | /* No-op for pixman renderer */ |
| 591 | } |
| 592 | |
| 593 | static void |
Lubomir Rintel | ddc2b1e | 2013-12-12 12:57:56 +0100 | [diff] [blame] | 594 | buffer_state_handle_buffer_destroy(struct wl_listener *listener, void *data) |
| 595 | { |
| 596 | struct pixman_surface_state *ps; |
| 597 | |
| 598 | ps = container_of(listener, struct pixman_surface_state, |
| 599 | buffer_destroy_listener); |
| 600 | |
| 601 | if (ps->image) { |
| 602 | pixman_image_unref(ps->image); |
| 603 | ps->image = NULL; |
| 604 | } |
| 605 | |
| 606 | ps->buffer_destroy_listener.notify = NULL; |
| 607 | } |
| 608 | |
| 609 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 610 | pixman_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer) |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 611 | { |
| 612 | struct pixman_surface_state *ps = get_surface_state(es); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 613 | struct wl_shm_buffer *shm_buffer; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 614 | pixman_format_code_t pixman_format; |
| 615 | |
| 616 | weston_buffer_reference(&ps->buffer_ref, buffer); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 617 | weston_buffer_release_reference(&ps->buffer_release_ref, |
| 618 | es->buffer_release_ref.buffer_release); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 619 | |
Lubomir Rintel | ddc2b1e | 2013-12-12 12:57:56 +0100 | [diff] [blame] | 620 | if (ps->buffer_destroy_listener.notify) { |
| 621 | wl_list_remove(&ps->buffer_destroy_listener.link); |
| 622 | ps->buffer_destroy_listener.notify = NULL; |
| 623 | } |
| 624 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 625 | if (ps->image) { |
| 626 | pixman_image_unref(ps->image); |
| 627 | ps->image = NULL; |
| 628 | } |
| 629 | |
| 630 | if (!buffer) |
| 631 | return; |
Jason Ekstrand | 52c476a | 2015-11-18 16:32:29 -0600 | [diff] [blame] | 632 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 633 | shm_buffer = wl_shm_buffer_get(buffer->resource); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 634 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 635 | if (! shm_buffer) { |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 636 | weston_log("Pixman renderer supports only SHM buffers\n"); |
| 637 | weston_buffer_reference(&ps->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 638 | weston_buffer_release_reference(&ps->buffer_release_ref, NULL); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 639 | return; |
| 640 | } |
| 641 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 642 | switch (wl_shm_buffer_get_format(shm_buffer)) { |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 643 | case WL_SHM_FORMAT_XRGB8888: |
| 644 | pixman_format = PIXMAN_x8r8g8b8; |
Philipp Zabel | 195dade | 2018-09-03 19:44:59 +0200 | [diff] [blame] | 645 | es->is_opaque = true; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 646 | break; |
| 647 | case WL_SHM_FORMAT_ARGB8888: |
| 648 | pixman_format = PIXMAN_a8r8g8b8; |
Philipp Zabel | 195dade | 2018-09-03 19:44:59 +0200 | [diff] [blame] | 649 | es->is_opaque = false; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 650 | break; |
Tomeu Vizoso | 1c1fc29 | 2013-08-06 20:05:56 +0200 | [diff] [blame] | 651 | case WL_SHM_FORMAT_RGB565: |
| 652 | pixman_format = PIXMAN_r5g6b5; |
Philipp Zabel | 195dade | 2018-09-03 19:44:59 +0200 | [diff] [blame] | 653 | es->is_opaque = true; |
Tomeu Vizoso | 1c1fc29 | 2013-08-06 20:05:56 +0200 | [diff] [blame] | 654 | break; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 655 | default: |
Vasilis Liaskovitis | 486b463 | 2018-10-10 16:14:55 +0200 | [diff] [blame] | 656 | weston_log("Unsupported SHM buffer format 0x%x\n", |
| 657 | wl_shm_buffer_get_format(shm_buffer)); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 658 | weston_buffer_reference(&ps->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 659 | weston_buffer_release_reference(&ps->buffer_release_ref, NULL); |
Vasilis Liaskovitis | 486b463 | 2018-10-10 16:14:55 +0200 | [diff] [blame] | 660 | weston_buffer_send_server_error(buffer, |
| 661 | "disconnecting due to unhandled buffer type"); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 662 | return; |
| 663 | break; |
| 664 | } |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 665 | |
| 666 | buffer->shm_buffer = shm_buffer; |
| 667 | buffer->width = wl_shm_buffer_get_width(shm_buffer); |
| 668 | buffer->height = wl_shm_buffer_get_height(shm_buffer); |
| 669 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 670 | ps->image = pixman_image_create_bits(pixman_format, |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 671 | buffer->width, buffer->height, |
| 672 | wl_shm_buffer_get_data(shm_buffer), |
| 673 | wl_shm_buffer_get_stride(shm_buffer)); |
Lubomir Rintel | ddc2b1e | 2013-12-12 12:57:56 +0100 | [diff] [blame] | 674 | |
| 675 | ps->buffer_destroy_listener.notify = |
| 676 | buffer_state_handle_buffer_destroy; |
| 677 | wl_signal_add(&buffer->destroy_signal, |
| 678 | &ps->buffer_destroy_listener); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 679 | } |
| 680 | |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 681 | static void |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 682 | pixman_renderer_surface_state_destroy(struct pixman_surface_state *ps) |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 683 | { |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 684 | wl_list_remove(&ps->surface_destroy_listener.link); |
| 685 | wl_list_remove(&ps->renderer_destroy_listener.link); |
Lubomir Rintel | ddc2b1e | 2013-12-12 12:57:56 +0100 | [diff] [blame] | 686 | if (ps->buffer_destroy_listener.notify) { |
| 687 | wl_list_remove(&ps->buffer_destroy_listener.link); |
| 688 | ps->buffer_destroy_listener.notify = NULL; |
| 689 | } |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 690 | |
| 691 | ps->surface->renderer_state = NULL; |
| 692 | |
| 693 | if (ps->image) { |
| 694 | pixman_image_unref(ps->image); |
| 695 | ps->image = NULL; |
| 696 | } |
| 697 | weston_buffer_reference(&ps->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 698 | weston_buffer_release_reference(&ps->buffer_release_ref, NULL); |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 699 | free(ps); |
| 700 | } |
| 701 | |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 702 | static void |
| 703 | surface_state_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 704 | { |
| 705 | struct pixman_surface_state *ps; |
| 706 | |
| 707 | ps = container_of(listener, struct pixman_surface_state, |
| 708 | surface_destroy_listener); |
| 709 | |
| 710 | pixman_renderer_surface_state_destroy(ps); |
| 711 | } |
| 712 | |
| 713 | static void |
| 714 | surface_state_handle_renderer_destroy(struct wl_listener *listener, void *data) |
| 715 | { |
| 716 | struct pixman_surface_state *ps; |
| 717 | |
| 718 | ps = container_of(listener, struct pixman_surface_state, |
| 719 | renderer_destroy_listener); |
| 720 | |
| 721 | pixman_renderer_surface_state_destroy(ps); |
| 722 | } |
| 723 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 724 | static int |
| 725 | pixman_renderer_create_surface(struct weston_surface *surface) |
| 726 | { |
| 727 | struct pixman_surface_state *ps; |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 728 | struct pixman_renderer *pr = get_renderer(surface->compositor); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 729 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 730 | ps = zalloc(sizeof *ps); |
| 731 | if (ps == NULL) |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 732 | return -1; |
| 733 | |
| 734 | surface->renderer_state = ps; |
| 735 | |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 736 | ps->surface = surface; |
| 737 | |
| 738 | ps->surface_destroy_listener.notify = |
| 739 | surface_state_handle_surface_destroy; |
| 740 | wl_signal_add(&surface->destroy_signal, |
| 741 | &ps->surface_destroy_listener); |
| 742 | |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 743 | ps->renderer_destroy_listener.notify = |
| 744 | surface_state_handle_renderer_destroy; |
| 745 | wl_signal_add(&pr->destroy_signal, |
| 746 | &ps->renderer_destroy_listener); |
| 747 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static void |
| 752 | pixman_renderer_surface_set_color(struct weston_surface *es, |
| 753 | float red, float green, float blue, float alpha) |
| 754 | { |
| 755 | struct pixman_surface_state *ps = get_surface_state(es); |
| 756 | pixman_color_t color; |
| 757 | |
| 758 | color.red = red * 0xffff; |
| 759 | color.green = green * 0xffff; |
| 760 | color.blue = blue * 0xffff; |
| 761 | color.alpha = alpha * 0xffff; |
Jason Ekstrand | 52c476a | 2015-11-18 16:32:29 -0600 | [diff] [blame] | 762 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 763 | if (ps->image) { |
| 764 | pixman_image_unref(ps->image); |
| 765 | ps->image = NULL; |
| 766 | } |
| 767 | |
| 768 | ps->image = pixman_image_create_solid_fill(&color); |
| 769 | } |
| 770 | |
| 771 | static void |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 772 | pixman_renderer_destroy(struct weston_compositor *ec) |
| 773 | { |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 774 | struct pixman_renderer *pr = get_renderer(ec); |
| 775 | |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 776 | wl_signal_emit(&pr->destroy_signal, pr); |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 777 | weston_binding_destroy(pr->debug_binding); |
| 778 | free(pr); |
| 779 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 780 | ec->renderer = NULL; |
| 781 | } |
| 782 | |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 783 | static void |
Pekka Paalanen | 6764bbe | 2015-02-11 12:29:56 +0200 | [diff] [blame] | 784 | pixman_renderer_surface_get_content_size(struct weston_surface *surface, |
| 785 | int *width, int *height) |
| 786 | { |
| 787 | struct pixman_surface_state *ps = get_surface_state(surface); |
| 788 | |
| 789 | if (ps->image) { |
| 790 | *width = pixman_image_get_width(ps->image); |
| 791 | *height = pixman_image_get_height(ps->image); |
| 792 | } else { |
| 793 | *width = 0; |
| 794 | *height = 0; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | static int |
| 799 | pixman_renderer_surface_copy_content(struct weston_surface *surface, |
| 800 | void *target, size_t size, |
| 801 | int src_x, int src_y, |
| 802 | int width, int height) |
| 803 | { |
| 804 | const pixman_format_code_t format = PIXMAN_a8b8g8r8; |
| 805 | const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */ |
| 806 | struct pixman_surface_state *ps = get_surface_state(surface); |
| 807 | pixman_image_t *out_buf; |
| 808 | |
| 809 | if (!ps->image) |
| 810 | return -1; |
| 811 | |
| 812 | out_buf = pixman_image_create_bits(format, width, height, |
| 813 | target, width * bytespp); |
| 814 | |
| 815 | pixman_image_set_transform(ps->image, NULL); |
| 816 | pixman_image_composite32(PIXMAN_OP_SRC, |
| 817 | ps->image, /* src */ |
| 818 | NULL, /* mask */ |
| 819 | out_buf, /* dest */ |
| 820 | src_x, src_y, /* src_x, src_y */ |
| 821 | 0, 0, /* mask_x, mask_y */ |
| 822 | 0, 0, /* dest_x, dest_y */ |
| 823 | width, height); |
| 824 | |
| 825 | pixman_image_unref(out_buf); |
| 826 | |
| 827 | return 0; |
| 828 | } |
| 829 | |
| 830 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 831 | debug_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
| 832 | uint32_t key, void *data) |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 833 | { |
| 834 | struct weston_compositor *ec = data; |
| 835 | struct pixman_renderer *pr = (struct pixman_renderer *) ec->renderer; |
| 836 | |
| 837 | pr->repaint_debug ^= 1; |
| 838 | |
| 839 | if (pr->repaint_debug) { |
| 840 | pixman_color_t red = { |
| 841 | 0x3fff, 0x0000, 0x0000, 0x3fff |
| 842 | }; |
| 843 | |
| 844 | pr->debug_color = pixman_image_create_solid_fill(&red); |
| 845 | } else { |
| 846 | pixman_image_unref(pr->debug_color); |
| 847 | weston_compositor_damage_all(ec); |
| 848 | } |
| 849 | } |
| 850 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 851 | WL_EXPORT int |
| 852 | pixman_renderer_init(struct weston_compositor *ec) |
| 853 | { |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 854 | struct pixman_renderer *renderer; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 855 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 856 | renderer = zalloc(sizeof *renderer); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 857 | if (renderer == NULL) |
| 858 | return -1; |
| 859 | |
Philipp Brüschweiler | f3e39f9 | 2013-03-08 20:35:39 +0100 | [diff] [blame] | 860 | renderer->repaint_debug = 0; |
| 861 | renderer->debug_color = NULL; |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 862 | renderer->base.read_pixels = pixman_renderer_read_pixels; |
| 863 | renderer->base.repaint_output = pixman_renderer_repaint_output; |
| 864 | renderer->base.flush_damage = pixman_renderer_flush_damage; |
| 865 | renderer->base.attach = pixman_renderer_attach; |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 866 | renderer->base.surface_set_color = pixman_renderer_surface_set_color; |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 867 | renderer->base.destroy = pixman_renderer_destroy; |
Pekka Paalanen | 6764bbe | 2015-02-11 12:29:56 +0200 | [diff] [blame] | 868 | renderer->base.surface_get_content_size = |
| 869 | pixman_renderer_surface_get_content_size; |
| 870 | renderer->base.surface_copy_content = |
| 871 | pixman_renderer_surface_copy_content; |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 872 | ec->renderer = &renderer->base; |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 873 | ec->capabilities |= WESTON_CAP_ROTATION_ANY; |
Pekka Paalanen | c93782a | 2015-03-06 10:33:50 +0200 | [diff] [blame] | 874 | ec->capabilities |= WESTON_CAP_VIEW_CLIP_MASK; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 875 | |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 876 | renderer->debug_binding = |
| 877 | weston_compositor_add_debug_binding(ec, KEY_R, |
| 878 | debug_binding, ec); |
Tomeu Vizoso | 1c1fc29 | 2013-08-06 20:05:56 +0200 | [diff] [blame] | 879 | |
| 880 | wl_display_add_shm_format(ec->wl_display, WL_SHM_FORMAT_RGB565); |
| 881 | |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 882 | wl_signal_init(&renderer->destroy_signal); |
| 883 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 884 | return 0; |
| 885 | } |
| 886 | |
| 887 | WL_EXPORT void |
Pekka Paalanen | acf50c3 | 2018-04-23 11:44:56 +0200 | [diff] [blame] | 888 | pixman_renderer_output_set_buffer(struct weston_output *output, |
| 889 | pixman_image_t *buffer) |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 890 | { |
| 891 | struct pixman_output_state *po = get_output_state(output); |
| 892 | |
| 893 | if (po->hw_buffer) |
| 894 | pixman_image_unref(po->hw_buffer); |
| 895 | po->hw_buffer = buffer; |
| 896 | |
| 897 | if (po->hw_buffer) { |
| 898 | output->compositor->read_format = pixman_image_get_format(po->hw_buffer); |
| 899 | pixman_image_ref(po->hw_buffer); |
| 900 | } |
| 901 | } |
| 902 | |
Pekka Paalanen | acf50c3 | 2018-04-23 11:44:56 +0200 | [diff] [blame] | 903 | WL_EXPORT void |
| 904 | pixman_renderer_output_set_hw_extra_damage(struct weston_output *output, |
| 905 | pixman_region32_t *extra_damage) |
| 906 | { |
| 907 | struct pixman_output_state *po = get_output_state(output); |
| 908 | |
| 909 | po->hw_extra_damage = extra_damage; |
| 910 | } |
| 911 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 912 | WL_EXPORT int |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 913 | pixman_renderer_output_create(struct weston_output *output, uint32_t flags) |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 914 | { |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 915 | struct pixman_output_state *po; |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 916 | int w, h; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 917 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 918 | po = zalloc(sizeof *po); |
| 919 | if (po == NULL) |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 920 | return -1; |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 921 | |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 922 | if (flags & PIXMAN_RENDERER_OUTPUT_USE_SHADOW) { |
| 923 | /* set shadow image transformation */ |
| 924 | w = output->current_mode->width; |
| 925 | h = output->current_mode->height; |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 926 | |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 927 | po->shadow_buffer = malloc(w * h * 4); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 928 | |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 929 | if (!po->shadow_buffer) { |
| 930 | free(po); |
| 931 | return -1; |
| 932 | } |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 933 | |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 934 | po->shadow_image = |
| 935 | pixman_image_create_bits(PIXMAN_x8r8g8b8, w, h, |
| 936 | po->shadow_buffer, w * 4); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 937 | |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 938 | if (!po->shadow_image) { |
| 939 | free(po->shadow_buffer); |
| 940 | free(po); |
| 941 | return -1; |
| 942 | } |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 943 | } |
| 944 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 945 | output->renderer_state = po; |
| 946 | |
| 947 | return 0; |
| 948 | } |
| 949 | |
| 950 | WL_EXPORT void |
| 951 | pixman_renderer_output_destroy(struct weston_output *output) |
| 952 | { |
| 953 | struct pixman_output_state *po = get_output_state(output); |
| 954 | |
Pekka Paalanen | 26ded94 | 2018-04-23 11:44:57 +0200 | [diff] [blame] | 955 | if (po->shadow_image) |
| 956 | pixman_image_unref(po->shadow_image); |
Ander Conselvan de Oliveira | 23e72b8 | 2013-01-25 15:13:06 +0200 | [diff] [blame] | 957 | |
| 958 | if (po->hw_buffer) |
| 959 | pixman_image_unref(po->hw_buffer); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 960 | |
Arnaud Vrac | 8e3fe08 | 2014-08-25 20:56:52 +0200 | [diff] [blame] | 961 | free(po->shadow_buffer); |
| 962 | |
| 963 | po->shadow_buffer = NULL; |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 964 | po->shadow_image = NULL; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 965 | po->hw_buffer = NULL; |
| 966 | |
| 967 | free(po); |
| 968 | } |