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 | * |
| 6 | * Permission to use, copy, modify, distribute, and sell this software and |
| 7 | * its documentation for any purpose is hereby granted without fee, provided |
| 8 | * that the above copyright notice appear in all copies and that both that |
| 9 | * copyright notice and this permission notice appear in supporting |
| 10 | * documentation, and that the name of the copyright holders not be used in |
| 11 | * advertising or publicity pertaining to distribution of the software |
| 12 | * without specific, written prior permission. The copyright holders make |
| 13 | * no representations about the suitability of this software for any |
| 14 | * purpose. It is provided "as is" without express or implied warranty. |
| 15 | * |
| 16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 17 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 20 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 21 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 22 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 23 | */ |
| 24 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 25 | #include "config.h" |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 26 | |
| 27 | #include <errno.h> |
| 28 | #include <stdlib.h> |
Pekka Paalanen | f75b6bb | 2015-03-04 16:12:04 +0200 | [diff] [blame^] | 29 | #include <assert.h> |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 30 | |
| 31 | #include "pixman-renderer.h" |
| 32 | |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 33 | #include <linux/input.h> |
| 34 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 35 | struct pixman_output_state { |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 36 | void *shadow_buffer; |
| 37 | pixman_image_t *shadow_image; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 38 | pixman_image_t *hw_buffer; |
| 39 | }; |
| 40 | |
| 41 | struct pixman_surface_state { |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 42 | struct weston_surface *surface; |
| 43 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 44 | pixman_image_t *image; |
| 45 | struct weston_buffer_reference buffer_ref; |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 46 | |
Lubomir Rintel | ddc2b1e | 2013-12-12 12:57:56 +0100 | [diff] [blame] | 47 | struct wl_listener buffer_destroy_listener; |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 48 | struct wl_listener surface_destroy_listener; |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 49 | struct wl_listener renderer_destroy_listener; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct pixman_renderer { |
| 53 | struct weston_renderer base; |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 54 | |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 55 | int repaint_debug; |
| 56 | pixman_image_t *debug_color; |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 57 | struct weston_binding *debug_binding; |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 58 | |
| 59 | struct wl_signal destroy_signal; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | static inline struct pixman_output_state * |
| 63 | get_output_state(struct weston_output *output) |
| 64 | { |
| 65 | return (struct pixman_output_state *)output->renderer_state; |
| 66 | } |
| 67 | |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 68 | static int |
| 69 | pixman_renderer_create_surface(struct weston_surface *surface); |
| 70 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 71 | static inline struct pixman_surface_state * |
| 72 | get_surface_state(struct weston_surface *surface) |
| 73 | { |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 74 | if (!surface->renderer_state) |
| 75 | pixman_renderer_create_surface(surface); |
| 76 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 77 | return (struct pixman_surface_state *)surface->renderer_state; |
| 78 | } |
| 79 | |
| 80 | static inline struct pixman_renderer * |
| 81 | get_renderer(struct weston_compositor *ec) |
| 82 | { |
| 83 | return (struct pixman_renderer *)ec->renderer; |
| 84 | } |
| 85 | |
| 86 | static int |
| 87 | pixman_renderer_read_pixels(struct weston_output *output, |
| 88 | pixman_format_code_t format, void *pixels, |
| 89 | uint32_t x, uint32_t y, |
| 90 | uint32_t width, uint32_t height) |
| 91 | { |
| 92 | struct pixman_output_state *po = get_output_state(output); |
Alexander Larsson | 97af792 | 2013-05-29 12:01:33 +0200 | [diff] [blame] | 93 | pixman_transform_t transform; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 94 | pixman_image_t *out_buf; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 95 | |
| 96 | if (!po->hw_buffer) { |
| 97 | errno = ENODEV; |
| 98 | return -1; |
| 99 | } |
| 100 | |
| 101 | out_buf = pixman_image_create_bits(format, |
| 102 | width, |
| 103 | height, |
| 104 | pixels, |
| 105 | (PIXMAN_FORMAT_BPP(format) / 8) * width); |
| 106 | |
Alexander Larsson | 97af792 | 2013-05-29 12:01:33 +0200 | [diff] [blame] | 107 | /* Caller expects vflipped source image */ |
| 108 | pixman_transform_init_translate(&transform, |
| 109 | pixman_int_to_fixed (x), |
| 110 | pixman_int_to_fixed (y - pixman_image_get_height (po->hw_buffer))); |
| 111 | pixman_transform_scale(&transform, NULL, |
| 112 | pixman_fixed_1, |
| 113 | pixman_fixed_minus_1); |
| 114 | pixman_image_set_transform(po->hw_buffer, &transform); |
| 115 | |
| 116 | pixman_image_composite32(PIXMAN_OP_SRC, |
| 117 | po->hw_buffer, /* src */ |
| 118 | NULL /* mask */, |
| 119 | out_buf, /* dest */ |
| 120 | 0, 0, /* src_x, src_y */ |
| 121 | 0, 0, /* mask_x, mask_y */ |
| 122 | 0, 0, /* dest_x, dest_y */ |
| 123 | pixman_image_get_width (po->hw_buffer), /* width */ |
| 124 | pixman_image_get_height (po->hw_buffer) /* height */); |
| 125 | pixman_image_set_transform(po->hw_buffer, NULL); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 126 | |
| 127 | pixman_image_unref(out_buf); |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
Vasily Khoruzhick | 031fc87 | 2013-01-29 14:58:14 +0300 | [diff] [blame] | 132 | static void |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 133 | region_global_to_output(struct weston_output *output, pixman_region32_t *region) |
| 134 | { |
| 135 | pixman_region32_translate(region, -output->x, -output->y); |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 136 | weston_transformed_region(output->width, output->height, |
| 137 | output->transform, output->current_scale, |
| 138 | region, region); |
Vasily Khoruzhick | 031fc87 | 2013-01-29 14:58:14 +0300 | [diff] [blame] | 139 | } |
| 140 | |
Vasily Khoruzhick | f4a457f | 2013-01-28 22:40:29 +0300 | [diff] [blame] | 141 | #define D2F(v) pixman_double_to_fixed((double)v) |
| 142 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 143 | static void |
Jason Ekstrand | 8870a23 | 2014-05-20 15:53:19 -0500 | [diff] [blame] | 144 | weston_matrix_to_pixman_transform(pixman_transform_t *pt, |
| 145 | const struct weston_matrix *wm) |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 146 | { |
Jason Ekstrand | 8870a23 | 2014-05-20 15:53:19 -0500 | [diff] [blame] | 147 | /* Pixman supports only 2D transform matrix, but Weston uses 3D, * |
| 148 | * so we're omitting Z coordinate here. */ |
| 149 | pt->matrix[0][0] = pixman_double_to_fixed(wm->d[0]); |
| 150 | pt->matrix[0][1] = pixman_double_to_fixed(wm->d[4]); |
| 151 | pt->matrix[0][2] = pixman_double_to_fixed(wm->d[12]); |
| 152 | pt->matrix[1][0] = pixman_double_to_fixed(wm->d[1]); |
| 153 | pt->matrix[1][1] = pixman_double_to_fixed(wm->d[5]); |
| 154 | pt->matrix[1][2] = pixman_double_to_fixed(wm->d[13]); |
| 155 | pt->matrix[2][0] = pixman_double_to_fixed(wm->d[3]); |
| 156 | pt->matrix[2][1] = pixman_double_to_fixed(wm->d[7]); |
| 157 | pt->matrix[2][2] = pixman_double_to_fixed(wm->d[15]); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static void |
Pekka Paalanen | 6ea523b | 2015-03-04 14:18:39 +0200 | [diff] [blame] | 161 | pixman_renderer_compute_transform(pixman_transform_t *transform_out, |
| 162 | struct weston_view *ev, |
| 163 | struct weston_output *output) |
| 164 | { |
| 165 | struct weston_matrix matrix; |
| 166 | |
| 167 | /* Set up the source transformation based on the surface |
| 168 | position, the output position/transform/scale and the client |
| 169 | specified buffer transform/scale */ |
| 170 | weston_matrix_invert(&matrix, &output->matrix); |
| 171 | |
| 172 | if (ev->transform.enabled) { |
| 173 | weston_matrix_multiply(&matrix, &ev->transform.inverse); |
| 174 | } else { |
| 175 | weston_matrix_translate(&matrix, |
| 176 | -ev->geometry.x, -ev->geometry.y, 0); |
| 177 | } |
| 178 | |
| 179 | weston_matrix_multiply(&matrix, &ev->surface->surface_to_buffer_matrix); |
| 180 | |
| 181 | weston_matrix_to_pixman_transform(transform_out, &matrix); |
| 182 | } |
| 183 | |
Pekka Paalanen | 23d4af5 | 2015-03-04 16:18:26 +0200 | [diff] [blame] | 184 | static bool |
| 185 | view_transformation_is_translation(struct weston_view *view) |
| 186 | { |
| 187 | if (!view->transform.enabled) |
| 188 | return true; |
| 189 | |
| 190 | if (view->transform.matrix.type <= WESTON_MATRIX_TRANSFORM_TRANSLATE) |
| 191 | return true; |
| 192 | |
| 193 | return false; |
| 194 | } |
| 195 | |
Pekka Paalanen | 6ea523b | 2015-03-04 14:18:39 +0200 | [diff] [blame] | 196 | static void |
Pekka Paalanen | f75b6bb | 2015-03-04 16:12:04 +0200 | [diff] [blame^] | 197 | region_intersect_only_translation(pixman_region32_t *result_global, |
| 198 | pixman_region32_t *global, |
| 199 | pixman_region32_t *surf, |
| 200 | struct weston_view *view) |
| 201 | { |
| 202 | float view_x, view_y; |
| 203 | |
| 204 | assert(view_transformation_is_translation(view)); |
| 205 | |
| 206 | /* Convert from surface to global coordinates */ |
| 207 | pixman_region32_copy(result_global, surf); |
| 208 | weston_view_to_global_float(view, 0, 0, &view_x, &view_y); |
| 209 | pixman_region32_translate(result_global, (int)view_x, (int)view_y); |
| 210 | |
| 211 | pixman_region32_intersect(result_global, result_global, global); |
| 212 | } |
| 213 | |
| 214 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 215 | repaint_region(struct weston_view *ev, struct weston_output *output, |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 216 | pixman_region32_t *region, pixman_region32_t *surf_region, |
| 217 | pixman_op_t pixman_op) |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 218 | { |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 219 | struct pixman_renderer *pr = |
| 220 | (struct pixman_renderer *) output->compositor->renderer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 221 | struct pixman_surface_state *ps = get_surface_state(ev->surface); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 222 | struct pixman_output_state *po = get_output_state(output); |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 223 | struct weston_buffer_viewport *vp = &ev->surface->buffer_viewport; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 224 | pixman_region32_t final_region; |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 225 | pixman_transform_t transform; |
Manuel Bachmann | 9c4ab66 | 2014-04-07 11:58:45 +0200 | [diff] [blame] | 226 | pixman_image_t *mask_image; |
| 227 | pixman_color_t mask = { 0, }; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 228 | |
| 229 | /* The final region to be painted is the intersection of |
| 230 | * 'region' and 'surf_region'. However, 'region' is in the global |
| 231 | * coordinates, and 'surf_region' is in the surface-local |
| 232 | * coordinates |
| 233 | */ |
| 234 | pixman_region32_init(&final_region); |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 235 | if (surf_region) { |
Pekka Paalanen | f75b6bb | 2015-03-04 16:12:04 +0200 | [diff] [blame^] | 236 | region_intersect_only_translation(&final_region, region, |
| 237 | surf_region, ev); |
Vasily Khoruzhick | f4a457f | 2013-01-28 22:40:29 +0300 | [diff] [blame] | 238 | } else { |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 239 | /* If there is no surface region, just use the global region */ |
| 240 | pixman_region32_copy(&final_region, region); |
Vasily Khoruzhick | f4a457f | 2013-01-28 22:40:29 +0300 | [diff] [blame] | 241 | } |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 242 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 243 | /* Convert from global to output coord */ |
| 244 | region_global_to_output(output, &final_region); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 245 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 246 | /* And clip to it */ |
| 247 | pixman_image_set_clip_region32 (po->shadow_image, &final_region); |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 248 | |
Pekka Paalanen | 6ea523b | 2015-03-04 14:18:39 +0200 | [diff] [blame] | 249 | pixman_renderer_compute_transform(&transform, ev, output); |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 250 | pixman_image_set_transform(ps->image, &transform); |
| 251 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 252 | if (ev->transform.enabled || output->current_scale != vp->buffer.scale) |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 253 | pixman_image_set_filter(ps->image, PIXMAN_FILTER_BILINEAR, NULL, 0); |
| 254 | else |
| 255 | pixman_image_set_filter(ps->image, PIXMAN_FILTER_NEAREST, NULL, 0); |
| 256 | |
Neil Roberts | e505171 | 2013-11-13 15:44:06 +0000 | [diff] [blame] | 257 | if (ps->buffer_ref.buffer) |
| 258 | wl_shm_buffer_begin_access(ps->buffer_ref.buffer->shm_buffer); |
| 259 | |
Manuel Bachmann | b1fff41 | 2014-04-05 05:31:37 +0200 | [diff] [blame] | 260 | if (ev->alpha < 1.0) { |
Manuel Bachmann | 9c4ab66 | 2014-04-07 11:58:45 +0200 | [diff] [blame] | 261 | mask.alpha = 0xffff * ev->alpha; |
Manuel Bachmann | b1fff41 | 2014-04-05 05:31:37 +0200 | [diff] [blame] | 262 | mask_image = pixman_image_create_solid_fill(&mask); |
Manuel Bachmann | 9c4ab66 | 2014-04-07 11:58:45 +0200 | [diff] [blame] | 263 | } else { |
Manuel Bachmann | b1fff41 | 2014-04-05 05:31:37 +0200 | [diff] [blame] | 264 | mask_image = NULL; |
Manuel Bachmann | 9c4ab66 | 2014-04-07 11:58:45 +0200 | [diff] [blame] | 265 | } |
Manuel Bachmann | b1fff41 | 2014-04-05 05:31:37 +0200 | [diff] [blame] | 266 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 267 | pixman_image_composite32(pixman_op, |
| 268 | ps->image, /* src */ |
Manuel Bachmann | b1fff41 | 2014-04-05 05:31:37 +0200 | [diff] [blame] | 269 | mask_image, /* mask */ |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 270 | po->shadow_image, /* dest */ |
| 271 | 0, 0, /* src_x, src_y */ |
| 272 | 0, 0, /* mask_x, mask_y */ |
| 273 | 0, 0, /* dest_x, dest_y */ |
| 274 | pixman_image_get_width (po->shadow_image), /* width */ |
| 275 | pixman_image_get_height (po->shadow_image) /* height */); |
| 276 | |
Manuel Bachmann | 9c4ab66 | 2014-04-07 11:58:45 +0200 | [diff] [blame] | 277 | if (mask_image) |
| 278 | pixman_image_unref(mask_image); |
| 279 | |
Neil Roberts | e505171 | 2013-11-13 15:44:06 +0000 | [diff] [blame] | 280 | if (ps->buffer_ref.buffer) |
| 281 | wl_shm_buffer_end_access(ps->buffer_ref.buffer->shm_buffer); |
| 282 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 283 | if (pr->repaint_debug) |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 284 | pixman_image_composite32(PIXMAN_OP_OVER, |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 285 | pr->debug_color, /* src */ |
| 286 | NULL /* mask */, |
| 287 | po->shadow_image, /* dest */ |
| 288 | 0, 0, /* src_x, src_y */ |
| 289 | 0, 0, /* mask_x, mask_y */ |
| 290 | 0, 0, /* dest_x, dest_y */ |
| 291 | pixman_image_get_width (po->shadow_image), /* width */ |
| 292 | pixman_image_get_height (po->shadow_image) /* height */); |
| 293 | |
| 294 | pixman_image_set_clip_region32 (po->shadow_image, NULL); |
| 295 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 296 | pixman_region32_fini(&final_region); |
| 297 | } |
| 298 | |
| 299 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 300 | draw_view(struct weston_view *ev, struct weston_output *output, |
| 301 | pixman_region32_t *damage) /* in global coordinates */ |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 302 | { |
Derek Foreman | 66951b7 | 2014-09-01 10:33:28 -0500 | [diff] [blame] | 303 | static int zoom_logged = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 304 | struct pixman_surface_state *ps = get_surface_state(ev->surface); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 305 | /* repaint bounding region in global coordinates: */ |
| 306 | pixman_region32_t repaint; |
| 307 | /* non-opaque region in surface coordinates: */ |
| 308 | pixman_region32_t surface_blend; |
| 309 | |
| 310 | /* No buffer attached */ |
| 311 | if (!ps->image) |
| 312 | return; |
| 313 | |
| 314 | pixman_region32_init(&repaint); |
| 315 | pixman_region32_intersect(&repaint, |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 316 | &ev->transform.boundingbox, damage); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 317 | pixman_region32_subtract(&repaint, &repaint, &ev->clip); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 318 | |
| 319 | if (!pixman_region32_not_empty(&repaint)) |
| 320 | goto out; |
| 321 | |
Derek Foreman | 66951b7 | 2014-09-01 10:33:28 -0500 | [diff] [blame] | 322 | if (output->zoom.active && !zoom_logged) { |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 323 | weston_log("pixman renderer does not support zoom\n"); |
Derek Foreman | 66951b7 | 2014-09-01 10:33:28 -0500 | [diff] [blame] | 324 | zoom_logged = 1; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 325 | } |
| 326 | |
Vasily Khoruzhick | f4a457f | 2013-01-28 22:40:29 +0300 | [diff] [blame] | 327 | /* TODO: Implement repaint_region_complex() using pixman_composite_trapezoids() */ |
Pekka Paalanen | 23d4af5 | 2015-03-04 16:18:26 +0200 | [diff] [blame] | 328 | if (ev->alpha != 1.0 || !view_transformation_is_translation(ev)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 329 | repaint_region(ev, output, &repaint, NULL, PIXMAN_OP_OVER); |
Vasily Khoruzhick | f4a457f | 2013-01-28 22:40:29 +0300 | [diff] [blame] | 330 | } else { |
| 331 | /* blended region is whole surface minus opaque region: */ |
| 332 | pixman_region32_init_rect(&surface_blend, 0, 0, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 333 | ev->surface->width, ev->surface->height); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 334 | pixman_region32_subtract(&surface_blend, &surface_blend, &ev->surface->opaque); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 335 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 336 | if (pixman_region32_not_empty(&ev->surface->opaque)) { |
| 337 | repaint_region(ev, output, &repaint, &ev->surface->opaque, PIXMAN_OP_SRC); |
Vasily Khoruzhick | f4a457f | 2013-01-28 22:40:29 +0300 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | if (pixman_region32_not_empty(&surface_blend)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 341 | repaint_region(ev, output, &repaint, &surface_blend, PIXMAN_OP_OVER); |
Vasily Khoruzhick | f4a457f | 2013-01-28 22:40:29 +0300 | [diff] [blame] | 342 | } |
| 343 | pixman_region32_fini(&surface_blend); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 344 | } |
| 345 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 346 | |
| 347 | out: |
| 348 | pixman_region32_fini(&repaint); |
| 349 | } |
| 350 | static void |
| 351 | repaint_surfaces(struct weston_output *output, pixman_region32_t *damage) |
| 352 | { |
| 353 | struct weston_compositor *compositor = output->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 354 | struct weston_view *view; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 355 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 356 | wl_list_for_each_reverse(view, &compositor->view_list, link) |
| 357 | if (view->plane == &compositor->primary_plane) |
| 358 | draw_view(view, output, damage); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static void |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 362 | copy_to_hw_buffer(struct weston_output *output, pixman_region32_t *region) |
| 363 | { |
| 364 | struct pixman_output_state *po = get_output_state(output); |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 365 | pixman_region32_t output_region; |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 366 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 367 | pixman_region32_init(&output_region); |
| 368 | pixman_region32_copy(&output_region, region); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 369 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 370 | region_global_to_output(output, &output_region); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 371 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 372 | pixman_image_set_clip_region32 (po->hw_buffer, &output_region); |
Ryo Munakata | 389d205 | 2014-09-04 01:56:53 +0900 | [diff] [blame] | 373 | pixman_region32_fini(&output_region); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 374 | |
Alexander Larsson | 1f206b4 | 2013-05-22 14:41:36 +0200 | [diff] [blame] | 375 | pixman_image_composite32(PIXMAN_OP_SRC, |
| 376 | po->shadow_image, /* src */ |
| 377 | NULL /* mask */, |
| 378 | po->hw_buffer, /* dest */ |
| 379 | 0, 0, /* src_x, src_y */ |
| 380 | 0, 0, /* mask_x, mask_y */ |
| 381 | 0, 0, /* dest_x, dest_y */ |
| 382 | pixman_image_get_width (po->hw_buffer), /* width */ |
| 383 | pixman_image_get_height (po->hw_buffer) /* height */); |
| 384 | |
| 385 | pixman_image_set_clip_region32 (po->hw_buffer, NULL); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | static void |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 389 | pixman_renderer_repaint_output(struct weston_output *output, |
| 390 | pixman_region32_t *output_damage) |
| 391 | { |
| 392 | struct pixman_output_state *po = get_output_state(output); |
| 393 | |
| 394 | if (!po->hw_buffer) |
| 395 | return; |
| 396 | |
| 397 | repaint_surfaces(output, output_damage); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 398 | copy_to_hw_buffer(output, output_damage); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 399 | |
| 400 | pixman_region32_copy(&output->previous_damage, output_damage); |
| 401 | wl_signal_emit(&output->frame_signal, output); |
| 402 | |
| 403 | /* Actual flip should be done by caller */ |
| 404 | } |
| 405 | |
| 406 | static void |
| 407 | pixman_renderer_flush_damage(struct weston_surface *surface) |
| 408 | { |
| 409 | /* No-op for pixman renderer */ |
| 410 | } |
| 411 | |
| 412 | static void |
Lubomir Rintel | ddc2b1e | 2013-12-12 12:57:56 +0100 | [diff] [blame] | 413 | buffer_state_handle_buffer_destroy(struct wl_listener *listener, void *data) |
| 414 | { |
| 415 | struct pixman_surface_state *ps; |
| 416 | |
| 417 | ps = container_of(listener, struct pixman_surface_state, |
| 418 | buffer_destroy_listener); |
| 419 | |
| 420 | if (ps->image) { |
| 421 | pixman_image_unref(ps->image); |
| 422 | ps->image = NULL; |
| 423 | } |
| 424 | |
| 425 | ps->buffer_destroy_listener.notify = NULL; |
| 426 | } |
| 427 | |
| 428 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 429 | pixman_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer) |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 430 | { |
| 431 | struct pixman_surface_state *ps = get_surface_state(es); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 432 | struct wl_shm_buffer *shm_buffer; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 433 | pixman_format_code_t pixman_format; |
| 434 | |
| 435 | weston_buffer_reference(&ps->buffer_ref, buffer); |
| 436 | |
Lubomir Rintel | ddc2b1e | 2013-12-12 12:57:56 +0100 | [diff] [blame] | 437 | if (ps->buffer_destroy_listener.notify) { |
| 438 | wl_list_remove(&ps->buffer_destroy_listener.link); |
| 439 | ps->buffer_destroy_listener.notify = NULL; |
| 440 | } |
| 441 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 442 | if (ps->image) { |
| 443 | pixman_image_unref(ps->image); |
| 444 | ps->image = NULL; |
| 445 | } |
| 446 | |
| 447 | if (!buffer) |
| 448 | return; |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 449 | |
| 450 | shm_buffer = wl_shm_buffer_get(buffer->resource); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 451 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 452 | if (! shm_buffer) { |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 453 | weston_log("Pixman renderer supports only SHM buffers\n"); |
| 454 | weston_buffer_reference(&ps->buffer_ref, NULL); |
| 455 | return; |
| 456 | } |
| 457 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 458 | switch (wl_shm_buffer_get_format(shm_buffer)) { |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 459 | case WL_SHM_FORMAT_XRGB8888: |
| 460 | pixman_format = PIXMAN_x8r8g8b8; |
| 461 | break; |
| 462 | case WL_SHM_FORMAT_ARGB8888: |
| 463 | pixman_format = PIXMAN_a8r8g8b8; |
| 464 | break; |
Tomeu Vizoso | 1c1fc29 | 2013-08-06 20:05:56 +0200 | [diff] [blame] | 465 | case WL_SHM_FORMAT_RGB565: |
| 466 | pixman_format = PIXMAN_r5g6b5; |
| 467 | break; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 468 | default: |
| 469 | weston_log("Unsupported SHM buffer format\n"); |
| 470 | weston_buffer_reference(&ps->buffer_ref, NULL); |
| 471 | return; |
| 472 | break; |
| 473 | } |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 474 | |
| 475 | buffer->shm_buffer = shm_buffer; |
| 476 | buffer->width = wl_shm_buffer_get_width(shm_buffer); |
| 477 | buffer->height = wl_shm_buffer_get_height(shm_buffer); |
| 478 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 479 | ps->image = pixman_image_create_bits(pixman_format, |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 480 | buffer->width, buffer->height, |
| 481 | wl_shm_buffer_get_data(shm_buffer), |
| 482 | wl_shm_buffer_get_stride(shm_buffer)); |
Lubomir Rintel | ddc2b1e | 2013-12-12 12:57:56 +0100 | [diff] [blame] | 483 | |
| 484 | ps->buffer_destroy_listener.notify = |
| 485 | buffer_state_handle_buffer_destroy; |
| 486 | wl_signal_add(&buffer->destroy_signal, |
| 487 | &ps->buffer_destroy_listener); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 488 | } |
| 489 | |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 490 | static void |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 491 | pixman_renderer_surface_state_destroy(struct pixman_surface_state *ps) |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 492 | { |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 493 | wl_list_remove(&ps->surface_destroy_listener.link); |
| 494 | wl_list_remove(&ps->renderer_destroy_listener.link); |
Lubomir Rintel | ddc2b1e | 2013-12-12 12:57:56 +0100 | [diff] [blame] | 495 | if (ps->buffer_destroy_listener.notify) { |
| 496 | wl_list_remove(&ps->buffer_destroy_listener.link); |
| 497 | ps->buffer_destroy_listener.notify = NULL; |
| 498 | } |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 499 | |
| 500 | ps->surface->renderer_state = NULL; |
| 501 | |
| 502 | if (ps->image) { |
| 503 | pixman_image_unref(ps->image); |
| 504 | ps->image = NULL; |
| 505 | } |
| 506 | weston_buffer_reference(&ps->buffer_ref, NULL); |
| 507 | free(ps); |
| 508 | } |
| 509 | |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 510 | static void |
| 511 | surface_state_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 512 | { |
| 513 | struct pixman_surface_state *ps; |
| 514 | |
| 515 | ps = container_of(listener, struct pixman_surface_state, |
| 516 | surface_destroy_listener); |
| 517 | |
| 518 | pixman_renderer_surface_state_destroy(ps); |
| 519 | } |
| 520 | |
| 521 | static void |
| 522 | surface_state_handle_renderer_destroy(struct wl_listener *listener, void *data) |
| 523 | { |
| 524 | struct pixman_surface_state *ps; |
| 525 | |
| 526 | ps = container_of(listener, struct pixman_surface_state, |
| 527 | renderer_destroy_listener); |
| 528 | |
| 529 | pixman_renderer_surface_state_destroy(ps); |
| 530 | } |
| 531 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 532 | static int |
| 533 | pixman_renderer_create_surface(struct weston_surface *surface) |
| 534 | { |
| 535 | struct pixman_surface_state *ps; |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 536 | struct pixman_renderer *pr = get_renderer(surface->compositor); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 537 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 538 | ps = zalloc(sizeof *ps); |
| 539 | if (ps == NULL) |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 540 | return -1; |
| 541 | |
| 542 | surface->renderer_state = ps; |
| 543 | |
Ander Conselvan de Oliveira | aa398ae | 2013-10-25 16:26:33 +0300 | [diff] [blame] | 544 | ps->surface = surface; |
| 545 | |
| 546 | ps->surface_destroy_listener.notify = |
| 547 | surface_state_handle_surface_destroy; |
| 548 | wl_signal_add(&surface->destroy_signal, |
| 549 | &ps->surface_destroy_listener); |
| 550 | |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 551 | ps->renderer_destroy_listener.notify = |
| 552 | surface_state_handle_renderer_destroy; |
| 553 | wl_signal_add(&pr->destroy_signal, |
| 554 | &ps->renderer_destroy_listener); |
| 555 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | static void |
| 560 | pixman_renderer_surface_set_color(struct weston_surface *es, |
| 561 | float red, float green, float blue, float alpha) |
| 562 | { |
| 563 | struct pixman_surface_state *ps = get_surface_state(es); |
| 564 | pixman_color_t color; |
| 565 | |
| 566 | color.red = red * 0xffff; |
| 567 | color.green = green * 0xffff; |
| 568 | color.blue = blue * 0xffff; |
| 569 | color.alpha = alpha * 0xffff; |
| 570 | |
| 571 | if (ps->image) { |
| 572 | pixman_image_unref(ps->image); |
| 573 | ps->image = NULL; |
| 574 | } |
| 575 | |
| 576 | ps->image = pixman_image_create_solid_fill(&color); |
| 577 | } |
| 578 | |
| 579 | static void |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 580 | pixman_renderer_destroy(struct weston_compositor *ec) |
| 581 | { |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 582 | struct pixman_renderer *pr = get_renderer(ec); |
| 583 | |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 584 | wl_signal_emit(&pr->destroy_signal, pr); |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 585 | weston_binding_destroy(pr->debug_binding); |
| 586 | free(pr); |
| 587 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 588 | ec->renderer = NULL; |
| 589 | } |
| 590 | |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 591 | static void |
Pekka Paalanen | 6764bbe | 2015-02-11 12:29:56 +0200 | [diff] [blame] | 592 | pixman_renderer_surface_get_content_size(struct weston_surface *surface, |
| 593 | int *width, int *height) |
| 594 | { |
| 595 | struct pixman_surface_state *ps = get_surface_state(surface); |
| 596 | |
| 597 | if (ps->image) { |
| 598 | *width = pixman_image_get_width(ps->image); |
| 599 | *height = pixman_image_get_height(ps->image); |
| 600 | } else { |
| 601 | *width = 0; |
| 602 | *height = 0; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | static int |
| 607 | pixman_renderer_surface_copy_content(struct weston_surface *surface, |
| 608 | void *target, size_t size, |
| 609 | int src_x, int src_y, |
| 610 | int width, int height) |
| 611 | { |
| 612 | const pixman_format_code_t format = PIXMAN_a8b8g8r8; |
| 613 | const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */ |
| 614 | struct pixman_surface_state *ps = get_surface_state(surface); |
| 615 | pixman_image_t *out_buf; |
| 616 | |
| 617 | if (!ps->image) |
| 618 | return -1; |
| 619 | |
| 620 | out_buf = pixman_image_create_bits(format, width, height, |
| 621 | target, width * bytespp); |
| 622 | |
| 623 | pixman_image_set_transform(ps->image, NULL); |
| 624 | pixman_image_composite32(PIXMAN_OP_SRC, |
| 625 | ps->image, /* src */ |
| 626 | NULL, /* mask */ |
| 627 | out_buf, /* dest */ |
| 628 | src_x, src_y, /* src_x, src_y */ |
| 629 | 0, 0, /* mask_x, mask_y */ |
| 630 | 0, 0, /* dest_x, dest_y */ |
| 631 | width, height); |
| 632 | |
| 633 | pixman_image_unref(out_buf); |
| 634 | |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 639 | debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 640 | void *data) |
| 641 | { |
| 642 | struct weston_compositor *ec = data; |
| 643 | struct pixman_renderer *pr = (struct pixman_renderer *) ec->renderer; |
| 644 | |
| 645 | pr->repaint_debug ^= 1; |
| 646 | |
| 647 | if (pr->repaint_debug) { |
| 648 | pixman_color_t red = { |
| 649 | 0x3fff, 0x0000, 0x0000, 0x3fff |
| 650 | }; |
| 651 | |
| 652 | pr->debug_color = pixman_image_create_solid_fill(&red); |
| 653 | } else { |
| 654 | pixman_image_unref(pr->debug_color); |
| 655 | weston_compositor_damage_all(ec); |
| 656 | } |
| 657 | } |
| 658 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 659 | WL_EXPORT int |
| 660 | pixman_renderer_init(struct weston_compositor *ec) |
| 661 | { |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 662 | struct pixman_renderer *renderer; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 663 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 664 | renderer = zalloc(sizeof *renderer); |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 665 | if (renderer == NULL) |
| 666 | return -1; |
| 667 | |
Philipp Brüschweiler | f3e39f9 | 2013-03-08 20:35:39 +0100 | [diff] [blame] | 668 | renderer->repaint_debug = 0; |
| 669 | renderer->debug_color = NULL; |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 670 | renderer->base.read_pixels = pixman_renderer_read_pixels; |
| 671 | renderer->base.repaint_output = pixman_renderer_repaint_output; |
| 672 | renderer->base.flush_damage = pixman_renderer_flush_damage; |
| 673 | renderer->base.attach = pixman_renderer_attach; |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 674 | renderer->base.surface_set_color = pixman_renderer_surface_set_color; |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 675 | renderer->base.destroy = pixman_renderer_destroy; |
Pekka Paalanen | 6764bbe | 2015-02-11 12:29:56 +0200 | [diff] [blame] | 676 | renderer->base.surface_get_content_size = |
| 677 | pixman_renderer_surface_get_content_size; |
| 678 | renderer->base.surface_copy_content = |
| 679 | pixman_renderer_surface_copy_content; |
Ander Conselvan de Oliveira | 8792ef1 | 2013-01-25 15:13:00 +0200 | [diff] [blame] | 680 | ec->renderer = &renderer->base; |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 681 | ec->capabilities |= WESTON_CAP_ROTATION_ANY; |
Pekka Paalanen | 4fc5dd0 | 2013-05-22 18:03:05 +0300 | [diff] [blame] | 682 | ec->capabilities |= WESTON_CAP_CAPTURE_YFLIP; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 683 | |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 684 | renderer->debug_binding = |
| 685 | weston_compositor_add_debug_binding(ec, KEY_R, |
| 686 | debug_binding, ec); |
Tomeu Vizoso | 1c1fc29 | 2013-08-06 20:05:56 +0200 | [diff] [blame] | 687 | |
| 688 | wl_display_add_shm_format(ec->wl_display, WL_SHM_FORMAT_RGB565); |
| 689 | |
Ander Conselvan de Oliveira | adda00e | 2013-10-25 16:26:34 +0300 | [diff] [blame] | 690 | wl_signal_init(&renderer->destroy_signal); |
| 691 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | WL_EXPORT void |
| 696 | pixman_renderer_output_set_buffer(struct weston_output *output, pixman_image_t *buffer) |
| 697 | { |
| 698 | struct pixman_output_state *po = get_output_state(output); |
| 699 | |
| 700 | if (po->hw_buffer) |
| 701 | pixman_image_unref(po->hw_buffer); |
| 702 | po->hw_buffer = buffer; |
| 703 | |
| 704 | if (po->hw_buffer) { |
| 705 | output->compositor->read_format = pixman_image_get_format(po->hw_buffer); |
| 706 | pixman_image_ref(po->hw_buffer); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | WL_EXPORT int |
| 711 | pixman_renderer_output_create(struct weston_output *output) |
| 712 | { |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 713 | struct pixman_output_state *po; |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 714 | int w, h; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 715 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 716 | po = zalloc(sizeof *po); |
| 717 | if (po == NULL) |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 718 | return -1; |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 719 | |
| 720 | /* set shadow image transformation */ |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 721 | w = output->current_mode->width; |
| 722 | h = output->current_mode->height; |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 723 | |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 724 | po->shadow_buffer = malloc(w * h * 4); |
| 725 | |
| 726 | if (!po->shadow_buffer) { |
| 727 | free(po); |
| 728 | return -1; |
| 729 | } |
| 730 | |
| 731 | po->shadow_image = |
| 732 | pixman_image_create_bits(PIXMAN_x8r8g8b8, w, h, |
| 733 | po->shadow_buffer, w * 4); |
| 734 | |
| 735 | if (!po->shadow_image) { |
| 736 | free(po->shadow_buffer); |
| 737 | free(po); |
| 738 | return -1; |
| 739 | } |
| 740 | |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 741 | output->renderer_state = po; |
| 742 | |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | WL_EXPORT void |
| 747 | pixman_renderer_output_destroy(struct weston_output *output) |
| 748 | { |
| 749 | struct pixman_output_state *po = get_output_state(output); |
| 750 | |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 751 | pixman_image_unref(po->shadow_image); |
Ander Conselvan de Oliveira | 23e72b8 | 2013-01-25 15:13:06 +0200 | [diff] [blame] | 752 | |
| 753 | if (po->hw_buffer) |
| 754 | pixman_image_unref(po->hw_buffer); |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 755 | |
Arnaud Vrac | 8e3fe08 | 2014-08-25 20:56:52 +0200 | [diff] [blame] | 756 | free(po->shadow_buffer); |
| 757 | |
| 758 | po->shadow_buffer = NULL; |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 759 | po->shadow_image = NULL; |
Vasily Khoruzhick | 71c2dd3 | 2013-01-07 20:39:49 +0300 | [diff] [blame] | 760 | po->hw_buffer = NULL; |
| 761 | |
| 762 | free(po); |
| 763 | } |