render: Implement texture_preferred_read_format

This commit is contained in:
Alexander Orzechowski 2023-11-30 20:01:12 -05:00
parent 57b18d26d0
commit c5a3c5ca4c
3 changed files with 60 additions and 1 deletions

View file

@ -195,6 +195,8 @@ static bool gles2_texture_read_pixels(struct wlr_texture *wlr_texture,
} }
push_gles2_debug(texture->renderer); push_gles2_debug(texture->renderer);
struct wlr_egl_context prev_ctx;
wlr_egl_save_context(&prev_ctx);
if (!wlr_egl_make_current(texture->renderer->egl)) { if (!wlr_egl_make_current(texture->renderer->egl)) {
return false; return false;
@ -228,15 +230,58 @@ static bool gles2_texture_read_pixels(struct wlr_texture *wlr_texture,
} }
} }
glBindFramebuffer(GL_FRAMEBUFFER, 0); wlr_egl_restore_context(&prev_ctx);
pop_gles2_debug(texture->renderer); pop_gles2_debug(texture->renderer);
return glGetError() == GL_NO_ERROR; return glGetError() == GL_NO_ERROR;
} }
static uint32_t gles2_texture_preferred_read_format(struct wlr_texture *wlr_texture) {
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
push_gles2_debug(texture->renderer);
struct wlr_egl_context prev_ctx;
wlr_egl_save_context(&prev_ctx);
uint32_t fmt = DRM_FORMAT_INVALID;
if (!wlr_egl_make_current(texture->renderer->egl)) {
goto out;
}
if (!gles2_texture_bind(texture)) {
goto out;
}
GLint gl_format = -1, gl_type = -1, alpha_size = -1;
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &gl_format);
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &gl_type);
glGetIntegerv(GL_ALPHA_BITS, &alpha_size);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
pop_gles2_debug(texture->renderer);
const struct wlr_gles2_pixel_format *pix_fmt =
get_gles2_format_from_gl(gl_format, gl_type, alpha_size > 0);
if (pix_fmt != NULL) {
fmt = pix_fmt->drm_format;
goto out;
}
if (texture->renderer->exts.EXT_read_format_bgra) {
fmt = DRM_FORMAT_XRGB8888;
goto out;
}
out:
wlr_egl_restore_context(&prev_ctx);
return fmt;
}
static const struct wlr_texture_impl texture_impl = { static const struct wlr_texture_impl texture_impl = {
.update_from_buffer = gles2_texture_update_from_buffer, .update_from_buffer = gles2_texture_update_from_buffer,
.read_pixels = gles2_texture_read_pixels, .read_pixels = gles2_texture_read_pixels,
.preferred_read_format = gles2_texture_preferred_read_format,
.destroy = handle_gles2_texture_destroy, .destroy = handle_gles2_texture_destroy,
}; };

View file

@ -115,8 +115,16 @@ static bool texture_read_pixels(struct wlr_texture *wlr_texture,
return true; return true;
} }
static uint32_t pixman_texture_preferred_read_format(struct wlr_texture *wlr_texture) {
struct wlr_pixman_texture *texture = get_texture(wlr_texture);
pixman_format_code_t pixman_format = pixman_image_get_format(texture->image);
return get_drm_format_from_pixman(pixman_format);
}
static const struct wlr_texture_impl texture_impl = { static const struct wlr_texture_impl texture_impl = {
.read_pixels = texture_read_pixels, .read_pixels = texture_read_pixels,
.preferred_read_format = pixman_texture_preferred_read_format,
.destroy = texture_destroy, .destroy = texture_destroy,
}; };

View file

@ -262,9 +262,15 @@ static bool vulkan_texture_read_pixels(struct wlr_texture *wlr_texture,
options->format, options->stride, src.width, src.height, src.x, src.y, 0, 0, p); options->format, options->stride, src.width, src.height, src.x, src.y, 0, 0, p);
} }
static uint32_t vulkan_texture_preferred_read_format(struct wlr_texture *wlr_texture) {
struct wlr_vk_texture *texture = vulkan_get_texture(wlr_texture);
return texture->format->drm;
}
static const struct wlr_texture_impl texture_impl = { static const struct wlr_texture_impl texture_impl = {
.update_from_buffer = vulkan_texture_update_from_buffer, .update_from_buffer = vulkan_texture_update_from_buffer,
.read_pixels = vulkan_texture_read_pixels, .read_pixels = vulkan_texture_read_pixels,
.preferred_read_format = vulkan_texture_preferred_read_format,
.destroy = vulkan_texture_unref, .destroy = vulkan_texture_unref,
}; };