mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-02-23 01:40:31 -05:00
merge in upstream
This commit is contained in:
commit
3576eec3cf
154 changed files with 4860 additions and 4410 deletions
23
render/allocator.c
Normal file
23
render/allocator.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "render/allocator.h"
|
||||
|
||||
void wlr_allocator_init(struct wlr_allocator *alloc,
|
||||
const struct wlr_allocator_interface *impl) {
|
||||
assert(impl && impl->destroy && impl->create_buffer);
|
||||
alloc->impl = impl;
|
||||
wl_signal_init(&alloc->events.destroy);
|
||||
}
|
||||
|
||||
void wlr_allocator_destroy(struct wlr_allocator *alloc) {
|
||||
if (alloc == NULL) {
|
||||
return;
|
||||
}
|
||||
wl_signal_emit(&alloc->events.destroy, NULL);
|
||||
alloc->impl->destroy(alloc);
|
||||
}
|
||||
|
||||
struct wlr_buffer *wlr_allocator_create_buffer(struct wlr_allocator *alloc,
|
||||
int width, int height, const struct wlr_drm_format *format) {
|
||||
return alloc->impl->create_buffer(alloc, width, height, format);
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
#include <string.h>
|
||||
#include <wlr/render/drm_format_set.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "render/drm_format_set.h"
|
||||
|
||||
void wlr_drm_format_set_finish(struct wlr_drm_format_set *set) {
|
||||
for (size_t i = 0; i < set->len; ++i) {
|
||||
|
|
@ -59,52 +60,18 @@ bool wlr_drm_format_set_has(const struct wlr_drm_format_set *set,
|
|||
bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format,
|
||||
uint64_t modifier) {
|
||||
assert(format != DRM_FORMAT_INVALID);
|
||||
|
||||
struct wlr_drm_format **ptr = format_set_get_ref(set, format);
|
||||
|
||||
if (ptr) {
|
||||
struct wlr_drm_format *fmt = *ptr;
|
||||
|
||||
if (modifier == DRM_FORMAT_MOD_INVALID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < fmt->len; ++i) {
|
||||
if (fmt->modifiers[i] == modifier) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fmt->len == fmt->cap) {
|
||||
size_t cap = fmt->cap ? fmt->cap * 2 : 4;
|
||||
|
||||
fmt = realloc(fmt, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * cap);
|
||||
if (!fmt) {
|
||||
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt->cap = cap;
|
||||
*ptr = fmt;
|
||||
}
|
||||
|
||||
fmt->modifiers[fmt->len++] = modifier;
|
||||
return true;
|
||||
return wlr_drm_format_add(ptr, modifier);
|
||||
}
|
||||
|
||||
size_t cap = modifier != DRM_FORMAT_MOD_INVALID ? 4 : 0;
|
||||
|
||||
struct wlr_drm_format *fmt =
|
||||
calloc(1, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * cap);
|
||||
struct wlr_drm_format *fmt = wlr_drm_format_create(format);
|
||||
if (!fmt) {
|
||||
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt->format = format;
|
||||
if (cap) {
|
||||
fmt->cap = cap;
|
||||
fmt->len = 1;
|
||||
fmt->modifiers[0] = modifier;
|
||||
if (!wlr_drm_format_add(&fmt, modifier)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (set->len == set->cap) {
|
||||
|
|
@ -125,3 +92,94 @@ bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format,
|
|||
set->formats[set->len++] = fmt;
|
||||
return true;
|
||||
}
|
||||
|
||||
struct wlr_drm_format *wlr_drm_format_create(uint32_t format) {
|
||||
size_t cap = 4;
|
||||
struct wlr_drm_format *fmt =
|
||||
calloc(1, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * cap);
|
||||
if (!fmt) {
|
||||
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||
return NULL;
|
||||
}
|
||||
fmt->format = format;
|
||||
fmt->cap = cap;
|
||||
return fmt;
|
||||
}
|
||||
|
||||
bool wlr_drm_format_add(struct wlr_drm_format **fmt_ptr, uint64_t modifier) {
|
||||
struct wlr_drm_format *fmt = *fmt_ptr;
|
||||
|
||||
if (modifier == DRM_FORMAT_MOD_INVALID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < fmt->len; ++i) {
|
||||
if (fmt->modifiers[i] == modifier) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fmt->len == fmt->cap) {
|
||||
size_t cap = fmt->cap ? fmt->cap * 2 : 4;
|
||||
|
||||
fmt = realloc(fmt, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * cap);
|
||||
if (!fmt) {
|
||||
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt->cap = cap;
|
||||
*fmt_ptr = fmt;
|
||||
}
|
||||
|
||||
fmt->modifiers[fmt->len++] = modifier;
|
||||
return true;
|
||||
}
|
||||
|
||||
struct wlr_drm_format *wlr_drm_format_dup(const struct wlr_drm_format *format) {
|
||||
assert(format->len <= format->cap);
|
||||
size_t format_size = sizeof(struct wlr_drm_format) +
|
||||
format->cap * sizeof(format->modifiers[0]);
|
||||
struct wlr_drm_format *duped_format = malloc(format_size);
|
||||
if (duped_format == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy(duped_format, format, format_size);
|
||||
return duped_format;
|
||||
}
|
||||
|
||||
struct wlr_drm_format *wlr_drm_format_intersect(
|
||||
const struct wlr_drm_format *a, const struct wlr_drm_format *b) {
|
||||
assert(a->format == b->format);
|
||||
|
||||
size_t format_cap = a->len < b->len ? a->len : b->len;
|
||||
size_t format_size = sizeof(struct wlr_drm_format) +
|
||||
format_cap * sizeof(a->modifiers[0]);
|
||||
struct wlr_drm_format *format = calloc(1, format_size);
|
||||
if (format == NULL) {
|
||||
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||
return NULL;
|
||||
}
|
||||
format->format = a->format;
|
||||
format->cap = format_cap;
|
||||
|
||||
for (size_t i = 0; i < a->len; i++) {
|
||||
for (size_t j = 0; j < b->len; j++) {
|
||||
if (a->modifiers[i] == b->modifiers[j]) {
|
||||
assert(format->len < format->cap);
|
||||
format->modifiers[format->len] = a->modifiers[i];
|
||||
format->len++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If both formats support modifiers, but the intersection is empty, then
|
||||
// the formats aren't compatible with each other
|
||||
if (format->len == 0 && a->len > 0 && b->len > 0) {
|
||||
free(format);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
|
|
|
|||
204
render/egl.c
204
render/egl.c
|
|
@ -1,10 +1,14 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <assert.h>
|
||||
#include <drm_fourcc.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <wlr/render/egl.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <wlr/util/region.h>
|
||||
#include <xf86drm.h>
|
||||
|
||||
static bool egl_get_config(EGLDisplay disp, const EGLint *attribs,
|
||||
EGLConfig *out, EGLint visual_id) {
|
||||
|
|
@ -71,6 +75,8 @@ static const char *egl_error_str(EGLint error) {
|
|||
return "EGL_BAD_CURRENT_SURFACE";
|
||||
case EGL_BAD_DISPLAY:
|
||||
return "EGL_BAD_DISPLAY";
|
||||
case EGL_BAD_DEVICE_EXT:
|
||||
return "EGL_BAD_DEVICE_EXT";
|
||||
case EGL_BAD_SURFACE:
|
||||
return "EGL_BAD_SURFACE";
|
||||
case EGL_BAD_MATCH:
|
||||
|
|
@ -132,13 +138,6 @@ static void init_dmabuf_formats(struct wlr_egl *egl) {
|
|||
return;
|
||||
}
|
||||
|
||||
egl->external_only_dmabuf_formats = calloc(formats_len, sizeof(EGLBoolean *));
|
||||
if (egl->external_only_dmabuf_formats == NULL) {
|
||||
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||
goto out;
|
||||
}
|
||||
|
||||
size_t external_formats_len = 0;
|
||||
for (int i = 0; i < formats_len; i++) {
|
||||
uint32_t fmt = formats[i];
|
||||
|
||||
|
|
@ -151,17 +150,23 @@ static void init_dmabuf_formats(struct wlr_egl *egl) {
|
|||
}
|
||||
|
||||
if (modifiers_len == 0) {
|
||||
wlr_drm_format_set_add(&egl->dmabuf_formats, fmt, DRM_FORMAT_MOD_INVALID);
|
||||
wlr_drm_format_set_add(&egl->dmabuf_texture_formats, fmt,
|
||||
DRM_FORMAT_MOD_INVALID);
|
||||
wlr_drm_format_set_add(&egl->dmabuf_render_formats, fmt,
|
||||
DRM_FORMAT_MOD_INVALID);
|
||||
}
|
||||
|
||||
for (int j = 0; j < modifiers_len; j++) {
|
||||
wlr_drm_format_set_add(&egl->dmabuf_formats, fmt, modifiers[j]);
|
||||
wlr_drm_format_set_add(&egl->dmabuf_texture_formats, fmt,
|
||||
modifiers[j]);
|
||||
if (!external_only[j]) {
|
||||
wlr_drm_format_set_add(&egl->dmabuf_render_formats, fmt,
|
||||
modifiers[j]);
|
||||
}
|
||||
}
|
||||
|
||||
free(modifiers);
|
||||
|
||||
egl->external_only_dmabuf_formats[external_formats_len] = external_only;
|
||||
external_formats_len++;
|
||||
free(external_only);
|
||||
}
|
||||
|
||||
char *str_formats = malloc(formats_len * 5 + 1);
|
||||
|
|
@ -289,14 +294,53 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display,
|
|||
"eglQueryWaylandBufferWL");
|
||||
}
|
||||
|
||||
if (!egl_get_config(egl->display, config_attribs, &egl->config, visual_id)) {
|
||||
wlr_log(WLR_ERROR, "Failed to get EGL config");
|
||||
goto error;
|
||||
const char *device_exts_str = NULL;
|
||||
if (check_egl_ext(client_exts_str, "EGL_EXT_device_query")) {
|
||||
load_egl_proc(&egl->procs.eglQueryDisplayAttribEXT,
|
||||
"eglQueryDisplayAttribEXT");
|
||||
load_egl_proc(&egl->procs.eglQueryDeviceStringEXT,
|
||||
"eglQueryDeviceStringEXT");
|
||||
|
||||
EGLAttrib device_attrib;
|
||||
if (!egl->procs.eglQueryDisplayAttribEXT(egl->display,
|
||||
EGL_DEVICE_EXT, &device_attrib)) {
|
||||
wlr_log(WLR_ERROR, "eglQueryDisplayAttribEXT(EGL_DEVICE_EXT) failed");
|
||||
goto error;
|
||||
}
|
||||
egl->device = (EGLDeviceEXT)device_attrib;
|
||||
|
||||
device_exts_str =
|
||||
egl->procs.eglQueryDeviceStringEXT(egl->device, EGL_EXTENSIONS);
|
||||
if (device_exts_str == NULL) {
|
||||
wlr_log(WLR_ERROR, "eglQueryDeviceStringEXT(EGL_EXTENSIONS) failed");
|
||||
goto error;
|
||||
}
|
||||
|
||||
egl->exts.device_drm_ext =
|
||||
check_egl_ext(device_exts_str, "EGL_EXT_device_drm");
|
||||
}
|
||||
|
||||
if (config_attribs != NULL) {
|
||||
if (!egl_get_config(egl->display, config_attribs, &egl->config, visual_id)) {
|
||||
wlr_log(WLR_ERROR, "Failed to get EGL config");
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
if (!check_egl_ext(display_exts_str, "EGL_KHR_no_config_context") &&
|
||||
!check_egl_ext(display_exts_str, "EGL_MESA_configless_context")) {
|
||||
wlr_log(WLR_ERROR, "EGL_KHR_no_config_context or "
|
||||
"EGL_MESA_configless_context not supported");
|
||||
goto error;
|
||||
}
|
||||
egl->config = EGL_NO_CONFIG_KHR;
|
||||
}
|
||||
|
||||
wlr_log(WLR_INFO, "Using EGL %d.%d", (int)major, (int)minor);
|
||||
wlr_log(WLR_INFO, "Supported EGL client extensions: %s", client_exts_str);
|
||||
wlr_log(WLR_INFO, "Supported EGL display extensions: %s", display_exts_str);
|
||||
if (device_exts_str != NULL) {
|
||||
wlr_log(WLR_INFO, "Supported EGL device extensions: %s", device_exts_str);
|
||||
}
|
||||
wlr_log(WLR_INFO, "EGL vendor: %s", eglQueryString(egl->display, EGL_VENDOR));
|
||||
|
||||
init_dmabuf_formats(egl);
|
||||
|
|
@ -357,12 +401,8 @@ void wlr_egl_finish(struct wlr_egl *egl) {
|
|||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < egl->dmabuf_formats.len; i++) {
|
||||
free(egl->external_only_dmabuf_formats[i]);
|
||||
}
|
||||
free(egl->external_only_dmabuf_formats);
|
||||
|
||||
wlr_drm_format_set_finish(&egl->dmabuf_formats);
|
||||
wlr_drm_format_set_finish(&egl->dmabuf_render_formats);
|
||||
wlr_drm_format_set_finish(&egl->dmabuf_texture_formats);
|
||||
|
||||
eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
if (egl->wl_display) {
|
||||
|
|
@ -561,27 +601,6 @@ EGLImageKHR wlr_egl_create_image_from_wl_drm(struct wlr_egl *egl,
|
|||
EGL_WAYLAND_BUFFER_WL, data, attribs);
|
||||
}
|
||||
|
||||
static bool dmabuf_format_is_external_only(struct wlr_egl *egl,
|
||||
uint32_t format, uint64_t modifier) {
|
||||
for (size_t i = 0; i < egl->dmabuf_formats.len; i++) {
|
||||
struct wlr_drm_format *fmt = egl->dmabuf_formats.formats[i];
|
||||
if (fmt->format == format) {
|
||||
if (egl->external_only_dmabuf_formats[i] == NULL) {
|
||||
break;
|
||||
}
|
||||
for (size_t j = 0; j < fmt->len; j++) {
|
||||
if (fmt->modifiers[j] == modifier) {
|
||||
return egl->external_only_dmabuf_formats[i][j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// No info, we're doomed. Choose GL_TEXTURE_EXTERNAL_OES and hope for the
|
||||
// best.
|
||||
return true;
|
||||
}
|
||||
|
||||
EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
|
||||
struct wlr_dmabuf_attributes *attributes, bool *external_only) {
|
||||
if (!egl->exts.image_base_khr || !egl->exts.image_dmabuf_import_ext) {
|
||||
|
|
@ -671,7 +690,7 @@ EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
|
|||
return EGL_NO_IMAGE_KHR;
|
||||
}
|
||||
|
||||
*external_only = dmabuf_format_is_external_only(egl,
|
||||
*external_only = !wlr_drm_format_set_has(&egl->dmabuf_render_formats,
|
||||
attributes->format, attributes->modifier);
|
||||
return image;
|
||||
}
|
||||
|
|
@ -765,13 +784,20 @@ static int get_egl_dmabuf_modifiers(struct wlr_egl *egl, int format,
|
|||
*modifiers, *external_only, &num)) {
|
||||
wlr_log(WLR_ERROR, "Failed to query dmabuf modifiers");
|
||||
free(*modifiers);
|
||||
free(*external_only);
|
||||
return -1;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
const struct wlr_drm_format_set *wlr_egl_get_dmabuf_formats(struct wlr_egl *egl) {
|
||||
return &egl->dmabuf_formats;
|
||||
const struct wlr_drm_format_set *wlr_egl_get_dmabuf_texture_formats(
|
||||
struct wlr_egl *egl) {
|
||||
return &egl->dmabuf_texture_formats;
|
||||
}
|
||||
|
||||
const struct wlr_drm_format_set *wlr_egl_get_dmabuf_render_formats(
|
||||
struct wlr_egl *egl) {
|
||||
return &egl->dmabuf_render_formats;
|
||||
}
|
||||
|
||||
bool wlr_egl_export_image_to_dmabuf(struct wlr_egl *egl, EGLImageKHR image,
|
||||
|
|
@ -818,3 +844,91 @@ bool wlr_egl_destroy_surface(struct wlr_egl *egl, EGLSurface surface) {
|
|||
}
|
||||
return eglDestroySurface(egl->display, surface);
|
||||
}
|
||||
|
||||
static bool device_has_name(const drmDevice *device, const char *name) {
|
||||
for (size_t i = 0; i < DRM_NODE_MAX; i++) {
|
||||
if (!(device->available_nodes & (1 << i))) {
|
||||
continue;
|
||||
}
|
||||
if (strcmp(device->nodes[i], name) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static char *get_render_name(const char *name) {
|
||||
uint32_t flags = 0;
|
||||
int devices_len = drmGetDevices2(flags, NULL, 0);
|
||||
if (devices_len < 0) {
|
||||
wlr_log(WLR_ERROR, "drmGetDevices2 failed");
|
||||
return NULL;
|
||||
}
|
||||
drmDevice **devices = calloc(devices_len, sizeof(drmDevice *));
|
||||
if (devices == NULL) {
|
||||
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||
return NULL;
|
||||
}
|
||||
devices_len = drmGetDevices2(flags, devices, devices_len);
|
||||
if (devices_len < 0) {
|
||||
free(devices);
|
||||
wlr_log(WLR_ERROR, "drmGetDevices2 failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const drmDevice *match = NULL;
|
||||
for (int i = 0; i < devices_len; i++) {
|
||||
if (device_has_name(devices[i], name)) {
|
||||
match = devices[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char *render_name = NULL;
|
||||
if (match == NULL) {
|
||||
wlr_log(WLR_ERROR, "Cannot find DRM device %s", name);
|
||||
} else if (!(match->available_nodes & (1 << DRM_NODE_RENDER))) {
|
||||
wlr_log(WLR_ERROR, "DRM device %s has no render node", name);
|
||||
} else {
|
||||
render_name = strdup(match->nodes[DRM_NODE_RENDER]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < devices_len; i++) {
|
||||
drmFreeDevice(&devices[i]);
|
||||
}
|
||||
free(devices);
|
||||
|
||||
return render_name;
|
||||
}
|
||||
|
||||
int wlr_egl_dup_drm_fd(struct wlr_egl *egl) {
|
||||
if (egl->device == EGL_NO_DEVICE_EXT || !egl->exts.device_drm_ext) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *primary_name = egl->procs.eglQueryDeviceStringEXT(egl->device,
|
||||
EGL_DRM_DEVICE_FILE_EXT);
|
||||
if (primary_name == NULL) {
|
||||
wlr_log(WLR_ERROR,
|
||||
"eglQueryDeviceStringEXT(EGL_DRM_DEVICE_FILE_EXT) failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *render_name = get_render_name(primary_name);
|
||||
if (render_name == NULL) {
|
||||
wlr_log(WLR_ERROR, "Can't find render node name for device %s",
|
||||
primary_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int render_fd = open(render_name, O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
||||
if (render_fd < 0) {
|
||||
wlr_log_errno(WLR_ERROR, "Failed to open DRM render node %s",
|
||||
render_name);
|
||||
free(render_name);
|
||||
return -1;
|
||||
}
|
||||
free(render_name);
|
||||
|
||||
return render_fd;
|
||||
}
|
||||
|
|
|
|||
182
render/gbm_allocator.c
Normal file
182
render/gbm_allocator.c
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <assert.h>
|
||||
#include <drm_fourcc.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <xf86drm.h>
|
||||
#include "render/gbm_allocator.h"
|
||||
|
||||
static const struct wlr_buffer_impl buffer_impl;
|
||||
|
||||
static struct wlr_gbm_buffer *get_gbm_buffer_from_buffer(
|
||||
struct wlr_buffer *buffer) {
|
||||
assert(buffer->impl == &buffer_impl);
|
||||
return (struct wlr_gbm_buffer *)buffer;
|
||||
}
|
||||
|
||||
static struct wlr_gbm_buffer *create_buffer(struct gbm_device *gbm_device,
|
||||
int width, int height, const struct wlr_drm_format *format) {
|
||||
struct gbm_bo *bo = NULL;
|
||||
if (format->len > 0) {
|
||||
bo = gbm_bo_create_with_modifiers(gbm_device, width, height,
|
||||
format->format, format->modifiers, format->len);
|
||||
}
|
||||
if (bo == NULL) {
|
||||
uint32_t usage = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
|
||||
if (format->len == 1 &&
|
||||
format->modifiers[0] == DRM_FORMAT_MOD_LINEAR) {
|
||||
usage |= GBM_BO_USE_LINEAR;
|
||||
}
|
||||
bo = gbm_bo_create(gbm_device, width, height, format->format, usage);
|
||||
}
|
||||
if (bo == NULL) {
|
||||
wlr_log(WLR_ERROR, "gbm_bo_create failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_gbm_buffer *buffer = calloc(1, sizeof(*buffer));
|
||||
if (buffer == NULL) {
|
||||
gbm_bo_destroy(bo);
|
||||
return NULL;
|
||||
}
|
||||
wlr_buffer_init(&buffer->base, &buffer_impl, width, height);
|
||||
buffer->gbm_bo = bo;
|
||||
|
||||
wlr_log(WLR_DEBUG, "Allocated %dx%d GBM buffer (format 0x%"PRIX32", "
|
||||
"modifier 0x%"PRIX64")", buffer->base.width, buffer->base.height,
|
||||
gbm_bo_get_format(bo), gbm_bo_get_modifier(bo));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void buffer_destroy(struct wlr_buffer *wlr_buffer) {
|
||||
struct wlr_gbm_buffer *buffer =
|
||||
get_gbm_buffer_from_buffer(wlr_buffer);
|
||||
wlr_dmabuf_attributes_finish(&buffer->dmabuf);
|
||||
gbm_bo_destroy(buffer->gbm_bo);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
static bool buffer_create_dmabuf(struct wlr_gbm_buffer *buffer) {
|
||||
assert(buffer->dmabuf.n_planes == 0);
|
||||
|
||||
struct gbm_bo *bo = buffer->gbm_bo;
|
||||
struct wlr_dmabuf_attributes attribs = {0};
|
||||
|
||||
attribs.n_planes = gbm_bo_get_plane_count(bo);
|
||||
if (attribs.n_planes > WLR_DMABUF_MAX_PLANES) {
|
||||
wlr_log(WLR_ERROR, "GBM BO contains too many planes (%d)",
|
||||
attribs.n_planes);
|
||||
return false;
|
||||
}
|
||||
|
||||
attribs.width = gbm_bo_get_width(bo);
|
||||
attribs.height = gbm_bo_get_height(bo);
|
||||
attribs.format = gbm_bo_get_format(bo);
|
||||
attribs.modifier = gbm_bo_get_modifier(bo);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < attribs.n_planes; ++i) {
|
||||
union gbm_bo_handle handle = gbm_bo_get_handle_for_plane(bo, i);
|
||||
if (handle.s32 < 0) {
|
||||
wlr_log(WLR_ERROR, "gbm_bo_get_handle_for_plane failed");
|
||||
goto error_fd;
|
||||
}
|
||||
|
||||
int drm_fd = gbm_device_get_fd(gbm_bo_get_device(bo));
|
||||
int ret = drmPrimeHandleToFD(drm_fd, handle.s32,
|
||||
DRM_CLOEXEC, &attribs.fd[i]);
|
||||
if (ret < 0 || attribs.fd[i] < 0) {
|
||||
wlr_log_errno(WLR_ERROR, "drmPrimeHandleToFD failed");
|
||||
goto error_fd;
|
||||
}
|
||||
|
||||
attribs.offset[i] = gbm_bo_get_offset(bo, i);
|
||||
attribs.stride[i] = gbm_bo_get_stride_for_plane(bo, i);
|
||||
}
|
||||
|
||||
memcpy(&buffer->dmabuf, &attribs, sizeof(attribs));
|
||||
return true;
|
||||
|
||||
error_fd:
|
||||
for (int j = 0; j < i; ++j) {
|
||||
close(attribs.fd[j]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool buffer_get_dmabuf(struct wlr_buffer *wlr_buffer,
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
struct wlr_gbm_buffer *buffer =
|
||||
get_gbm_buffer_from_buffer(wlr_buffer);
|
||||
|
||||
memset(attribs, 0, sizeof(*attribs));
|
||||
|
||||
// Only export the buffer once
|
||||
if (buffer->dmabuf.n_planes == 0) {
|
||||
if (!buffer_create_dmabuf(buffer)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(attribs, &buffer->dmabuf, sizeof(buffer->dmabuf));
|
||||
return true;
|
||||
}
|
||||
|
||||
static const struct wlr_buffer_impl buffer_impl = {
|
||||
.destroy = buffer_destroy,
|
||||
.get_dmabuf = buffer_get_dmabuf,
|
||||
};
|
||||
|
||||
static const struct wlr_allocator_interface allocator_impl;
|
||||
|
||||
static struct wlr_gbm_allocator *get_gbm_alloc_from_alloc(
|
||||
struct wlr_allocator *alloc) {
|
||||
assert(alloc->impl == &allocator_impl);
|
||||
return (struct wlr_gbm_allocator *)alloc;
|
||||
}
|
||||
|
||||
struct wlr_gbm_allocator *wlr_gbm_allocator_create(int fd) {
|
||||
struct wlr_gbm_allocator *alloc = calloc(1, sizeof(*alloc));
|
||||
if (alloc == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
wlr_allocator_init(&alloc->base, &allocator_impl);
|
||||
|
||||
alloc->fd = fd;
|
||||
|
||||
alloc->gbm_device = gbm_create_device(fd);
|
||||
if (alloc->gbm_device == NULL) {
|
||||
wlr_log(WLR_ERROR, "gbm_create_device failed");
|
||||
free(alloc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return alloc;
|
||||
}
|
||||
|
||||
static void allocator_destroy(struct wlr_allocator *wlr_alloc) {
|
||||
struct wlr_gbm_allocator *alloc = get_gbm_alloc_from_alloc(wlr_alloc);
|
||||
gbm_device_destroy(alloc->gbm_device);
|
||||
close(alloc->fd);
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
static struct wlr_buffer *allocator_create_buffer(
|
||||
struct wlr_allocator *wlr_alloc, int width, int height,
|
||||
const struct wlr_drm_format *format) {
|
||||
struct wlr_gbm_allocator *alloc = get_gbm_alloc_from_alloc(wlr_alloc);
|
||||
struct wlr_gbm_buffer *buffer =
|
||||
create_buffer(alloc->gbm_device, width, height, format);
|
||||
if (buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return &buffer->base;
|
||||
}
|
||||
|
||||
static const struct wlr_allocator_interface allocator_impl = {
|
||||
.destroy = allocator_destroy,
|
||||
.create_buffer = allocator_create_buffer,
|
||||
};
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-server-protocol.h>
|
||||
#include <wayland-util.h>
|
||||
#include <wlr/render/egl.h>
|
||||
|
|
@ -21,11 +22,9 @@ static const GLfloat verts[] = {
|
|||
0, 1, // bottom left
|
||||
};
|
||||
|
||||
struct wlr_gles2_procs gles2_procs = {0};
|
||||
|
||||
static const struct wlr_renderer_impl renderer_impl;
|
||||
|
||||
static struct wlr_gles2_renderer *gles2_get_renderer(
|
||||
struct wlr_gles2_renderer *gles2_get_renderer(
|
||||
struct wlr_renderer *wlr_renderer) {
|
||||
assert(wlr_renderer->impl == &renderer_impl);
|
||||
return (struct wlr_gles2_renderer *)wlr_renderer;
|
||||
|
|
@ -38,12 +37,145 @@ static struct wlr_gles2_renderer *gles2_get_renderer_in_context(
|
|||
return renderer;
|
||||
}
|
||||
|
||||
static void destroy_buffer(struct wlr_gles2_buffer *buffer) {
|
||||
wl_list_remove(&buffer->link);
|
||||
wl_list_remove(&buffer->buffer_destroy.link);
|
||||
|
||||
wlr_egl_make_current(buffer->renderer->egl, EGL_NO_SURFACE, NULL);
|
||||
|
||||
push_gles2_debug(buffer->renderer);
|
||||
|
||||
glDeleteFramebuffers(1, &buffer->fbo);
|
||||
glDeleteRenderbuffers(1, &buffer->rbo);
|
||||
|
||||
pop_gles2_debug(buffer->renderer);
|
||||
|
||||
wlr_egl_destroy_image(buffer->renderer->egl, buffer->image);
|
||||
wlr_egl_unset_current(buffer->renderer->egl);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
static struct wlr_gles2_buffer *get_buffer(struct wlr_gles2_renderer *renderer,
|
||||
struct wlr_buffer *wlr_buffer) {
|
||||
struct wlr_gles2_buffer *buffer;
|
||||
wl_list_for_each(buffer, &renderer->buffers, link) {
|
||||
if (buffer->buffer == wlr_buffer) {
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void handle_buffer_destroy(struct wl_listener *listener, void *data) {
|
||||
struct wlr_gles2_buffer *buffer =
|
||||
wl_container_of(listener, buffer, buffer_destroy);
|
||||
destroy_buffer(buffer);
|
||||
}
|
||||
|
||||
static struct wlr_gles2_buffer *create_buffer(struct wlr_gles2_renderer *renderer,
|
||||
struct wlr_buffer *wlr_buffer) {
|
||||
struct wlr_gles2_buffer *buffer = calloc(1, sizeof(*buffer));
|
||||
if (buffer == NULL) {
|
||||
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||
return NULL;
|
||||
}
|
||||
buffer->buffer = wlr_buffer;
|
||||
buffer->renderer = renderer;
|
||||
|
||||
struct wlr_dmabuf_attributes dmabuf = {0};
|
||||
if (!wlr_buffer_get_dmabuf(wlr_buffer, &dmabuf)) {
|
||||
goto error_buffer;
|
||||
}
|
||||
|
||||
bool external_only;
|
||||
buffer->image = wlr_egl_create_image_from_dmabuf(renderer->egl,
|
||||
&dmabuf, &external_only);
|
||||
if (buffer->image == EGL_NO_IMAGE_KHR) {
|
||||
goto error_buffer;
|
||||
}
|
||||
|
||||
push_gles2_debug(renderer);
|
||||
|
||||
glGenRenderbuffers(1, &buffer->rbo);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, buffer->rbo);
|
||||
renderer->procs.glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,
|
||||
buffer->image);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
|
||||
glGenFramebuffers(1, &buffer->fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, buffer->fbo);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||
GL_RENDERBUFFER, buffer->rbo);
|
||||
GLenum fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
if (fb_status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
wlr_log(WLR_ERROR, "Failed to create FBO");
|
||||
goto error_image;
|
||||
}
|
||||
|
||||
buffer->buffer_destroy.notify = handle_buffer_destroy;
|
||||
wl_signal_add(&wlr_buffer->events.destroy, &buffer->buffer_destroy);
|
||||
|
||||
wl_list_insert(&renderer->buffers, &buffer->link);
|
||||
|
||||
wlr_log(WLR_DEBUG, "Created GL FBO for buffer %dx%d",
|
||||
wlr_buffer->width, wlr_buffer->height);
|
||||
|
||||
return buffer;
|
||||
|
||||
error_image:
|
||||
wlr_egl_destroy_image(renderer->egl, buffer->image);
|
||||
error_buffer:
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool gles2_bind_buffer(struct wlr_renderer *wlr_renderer,
|
||||
struct wlr_buffer *wlr_buffer) {
|
||||
struct wlr_gles2_renderer *renderer =
|
||||
gles2_get_renderer_in_context(wlr_renderer);
|
||||
|
||||
if (renderer->current_buffer != NULL) {
|
||||
push_gles2_debug(renderer);
|
||||
glFlush();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
wlr_buffer_unlock(renderer->current_buffer->buffer);
|
||||
renderer->current_buffer = NULL;
|
||||
}
|
||||
|
||||
if (wlr_buffer == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
struct wlr_gles2_buffer *buffer = get_buffer(renderer, wlr_buffer);
|
||||
if (buffer == NULL) {
|
||||
buffer = create_buffer(renderer, wlr_buffer);
|
||||
}
|
||||
if (buffer == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
wlr_buffer_lock(wlr_buffer);
|
||||
renderer->current_buffer = buffer;
|
||||
|
||||
push_gles2_debug(renderer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, renderer->current_buffer->fbo);
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void gles2_begin(struct wlr_renderer *wlr_renderer, uint32_t width,
|
||||
uint32_t height) {
|
||||
struct wlr_gles2_renderer *renderer =
|
||||
gles2_get_renderer_in_context(wlr_renderer);
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(renderer);
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
renderer->viewport_width = width;
|
||||
|
|
@ -56,7 +188,7 @@ static void gles2_begin(struct wlr_renderer *wlr_renderer, uint32_t width,
|
|||
// XXX: maybe we should save output projection and remove some of the need
|
||||
// for users to sling matricies themselves
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
}
|
||||
|
||||
static void gles2_end(struct wlr_renderer *wlr_renderer) {
|
||||
|
|
@ -66,12 +198,13 @@ static void gles2_end(struct wlr_renderer *wlr_renderer) {
|
|||
|
||||
static void gles2_clear(struct wlr_renderer *wlr_renderer,
|
||||
const float color[static 4]) {
|
||||
gles2_get_renderer_in_context(wlr_renderer);
|
||||
struct wlr_gles2_renderer *renderer =
|
||||
gles2_get_renderer_in_context(wlr_renderer);
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(renderer);
|
||||
glClearColor(color[0], color[1], color[2], color[3]);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
}
|
||||
|
||||
static void gles2_scissor(struct wlr_renderer *wlr_renderer,
|
||||
|
|
@ -79,20 +212,30 @@ static void gles2_scissor(struct wlr_renderer *wlr_renderer,
|
|||
struct wlr_gles2_renderer *renderer =
|
||||
gles2_get_renderer_in_context(wlr_renderer);
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(renderer);
|
||||
if (box != NULL) {
|
||||
struct wlr_box gl_box;
|
||||
wlr_box_transform(&gl_box, box, WL_OUTPUT_TRANSFORM_FLIPPED_180,
|
||||
renderer->viewport_width, renderer->viewport_height);
|
||||
if (renderer->current_buffer != NULL) {
|
||||
memcpy(&gl_box, box, sizeof(gl_box));
|
||||
} else {
|
||||
wlr_box_transform(&gl_box, box, WL_OUTPUT_TRANSFORM_FLIPPED_180,
|
||||
renderer->viewport_width, renderer->viewport_height);
|
||||
}
|
||||
|
||||
glScissor(gl_box.x, gl_box.y, gl_box.width, gl_box.height);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
} else {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
}
|
||||
|
||||
static const float flip_180[9] = {
|
||||
1.0f, 0.0f, 0.0f,
|
||||
0.0f, -1.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f,
|
||||
};
|
||||
|
||||
static bool gles2_render_subtexture_with_matrix(
|
||||
struct wlr_renderer *wlr_renderer, struct wlr_texture *wlr_texture,
|
||||
const struct wlr_fbox *box, const float matrix[static 9],
|
||||
|
|
@ -125,12 +268,17 @@ static bool gles2_render_subtexture_with_matrix(
|
|||
abort();
|
||||
}
|
||||
|
||||
float gl_matrix[9];
|
||||
if (renderer->current_buffer != NULL) {
|
||||
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
|
||||
} else {
|
||||
memcpy(gl_matrix, matrix, sizeof(gl_matrix));
|
||||
}
|
||||
// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
|
||||
// to GL_FALSE
|
||||
float transposition[9];
|
||||
wlr_matrix_transpose(transposition, matrix);
|
||||
wlr_matrix_transpose(gl_matrix, gl_matrix);
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(renderer);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(texture->target, texture->tex);
|
||||
|
|
@ -139,7 +287,7 @@ static bool gles2_render_subtexture_with_matrix(
|
|||
|
||||
glUseProgram(shader->program);
|
||||
|
||||
glUniformMatrix3fv(shader->proj, 1, GL_FALSE, transposition);
|
||||
glUniformMatrix3fv(shader->proj, 1, GL_FALSE, gl_matrix);
|
||||
glUniform1i(shader->invert_y, texture->inverted_y);
|
||||
glUniform1i(shader->tex, 0);
|
||||
glUniform1f(shader->alpha, alpha);
|
||||
|
|
@ -168,7 +316,7 @@ static bool gles2_render_subtexture_with_matrix(
|
|||
|
||||
glBindTexture(texture->target, 0);
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -177,15 +325,20 @@ static void gles2_render_quad_with_matrix(struct wlr_renderer *wlr_renderer,
|
|||
struct wlr_gles2_renderer *renderer =
|
||||
gles2_get_renderer_in_context(wlr_renderer);
|
||||
|
||||
float gl_matrix[9];
|
||||
if (renderer->current_buffer != NULL) {
|
||||
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
|
||||
} else {
|
||||
memcpy(gl_matrix, matrix, sizeof(gl_matrix));
|
||||
}
|
||||
// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
|
||||
// to GL_FALSE
|
||||
float transposition[9];
|
||||
wlr_matrix_transpose(transposition, matrix);
|
||||
wlr_matrix_transpose(gl_matrix, gl_matrix);
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(renderer);
|
||||
glUseProgram(renderer->shaders.quad.program);
|
||||
|
||||
glUniformMatrix3fv(renderer->shaders.quad.proj, 1, GL_FALSE, transposition);
|
||||
glUniformMatrix3fv(renderer->shaders.quad.proj, 1, GL_FALSE, gl_matrix);
|
||||
glUniform4f(renderer->shaders.quad.color, color[0], color[1], color[2], color[3]);
|
||||
|
||||
glVertexAttribPointer(renderer->shaders.quad.pos_attrib, 2, GL_FLOAT, GL_FALSE,
|
||||
|
|
@ -197,7 +350,7 @@ static void gles2_render_quad_with_matrix(struct wlr_renderer *wlr_renderer,
|
|||
|
||||
glDisableVertexAttribArray(renderer->shaders.quad.pos_attrib);
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
}
|
||||
|
||||
static void gles2_render_ellipse_with_matrix(struct wlr_renderer *wlr_renderer,
|
||||
|
|
@ -205,10 +358,15 @@ static void gles2_render_ellipse_with_matrix(struct wlr_renderer *wlr_renderer,
|
|||
struct wlr_gles2_renderer *renderer =
|
||||
gles2_get_renderer_in_context(wlr_renderer);
|
||||
|
||||
float gl_matrix[9];
|
||||
if (renderer->current_buffer != NULL) {
|
||||
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
|
||||
} else {
|
||||
memcpy(gl_matrix, matrix, sizeof(gl_matrix));
|
||||
}
|
||||
// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
|
||||
// to GL_FALSE
|
||||
float transposition[9];
|
||||
wlr_matrix_transpose(transposition, matrix);
|
||||
wlr_matrix_transpose(gl_matrix, gl_matrix);
|
||||
|
||||
static const GLfloat texcoord[] = {
|
||||
1, 0, // top right
|
||||
|
|
@ -217,10 +375,10 @@ static void gles2_render_ellipse_with_matrix(struct wlr_renderer *wlr_renderer,
|
|||
0, 1, // bottom left
|
||||
};
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(renderer);
|
||||
glUseProgram(renderer->shaders.ellipse.program);
|
||||
|
||||
glUniformMatrix3fv(renderer->shaders.ellipse.proj, 1, GL_FALSE, transposition);
|
||||
glUniformMatrix3fv(renderer->shaders.ellipse.proj, 1, GL_FALSE, gl_matrix);
|
||||
glUniform4f(renderer->shaders.ellipse.color, color[0], color[1], color[2], color[3]);
|
||||
|
||||
glVertexAttribPointer(renderer->shaders.ellipse.pos_attrib, 2, GL_FLOAT,
|
||||
|
|
@ -235,19 +393,14 @@ static void gles2_render_ellipse_with_matrix(struct wlr_renderer *wlr_renderer,
|
|||
|
||||
glDisableVertexAttribArray(renderer->shaders.ellipse.pos_attrib);
|
||||
glDisableVertexAttribArray(renderer->shaders.ellipse.tex_attrib);
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
}
|
||||
|
||||
static const enum wl_shm_format *gles2_renderer_formats(
|
||||
static const enum wl_shm_format *gles2_get_shm_texture_formats(
|
||||
struct wlr_renderer *wlr_renderer, size_t *len) {
|
||||
return get_gles2_wl_formats(len);
|
||||
}
|
||||
|
||||
static bool gles2_format_supported(struct wlr_renderer *wlr_renderer,
|
||||
enum wl_shm_format wl_fmt) {
|
||||
return get_gles2_format_from_wl(wl_fmt) != NULL;
|
||||
}
|
||||
|
||||
static bool gles2_resource_is_wl_drm_buffer(struct wlr_renderer *wlr_renderer,
|
||||
struct wl_resource *resource) {
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
|
|
@ -276,10 +429,16 @@ static void gles2_wl_drm_buffer_get_size(struct wlr_renderer *wlr_renderer,
|
|||
buffer, EGL_HEIGHT, height);
|
||||
}
|
||||
|
||||
static const struct wlr_drm_format_set *gles2_get_dmabuf_formats(
|
||||
static const struct wlr_drm_format_set *gles2_get_dmabuf_texture_formats(
|
||||
struct wlr_renderer *wlr_renderer) {
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
return wlr_egl_get_dmabuf_formats(renderer->egl);
|
||||
return wlr_egl_get_dmabuf_texture_formats(renderer->egl);
|
||||
}
|
||||
|
||||
static const struct wlr_drm_format_set *gles2_get_dmabuf_render_formats(
|
||||
struct wlr_renderer *wlr_renderer) {
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
return wlr_egl_get_dmabuf_render_formats(renderer->egl);
|
||||
}
|
||||
|
||||
static enum wl_shm_format gles2_preferred_read_format(
|
||||
|
|
@ -288,14 +447,21 @@ static enum wl_shm_format gles2_preferred_read_format(
|
|||
gles2_get_renderer_in_context(wlr_renderer);
|
||||
|
||||
GLint gl_format = -1, gl_type = -1;
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(renderer);
|
||||
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &gl_format);
|
||||
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &gl_type);
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
EGLint alpha_size = -1;
|
||||
eglGetConfigAttrib(renderer->egl->display, renderer->egl->config,
|
||||
EGL_ALPHA_SIZE, &alpha_size);
|
||||
if (renderer->current_buffer != NULL) {
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, renderer->current_buffer->rbo);
|
||||
glGetRenderbufferParameteriv(GL_RENDERBUFFER,
|
||||
GL_RENDERBUFFER_ALPHA_SIZE, &alpha_size);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
} else if (renderer->egl->config != EGL_NO_CONFIG_KHR) {
|
||||
eglGetConfigAttrib(renderer->egl->display, renderer->egl->config,
|
||||
EGL_ALPHA_SIZE, &alpha_size);
|
||||
}
|
||||
|
||||
const struct wlr_gles2_pixel_format *fmt =
|
||||
get_gles2_format_from_gl(gl_format, gl_type, alpha_size > 0);
|
||||
|
|
@ -328,7 +494,7 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
|
|||
return false;
|
||||
}
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(renderer);
|
||||
|
||||
// Make sure any pending drawing is finished before we try to read it
|
||||
glFinish();
|
||||
|
|
@ -340,22 +506,38 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
|
|||
if (pack_stride == stride && dst_x == 0 && flags != NULL) {
|
||||
// Under these particular conditions, we can read the pixels with only
|
||||
// one glReadPixels call
|
||||
glReadPixels(src_x, renderer->viewport_height - height - src_y,
|
||||
width, height, fmt->gl_format, fmt->gl_type, p);
|
||||
*flags = WLR_RENDERER_READ_PIXELS_Y_INVERT;
|
||||
|
||||
uint32_t y = src_y;
|
||||
if (renderer->current_buffer == NULL) {
|
||||
y = renderer->viewport_height - height - src_y;
|
||||
}
|
||||
|
||||
glReadPixels(src_x, y, width, height, fmt->gl_format, fmt->gl_type, p);
|
||||
|
||||
if (renderer->current_buffer != NULL) {
|
||||
*flags = 0;
|
||||
} else {
|
||||
*flags = WLR_RENDERER_READ_PIXELS_Y_INVERT;
|
||||
}
|
||||
} else {
|
||||
// Unfortunately GLES2 doesn't support GL_PACK_*, so we have to read
|
||||
// the lines out row by row
|
||||
for (size_t i = 0; i < height; ++i) {
|
||||
glReadPixels(src_x, renderer->viewport_height - src_y - i - 1, width, 1, fmt->gl_format,
|
||||
uint32_t y = src_y + i;
|
||||
if (renderer->current_buffer == NULL) {
|
||||
y = renderer->viewport_height - src_y - i - 1;
|
||||
}
|
||||
|
||||
glReadPixels(src_x, y, width, 1, fmt->gl_format,
|
||||
fmt->gl_type, p + i * stride + dst_x * fmt->bpp / 8);
|
||||
}
|
||||
|
||||
if (flags != NULL) {
|
||||
*flags = 0;
|
||||
}
|
||||
}
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
return glGetError() == GL_NO_ERROR;
|
||||
}
|
||||
|
|
@ -363,7 +545,8 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
|
|||
static bool gles2_blit_dmabuf(struct wlr_renderer *wlr_renderer,
|
||||
struct wlr_dmabuf_attributes *dst_attr,
|
||||
struct wlr_dmabuf_attributes *src_attr) {
|
||||
if (!gles2_procs.glEGLImageTargetRenderbufferStorageOES) {
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
if (!renderer->procs.glEGLImageTargetRenderbufferStorageOES) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -377,6 +560,7 @@ static bool gles2_blit_dmabuf(struct wlr_renderer *wlr_renderer,
|
|||
goto restore_context_out;
|
||||
}
|
||||
|
||||
// TODO: get inverted_y right when current_buffer != NULL
|
||||
// This is to take into account y-inversion on both buffers rather than
|
||||
// just the source buffer.
|
||||
bool src_inverted_y =
|
||||
|
|
@ -384,19 +568,21 @@ static bool gles2_blit_dmabuf(struct wlr_renderer *wlr_renderer,
|
|||
bool dst_inverted_y =
|
||||
!!(dst_attr->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT);
|
||||
struct wlr_gles2_texture *gles2_src_tex = gles2_get_texture(src_tex);
|
||||
// The result is negated because wlr_matrix_projection y-inverts the
|
||||
// texture.
|
||||
gles2_src_tex->inverted_y = !(src_inverted_y ^ dst_inverted_y);
|
||||
gles2_src_tex->inverted_y = src_inverted_y ^ dst_inverted_y;
|
||||
if (renderer->current_buffer == NULL) {
|
||||
// The result is negated because wlr_matrix_projection y-inverts the
|
||||
// texture.
|
||||
gles2_src_tex->inverted_y = !gles2_src_tex->inverted_y;
|
||||
}
|
||||
|
||||
struct wlr_egl *egl = wlr_gles2_renderer_get_egl(wlr_renderer);
|
||||
if (!wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL)) {
|
||||
if (!wlr_egl_make_current(renderer->egl, EGL_NO_SURFACE, NULL)) {
|
||||
goto texture_destroy_out;
|
||||
}
|
||||
|
||||
// TODO: The imported buffer should be checked with
|
||||
// eglQueryDmaBufModifiersEXT to see if it may be modified.
|
||||
bool external_only = false;
|
||||
EGLImageKHR image = wlr_egl_create_image_from_dmabuf(egl, dst_attr,
|
||||
EGLImageKHR image = wlr_egl_create_image_from_dmabuf(renderer->egl, dst_attr,
|
||||
&external_only);
|
||||
if (image == EGL_NO_IMAGE_KHR) {
|
||||
goto texture_destroy_out;
|
||||
|
|
@ -405,7 +591,7 @@ static bool gles2_blit_dmabuf(struct wlr_renderer *wlr_renderer,
|
|||
GLuint rbo = 0;
|
||||
glGenRenderbuffers(1, &rbo);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
|
||||
gles2_procs.glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,
|
||||
renderer->procs.glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,
|
||||
image);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
|
||||
|
|
@ -434,7 +620,7 @@ out:
|
|||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
glDeleteRenderbuffers(1, &rbo);
|
||||
wlr_egl_destroy_image(egl, image);
|
||||
wlr_egl_destroy_image(renderer->egl, image);
|
||||
texture_destroy_out:
|
||||
wlr_texture_destroy(src_tex);
|
||||
restore_context_out:
|
||||
|
|
@ -442,27 +628,6 @@ restore_context_out:
|
|||
return r;
|
||||
}
|
||||
|
||||
static struct wlr_texture *gles2_texture_from_pixels(
|
||||
struct wlr_renderer *wlr_renderer, enum wl_shm_format wl_fmt,
|
||||
uint32_t stride, uint32_t width, uint32_t height, const void *data) {
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
return wlr_gles2_texture_from_pixels(renderer->egl, wl_fmt, stride, width,
|
||||
height, data);
|
||||
}
|
||||
|
||||
static struct wlr_texture *gles2_texture_from_wl_drm(
|
||||
struct wlr_renderer *wlr_renderer, struct wl_resource *data) {
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
return wlr_gles2_texture_from_wl_drm(renderer->egl, data);
|
||||
}
|
||||
|
||||
static struct wlr_texture *gles2_texture_from_dmabuf(
|
||||
struct wlr_renderer *wlr_renderer,
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
return wlr_gles2_texture_from_dmabuf(renderer->egl, attribs);
|
||||
}
|
||||
|
||||
static bool gles2_init_wl_display(struct wlr_renderer *wlr_renderer,
|
||||
struct wl_display *wl_display) {
|
||||
struct wlr_gles2_renderer *renderer =
|
||||
|
|
@ -488,6 +653,17 @@ static bool gles2_init_wl_display(struct wlr_renderer *wlr_renderer,
|
|||
return true;
|
||||
}
|
||||
|
||||
static int gles2_get_drm_fd(struct wlr_renderer *wlr_renderer) {
|
||||
struct wlr_gles2_renderer *renderer =
|
||||
gles2_get_renderer(wlr_renderer);
|
||||
|
||||
if (renderer->drm_fd < 0) {
|
||||
renderer->drm_fd = wlr_egl_dup_drm_fd(renderer->egl);
|
||||
}
|
||||
|
||||
return renderer->drm_fd;
|
||||
}
|
||||
|
||||
struct wlr_egl *wlr_gles2_renderer_get_egl(struct wlr_renderer *wlr_renderer) {
|
||||
struct wlr_gles2_renderer *renderer =
|
||||
gles2_get_renderer(wlr_renderer);
|
||||
|
|
@ -499,26 +675,36 @@ static void gles2_destroy(struct wlr_renderer *wlr_renderer) {
|
|||
|
||||
wlr_egl_make_current(renderer->egl, EGL_NO_SURFACE, NULL);
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
struct wlr_gles2_buffer *buffer, *buffer_tmp;
|
||||
wl_list_for_each_safe(buffer, buffer_tmp, &renderer->buffers, link) {
|
||||
destroy_buffer(buffer);
|
||||
}
|
||||
|
||||
push_gles2_debug(renderer);
|
||||
glDeleteProgram(renderer->shaders.quad.program);
|
||||
glDeleteProgram(renderer->shaders.ellipse.program);
|
||||
glDeleteProgram(renderer->shaders.tex_rgba.program);
|
||||
glDeleteProgram(renderer->shaders.tex_rgbx.program);
|
||||
glDeleteProgram(renderer->shaders.tex_ext.program);
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
if (renderer->exts.debug_khr) {
|
||||
glDisable(GL_DEBUG_OUTPUT_KHR);
|
||||
gles2_procs.glDebugMessageCallbackKHR(NULL, NULL);
|
||||
renderer->procs.glDebugMessageCallbackKHR(NULL, NULL);
|
||||
}
|
||||
|
||||
wlr_egl_unset_current(renderer->egl);
|
||||
|
||||
if (renderer->drm_fd >= 0) {
|
||||
close(renderer->drm_fd);
|
||||
}
|
||||
|
||||
free(renderer);
|
||||
}
|
||||
|
||||
static const struct wlr_renderer_impl renderer_impl = {
|
||||
.destroy = gles2_destroy,
|
||||
.bind_buffer = gles2_bind_buffer,
|
||||
.begin = gles2_begin,
|
||||
.end = gles2_end,
|
||||
.clear = gles2_clear,
|
||||
|
|
@ -526,11 +712,11 @@ static const struct wlr_renderer_impl renderer_impl = {
|
|||
.render_subtexture_with_matrix = gles2_render_subtexture_with_matrix,
|
||||
.render_quad_with_matrix = gles2_render_quad_with_matrix,
|
||||
.render_ellipse_with_matrix = gles2_render_ellipse_with_matrix,
|
||||
.formats = gles2_renderer_formats,
|
||||
.format_supported = gles2_format_supported,
|
||||
.get_shm_texture_formats = gles2_get_shm_texture_formats,
|
||||
.resource_is_wl_drm_buffer = gles2_resource_is_wl_drm_buffer,
|
||||
.wl_drm_buffer_get_size = gles2_wl_drm_buffer_get_size,
|
||||
.get_dmabuf_formats = gles2_get_dmabuf_formats,
|
||||
.get_dmabuf_texture_formats = gles2_get_dmabuf_texture_formats,
|
||||
.get_dmabuf_render_formats = gles2_get_dmabuf_render_formats,
|
||||
.preferred_read_format = gles2_preferred_read_format,
|
||||
.read_pixels = gles2_read_pixels,
|
||||
.texture_from_pixels = gles2_texture_from_pixels,
|
||||
|
|
@ -538,22 +724,24 @@ static const struct wlr_renderer_impl renderer_impl = {
|
|||
.texture_from_dmabuf = gles2_texture_from_dmabuf,
|
||||
.init_wl_display = gles2_init_wl_display,
|
||||
.blit_dmabuf = gles2_blit_dmabuf,
|
||||
.get_drm_fd = gles2_get_drm_fd,
|
||||
};
|
||||
|
||||
void push_gles2_marker(const char *file, const char *func) {
|
||||
if (!gles2_procs.glPushDebugGroupKHR) {
|
||||
void push_gles2_debug_(struct wlr_gles2_renderer *renderer,
|
||||
const char *file, const char *func) {
|
||||
if (!renderer->procs.glPushDebugGroupKHR) {
|
||||
return;
|
||||
}
|
||||
|
||||
int len = snprintf(NULL, 0, "%s:%s", file, func) + 1;
|
||||
char str[len];
|
||||
snprintf(str, len, "%s:%s", file, func);
|
||||
gles2_procs.glPushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION_KHR, 1, -1, str);
|
||||
renderer->procs.glPushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION_KHR, 1, -1, str);
|
||||
}
|
||||
|
||||
void pop_gles2_marker(void) {
|
||||
if (gles2_procs.glPopDebugGroupKHR) {
|
||||
gles2_procs.glPopDebugGroupKHR();
|
||||
void pop_gles2_debug(struct wlr_gles2_renderer *renderer) {
|
||||
if (renderer->procs.glPopDebugGroupKHR) {
|
||||
renderer->procs.glPopDebugGroupKHR();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -577,8 +765,9 @@ static void gles2_log(GLenum src, GLenum type, GLuint id, GLenum severity,
|
|||
_wlr_log(gles2_log_importance_to_wlr(type), "[GLES2] %s", msg);
|
||||
}
|
||||
|
||||
static GLuint compile_shader(GLuint type, const GLchar *src) {
|
||||
PUSH_GLES2_DEBUG;
|
||||
static GLuint compile_shader(struct wlr_gles2_renderer *renderer,
|
||||
GLuint type, const GLchar *src) {
|
||||
push_gles2_debug(renderer);
|
||||
|
||||
GLuint shader = glCreateShader(type);
|
||||
glShaderSource(shader, 1, &src, NULL);
|
||||
|
|
@ -591,19 +780,20 @@ static GLuint compile_shader(GLuint type, const GLchar *src) {
|
|||
shader = 0;
|
||||
}
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
return shader;
|
||||
}
|
||||
|
||||
static GLuint link_program(const GLchar *vert_src, const GLchar *frag_src) {
|
||||
PUSH_GLES2_DEBUG;
|
||||
static GLuint link_program(struct wlr_gles2_renderer *renderer,
|
||||
const GLchar *vert_src, const GLchar *frag_src) {
|
||||
push_gles2_debug(renderer);
|
||||
|
||||
GLuint vert = compile_shader(GL_VERTEX_SHADER, vert_src);
|
||||
GLuint vert = compile_shader(renderer, GL_VERTEX_SHADER, vert_src);
|
||||
if (!vert) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
GLuint frag = compile_shader(GL_FRAGMENT_SHADER, frag_src);
|
||||
GLuint frag = compile_shader(renderer, GL_FRAGMENT_SHADER, frag_src);
|
||||
if (!frag) {
|
||||
glDeleteShader(vert);
|
||||
goto error;
|
||||
|
|
@ -626,11 +816,11 @@ static GLuint link_program(const GLchar *vert_src, const GLchar *frag_src) {
|
|||
goto error;
|
||||
}
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
return prog;
|
||||
|
||||
error:
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -687,8 +877,11 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||
}
|
||||
wlr_renderer_init(&renderer->wlr_renderer, &renderer_impl);
|
||||
|
||||
wl_list_init(&renderer->buffers);
|
||||
|
||||
renderer->egl = egl;
|
||||
renderer->exts_str = exts_str;
|
||||
renderer->drm_fd = -1;
|
||||
|
||||
wlr_log(WLR_INFO, "Using %s", glGetString(GL_VERSION));
|
||||
wlr_log(WLR_INFO, "GL vendor: %s", glGetString(GL_VENDOR));
|
||||
|
|
@ -700,47 +893,52 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||
free(renderer);
|
||||
return NULL;
|
||||
}
|
||||
if (!check_gl_ext(exts_str, "GL_EXT_unpack_subimage")) {
|
||||
wlr_log(WLR_ERROR, "GL_EXT_unpack_subimage not supported");
|
||||
free(renderer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
renderer->exts.read_format_bgra_ext =
|
||||
check_gl_ext(exts_str, "GL_EXT_read_format_bgra");
|
||||
|
||||
if (check_gl_ext(exts_str, "GL_KHR_debug")) {
|
||||
renderer->exts.debug_khr = true;
|
||||
load_gl_proc(&gles2_procs.glDebugMessageCallbackKHR,
|
||||
load_gl_proc(&renderer->procs.glDebugMessageCallbackKHR,
|
||||
"glDebugMessageCallbackKHR");
|
||||
load_gl_proc(&gles2_procs.glDebugMessageControlKHR,
|
||||
load_gl_proc(&renderer->procs.glDebugMessageControlKHR,
|
||||
"glDebugMessageControlKHR");
|
||||
}
|
||||
|
||||
if (check_gl_ext(exts_str, "GL_OES_EGL_image_external")) {
|
||||
renderer->exts.egl_image_external_oes = true;
|
||||
load_gl_proc(&gles2_procs.glEGLImageTargetTexture2DOES,
|
||||
load_gl_proc(&renderer->procs.glEGLImageTargetTexture2DOES,
|
||||
"glEGLImageTargetTexture2DOES");
|
||||
}
|
||||
|
||||
if (check_gl_ext(exts_str, "GL_OES_EGL_image")) {
|
||||
renderer->exts.egl_image_oes = true;
|
||||
load_gl_proc(&gles2_procs.glEGLImageTargetRenderbufferStorageOES,
|
||||
load_gl_proc(&renderer->procs.glEGLImageTargetRenderbufferStorageOES,
|
||||
"glEGLImageTargetRenderbufferStorageOES");
|
||||
}
|
||||
|
||||
if (renderer->exts.debug_khr) {
|
||||
glEnable(GL_DEBUG_OUTPUT_KHR);
|
||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR);
|
||||
gles2_procs.glDebugMessageCallbackKHR(gles2_log, NULL);
|
||||
renderer->procs.glDebugMessageCallbackKHR(gles2_log, NULL);
|
||||
|
||||
// Silence unwanted message types
|
||||
gles2_procs.glDebugMessageControlKHR(GL_DONT_CARE,
|
||||
renderer->procs.glDebugMessageControlKHR(GL_DONT_CARE,
|
||||
GL_DEBUG_TYPE_POP_GROUP_KHR, GL_DONT_CARE, 0, NULL, GL_FALSE);
|
||||
gles2_procs.glDebugMessageControlKHR(GL_DONT_CARE,
|
||||
renderer->procs.glDebugMessageControlKHR(GL_DONT_CARE,
|
||||
GL_DEBUG_TYPE_PUSH_GROUP_KHR, GL_DONT_CARE, 0, NULL, GL_FALSE);
|
||||
}
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(renderer);
|
||||
|
||||
GLuint prog;
|
||||
renderer->shaders.quad.program = prog =
|
||||
link_program(quad_vertex_src, quad_fragment_src);
|
||||
link_program(renderer, quad_vertex_src, quad_fragment_src);
|
||||
if (!renderer->shaders.quad.program) {
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -749,7 +947,7 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||
renderer->shaders.quad.pos_attrib = glGetAttribLocation(prog, "pos");
|
||||
|
||||
renderer->shaders.ellipse.program = prog =
|
||||
link_program(quad_vertex_src, ellipse_fragment_src);
|
||||
link_program(renderer, quad_vertex_src, ellipse_fragment_src);
|
||||
if (!renderer->shaders.ellipse.program) {
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -759,7 +957,7 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||
renderer->shaders.ellipse.tex_attrib = glGetAttribLocation(prog, "texcoord");
|
||||
|
||||
renderer->shaders.tex_rgba.program = prog =
|
||||
link_program(tex_vertex_src, tex_fragment_src_rgba);
|
||||
link_program(renderer, tex_vertex_src, tex_fragment_src_rgba);
|
||||
if (!renderer->shaders.tex_rgba.program) {
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -771,7 +969,7 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||
renderer->shaders.tex_rgba.tex_attrib = glGetAttribLocation(prog, "texcoord");
|
||||
|
||||
renderer->shaders.tex_rgbx.program = prog =
|
||||
link_program(tex_vertex_src, tex_fragment_src_rgbx);
|
||||
link_program(renderer, tex_vertex_src, tex_fragment_src_rgbx);
|
||||
if (!renderer->shaders.tex_rgbx.program) {
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -784,7 +982,7 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||
|
||||
if (renderer->exts.egl_image_external_oes) {
|
||||
renderer->shaders.tex_ext.program = prog =
|
||||
link_program(tex_vertex_src, tex_fragment_src_external);
|
||||
link_program(renderer, tex_vertex_src, tex_fragment_src_external);
|
||||
if (!renderer->shaders.tex_ext.program) {
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -796,7 +994,7 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||
renderer->shaders.tex_ext.tex_attrib = glGetAttribLocation(prog, "texcoord");
|
||||
}
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
wlr_egl_unset_current(renderer->egl);
|
||||
|
||||
|
|
@ -809,11 +1007,11 @@ error:
|
|||
glDeleteProgram(renderer->shaders.tex_rgbx.program);
|
||||
glDeleteProgram(renderer->shaders.tex_ext.program);
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
if (renderer->exts.debug_khr) {
|
||||
glDisable(GL_DEBUG_OUTPUT_KHR);
|
||||
gles2_procs.glDebugMessageCallbackKHR(NULL, NULL);
|
||||
renderer->procs.glDebugMessageCallbackKHR(NULL, NULL);
|
||||
}
|
||||
|
||||
wlr_egl_unset_current(renderer->egl);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ struct wlr_gles2_texture *gles2_get_texture(
|
|||
static struct wlr_gles2_texture *get_gles2_texture_in_context(
|
||||
struct wlr_texture *wlr_texture) {
|
||||
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
|
||||
wlr_egl_make_current(texture->egl, EGL_NO_SURFACE, NULL);
|
||||
wlr_egl_make_current(texture->renderer->egl, EGL_NO_SURFACE, NULL);
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
|
|||
|
||||
if (texture->target != GL_TEXTURE_2D) {
|
||||
wlr_log(WLR_ERROR, "Cannot write pixels to immutable texture");
|
||||
wlr_egl_unset_current(texture->egl);
|
||||
wlr_egl_unset_current(texture->renderer->egl);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -55,8 +55,7 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
|
|||
get_gles2_format_from_wl(texture->wl_format);
|
||||
assert(fmt);
|
||||
|
||||
// TODO: what if the unpack subimage extension isn't supported?
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(texture->renderer);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture->tex);
|
||||
|
||||
|
|
@ -73,9 +72,9 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
|
|||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(texture->renderer);
|
||||
|
||||
wlr_egl_unset_current(texture->egl);
|
||||
wlr_egl_unset_current(texture->renderer->egl);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -86,12 +85,12 @@ static bool gles2_texture_to_dmabuf(struct wlr_texture *wlr_texture,
|
|||
if (!texture->image) {
|
||||
assert(texture->target == GL_TEXTURE_2D);
|
||||
|
||||
if (!texture->egl->exts.image_base_khr) {
|
||||
if (!texture->renderer->egl->exts.image_base_khr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
texture->image = texture->egl->procs.eglCreateImageKHR(
|
||||
texture->egl->display, texture->egl->context, EGL_GL_TEXTURE_2D_KHR,
|
||||
texture->image = texture->renderer->egl->procs.eglCreateImageKHR(
|
||||
texture->renderer->egl->display, texture->renderer->egl->context, EGL_GL_TEXTURE_2D_KHR,
|
||||
(EGLClientBuffer)(uintptr_t)texture->tex, NULL);
|
||||
if (texture->image == EGL_NO_IMAGE_KHR) {
|
||||
return false;
|
||||
|
|
@ -103,7 +102,7 @@ static bool gles2_texture_to_dmabuf(struct wlr_texture *wlr_texture,
|
|||
flags |= WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT;
|
||||
}
|
||||
|
||||
return wlr_egl_export_image_to_dmabuf(texture->egl, texture->image,
|
||||
return wlr_egl_export_image_to_dmabuf(texture->renderer->egl, texture->image,
|
||||
wlr_texture->width, wlr_texture->height, flags, attribs);
|
||||
}
|
||||
|
||||
|
|
@ -115,14 +114,14 @@ static void gles2_texture_destroy(struct wlr_texture *wlr_texture) {
|
|||
struct wlr_gles2_texture *texture =
|
||||
get_gles2_texture_in_context(wlr_texture);
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(texture->renderer);
|
||||
|
||||
glDeleteTextures(1, &texture->tex);
|
||||
wlr_egl_destroy_image(texture->egl, texture->image);
|
||||
wlr_egl_destroy_image(texture->renderer->egl, texture->image);
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(texture->renderer);
|
||||
|
||||
wlr_egl_unset_current(texture->egl);
|
||||
wlr_egl_unset_current(texture->renderer->egl);
|
||||
|
||||
free(texture);
|
||||
}
|
||||
|
|
@ -134,10 +133,12 @@ static const struct wlr_texture_impl texture_impl = {
|
|||
.destroy = gles2_texture_destroy,
|
||||
};
|
||||
|
||||
struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl,
|
||||
struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer,
|
||||
enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width,
|
||||
uint32_t height, const void *data) {
|
||||
wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
|
||||
wlr_egl_make_current(renderer->egl, EGL_NO_SURFACE, NULL);
|
||||
|
||||
const struct wlr_gles2_pixel_format *fmt = get_gles2_format_from_wl(wl_fmt);
|
||||
if (fmt == NULL) {
|
||||
|
|
@ -152,12 +153,12 @@ struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl,
|
|||
return NULL;
|
||||
}
|
||||
wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
|
||||
texture->egl = egl;
|
||||
texture->renderer = renderer;
|
||||
texture->target = GL_TEXTURE_2D;
|
||||
texture->has_alpha = fmt->has_alpha;
|
||||
texture->wl_format = fmt->wl_format;
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(renderer);
|
||||
|
||||
glGenTextures(1, &texture->tex);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->tex);
|
||||
|
|
@ -169,24 +170,26 @@ struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl,
|
|||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
wlr_egl_unset_current(egl);
|
||||
wlr_egl_unset_current(renderer->egl);
|
||||
return &texture->wlr_texture;
|
||||
}
|
||||
|
||||
struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
|
||||
struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer,
|
||||
struct wl_resource *resource) {
|
||||
wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
|
||||
if (!gles2_procs.glEGLImageTargetTexture2DOES) {
|
||||
wlr_egl_make_current(renderer->egl, EGL_NO_SURFACE, NULL);
|
||||
|
||||
if (!renderer->procs.glEGLImageTargetTexture2DOES) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EGLint fmt;
|
||||
int width, height;
|
||||
bool inverted_y;
|
||||
EGLImageKHR image = wlr_egl_create_image_from_wl_drm(egl, resource,
|
||||
EGLImageKHR image = wlr_egl_create_image_from_wl_drm(renderer->egl, resource,
|
||||
&fmt, &width, &height, &inverted_y);
|
||||
if (image == EGL_NO_IMAGE_KHR) {
|
||||
wlr_log(WLR_ERROR, "Failed to create EGL image from wl_drm resource");
|
||||
|
|
@ -197,11 +200,11 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
|
|||
calloc(1, sizeof(struct wlr_gles2_texture));
|
||||
if (texture == NULL) {
|
||||
wlr_log(WLR_ERROR, "Allocation failed");
|
||||
wlr_egl_destroy_image(egl, image);
|
||||
wlr_egl_destroy_image(renderer->egl, image);
|
||||
return NULL;
|
||||
}
|
||||
wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
|
||||
texture->egl = egl;
|
||||
texture->renderer = renderer;
|
||||
|
||||
texture->wl_format = 0xFFFFFFFF; // texture can't be written anyways
|
||||
texture->image = image;
|
||||
|
|
@ -217,36 +220,38 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
|
|||
break;
|
||||
default:
|
||||
wlr_log(WLR_ERROR, "Invalid or unsupported EGL buffer format");
|
||||
wlr_egl_destroy_image(egl, image);
|
||||
wlr_egl_destroy_image(renderer->egl, image);
|
||||
free(texture);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
texture->target = GL_TEXTURE_EXTERNAL_OES;
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(renderer);
|
||||
|
||||
glGenTextures(1, &texture->tex);
|
||||
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture->tex);
|
||||
gles2_procs.glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES,
|
||||
renderer->procs.glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES,
|
||||
texture->image);
|
||||
glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
wlr_egl_unset_current(egl);
|
||||
wlr_egl_unset_current(renderer->egl);
|
||||
return &texture->wlr_texture;
|
||||
}
|
||||
|
||||
struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
|
||||
struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer,
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
|
||||
if (!gles2_procs.glEGLImageTargetTexture2DOES) {
|
||||
wlr_egl_make_current(renderer->egl, EGL_NO_SURFACE, NULL);
|
||||
|
||||
if (!renderer->procs.glEGLImageTargetTexture2DOES) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!egl->exts.image_dmabuf_import_ext) {
|
||||
if (!renderer->egl->exts.image_dmabuf_import_ext) {
|
||||
wlr_log(WLR_ERROR, "Cannot create DMA-BUF texture: EGL extension "
|
||||
"unavailable");
|
||||
return NULL;
|
||||
|
|
@ -272,7 +277,7 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
|
|||
}
|
||||
wlr_texture_init(&texture->wlr_texture, &texture_impl,
|
||||
attribs->width, attribs->height);
|
||||
texture->egl = egl;
|
||||
texture->renderer = renderer;
|
||||
texture->has_alpha = true;
|
||||
texture->wl_format = 0xFFFFFFFF; // texture can't be written anyways
|
||||
texture->inverted_y =
|
||||
|
|
@ -280,7 +285,7 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
|
|||
|
||||
bool external_only;
|
||||
texture->image =
|
||||
wlr_egl_create_image_from_dmabuf(egl, attribs, &external_only);
|
||||
wlr_egl_create_image_from_dmabuf(renderer->egl, attribs, &external_only);
|
||||
if (texture->image == EGL_NO_IMAGE_KHR) {
|
||||
wlr_log(WLR_ERROR, "Failed to create EGL image from DMA-BUF");
|
||||
free(texture);
|
||||
|
|
@ -289,16 +294,16 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
|
|||
|
||||
texture->target = external_only ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D;
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
push_gles2_debug(renderer);
|
||||
|
||||
glGenTextures(1, &texture->tex);
|
||||
glBindTexture(texture->target, texture->tex);
|
||||
gles2_procs.glEGLImageTargetTexture2DOES(texture->target, texture->image);
|
||||
renderer->procs.glEGLImageTargetTexture2DOES(texture->target, texture->image);
|
||||
glBindTexture(texture->target, 0);
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
wlr_egl_unset_current(egl);
|
||||
wlr_egl_unset_current(renderer->egl);
|
||||
return &texture->wlr_texture;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
wlr_files += files(
|
||||
'allocator.c',
|
||||
'dmabuf.c',
|
||||
'egl.c',
|
||||
'drm_format_set.c',
|
||||
'gbm_allocator.c',
|
||||
'gles2/pixel_format.c',
|
||||
'gles2/renderer.c',
|
||||
'gles2/shaders.c',
|
||||
'gles2/texture.c',
|
||||
'swapchain.c',
|
||||
'wlr_renderer.c',
|
||||
'wlr_texture.c',
|
||||
)
|
||||
|
|
|
|||
144
render/swapchain.c
Normal file
144
render/swapchain.c
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <wlr/types/wlr_buffer.h>
|
||||
#include "render/allocator.h"
|
||||
#include "render/drm_format_set.h"
|
||||
#include "render/swapchain.h"
|
||||
|
||||
static void swapchain_handle_allocator_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_swapchain *swapchain =
|
||||
wl_container_of(listener, swapchain, allocator_destroy);
|
||||
swapchain->allocator = NULL;
|
||||
}
|
||||
|
||||
struct wlr_swapchain *wlr_swapchain_create(
|
||||
struct wlr_allocator *alloc, int width, int height,
|
||||
const struct wlr_drm_format *format) {
|
||||
struct wlr_swapchain *swapchain = calloc(1, sizeof(*swapchain));
|
||||
if (swapchain == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
swapchain->allocator = alloc;
|
||||
swapchain->width = width;
|
||||
swapchain->height = height;
|
||||
|
||||
swapchain->format = wlr_drm_format_dup(format);
|
||||
if (swapchain->format == NULL) {
|
||||
free(swapchain);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
swapchain->allocator_destroy.notify = swapchain_handle_allocator_destroy;
|
||||
wl_signal_add(&alloc->events.destroy, &swapchain->allocator_destroy);
|
||||
|
||||
return swapchain;
|
||||
}
|
||||
|
||||
static void slot_reset(struct wlr_swapchain_slot *slot) {
|
||||
if (slot->acquired) {
|
||||
wl_list_remove(&slot->release.link);
|
||||
}
|
||||
wlr_buffer_drop(slot->buffer);
|
||||
memset(slot, 0, sizeof(*slot));
|
||||
}
|
||||
|
||||
void wlr_swapchain_destroy(struct wlr_swapchain *swapchain) {
|
||||
if (swapchain == NULL) {
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < WLR_SWAPCHAIN_CAP; i++) {
|
||||
slot_reset(&swapchain->slots[i]);
|
||||
}
|
||||
wl_list_remove(&swapchain->allocator_destroy.link);
|
||||
free(swapchain->format);
|
||||
free(swapchain);
|
||||
}
|
||||
|
||||
static void slot_handle_release(struct wl_listener *listener, void *data) {
|
||||
struct wlr_swapchain_slot *slot =
|
||||
wl_container_of(listener, slot, release);
|
||||
wl_list_remove(&slot->release.link);
|
||||
slot->acquired = false;
|
||||
}
|
||||
|
||||
static struct wlr_buffer *slot_acquire(struct wlr_swapchain *swapchain,
|
||||
struct wlr_swapchain_slot *slot, int *age) {
|
||||
assert(!slot->acquired);
|
||||
assert(slot->buffer != NULL);
|
||||
|
||||
slot->acquired = true;
|
||||
|
||||
slot->release.notify = slot_handle_release;
|
||||
wl_signal_add(&slot->buffer->events.release, &slot->release);
|
||||
|
||||
if (age != NULL) {
|
||||
*age = slot->age;
|
||||
}
|
||||
|
||||
return wlr_buffer_lock(slot->buffer);
|
||||
}
|
||||
|
||||
struct wlr_buffer *wlr_swapchain_acquire(struct wlr_swapchain *swapchain,
|
||||
int *age) {
|
||||
struct wlr_swapchain_slot *free_slot = NULL;
|
||||
for (size_t i = 0; i < WLR_SWAPCHAIN_CAP; i++) {
|
||||
struct wlr_swapchain_slot *slot = &swapchain->slots[i];
|
||||
if (slot->acquired) {
|
||||
continue;
|
||||
}
|
||||
if (slot->buffer != NULL) {
|
||||
return slot_acquire(swapchain, slot, age);
|
||||
}
|
||||
free_slot = slot;
|
||||
}
|
||||
if (free_slot == NULL) {
|
||||
wlr_log(WLR_ERROR, "No free output buffer slot");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (swapchain->allocator == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wlr_log(WLR_DEBUG, "Allocating new swapchain buffer");
|
||||
free_slot->buffer = wlr_allocator_create_buffer(swapchain->allocator,
|
||||
swapchain->width, swapchain->height, swapchain->format);
|
||||
if (free_slot->buffer == NULL) {
|
||||
wlr_log(WLR_ERROR, "Failed to allocate buffer");
|
||||
return NULL;
|
||||
}
|
||||
return slot_acquire(swapchain, free_slot, age);
|
||||
}
|
||||
|
||||
static bool swapchain_has_buffer(struct wlr_swapchain *swapchain,
|
||||
struct wlr_buffer *buffer) {
|
||||
for (size_t i = 0; i < WLR_SWAPCHAIN_CAP; i++) {
|
||||
struct wlr_swapchain_slot *slot = &swapchain->slots[i];
|
||||
if (slot->buffer == buffer) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void wlr_swapchain_set_buffer_submitted(struct wlr_swapchain *swapchain,
|
||||
struct wlr_buffer *buffer) {
|
||||
assert(buffer != NULL);
|
||||
|
||||
if (!swapchain_has_buffer(swapchain, buffer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// See the algorithm described in:
|
||||
// https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_buffer_age.txt
|
||||
for (size_t i = 0; i < WLR_SWAPCHAIN_CAP; i++) {
|
||||
struct wlr_swapchain_slot *slot = &swapchain->slots[i];
|
||||
if (slot->buffer == buffer) {
|
||||
slot->age = 1;
|
||||
} else if (slot->age > 0) {
|
||||
slot->age++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
#include <wlr/types/wlr_matrix.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "util/signal.h"
|
||||
#include "render/wlr_renderer.h"
|
||||
|
||||
void wlr_renderer_init(struct wlr_renderer *renderer,
|
||||
const struct wlr_renderer_impl *impl) {
|
||||
|
|
@ -16,8 +17,7 @@ void wlr_renderer_init(struct wlr_renderer *renderer,
|
|||
assert(impl->render_subtexture_with_matrix);
|
||||
assert(impl->render_quad_with_matrix);
|
||||
assert(impl->render_ellipse_with_matrix);
|
||||
assert(impl->formats);
|
||||
assert(impl->format_supported);
|
||||
assert(impl->get_shm_texture_formats);
|
||||
assert(impl->texture_from_pixels);
|
||||
renderer->impl = impl;
|
||||
|
||||
|
|
@ -37,7 +37,16 @@ void wlr_renderer_destroy(struct wlr_renderer *r) {
|
|||
}
|
||||
}
|
||||
|
||||
void wlr_renderer_begin(struct wlr_renderer *r, int width, int height) {
|
||||
bool wlr_renderer_bind_buffer(struct wlr_renderer *r,
|
||||
struct wlr_buffer *buffer) {
|
||||
assert(!r->rendering);
|
||||
if (!r->impl->bind_buffer) {
|
||||
return false;
|
||||
}
|
||||
return r->impl->bind_buffer(r, buffer);
|
||||
}
|
||||
|
||||
void wlr_renderer_begin(struct wlr_renderer *r, uint32_t width, uint32_t height) {
|
||||
assert(!r->rendering);
|
||||
|
||||
r->impl->begin(r, width, height);
|
||||
|
|
@ -99,6 +108,9 @@ bool wlr_render_subtexture_with_matrix(struct wlr_renderer *r,
|
|||
|
||||
void wlr_render_rect(struct wlr_renderer *r, const struct wlr_box *box,
|
||||
const float color[static 4], const float projection[static 9]) {
|
||||
if (box->width == 0 || box->height == 0) {
|
||||
return;
|
||||
}
|
||||
assert(box->width > 0 && box->height > 0);
|
||||
float matrix[9];
|
||||
wlr_matrix_project_box(matrix, box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
|
||||
|
|
@ -115,6 +127,9 @@ void wlr_render_quad_with_matrix(struct wlr_renderer *r,
|
|||
|
||||
void wlr_render_ellipse(struct wlr_renderer *r, const struct wlr_box *box,
|
||||
const float color[static 4], const float projection[static 9]) {
|
||||
if (box->width == 0 || box->height == 0) {
|
||||
return;
|
||||
}
|
||||
assert(box->width > 0 && box->height > 0);
|
||||
float matrix[9];
|
||||
wlr_matrix_project_box(matrix, box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
|
||||
|
|
@ -129,9 +144,9 @@ void wlr_render_ellipse_with_matrix(struct wlr_renderer *r,
|
|||
r->impl->render_ellipse_with_matrix(r, color, matrix);
|
||||
}
|
||||
|
||||
const enum wl_shm_format *wlr_renderer_get_formats(
|
||||
const enum wl_shm_format *wlr_renderer_get_shm_texture_formats(
|
||||
struct wlr_renderer *r, size_t *len) {
|
||||
return r->impl->formats(r, len);
|
||||
return r->impl->get_shm_texture_formats(r, len);
|
||||
}
|
||||
|
||||
bool wlr_renderer_resource_is_wl_drm_buffer(struct wlr_renderer *r,
|
||||
|
|
@ -150,12 +165,20 @@ void wlr_renderer_wl_drm_buffer_get_size(struct wlr_renderer *r,
|
|||
return r->impl->wl_drm_buffer_get_size(r, buffer, width, height);
|
||||
}
|
||||
|
||||
const struct wlr_drm_format_set *wlr_renderer_get_dmabuf_formats(
|
||||
const struct wlr_drm_format_set *wlr_renderer_get_dmabuf_texture_formats(
|
||||
struct wlr_renderer *r) {
|
||||
if (!r->impl->get_dmabuf_formats) {
|
||||
if (!r->impl->get_dmabuf_texture_formats) {
|
||||
return NULL;
|
||||
}
|
||||
return r->impl->get_dmabuf_formats(r);
|
||||
return r->impl->get_dmabuf_texture_formats(r);
|
||||
}
|
||||
|
||||
const struct wlr_drm_format_set *wlr_renderer_get_dmabuf_render_formats(
|
||||
struct wlr_renderer *r) {
|
||||
if (!r->impl->get_dmabuf_render_formats) {
|
||||
return NULL;
|
||||
}
|
||||
return r->impl->get_dmabuf_render_formats(r);
|
||||
}
|
||||
|
||||
bool wlr_renderer_read_pixels(struct wlr_renderer *r, enum wl_shm_format fmt,
|
||||
|
|
@ -179,11 +202,6 @@ bool wlr_renderer_blit_dmabuf(struct wlr_renderer *r,
|
|||
return r->impl->blit_dmabuf(r, dst, src);
|
||||
}
|
||||
|
||||
bool wlr_renderer_format_supported(struct wlr_renderer *r,
|
||||
enum wl_shm_format fmt) {
|
||||
return r->impl->format_supported(r, fmt);
|
||||
}
|
||||
|
||||
bool wlr_renderer_init_wl_display(struct wlr_renderer *r,
|
||||
struct wl_display *wl_display) {
|
||||
if (wl_display_init_shm(wl_display)) {
|
||||
|
|
@ -192,19 +210,29 @@ bool wlr_renderer_init_wl_display(struct wlr_renderer *r,
|
|||
}
|
||||
|
||||
size_t len;
|
||||
const enum wl_shm_format *formats = wlr_renderer_get_formats(r, &len);
|
||||
const enum wl_shm_format *formats =
|
||||
wlr_renderer_get_shm_texture_formats(r, &len);
|
||||
if (formats == NULL) {
|
||||
wlr_log(WLR_ERROR, "Failed to initialize shm: cannot get formats");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool argb8888 = false, xrgb8888 = false;
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
// These formats are already added by default
|
||||
if (formats[i] != WL_SHM_FORMAT_ARGB8888 &&
|
||||
formats[i] != WL_SHM_FORMAT_XRGB8888) {
|
||||
// ARGB8888 and XRGB8888 must be supported and are implicitly
|
||||
// advertised by wl_display_init_shm
|
||||
switch (formats[i]) {
|
||||
case WL_SHM_FORMAT_ARGB8888:
|
||||
argb8888 = true;
|
||||
break;
|
||||
case WL_SHM_FORMAT_XRGB8888:
|
||||
xrgb8888 = true;
|
||||
break;
|
||||
default:
|
||||
wl_display_add_shm_format(wl_display, formats[i]);
|
||||
}
|
||||
}
|
||||
assert(argb8888 && xrgb8888);
|
||||
|
||||
if (r->impl->init_wl_display) {
|
||||
if (!r->impl->init_wl_display(r, wl_display)) {
|
||||
|
|
@ -240,7 +268,11 @@ struct wlr_renderer *wlr_renderer_autocreate(struct wlr_egl *egl,
|
|||
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,
|
||||
if (config_attribs != NULL) {
|
||||
config_attribs = all_config_attribs;
|
||||
}
|
||||
|
||||
if (!wlr_egl_init(egl, platform, remote_display, config_attribs,
|
||||
visual_id)) {
|
||||
wlr_log(WLR_ERROR, "Could not initialize EGL");
|
||||
return NULL;
|
||||
|
|
@ -253,3 +285,10 @@ struct wlr_renderer *wlr_renderer_autocreate(struct wlr_egl *egl,
|
|||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
int wlr_renderer_get_drm_fd(struct wlr_renderer *r) {
|
||||
if (!r->impl->get_drm_fd) {
|
||||
return -1;
|
||||
}
|
||||
return r->impl->get_drm_fd(r);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue