[PATCH v2 3/3] compositor: Adds the ability to invert colors with Alt + I.
John Kåre Alsaker
john.kare.alsaker at gmail.com
Tue Sep 11 09:57:56 PDT 2012
---
src/compositor.h | 3 +++
src/gles2-renderer.c | 18 ++++++++++++++++--
src/shell.c | 11 +++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/compositor.h b/src/compositor.h
index 284c0ac..8305058 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -296,6 +296,7 @@ struct weston_compositor {
struct weston_shader texture_shader_y_uv;
struct weston_shader texture_shader_y_u_v;
struct weston_shader texture_shader_y_xuxv;
+ struct weston_shader invert_color_shader;
struct weston_shader solid_shader;
struct weston_shader *current_shader;
struct wl_display *wl_display;
@@ -340,6 +341,8 @@ struct weston_compositor {
struct weston_plane primary_plane;
int fan_debug;
+ int invert_color;
+
uint32_t focus;
struct weston_renderer *renderer;
diff --git a/src/gles2-renderer.c b/src/gles2-renderer.c
index 6505344..167ada3 100644
--- a/src/gles2-renderer.c
+++ b/src/gles2-renderer.c
@@ -571,7 +571,7 @@ weston_compositor_use_shader(struct weston_compositor *compositor,
static void
repaint_surfaces_start(struct weston_output *output, pixman_region32_t *damage)
{
- output->indirect_drawing = 0 && !output->indirect_disable;
+ output->indirect_drawing = output->compositor->invert_color && !output->indirect_disable;
if(output->indirect_drawing) {
if(!output->indirect_fbo)
@@ -613,7 +613,7 @@ repaint_surfaces_finish(struct weston_output *output, pixman_region32_t *damage)
if(output->indirect_drawing) {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
- struct weston_shader *shader = &ec->texture_shader_rgba;
+ struct weston_shader *shader = &ec->invert_color_shader;
weston_compositor_use_shader(ec, shader);
@@ -1073,6 +1073,17 @@ static const char texture_fragment_shader_y_xuxv[] =
FRAGMENT_CONVERT_YUV
"}\n";
+static const char invert_color_fragment_shader[] =
+ "precision mediump float;\n"
+ "varying vec2 v_texcoord;\n"
+ "uniform sampler2D tex;\n"
+ "uniform float alpha;\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = texture2D(tex, v_texcoord);\n;"
+ " gl_FragColor.rgb = vec3(1.0) - gl_FragColor.rgb;\n;"
+ "}\n";
+
static const char solid_fragment_shader[] =
"precision mediump float;\n"
"uniform vec4 color;\n"
@@ -1316,6 +1327,9 @@ gles2_renderer_init(struct weston_compositor *ec)
if (weston_shader_init(&ec->texture_shader_y_xuxv,
vertex_shader, texture_fragment_shader_y_xuxv) < 0)
return -1;
+ if (weston_shader_init(&ec->invert_color_shader,
+ vertex_shader, invert_color_fragment_shader) < 0)
+ return -1;
if (weston_shader_init(&ec->solid_shader,
vertex_shader, solid_fragment_shader) < 0)
return -1;
diff --git a/src/shell.c b/src/shell.c
index 06d8684..b40a738 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -3488,6 +3488,15 @@ debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
}
}
+static void
+invert_color_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
+ void *data)
+{
+ struct desktop_shell *shell = data;
+ struct weston_compositor *compositor = shell->compositor;
+ compositor->invert_color = !compositor->invert_color;
+ weston_compositor_damage_all(compositor);
+}
static void
fan_debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
@@ -3664,6 +3673,8 @@ shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
backlight_binding, ec);
weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
debug_repaint_binding, shell);
+ weston_compositor_add_key_binding(ec, KEY_I, mod | MODIFIER_ALT,
+ invert_color_binding, shell);
weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_ALT,
fan_debug_repaint_binding, shell);
weston_compositor_add_key_binding(ec, KEY_K, mod,
--
1.7.12
More information about the wayland-devel
mailing list