render/gles2: remove current_buffer checks

All backends now use wlr_swapchain. This means the renderer is
guaranteed to have a current_buffer bound.

Remove the legacy code used for EGLSurface.
This commit is contained in:
Simon Ser 2021-02-16 16:19:19 +01:00
parent 6ca59519c9
commit bfd020047d
1 changed files with 23 additions and 59 deletions

View File

@ -34,6 +34,7 @@ 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(wlr_egl_is_current(renderer->egl));
assert(renderer->current_buffer != NULL);
return renderer;
}
@ -222,15 +223,7 @@ static void gles2_scissor(struct wlr_renderer *wlr_renderer,
push_gles2_debug(renderer);
if (box != NULL) {
struct wlr_box gl_box;
if (renderer->current_buffer != NULL) {
memcpy(&gl_box, box, sizeof(gl_box));
} else {
wlr_box_transform(&gl_box, box, WL_OUTPUT_TRANSFORM_FLIPPED_180,
renderer->viewport_width, renderer->viewport_height);
}
glScissor(gl_box.x, gl_box.y, gl_box.width, gl_box.height);
glScissor(box->x, box->y, box->width, box->height);
glEnable(GL_SCISSOR_TEST);
} else {
glDisable(GL_SCISSOR_TEST);
@ -277,11 +270,8 @@ static bool gles2_render_subtexture_with_matrix(
}
float gl_matrix[9];
if (renderer->current_buffer != NULL) {
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
} else {
memcpy(gl_matrix, matrix, sizeof(gl_matrix));
}
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
// to GL_FALSE
wlr_matrix_transpose(gl_matrix, gl_matrix);
@ -334,11 +324,8 @@ static void gles2_render_quad_with_matrix(struct wlr_renderer *wlr_renderer,
gles2_get_renderer_in_context(wlr_renderer);
float gl_matrix[9];
if (renderer->current_buffer != NULL) {
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
} else {
memcpy(gl_matrix, matrix, sizeof(gl_matrix));
}
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
// to GL_FALSE
wlr_matrix_transpose(gl_matrix, gl_matrix);
@ -367,11 +354,8 @@ static void gles2_render_ellipse_with_matrix(struct wlr_renderer *wlr_renderer,
gles2_get_renderer_in_context(wlr_renderer);
float gl_matrix[9];
if (renderer->current_buffer != NULL) {
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
} else {
memcpy(gl_matrix, matrix, sizeof(gl_matrix));
}
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
// to GL_FALSE
wlr_matrix_transpose(gl_matrix, gl_matrix);
@ -454,19 +438,19 @@ static enum wl_shm_format gles2_preferred_read_format(
struct wlr_gles2_renderer *renderer =
gles2_get_renderer_in_context(wlr_renderer);
GLint gl_format = -1, gl_type = -1;
push_gles2_debug(renderer);
GLint gl_format = -1, gl_type = -1;
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &gl_format);
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &gl_type);
pop_gles2_debug(renderer);
EGLint alpha_size = -1;
if (renderer->current_buffer != NULL) {
glBindRenderbuffer(GL_RENDERBUFFER, renderer->current_buffer->rbo);
glGetRenderbufferParameteriv(GL_RENDERBUFFER,
GL_RENDERBUFFER_ALPHA_SIZE, &alpha_size);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
glBindRenderbuffer(GL_RENDERBUFFER, renderer->current_buffer->rbo);
glGetRenderbufferParameteriv(GL_RENDERBUFFER,
GL_RENDERBUFFER_ALPHA_SIZE, &alpha_size);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
pop_gles2_debug(renderer);
const struct wlr_gles2_pixel_format *fmt =
get_gles2_format_from_gl(gl_format, gl_type, alpha_size > 0);
@ -508,42 +492,27 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
unsigned char *p = (unsigned char *)data + dst_y * stride;
uint32_t pack_stride = width * fmt->bpp / 8;
if (pack_stride == stride && dst_x == 0 && flags != NULL) {
if (pack_stride == stride && dst_x == 0) {
// Under these particular conditions, we can read the pixels with only
// one glReadPixels call
uint32_t y = src_y;
if (renderer->current_buffer == NULL) {
y = renderer->viewport_height - height - src_y;
}
glReadPixels(src_x, y, width, height, fmt->gl_format, fmt->gl_type, p);
if (renderer->current_buffer != NULL) {
*flags = 0;
} else {
*flags = WLR_RENDERER_READ_PIXELS_Y_INVERT;
}
glReadPixels(src_x, src_y, width, height, fmt->gl_format, fmt->gl_type, p);
} else {
// Unfortunately GLES2 doesn't support GL_PACK_*, so we have to read
// the lines out row by row
for (size_t i = 0; i < height; ++i) {
uint32_t y = src_y + i;
if (renderer->current_buffer == NULL) {
y = renderer->viewport_height - src_y - i - 1;
}
glReadPixels(src_x, y, width, 1, fmt->gl_format,
fmt->gl_type, p + i * stride + dst_x * fmt->bpp / 8);
}
if (flags != NULL) {
*flags = 0;
}
}
pop_gles2_debug(renderer);
if (flags != NULL) {
*flags = 0;
}
return glGetError() == GL_NO_ERROR;
}
@ -565,7 +534,7 @@ static bool gles2_blit_dmabuf(struct wlr_renderer *wlr_renderer,
goto restore_context_out;
}
// TODO: get inverted_y right when current_buffer != NULL
// TODO: get inverted_y right
// This is to take into account y-inversion on both buffers rather than
// just the source buffer.
bool src_inverted_y =
@ -574,11 +543,6 @@ static bool gles2_blit_dmabuf(struct wlr_renderer *wlr_renderer,
!!(dst_attr->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT);
struct wlr_gles2_texture *gles2_src_tex = gles2_get_texture(src_tex);
gles2_src_tex->inverted_y = src_inverted_y ^ dst_inverted_y;
if (renderer->current_buffer == NULL) {
// The result is negated because wlr_matrix_projection y-inverts the
// texture.
gles2_src_tex->inverted_y = !gles2_src_tex->inverted_y;
}
if (!wlr_egl_make_current(renderer->egl)) {
goto texture_destroy_out;