From 710e5fd7a00651a58e3907d7910d169d3258e17e Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 20 Jun 2021 06:59:55 +0100 Subject: [PATCH] backend: remove image operation BAKE It's not used. Signed-off-by: Yuxuan Shui --- src/backend/backend.h | 8 +--- src/backend/gl/gl_common.c | 70 ----------------------------------- src/backend/xrender/xrender.c | 32 ---------------- 3 files changed, 2 insertions(+), 108 deletions(-) diff --git a/src/backend/backend.h b/src/backend/backend.h index 575bf97..775f570 100644 --- a/src/backend/backend.h +++ b/src/backend/backend.h @@ -57,9 +57,6 @@ enum image_properties { }; enum image_operations { - // Apply the image properties, reset the image properties to their defaults - // afterwards. - IMAGE_OP_BAKE_PROPERTIES, // Multiply the alpha channel by the argument IMAGE_OP_APPLY_ALPHA, }; @@ -228,8 +225,7 @@ struct backend_operations { void *image_data, void *args); /** - * Manipulate an image. Image properties are untouched by and have no effects on - * operations other than BAKE. + * Manipulate an image. Image properties are untouched. * * @param backend_data backend data * @param op the operation to perform @@ -247,7 +243,7 @@ struct backend_operations { /** * Read the color of the pixel at given position of the given image. Image - * properties have no effect. BAKE them first before reading the pixels. + * properties have no effect. * * @param backend_data backend_data * @param image_data an image data structure previously returned by the diff --git a/src/backend/gl/gl_common.c b/src/backend/gl/gl_common.c index b7b2652..ba94c98 100644 --- a/src/backend/gl/gl_common.c +++ b/src/backend/gl/gl_common.c @@ -1778,75 +1778,6 @@ static inline void gl_image_decouple(backend_t *base, struct backend_image *img) inner->refcount--; } -/// Decouple `img` from the image it references, also applies all the lazy operations -static inline void gl_image_bake(backend_t *base, struct backend_image *img) { - if (!img->color_inverted && img->opacity == 1 && img->max_brightness == 1 && - img->dim == 0) { - // Nothing to bake - return; - } - auto gd = (struct gl_data *)base; - auto new_tex = ccalloc(1, struct gl_texture); - auto inner = (struct gl_texture *)img->inner; - - new_tex->texture = gl_new_texture(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, new_tex->texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, inner->width, inner->height, 0, GL_BGRA, - GL_UNSIGNED_BYTE, NULL); - new_tex->y_inverted = true; - new_tex->height = inner->height; - new_tex->width = inner->width; - new_tex->refcount = 1; - new_tex->user_data = gd->decouple_texture_user_data(base, inner->user_data); - - GLuint fbo; - glGenFramebuffers(1, &fbo); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, - new_tex->texture, 0); - glDrawBuffer(GL_COLOR_ATTACHMENT0); - - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT); - - // clang-format off - GLint coord[] = { - // top left - 0, 0, // vertex coord - 0, 0, // texture coord - - // top right - inner->width, 0, // vertex coord - inner->width, 0, // texture coord - - // bottom right - inner->width, inner->height, - inner->width, inner->height, - - // bottom left - 0, inner->height, - 0, inner->height, - }; - // clang-format on - - _gl_compose(base, img, fbo, coord, (GLuint[]){0, 1, 2, 2, 3, 0}, 1); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - glDeleteFramebuffers(1, &fbo); - - inner->refcount--; - if (inner->refcount == 0) { - gl_release_image_inner(base, inner); - } - img->inner = (struct backend_image_inner_base *)new_tex; - - // Clear lazy operation flags - img->color_inverted = false; - img->dim = 0; - img->opacity = 1; - - gl_check_err(); -} - static void gl_image_apply_alpha(backend_t *base, struct backend_image *img, const region_t *reg_op, double alpha) { // Result color = 0 (GL_ZERO) + alpha (GL_CONSTANT_ALPHA) * original color @@ -1926,7 +1857,6 @@ bool gl_image_op(backend_t *base, enum image_operations op, void *image_data, assert(tex->inner->refcount == 1); gl_image_apply_alpha(base, tex, reg_op, *(double *)arg); break; - case IMAGE_OP_BAKE_PROPERTIES: gl_image_bake(base, tex); break; } return true; diff --git a/src/backend/xrender/xrender.c b/src/backend/xrender/xrender.c index 725e5bb..d28f4fb 100644 --- a/src/backend/xrender/xrender.c +++ b/src/backend/xrender/xrender.c @@ -527,36 +527,6 @@ static bool decouple_image(backend_t *base, struct backend_image *img, const reg inner->refcount--; return true; } -static bool bake_image(backend_t *base, struct backend_image *img, const region_t *reg) { - struct _xrender_data *xd = (void *)base; - struct _xrender_image_data_inner *inner = (void *)img->inner; - assert(inner->visual != XCB_NONE); - - if (!img->color_inverted && img->opacity == 1 && img->dim == 0) { - // Nothing to bake - return true; - } - - log_trace("xrender: copying %#010x visual %#x", inner->pixmap, inner->visual); - auto inner2 = - new_inner(base, inner->width, inner->height, inner->visual, inner->depth); - if (!inner2) { - return false; - } - - inner2->has_alpha = (inner->has_alpha || img->opacity != 1); - compose_impl(xd, img, 0, 0, reg, NULL, inner2->pict); - - img->opacity = 1; - img->inner = (struct backend_image_inner_base *)inner2; - img->dim = 0; - img->color_inverted = false; - inner->refcount--; - if (inner->refcount == 0) { - release_image_inner(base, inner); - } - return true; -} static bool image_op(backend_t *base, enum image_operations op, void *image, const region_t *reg_op, const region_t *reg_visible, void *arg) { @@ -569,8 +539,6 @@ static bool image_op(backend_t *base, enum image_operations op, void *image, pixman_region32_intersect(®, (region_t *)reg_op, (region_t *)reg_visible); switch (op) { - case IMAGE_OP_BAKE_PROPERTIES: return bake_image(base, img, ®); - case IMAGE_OP_APPLY_ALPHA: assert(reg_op);