diff options
author | Eric Anholt <eric@anholt.net> | 2016-01-26 15:19:50 -0800 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2016-01-26 15:21:54 -0800 |
commit | 6ce0e5fc7cccb825381db01e74c7d3e29ad89e8e (patch) | |
tree | 0b3e49b97130d495c71715c2a73764eb2a91b80b | |
parent | c0ea869b7b304d83c9ca61c6e6ec5c85f7b487ed (diff) |
glamor: Convert XV to using glamor_program.c.
One less custom path! By following the common glamor_program.c use
pattern, we get the ability to handle large pixmaps as the
destination. It's also one less place where glamor_utils.h coordinate
transformation happens.
Signed-off-by: Eric Anholt <eric@anholt.net>
-rw-r--r-- | glamor/glamor_priv.h | 2 | ||||
-rw-r--r-- | glamor/glamor_xv.c | 147 |
2 files changed, 71 insertions, 78 deletions
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h index f1eed5bb9..d78db7fc2 100644 --- a/glamor/glamor_priv.h +++ b/glamor/glamor_priv.h @@ -318,7 +318,7 @@ typedef struct glamor_screen_private { Bool logged_any_fbo_allocation_failure; /* xv */ - GLint xv_prog; + glamor_program xv_prog; struct glamor_context ctx; } glamor_screen_private; diff --git a/glamor/glamor_xv.c b/glamor/glamor_xv.c index 2593d47b5..e8c849d8e 100644 --- a/glamor/glamor_xv.c +++ b/glamor/glamor_xv.c @@ -37,6 +37,7 @@ #endif #include "glamor_priv.h" +#include "glamor_transform.h" #include "glamor_transfer.h" #include <X11/extensions/Xv.h> @@ -58,36 +59,36 @@ typedef struct tagREF_TRANSFORM { #define RTFContrast(a) (1.0 + ((a)*1.0)/1000.0) #define RTFHue(a) (((a)*3.1416)/1000.0) -static const char *xv_vs = "attribute vec4 v_position;\n" - "attribute vec4 v_texcoord0;\n" - "varying vec2 tcs;\n" - "void main()\n" - "{\n" - " gl_Position = v_position;\n" - "tcs = v_texcoord0.xy;\n" - "}\n"; - -static const char *xv_ps = GLAMOR_DEFAULT_PRECISION - "uniform sampler2D y_sampler;\n" - "uniform sampler2D u_sampler;\n" - "uniform sampler2D v_sampler;\n" - "uniform vec4 offsetyco;\n" - "uniform vec4 ucogamma;\n" - "uniform vec4 vco;\n" - "varying vec2 tcs;\n" - "float sample;\n" - "vec4 temp1;\n" - "void main()\n" - "{\n" - "sample = texture2D(y_sampler, tcs).w;\n" - "temp1.xyz = offsetyco.www * vec3(sample) + offsetyco.xyz;\n" - "sample = texture2D(u_sampler, tcs).w;\n" - "temp1.xyz = ucogamma.xyz * vec3(sample) + temp1.xyz;\n" - "sample = texture2D(v_sampler, tcs).w;\n" - "temp1.xyz = clamp(vco.xyz * vec3(sample) + temp1.xyz, 0.0, 1.0);\n" - "temp1.w = 1.0;\n" - "gl_FragColor = temp1;\n" - "}\n"; +static const glamor_facet glamor_facet_xv_planar = { + .name = "xv_planar", + + .source_name = "v_texcoord0", + .vs_vars = ("attribute vec2 position;\n" + "attribute vec2 v_texcoord0;\n" + "varying vec2 tcs;\n"), + .vs_exec = (GLAMOR_POS(gl_Position, position) + " tcs = v_texcoord0;\n"), + + .fs_vars = ("uniform sampler2D y_sampler;\n" + "uniform sampler2D u_sampler;\n" + "uniform sampler2D v_sampler;\n" + "uniform vec4 offsetyco;\n" + "uniform vec4 ucogamma;\n" + "uniform vec4 vco;\n" + "varying vec2 tcs;\n"), + .fs_exec = ( + " float sample;\n" + " vec4 temp1;\n" + " sample = texture2D(y_sampler, tcs).w;\n" + " temp1.xyz = offsetyco.www * vec3(sample) + offsetyco.xyz;\n" + " sample = texture2D(u_sampler, tcs).w;\n" + " temp1.xyz = ucogamma.xyz * vec3(sample) + temp1.xyz;\n" + " sample = texture2D(v_sampler, tcs).w;\n" + " temp1.xyz = clamp(vco.xyz * vec3(sample) + temp1.xyz, 0.0, 1.0);\n" + " temp1.w = 1.0;\n" + " gl_FragColor = temp1;\n" + ), +}; #define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE) @@ -113,30 +114,19 @@ int glamor_xv_num_images = ARRAY_SIZE(glamor_xv_images); static void glamor_init_xv_shader(ScreenPtr screen) { - glamor_screen_private *glamor_priv; - GLint fs_prog, vs_prog, sampler_loc; - - glamor_priv = glamor_get_screen_private(screen); - glamor_make_current(glamor_priv); - glamor_priv->xv_prog = glCreateProgram(); - - vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, xv_vs); - fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, xv_ps); - glAttachShader(glamor_priv->xv_prog, vs_prog); - glAttachShader(glamor_priv->xv_prog, fs_prog); + glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); + GLint sampler_loc; - glBindAttribLocation(glamor_priv->xv_prog, - GLAMOR_VERTEX_POS, "v_position"); - glBindAttribLocation(glamor_priv->xv_prog, - GLAMOR_VERTEX_SOURCE, "v_texcoord0"); - glamor_link_glsl_prog(screen, glamor_priv->xv_prog, "xv"); + glamor_build_program(screen, + &glamor_priv->xv_prog, + &glamor_facet_xv_planar, NULL, NULL, NULL); - glUseProgram(glamor_priv->xv_prog); - sampler_loc = glGetUniformLocation(glamor_priv->xv_prog, "y_sampler"); + glUseProgram(glamor_priv->xv_prog.prog); + sampler_loc = glGetUniformLocation(glamor_priv->xv_prog.prog, "y_sampler"); glUniform1i(sampler_loc, 0); - sampler_loc = glGetUniformLocation(glamor_priv->xv_prog, "u_sampler"); + sampler_loc = glGetUniformLocation(glamor_priv->xv_prog.prog, "u_sampler"); glUniform1i(sampler_loc, 1); - sampler_loc = glGetUniformLocation(glamor_priv->xv_prog, "v_sampler"); + sampler_loc = glGetUniformLocation(glamor_priv->xv_prog.prog, "v_sampler"); glUniform1i(sampler_loc, 2); } @@ -256,8 +246,6 @@ glamor_xv_render(glamor_port_private *port_priv) glamor_pixmap_private *src_pixmap_priv[3]; BoxPtr box = REGION_RECTS(&port_priv->clip); int nBox = REGION_NUM_RECTS(&port_priv->clip); - int dst_x_off, dst_y_off; - GLfloat dst_xscale, dst_yscale; GLfloat src_xscale[3], src_yscale[3]; int i; const float Loff = -0.0627; @@ -270,8 +258,9 @@ glamor_xv_render(glamor_port_private *port_priv) GLint uloc; GLfloat *v; char *vbo_offset; + int dst_box_x, dst_box_y; - if (!glamor_priv->xv_prog) + if (!glamor_priv->xv_prog.prog) glamor_init_xv_shader(screen); cont = RTFContrast(port_priv->contrast); @@ -293,10 +282,6 @@ glamor_xv_render(glamor_port_private *port_priv) off[2] = Loff * yco + Coff * (uco[2] + vco[2]) + bright; gamma = 1.0; - pixmap_priv_get_dest_scale(pixmap, pixmap_priv, &dst_xscale, &dst_yscale); - glamor_get_drawable_deltas(port_priv->pDraw, port_priv->pPixmap, &dst_x_off, - &dst_y_off); - glamor_set_destination_pixmap_priv_nc(glamor_priv, pixmap, pixmap_priv); glamor_set_alu(screen, GXcopy); for (i = 0; i < 3; i++) { @@ -308,13 +293,13 @@ glamor_xv_render(glamor_port_private *port_priv) } } glamor_make_current(glamor_priv); - glUseProgram(glamor_priv->xv_prog); + glUseProgram(glamor_priv->xv_prog.prog); - uloc = glGetUniformLocation(glamor_priv->xv_prog, "offsetyco"); + uloc = glGetUniformLocation(glamor_priv->xv_prog.prog, "offsetyco"); glUniform4f(uloc, off[0], off[1], off[2], yco); - uloc = glGetUniformLocation(glamor_priv->xv_prog, "ucogamma"); + uloc = glGetUniformLocation(glamor_priv->xv_prog.prog, "ucogamma"); glUniform4f(uloc, uco[0], uco[1], uco[2], gamma); - uloc = glGetUniformLocation(glamor_priv->xv_prog, "vco"); + uloc = glGetUniformLocation(glamor_priv->xv_prog.prog, "vco"); glUniform4f(uloc, vco[0], vco[1], vco[2], 0); glActiveTexture(GL_TEXTURE0); @@ -352,16 +337,14 @@ glamor_xv_render(glamor_port_private *port_priv) * GL_QUAD. */ i = 0; - v[i++] = v_from_x_coord_x(dst_xscale, port_priv->drw_x + dst_x_off); - v[i++] = v_from_x_coord_y(dst_yscale, port_priv->drw_y + dst_y_off); + v[i++] = port_priv->drw_x; + v[i++] = port_priv->drw_y; - v[i++] = v_from_x_coord_x(dst_xscale, port_priv->drw_x + dst_x_off + - port_priv->dst_w * 2); - v[i++] = v_from_x_coord_y(dst_yscale, port_priv->drw_y + dst_y_off); + v[i++] = port_priv->drw_x + port_priv->dst_w * 2; + v[i++] = port_priv->drw_y; - v[i++] = v_from_x_coord_x(dst_xscale, port_priv->drw_x + dst_x_off); - v[i++] = v_from_x_coord_y(dst_yscale, port_priv->drw_y + dst_y_off + - port_priv->dst_h * 2); + v[i++] = port_priv->drw_x; + v[i++] = port_priv->drw_y + port_priv->dst_h * 2; v[i++] = t_from_x_coord_x(src_xscale[0], port_priv->src_x); v[i++] = t_from_x_coord_y(src_yscale[0], port_priv->src_y); @@ -385,16 +368,26 @@ glamor_xv_render(glamor_port_private *port_priv) glamor_put_vbo_space(screen); /* Now draw our big triangle, clipped to each of the clip boxes. */ - for (i = 0; i < nBox; i++) { - int dstx, dsty, dstw, dsth; + glamor_pixmap_loop(pixmap_priv, dst_box_x, dst_box_y) { + int dst_off_x, dst_off_y; + + glamor_set_destination_drawable(port_priv->pDraw, + dst_box_x, dst_box_y, + FALSE, FALSE, + glamor_priv->xv_prog.matrix_uniform, + &dst_off_x, &dst_off_y); - dstx = box[i].x1 + dst_x_off; - dsty = box[i].y1 + dst_y_off; - dstw = box[i].x2 - box[i].x1; - dsth = box[i].y2 - box[i].y1; + for (i = 0; i < nBox; i++) { + int dstx, dsty, dstw, dsth; - glScissor(dstx, dsty, dstw, dsth); - glDrawArrays(GL_TRIANGLE_FAN, 0, 3); + dstx = box[i].x1 + dst_off_x; + dsty = box[i].y1 + dst_off_y; + dstw = box[i].x2 - box[i].x1; + dsth = box[i].y2 - box[i].y1; + + glScissor(dstx, dsty, dstw, dsth); + glDrawArrays(GL_TRIANGLE_FAN, 0, 3); + } } glDisable(GL_SCISSOR_TEST); |