mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-21 06:46:46 -04:00
wlr_texture: Expose owning renderer
This commit is contained in:
parent
43a3cbe6ae
commit
fc6fd95e4d
9 changed files with 46 additions and 35 deletions
|
|
@ -92,7 +92,6 @@ struct wlr_gles2_buffer {
|
||||||
|
|
||||||
struct wlr_gles2_texture {
|
struct wlr_gles2_texture {
|
||||||
struct wlr_texture wlr_texture;
|
struct wlr_texture wlr_texture;
|
||||||
struct wlr_gles2_renderer *renderer;
|
|
||||||
struct wl_list link; // wlr_gles2_renderer.textures
|
struct wl_list link; // wlr_gles2_renderer.textures
|
||||||
|
|
||||||
// Basically:
|
// Basically:
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ struct wlr_pixman_buffer {
|
||||||
|
|
||||||
struct wlr_pixman_texture {
|
struct wlr_pixman_texture {
|
||||||
struct wlr_texture wlr_texture;
|
struct wlr_texture wlr_texture;
|
||||||
struct wlr_pixman_renderer *renderer;
|
|
||||||
struct wl_list link; // wlr_pixman_renderer.textures
|
struct wl_list link; // wlr_pixman_renderer.textures
|
||||||
|
|
||||||
pixman_image_t *image;
|
pixman_image_t *image;
|
||||||
|
|
|
||||||
|
|
@ -234,7 +234,6 @@ struct wlr_vk_renderer *vulkan_get_renderer(struct wlr_renderer *r);
|
||||||
// State (e.g. image texture) associated with a surface.
|
// State (e.g. image texture) associated with a surface.
|
||||||
struct wlr_vk_texture {
|
struct wlr_vk_texture {
|
||||||
struct wlr_texture wlr_texture;
|
struct wlr_texture wlr_texture;
|
||||||
struct wlr_vk_renderer *renderer;
|
|
||||||
uint32_t mem_count;
|
uint32_t mem_count;
|
||||||
VkDeviceMemory memories[WLR_DMABUF_MAX_PLANES];
|
VkDeviceMemory memories[WLR_DMABUF_MAX_PLANES];
|
||||||
VkImage image;
|
VkImage image;
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ struct wlr_texture_impl {
|
||||||
void (*destroy)(struct wlr_texture *texture);
|
void (*destroy)(struct wlr_texture *texture);
|
||||||
};
|
};
|
||||||
|
|
||||||
void wlr_texture_init(struct wlr_texture *texture,
|
void wlr_texture_init(struct wlr_texture *texture, struct wlr_renderer *rendener,
|
||||||
const struct wlr_texture_impl *impl, uint32_t width, uint32_t height);
|
const struct wlr_texture_impl *impl, uint32_t width, uint32_t height);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ struct wlr_texture {
|
||||||
const struct wlr_texture_impl *impl;
|
const struct wlr_texture_impl *impl;
|
||||||
uint32_t width, height;
|
uint32_t width, height;
|
||||||
|
|
||||||
|
struct wlr_renderer *renderer;
|
||||||
|
|
||||||
struct wlr_raster *raster;
|
struct wlr_raster *raster;
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -79,11 +79,14 @@ static bool gles2_texture_update_from_raster(struct wlr_texture *wlr_texture,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct wlr_gles2_renderer *renderer =
|
||||||
|
gles2_get_renderer(texture->wlr_texture.renderer);
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
wlr_egl_save_context(&prev_ctx);
|
||||||
wlr_egl_make_current(texture->renderer->egl);
|
wlr_egl_make_current(renderer->egl);
|
||||||
|
|
||||||
push_gles2_debug(texture->renderer);
|
push_gles2_debug(renderer);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture->tex);
|
glBindTexture(GL_TEXTURE_2D, texture->tex);
|
||||||
|
|
||||||
|
|
@ -109,7 +112,7 @@ static bool gles2_texture_update_from_raster(struct wlr_texture *wlr_texture,
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
pop_gles2_debug(texture->renderer);
|
pop_gles2_debug(renderer);
|
||||||
|
|
||||||
wlr_egl_restore_context(&prev_ctx);
|
wlr_egl_restore_context(&prev_ctx);
|
||||||
|
|
||||||
|
|
@ -127,18 +130,21 @@ static bool gles2_texture_invalidate(struct wlr_gles2_texture *texture) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct wlr_gles2_renderer *renderer =
|
||||||
|
gles2_get_renderer(texture->wlr_texture.renderer);
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
wlr_egl_save_context(&prev_ctx);
|
||||||
wlr_egl_make_current(texture->renderer->egl);
|
wlr_egl_make_current(renderer->egl);
|
||||||
|
|
||||||
push_gles2_debug(texture->renderer);
|
push_gles2_debug(renderer);
|
||||||
|
|
||||||
glBindTexture(texture->target, texture->tex);
|
glBindTexture(texture->target, texture->tex);
|
||||||
texture->renderer->procs.glEGLImageTargetTexture2DOES(texture->target,
|
renderer->procs.glEGLImageTargetTexture2DOES(texture->target,
|
||||||
texture->image);
|
texture->image);
|
||||||
glBindTexture(texture->target, 0);
|
glBindTexture(texture->target, 0);
|
||||||
|
|
||||||
pop_gles2_debug(texture->renderer);
|
pop_gles2_debug(renderer);
|
||||||
|
|
||||||
wlr_egl_restore_context(&prev_ctx);
|
wlr_egl_restore_context(&prev_ctx);
|
||||||
|
|
||||||
|
|
@ -151,16 +157,20 @@ void gles2_texture_destroy(struct wlr_gles2_texture *texture) {
|
||||||
wlr_addon_finish(&texture->buffer_addon);
|
wlr_addon_finish(&texture->buffer_addon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct wlr_gles2_renderer *renderer =
|
||||||
|
gles2_get_renderer(texture->wlr_texture.renderer);
|
||||||
|
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
wlr_egl_save_context(&prev_ctx);
|
||||||
wlr_egl_make_current(texture->renderer->egl);
|
wlr_egl_make_current(renderer->egl);
|
||||||
|
|
||||||
push_gles2_debug(texture->renderer);
|
push_gles2_debug(renderer);
|
||||||
|
|
||||||
glDeleteTextures(1, &texture->tex);
|
glDeleteTextures(1, &texture->tex);
|
||||||
wlr_egl_destroy_image(texture->renderer->egl, texture->image);
|
wlr_egl_destroy_image(renderer->egl, texture->image);
|
||||||
|
|
||||||
pop_gles2_debug(texture->renderer);
|
pop_gles2_debug(renderer);
|
||||||
|
|
||||||
wlr_egl_restore_context(&prev_ctx);
|
wlr_egl_restore_context(&prev_ctx);
|
||||||
|
|
||||||
|
|
@ -191,8 +201,8 @@ static struct wlr_gles2_texture *gles2_texture_create(
|
||||||
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
|
wlr_texture_init(&texture->wlr_texture, &renderer->wlr_renderer,
|
||||||
texture->renderer = renderer;
|
&texture_impl, width, height);
|
||||||
wl_list_insert(&renderer->textures, &texture->link);
|
wl_list_insert(&renderer->textures, &texture->link);
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
@ -361,7 +371,7 @@ struct wlr_gles2_texture *gles2_raster_upload(struct wlr_gles2_renderer *rendere
|
||||||
if (wlr_texture_is_gles2(raster_texture)) {
|
if (wlr_texture_is_gles2(raster_texture)) {
|
||||||
struct wlr_gles2_texture *gles2_tex =
|
struct wlr_gles2_texture *gles2_tex =
|
||||||
(struct wlr_gles2_texture *)raster_texture;
|
(struct wlr_gles2_texture *)raster_texture;
|
||||||
if (gles2_tex->renderer != renderer) {
|
if (gles2_tex->wlr_texture.renderer != &renderer->wlr_renderer) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return gles2_tex;
|
return gles2_tex;
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ static struct wlr_pixman_texture *pixman_texture_create(
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
|
wlr_texture_init(&texture->wlr_texture, &renderer->wlr_renderer,
|
||||||
texture->renderer = renderer;
|
&texture_impl, width, height);
|
||||||
|
|
||||||
texture->format_info = drm_get_pixel_format_info(drm_format);
|
texture->format_info = drm_get_pixel_format_info(drm_format);
|
||||||
if (!texture->format_info) {
|
if (!texture->format_info) {
|
||||||
|
|
@ -80,7 +80,7 @@ static struct wlr_pixman_texture *raster_upload(
|
||||||
if (wlr_texture_is_pixman(raster_texture)) {
|
if (wlr_texture_is_pixman(raster_texture)) {
|
||||||
struct wlr_pixman_texture *pixman_tex =
|
struct wlr_pixman_texture *pixman_tex =
|
||||||
(struct wlr_pixman_texture *)raster_texture;
|
(struct wlr_pixman_texture *)raster_texture;
|
||||||
if (pixman_tex->renderer != renderer) {
|
if (pixman_tex->wlr_texture.renderer != &renderer->wlr_renderer) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return pixman_tex;
|
return pixman_tex;
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,9 @@ static bool write_pixels(struct wlr_texture *wlr_texture,
|
||||||
VkAccessFlags src_access) {
|
VkAccessFlags src_access) {
|
||||||
VkResult res;
|
VkResult res;
|
||||||
struct wlr_vk_texture *texture = vulkan_get_texture(wlr_texture);
|
struct wlr_vk_texture *texture = vulkan_get_texture(wlr_texture);
|
||||||
struct wlr_vk_renderer *renderer = texture->renderer;
|
struct wlr_vk_renderer *renderer =
|
||||||
VkDevice dev = texture->renderer->dev->dev;
|
vulkan_get_renderer(wlr_texture->renderer);
|
||||||
|
VkDevice dev = renderer->dev->dev;
|
||||||
|
|
||||||
// make sure assumptions are met
|
// make sure assumptions are met
|
||||||
assert(src_x + width <= texture->wlr_texture.width);
|
assert(src_x + width <= texture->wlr_texture.width);
|
||||||
|
|
@ -179,18 +180,16 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
void vulkan_texture_destroy(struct wlr_vk_texture *texture) {
|
void vulkan_texture_destroy(struct wlr_vk_texture *texture) {
|
||||||
if (!texture->renderer) {
|
struct wlr_vk_renderer *renderer =
|
||||||
free(texture);
|
vulkan_get_renderer(texture->wlr_texture.renderer);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// when we recorded a command to fill this image _this_ frame,
|
// when we recorded a command to fill this image _this_ frame,
|
||||||
// it has to be executed before the texture can be destroyed.
|
// it has to be executed before the texture can be destroyed.
|
||||||
// Add it to the renderer->destroy_textures list, destroying
|
// Add it to the renderer->destroy_textures list, destroying
|
||||||
// _after_ the stage command buffer has exectued
|
// _after_ the stage command buffer has exectued
|
||||||
if (texture->last_used == texture->renderer->frame) {
|
if (texture->last_used == renderer->frame) {
|
||||||
assert(texture->destroy_link.next == NULL); // not already inserted
|
assert(texture->destroy_link.next == NULL); // not already inserted
|
||||||
wl_list_insert(&texture->renderer->destroy_textures,
|
wl_list_insert(&renderer->destroy_textures,
|
||||||
&texture->destroy_link);
|
&texture->destroy_link);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -198,9 +197,9 @@ void vulkan_texture_destroy(struct wlr_vk_texture *texture) {
|
||||||
wl_list_remove(&texture->link);
|
wl_list_remove(&texture->link);
|
||||||
wl_list_remove(&texture->buffer_destroy.link);
|
wl_list_remove(&texture->buffer_destroy.link);
|
||||||
|
|
||||||
VkDevice dev = texture->renderer->dev->dev;
|
VkDevice dev = renderer->dev->dev;
|
||||||
if (texture->ds && texture->ds_pool) {
|
if (texture->ds && texture->ds_pool) {
|
||||||
vulkan_free_ds(texture->renderer, texture->ds_pool, texture->ds);
|
vulkan_free_ds(renderer, texture->ds_pool, texture->ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
vkDestroyImageView(dev, texture->image_view, NULL);
|
vkDestroyImageView(dev, texture->image_view, NULL);
|
||||||
|
|
@ -237,8 +236,8 @@ static struct wlr_vk_texture *vulkan_texture_create(
|
||||||
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
|
wlr_texture_init(&texture->wlr_texture, &renderer->wlr_renderer,
|
||||||
texture->renderer = renderer;
|
&texture_impl, width, height);
|
||||||
wl_list_insert(&renderer->textures, &texture->link);
|
wl_list_insert(&renderer->textures, &texture->link);
|
||||||
wl_list_init(&texture->buffer_destroy.link);
|
wl_list_init(&texture->buffer_destroy.link);
|
||||||
return texture;
|
return texture;
|
||||||
|
|
@ -725,7 +724,7 @@ struct wlr_vk_texture *vulkan_raster_upload(struct wlr_vk_renderer *renderer,
|
||||||
if (wlr_texture_is_vk(raster_texture)) {
|
if (wlr_texture_is_vk(raster_texture)) {
|
||||||
struct wlr_vk_texture *vk_tex =
|
struct wlr_vk_texture *vk_tex =
|
||||||
(struct wlr_vk_texture *)raster_texture;
|
(struct wlr_vk_texture *)raster_texture;
|
||||||
if (vk_tex->renderer != renderer) {
|
if (vk_tex->wlr_texture.renderer != &renderer->wlr_renderer) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return vk_tex;
|
return vk_tex;
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,12 @@
|
||||||
#include <wlr/types/wlr_raster.h>
|
#include <wlr/types/wlr_raster.h>
|
||||||
#include "types/wlr_buffer.h"
|
#include "types/wlr_buffer.h"
|
||||||
|
|
||||||
void wlr_texture_init(struct wlr_texture *texture,
|
void wlr_texture_init(struct wlr_texture *texture, struct wlr_renderer *renderer,
|
||||||
const struct wlr_texture_impl *impl, uint32_t width, uint32_t height) {
|
const struct wlr_texture_impl *impl, uint32_t width, uint32_t height) {
|
||||||
|
assert(renderer);
|
||||||
|
|
||||||
memset(texture, 0, sizeof(*texture));
|
memset(texture, 0, sizeof(*texture));
|
||||||
|
texture->renderer = renderer;
|
||||||
texture->impl = impl;
|
texture->impl = impl;
|
||||||
texture->width = width;
|
texture->width = width;
|
||||||
texture->height = height;
|
texture->height = height;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue