blob: 6eed40ee575a61b7d77e4e95b25988b123dc3615 [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
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030028#include <stdint.h>
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020029#include <stdlib.h>
30
31#include "compositor.h"
32
John Kåre Alsakera95b2d62012-11-13 19:10:21 +010033static int
34noop_renderer_read_pixels(struct weston_output *output,
35 pixman_format_code_t format, void *pixels,
36 uint32_t x, uint32_t y,
37 uint32_t width, uint32_t height)
38{
39 return 0;
40}
41
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020042static void
43noop_renderer_repaint_output(struct weston_output *output,
44 pixman_region32_t *output_damage)
45{
46}
47
48static void
49noop_renderer_flush_damage(struct weston_surface *surface)
50{
51}
52
53static void
Jason Ekstrand6bd62942013-06-20 20:38:23 -050054noop_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020055{
Emilio Pozuelo Monfort2c87d942014-02-07 09:34:44 +010056 struct wl_shm_buffer *shm_buffer;
Emilio Pozuelo Monfort2a679022014-02-07 09:34:45 +010057 uint8_t *data;
58 uint32_t size, i, width, height, stride;
59 volatile unsigned char unused = 0; /* volatile so it's not optimized out */
Emilio Pozuelo Monfort2c87d942014-02-07 09:34:44 +010060
61 if (!buffer)
62 return;
63
64 shm_buffer = wl_shm_buffer_get(buffer->resource);
65
66 if (!shm_buffer) {
67 weston_log("No-op renderer supports only SHM buffers\n");
68 return;
69 }
70
Emilio Pozuelo Monfort2a679022014-02-07 09:34:45 +010071 data = wl_shm_buffer_get_data(shm_buffer);
72 stride = wl_shm_buffer_get_stride(shm_buffer);
73 width = wl_shm_buffer_get_width(shm_buffer);
74 height = wl_shm_buffer_get_height(shm_buffer);
75 size = stride * height;
76
77 /* Access the buffer data to make sure the buffer's client gets killed
78 * if the buffer size is invalid. This makes the bad_buffer test pass.
79 * This can be removed if we start reading the buffer contents
80 * somewhere else, e.g. in repaint_output(). */
81 wl_shm_buffer_begin_access(shm_buffer);
82 for (i = 0; i < size; i++)
83 unused ^= data[i];
84 wl_shm_buffer_end_access(shm_buffer);
85
Emilio Pozuelo Monfort2c87d942014-02-07 09:34:44 +010086 buffer->shm_buffer = shm_buffer;
Emilio Pozuelo Monfort2a679022014-02-07 09:34:45 +010087 buffer->width = width;
88 buffer->height = height;
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020089}
90
John Kåre Alsaker878f4492012-11-13 19:10:23 +010091static void
92noop_renderer_surface_set_color(struct weston_surface *surface,
93 float red, float green, float blue, float alpha)
94{
95}
96
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020097static void
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020098noop_renderer_destroy(struct weston_compositor *ec)
99{
100 free(ec->renderer);
101 ec->renderer = NULL;
102}
103
104WL_EXPORT int
105noop_renderer_init(struct weston_compositor *ec)
106{
107 struct weston_renderer *renderer;
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +0200108
109 renderer = malloc(sizeof *renderer);
110 if (renderer == NULL)
111 return -1;
112
John Kåre Alsakera95b2d62012-11-13 19:10:21 +0100113 renderer->read_pixels = noop_renderer_read_pixels;
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +0200114 renderer->repaint_output = noop_renderer_repaint_output;
115 renderer->flush_damage = noop_renderer_flush_damage;
116 renderer->attach = noop_renderer_attach;
John Kåre Alsaker878f4492012-11-13 19:10:23 +0100117 renderer->surface_set_color = noop_renderer_surface_set_color;
Vasily Khoruzhick52cfd612013-01-08 19:09:01 +0300118 renderer->destroy = noop_renderer_destroy;
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +0200119 ec->renderer = renderer;
120
121 return 0;
122}