render/gles2: remove depth and bpp gles2_pixel_format, use drm pixel format

This commit is contained in:
Simon Zeni 2021-03-24 10:10:52 -04:00 committed by Simon Ser
parent 9b3f2e327f
commit 78d21fa131
4 changed files with 21 additions and 16 deletions

View File

@ -17,7 +17,6 @@
struct wlr_gles2_pixel_format { struct wlr_gles2_pixel_format {
uint32_t drm_format; uint32_t drm_format;
GLint gl_format, gl_type; GLint gl_format, gl_type;
int depth, bpp;
bool has_alpha; bool has_alpha;
}; };

View File

@ -10,32 +10,24 @@
static const struct wlr_gles2_pixel_format formats[] = { static const struct wlr_gles2_pixel_format formats[] = {
{ {
.drm_format = DRM_FORMAT_ARGB8888, .drm_format = DRM_FORMAT_ARGB8888,
.depth = 32,
.bpp = 32,
.gl_format = GL_BGRA_EXT, .gl_format = GL_BGRA_EXT,
.gl_type = GL_UNSIGNED_BYTE, .gl_type = GL_UNSIGNED_BYTE,
.has_alpha = true, .has_alpha = true,
}, },
{ {
.drm_format = DRM_FORMAT_XRGB8888, .drm_format = DRM_FORMAT_XRGB8888,
.depth = 24,
.bpp = 32,
.gl_format = GL_BGRA_EXT, .gl_format = GL_BGRA_EXT,
.gl_type = GL_UNSIGNED_BYTE, .gl_type = GL_UNSIGNED_BYTE,
.has_alpha = false, .has_alpha = false,
}, },
{ {
.drm_format = DRM_FORMAT_XBGR8888, .drm_format = DRM_FORMAT_XBGR8888,
.depth = 24,
.bpp = 32,
.gl_format = GL_RGBA, .gl_format = GL_RGBA,
.gl_type = GL_UNSIGNED_BYTE, .gl_type = GL_UNSIGNED_BYTE,
.has_alpha = false, .has_alpha = false,
}, },
{ {
.drm_format = DRM_FORMAT_ABGR8888, .drm_format = DRM_FORMAT_ABGR8888,
.depth = 32,
.bpp = 32,
.gl_format = GL_RGBA, .gl_format = GL_RGBA,
.gl_type = GL_UNSIGNED_BYTE, .gl_type = GL_UNSIGNED_BYTE,
.has_alpha = true, .has_alpha = true,

View File

@ -15,6 +15,7 @@
#include <wlr/types/wlr_linux_dmabuf_v1.h> #include <wlr/types/wlr_linux_dmabuf_v1.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "render/gles2.h" #include "render/gles2.h"
#include "render/pixel_format.h"
static const GLfloat verts[] = { static const GLfloat verts[] = {
1, 0, // top right 1, 0, // top right
@ -492,6 +493,10 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
return false; return false;
} }
const struct wlr_pixel_format_info *drm_fmt =
drm_get_pixel_format_info(fmt->drm_format);
assert(drm_fmt);
push_gles2_debug(renderer); push_gles2_debug(renderer);
// Make sure any pending drawing is finished before we try to read it // Make sure any pending drawing is finished before we try to read it
@ -500,7 +505,7 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
glGetError(); // Clear the error flag glGetError(); // Clear the error flag
unsigned char *p = (unsigned char *)data + dst_y * stride; unsigned char *p = (unsigned char *)data + dst_y * stride;
uint32_t pack_stride = width * fmt->bpp / 8; uint32_t pack_stride = width * drm_fmt->bpp / 8;
if (pack_stride == stride && dst_x == 0) { if (pack_stride == stride && dst_x == 0) {
// Under these particular conditions, we can read the pixels with only // Under these particular conditions, we can read the pixels with only
// one glReadPixels call // one glReadPixels call
@ -512,7 +517,7 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
for (size_t i = 0; i < height; ++i) { for (size_t i = 0; i < height; ++i) {
uint32_t y = src_y + i; uint32_t y = src_y + i;
glReadPixels(src_x, y, width, 1, fmt->gl_format, glReadPixels(src_x, y, width, 1, fmt->gl_format,
fmt->gl_type, p + i * stride + dst_x * fmt->bpp / 8); fmt->gl_type, p + i * stride + dst_x * drm_fmt->bpp / 8);
} }
} }

View File

@ -12,6 +12,7 @@
#include <wlr/types/wlr_matrix.h> #include <wlr/types/wlr_matrix.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "render/gles2.h" #include "render/gles2.h"
#include "render/pixel_format.h"
#include "util/signal.h" #include "util/signal.h"
static const struct wlr_texture_impl texture_impl; static const struct wlr_texture_impl texture_impl;
@ -31,7 +32,7 @@ static bool gles2_texture_is_opaque(struct wlr_texture *wlr_texture) {
return !texture->has_alpha; return !texture->has_alpha;
} }
static bool check_stride(const struct wlr_gles2_pixel_format *fmt, static bool check_stride(const struct wlr_pixel_format_info *fmt,
uint32_t stride, uint32_t width) { uint32_t stride, uint32_t width) {
if (stride % (fmt->bpp / 8) != 0) { if (stride % (fmt->bpp / 8) != 0) {
wlr_log(WLR_ERROR, "Invalid stride %d (incompatible with %d " wlr_log(WLR_ERROR, "Invalid stride %d (incompatible with %d "
@ -61,7 +62,11 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
get_gles2_format_from_drm(texture->drm_format); get_gles2_format_from_drm(texture->drm_format);
assert(fmt); assert(fmt);
if (!check_stride(fmt, stride, width)) { const struct wlr_pixel_format_info *drm_fmt =
drm_get_pixel_format_info(texture->drm_format);
assert(drm_fmt);
if (!check_stride(drm_fmt, stride, width)) {
return false; return false;
} }
@ -73,7 +78,7 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
glBindTexture(GL_TEXTURE_2D, texture->tex); glBindTexture(GL_TEXTURE_2D, texture->tex);
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / (fmt->bpp / 8)); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / (drm_fmt->bpp / 8));
glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, src_x); glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, src_x);
glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, src_y); glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, src_y);
@ -163,7 +168,11 @@ struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer,
return NULL; return NULL;
} }
if (!check_stride(fmt, stride, width)) { const struct wlr_pixel_format_info *drm_fmt =
drm_get_pixel_format_info(drm_format);
assert(drm_fmt);
if (!check_stride(drm_fmt, stride, width)) {
return NULL; return NULL;
} }
@ -190,7 +199,7 @@ struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / (fmt->bpp / 8)); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / (drm_fmt->bpp / 8));
glTexImage2D(GL_TEXTURE_2D, 0, fmt->gl_format, width, height, 0, glTexImage2D(GL_TEXTURE_2D, 0, fmt->gl_format, width, height, 0,
fmt->gl_format, fmt->gl_type, data); fmt->gl_format, fmt->gl_type, data);
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0);