blob: b6499b82cf122301f86ae01e1a3eda55068db655 [file] [log] [blame]
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +02001/*
2 * Copyright © 2012 Intel Corporation
3 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -07004 * 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 Oliveira11f8d402012-10-29 18:19:24 +020011 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -070012 * 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 Oliveira11f8d402012-10-29 18:19:24 +020024 */
25
Daniel Stonec228e232013-05-22 18:03:19 +030026#include "config.h"
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020027
28#include <stdlib.h>
29
30#include "compositor.h"
31
John Kåre Alsakera95b2d62012-11-13 19:10:21 +010032static int
33noop_renderer_read_pixels(struct weston_output *output,
34 pixman_format_code_t format, void *pixels,
35 uint32_t x, uint32_t y,
36 uint32_t width, uint32_t height)
37{
38 return 0;
39}
40
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020041static void
42noop_renderer_repaint_output(struct weston_output *output,
43 pixman_region32_t *output_damage)
44{
45}
46
47static void
48noop_renderer_flush_damage(struct weston_surface *surface)
49{
50}
51
52static void
Jason Ekstrand6bd62942013-06-20 20:38:23 -050053noop_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020054{
Emilio Pozuelo Monfort2c87d942014-02-07 09:34:44 +010055 struct wl_shm_buffer *shm_buffer;
Emilio Pozuelo Monfort2a679022014-02-07 09:34:45 +010056 uint8_t *data;
57 uint32_t size, i, width, height, stride;
58 volatile unsigned char unused = 0; /* volatile so it's not optimized out */
Emilio Pozuelo Monfort2c87d942014-02-07 09:34:44 +010059
60 if (!buffer)
61 return;
62
63 shm_buffer = wl_shm_buffer_get(buffer->resource);
64
65 if (!shm_buffer) {
66 weston_log("No-op renderer supports only SHM buffers\n");
67 return;
68 }
69
Emilio Pozuelo Monfort2a679022014-02-07 09:34:45 +010070 data = wl_shm_buffer_get_data(shm_buffer);
71 stride = wl_shm_buffer_get_stride(shm_buffer);
72 width = wl_shm_buffer_get_width(shm_buffer);
73 height = wl_shm_buffer_get_height(shm_buffer);
74 size = stride * height;
75
76 /* Access the buffer data to make sure the buffer's client gets killed
77 * if the buffer size is invalid. This makes the bad_buffer test pass.
78 * This can be removed if we start reading the buffer contents
79 * somewhere else, e.g. in repaint_output(). */
80 wl_shm_buffer_begin_access(shm_buffer);
81 for (i = 0; i < size; i++)
82 unused ^= data[i];
83 wl_shm_buffer_end_access(shm_buffer);
84
Emilio Pozuelo Monfort2c87d942014-02-07 09:34:44 +010085 buffer->shm_buffer = shm_buffer;
Emilio Pozuelo Monfort2a679022014-02-07 09:34:45 +010086 buffer->width = width;
87 buffer->height = height;
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020088}
89
John Kåre Alsaker878f4492012-11-13 19:10:23 +010090static void
91noop_renderer_surface_set_color(struct weston_surface *surface,
92 float red, float green, float blue, float alpha)
93{
94}
95
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020096static void
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020097noop_renderer_destroy(struct weston_compositor *ec)
98{
99 free(ec->renderer);
100 ec->renderer = NULL;
101}
102
103WL_EXPORT int
104noop_renderer_init(struct weston_compositor *ec)
105{
106 struct weston_renderer *renderer;
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +0200107
108 renderer = malloc(sizeof *renderer);
109 if (renderer == NULL)
110 return -1;
111
John Kåre Alsakera95b2d62012-11-13 19:10:21 +0100112 renderer->read_pixels = noop_renderer_read_pixels;
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +0200113 renderer->repaint_output = noop_renderer_repaint_output;
114 renderer->flush_damage = noop_renderer_flush_damage;
115 renderer->attach = noop_renderer_attach;
John Kåre Alsaker878f4492012-11-13 19:10:23 +0100116 renderer->surface_set_color = noop_renderer_surface_set_color;
Vasily Khoruzhick52cfd612013-01-08 19:09:01 +0300117 renderer->destroy = noop_renderer_destroy;
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +0200118 ec->renderer = renderer;
119
120 return 0;
121}