aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/glamor/glamor_program.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2015-05-15 19:14:42 +0200
committermarha <marha@users.sourceforge.net>2015-05-15 19:14:42 +0200
commit843964ee791452b197e41dacb0146f5b456ffaa5 (patch)
treeb1b0734c17ce1d488aa4d6e95f27363d80731e10 /xorg-server/glamor/glamor_program.c
parenta71d524ecad48837e0124a03124bc05f59a48be7 (diff)
downloadvcxsrv-843964ee791452b197e41dacb0146f5b456ffaa5.tar.gz
vcxsrv-843964ee791452b197e41dacb0146f5b456ffaa5.tar.bz2
vcxsrv-843964ee791452b197e41dacb0146f5b456ffaa5.zip
randrproto fontconfig libfontenc libxcb mesalib xserver pixman xkeyboard-config git update 15 May 2015
xserver commit bf6344e1913a5d24c2d68eaca999ea3d71e1b707 libxcb commit cb621341a62e6d2233db3e337611f6fdd4f675a6 libxcb/xcb-proto commit 4c550465934164aab2449a125f75f4ca07816233 xkeyboard-config commit 5da6d510b460cad1b31288618cc364e586576826 libX11 commit d3415d1f052530760b4617db45affcb984cfe35c libXdmcp commit b10f382e3aa2e86cd5a2bc27d6758da55f0ab1f6 libXext commit efdcbb7634501e1117d422636a0a75d7ea84b16b libfontenc commit 42f3a39c3085afd9ef904ae39102fd49bbc2e4a5 libXinerama commit edd95182b26eb5d576d4878c559e0f17dddaa909 libXau commit 1e4635be11154dd8262f37b379511bd627defa2a xkbcomp commit 1ae525b3d236b59e6437b2b5433d460e18370973 pixman commit 82f9b4faaf1aa63ec26b0dfd227f1a8e5e139ae2 xextproto commit 66afec3f49e8eb0d4c2e9af7088fc3116d4bafd7 randrproto commit 895ee5264524c7c239ee4ef5e39c4e295323fb51 glproto commit bd3d751e1eb17efb39f65093271bb4ac071aa9e0 mkfontscale commit 87d628f8eec170ec13bb9feefb1ce05aed07d1d6 xwininfo commit 0c49f8f2bd56b1e77721e81030ea948386dcdf4e libXft commit e8a83226bc10afb587f6f34daac44d2ef809c85e libXmu commit 4459e6940fe3fdf26a8d5d4c71989498bc400a62 libxtrans commit 7cbad9fe2e61cd9d5caeaf361826a6f4bd320f03 fontconfig commit 55ff8419274fd5ce59675f220b85035a3986d6cf mesa commit 3687d752e51829b4723c9abb07ae56d2bbcda570
Diffstat (limited to 'xorg-server/glamor/glamor_program.c')
-rw-r--r--xorg-server/glamor/glamor_program.c281
1 files changed, 267 insertions, 14 deletions
diff --git a/xorg-server/glamor/glamor_program.c b/xorg-server/glamor/glamor_program.c
index 8aab53f4f..1dc5f1983 100644
--- a/xorg-server/glamor/glamor_program.c
+++ b/xorg-server/glamor/glamor_program.c
@@ -47,7 +47,7 @@ static const glamor_facet glamor_fill_tile = {
.name = "tile",
.vs_exec = " fill_pos = (fill_offset + primitive.xy + pos) * fill_size_inv;\n",
.fs_exec = " gl_FragColor = texture2D(sampler, fill_pos);\n",
- .locations = glamor_program_location_fill,
+ .locations = glamor_program_location_fillsamp | glamor_program_location_fillpos,
.use = use_tile,
};
@@ -66,7 +66,7 @@ static const glamor_facet glamor_fill_stipple = {
" if (a == 0.0)\n"
" discard;\n"
" gl_FragColor = fg;\n"),
- .locations = glamor_program_location_fg | glamor_program_location_fill,
+ .locations = glamor_program_location_fg | glamor_program_location_fillsamp | glamor_program_location_fillpos,
.use = use_stipple,
};
@@ -87,7 +87,7 @@ static const glamor_facet glamor_fill_opaque_stipple = {
" gl_FragColor = bg;\n"
" else\n"
" gl_FragColor = fg;\n"),
- .locations = glamor_program_location_fg | glamor_program_location_bg | glamor_program_location_fill,
+ .locations = glamor_program_location_fg | glamor_program_location_bg | glamor_program_location_fillsamp | glamor_program_location_fillpos,
.use = use_opaque_stipple
};
@@ -114,12 +114,15 @@ static glamor_location_var location_vars[] = {
.fs_vars = "uniform vec4 bg;\n"
},
{
- .location = glamor_program_location_fill,
+ .location = glamor_program_location_fillsamp,
+ .fs_vars = "uniform sampler2D sampler;\n"
+ },
+ {
+ .location = glamor_program_location_fillpos,
.vs_vars = ("uniform vec2 fill_offset;\n"
"uniform vec2 fill_size_inv;\n"
"varying vec2 fill_pos;\n"),
- .fs_vars = ("uniform sampler2D sampler;\n"
- "uniform vec2 fill_size_inv;\n"
+ .fs_vars = ("uniform vec2 fill_size_inv;\n"
"varying vec2 fill_pos;\n")
},
{
@@ -136,6 +139,10 @@ static glamor_location_var location_vars[] = {
.vs_vars = "uniform float dash_length;\n",
.fs_vars = "uniform sampler2D dash;\n",
},
+ {
+ .location = glamor_program_location_atlas,
+ .fs_vars = "uniform sampler2D atlas;\n",
+ },
};
#define NUM_LOCATION_VARS (sizeof location_vars / sizeof location_vars[0])
@@ -183,6 +190,7 @@ fs_location_vars(glamor_program_location locations)
static const char vs_template[] =
"%s" /* version */
+ "%s" /* defines */
"%s" /* prim vs_vars */
"%s" /* fill vs_vars */
"%s" /* location vs_vars */
@@ -195,12 +203,14 @@ static const char vs_template[] =
static const char fs_template[] =
"%s" /* version */
GLAMOR_DEFAULT_PRECISION
+ "%s" /* defines */
"%s" /* prim fs_vars */
"%s" /* fill fs_vars */
"%s" /* location fs_vars */
"void main() {\n"
"%s" /* prim fs_exec */
"%s" /* fill fs_exec */
+ "%s" /* combine */
"}\n";
static const char *
@@ -236,7 +246,9 @@ Bool
glamor_build_program(ScreenPtr screen,
glamor_program *prog,
const glamor_facet *prim,
- const glamor_facet *fill)
+ const glamor_facet *fill,
+ const char *combine,
+ const char *defines)
{
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
@@ -282,6 +294,7 @@ glamor_build_program(ScreenPtr screen,
if (asprintf(&vs_prog_string,
vs_template,
str(version_string),
+ str(defines),
str(prim->vs_vars),
str(fill->vs_vars),
vs_vars,
@@ -292,26 +305,30 @@ glamor_build_program(ScreenPtr screen,
if (asprintf(&fs_prog_string,
fs_template,
str(version_string),
+ str(defines),
str(prim->fs_vars),
str(fill->fs_vars),
fs_vars,
str(prim->fs_exec),
- str(fill->fs_exec)) < 0)
+ str(fill->fs_exec),
+ str(combine)) < 0)
fs_prog_string = NULL;
if (!vs_prog_string || !fs_prog_string)
goto fail;
+ prog->prog = glCreateProgram();
#if DBG
- ErrorF("\nPrograms for %s %s\nVertex shader:\n\n%s\n\nFragment Shader:\n\n%s",
- prim->name, fill->name, vs_prog_string, fs_prog_string);
+ ErrorF("\n\tProgram %d for %s %s\n\tVertex shader:\n\n\t================\n%s\n\n\tFragment Shader:\n\n%s\t================\n",
+ prog->prog, prim->name, fill->name, vs_prog_string, fs_prog_string);
#endif
- prog->prog = glCreateProgram();
prog->flags = flags;
prog->locations = locations;
prog->prim_use = prim->use;
+ prog->prim_use_render = prim->use_render;
prog->fill_use = fill->use;
+ prog->fill_use_render = fill->use_render;
vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_prog_string);
fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, fs_prog_string);
@@ -335,13 +352,14 @@ glamor_build_program(ScreenPtr screen,
prog->matrix_uniform = glamor_get_uniform(prog, glamor_program_location_none, "v_matrix");
prog->fg_uniform = glamor_get_uniform(prog, glamor_program_location_fg, "fg");
prog->bg_uniform = glamor_get_uniform(prog, glamor_program_location_bg, "bg");
- prog->fill_offset_uniform = glamor_get_uniform(prog, glamor_program_location_fill, "fill_offset");
- prog->fill_size_inv_uniform = glamor_get_uniform(prog, glamor_program_location_fill, "fill_size_inv");
+ prog->fill_offset_uniform = glamor_get_uniform(prog, glamor_program_location_fillpos, "fill_offset");
+ prog->fill_size_inv_uniform = glamor_get_uniform(prog, glamor_program_location_fillpos, "fill_size_inv");
prog->font_uniform = glamor_get_uniform(prog, glamor_program_location_font, "font");
prog->bitplane_uniform = glamor_get_uniform(prog, glamor_program_location_bitplane, "bitplane");
prog->bitmul_uniform = glamor_get_uniform(prog, glamor_program_location_bitplane, "bitmul");
prog->dash_uniform = glamor_get_uniform(prog, glamor_program_location_dash, "dash");
prog->dash_length_uniform = glamor_get_uniform(prog, glamor_program_location_dash, "dash_length");
+ prog->atlas_uniform = glamor_get_uniform(prog, glamor_program_location_atlas, "atlas");
free(version_string);
free(fs_vars);
@@ -396,7 +414,7 @@ glamor_use_program_fill(PixmapPtr pixmap,
if (!fill)
return NULL;
- if (!glamor_build_program(screen, prog, prim, fill))
+ if (!glamor_build_program(screen, prog, prim, fill, NULL, NULL))
return NULL;
}
@@ -405,3 +423,238 @@ glamor_use_program_fill(PixmapPtr pixmap,
return prog;
}
+
+static struct blendinfo composite_op_info[] = {
+ [PictOpClear] = {0, 0, GL_ZERO, GL_ZERO},
+ [PictOpSrc] = {0, 0, GL_ONE, GL_ZERO},
+ [PictOpDst] = {0, 0, GL_ZERO, GL_ONE},
+ [PictOpOver] = {0, 1, GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
+ [PictOpOverReverse] = {1, 0, GL_ONE_MINUS_DST_ALPHA, GL_ONE},
+ [PictOpIn] = {1, 0, GL_DST_ALPHA, GL_ZERO},
+ [PictOpInReverse] = {0, 1, GL_ZERO, GL_SRC_ALPHA},
+ [PictOpOut] = {1, 0, GL_ONE_MINUS_DST_ALPHA, GL_ZERO},
+ [PictOpOutReverse] = {0, 1, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA},
+ [PictOpAtop] = {1, 1, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA},
+ [PictOpAtopReverse] = {1, 1, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA},
+ [PictOpXor] = {1, 1, GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA},
+ [PictOpAdd] = {0, 0, GL_ONE, GL_ONE},
+};
+
+static void
+glamor_set_blend(CARD8 op, glamor_program_alpha alpha, PicturePtr dst)
+{
+ GLenum src_blend, dst_blend;
+ struct blendinfo *op_info;
+
+ switch (alpha) {
+ case glamor_program_alpha_ca_first:
+ op = PictOpOutReverse;
+ break;
+ case glamor_program_alpha_ca_second:
+ op = PictOpAdd;
+ break;
+ default:
+ break;
+ }
+
+ if (op == PictOpSrc)
+ return;
+
+ op_info = &composite_op_info[op];
+
+ src_blend = op_info->source_blend;
+ dst_blend = op_info->dest_blend;
+
+ /* If there's no dst alpha channel, adjust the blend op so that we'll treat
+ * it as always 1.
+ */
+ if (PICT_FORMAT_A(dst->format) == 0 && op_info->dest_alpha) {
+ if (src_blend == GL_DST_ALPHA)
+ src_blend = GL_ONE;
+ else if (src_blend == GL_ONE_MINUS_DST_ALPHA)
+ src_blend = GL_ZERO;
+ }
+
+ /* Set up the source alpha value for blending in component alpha mode. */
+ if (alpha != glamor_program_alpha_normal && op_info->source_alpha) {
+ if (dst_blend == GL_SRC_ALPHA)
+ dst_blend = GL_SRC_COLOR;
+ else if (dst_blend == GL_ONE_MINUS_SRC_ALPHA)
+ dst_blend = GL_ONE_MINUS_SRC_COLOR;
+ }
+
+ glEnable(GL_BLEND);
+ glBlendFunc(src_blend, dst_blend);
+}
+
+static Bool
+use_source_solid(CARD8 op, PicturePtr src, PicturePtr dst, glamor_program *prog)
+{
+
+ glamor_set_blend(op, prog->alpha, dst);
+
+ glamor_set_color(glamor_get_drawable_pixmap(dst->pDrawable),
+ src->pSourcePict->solidFill.color,
+ prog->fg_uniform);
+ return TRUE;
+}
+
+const glamor_facet glamor_source_solid = {
+ .name = "render_solid",
+ .fs_exec = " vec4 source = fg;\n",
+ .locations = glamor_program_location_fg,
+ .use_render = use_source_solid,
+};
+
+static Bool
+use_source_picture(CARD8 op, PicturePtr src, PicturePtr dst, glamor_program *prog)
+{
+ glamor_set_blend(op, prog->alpha, dst);
+
+ return glamor_set_texture((PixmapPtr) src->pDrawable,
+ 0, 0,
+ prog->fill_offset_uniform,
+ prog->fill_size_inv_uniform);
+}
+
+const glamor_facet glamor_source_picture = {
+ .name = "render_picture",
+ .vs_exec = " fill_pos = (fill_offset + primitive.xy + pos) * fill_size_inv;\n",
+ .fs_exec = " vec4 source = texture2D(sampler, fill_pos);\n",
+ .locations = glamor_program_location_fillsamp | glamor_program_location_fillpos,
+ .use_render = use_source_picture,
+};
+
+static Bool
+use_source_1x1_picture(CARD8 op, PicturePtr src, PicturePtr dst, glamor_program *prog)
+{
+ glamor_set_blend(op, prog->alpha, dst);
+
+ return glamor_set_texture_pixmap((PixmapPtr) src->pDrawable);
+}
+
+const glamor_facet glamor_source_1x1_picture = {
+ .name = "render_picture",
+ .fs_exec = " vec4 source = texture2D(sampler, vec2(0.5));\n",
+ .locations = glamor_program_location_fillsamp,
+ .use_render = use_source_1x1_picture,
+};
+
+const glamor_facet *glamor_facet_source[glamor_program_source_count] = {
+ [glamor_program_source_solid] = &glamor_source_solid,
+ [glamor_program_source_picture] = &glamor_source_picture,
+ [glamor_program_source_1x1_picture] = &glamor_source_1x1_picture,
+};
+
+static const char *glamor_combine[] = {
+ [glamor_program_alpha_normal] = " gl_FragColor = source * mask.a;\n",
+ [glamor_program_alpha_ca_first] = " gl_FragColor = source.a * mask;\n",
+ [glamor_program_alpha_ca_second] = " gl_FragColor = source * mask;\n"
+};
+
+static Bool
+glamor_setup_one_program_render(ScreenPtr screen,
+ glamor_program *prog,
+ glamor_program_source source_type,
+ glamor_program_alpha alpha,
+ const glamor_facet *prim,
+ const char *defines)
+{
+ if (prog->failed)
+ return FALSE;
+
+ if (!prog->prog) {
+ const glamor_facet *fill = glamor_facet_source[source_type];
+
+ if (!fill)
+ return FALSE;
+
+ if (!glamor_build_program(screen, prog, prim, fill, glamor_combine[alpha], defines))
+ return FALSE;
+ prog->alpha = alpha;
+ }
+
+ return TRUE;
+}
+
+glamor_program *
+glamor_setup_program_render(CARD8 op,
+ PicturePtr src,
+ PicturePtr mask,
+ PicturePtr dst,
+ glamor_program_render *program_render,
+ const glamor_facet *prim,
+ const char *defines)
+{
+ ScreenPtr screen = dst->pDrawable->pScreen;
+ glamor_program_alpha alpha;
+ glamor_program_source source_type;
+ glamor_program *prog;
+
+ if (op > ARRAY_SIZE(composite_op_info))
+ return NULL;
+
+ if (glamor_is_component_alpha(mask)) {
+ /* This only works for PictOpOver */
+ if (op != PictOpOver)
+ return NULL;
+ alpha = glamor_program_alpha_ca_first;
+ } else
+ alpha = glamor_program_alpha_normal;
+
+ if (src->pDrawable) {
+
+ /* Can't do transforms, alphamaps or sourcing from non-pixmaps yet */
+ if (src->transform || src->alphaMap || src->pDrawable->type != DRAWABLE_PIXMAP)
+ return NULL;
+
+ if (src->pDrawable->width == 1 && src->pDrawable->height == 1 && src->repeat)
+ source_type = glamor_program_source_1x1_picture;
+ else
+ source_type = glamor_program_source_picture;
+ } else {
+ SourcePictPtr sp = src->pSourcePict;
+ if (!sp)
+ return NULL;
+ switch (sp->type) {
+ case SourcePictTypeSolidFill:
+ source_type = glamor_program_source_solid;
+ break;
+ default:
+ return NULL;
+ }
+ }
+
+ prog = &program_render->progs[source_type][alpha];
+ if (!glamor_setup_one_program_render(screen, prog, source_type, alpha, prim, defines))
+ return NULL;
+
+ if (alpha == glamor_program_alpha_ca_first) {
+
+ /* Make sure we can also build the second program before
+ * deciding to use this path.
+ */
+ if (!glamor_setup_one_program_render(screen,
+ &program_render->progs[source_type][glamor_program_alpha_ca_second],
+ source_type, glamor_program_alpha_ca_second, prim,
+ defines))
+ return NULL;
+ }
+ return prog;
+}
+
+Bool
+glamor_use_program_render(glamor_program *prog,
+ CARD8 op,
+ PicturePtr src,
+ PicturePtr dst)
+{
+ glUseProgram(prog->prog);
+
+ if (prog->prim_use_render && !prog->prim_use_render(op, src, dst, prog))
+ return FALSE;
+
+ if (prog->fill_use_render && !prog->fill_use_render(op, src, dst, prog))
+ return FALSE;
+ return TRUE;
+}