Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 23 | #include "config.h" |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 24 | |
| 25 | #include <stdlib.h> |
| 26 | |
| 27 | #include "compositor.h" |
| 28 | |
John Kåre Alsaker | a95b2d6 | 2012-11-13 19:10:21 +0100 | [diff] [blame] | 29 | static int |
| 30 | noop_renderer_read_pixels(struct weston_output *output, |
| 31 | pixman_format_code_t format, void *pixels, |
| 32 | uint32_t x, uint32_t y, |
| 33 | uint32_t width, uint32_t height) |
| 34 | { |
| 35 | return 0; |
| 36 | } |
| 37 | |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 38 | static void |
| 39 | noop_renderer_repaint_output(struct weston_output *output, |
| 40 | pixman_region32_t *output_damage) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | static void |
| 45 | noop_renderer_flush_damage(struct weston_surface *surface) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 50 | 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] | 51 | { |
Emilio Pozuelo Monfort | 2c87d94 | 2014-02-07 09:34:44 +0100 | [diff] [blame] | 52 | struct wl_shm_buffer *shm_buffer; |
Emilio Pozuelo Monfort | 2a67902 | 2014-02-07 09:34:45 +0100 | [diff] [blame^] | 53 | uint8_t *data; |
| 54 | uint32_t size, i, width, height, stride; |
| 55 | 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] | 56 | |
| 57 | if (!buffer) |
| 58 | return; |
| 59 | |
| 60 | shm_buffer = wl_shm_buffer_get(buffer->resource); |
| 61 | |
| 62 | if (!shm_buffer) { |
| 63 | weston_log("No-op renderer supports only SHM buffers\n"); |
| 64 | return; |
| 65 | } |
| 66 | |
Emilio Pozuelo Monfort | 2a67902 | 2014-02-07 09:34:45 +0100 | [diff] [blame^] | 67 | data = wl_shm_buffer_get_data(shm_buffer); |
| 68 | stride = wl_shm_buffer_get_stride(shm_buffer); |
| 69 | width = wl_shm_buffer_get_width(shm_buffer); |
| 70 | height = wl_shm_buffer_get_height(shm_buffer); |
| 71 | size = stride * height; |
| 72 | |
| 73 | /* Access the buffer data to make sure the buffer's client gets killed |
| 74 | * if the buffer size is invalid. This makes the bad_buffer test pass. |
| 75 | * This can be removed if we start reading the buffer contents |
| 76 | * somewhere else, e.g. in repaint_output(). */ |
| 77 | wl_shm_buffer_begin_access(shm_buffer); |
| 78 | for (i = 0; i < size; i++) |
| 79 | unused ^= data[i]; |
| 80 | wl_shm_buffer_end_access(shm_buffer); |
| 81 | |
Emilio Pozuelo Monfort | 2c87d94 | 2014-02-07 09:34:44 +0100 | [diff] [blame] | 82 | buffer->shm_buffer = shm_buffer; |
Emilio Pozuelo Monfort | 2a67902 | 2014-02-07 09:34:45 +0100 | [diff] [blame^] | 83 | buffer->width = width; |
| 84 | buffer->height = height; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 85 | } |
| 86 | |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 87 | static void |
| 88 | noop_renderer_surface_set_color(struct weston_surface *surface, |
| 89 | float red, float green, float blue, float alpha) |
| 90 | { |
| 91 | } |
| 92 | |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 93 | static void |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 94 | noop_renderer_destroy(struct weston_compositor *ec) |
| 95 | { |
| 96 | free(ec->renderer); |
| 97 | ec->renderer = NULL; |
| 98 | } |
| 99 | |
| 100 | WL_EXPORT int |
| 101 | noop_renderer_init(struct weston_compositor *ec) |
| 102 | { |
| 103 | struct weston_renderer *renderer; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 104 | |
| 105 | renderer = malloc(sizeof *renderer); |
| 106 | if (renderer == NULL) |
| 107 | return -1; |
| 108 | |
John Kåre Alsaker | a95b2d6 | 2012-11-13 19:10:21 +0100 | [diff] [blame] | 109 | renderer->read_pixels = noop_renderer_read_pixels; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 110 | renderer->repaint_output = noop_renderer_repaint_output; |
| 111 | renderer->flush_damage = noop_renderer_flush_damage; |
| 112 | renderer->attach = noop_renderer_attach; |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 113 | renderer->surface_set_color = noop_renderer_surface_set_color; |
Vasily Khoruzhick | 52cfd61 | 2013-01-08 19:09:01 +0300 | [diff] [blame] | 114 | renderer->destroy = noop_renderer_destroy; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 115 | ec->renderer = renderer; |
| 116 | |
| 117 | return 0; |
| 118 | } |