backend: remove image operation BAKE

It's not used.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2021-06-20 06:59:55 +01:00
parent 48b7d7c27d
commit 710e5fd7a0
No known key found for this signature in database
GPG Key ID: D3A4405BE6CC17F4
3 changed files with 2 additions and 108 deletions

View File

@ -57,9 +57,6 @@ enum image_properties {
}; };
enum image_operations { 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 // Multiply the alpha channel by the argument
IMAGE_OP_APPLY_ALPHA, IMAGE_OP_APPLY_ALPHA,
}; };
@ -228,8 +225,7 @@ struct backend_operations {
void *image_data, void *args); void *image_data, void *args);
/** /**
* Manipulate an image. Image properties are untouched by and have no effects on * Manipulate an image. Image properties are untouched.
* operations other than BAKE.
* *
* @param backend_data backend data * @param backend_data backend data
* @param op the operation to perform * @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 * 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 backend_data backend_data
* @param image_data an image data structure previously returned by the * @param image_data an image data structure previously returned by the

View File

@ -1778,75 +1778,6 @@ static inline void gl_image_decouple(backend_t *base, struct backend_image *img)
inner->refcount--; 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, static void gl_image_apply_alpha(backend_t *base, struct backend_image *img,
const region_t *reg_op, double alpha) { const region_t *reg_op, double alpha) {
// Result color = 0 (GL_ZERO) + alpha (GL_CONSTANT_ALPHA) * original color // 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); assert(tex->inner->refcount == 1);
gl_image_apply_alpha(base, tex, reg_op, *(double *)arg); gl_image_apply_alpha(base, tex, reg_op, *(double *)arg);
break; break;
case IMAGE_OP_BAKE_PROPERTIES: gl_image_bake(base, tex); break;
} }
return true; return true;

View File

@ -527,36 +527,6 @@ static bool decouple_image(backend_t *base, struct backend_image *img, const reg
inner->refcount--; inner->refcount--;
return true; 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, 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) { 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(&reg, (region_t *)reg_op, (region_t *)reg_visible); pixman_region32_intersect(&reg, (region_t *)reg_op, (region_t *)reg_visible);
switch (op) { switch (op) {
case IMAGE_OP_BAKE_PROPERTIES: return bake_image(base, img, &reg);
case IMAGE_OP_APPLY_ALPHA: case IMAGE_OP_APPLY_ALPHA:
assert(reg_op); assert(reg_op);