Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 11 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 24 | */ |
| 25 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 26 | #include "config.h" |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 27 | |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 28 | #include <stdint.h> |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 29 | #include <stdlib.h> |
| 30 | |
Pekka Paalanen | 3d5d947 | 2019-03-28 16:28:47 +0200 | [diff] [blame] | 31 | #include <libweston/libweston.h> |
Guillaume Champagne | f1e8fc9 | 2020-01-27 20:14:29 -0500 | [diff] [blame] | 32 | #include "libweston-internal.h" |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 33 | |
John Kåre Alsaker | a95b2d6 | 2012-11-13 19:10:21 +0100 | [diff] [blame] | 34 | static int |
| 35 | noop_renderer_read_pixels(struct weston_output *output, |
| 36 | pixman_format_code_t format, void *pixels, |
| 37 | uint32_t x, uint32_t y, |
| 38 | uint32_t width, uint32_t height) |
| 39 | { |
| 40 | return 0; |
| 41 | } |
| 42 | |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 43 | static void |
| 44 | noop_renderer_repaint_output(struct weston_output *output, |
| 45 | pixman_region32_t *output_damage) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | static void |
| 50 | noop_renderer_flush_damage(struct weston_surface *surface) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 55 | noop_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer) |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 56 | { |
Emilio Pozuelo Monfort | 2c87d94 | 2014-02-07 09:34:44 +0100 | [diff] [blame] | 57 | struct wl_shm_buffer *shm_buffer; |
Emilio Pozuelo Monfort | 2a67902 | 2014-02-07 09:34:45 +0100 | [diff] [blame] | 58 | uint8_t *data; |
| 59 | uint32_t size, i, width, height, stride; |
| 60 | volatile unsigned char unused = 0; /* volatile so it's not optimized out */ |
Emilio Pozuelo Monfort | 2c87d94 | 2014-02-07 09:34:44 +0100 | [diff] [blame] | 61 | |
| 62 | if (!buffer) |
| 63 | return; |
| 64 | |
| 65 | shm_buffer = wl_shm_buffer_get(buffer->resource); |
| 66 | |
| 67 | if (!shm_buffer) { |
| 68 | weston_log("No-op renderer supports only SHM buffers\n"); |
| 69 | return; |
| 70 | } |
| 71 | |
Emilio Pozuelo Monfort | 2a67902 | 2014-02-07 09:34:45 +0100 | [diff] [blame] | 72 | data = wl_shm_buffer_get_data(shm_buffer); |
| 73 | stride = wl_shm_buffer_get_stride(shm_buffer); |
| 74 | width = wl_shm_buffer_get_width(shm_buffer); |
| 75 | height = wl_shm_buffer_get_height(shm_buffer); |
| 76 | size = stride * height; |
| 77 | |
| 78 | /* Access the buffer data to make sure the buffer's client gets killed |
| 79 | * if the buffer size is invalid. This makes the bad_buffer test pass. |
| 80 | * This can be removed if we start reading the buffer contents |
| 81 | * somewhere else, e.g. in repaint_output(). */ |
| 82 | wl_shm_buffer_begin_access(shm_buffer); |
| 83 | for (i = 0; i < size; i++) |
| 84 | unused ^= data[i]; |
| 85 | wl_shm_buffer_end_access(shm_buffer); |
| 86 | |
Emilio Pozuelo Monfort | 2c87d94 | 2014-02-07 09:34:44 +0100 | [diff] [blame] | 87 | buffer->shm_buffer = shm_buffer; |
Emilio Pozuelo Monfort | 2a67902 | 2014-02-07 09:34:45 +0100 | [diff] [blame] | 88 | buffer->width = width; |
| 89 | buffer->height = height; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 90 | } |
| 91 | |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 92 | static void |
| 93 | noop_renderer_surface_set_color(struct weston_surface *surface, |
| 94 | float red, float green, float blue, float alpha) |
| 95 | { |
| 96 | } |
| 97 | |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 98 | static void |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 99 | noop_renderer_destroy(struct weston_compositor *ec) |
| 100 | { |
| 101 | free(ec->renderer); |
| 102 | ec->renderer = NULL; |
| 103 | } |
| 104 | |
| 105 | WL_EXPORT int |
| 106 | noop_renderer_init(struct weston_compositor *ec) |
| 107 | { |
| 108 | struct weston_renderer *renderer; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 109 | |
Pekka Paalanen | 2091874 | 2019-10-02 13:39:41 +0300 | [diff] [blame] | 110 | renderer = zalloc(sizeof *renderer); |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 111 | if (renderer == NULL) |
| 112 | return -1; |
| 113 | |
John Kåre Alsaker | a95b2d6 | 2012-11-13 19:10:21 +0100 | [diff] [blame] | 114 | renderer->read_pixels = noop_renderer_read_pixels; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 115 | renderer->repaint_output = noop_renderer_repaint_output; |
| 116 | renderer->flush_damage = noop_renderer_flush_damage; |
| 117 | renderer->attach = noop_renderer_attach; |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 118 | renderer->surface_set_color = noop_renderer_surface_set_color; |
Vasily Khoruzhick | 52cfd61 | 2013-01-08 19:09:01 +0300 | [diff] [blame] | 119 | renderer->destroy = noop_renderer_destroy; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 120 | ec->renderer = renderer; |
| 121 | |
| 122 | return 0; |
| 123 | } |