From 814573a352ddf54e8d2b2bad459f967ce852b769 Mon Sep 17 00:00:00 2001 From: Stanislav Vorobiov Date: Wed, 13 Aug 2014 16:10:47 +0400 Subject: [PATCH] VIGS/qt5: respect maru_brightness Change-Id: Ic8687f08bd03bdbb6b6984661b40eb5989f7a8b8 Signed-off-by: Stanislav Vorobiov --- hw/vigs/vigs_gl_backend.c | 39 ++++++++++++++++++++++++++++++++--- hw/vigs/vigs_gl_backend.h | 3 +++ hw/vigs/vigs_gl_backend_cgl.c | 1 + hw/vigs/vigs_gl_backend_glx.c | 1 + hw/vigs/vigs_gl_backend_wgl.c | 1 + 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/hw/vigs/vigs_gl_backend.c b/hw/vigs/vigs_gl_backend.c index e66eb0bc3d..2330751076 100644 --- a/hw/vigs/vigs_gl_backend.c +++ b/hw/vigs/vigs_gl_backend.c @@ -36,6 +36,7 @@ #include "vigs_ref.h" #include "vigs_qt5.h" #include "winsys_gl.h" +#include "hw/pci/maru_brightness.h" #include extern uint32_t qt5_window_width; @@ -193,10 +194,32 @@ static const char *g_fs_color_source_gl3 = " FragColor = color;\n" "}\n"; +static const char *g_fs_dpy_source_gl2 = + "#version 120\n\n" + "uniform sampler2D tex;\n" + "uniform float brightness;\n" + "varying vec2 v_texCoord;\n" + "void main()\n" + "{\n" + " gl_FragColor = texture2D(tex, v_texCoord) * brightness;\n" + "}\n"; + +static const char *g_fs_dpy_source_gl3 = + "#version 140\n\n" + "uniform sampler2D tex;\n" + "uniform float brightness;\n" + "in vec2 v_texCoord;\n" + "out vec4 FragColor;\n" + "void main()\n" + "{\n" + " FragColor = texture(tex, v_texCoord) * brightness;\n" + "}\n"; + static const char *g_fs_scale_source_gl2 = "#version 120\n\ \n\ uniform sampler2D tex;\n\ +uniform float brightness;\n\ uniform vec2 texSize;\n\ varying vec2 v_texCoord;\n\ vec4 cubic(float x)\n\ @@ -243,13 +266,14 @@ texscale);\n\ \n\ gl_FragColor = mix(\n\ mix(sample3, sample2, sx),\n\ - mix(sample1, sample0, sx), sy);\n\ + mix(sample1, sample0, sx), sy) * brightness;\n\ }"; static const char *g_fs_scale_source_gl3 = "#version 140\n\ \n\ uniform sampler2D tex;\n\ +uniform float brightness;\n\ uniform vec2 texSize;\n\ in vec2 v_texCoord;\n\ out vec4 FragColor;\n\ @@ -297,7 +321,7 @@ texscale);\n\ \n\ FragColor = mix(\n\ mix(sample3, sample2, sx),\n\ - mix(sample1, sample0, sx), sy);\n\ + mix(sample1, sample0, sx), sy) * brightness;\n\ }"; static GLuint vigs_gl_backend_alloc_tmp_texture(void *user_data, @@ -1667,6 +1691,11 @@ static bool vigs_gl_backend_display(struct vigs_backend *backend, bool scale; GLfloat rotated_ortho[16]; GLfloat *ortho; + float brightness = (float)(255 - brightness_tbl[brightness_level]) / 255.0f; + + if (display_off) { + brightness = 0.0f; + } if (!gl_backend->is_gl_2 && !gl_backend->dpy_vao) { gl_backend->GenVertexArrays(1, &gl_backend->dpy_vao); @@ -1710,10 +1739,12 @@ static bool vigs_gl_backend_display(struct vigs_backend *backend, texSize[1] = gl_backend->dpy_tex_height; gl_backend->Uniform2fv(gl_backend->dpy_scale_prog_texSize_loc, 1, texSize); + gl_backend->Uniform1f(gl_backend->dpy_scale_prog_brightness_loc, brightness); } else { gl_backend->UseProgram(gl_backend->dpy_tex_prog_id); gl_backend->UniformMatrix4fv(gl_backend->dpy_tex_prog_proj_loc, 1, GL_FALSE, ortho); + gl_backend->Uniform1f(gl_backend->dpy_tex_prog_brightness_loc, brightness); } gl_backend->BindTexture(GL_TEXTURE_2D, gl_backend->dpy_tex); @@ -1895,7 +1926,7 @@ bool vigs_gl_backend_init(struct vigs_gl_backend *gl_backend) } gl_backend->dpy_tex_prog_fs_id = vigs_gl_create_shader(gl_backend, - (gl_backend->is_gl_2 ? g_fs_tex_source_gl2 : g_fs_tex_source_gl3), + (gl_backend->is_gl_2 ? g_fs_dpy_source_gl2 : g_fs_dpy_source_gl3), GL_FRAGMENT_SHADER); if (!gl_backend->dpy_tex_prog_fs_id) { @@ -1913,6 +1944,7 @@ bool vigs_gl_backend_init(struct vigs_gl_backend *gl_backend) gl_backend->dpy_tex_prog_proj_loc = gl_backend->GetUniformLocation(gl_backend->dpy_tex_prog_id, "proj"); gl_backend->dpy_tex_prog_vertCoord_loc = gl_backend->GetAttribLocation(gl_backend->dpy_tex_prog_id, "vertCoord"); gl_backend->dpy_tex_prog_texCoord_loc = gl_backend->GetAttribLocation(gl_backend->dpy_tex_prog_id, "texCoord"); + gl_backend->dpy_tex_prog_brightness_loc = gl_backend->GetUniformLocation(gl_backend->dpy_tex_prog_id, "brightness"); gl_backend->dpy_scale_prog_vs_id = vigs_gl_create_shader(gl_backend, (gl_backend->is_gl_2 ? g_vs_tex_source_gl2 : g_vs_tex_source_gl3), @@ -1942,6 +1974,7 @@ bool vigs_gl_backend_init(struct vigs_gl_backend *gl_backend) gl_backend->dpy_scale_prog_vertCoord_loc = gl_backend->GetAttribLocation(gl_backend->dpy_scale_prog_id, "vertCoord"); gl_backend->dpy_scale_prog_texCoord_loc = gl_backend->GetAttribLocation(gl_backend->dpy_scale_prog_id, "texCoord"); gl_backend->dpy_scale_prog_texSize_loc = gl_backend->GetUniformLocation(gl_backend->dpy_scale_prog_id, "texSize"); + gl_backend->dpy_scale_prog_brightness_loc = gl_backend->GetUniformLocation(gl_backend->dpy_scale_prog_id, "brightness"); gl_backend->Disable(GL_DEPTH_TEST); gl_backend->Disable(GL_BLEND); diff --git a/hw/vigs/vigs_gl_backend.h b/hw/vigs/vigs_gl_backend.h index 450d1a22df..98cfe990a3 100644 --- a/hw/vigs/vigs_gl_backend.h +++ b/hw/vigs/vigs_gl_backend.h @@ -120,6 +120,7 @@ struct vigs_gl_backend void (GLAPIENTRY* Uniform4fv)(GLint location, GLsizei count, const GLfloat* value); void (GLAPIENTRY* UniformMatrix4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); void (GLAPIENTRY* Uniform2fv)(GLint location, GLsizei count, const GLfloat* value); + void (GLAPIENTRY* Uniform1f)(GLint location, GLfloat v0); /* * @} @@ -201,6 +202,7 @@ struct vigs_gl_backend GLint dpy_tex_prog_proj_loc; GLint dpy_tex_prog_vertCoord_loc; GLint dpy_tex_prog_texCoord_loc; + GLint dpy_tex_prog_brightness_loc; GLuint dpy_scale_prog_vs_id; GLuint dpy_scale_prog_fs_id; @@ -209,6 +211,7 @@ struct vigs_gl_backend GLint dpy_scale_prog_vertCoord_loc; GLint dpy_scale_prog_texCoord_loc; GLint dpy_scale_prog_texSize_loc; + GLint dpy_scale_prog_brightness_loc; GLuint dpy_vbo; uint32_t dpy_vbo_size; diff --git a/hw/vigs/vigs_gl_backend_cgl.c b/hw/vigs/vigs_gl_backend_cgl.c index 768146d2b2..e31adeac72 100644 --- a/hw/vigs/vigs_gl_backend_cgl.c +++ b/hw/vigs/vigs_gl_backend_cgl.c @@ -321,6 +321,7 @@ struct vigs_backend *vigs_gl_backend_create(void *display) VIGS_GL_GET_PROC(Uniform4fv, glUniform4fv); VIGS_GL_GET_PROC(UniformMatrix4fv, glUniformMatrix4fv); VIGS_GL_GET_PROC(Uniform2fv, glUniform2fv); + VIGS_GL_GET_PROC(Uniform1f, glUniform1f); VIGS_GL_GET_PROC_OPTIONAL(MapBufferRange, glMapBufferRange); diff --git a/hw/vigs/vigs_gl_backend_glx.c b/hw/vigs/vigs_gl_backend_glx.c index 9b478dfc8d..ade9181100 100644 --- a/hw/vigs/vigs_gl_backend_glx.c +++ b/hw/vigs/vigs_gl_backend_glx.c @@ -499,6 +499,7 @@ struct vigs_backend *vigs_gl_backend_create(void *display) VIGS_GL_GET_PROC(Uniform4fv, glUniform4fv); VIGS_GL_GET_PROC(UniformMatrix4fv, glUniformMatrix4fv); VIGS_GL_GET_PROC(Uniform2fv, glUniform2fv); + VIGS_GL_GET_PROC(Uniform1f, glUniform1f); VIGS_GL_GET_PROC_OPTIONAL(MapBufferRange, glMapBufferRange); diff --git a/hw/vigs/vigs_gl_backend_wgl.c b/hw/vigs/vigs_gl_backend_wgl.c index 488e2a6a23..eeb121ce45 100644 --- a/hw/vigs/vigs_gl_backend_wgl.c +++ b/hw/vigs/vigs_gl_backend_wgl.c @@ -613,6 +613,7 @@ struct vigs_backend *vigs_gl_backend_create(void *display) VIGS_GL_GET_PROC(Uniform4fv, glUniform4fv); VIGS_GL_GET_PROC(UniformMatrix4fv, glUniformMatrix4fv); VIGS_GL_GET_PROC(Uniform2fv, glUniform2fv); + VIGS_GL_GET_PROC(Uniform1f, glUniform1f); VIGS_GL_GET_PROC_OPTIONAL(MapBufferRange, glMapBufferRange); -- 2.34.1