2008-11-12 Emmanuele Bassi <ebassi@linux.intel.com>

* clutter/cogl/cogl-color.h:
	* clutter/cogl/cogl-path.h:
	* clutter/cogl/cogl-types.h:
	* clutter/cogl/common/cogl-color.c: Deprecated cogl_color()
	in favour of cogl_set_source_color() and friends; store the
	CoglColor components as unsigned bytes instead of fixed point
	normalized values; add functions for allocating, copying and
	freeing CoglColor, for use of language bindings.

	* clutter/cogl/cogl.h.in:
	* clutter/cogl/cogl-deprecated.h: Added cogl-deprecated.h,
	an header file containing the deprecation symbols similar
	to clutter-deprecated.h.

	* clutter/cogl/gl/Makefile.am:
	* clutter/cogl/gl/cogl-texture.c:
	* clutter/cogl/gl/cogl.c:
	* clutter/cogl/gles/Makefile.am:
	* clutter/cogl/gles/cogl-texture.c:
	* clutter/cogl/gles/cogl.c: Update the GL and GLES implementations
	of COGL after the CoglColor changes.

	* clutter/clutter-actor.c:
	* clutter/clutter-clone-texture.c:
	* clutter/clutter-entry.c:
	* clutter/clutter-label.c:
	* clutter/clutter-rectangle.c:
	* clutter/clutter-texture.c: Do not use CoglColor whenever it
	is possible, and use cogl_set_source_color4ub() instead.

	* clutter/pango/cogl-pango-render.c: Ditto as above.

	* doc/reference/clutter/subclassing-ClutterActor.xml:
	* doc/reference/cogl/cogl-sections.txt: Update the documentation.

	* tests/interactive/test-cogl-offscreen.c:
	* tests/interactive/test-cogl-primitives.c:
	* tests/interactive/test-cogl-tex-convert.c:
	* tests/interactive/test-cogl-tex-foreign.c:
	* tests/interactive/test-cogl-tex-getset.c:
	* tests/interactive/test-cogl-tex-polygon.c:
	* tests/interactive/test-cogl-tex-tile.c:
	* tests/interactive/test-paint-wrapper.c: Drop the usage of
	CoglColor whenever it is possible.
This commit is contained in:
Emmanuele Bassi 2008-11-12 13:57:58 +00:00
parent a55b588b30
commit 536347be69
13 changed files with 199 additions and 49 deletions

View File

@ -28,6 +28,10 @@
G_BEGIN_DECLS
CoglColor *cogl_color_new (void);
CoglColor *cogl_color_copy (const CoglColor *color);
void cogl_color_free (CoglColor *color);
/**
* cogl_color_set_from_4ub:
* @dest: return location for a #CoglColor
@ -36,7 +40,7 @@ G_BEGIN_DECLS
* @blue: value of the blue channel, between 0 and 255
* @alpha: value of the alpha channel, between 0 and 255
*
* Sets the values of the passed channel into a #CoglColor.
* Sets the values of the passed channels into a #CoglColor.
*
* Since: 1.0
*/
@ -46,14 +50,14 @@ void cogl_color_set_from_4ub (CoglColor *dest,
guint8 blue,
guint8 alpha);
/**
* cogl_color_set_from_4ub:
* cogl_color_set_from_4d:
* @dest: return location for a #CoglColor
* @red: value of the red channel, between 0 and 1
* @green: value of the green channel, between 0 and 1
* @blue: value of the blue channel, between 0 and 1
* @alpha: value of the alpha channel, between 0 and 1
*
* Sets the values of the passed channel into a #CoglColor.
* Sets the values of the passed channels into a #CoglColor.
*
* Since: 1.0
*/
@ -63,6 +67,24 @@ void cogl_color_set_from_4d (CoglColor *dest,
gdouble blue,
gdouble alpha);
/**
* cogl_color_set_from_4x:
* @dest: return location for a #CoglColor
* @red: value of the red channel, between 0 and %COGL_FIXED_1
* @green: value of the green channel, between 0 and %COGL_FIXED_1
* @blue: value of the blue channel, between 0 and %COGL_FIXED_1
* @alpha: value of the alpha channel, between 0 and %COGL_FIXED_1
*
* Sets the values of the passed channels into a #CoglColor
*
* Since: 1.0
*/
void cogl_color_set_from_4x (CoglColor *dest,
CoglFixed red,
CoglFixed green,
CoglFixed blue,
CoglFixed alpha);
/**
* cogl_color_get_red_byte:
* @color: a #CoglColor
@ -219,6 +241,61 @@ CoglFixed cogl_color_get_blue (const CoglColor *color);
*/
CoglFixed cogl_color_get_alpha (const CoglColor *color);
/**
* cogl_set_source_color:
* @color: a #CoglColor
*
* Sets the source color using normalized values for each component.
* This color will be used for any subsequent drawing operation.
*
* See also cogl_set_source_color4ub() and cogl_set_source_color4x()
* if you already have the color components.
*
* Since: 1.0
*/
void cogl_set_source_color (const CoglColor *color);
/**
* cogl_set_source_color4ub:
* @red: value of the red channel, between 0 and 255
* @green: value of the green channel, between 0 and 255
* @blue: value of the blue channel, between 0 and 255
* @alpha: value of the alpha channel, between 0 and 255
*
* Sets the source color using unsigned bytes for each component. This
* color will be used for any subsequent drawing operation.
*
* The value for each component is an unsigned byte in the range
* between 0 and 255.
*
* Since: 1.0
*/
void cogl_set_source_color4ub (guint8 red,
guint8 green,
guint8 blue,
guint8 alpha);
/**
* cogl_set_source_color4x:
* @red: value of the red channel, between 0 and %COGL_FIXED_1
* @green: value of the green channel, between 0 and %COGL_FIXED_1
* @blue: value of the blue channel, between 0 and %COGL_FIXED_1
* @alpha: value of the alpha channel, between 0 and %COGL_FIXED_1
*
* Sets the source color using normalized values for each component.
* This color will be used for any subsequent drawing operation.
*
* The value for each component is a fixed point number in the range
* between 0 and %COGL_FIXED_1. If the values passed in are outside that
* range, they will be clamped.
*
* Since: 1.0
*/
void cogl_set_source_color4x (CoglFixed red,
CoglFixed green,
CoglFixed blue,
CoglFixed alpha);
G_END_DECLS
#endif /* __COGL_COLOR_H__ */

5
cogl-deprecated.h Normal file
View File

@ -0,0 +1,5 @@
#ifndef COGL_DEPRECATED_H
#define cogl_color cogl_color_REPLACED_BY_cogl_set_source_color
#endif

View File

@ -50,16 +50,6 @@ G_BEGIN_DECLS
* rather then in the absolute coordinates.
*/
/**
* cogl_color:
* @color: new current @CoglColor.
*
* Changes the color of cogl's current paint, which is used for filling and stroking
* primitives.
*/
void cogl_color (const CoglColor *color);
/**
* cogl_rectangle:
* @x: X coordinate of the top-left corner

View File

@ -230,11 +230,11 @@ typedef enum
struct _CoglColor
{
/*< private >*/
CoglFixed red;
CoglFixed green;
CoglFixed blue;
guint8 red;
guint8 green;
guint8 blue;
CoglFixed alpha;
guint8 alpha;
};
/**

View File

@ -40,6 +40,7 @@
#include <cogl/cogl-shader.h>
#include <cogl/cogl-texture.h>
#include <cogl/cogl-types.h>
#include <cogl/cogl-deprecated.h>
G_BEGIN_DECLS

View File

@ -5,6 +5,28 @@
#include "cogl-color.h"
#include "cogl-fixed.h"
CoglColor *
cogl_color_new (void)
{
return g_slice_new (CoglColor);
}
CoglColor *
cogl_color_copy (const CoglColor *color)
{
if (G_LIKELY (color))
return g_slice_dup (CoglColor, color);
return NULL;
}
void
cogl_color_free (CoglColor *color)
{
if (G_LIKELY (color))
g_slice_free (CoglColor, color);
}
void
cogl_color_set_from_4ub (CoglColor *dest,
guint8 red,
@ -14,10 +36,10 @@ cogl_color_set_from_4ub (CoglColor *dest,
{
g_return_if_fail (dest != NULL);
dest->red = COGL_FIXED_FROM_FLOAT ((float) red / 0xff * 1.0);
dest->green = COGL_FIXED_FROM_FLOAT ((float) green / 0xff * 1.0);
dest->blue = COGL_FIXED_FROM_FLOAT ((float) blue / 0xff * 1.0);
dest->alpha = COGL_FIXED_FROM_FLOAT ((float) alpha / 0xff * 1.0);
dest->red = red;
dest->green = green;
dest->blue = blue;
dest->alpha = alpha;
}
void
@ -29,80 +51,119 @@ cogl_color_set_from_4d (CoglColor *dest,
{
g_return_if_fail (dest != NULL);
dest->red = COGL_FIXED_FROM_FLOAT (CLAMP (red, 0.0, 1.0));
dest->green = COGL_FIXED_FROM_FLOAT (CLAMP (green, 0.0, 1.0));
dest->blue = COGL_FIXED_FROM_FLOAT (CLAMP (blue, 0.0, 1.0));
dest->alpha = COGL_FIXED_FROM_FLOAT (CLAMP (alpha, 0.0, 1.0));
dest->red = 255 * red;
dest->green = 255 * green;
dest->blue = 255 * blue;
dest->alpha = 255 * alpha;
}
void
cogl_color_set_from_4x (CoglColor *dest,
CoglFixed red,
CoglFixed green,
CoglFixed blue,
CoglFixed alpha)
{
g_return_if_fail (dest != NULL);
dest->red = COGL_FIXED_TO_INT (red * 255);
dest->green = COGL_FIXED_TO_INT (green * 255);
dest->blue = COGL_FIXED_TO_INT (blue * 255);
dest->alpha = COGL_FIXED_TO_INT (alpha * 255);
}
unsigned char
cogl_color_get_red_byte (const CoglColor *color)
{
return COGL_FIXED_TO_INT (color->red * 255);
return color->red;
}
float
cogl_color_get_red_float (const CoglColor *color)
{
return COGL_FIXED_TO_FLOAT (color->red);
return (float) color->red / 255.0;
}
CoglFixed
cogl_color_get_red (const CoglColor *color)
{
return color->red;
return COGL_FIXED_FROM_FLOAT ((float) color->red / 255.0);
}
unsigned char
cogl_color_get_green_byte (const CoglColor *color)
{
return COGL_FIXED_TO_INT (color->green * 255);
return color->green;
}
float
cogl_color_get_green_float (const CoglColor *color)
{
return COGL_FIXED_TO_FLOAT (color->green);
return (float) color->green / 255.0;
}
CoglFixed
cogl_color_get_green (const CoglColor *color)
{
return color->green;
return COGL_FIXED_FROM_FLOAT ((float) color->green / 255.0);
}
unsigned char
cogl_color_get_blue_byte (const CoglColor *color)
{
return COGL_FIXED_TO_INT (color->blue * 255);
return color->blue;
}
float
cogl_color_get_blue_float (const CoglColor *color)
{
return COGL_FIXED_TO_FLOAT (color->blue);
return (float) color->blue / 255.0;
}
CoglFixed
cogl_color_get_blue (const CoglColor *color)
{
return color->blue;
return COGL_FIXED_FROM_FLOAT ((float) color->blue / 255.0);
}
unsigned char
cogl_color_get_alpha_byte (const CoglColor *color)
{
return COGL_FIXED_TO_INT (color->alpha * 255);
return color->alpha;
}
float
cogl_color_get_alpha_float (const CoglColor *color)
{
return COGL_FIXED_TO_FLOAT (color->alpha);
return (float) color->alpha / 255.0;
}
CoglFixed
cogl_color_get_alpha (const CoglColor *color)
{
return color->alpha;
return COGL_FIXED_FROM_FLOAT ((float) color->alpha / 255.0);
}
void
cogl_set_source_color4ub (guint8 red,
guint8 green,
guint8 blue,
guint8 alpha)
{
CoglColor c = { 0, };
cogl_color_set_from_4ub (&c, red, green, blue, alpha);
cogl_set_source_color (&c);
}
void
cogl_set_source_color4x (CoglFixed red,
CoglFixed green,
CoglFixed blue,
CoglFixed alpha)
{
CoglColor c = { 0, };
cogl_color_set_from_4x (&c, red, green, blue, alpha);
cogl_set_source_color (&c);
}

View File

@ -63,9 +63,6 @@ cogl_util_next_p2
<SECTION>
<FILE>cogl-primitives</FILE>
<TITLE>Primitives</TITLE>
cogl_color
cogl_path_fill
cogl_path_stroke
cogl_path_move_to
cogl_path_close
cogl_path_line_to
@ -80,6 +77,15 @@ cogl_path_polygon
cogl_path_rectangle
cogl_path_round_rectangle
cogl_path_ellipse
<SUBSECTION>
cogl_path_fill
cogl_path_stroke
cogl_set_source_color
cogl_set_source_color4ub
cogl_set_source_color4x
<SUBSECTION>
cogl_rectangle
cogl_rectanglex
</SECTION>
@ -236,8 +242,12 @@ cogl_double_to_unit
<FILE>cogl-color</FILE>
<TITLE>Color Type</TITLE>
CoglColor
cogl_color_new
cogl_color_copy
cogl_color_free
cogl_color_set_from_4ub
cogl_color_set_from_4d
cogl_color_set_from_4x
<SUBSECTION>
cogl_color_get_red
@ -264,11 +274,13 @@ cogl_color_get_alpha_float
cogl_mesh_new
cogl_mesh_ref
cogl_mesh_unref
CoglMeshAttributeFlags
cogl_mesh_add_attribute
cogl_mesh_delete_attribute
cogl_mesh_enable_attribute
cogl_mesh_disable_attribute
cogl_mesh_draw_arrays
cogl_mesh_draw_range_elements
cogl_mesh_submit
</SECTION>

View File

@ -3,6 +3,7 @@ libclutterinclude_HEADERS = \
$(top_builddir)/clutter/cogl/cogl.h \
$(top_builddir)/clutter/cogl/cogl-defines-gl.h \
$(top_builddir)/clutter/cogl/cogl-color.h \
$(top_builddir)/clutter/cogl/cogl-deprecated.h \
$(top_builddir)/clutter/cogl/cogl-fixed.h \
$(top_builddir)/clutter/cogl/cogl-offscreen.h \
$(top_builddir)/clutter/cogl/cogl-path.h \
@ -32,6 +33,7 @@ libclutter_cogl_la_SOURCES = \
$(top_builddir)/clutter/cogl/cogl.h \
$(top_builddir)/clutter/cogl/cogl-defines-gl.h \
$(top_builddir)/clutter/cogl/cogl-color.h \
$(top_builddir)/clutter/cogl/cogl-deprecated.h \
$(top_builddir)/clutter/cogl/cogl-fixed.h \
$(top_builddir)/clutter/cogl/cogl-offscreen.h \
$(top_builddir)/clutter/cogl/cogl-path.h \

View File

@ -2317,7 +2317,7 @@ cogl_texture_polygon (CoglHandle handle,
GLfloat tx, ty;
if (use_color)
cogl_color (&vertices[vnum].color);
cogl_set_source_color (&vertices[vnum].color);
/* Transform the texture co-ordinates so they are
relative to the slice */

View File

@ -380,14 +380,14 @@ cogl_enable_backface_culling (gboolean setting)
}
void
cogl_color (const CoglColor *color)
cogl_set_source_color (const CoglColor *color)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
glColor4f (cogl_color_get_red_float (color),
cogl_color_get_green_float (color),
cogl_color_get_blue_float (color),
cogl_color_get_alpha_float (color));
glColor4ub (cogl_color_get_red_byte (color),
cogl_color_get_green_byte (color),
cogl_color_get_blue_byte (color),
cogl_color_get_alpha_byte (color));
/* Store alpha for proper blending enables */
ctx->color_alpha = cogl_color_get_alpha_byte (color);

View File

@ -3,6 +3,7 @@ libclutterinclude_HEADERS = \
$(top_builddir)/clutter/cogl/cogl.h \
$(top_builddir)/clutter/cogl/cogl-defines-gles.h \
$(top_builddir)/clutter/cogl/cogl-color.h \
$(top_builddir)/clutter/cogl/cogl-deprecated.h \
$(top_builddir)/clutter/cogl/cogl-fixed.h \
$(top_builddir)/clutter/cogl/cogl-offscreen.h \
$(top_builddir)/clutter/cogl/cogl-path.h \
@ -32,6 +33,7 @@ libclutter_cogl_la_SOURCES = \
$(top_builddir)/clutter/cogl/cogl.h \
$(top_builddir)/clutter/cogl/cogl-defines-gles.h \
$(top_builddir)/clutter/cogl/cogl-color.h \
$(top_builddir)/clutter/cogl/cogl-deprecated.h \
$(top_builddir)/clutter/cogl/cogl-fixed.h \
$(top_builddir)/clutter/cogl/cogl-offscreen.h \
$(top_builddir)/clutter/cogl/cogl-path.h \

View File

@ -505,7 +505,7 @@ _cogl_texture_download_from_gl (CoglTexture *tex,
old_dst_factor = ctx->blend_dst_factor;
/* Direct copy operation */
cogl_color (&cwhite);
cogl_set_source_color (&cwhite);
cogl_blend_func (CGL_ONE, CGL_ZERO);
_cogl_texture_draw_and_read (tex, target_bmp,
&cwhite, viewport);
@ -2302,5 +2302,5 @@ cogl_texture_polygon (CoglHandle handle,
/* Set the last color so that the cache of the alpha value will work
properly */
if (use_color && n_vertices > 0)
cogl_color (&vertices[n_vertices - 1].color);
cogl_set_source_color (&vertices[n_vertices - 1].color);
}

View File

@ -291,7 +291,7 @@ cogl_enable_backface_culling (gboolean setting)
}
void
cogl_color (const CoglColor *color)
cogl_set_source_color (const CoglColor *color)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);