blob: d86e7f0b172ce6ea8360958016077e644d18e8f1 [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
Pekka Paalanen3d5d9472019-03-28 16:28:47 +020031#include <libweston/libweston.h>
Guillaume Champagnef1e8fc92020-01-27 20:14:29 -050032#include "libweston-internal.h"
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020033
John Kåre Alsakera95b2d62012-11-13 19:10:21 +010034static int
35noop_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 Oliveira11f8d402012-10-29 18:19:24 +020043static void
44noop_renderer_repaint_output(struct weston_output *output,
45 pixman_region32_t *output_damage)
46{
47}
48
49static void
50noop_renderer_flush_damage(struct weston_surface *surface)
51{
52}
53
54static void
Jason Ekstrand6bd62942013-06-20 20:38:23 -050055noop_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020056{
Emilio Pozuelo Monfort2c87d942014-02-07 09:34:44 +010057 struct wl_shm_buffer *shm_buffer;
Emilio Pozuelo Monfort2a679022014-02-07 09:34:45 +010058 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 Monfort2c87d942014-02-07 09:34:44 +010061
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 Monfort2a679022014-02-07 09:34:45 +010072 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 Monfort2c87d942014-02-07 09:34:44 +010087 buffer->shm_buffer = shm_buffer;
Emilio Pozuelo Monfort2a679022014-02-07 09:34:45 +010088 buffer->width = width;
89 buffer->height = height;
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020090}
91
John Kåre Alsaker878f4492012-11-13 19:10:23 +010092static void
93noop_renderer_surface_set_color(struct weston_surface *surface,
94 float red, float green, float blue, float alpha)
95{
96}
97
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020098static void
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +020099noop_renderer_destroy(struct weston_compositor *ec)
100{
101 free(ec->renderer);
102 ec->renderer = NULL;
103}
104
105WL_EXPORT int
106noop_renderer_init(struct weston_compositor *ec)
107{
108 struct weston_renderer *renderer;
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +0200109
Pekka Paalanen20918742019-10-02 13:39:41 +0300110 renderer = zalloc(sizeof *renderer);
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +0200111 if (renderer == NULL)
112 return -1;
113
John Kåre Alsakera95b2d62012-11-13 19:10:21 +0100114 renderer->read_pixels = noop_renderer_read_pixels;
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +0200115 renderer->repaint_output = noop_renderer_repaint_output;
116 renderer->flush_damage = noop_renderer_flush_damage;
117 renderer->attach = noop_renderer_attach;
John Kåre Alsaker878f4492012-11-13 19:10:23 +0100118 renderer->surface_set_color = noop_renderer_surface_set_color;
Vasily Khoruzhick52cfd612013-01-08 19:09:01 +0300119 renderer->destroy = noop_renderer_destroy;
Ander Conselvan de Oliveira11f8d402012-10-29 18:19:24 +0200120 ec->renderer = renderer;
121
122 return 0;
123}