2018-03-24 18:30:28 -04:00
|
|
|
#include <assert.h>
|
2017-06-08 15:52:42 -04:00
|
|
|
#include <stdbool.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <stdlib.h>
|
2019-05-15 23:52:13 +12:00
|
|
|
#include <pixman.h>
|
2018-09-01 19:27:18 +02:00
|
|
|
#include <wlr/render/gles2.h>
|
2017-06-08 15:52:42 -04:00
|
|
|
#include <wlr/render/interface.h>
|
2018-03-19 23:16:29 +01:00
|
|
|
#include <wlr/render/wlr_renderer.h>
|
2019-05-15 23:52:13 +12:00
|
|
|
#include <wlr/types/wlr_compositor.h>
|
2018-09-01 19:27:18 +02:00
|
|
|
#include <wlr/types/wlr_linux_dmabuf_v1.h>
|
2018-03-15 19:31:02 +01:00
|
|
|
#include <wlr/types/wlr_matrix.h>
|
2018-04-20 23:58:30 +01:00
|
|
|
#include <wlr/util/log.h>
|
2018-04-26 00:11:36 +01:00
|
|
|
#include "util/signal.h"
|
2017-06-08 15:52:42 -04:00
|
|
|
|
2017-08-14 08:37:50 -04:00
|
|
|
void wlr_renderer_init(struct wlr_renderer *renderer,
|
2018-03-20 19:14:33 +01:00
|
|
|
const struct wlr_renderer_impl *impl) {
|
2018-03-24 18:30:28 -04:00
|
|
|
assert(impl->begin);
|
|
|
|
|
assert(impl->clear);
|
|
|
|
|
assert(impl->scissor);
|
|
|
|
|
assert(impl->render_texture_with_matrix);
|
2018-03-26 19:13:13 -04:00
|
|
|
assert(impl->render_quad_with_matrix);
|
|
|
|
|
assert(impl->render_ellipse_with_matrix);
|
2018-03-24 18:30:28 -04:00
|
|
|
assert(impl->formats);
|
|
|
|
|
assert(impl->format_supported);
|
|
|
|
|
assert(impl->texture_from_pixels);
|
2017-08-14 08:37:50 -04:00
|
|
|
renderer->impl = impl;
|
2018-04-26 00:11:36 +01:00
|
|
|
|
|
|
|
|
wl_signal_init(&renderer->events.destroy);
|
2017-06-08 15:52:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wlr_renderer_destroy(struct wlr_renderer *r) {
|
2018-06-30 11:04:17 +09:00
|
|
|
if (!r) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-04-26 00:11:36 +01:00
|
|
|
wlr_signal_emit_safe(&r->events.destroy, r);
|
|
|
|
|
|
2018-06-30 11:04:17 +09:00
|
|
|
if (r->impl && r->impl->destroy) {
|
2017-08-14 08:37:50 -04:00
|
|
|
r->impl->destroy(r);
|
2017-08-14 16:16:20 +02:00
|
|
|
} else {
|
|
|
|
|
free(r);
|
2017-08-14 08:37:50 -04:00
|
|
|
}
|
2017-06-08 15:52:42 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-20 23:10:42 +01:00
|
|
|
void wlr_renderer_begin(struct wlr_renderer *r, int width, int height) {
|
|
|
|
|
r->impl->begin(r, width, height);
|
2017-06-08 15:52:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wlr_renderer_end(struct wlr_renderer *r) {
|
2018-03-24 18:30:28 -04:00
|
|
|
if (r->impl->end) {
|
|
|
|
|
r->impl->end(r);
|
|
|
|
|
}
|
2017-06-08 15:52:42 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-15 11:10:56 +01:00
|
|
|
void wlr_renderer_clear(struct wlr_renderer *r, const float color[static 4]) {
|
2018-02-03 09:32:02 +01:00
|
|
|
r->impl->clear(r, color);
|
2018-01-22 16:42:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box) {
|
|
|
|
|
r->impl->scissor(r, box);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-15 19:31:02 +01:00
|
|
|
bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture,
|
|
|
|
|
const float projection[static 9], int x, int y, float alpha) {
|
2018-03-26 19:13:13 -04:00
|
|
|
struct wlr_box box = { .x = x, .y = y };
|
|
|
|
|
wlr_texture_get_size(texture, &box.width, &box.height);
|
2018-03-24 18:30:28 -04:00
|
|
|
|
2018-03-26 12:41:51 -04:00
|
|
|
float matrix[9];
|
|
|
|
|
wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
|
|
|
|
|
projection);
|
2018-03-15 19:31:02 +01:00
|
|
|
|
2018-03-26 12:41:51 -04:00
|
|
|
return wlr_render_texture_with_matrix(r, texture, matrix, alpha);
|
2018-03-15 19:31:02 +01:00
|
|
|
}
|
|
|
|
|
|
2018-03-15 15:33:58 +01:00
|
|
|
bool wlr_render_texture_with_matrix(struct wlr_renderer *r,
|
|
|
|
|
struct wlr_texture *texture, const float matrix[static 9],
|
2018-03-15 11:10:56 +01:00
|
|
|
float alpha) {
|
2018-03-15 15:33:58 +01:00
|
|
|
return r->impl->render_texture_with_matrix(r, texture, matrix, alpha);
|
2017-06-08 15:52:42 -04:00
|
|
|
}
|
2017-06-15 15:31:13 -04:00
|
|
|
|
2018-03-26 12:41:51 -04:00
|
|
|
void wlr_render_rect(struct wlr_renderer *r, const struct wlr_box *box,
|
|
|
|
|
const float color[static 4], const float projection[static 9]) {
|
|
|
|
|
float matrix[9];
|
|
|
|
|
wlr_matrix_project_box(matrix, box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
|
|
|
|
|
projection);
|
|
|
|
|
|
|
|
|
|
wlr_render_quad_with_matrix(r, color, matrix);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wlr_render_quad_with_matrix(struct wlr_renderer *r,
|
2018-03-15 15:33:58 +01:00
|
|
|
const float color[static 4], const float matrix[static 9]) {
|
2018-03-26 12:41:51 -04:00
|
|
|
r->impl->render_quad_with_matrix(r, color, matrix);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wlr_render_ellipse(struct wlr_renderer *r, const struct wlr_box *box,
|
|
|
|
|
const float color[static 4], const float projection[static 9]) {
|
|
|
|
|
float matrix[9];
|
|
|
|
|
wlr_matrix_project_box(matrix, box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
|
|
|
|
|
projection);
|
|
|
|
|
|
|
|
|
|
wlr_render_ellipse_with_matrix(r, color, matrix);
|
2017-06-15 15:31:13 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-26 12:41:51 -04:00
|
|
|
void wlr_render_ellipse_with_matrix(struct wlr_renderer *r,
|
2018-03-15 15:33:58 +01:00
|
|
|
const float color[static 4], const float matrix[static 9]) {
|
2018-03-26 12:41:51 -04:00
|
|
|
r->impl->render_ellipse_with_matrix(r, color, matrix);
|
2017-06-15 15:31:13 -04:00
|
|
|
}
|
2017-06-22 16:32:47 -04:00
|
|
|
|
|
|
|
|
const enum wl_shm_format *wlr_renderer_get_formats(
|
|
|
|
|
struct wlr_renderer *r, size_t *len) {
|
2017-08-14 08:37:50 -04:00
|
|
|
return r->impl->formats(r, len);
|
2017-06-22 16:32:47 -04:00
|
|
|
}
|
2017-08-10 22:15:37 -04:00
|
|
|
|
2018-03-24 18:30:28 -04:00
|
|
|
bool wlr_renderer_resource_is_wl_drm_buffer(struct wlr_renderer *r,
|
|
|
|
|
struct wl_resource *resource) {
|
|
|
|
|
if (!r->impl->resource_is_wl_drm_buffer) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return r->impl->resource_is_wl_drm_buffer(r, resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wlr_renderer_wl_drm_buffer_get_size(struct wlr_renderer *r,
|
|
|
|
|
struct wl_resource *buffer, int *width, int *height) {
|
|
|
|
|
if (!r->impl->wl_drm_buffer_get_size) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return r->impl->wl_drm_buffer_get_size(r, buffer, width, height);
|
2017-08-10 22:15:37 -04:00
|
|
|
}
|
2017-10-08 02:11:56 +02:00
|
|
|
|
2019-04-01 19:17:23 +03:00
|
|
|
const struct wlr_drm_format_set *wlr_renderer_get_dmabuf_formats(
|
|
|
|
|
struct wlr_renderer *r) {
|
2018-04-08 11:00:56 -04:00
|
|
|
if (!r->impl->get_dmabuf_formats) {
|
2019-04-01 19:17:23 +03:00
|
|
|
return NULL;
|
2018-04-08 11:00:56 -04:00
|
|
|
}
|
2019-04-01 19:17:23 +03:00
|
|
|
return r->impl->get_dmabuf_formats(r);
|
2018-04-08 11:00:56 -04:00
|
|
|
}
|
|
|
|
|
|
2018-01-23 22:06:54 +01:00
|
|
|
bool wlr_renderer_read_pixels(struct wlr_renderer *r, enum wl_shm_format fmt,
|
2018-06-23 14:02:43 +01:00
|
|
|
uint32_t *flags, uint32_t stride, uint32_t width, uint32_t height,
|
2018-01-23 22:06:54 +01:00
|
|
|
uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y,
|
|
|
|
|
void *data) {
|
2018-03-24 18:30:28 -04:00
|
|
|
if (!r->impl->read_pixels) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-06-23 14:02:43 +01:00
|
|
|
return r->impl->read_pixels(r, fmt, flags, stride, width, height,
|
|
|
|
|
src_x, src_y, dst_x, dst_y, data);
|
2018-01-23 22:06:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool wlr_renderer_format_supported(struct wlr_renderer *r,
|
|
|
|
|
enum wl_shm_format fmt) {
|
|
|
|
|
return r->impl->format_supported(r, fmt);
|
2017-10-08 02:11:56 +02:00
|
|
|
}
|
2018-04-20 23:58:30 +01:00
|
|
|
|
2019-05-15 23:52:13 +12:00
|
|
|
struct buffer {
|
|
|
|
|
struct wlr_buffer base;
|
|
|
|
|
struct wl_list link;
|
|
|
|
|
|
|
|
|
|
bool released;
|
|
|
|
|
struct wlr_texture *texture;
|
|
|
|
|
|
|
|
|
|
struct wl_listener resource_destroy;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void buffer_resource_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
|
struct buffer *buf = wl_container_of(listener, buf, resource_destroy);
|
|
|
|
|
|
|
|
|
|
buf->base.resource = NULL;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* At this point, if the wl_buffer comes from a dmabuf-based buffer, we
|
|
|
|
|
* still haven't released it (i.e. we'll read it in the future) but the
|
|
|
|
|
* client destroyed it. Reading the texture itself should be fine
|
|
|
|
|
* because we still hold a reference to the dmabuf via the texture.
|
|
|
|
|
* However the client could decide to re-use the same dmabuf for
|
|
|
|
|
* something else, in which case we'll read garbage. We decide to
|
|
|
|
|
* accept this risk.
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct wlr_buffer *create_buffer(struct wlr_renderer *renderer,
|
|
|
|
|
struct wl_resource *res) {
|
|
|
|
|
struct buffer *buf = calloc(1, sizeof(*buf));
|
|
|
|
|
if (!buf) {
|
|
|
|
|
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
|
|
|
|
wl_resource_post_no_memory(res);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wl_shm_buffer *shm = wl_shm_buffer_get(res);
|
|
|
|
|
if (shm) {
|
|
|
|
|
enum wl_shm_format fmt = wl_shm_buffer_get_format(shm);
|
|
|
|
|
int32_t stride = wl_shm_buffer_get_stride(shm);
|
|
|
|
|
int32_t width = wl_shm_buffer_get_width(shm);
|
|
|
|
|
int32_t height = wl_shm_buffer_get_height(shm);
|
|
|
|
|
|
|
|
|
|
wl_shm_buffer_begin_access(shm);
|
|
|
|
|
void *data = wl_shm_buffer_get_data(shm);
|
|
|
|
|
buf->texture = wlr_texture_from_pixels(renderer, fmt, stride,
|
|
|
|
|
width, height, data);
|
|
|
|
|
wl_shm_buffer_end_access(shm);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We have uploaded the data, we don't need to access the
|
|
|
|
|
* wl_buffer anymore
|
|
|
|
|
*/
|
|
|
|
|
wl_buffer_send_release(res);
|
|
|
|
|
buf->released = true;
|
|
|
|
|
buf->base.protocol = "wl_shm";
|
|
|
|
|
} else if (wlr_renderer_resource_is_wl_drm_buffer(renderer, res)) {
|
|
|
|
|
buf->texture = wlr_texture_from_wl_drm(renderer, res);
|
|
|
|
|
buf->base.protocol = "egl";
|
|
|
|
|
} else if (wlr_dmabuf_v1_resource_is_buffer(res)) {
|
|
|
|
|
struct wlr_dmabuf_v1_buffer *dmabuf =
|
|
|
|
|
wlr_dmabuf_v1_buffer_from_buffer_resource(res);
|
|
|
|
|
buf->texture = wlr_texture_from_dmabuf(renderer, &dmabuf->attributes);
|
|
|
|
|
buf->base.protocol = "zwp_linux_dmabuf_v1";
|
|
|
|
|
} else {
|
|
|
|
|
wlr_log(WLR_ERROR, "Cannot upload texture: unknown buffer type");
|
|
|
|
|
|
|
|
|
|
// Instead of just logging the error, also disconnect the client with a
|
|
|
|
|
// fatal protocol error so that it's clear something went wrong.
|
|
|
|
|
wl_resource_post_error(res, 0, "unknown buffer type");
|
|
|
|
|
free(buf);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!buf->texture) {
|
|
|
|
|
wlr_log(WLR_ERROR, "Failed to create texture");
|
|
|
|
|
wl_resource_post_error(res, 0, "failed to use buffer");
|
|
|
|
|
free(buf);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
|
wlr_texture_get_size(buf->texture, &width, &height);
|
|
|
|
|
buf->base.width = width;
|
|
|
|
|
buf->base.height = height;
|
|
|
|
|
buf->base.ref_cnt = 1;
|
|
|
|
|
|
|
|
|
|
return &buf->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct wlr_buffer *buffer_ref(struct wlr_buffer *buffer) {
|
|
|
|
|
assert(buffer);
|
|
|
|
|
++buffer->ref_cnt;
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void buffer_unref(struct wlr_buffer *buffer_base) {
|
|
|
|
|
struct buffer *buffer = wl_container_of(buffer_base, buffer, base);
|
|
|
|
|
assert(buffer->base.ref_cnt > 0);
|
|
|
|
|
|
|
|
|
|
if (--buffer->base.ref_cnt > 0) {
|
2018-04-20 23:58:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-15 23:52:13 +12:00
|
|
|
if (buffer->base.resource) {
|
|
|
|
|
if (!buffer->released) {
|
|
|
|
|
wl_buffer_send_release(buffer->base.resource);
|
|
|
|
|
}
|
|
|
|
|
wl_list_remove(&buffer->resource_destroy.link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wlr_texture_destroy(buffer->texture);
|
|
|
|
|
free(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct wlr_buffer *buffer_create(void *userdata,
|
|
|
|
|
struct wlr_buffer *buffer_base, pixman_region32_t *buffer_damage,
|
|
|
|
|
struct wl_resource *res) {
|
|
|
|
|
struct wlr_renderer *renderer = userdata;
|
|
|
|
|
struct buffer *buffer = wl_container_of(buffer_base, buffer, base);
|
|
|
|
|
|
|
|
|
|
if (!buffer) {
|
|
|
|
|
return create_buffer(renderer, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The old buffer is still being used somewhere else, so we cannot
|
|
|
|
|
* change/reuse it.
|
|
|
|
|
*/
|
|
|
|
|
if (buffer->base.ref_cnt != 1) {
|
|
|
|
|
buffer_unref(&buffer->base);
|
|
|
|
|
return create_buffer(renderer, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Any kind of buffer sharing only happens with wl_shm.
|
|
|
|
|
* dmabuf-based textures are cheap to create and aren't modifiable.
|
|
|
|
|
*/
|
|
|
|
|
struct wl_shm_buffer *old_shm = wl_shm_buffer_get(buffer->base.resource);
|
|
|
|
|
struct wl_shm_buffer *new_shm = wl_shm_buffer_get(res);
|
|
|
|
|
if (!old_shm || !new_shm) {
|
|
|
|
|
buffer_unref(&buffer->base);
|
|
|
|
|
return create_buffer(renderer, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We can't change the shm format.
|
|
|
|
|
*/
|
|
|
|
|
enum wl_shm_format old_fmt = wl_shm_buffer_get_format(old_shm);
|
|
|
|
|
enum wl_shm_format new_fmt = wl_shm_buffer_get_format(new_shm);
|
|
|
|
|
if (old_fmt != new_fmt) {
|
|
|
|
|
buffer_unref(&buffer->base);
|
|
|
|
|
return create_buffer(renderer, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We can't change the dimensions.
|
|
|
|
|
*/
|
|
|
|
|
int32_t stride = wl_shm_buffer_get_stride(new_shm);
|
|
|
|
|
int32_t width = wl_shm_buffer_get_width(new_shm);
|
|
|
|
|
int32_t height = wl_shm_buffer_get_height(new_shm);
|
|
|
|
|
int old_width, old_height;
|
|
|
|
|
wlr_texture_get_size(buffer->texture, &old_width, &old_height);
|
|
|
|
|
if (width != old_width || height != old_height) {
|
|
|
|
|
buffer_unref(&buffer->base);
|
|
|
|
|
return create_buffer(renderer, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_shm_buffer_begin_access(new_shm);
|
|
|
|
|
void *data = wl_shm_buffer_get_data(new_shm);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Apply damage to buffer.
|
|
|
|
|
*/
|
|
|
|
|
pixman_region32_t damage;
|
|
|
|
|
pixman_region32_init_rect(&damage, 0, 0, width, height);
|
|
|
|
|
pixman_region32_intersect(&damage, &damage, buffer_damage);
|
|
|
|
|
int n;
|
|
|
|
|
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &n);
|
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
|
pixman_box32_t *r = &rects[i];
|
|
|
|
|
if (!wlr_texture_write_pixels(buffer->texture, stride,
|
|
|
|
|
r->x2 - r->x1, r->y2 - r->y1, r->x1, r->y1,
|
|
|
|
|
r->x1, r->y1, data)) {
|
|
|
|
|
wlr_log(WLR_ERROR, "Failed to write pixels");
|
|
|
|
|
wl_resource_post_error(res, 0, "failed to use buffer");
|
|
|
|
|
buffer_unref(&buffer->base);
|
|
|
|
|
wl_shm_buffer_end_access(new_shm);
|
|
|
|
|
pixman_region32_fini(&damage);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_shm_buffer_end_access(new_shm);
|
|
|
|
|
pixman_region32_fini(&damage);
|
|
|
|
|
/*
|
|
|
|
|
* We've copied the data into a local GPU buffer, so we don't need to
|
|
|
|
|
* hold onto the wl_buffer anymore.
|
|
|
|
|
*/
|
|
|
|
|
wl_buffer_send_release(res);
|
|
|
|
|
|
|
|
|
|
wl_list_remove(&buffer->resource_destroy.link);
|
|
|
|
|
wl_resource_add_destroy_listener(res, &buffer->resource_destroy);
|
|
|
|
|
buffer->resource_destroy.notify = buffer_resource_destroy;
|
|
|
|
|
|
|
|
|
|
buffer->base.resource = res;
|
|
|
|
|
buffer->released = true;
|
|
|
|
|
|
|
|
|
|
return &buffer->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const struct wlr_compositor_buffer_impl buffer_impl = {
|
|
|
|
|
.create = buffer_create,
|
|
|
|
|
.ref = buffer_ref,
|
|
|
|
|
.unref = buffer_unref,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void wlr_renderer_set_compositor(struct wlr_renderer *renderer,
|
|
|
|
|
struct wlr_compositor *comp) {
|
|
|
|
|
assert(renderer);
|
|
|
|
|
assert(comp);
|
|
|
|
|
|
|
|
|
|
struct wl_display *display = comp->display;
|
|
|
|
|
|
2018-04-20 23:58:30 +01:00
|
|
|
size_t len;
|
2019-05-15 23:52:13 +12:00
|
|
|
const enum wl_shm_format *formats = wlr_renderer_get_formats(renderer, &len);
|
2018-04-20 23:58:30 +01:00
|
|
|
if (formats == NULL) {
|
2018-07-09 22:49:54 +01:00
|
|
|
wlr_log(WLR_ERROR, "Failed to initialize shm: cannot get formats");
|
2018-04-20 23:58:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < len; ++i) {
|
2018-05-21 19:07:08 +01:00
|
|
|
// These formats are already added by default
|
2018-04-21 14:31:52 +01:00
|
|
|
if (formats[i] != WL_SHM_FORMAT_ARGB8888 &&
|
|
|
|
|
formats[i] != WL_SHM_FORMAT_XRGB8888) {
|
2019-05-15 23:52:13 +12:00
|
|
|
wl_display_add_shm_format(display, formats[i]);
|
2018-04-21 14:31:52 +01:00
|
|
|
}
|
2018-04-20 23:58:30 +01:00
|
|
|
}
|
2018-05-21 19:07:08 +01:00
|
|
|
|
2019-05-15 23:52:13 +12:00
|
|
|
if (wl_display_init_shm(display)) {
|
|
|
|
|
wlr_log(WLR_ERROR, "Failed to initialize shm");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (renderer->impl->texture_from_dmabuf) {
|
|
|
|
|
wlr_linux_dmabuf_v1_create(display, renderer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (renderer->impl->init_wl_display) {
|
|
|
|
|
renderer->impl->init_wl_display(renderer, display);
|
2018-09-01 19:27:18 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-15 23:52:13 +12:00
|
|
|
wlr_compositor_set_buffer_impl(comp, renderer, &buffer_impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_texture *wlr_commit_get_texture(struct wlr_commit *commit) {
|
|
|
|
|
assert(commit);
|
|
|
|
|
|
|
|
|
|
if (commit->buffer) {
|
|
|
|
|
struct buffer *buffer = wl_container_of(commit->buffer, buffer, base);
|
|
|
|
|
return buffer->texture;
|
2018-05-21 19:07:08 +01:00
|
|
|
}
|
2019-05-15 23:52:13 +12:00
|
|
|
|
|
|
|
|
return NULL;
|
2018-04-20 23:58:30 +01:00
|
|
|
}
|
2018-05-25 13:14:35 +03:00
|
|
|
|
|
|
|
|
struct wlr_renderer *wlr_renderer_autocreate(struct wlr_egl *egl,
|
2018-05-30 14:18:07 +01:00
|
|
|
EGLenum platform, void *remote_display, EGLint *config_attribs,
|
|
|
|
|
EGLint visual_id) {
|
2018-11-04 09:23:57 +01:00
|
|
|
// Append GLES2-specific bits to the provided EGL config attributes
|
|
|
|
|
EGLint gles2_config_attribs[] = {
|
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
|
EGL_NONE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
size_t config_attribs_len = 0; // not including terminating EGL_NONE
|
|
|
|
|
while (config_attribs != NULL &&
|
|
|
|
|
config_attribs[config_attribs_len] != EGL_NONE) {
|
|
|
|
|
++config_attribs_len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t all_config_attribs_len = config_attribs_len +
|
|
|
|
|
sizeof(gles2_config_attribs) / sizeof(gles2_config_attribs[0]);
|
|
|
|
|
EGLint all_config_attribs[all_config_attribs_len];
|
|
|
|
|
if (config_attribs_len > 0) {
|
|
|
|
|
memcpy(all_config_attribs, config_attribs,
|
|
|
|
|
config_attribs_len * sizeof(EGLint));
|
|
|
|
|
}
|
|
|
|
|
memcpy(&all_config_attribs[config_attribs_len], gles2_config_attribs,
|
|
|
|
|
sizeof(gles2_config_attribs));
|
|
|
|
|
|
|
|
|
|
if (!wlr_egl_init(egl, platform, remote_display, all_config_attribs,
|
|
|
|
|
visual_id)) {
|
2018-07-09 22:49:54 +01:00
|
|
|
wlr_log(WLR_ERROR, "Could not initialize EGL");
|
2018-05-25 13:14:35 +03:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_renderer *renderer = wlr_gles2_renderer_create(egl);
|
|
|
|
|
if (!renderer) {
|
|
|
|
|
wlr_egl_finish(egl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return renderer;
|
|
|
|
|
}
|