2009-07-29 16:21:07 +00:00
|
|
|
/*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Cogl
|
2009-07-29 16:21:07 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2009-07-29 16:21:07 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Intel Corporation.
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2009-07-29 16:21:07 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2009-07-29 16:21:07 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2009-07-29 16:21:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "cogl-pango-display-list.h"
|
2013-04-28 02:22:24 +00:00
|
|
|
#include "cogl-pango-pipeline-cache.h"
|
2011-07-07 19:44:56 +00:00
|
|
|
#include "cogl/cogl-context-private.h"
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
COGL_PANGO_DISPLAY_LIST_TEXTURE,
|
|
|
|
COGL_PANGO_DISPLAY_LIST_RECTANGLE,
|
|
|
|
COGL_PANGO_DISPLAY_LIST_TRAPEZOID
|
|
|
|
} CoglPangoDisplayListNodeType;
|
|
|
|
|
|
|
|
typedef struct _CoglPangoDisplayListNode CoglPangoDisplayListNode;
|
2011-08-10 17:13:14 +00:00
|
|
|
typedef struct _CoglPangoDisplayListRectangle CoglPangoDisplayListRectangle;
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
struct _CoglPangoDisplayList
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool color_override;
|
2010-02-26 12:38:22 +00:00
|
|
|
CoglColor color;
|
|
|
|
GSList *nodes;
|
|
|
|
GSList *last_node;
|
|
|
|
CoglPangoPipelineCache *pipeline_cache;
|
2009-07-29 16:21:07 +00:00
|
|
|
};
|
|
|
|
|
2011-08-10 17:13:14 +00:00
|
|
|
/* This matches the format expected by cogl_rectangles_with_texture_coords */
|
|
|
|
struct _CoglPangoDisplayListRectangle
|
|
|
|
{
|
|
|
|
float x_1, y_1, x_2, y_2;
|
|
|
|
float s_1, t_1, s_2, t_2;
|
|
|
|
};
|
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
struct _CoglPangoDisplayListNode
|
|
|
|
{
|
|
|
|
CoglPangoDisplayListNodeType type;
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool color_override;
|
2009-07-29 16:21:07 +00:00
|
|
|
CoglColor color;
|
|
|
|
|
2010-02-26 12:38:22 +00:00
|
|
|
CoglPipeline *pipeline;
|
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
/* The texture to render these coords from */
|
2011-08-24 20:30:34 +00:00
|
|
|
CoglTexture *texture;
|
2011-08-10 17:13:14 +00:00
|
|
|
/* Array of rectangles in the format expected by
|
|
|
|
cogl_rectangles_with_texture_coords */
|
|
|
|
GArray *rectangles;
|
2011-08-10 16:03:48 +00:00
|
|
|
/* A primitive representing those vertices */
|
|
|
|
CoglPrimitive *primitive;
|
2009-07-29 16:21:07 +00:00
|
|
|
} texture;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
float x_1, y_1;
|
|
|
|
float x_2, y_2;
|
|
|
|
} rectangle;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2013-04-28 02:22:24 +00:00
|
|
|
CoglPrimitive *primitive;
|
2009-07-29 16:21:07 +00:00
|
|
|
} trapezoid;
|
|
|
|
} d;
|
|
|
|
};
|
|
|
|
|
|
|
|
CoglPangoDisplayList *
|
2010-02-26 12:38:22 +00:00
|
|
|
_cogl_pango_display_list_new (CoglPangoPipelineCache *pipeline_cache)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
2010-02-26 12:38:22 +00:00
|
|
|
CoglPangoDisplayList *dl = g_slice_new0 (CoglPangoDisplayList);
|
|
|
|
|
|
|
|
dl->pipeline_cache = pipeline_cache;
|
|
|
|
|
|
|
|
return dl;
|
2009-07-29 16:21:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_pango_display_list_append_node (CoglPangoDisplayList *dl,
|
|
|
|
CoglPangoDisplayListNode *node)
|
|
|
|
{
|
|
|
|
if (dl->last_node)
|
|
|
|
dl->last_node = dl->last_node->next = g_slist_prepend (NULL, node);
|
|
|
|
else
|
|
|
|
dl->last_node = dl->nodes = g_slist_prepend (NULL, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pango_display_list_set_color_override (CoglPangoDisplayList *dl,
|
|
|
|
const CoglColor *color)
|
|
|
|
{
|
|
|
|
dl->color_override = TRUE;
|
|
|
|
dl->color = *color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pango_display_list_remove_color_override (CoglPangoDisplayList *dl)
|
|
|
|
{
|
|
|
|
dl->color_override = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
|
2011-08-24 20:30:34 +00:00
|
|
|
CoglTexture *texture,
|
2009-07-29 16:21:07 +00:00
|
|
|
float x_1, float y_1,
|
|
|
|
float x_2, float y_2,
|
|
|
|
float tx_1, float ty_1,
|
|
|
|
float tx_2, float ty_2)
|
|
|
|
{
|
|
|
|
CoglPangoDisplayListNode *node;
|
2011-08-10 17:13:14 +00:00
|
|
|
CoglPangoDisplayListRectangle *rectangle;
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
/* Add to the last node if it is a texture node with the same
|
|
|
|
target texture */
|
|
|
|
if (dl->last_node
|
|
|
|
&& (node = dl->last_node->data)->type == COGL_PANGO_DISPLAY_LIST_TEXTURE
|
|
|
|
&& node->d.texture.texture == texture
|
|
|
|
&& (dl->color_override
|
|
|
|
? (node->color_override && cogl_color_equal (&dl->color, &node->color))
|
|
|
|
: !node->color_override))
|
|
|
|
{
|
|
|
|
/* Get rid of the vertex buffer so that it will be recreated */
|
2011-08-10 16:03:48 +00:00
|
|
|
if (node->d.texture.primitive != NULL)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
2011-08-10 16:03:48 +00:00
|
|
|
cogl_object_unref (node->d.texture.primitive);
|
|
|
|
node->d.texture.primitive = NULL;
|
2009-07-29 16:21:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise create a new node */
|
|
|
|
node = g_slice_new (CoglPangoDisplayListNode);
|
|
|
|
|
|
|
|
node->type = COGL_PANGO_DISPLAY_LIST_TEXTURE;
|
|
|
|
node->color_override = dl->color_override;
|
|
|
|
node->color = dl->color;
|
2010-02-26 12:38:22 +00:00
|
|
|
node->pipeline = NULL;
|
2011-08-24 20:30:34 +00:00
|
|
|
node->d.texture.texture = cogl_object_ref (texture);
|
2011-08-10 17:13:14 +00:00
|
|
|
node->d.texture.rectangles
|
|
|
|
= g_array_new (FALSE, FALSE, sizeof (CoglPangoDisplayListRectangle));
|
2011-08-10 16:03:48 +00:00
|
|
|
node->d.texture.primitive = NULL;
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
_cogl_pango_display_list_append_node (dl, node);
|
|
|
|
}
|
|
|
|
|
2011-08-10 17:13:14 +00:00
|
|
|
g_array_set_size (node->d.texture.rectangles,
|
|
|
|
node->d.texture.rectangles->len + 1);
|
|
|
|
rectangle = &g_array_index (node->d.texture.rectangles,
|
|
|
|
CoglPangoDisplayListRectangle,
|
|
|
|
node->d.texture.rectangles->len - 1);
|
|
|
|
rectangle->x_1 = x_1;
|
|
|
|
rectangle->y_1 = y_1;
|
|
|
|
rectangle->x_2 = x_2;
|
|
|
|
rectangle->y_2 = y_2;
|
|
|
|
rectangle->s_1 = tx_1;
|
|
|
|
rectangle->t_1 = ty_1;
|
|
|
|
rectangle->s_2 = tx_2;
|
|
|
|
rectangle->t_2 = ty_2;
|
2009-07-29 16:21:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pango_display_list_add_rectangle (CoglPangoDisplayList *dl,
|
|
|
|
float x_1, float y_1,
|
|
|
|
float x_2, float y_2)
|
|
|
|
{
|
|
|
|
CoglPangoDisplayListNode *node = g_slice_new (CoglPangoDisplayListNode);
|
|
|
|
|
|
|
|
node->type = COGL_PANGO_DISPLAY_LIST_RECTANGLE;
|
|
|
|
node->color_override = dl->color_override;
|
|
|
|
node->color = dl->color;
|
|
|
|
node->d.rectangle.x_1 = x_1;
|
|
|
|
node->d.rectangle.y_1 = y_1;
|
|
|
|
node->d.rectangle.x_2 = x_2;
|
|
|
|
node->d.rectangle.y_2 = y_2;
|
2010-02-26 12:38:22 +00:00
|
|
|
node->pipeline = NULL;
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
_cogl_pango_display_list_append_node (dl, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pango_display_list_add_trapezoid (CoglPangoDisplayList *dl,
|
|
|
|
float y_1,
|
|
|
|
float x_11,
|
|
|
|
float x_21,
|
|
|
|
float y_2,
|
|
|
|
float x_12,
|
|
|
|
float x_22)
|
|
|
|
{
|
2013-04-28 02:22:24 +00:00
|
|
|
CoglContext *ctx = dl->pipeline_cache->ctx;
|
2009-07-29 16:21:07 +00:00
|
|
|
CoglPangoDisplayListNode *node = g_slice_new (CoglPangoDisplayListNode);
|
2013-04-28 02:22:24 +00:00
|
|
|
CoglVertexP2 vertices[4] = {
|
|
|
|
{ x_11, y_1 },
|
|
|
|
{ x_12, y_2 },
|
|
|
|
{ x_22, y_2 },
|
|
|
|
{ x_21, y_1 }
|
|
|
|
};
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
node->type = COGL_PANGO_DISPLAY_LIST_TRAPEZOID;
|
|
|
|
node->color_override = dl->color_override;
|
|
|
|
node->color = dl->color;
|
2010-02-26 12:38:22 +00:00
|
|
|
node->pipeline = NULL;
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2013-04-28 02:22:24 +00:00
|
|
|
node->d.trapezoid.primitive =
|
|
|
|
cogl_primitive_new_p2 (ctx,
|
|
|
|
COGL_VERTICES_MODE_TRIANGLE_FAN,
|
|
|
|
4,
|
|
|
|
vertices);
|
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
_cogl_pango_display_list_append_node (dl, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-10 11:16:03 +00:00
|
|
|
emit_rectangles_through_journal (CoglFramebuffer *fb,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglPangoDisplayListNode *node)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
2012-05-10 11:16:03 +00:00
|
|
|
const float *rectangles = (const float *)node->d.texture.rectangles->data;
|
|
|
|
|
|
|
|
cogl_framebuffer_draw_textured_rectangles (fb,
|
|
|
|
pipeline,
|
|
|
|
rectangles,
|
|
|
|
node->d.texture.rectangles->len);
|
2010-10-27 11:36:24 +00:00
|
|
|
}
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2010-10-27 11:36:24 +00:00
|
|
|
static void
|
2012-05-10 11:16:03 +00:00
|
|
|
emit_vertex_buffer_geometry (CoglFramebuffer *fb,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglPangoDisplayListNode *node)
|
2010-10-27 11:36:24 +00:00
|
|
|
{
|
2012-05-10 11:16:03 +00:00
|
|
|
CoglContext *ctx = fb->context;
|
2011-07-07 19:44:56 +00:00
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
/* It's expensive to go through the Cogl journal for large runs
|
|
|
|
* of text in part because the journal transforms the quads in software
|
|
|
|
* to avoid changing the modelview matrix. So for larger runs of text
|
|
|
|
* we load the vertices into a VBO, and this has the added advantage
|
|
|
|
* that if the text doesn't change from frame to frame the VBO can
|
|
|
|
* be re-used avoiding the repeated cost of validating the data and
|
|
|
|
* mapping it into the GPU... */
|
|
|
|
|
2011-08-10 16:03:48 +00:00
|
|
|
if (node->d.texture.primitive == NULL)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
2011-08-10 16:03:48 +00:00
|
|
|
CoglAttributeBuffer *buffer;
|
2011-08-10 17:13:14 +00:00
|
|
|
CoglVertexP2T2 *verts, *v;
|
|
|
|
int n_verts;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool allocated = FALSE;
|
2011-08-10 16:03:48 +00:00
|
|
|
CoglAttribute *attributes[2];
|
|
|
|
CoglPrimitive *prim;
|
2011-08-10 17:13:14 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
n_verts = node->d.texture.rectangles->len * 4;
|
2011-08-10 16:03:48 +00:00
|
|
|
|
|
|
|
buffer
|
2012-11-08 17:54:10 +00:00
|
|
|
= cogl_attribute_buffer_new_with_size (ctx,
|
|
|
|
n_verts *
|
|
|
|
sizeof (CoglVertexP2T2));
|
2011-08-10 17:13:14 +00:00
|
|
|
|
|
|
|
if ((verts = cogl_buffer_map (COGL_BUFFER (buffer),
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD)) == NULL)
|
|
|
|
{
|
|
|
|
verts = g_new (CoglVertexP2T2, n_verts);
|
|
|
|
allocated = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = verts;
|
|
|
|
|
|
|
|
/* Copy the rectangles into the buffer and expand into four
|
|
|
|
vertices instead of just two */
|
|
|
|
for (i = 0; i < node->d.texture.rectangles->len; i++)
|
|
|
|
{
|
|
|
|
const CoglPangoDisplayListRectangle *rectangle
|
|
|
|
= &g_array_index (node->d.texture.rectangles,
|
|
|
|
CoglPangoDisplayListRectangle, i);
|
|
|
|
|
|
|
|
v->x = rectangle->x_1;
|
|
|
|
v->y = rectangle->y_1;
|
|
|
|
v->s = rectangle->s_1;
|
|
|
|
v->t = rectangle->t_1;
|
|
|
|
v++;
|
|
|
|
v->x = rectangle->x_1;
|
|
|
|
v->y = rectangle->y_2;
|
|
|
|
v->s = rectangle->s_1;
|
|
|
|
v->t = rectangle->t_2;
|
|
|
|
v++;
|
|
|
|
v->x = rectangle->x_2;
|
|
|
|
v->y = rectangle->y_2;
|
|
|
|
v->s = rectangle->s_2;
|
|
|
|
v->t = rectangle->t_2;
|
|
|
|
v++;
|
|
|
|
v->x = rectangle->x_2;
|
|
|
|
v->y = rectangle->y_1;
|
|
|
|
v->s = rectangle->s_2;
|
|
|
|
v->t = rectangle->t_1;
|
|
|
|
v++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allocated)
|
|
|
|
{
|
|
|
|
cogl_buffer_set_data (COGL_BUFFER (buffer),
|
|
|
|
0, /* offset */
|
|
|
|
verts,
|
|
|
|
sizeof (CoglVertexP2T2) * n_verts);
|
|
|
|
g_free (verts);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cogl_buffer_unmap (COGL_BUFFER (buffer));
|
|
|
|
|
2011-08-10 16:03:48 +00:00
|
|
|
attributes[0] = cogl_attribute_new (buffer,
|
|
|
|
"cogl_position_in",
|
|
|
|
sizeof (CoglVertexP2T2),
|
|
|
|
G_STRUCT_OFFSET (CoglVertexP2T2, x),
|
|
|
|
2, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
|
|
|
attributes[1] = cogl_attribute_new (buffer,
|
|
|
|
"cogl_tex_coord0_in",
|
|
|
|
sizeof (CoglVertexP2T2),
|
|
|
|
G_STRUCT_OFFSET (CoglVertexP2T2, s),
|
|
|
|
2, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
|
|
|
|
|
|
|
prim = cogl_primitive_new_with_attributes (COGL_VERTICES_MODE_TRIANGLES,
|
2011-08-10 17:13:14 +00:00
|
|
|
n_verts,
|
2011-08-10 16:03:48 +00:00
|
|
|
attributes,
|
|
|
|
2 /* n_attributes */);
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
#ifdef CLUTTER_COGL_HAS_GL
|
2013-11-25 16:11:36 +00:00
|
|
|
if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_QUADS))
|
2011-08-10 16:03:48 +00:00
|
|
|
cogl_primitive_set_mode (prim, GL_QUADS);
|
|
|
|
else
|
2011-07-07 19:44:56 +00:00
|
|
|
#endif
|
2011-08-10 16:03:48 +00:00
|
|
|
{
|
|
|
|
/* GLES doesn't support GL_QUADS so instead we use a VBO
|
|
|
|
with indexed vertices to generate GL_TRIANGLES from the
|
|
|
|
quads */
|
|
|
|
|
|
|
|
CoglIndices *indices =
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_get_rectangle_indices (ctx, node->d.texture.rectangles->len);
|
2011-08-10 16:03:48 +00:00
|
|
|
|
2011-10-25 21:34:59 +00:00
|
|
|
cogl_primitive_set_indices (prim, indices,
|
|
|
|
node->d.texture.rectangles->len * 6);
|
2011-08-10 16:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
node->d.texture.primitive = prim;
|
|
|
|
|
|
|
|
cogl_object_unref (buffer);
|
|
|
|
cogl_object_unref (attributes[0]);
|
|
|
|
cogl_object_unref (attributes[1]);
|
2011-07-07 19:44:56 +00:00
|
|
|
}
|
2011-08-10 16:03:48 +00:00
|
|
|
|
2013-07-09 22:47:29 +00:00
|
|
|
cogl_primitive_draw (node->d.texture.primitive,
|
|
|
|
fb,
|
|
|
|
pipeline);
|
2009-07-29 16:21:07 +00:00
|
|
|
}
|
|
|
|
|
2010-10-27 11:36:24 +00:00
|
|
|
static void
|
2012-05-10 11:16:03 +00:00
|
|
|
_cogl_framebuffer_draw_display_list_texture (CoglFramebuffer *fb,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglPangoDisplayListNode *node)
|
2010-10-27 11:36:24 +00:00
|
|
|
{
|
|
|
|
/* For small runs of text like icon labels, we can get better performance
|
|
|
|
* going through the Cogl journal since text may then be batched together
|
|
|
|
* with other geometry. */
|
2011-08-10 17:13:14 +00:00
|
|
|
/* FIXME: 25 is a number I plucked out of thin air; it would be good
|
2010-10-27 11:36:24 +00:00
|
|
|
* to determine this empirically! */
|
2011-08-10 17:13:14 +00:00
|
|
|
if (node->d.texture.rectangles->len < 25)
|
2012-05-10 11:16:03 +00:00
|
|
|
emit_rectangles_through_journal (fb, pipeline, node);
|
2010-10-27 11:36:24 +00:00
|
|
|
else
|
2012-05-10 11:16:03 +00:00
|
|
|
emit_vertex_buffer_geometry (fb, pipeline, node);
|
2010-10-27 11:36:24 +00:00
|
|
|
}
|
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
void
|
2012-05-10 11:16:03 +00:00
|
|
|
_cogl_pango_display_list_render (CoglFramebuffer *fb,
|
|
|
|
CoglPangoDisplayList *dl,
|
2010-02-26 12:38:22 +00:00
|
|
|
const CoglColor *color)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = dl->nodes; l; l = l->next)
|
|
|
|
{
|
|
|
|
CoglPangoDisplayListNode *node = l->data;
|
|
|
|
CoglColor draw_color;
|
|
|
|
|
2010-02-26 12:38:22 +00:00
|
|
|
if (node->pipeline == NULL)
|
|
|
|
{
|
|
|
|
if (node->type == COGL_PANGO_DISPLAY_LIST_TEXTURE)
|
|
|
|
node->pipeline =
|
|
|
|
_cogl_pango_pipeline_cache_get (dl->pipeline_cache,
|
|
|
|
node->d.texture.texture);
|
|
|
|
else
|
|
|
|
node->pipeline =
|
|
|
|
_cogl_pango_pipeline_cache_get (dl->pipeline_cache,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
if (node->color_override)
|
|
|
|
/* Use the override color but preserve the alpha from the
|
|
|
|
draw color */
|
2010-09-03 15:55:12 +00:00
|
|
|
cogl_color_init_from_4ub (&draw_color,
|
|
|
|
cogl_color_get_red_byte (&node->color),
|
|
|
|
cogl_color_get_green_byte (&node->color),
|
|
|
|
cogl_color_get_blue_byte (&node->color),
|
|
|
|
cogl_color_get_alpha_byte (color));
|
2009-07-29 16:21:07 +00:00
|
|
|
else
|
|
|
|
draw_color = *color;
|
|
|
|
cogl_color_premultiply (&draw_color);
|
|
|
|
|
2010-02-26 12:38:22 +00:00
|
|
|
cogl_pipeline_set_color (node->pipeline, &draw_color);
|
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
switch (node->type)
|
|
|
|
{
|
|
|
|
case COGL_PANGO_DISPLAY_LIST_TEXTURE:
|
2012-05-10 11:16:03 +00:00
|
|
|
_cogl_framebuffer_draw_display_list_texture (fb, node->pipeline, node);
|
2009-07-29 16:21:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_PANGO_DISPLAY_LIST_RECTANGLE:
|
2012-05-10 11:16:03 +00:00
|
|
|
cogl_framebuffer_draw_rectangle (fb,
|
|
|
|
node->pipeline,
|
|
|
|
node->d.rectangle.x_1,
|
|
|
|
node->d.rectangle.y_1,
|
|
|
|
node->d.rectangle.x_2,
|
|
|
|
node->d.rectangle.y_2);
|
2009-07-29 16:21:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_PANGO_DISPLAY_LIST_TRAPEZOID:
|
2013-04-28 02:22:24 +00:00
|
|
|
cogl_framebuffer_draw_primitive (fb, node->pipeline,
|
|
|
|
node->d.trapezoid.primitive);
|
2009-07-29 16:21:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_pango_display_list_node_free (CoglPangoDisplayListNode *node)
|
|
|
|
{
|
|
|
|
if (node->type == COGL_PANGO_DISPLAY_LIST_TEXTURE)
|
|
|
|
{
|
2011-08-10 17:13:14 +00:00
|
|
|
g_array_free (node->d.texture.rectangles, TRUE);
|
2011-08-24 20:30:34 +00:00
|
|
|
if (node->d.texture.texture != NULL)
|
|
|
|
cogl_object_unref (node->d.texture.texture);
|
2011-08-10 16:03:48 +00:00
|
|
|
if (node->d.texture.primitive != NULL)
|
|
|
|
cogl_object_unref (node->d.texture.primitive);
|
2009-07-29 16:21:07 +00:00
|
|
|
}
|
2013-04-28 02:22:24 +00:00
|
|
|
else if (node->type == COGL_PANGO_DISPLAY_LIST_TRAPEZOID)
|
|
|
|
cogl_object_unref (node->d.trapezoid.primitive);
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2010-02-26 12:38:22 +00:00
|
|
|
if (node->pipeline)
|
|
|
|
cogl_object_unref (node->pipeline);
|
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
g_slice_free (CoglPangoDisplayListNode, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pango_display_list_clear (CoglPangoDisplayList *dl)
|
|
|
|
{
|
|
|
|
g_slist_foreach (dl->nodes, (GFunc) _cogl_pango_display_list_node_free, NULL);
|
|
|
|
g_slist_free (dl->nodes);
|
|
|
|
dl->nodes = NULL;
|
|
|
|
dl->last_node = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pango_display_list_free (CoglPangoDisplayList *dl)
|
|
|
|
{
|
|
|
|
_cogl_pango_display_list_clear (dl);
|
|
|
|
g_slice_free (CoglPangoDisplayList, dl);
|
|
|
|
}
|