mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-12 16:35:58 +01:00
render/gles2: remove depth and bpp gles2_pixel_format, use drm pixel format
This commit is contained in:
parent
9b3f2e327f
commit
78d21fa131
4 changed files with 21 additions and 16 deletions
|
@ -17,7 +17,6 @@
|
|||
struct wlr_gles2_pixel_format {
|
||||
uint32_t drm_format;
|
||||
GLint gl_format, gl_type;
|
||||
int depth, bpp;
|
||||
bool has_alpha;
|
||||
};
|
||||
|
||||
|
|
|
@ -10,32 +10,24 @@
|
|||
static const struct wlr_gles2_pixel_format formats[] = {
|
||||
{
|
||||
.drm_format = DRM_FORMAT_ARGB8888,
|
||||
.depth = 32,
|
||||
.bpp = 32,
|
||||
.gl_format = GL_BGRA_EXT,
|
||||
.gl_type = GL_UNSIGNED_BYTE,
|
||||
.has_alpha = true,
|
||||
},
|
||||
{
|
||||
.drm_format = DRM_FORMAT_XRGB8888,
|
||||
.depth = 24,
|
||||
.bpp = 32,
|
||||
.gl_format = GL_BGRA_EXT,
|
||||
.gl_type = GL_UNSIGNED_BYTE,
|
||||
.has_alpha = false,
|
||||
},
|
||||
{
|
||||
.drm_format = DRM_FORMAT_XBGR8888,
|
||||
.depth = 24,
|
||||
.bpp = 32,
|
||||
.gl_format = GL_RGBA,
|
||||
.gl_type = GL_UNSIGNED_BYTE,
|
||||
.has_alpha = false,
|
||||
},
|
||||
{
|
||||
.drm_format = DRM_FORMAT_ABGR8888,
|
||||
.depth = 32,
|
||||
.bpp = 32,
|
||||
.gl_format = GL_RGBA,
|
||||
.gl_type = GL_UNSIGNED_BYTE,
|
||||
.has_alpha = true,
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <wlr/types/wlr_linux_dmabuf_v1.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "render/gles2.h"
|
||||
#include "render/pixel_format.h"
|
||||
|
||||
static const GLfloat verts[] = {
|
||||
1, 0, // top right
|
||||
|
@ -492,6 +493,10 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
|
|||
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);
|
||||
|
||||
// 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
|
||||
|
||||
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) {
|
||||
// Under these particular conditions, we can read the pixels with only
|
||||
// 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) {
|
||||
uint32_t y = src_y + i;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <wlr/types/wlr_matrix.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "render/gles2.h"
|
||||
#include "render/pixel_format.h"
|
||||
#include "util/signal.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (stride % (fmt->bpp / 8) != 0) {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -73,7 +78,7 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
|
|||
|
||||
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_ROWS_EXT, src_y);
|
||||
|
||||
|
@ -163,7 +168,11 @@ struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer,
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -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_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,
|
||||
fmt->gl_format, fmt->gl_type, data);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0);
|
||||
|
|
Loading…
Reference in a new issue