1 /*
2 * Copyright © 2012 Intel Corporation
3 *
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:
11 *
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.
24 */
25
26 #include "config.h"
27
28 #include <stdint.h>
29 #include <stdlib.h>
30
31 #include <libweston/libweston.h>
32 #include "libweston-internal.h"
33
34 static int
noop_renderer_read_pixels(struct weston_output * output,pixman_format_code_t format,void * pixels,uint32_t x,uint32_t y,uint32_t width,uint32_t height)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
43 static void
noop_renderer_repaint_output(struct weston_output * output,pixman_region32_t * output_damage)44 noop_renderer_repaint_output(struct weston_output *output,
45 pixman_region32_t *output_damage)
46 {
47 }
48
49 static void
noop_renderer_flush_damage(struct weston_surface * surface)50 noop_renderer_flush_damage(struct weston_surface *surface)
51 {
52 }
53
54 static void
noop_renderer_attach(struct weston_surface * es,struct weston_buffer * buffer)55 noop_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
56 {
57 struct wl_shm_buffer *shm_buffer;
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 */
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
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
87 buffer->shm_buffer = shm_buffer;
88 buffer->width = width;
89 buffer->height = height;
90 }
91
92 static void
noop_renderer_surface_set_color(struct weston_surface * surface,float red,float green,float blue,float alpha)93 noop_renderer_surface_set_color(struct weston_surface *surface,
94 float red, float green, float blue, float alpha)
95 {
96 }
97
98 static void
noop_renderer_destroy(struct weston_compositor * ec)99 noop_renderer_destroy(struct weston_compositor *ec)
100 {
101 free(ec->renderer);
102 ec->renderer = NULL;
103 }
104
105 WL_EXPORT int
noop_renderer_init(struct weston_compositor * ec)106 noop_renderer_init(struct weston_compositor *ec)
107 {
108 struct weston_renderer *renderer;
109
110 renderer = zalloc(sizeof *renderer);
111 if (renderer == NULL)
112 return -1;
113
114 renderer->read_pixels = noop_renderer_read_pixels;
115 renderer->repaint_output = noop_renderer_repaint_output;
116 renderer->flush_damage = noop_renderer_flush_damage;
117 renderer->attach = noop_renderer_attach;
118 renderer->surface_set_color = noop_renderer_surface_set_color;
119 renderer->destroy = noop_renderer_destroy;
120 ec->renderer = renderer;
121
122 return 0;
123 }
124