backend: remove the read_pixel interface.

Sample the border color in the shader instead.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2022-01-24 17:13:37 +00:00
parent ef73668eb9
commit e50be3173f
No known key found for this signature in database
GPG Key ID: D3A4405BE6CC17F4
8 changed files with 3 additions and 88 deletions

View File

@ -343,14 +343,6 @@ void paint_all_new(session_t *ps, struct managed_win *t, bool ignore_damage) {
ps->backend_data, IMAGE_PROPERTY_CORNER_RADIUS, w->win_image,
(double[]){w->corner_radius});
if (w->corner_radius) {
struct color border_color;
ps->backend_data->ops->read_pixel(
ps->backend_data, w->win_image, 0, w->heightb,
&border_color);
ps->backend_data->ops->set_image_property(
ps->backend_data, IMAGE_PROPERTY_BORDER_COLOR,
w->win_image, &border_color);
int border_width = w->g.border_width;
if (border_width == 0) {
// Some WM has borders implemented as WM frames

View File

@ -58,9 +58,6 @@ enum image_properties {
// Gives the image a rounded corner.
// 1 double, default: 0
IMAGE_PROPERTY_CORNER_RADIUS,
// Border color
// 1 struct color, default: black
IMAGE_PROPERTY_BORDER_COLOR,
// Border width
// 1 int, default: 0
IMAGE_PROPERTY_BORDER_WIDTH,
@ -251,20 +248,6 @@ struct backend_operations {
bool (*image_op)(backend_t *backend_data, enum image_operations op, void *image_data,
const region_t *reg_op, const region_t *reg_visible, void *args);
/**
* Read the color of the pixel at given position of the given image. Image
* properties have no effect.
*
* @param backend_data backend_data
* @param image_data an image data structure previously returned by the
* backend. the image to read pixel from.
* @param x, y coordinate of the pixel to read
* @param[out] color the color of the pixel
* @return whether the operation is successful
*/
bool (*read_pixel)(backend_t *backend_data, void *image_data, int x, int y,
struct color *output);
/// Create another instance of the `image_data`. All `image_op` and
/// `set_image_property` calls on the returned image should not affect the
/// original image

View File

@ -451,7 +451,6 @@ bool default_set_image_property(backend_t *base attr_unused, enum image_properti
break;
case IMAGE_PROPERTY_CORNER_RADIUS: tex->corner_radius = dargs[0]; break;
case IMAGE_PROPERTY_MAX_BRIGHTNESS: tex->max_brightness = dargs[0]; break;
case IMAGE_PROPERTY_BORDER_COLOR: tex->border_color = *(struct color *)arg; break;
case IMAGE_PROPERTY_BORDER_WIDTH: tex->border_width = *(int *)arg; break;
}

View File

@ -41,7 +41,6 @@ struct backend_image {
// Effective size of the image
int ewidth, eheight;
bool color_inverted;
struct color border_color;
int border_width;
};

View File

@ -397,10 +397,6 @@ static void _gl_compose(backend_t *base, struct backend_image *img, GLuint targe
if (gd->win_shader.uniform_border_width >= 0) {
glUniform1f(gd->win_shader.uniform_border_width, (float)img->border_width);
}
if (gd->win_shader.uniform_border_color >= 0) {
glUniform3f(gd->win_shader.uniform_border_color, (float)img->border_color.red,
(float)img->border_color.green, (float)img->border_color.blue);
}
// log_trace("Draw: %d, %d, %d, %d -> %d, %d (%d, %d) z %d\n",
// x, y, width, height, dx, dy, ptex->width, ptex->height, z);
@ -901,7 +897,6 @@ static int gl_win_shader_from_string(const char *vshader_str, const char *fshade
bind_uniform(ret, max_brightness);
bind_uniform(ret, corner_radius);
bind_uniform(ret, border_width);
bind_uniform(ret, border_color);
gl_check_err();
@ -1534,7 +1529,6 @@ const char *win_shader_glsl = GLSL(330,
uniform float dim;
uniform float corner_radius;
uniform float border_width;
uniform vec3 border_color;
uniform bool invert_color;
in vec2 texcoord;
uniform sampler2D tex;
@ -1549,6 +1543,7 @@ const char *win_shader_glsl = GLSL(330,
void main() {
vec4 c = texelFetch(tex, ivec2(texcoord), 0);
vec4 border_color = texture(tex, vec2(0.0, 0.5));
if (invert_color) {
c = vec4(c.aaa - c.rgb, c.a);
}
@ -1567,10 +1562,10 @@ const char *win_shader_glsl = GLSL(330,
float rect_distance = rectangle_sdf(texcoord - outer_size / 2.0f,
inner_size / 2.0f) - corner_radius;
if (rect_distance > 0.0f) {
c = (1.0f - clamp(rect_distance, 0.0f, 1.0f)) * vec4(border_color, 1.0);
c = (1.0f - clamp(rect_distance, 0.0f, 1.0f)) * border_color;
} else {
float factor = clamp(rect_distance + border_width, 0.0f, 1.0f);
c = (1.0f - factor) * c + factor * vec4(border_color, 1.0);
c = (1.0f - factor) * c + factor * border_color;
}
gl_FragColor = c;
@ -1913,29 +1908,3 @@ bool gl_image_op(backend_t *base, enum image_operations op, void *image_data,
return true;
}
bool gl_read_pixel(backend_t *base attr_unused, void *image_data, int x, int y,
struct color *output) {
struct backend_image *tex = image_data;
auto inner = (struct gl_texture *)tex->inner;
GLuint fbo;
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
inner->texture, 0);
glReadBuffer(GL_COLOR_ATTACHMENT0);
GLfloat color[4];
glReadPixels(x, inner->y_inverted ? inner->height - y : y, 1, 1, GL_RGBA,
GL_FLOAT, color);
output->alpha = color[3];
output->red = color[0];
output->green = color[1];
output->blue = color[2];
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &fbo);
bool ret = glGetError() == GL_NO_ERROR;
gl_clear_err();
return ret;
}

View File

@ -37,7 +37,6 @@ typedef struct {
GLint uniform_max_brightness;
GLint uniform_corner_radius;
GLint uniform_border_width;
GLint uniform_border_color;
} gl_win_shader_t;
// Program and uniforms for brightness shader

View File

@ -530,7 +530,6 @@ struct backend_operations glx_ops = {
.compose = gl_compose,
.image_op = gl_image_op,
.set_image_property = default_set_image_property,
.read_pixel = gl_read_pixel,
.clone_image = default_clone_image,
.blur = gl_blur,
.is_image_transparent = default_is_image_transparent,

View File

@ -745,30 +745,6 @@ static void get_blur_size(void *blur_context, int *width, int *height) {
*height = ctx->resize_height;
}
static bool
read_pixel(backend_t *backend_data, void *image_data, int x, int y, struct color *output) {
auto xd = (struct _xrender_data *)backend_data;
auto img = (struct backend_image *)image_data;
auto inner = (struct _xrender_image_data_inner *)img->inner;
auto r = XCB_AWAIT(xcb_get_image, xd->base.c, XCB_IMAGE_FORMAT_XY_PIXMAP, inner->pixmap,
to_i16_checked(x), to_i16_checked(y), 1, 1, (uint32_t)-1L);
if (!r) {
return false;
}
// Color format seems to be BGRA8888, see glamor_format_for_pixmap from the
// Xserver codebase.
uint8_t *pixels = xcb_get_image_data(r);
output->blue = pixels[0] / 255.0;
output->green = pixels[1] / 255.0;
output->red = pixels[2] / 255.0;
output->alpha = pixels[3] / 255.0;
return true;
}
static backend_t *backend_xrender_init(session_t *ps) {
auto xd = ccalloc(1, struct _xrender_data);
init_backend_base(&xd->base, ps);
@ -888,7 +864,6 @@ struct backend_operations xrender_ops = {
.max_buffer_age = 2,
.image_op = image_op,
.read_pixel = read_pixel,
.clone_image = clone_image,
.set_image_property = set_image_property,
.create_blur_context = create_blur_context,