Commit 1b745e0c authored by Keith Packard's avatar Keith Packard

glamor: Adapt glamor_program API to handle render acceleration

This extends the existing API to support options needed for render
accleration, including an additional fragment, 'combine', (which
provides a place to perform the source IN mask operation before the
final OP dest state) and an additional 'defines' parameter which
provides a way to add target-dependent values without using a uniform.
Signed-off-by: default avatarKeith Packard <keithp@keithp.com>
Reviewed-by: default avatarEric Anholt <eric@anholt.net>
parent ff3195aa
......@@ -53,7 +53,7 @@ static const glamor_facet glamor_facet_copyarea = {
.vs_exec = (GLAMOR_POS(gl_Position, primitive.xy)
" fill_pos = (fill_offset + primitive.xy) * 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_copyarea,
};
......@@ -140,7 +140,7 @@ static const glamor_facet glamor_facet_copyplane = {
" gl_FragColor = fg;\n"
" else\n"
" gl_FragColor = bg;\n"),
.locations = glamor_program_location_fill|glamor_program_location_fg|glamor_program_location_bg|glamor_program_location_bitplane,
.locations = glamor_program_location_fillsamp|glamor_program_location_fillpos|glamor_program_location_fg|glamor_program_location_bg|glamor_program_location_bitplane,
.use = use_copyplane,
};
......@@ -338,7 +338,7 @@ glamor_copy_fbo_fbo_draw(DrawablePtr src,
if (!prog->prog) {
if (!glamor_build_program(screen, prog,
copy_facet, NULL))
copy_facet, NULL, NULL, NULL))
goto bail_ctx;
}
......
......@@ -170,7 +170,7 @@ glamor_dash_setup(DrawablePtr drawable, GCPtr gc)
if (!prog->prog) {
if (!glamor_build_program(screen, prog,
&glamor_facet_double_dash_lines,
NULL))
NULL, NULL, NULL))
goto bail;
}
......
......@@ -60,7 +60,8 @@ glamor_poly_point_gl(DrawablePtr drawable, GCPtr gc, int mode, int npt, DDXPoint
if (!prog->prog) {
if (!glamor_build_program(screen, prog,
&glamor_facet_point,
&glamor_fill_solid))
&glamor_fill_solid,
NULL, NULL))
goto bail;
}
......
This diff is collapsed.
......@@ -27,23 +27,36 @@ typedef enum {
glamor_program_location_none = 0,
glamor_program_location_fg = 1,
glamor_program_location_bg = 2,
glamor_program_location_fill = 4,
glamor_program_location_font = 8,
glamor_program_location_bitplane = 16,
glamor_program_location_dash = 32,
glamor_program_location_fillsamp = 4,
glamor_program_location_fillpos = 8,
glamor_program_location_font = 16,
glamor_program_location_bitplane = 32,
glamor_program_location_dash = 64,
glamor_program_location_atlas = 128,
} glamor_program_location;
typedef enum {
glamor_program_flag_none = 0,
} glamor_program_flag;
typedef enum {
glamor_program_alpha_normal,
glamor_program_alpha_ca_first,
glamor_program_alpha_ca_second,
glamor_program_alpha_count
} glamor_program_alpha;
typedef struct _glamor_program glamor_program;
typedef Bool (*glamor_use) (PixmapPtr pixmap, GCPtr gc, glamor_program *prog, void *arg);
typedef Bool (*glamor_use_render) (CARD8 op, PicturePtr src, PicturePtr dst, glamor_program *prog);
typedef struct {
const char *name;
const int version;
char *vs_defines;
char *fs_defines;
const char *vs_vars;
const char *vs_exec;
const char *fs_vars;
......@@ -52,6 +65,7 @@ typedef struct {
const glamor_program_flag flags;
const char *source_name;
glamor_use use;
glamor_use_render use_render;
} glamor_facet;
struct _glamor_program {
......@@ -71,6 +85,9 @@ struct _glamor_program {
glamor_program_flag flags;
glamor_use prim_use;
glamor_use fill_use;
glamor_program_alpha alpha;
glamor_use_render prim_use_render;
glamor_use_render fill_use_render;
};
typedef struct {
......@@ -83,7 +100,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);
Bool
glamor_use_program(PixmapPtr pixmap,
......@@ -97,4 +116,37 @@ glamor_use_program_fill(PixmapPtr pixmap,
glamor_program_fill *program_fill,
const glamor_facet *prim);
typedef enum {
glamor_program_source_solid,
glamor_program_source_picture,
glamor_program_source_1x1_picture,
glamor_program_source_count,
} glamor_program_source;
typedef struct {
glamor_program progs[glamor_program_source_count][glamor_program_alpha_count];
} glamor_program_render;
static inline Bool
glamor_is_component_alpha(PicturePtr mask) {
if (mask && mask->componentAlpha && PICT_FORMAT_RGB(mask->format))
return TRUE;
return FALSE;
}
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);
Bool
glamor_use_program_render(glamor_program *prog,
CARD8 op,
PicturePtr src,
PicturePtr dst);
#endif /* _GLAMOR_PROGRAM_H_ */
......@@ -417,7 +417,7 @@ glamor_image_text(DrawablePtr drawable, GCPtr gc,
fill_facet = &glamor_facet_image_fill;
}
if (!glamor_build_program(screen, prog, prim_facet, fill_facet))
if (!glamor_build_program(screen, prog, prim_facet, fill_facet, NULL, NULL))
goto bail;
}
......
......@@ -155,11 +155,7 @@ glamor_set_solid(PixmapPtr pixmap,
}
Bool
glamor_set_texture(PixmapPtr texture,
int off_x,
int off_y,
GLint offset_uniform,
GLint size_inv_uniform)
glamor_set_texture_pixmap(PixmapPtr texture)
{
glamor_pixmap_private *texture_priv;
......@@ -174,6 +170,23 @@ glamor_set_texture(PixmapPtr texture,
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture_priv->fbo->tex);
/* we're not setting the sampler uniform here as we always use
* GL_TEXTURE0, and the default value for uniforms is zero. So,
* save a bit of CPU time by taking advantage of that.
*/
return TRUE;
}
Bool
glamor_set_texture(PixmapPtr texture,
int off_x,
int off_y,
GLint offset_uniform,
GLint size_inv_uniform)
{
if (!glamor_set_texture_pixmap(texture))
return FALSE;
glUniform2f(offset_uniform, off_x, off_y);
glUniform2f(size_inv_uniform, 1.0f/texture->drawable.width, 1.0f/texture->drawable.height);
return TRUE;
......
......@@ -38,6 +38,9 @@ glamor_set_color(PixmapPtr pixmap,
CARD32 pixel,
GLint uniform);
Bool
glamor_set_texture_pixmap(PixmapPtr texture);
Bool
glamor_set_texture(PixmapPtr texture,
int off_x,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment