From 33a2eb4b7775d1a3ab2b767739c1f1f054683d22 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 18:49:43 -0400 Subject: Untie wlr_backend from wlr_renderer --- include/wlr/render/gles2.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/wlr/render/gles2.h') diff --git a/include/wlr/render/gles2.h b/include/wlr/render/gles2.h index b3b43ab2..a59956bd 100644 --- a/include/wlr/render/gles2.h +++ b/include/wlr/render/gles2.h @@ -5,6 +5,7 @@ #include struct wlr_egl; -struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend); + +struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl); #endif -- cgit v1.2.3 From f3f61bed3e055e7032466723afda33a56f585dc5 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 1 Apr 2018 16:07:50 -0400 Subject: Untie wlr_gles2_renderer and wlr_gles2_texture --- include/render/gles2.h | 15 ++------------- include/wlr/render/egl.h | 2 ++ include/wlr/render/gles2.h | 8 ++++++++ render/egl.c | 4 ++++ render/gles2/renderer.c | 33 +++++++++++++++++++++++++++++---- render/gles2/texture.c | 31 +++++++++++++++---------------- 6 files changed, 60 insertions(+), 33 deletions(-) (limited to 'include/wlr/render/gles2.h') diff --git a/include/render/gles2.h b/include/render/gles2.h index 32cb3221..50252027 100644 --- a/include/render/gles2.h +++ b/include/render/gles2.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -49,7 +50,7 @@ enum wlr_gles2_texture_type { struct wlr_gles2_texture { struct wlr_texture wlr_texture; - struct wlr_gles2_renderer *renderer; + struct wlr_egl *egl; enum wlr_gles2_texture_type type; int width, height; bool has_alpha; @@ -68,20 +69,8 @@ struct wlr_gles2_texture { const struct gles2_pixel_format *gles2_format_from_wl(enum wl_shm_format fmt); const enum wl_shm_format *gles2_formats(size_t *len); -struct wlr_gles2_renderer *gles2_get_renderer( - struct wlr_renderer *wlr_renderer); -struct wlr_gles2_renderer *gles2_get_renderer_in_context( - struct wlr_renderer *wlr_renderer); - struct wlr_gles2_texture *gles2_get_texture_in_context( struct wlr_texture *wlr_texture); -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_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, - struct wl_resource *data); -struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, - struct wlr_dmabuf_buffer_attribs *attribs); void gles2_push_marker(const char *file, const char *func); void gles2_pop_marker(void); diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h index cca77870..51f63b20 100644 --- a/include/wlr/render/egl.h +++ b/include/wlr/render/egl.h @@ -93,6 +93,8 @@ bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image); bool wlr_egl_make_current(struct wlr_egl *egl, EGLSurface surface, int *buffer_age); +bool wlr_egl_is_current(struct wlr_egl *egl); + bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface, pixman_region32_t *damage); diff --git a/include/wlr/render/gles2.h b/include/wlr/render/gles2.h index a59956bd..65bb36c1 100644 --- a/include/wlr/render/gles2.h +++ b/include/wlr/render/gles2.h @@ -8,4 +8,12 @@ struct wlr_egl; struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl); +struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl, + enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height, + const void *data); +struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl, + struct wl_resource *data); +struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl, + struct wlr_dmabuf_buffer_attribs *attribs); + #endif diff --git a/render/egl.c b/render/egl.c index a424e8e9..473d1319 100644 --- a/render/egl.c +++ b/render/egl.c @@ -270,6 +270,10 @@ bool wlr_egl_make_current(struct wlr_egl *egl, EGLSurface surface, return true; } +bool wlr_egl_is_current(struct wlr_egl *egl) { + return eglGetCurrentContext() == egl->context; +} + bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface, pixman_region32_t *damage) { EGLBoolean ret; diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 77af0ab7..b8bce98d 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -16,16 +16,16 @@ static const struct wlr_renderer_impl renderer_impl; -struct wlr_gles2_renderer *gles2_get_renderer( +static 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; } -struct wlr_gles2_renderer *gles2_get_renderer_in_context( +static struct wlr_gles2_renderer *gles2_get_renderer_in_context( struct wlr_renderer *wlr_renderer) { struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); - assert(eglGetCurrentContext() == renderer->egl->context); + assert(wlr_egl_is_current(renderer->egl)); return renderer; } @@ -252,11 +252,32 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer, return true; } -static bool gles2_format_supported(struct wlr_renderer *r, +static bool gles2_format_supported(struct wlr_renderer *wlr_renderer, enum wl_shm_format wl_fmt) { return gles2_format_from_wl(wl_fmt) != NULL; } +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_buffer_attribs *attribs) { + struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); + return wlr_gles2_texture_from_dmabuf(renderer->egl, attribs); +} + static void gles2_destroy(struct wlr_renderer *wlr_renderer) { struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); @@ -400,6 +421,10 @@ extern const GLchar tex_fragment_src_rgbx[]; extern const GLchar tex_fragment_src_external[]; struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) { + if (!load_glapi()) { + return NULL; + } + struct wlr_gles2_renderer *renderer = calloc(1, sizeof(struct wlr_gles2_renderer)); if (renderer == NULL) { diff --git a/render/gles2/texture.c b/render/gles2/texture.c index e4936d71..45169daf 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -25,7 +25,7 @@ static struct wlr_gles2_texture *gles2_get_texture( struct wlr_gles2_texture *gles2_get_texture_in_context( struct wlr_texture *wlr_texture) { struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); - assert(eglGetCurrentContext() == texture->renderer->egl->context); + assert(wlr_egl_is_current(texture->egl)); return texture; } @@ -81,7 +81,7 @@ static void gles2_texture_destroy(struct wlr_texture *wlr_texture) { struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); - wlr_egl_make_current(texture->renderer->egl, EGL_NO_SURFACE, NULL); + wlr_egl_make_current(texture->egl, EGL_NO_SURFACE, NULL); GLES2_DEBUG_PUSH; @@ -90,7 +90,7 @@ static void gles2_texture_destroy(struct wlr_texture *wlr_texture) { } if (texture->image) { assert(eglDestroyImageKHR); - wlr_egl_destroy_image(texture->renderer->egl, texture->image); + wlr_egl_destroy_image(texture->egl, texture->image); } if (texture->type == WLR_GLES2_TEXTURE_GLTEX) { @@ -108,11 +108,10 @@ static const struct wlr_texture_impl texture_impl = { .destroy = gles2_texture_destroy, }; -struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer, +struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl, 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_in_context(wlr_renderer); + assert(wlr_egl_is_current(egl)); const struct gles2_pixel_format *fmt = gles2_format_from_wl(wl_fmt); if (fmt == NULL) { @@ -127,7 +126,7 @@ struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer, return NULL; } wlr_texture_init(&texture->wlr_texture, &texture_impl); - texture->renderer = renderer; + texture->egl = egl; texture->width = width; texture->height = height; texture->type = WLR_GLES2_TEXTURE_GLTEX; @@ -147,9 +146,9 @@ struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer, return &texture->wlr_texture; } -struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, +struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl, struct wl_resource *data) { - struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); + assert(wlr_egl_is_current(egl)); if (!glEGLImageTargetTexture2DOES) { return NULL; @@ -162,11 +161,11 @@ struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, return NULL; } wlr_texture_init(&texture->wlr_texture, &texture_impl); - texture->renderer = renderer; + texture->egl = egl; texture->wl_drm = data; EGLint fmt; - texture->image = wlr_egl_create_image_from_wl_drm(renderer->egl, data, &fmt, + texture->image = wlr_egl_create_image_from_wl_drm(egl, data, &fmt, &texture->width, &texture->height, &texture->inverted_y); if (texture->image == NULL) { free(texture); @@ -202,15 +201,15 @@ struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, return &texture->wlr_texture; } -struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, +struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl, struct wlr_dmabuf_buffer_attribs *attribs) { - struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); + assert(wlr_egl_is_current(egl)); if (!glEGLImageTargetTexture2DOES) { return NULL; } - if (!renderer->egl->egl_exts.dmabuf_import) { + if (!egl->egl_exts.dmabuf_import) { wlr_log(L_ERROR, "Cannot create DMA-BUF texture: EGL extension " "unavailable"); return NULL; @@ -223,7 +222,7 @@ struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, return NULL; } wlr_texture_init(&texture->wlr_texture, &texture_impl); - texture->renderer = renderer; + texture->egl = egl; texture->width = attribs->width; texture->height = attribs->height; texture->type = WLR_GLES2_TEXTURE_DMABUF; @@ -231,7 +230,7 @@ struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, texture->inverted_y = (attribs->flags & WLR_DMABUF_BUFFER_ATTRIBS_FLAGS_Y_INVERT) != 0; - texture->image = wlr_egl_create_image_from_dmabuf(renderer->egl, attribs); + texture->image = wlr_egl_create_image_from_dmabuf(egl, attribs); if (texture->image == NULL) { free(texture); return NULL; -- cgit v1.2.3