cogl: Remove Color.init_from_4ub

Slowly switching to using floats only in CoglColor
Helps https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3544

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3594>
This commit is contained in:
Bilal Elmoussaoui 2024-02-16 23:44:34 +01:00 committed by Marge Bot
parent cf0803ab71
commit 60e10511ae
23 changed files with 95 additions and 118 deletions

View File

@ -3056,11 +3056,11 @@ _clutter_actor_draw_paint_volume_full (ClutterActor *self,
n_vertices,
(CoglVertexP3 *)line_ends);
cogl_color_init_from_4ub (&cogl_color,
color->red,
color->green,
color->blue,
color->alpha);
cogl_color_init_from_4f (&cogl_color,
color->red / 255.0,
color->green / 255.0,
color->blue / 255.0,
color->alpha / 255.0);
cogl_pipeline_set_color (outline, &cogl_color);
pipeline_node = clutter_pipeline_node_new (outline);

View File

@ -313,7 +313,7 @@ apply_blur_pass (BlurPass *pass)
{
CoglColor transparent;
cogl_color_init_from_4ub (&transparent, 0, 0, 0, 0);
cogl_color_init_from_4f (&transparent, 0.0, 0.0, 0.0, 0.0);
cogl_framebuffer_clear (pass->framebuffer,
COGL_BUFFER_BIT_COLOR,

View File

@ -238,7 +238,7 @@ clutter_deform_effect_paint_target (ClutterOffscreenEffect *effect,
vertex.y = height * vertex.ty;
vertex.z = 0.0f;
cogl_color_init_from_4ub (&vertex.color, 255, 255, 255, opacity);
cogl_color_init_from_4f (&vertex.color, 1.0, 1.0, 1.0, opacity / 255.0);
clutter_deform_effect_deform_vertex (self,
width, height,

View File

@ -77,7 +77,7 @@ clutter_page_turn_effect_deform_vertex (ClutterDeformEffect *effect,
{
ClutterPageTurnEffect *self = CLUTTER_PAGE_TURN_EFFECT (effect);
gfloat cx, cy, rx, ry, radians, turn_angle;
guint shade;
float shade;
if (self->period == 0.0)
return;
@ -103,12 +103,12 @@ clutter_page_turn_effect_deform_vertex (ClutterDeformEffect *effect,
* ray (i.e. the page crease)
*/
turn_angle = (rx / self->radius * G_PI_2) - G_PI_2;
shade = (sin (turn_angle) * 96.0f) + 159.0f;
shade = ((sin (turn_angle) * 96.0f) + 159.0f) / 255.0;
/* Add a gradient that makes it look like lighting and hides the switch
* between textures.
*/
cogl_color_init_from_4ub (&vertex->color, shade, shade, shade, 0xff);
cogl_color_init_from_4f (&vertex->color, shade, shade, shade, 1.0);
}
if (rx > 0)

View File

@ -161,11 +161,11 @@ clutter_root_node_new (CoglFramebuffer *framebuffer,
res = _clutter_paint_node_create (CLUTTER_TYPE_ROOT_NODE);
cogl_color_init_from_4ub (&res->clear_color,
clear_color->red,
clear_color->green,
clear_color->blue,
clear_color->alpha);
cogl_color_init_from_4f (&res->clear_color,
clear_color->red / 255.0,
clear_color->green / 255.0,
clear_color->blue / 255.0,
clear_color->alpha / 255.0);
cogl_color_premultiply (&res->clear_color);
res->framebuffer = g_object_ref (framebuffer);
@ -565,11 +565,11 @@ clutter_color_node_new (const ClutterColor *color)
{
CoglColor cogl_color;
cogl_color_init_from_4ub (&cogl_color,
color->red,
color->green,
color->blue,
color->alpha);
cogl_color_init_from_4f (&cogl_color,
color->red / 255.0,
color->green / 255.0,
color->blue / 255.0,
color->alpha / 255.0);
cogl_color_premultiply (&cogl_color);
cogl_pipeline_set_color (cnode->pipeline, &cogl_color);
@ -674,15 +674,15 @@ clutter_texture_node_new (CoglTexture *texture,
if (color != NULL)
{
cogl_color_init_from_4ub (&cogl_color,
color->red,
color->green,
color->blue,
color->alpha);
cogl_color_init_from_4f (&cogl_color,
color->red / 255.0,
color->green / 255.0,
color->blue / 255.0,
color->alpha / 255.0);
cogl_color_premultiply (&cogl_color);
}
else
cogl_color_init_from_4ub (&cogl_color, 255, 255, 255, 255);
cogl_color_init_from_4f (&cogl_color, 1.0, 1.0, 1.0, 1.0);
cogl_pipeline_set_color (tnode->pipeline, &cogl_color);
@ -843,11 +843,11 @@ clutter_text_node_new (PangoLayout *layout,
if (color != NULL)
{
cogl_color_init_from_4ub (&res->color,
color->red,
color->green,
color->blue,
color->alpha);
cogl_color_init_from_4f (&res->color,
color->red / 255.0,
color->green / 255.0,
color->blue / 255.0,
color->alpha / 255.0);
}
return (ClutterPaintNode *) res;

View File

@ -2702,7 +2702,7 @@ clutter_stage_paint_to_framebuffer (ClutterStage *stage,
{
CoglColor clear_color;
cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 0);
cogl_color_init_from_4f (&clear_color, 0.0, 0.0, 0.0, 0.0);
cogl_framebuffer_clear (framebuffer, COGL_BUFFER_BIT_COLOR, &clear_color);
}

View File

@ -1925,11 +1925,11 @@ paint_selection_rectangle (ClutterText *self,
else
color = &priv->text_color;
cogl_color_init_from_4ub (&cogl_color,
color->red,
color->green,
color->blue,
paint_opacity * color->alpha / 255);
cogl_color_init_from_4f (&cogl_color,
color->red / 255.0,
color->green / 255.0,
color->blue / 255.0,
paint_opacity / 255.0 * color->alpha / 255.0);
cogl_color_premultiply (&cogl_color);
cogl_pipeline_set_color (color_pipeline, &cogl_color);
@ -1945,11 +1945,11 @@ paint_selection_rectangle (ClutterText *self,
else
color = &priv->text_color;
cogl_color_init_from_4ub (&cogl_color,
color->red,
color->green,
color->blue,
paint_opacity * color->alpha / 255);
cogl_color_init_from_4f (&cogl_color,
color->red / 255.0,
color->green / 255.0,
color->blue / 255.0,
paint_opacity / 255.0 * color->alpha / 255.0);
cogl_pango_show_layout (fb, layout, priv->text_x, 0, &cogl_color);
@ -1982,11 +1982,11 @@ selection_paint (ClutterText *self,
color = &priv->text_color;
cogl_color_init_from_4ub (&cogl_color,
color->red,
color->green,
color->blue,
paint_opacity * color->alpha / 255);
cogl_color_init_from_4f (&cogl_color,
color->red / 255.0,
color->green / 255.0,
color->blue / 255.0,
paint_opacity / 255.0 * color->alpha / 255.0);
cogl_color_premultiply (&cogl_color);
cogl_pipeline_set_color (color_pipeline, &cogl_color);
@ -2753,11 +2753,11 @@ clutter_text_paint (ClutterActor *self,
CLUTTER_NOTE (PAINT, "painting text (text: '%s')",
clutter_text_buffer_get_text (get_buffer (text)));
cogl_color_init_from_4ub (&color,
priv->text_color.red,
priv->text_color.green,
priv->text_color.blue,
real_opacity);
cogl_color_init_from_4f (&color,
priv->text_color.red / 255.0,
priv->text_color.green / 255.0,
priv->text_color.blue / 255.0,
real_opacity / 255.0);
cogl_pango_show_layout (fb, layout, priv->text_x, priv->text_y, &color);
selection_paint (text, fb);

View File

@ -714,11 +714,11 @@ cogl_pango_renderer_set_color_for_part (PangoRenderer *renderer,
{
CoglColor color;
cogl_color_init_from_4ub (&color,
pango_color->red >> 8,
pango_color->green >> 8,
pango_color->blue >> 8,
alpha ? alpha >> 8 : 0xff);
cogl_color_init_from_4f (&color,
pango_color->red / 65535.0,
pango_color->green / 65535.0,
pango_color->blue / 65535.0,
alpha ? alpha / 65535.0 : 1.0);
_cogl_pango_display_list_set_color_override (priv->display_list, &color);
}
@ -901,8 +901,8 @@ cogl_pango_renderer_draw_glyphs (PangoRenderer *renderer,
alpha = pango_renderer_get_alpha (renderer,
PANGO_RENDER_PART_FOREGROUND);
cogl_color_init_from_4ub (&color, 0xff, 0xff, 0xff,
alpha ? alpha >> 8 : 0xff);
cogl_color_init_from_4f (&color, 1.0, 1.0, 1.0,
alpha ? (alpha >> 8) / 255.0 : 1.0);
_cogl_pango_display_list_set_color_override (priv->display_list, &color);
}

View File

@ -57,21 +57,6 @@ cogl_color_free (CoglColor *color)
g_free (color);
}
void
cogl_color_init_from_4ub (CoglColor *color,
uint8_t red,
uint8_t green,
uint8_t blue,
uint8_t alpha)
{
g_return_if_fail (color != NULL);
color->red = red;
color->green = green;
color->blue = blue;
color->alpha = alpha;
}
void
cogl_color_init_from_4f (CoglColor *color,
float red,

View File

@ -81,23 +81,6 @@ cogl_color_copy (const CoglColor *color);
COGL_EXPORT void
cogl_color_free (CoglColor *color);
/**
* cogl_color_init_from_4ub:
* @color: A pointer to a #CoglColor to initialize
* @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 values of the passed channels into a #CoglColor.
*/
COGL_EXPORT void
cogl_color_init_from_4ub (CoglColor *color,
uint8_t red,
uint8_t green,
uint8_t blue,
uint8_t alpha);
/**
* cogl_color_init_from_4f:
* @color: A pointer to a #CoglColor to initialize

View File

@ -194,8 +194,8 @@ create_default_big_state (void)
blend_state->blend_equation_alpha = GL_FUNC_ADD;
blend_state->blend_src_factor_alpha = GL_ONE;
blend_state->blend_dst_factor_alpha = GL_ONE_MINUS_SRC_ALPHA;
cogl_color_init_from_4ub (&blend_state->blend_constant,
0x00, 0x00, 0x00, 0x00);
cogl_color_init_from_4f (&blend_state->blend_constant,
0.0, 0.0, 0.0, 0.0);
blend_state->blend_src_factor_rgb = GL_ONE;
blend_state->blend_dst_factor_rgb = GL_ONE_MINUS_SRC_ALPHA;
@ -229,7 +229,7 @@ _cogl_pipeline_init_default_pipeline (CoglContext *context)
pipeline->has_big_state = TRUE;
/* Use the same defaults as the GL spec... */
cogl_color_init_from_4ub (&pipeline->color, 0xff, 0xff, 0xff, 0xff);
cogl_color_init_from_4f (&pipeline->color, 1.0, 1.0, 1.0, 1.0);
#ifdef COGL_ENABLE_DEBUG
pipeline->static_breadcrumb = "default pipeline";

View File

@ -354,7 +354,7 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src,
&matrix);
cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix);
cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 0);
cogl_color_init_from_4f (&clear_color, 0.0, 0.0, 0.0, 0.0);
cogl_framebuffer_clear (fb, COGL_BUFFER_BIT_COLOR, &clear_color);
cogl_framebuffer_draw_rectangle (fb, pipeline,
-1, 1, 1, -1);

View File

@ -846,7 +846,8 @@ do_paint_content (MetaShapedTexture *stex,
cogl_pipeline_set_layer_filters (blended_pipeline, i, min_filter, mag_filter);
}
cogl_color_init_from_4ub (&color, opacity, opacity, opacity, opacity);
cogl_color_init_from_4f (&color, opacity / 255.0, opacity / 255.0,
opacity / 255.0, opacity / 255.0);
cogl_pipeline_set_color (blended_pipeline, &color);
if (blended_tex_region)

View File

@ -1448,7 +1448,7 @@ meta_window_actor_blit_to_framebuffer (MetaScreenCastWindow *screen_cast_window,
clutter_actor_inhibit_culling (actor);
cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 0);
cogl_color_init_from_4f (&clear_color, 0.0, 0.0, 0.0, 0.0);
cogl_framebuffer_clear (framebuffer, COGL_BUFFER_BIT_COLOR, &clear_color);
cogl_framebuffer_orthographic (framebuffer,
0, 0,
@ -1606,7 +1606,7 @@ create_framebuffer_from_window_actor (MetaWindowActor *self,
return NULL;
}
cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 0);
cogl_color_init_from_4f (&clear_color, 0.0, 0.0, 0.0, 0.0);
cogl_framebuffer_clear (framebuffer, COGL_BUFFER_BIT_COLOR, &clear_color);
cogl_framebuffer_orthographic (framebuffer, 0, 0, clip->width, clip->height,
0, 1.0);

View File

@ -83,11 +83,11 @@ test_coglbox_fade_texture (CoglFramebuffer *framebuffer,
{
CoglColor cogl_color;
cogl_color_init_from_4ub (&cogl_color,
255,
255,
255,
((i ^ (i >> 1)) & 1) ? 0 : 128);
cogl_color_init_from_4f (&cogl_color,
1.0,
1.0,
1.0,
((i ^ (i >> 1)) & 1) ? 0.0 : 128.0 / 255.0);
cogl_color_premultiply (&cogl_color);
vertices[i].r = cogl_color_get_red (&cogl_color) * 255.0;
vertices[i].g = cogl_color_get_green (&cogl_color) * 255.0;

View File

@ -37,7 +37,7 @@ test_alpha_test (void)
COGL_PIPELINE_ALPHA_FUNC_GEQUAL,
254 / 255.0f /* alpha reference */);
cogl_color_init_from_4ub (&clear_color, 0x00, 0x00, 0xff, 0xff);
cogl_color_init_from_4f (&clear_color, 0.0, 0.0, 1.0, 1.0);
cogl_framebuffer_clear (test_fb,
COGL_BUFFER_BIT_COLOR,
&clear_color);

View File

@ -97,7 +97,9 @@ test_blend_paint (TestState *state,
return;
}
cogl_color_init_from_4ub (&blend_const_color, Br, Bg, Bb, Ba);
cogl_color_init_from_4f (&blend_const_color,
Br / 255.0, Bg / 255.0,
Bb / 255.0, Ba / 255.0);
cogl_pipeline_set_blend_constant (pipeline, &blend_const_color);
cogl_framebuffer_draw_rectangle (test_fb,
@ -215,7 +217,9 @@ test_tex_combine (TestState *state,
combine_string, error->message);
}
cogl_color_init_from_4ub (&combine_const_color, Cr, Cg, Cb, Ca);
cogl_color_init_from_4f (&combine_const_color,
Cr / 255.0, Cg / 255.0,
Cb / 255.0, Ca / 255.0);
cogl_pipeline_set_layer_combine_constant (pipeline, 1, &combine_const_color);
cogl_framebuffer_draw_rectangle (test_fb,

View File

@ -36,11 +36,11 @@ paint (TestState *state)
CoglShader *shader;
CoglProgram *program;
cogl_color_init_from_4ub (&color, 0, 0, 0, 255);
cogl_color_init_from_4f (&color, 0.0, 0.0, 0.0, 1.0);
cogl_framebuffer_clear (test_fb, COGL_BUFFER_BIT_COLOR, &color);
/* Set the primary vertex color as red */
cogl_color_init_from_4ub (&color, 0xff, 0x00, 0x00, 0xff);
cogl_color_init_from_4f (&color, 1.0, 0.0, 0.0, 1.0);
cogl_pipeline_set_color (pipeline, &color);
/* Override the vertex color in the texture environment with a

View File

@ -11,11 +11,11 @@ create_two_layer_pipeline (void)
CoglColor color;
/* The pipeline is initially black */
cogl_color_init_from_4f (&color, 0.0, 0.0, 0.0, 255.0);
cogl_color_init_from_4f (&color, 0.0, 0.0, 0.0, 1.0);
cogl_pipeline_set_color (pipeline, &color);
/* The first layer adds a full red component */
cogl_color_init_from_4ub (&color, 255, 0, 0, 255);
cogl_color_init_from_4f (&color, 1.0, 0.0, 0.0, 1.0);
cogl_pipeline_set_layer_combine_constant (pipeline, 0, &color);
cogl_pipeline_set_layer_combine (pipeline,
0, /* layer_num */
@ -23,7 +23,7 @@ create_two_layer_pipeline (void)
NULL);
/* The second layer adds a full green component */
cogl_color_init_from_4ub (&color, 0, 255, 0, 255);
cogl_color_init_from_4f (&color, 0.0, 1.0, 0.0, 1.0);
cogl_pipeline_set_layer_combine_constant (pipeline, 1, &color);
cogl_pipeline_set_layer_combine (pipeline,
1, /* layer_num */
@ -122,7 +122,7 @@ test_layer_remove (void)
/* Check that we can modify a layer in a child pipeline */
pipeline0 = create_two_layer_pipeline ();
pipeline1 = cogl_pipeline_copy (pipeline0);
cogl_color_init_from_4ub (&color, 0, 0, 255, 255);
cogl_color_init_from_4f (&color, 0.0, 0.0, 1.0, 1.0);
cogl_pipeline_set_layer_combine_constant (pipeline1, 0, &color);
test_color (pipeline0, 0xffff00ff, pos++);
test_color (pipeline1, 0x00ffffff, pos++);
@ -133,7 +133,7 @@ test_layer_remove (void)
/* Check that we can modify a layer in a child pipeline but then remove it */
pipeline0 = create_two_layer_pipeline ();
pipeline1 = cogl_pipeline_copy (pipeline0);
cogl_color_init_from_4ub (&color, 0, 0, 255, 255);
cogl_color_init_from_4f (&color, 0.0, 0.0, 1.0, 1.0);
cogl_pipeline_set_layer_combine_constant (pipeline1, 0, &color);
cogl_pipeline_remove_layer (pipeline1, 0);
test_color (pipeline0, 0xffff00ff, pos++);

View File

@ -439,7 +439,9 @@ test_offscreen_texture_formats_store_rgb8 (void)
};
int i;
cogl_color_init_from_4ub (&color, red, green, blue, alpha);
cogl_color_init_from_4f (&color,
red / 255.0, green / 255.0,
blue / 255.0, alpha / 255.0);
for (i = 0; i < G_N_ELEMENTS (formats); i++)
{
@ -810,7 +812,9 @@ test_offscreen_texture_formats_paint_rgb8 (void)
};
int i;
cogl_color_init_from_4ub (&color, red, green, blue, alpha);
cogl_color_init_from_4f (&color,
red / 255.0, green / 255.0,
blue / 255.0, alpha / 255.0);
for (i = 0; i < G_N_ELEMENTS (formats); i++)
{

View File

@ -149,7 +149,7 @@ test_flush (TestState *state)
offscreen = cogl_offscreen_new_with_texture (tex);
framebuffer = COGL_FRAMEBUFFER (offscreen);
cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 255);
cogl_color_init_from_4f (&clear_color, 0.0, 0.0, 0.0, 1.0);
cogl_framebuffer_clear (framebuffer, COGL_BUFFER_BIT_COLOR, &clear_color);
cogl_framebuffer_draw_rectangle (framebuffer, pipeline, -1, -1, 1, 1);

View File

@ -69,7 +69,7 @@ test_pipeline_cache_unrefs_texture (void)
for (i = 0; i < N_TEXTURES; i++)
{
CoglColor combine_constant;
cogl_color_init_from_4ub (&combine_constant, i, 0, 0, 255);
cogl_color_init_from_4f (&combine_constant, i / 255.0, 0.0, 0.0, 1.0);
cogl_pipeline_set_layer_combine_constant (simple_pipeline,
i,
&combine_constant);

View File

@ -84,7 +84,7 @@ on_after_paint (ClutterActor *actor,
float height;
/* for clearing the offscreen framebuffer to black... */
cogl_color_init_from_4ub (&black, 0x00, 0x00, 0x00, 0xff);
cogl_color_init_from_4f (&black, 0.0, 0.0, 0.0, 1.0);
cogl_get_viewport (saved_viewport);
cogl_get_projection_matrix (&saved_projection);