Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
render/gles: Add shm initialisation and interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ascent12 committed Jan 25, 2019
1 parent 8ebc579 commit 19bb46a
Show file tree
Hide file tree
Showing 14 changed files with 538 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ int main(void) {
return 1;
}

st.renderer = wlr_renderer_autocreate_2(st.backend);
st.renderer = wlr_renderer_autocreate_2(st.display, st.backend);
if (!st.renderer) {
return 1;
}
Expand Down
76 changes: 75 additions & 1 deletion include/render/renderer/gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,40 @@
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <pixman.h>
#include <wayland-server.h>

#include <wlr/render/allocator/gbm.h>
#include <wlr/render/egl.h>
#include <wlr/render/format_set.h>
#include <wlr/render/renderer.h>

struct wlr_gles {
struct wlr_renderer_2 base;
struct wl_display *display;
struct wlr_backend *backend;

struct wlr_gbm_allocator *gbm;
struct wlr_egl_2 *egl;

PFNGLEGLIMAGETARGETTEXTURE2DOESPROC egl_image_target_texture;
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC egl_image_target_texture_2d;
PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC egl_image_target_renderbuffer;

// Optional extensions
bool has_required_internalformat;
bool has_texture_type_2_10_10_10_rev;
bool has_unpack_subimage;

struct wlr_format_set shm_formats;
};

struct wlr_gles_rgb_format {
uint32_t fourcc;
GLenum format;
GLenum type;
bool opaque;
// Requires GL_EXT_texture_type_2_10_10_10_REV
bool is_10bit;
};

struct wlr_gles_image {
Expand All @@ -27,4 +47,58 @@ struct wlr_gles_image {
GLuint renderbuffer;
};

enum wlr_gles_texture_type {
// No client buffer attached
WLR_GLES_TEXTURE_NULL,
// Created locally from raw pixels, and not any client buffers
WLR_GLES_TEXTURE_PIXELS,
// zwp_linux_dmabuf_v1
WLR_GLES_TEXTURE_DMABUF,
// EGL_WL_bind_wayland_display
WLR_GLES_TEXTURE_EGL,
// wl_shm
WLR_GLES_TEXTURE_SHM,
};

struct wlr_gles_texture {
struct wlr_texture_2 base;
struct wlr_gles *gles;

/*
* We perform all allocations using GBM, so that we have the possibility
* of directy scanning-out as many clients as we possibly can.
*
* We reuse the wlr_gbm_image type so that we can pass it to
* wlr_backend_attach_gbm. The renderer_private field will be NULL,
* so it can be distinguished from GBM images created by a
* wlr_allocator.
*/
struct wlr_gbm_image img;

enum wlr_gles_texture_type type;
struct wl_resource *resource;
const struct wlr_gles_rgb_format *fmt;
/*
* GL_TEXTURE_2D for PIXELS and SHM
* GL_TEXTURE_EXTERNAL_OES for DMABUF and EGL
*
* As such, you cannot call gl*Tex*Image*() on DMABUF/EGL, and they
* should be considered immutable. It also affects what shader you need
* to render them.
*
* See the specifications of OES_EGL_image and OES_EGL_image_external
* for more information.
*/
EGLImageKHR egl;
GLuint texture;
};

struct wlr_gles_texture *gles_texture_create(struct wlr_gles *gles);

const struct wlr_gles_rgb_format *gles_rgb_format_from_fourcc(
struct wlr_gles *gles, uint32_t fourcc);
const struct wlr_gles_rgb_format *gles_rgb_format_from_gl(struct wlr_gles *gles,
GLenum format, GLenum type);
bool gles_populate_shm_formats(struct wlr_gles *gles);

#endif
2 changes: 1 addition & 1 deletion include/wlr/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

#include <wayland-server.h>
#include <wlr/backend/session.h>
#include <wlr/render/allocator/gbm.h>
#include <wlr/render/egl.h>

struct wlr_backend_impl;
struct wlr_gbm_image;

struct wlr_backend {
const struct wlr_backend_impl *impl;
Expand Down
5 changes: 5 additions & 0 deletions include/wlr/render/allocator/gbm.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ struct wlr_gbm_image {
void *renderer_priv;
};

struct wlr_gbm_allocator_impl {
bool (*create)(void *userdata, struct wlr_gbm_image *img);
void (*destroy)(void *userdata, struct wlr_gbm_image *img);
};

typedef bool (*wlr_gbm_create_func_t)(void *, struct wlr_gbm_image *);
typedef void (*wlr_gbm_destroy_func_t)(void *, struct wlr_gbm_image *);

Expand Down
5 changes: 5 additions & 0 deletions include/wlr/render/allocator/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
#include <stddef.h>
#include <stdint.h>

#include <wayland-server.h>

struct wlr_allocator;
struct wlr_backend;
struct wlr_dmabuf_attribs;
struct wlr_external_image;
struct wlr_image;

struct wlr_allocator_impl {
struct wlr_image *(*allocate)(struct wlr_allocator *alloc,
Expand Down
19 changes: 18 additions & 1 deletion include/wlr/render/renderer.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#ifndef WLR_RENDER_RENDERER_H
#define WLR_RENDER_RENDERER_H

#include <stdbool.h>

#include <pixman.h>
#include <wayland-server.h>

struct wlr_allocator;
struct wlr_backend;
struct wlr_image;
struct wlr_renderer_impl_2;
struct wlr_texture_impl_2;

struct wlr_renderer_2 {
const struct wlr_renderer_impl_2 *impl;
Expand All @@ -16,7 +20,12 @@ struct wlr_renderer_2 {
} events;
};

struct wlr_renderer_2 *wlr_renderer_autocreate_2(struct wlr_backend *backend);
struct wlr_texture_2 {
const struct wlr_texture_impl_2 *impl;
};

struct wlr_renderer_2 *wlr_renderer_autocreate_2(struct wl_display *display,
struct wlr_backend *backend);

void wlr_renderer_destroy_2(struct wlr_renderer_2 *renderer);

Expand All @@ -28,4 +37,12 @@ void wlr_renderer_flush_2(struct wlr_renderer_2 *renderer, int *fence_out);

void wlr_renderer_clear_2(struct wlr_renderer_2 *renderer, const float color[static 4]);

struct wlr_texture_2 *wlr_texture_from_buffer_2(struct wlr_renderer_2 *renderer,
struct wl_resource *buffer);

void wlr_texture_destroy_2(struct wlr_texture_2 *tex);

bool wlr_texture_apply_damage_2(struct wlr_texture_2 *tex, struct wl_resource *buffer,
pixman_region32_t *damage);

#endif
5 changes: 4 additions & 1 deletion include/wlr/render/renderer/gles.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#ifndef WLR_RENDER_RENDERER_GLES_H
#define WLR_RENDER_RENDERER_GLES_H

#include <wayland-server.h>

struct wlr_backend;
struct wlr_renderer_2;

struct wlr_renderer_2 *wlr_gles_renderer_create(struct wlr_backend *backend);
struct wlr_renderer_2 *wlr_gles_renderer_create(struct wl_display *display,
struct wlr_backend *backend);

#endif
18 changes: 18 additions & 0 deletions include/wlr/render/renderer/interface.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef WLR_RENDER_RENDERER_INTERFACE_H
#define WLR_RENDER_RENDERER_INTERFACE_H

#include <stdbool.h>

#include <pixman.h>

/*
* New API.
* TODO: Remove the _2 suffix when the old API is removed.
Expand All @@ -9,6 +13,7 @@
struct wlr_allocator;
struct wlr_image;
struct wlr_renderer_2;
struct wlr_texture_2;

struct wlr_renderer_impl_2 {
void (*destroy)(struct wlr_renderer_2 *renderer);
Expand All @@ -19,9 +24,22 @@ struct wlr_renderer_impl_2 {
void (*flush)(struct wlr_renderer_2 *renderer, int *fence_out);

void (*clear)(struct wlr_renderer_2 *renderer, const float color[static 4]);

struct wlr_texture_2 *(*texture_from_buffer)(struct wlr_renderer_2 *renderer,
struct wl_resource *buffer);
};

struct wlr_texture_impl_2 {
void (*destroy)(struct wlr_texture_2 *texture);

bool (*apply_damage)(struct wlr_texture_2 *texture,
struct wl_resource *buffer, pixman_region32_t *damage);
};

void wlr_renderer_init_2(struct wlr_renderer_2 *renderer,
const struct wlr_renderer_impl_2 *impl);

void wlr_texture_init_2(struct wlr_texture_2 *texture,
const struct wlr_texture_impl_2 *impl);

#endif
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_project_arguments(
[
'-DWLR_SRC_DIR="@0@"'.format(meson.current_source_dir()),
'-DWLR_USE_UNSTABLE',
'-DWLR_LITTLE_ENDIAN=@0@'.format((host_machine.endian() == 'little').to_int()),

'-Wno-unused-parameter',
'-Wundef',
Expand Down
3 changes: 3 additions & 0 deletions render/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ lib_wlr_render = static_library(
'gles2/util.c',
'swapchain.c',
'renderer.c',
'shm.c',
'wlr_renderer.c',
'wlr_texture.c',
'renderer/gles/gles.c',
'renderer/gles/texture.c',
'renderer/gles/format.c',
),
glapi,
include_directories: wlr_inc,
Expand Down
30 changes: 28 additions & 2 deletions render/renderer.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#include <stdbool.h>

#include <wayland-server.h>

#include <wlr/render/renderer.h>
#include <wlr/render/renderer/gles.h>
#include <wlr/render/renderer/interface.h>

struct wlr_renderer_2 *wlr_renderer_autocreate_2(struct wlr_backend *backend) {
return wlr_gles_renderer_create(backend);
struct wlr_renderer_2 *wlr_renderer_autocreate_2(struct wl_display *display,
struct wlr_backend *backend) {
return wlr_gles_renderer_create(display, backend);
}

void wlr_renderer_destroy_2(struct wlr_renderer_2 *renderer) {
Expand All @@ -32,8 +35,31 @@ void wlr_renderer_clear_2(struct wlr_renderer_2 *renderer, const float color[sta
renderer->impl->clear(renderer, color);
}

struct wlr_texture_2 *wlr_texture_from_buffer_2(struct wlr_renderer_2 *renderer,
struct wl_resource *buffer) {
return renderer->impl->texture_from_buffer(renderer, buffer);
}

void wlr_renderer_init_2(struct wlr_renderer_2 *renderer,
const struct wlr_renderer_impl_2 *impl) {
renderer->impl = impl;
wl_signal_init(&renderer->events.destroy);
}

void wlr_texture_destroy_2(struct wlr_texture_2 *tex) {
if (!tex) {
return;
}

tex->impl->destroy(tex);
}

bool wlr_texture_apply_damage_2(struct wlr_texture_2 *tex, struct wl_resource *buffer,
pixman_region32_t *damage) {
return tex->impl->apply_damage(tex, buffer, damage);
}

void wlr_texture_init_2(struct wlr_texture_2 *tex,
const struct wlr_texture_impl_2 *impl) {
tex->impl = impl;
}
Loading

0 comments on commit 19bb46a

Please sign in to comment.