diff mbox

[04/21] gl: Pass more information to the shader emitter functions

Message ID 1311602208-5973-4-git-send-email-alexandros.frantzis@linaro.org
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org July 25, 2011, 1:56 p.m. UTC
From: Alexandros Frantzis <alexandros.frantzis@linaro.org>

This makes the shader emitter functions more versatile. It allows them to use
all information provided by the operands and the context to decide what shader
to produce.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 src/cairo-gl-composite.c |    8 ++++----
 src/cairo-gl-private.h   |    4 ++--
 src/cairo-gl-shaders.c   |   34 +++++++++++++++++-----------------
 3 files changed, 23 insertions(+), 23 deletions(-)
diff mbox

Patch

diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c
index c8f84a9..05982c4 100644
--- a/src/cairo-gl-composite.c
+++ b/src/cairo-gl-composite.c
@@ -782,8 +782,8 @@  _cairo_gl_composite_begin_component_alpha  (cairo_gl_context_t *ctx,
     if (setup->op == CAIRO_OPERATOR_OVER) {
 	setup->op = CAIRO_OPERATOR_ADD;
 	status = _cairo_gl_get_shader_by_type (ctx,
-                                               setup->src.type,
-                                               setup->mask.type,
+                                               &setup->src,
+                                               &setup->mask,
                                                CAIRO_GL_SHADER_IN_CA_SOURCE_ALPHA,
                                                &pre_shader);
         if (unlikely (status))
@@ -831,8 +831,8 @@  _cairo_gl_composite_begin (cairo_gl_composite_t *setup,
     }
 
     status = _cairo_gl_get_shader_by_type (ctx,
-                                           setup->src.type,
-                                           setup->mask.type,
+                                           &setup->src,
+                                           &setup->mask,
                                            component_alpha ? CAIRO_GL_SHADER_IN_CA_SOURCE
                                                            : CAIRO_GL_SHADER_IN_NORMAL,
                                            &shader);
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 602550f..e4f1cce 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -517,8 +517,8 @@  _cairo_gl_context_is_flushed (cairo_gl_context_t *ctx)
 
 cairo_private cairo_status_t
 _cairo_gl_get_shader_by_type (cairo_gl_context_t *ctx,
-                              cairo_gl_operand_type_t source,
-                              cairo_gl_operand_type_t mask,
+                              cairo_gl_operand_t *source,
+                              cairo_gl_operand_t *mask,
                               cairo_gl_shader_in_t in,
                               cairo_gl_shader_t **shader);
 
diff --git a/src/cairo-gl-shaders.c b/src/cairo-gl-shaders.c
index 39e4e30..c59f4f7 100644
--- a/src/cairo-gl-shaders.c
+++ b/src/cairo-gl-shaders.c
@@ -536,14 +536,14 @@  cairo_gl_shader_get_vertex_source (cairo_gl_var_type_t src,
 
 static void
 cairo_gl_shader_emit_color (cairo_output_stream_t *stream,
-                            GLuint tex_target,
-                            cairo_gl_operand_type_t type,
+                            cairo_gl_context_t *ctx,
+                            cairo_gl_operand_t *op,
                             cairo_gl_tex_t name)
 {
     const char *namestr = operand_names[name];
-    const char *rectstr = (tex_target == GL_TEXTURE_RECTANGLE ? "Rect" : "");
+    const char *rectstr = (ctx->tex_target == GL_TEXTURE_RECTANGLE ? "Rect" : "");
 
-    switch (type) {
+    switch (op->type) {
     case CAIRO_GL_OPERAND_COUNT:
     default:
         ASSERT_NOT_REACHED;
@@ -677,11 +677,11 @@  cairo_gl_shader_emit_color (cairo_output_stream_t *stream,
 }
 
 static cairo_status_t
-cairo_gl_shader_get_fragment_source (GLuint tex_target,
+cairo_gl_shader_get_fragment_source (cairo_gl_context_t *ctx,
                                      cairo_gl_shader_in_t in,
-                                     cairo_gl_operand_type_t src,
-                                     cairo_gl_operand_type_t mask,
-                                     cairo_gl_operand_type_t dest,
+                                     cairo_gl_operand_t *src,
+                                     cairo_gl_operand_t *mask,
+                                     cairo_gl_operand_type_t dest_type,
 				     char **out)
 {
     cairo_output_stream_t *stream = _cairo_memory_stream_create ();
@@ -689,8 +689,8 @@  cairo_gl_shader_get_fragment_source (GLuint tex_target,
     unsigned long length;
     cairo_status_t status;
 
-    cairo_gl_shader_emit_color (stream, tex_target, src, CAIRO_GL_TEX_SOURCE);
-    cairo_gl_shader_emit_color (stream, tex_target, mask, CAIRO_GL_TEX_MASK);
+    cairo_gl_shader_emit_color (stream, ctx, src, CAIRO_GL_TEX_SOURCE);
+    cairo_gl_shader_emit_color (stream, ctx, mask, CAIRO_GL_TEX_MASK);
 
     _cairo_output_stream_printf (stream,
         "void main()\n"
@@ -867,8 +867,8 @@  _cairo_gl_set_shader (cairo_gl_context_t *ctx,
 
 cairo_status_t
 _cairo_gl_get_shader_by_type (cairo_gl_context_t *ctx,
-                              cairo_gl_operand_type_t source,
-                              cairo_gl_operand_type_t mask,
+                              cairo_gl_operand_t *source,
+                              cairo_gl_operand_t *mask,
                               cairo_gl_shader_in_t in,
                               cairo_gl_shader_t **shader)
 {
@@ -876,8 +876,8 @@  _cairo_gl_get_shader_by_type (cairo_gl_context_t *ctx,
     char *fs_source;
     cairo_status_t status;
 
-    lookup.src = source;
-    lookup.mask = mask;
+    lookup.src = source->type;
+    lookup.mask = mask->type;
     lookup.dest = CAIRO_GL_OPERAND_NONE;
     lookup.in = in;
     lookup.base.hash = _cairo_gl_shader_cache_hash (&lookup);
@@ -890,7 +890,7 @@  _cairo_gl_get_shader_by_type (cairo_gl_context_t *ctx,
 	return CAIRO_STATUS_SUCCESS;
     }
 
-    status = cairo_gl_shader_get_fragment_source (ctx->tex_target,
+    status = cairo_gl_shader_get_fragment_source (ctx,
 						  in,
 						  source,
 						  mask,
@@ -911,8 +911,8 @@  _cairo_gl_get_shader_by_type (cairo_gl_context_t *ctx,
     _cairo_gl_shader_init (&entry->shader);
     status = _cairo_gl_shader_compile (ctx,
 				       &entry->shader,
-				       cairo_gl_operand_get_var_type (source),
-				       cairo_gl_operand_get_var_type (mask),
+				       cairo_gl_operand_get_var_type (source->type),
+				       cairo_gl_operand_get_var_type (mask->type),
 				       fs_source);
     free (fs_source);