st-drawing-area: Fix Cogl deprecations

This commit is contained in:
Jasper St. Pierre 2015-02-20 17:01:15 -08:00
parent 1c5b73bfdf
commit ad75739fc5

View File

@ -39,8 +39,8 @@
G_DEFINE_TYPE(StDrawingArea, st_drawing_area, ST_TYPE_WIDGET); G_DEFINE_TYPE(StDrawingArea, st_drawing_area, ST_TYPE_WIDGET);
struct _StDrawingAreaPrivate { struct _StDrawingAreaPrivate {
CoglHandle texture; CoglTexture *texture;
CoglHandle material; CoglPipeline *pipeline;
cairo_t *context; cairo_t *context;
guint needs_repaint : 1; guint needs_repaint : 1;
guint in_repaint : 1; guint in_repaint : 1;
@ -61,17 +61,8 @@ st_drawing_area_dispose (GObject *object)
StDrawingArea *area = ST_DRAWING_AREA (object); StDrawingArea *area = ST_DRAWING_AREA (object);
StDrawingAreaPrivate *priv = area->priv; StDrawingAreaPrivate *priv = area->priv;
if (priv->material != COGL_INVALID_HANDLE) g_clear_pointer (&priv->pipeline, cogl_object_unref);
{ g_clear_pointer (&priv->texture, cogl_object_unref);
cogl_handle_unref (priv->material);
priv->material = COGL_INVALID_HANDLE;
}
if (priv->texture != COGL_INVALID_HANDLE)
{
cogl_handle_unref (priv->texture);
priv->texture = COGL_INVALID_HANDLE;
}
G_OBJECT_CLASS (st_drawing_area_parent_class)->dispose (object); G_OBJECT_CLASS (st_drawing_area_parent_class)->dispose (object);
} }
@ -85,8 +76,6 @@ st_drawing_area_paint (ClutterActor *self)
ClutterActorBox allocation_box; ClutterActorBox allocation_box;
ClutterActorBox content_box; ClutterActorBox content_box;
int width, height; int width, height;
CoglColor color;
guint8 paint_opacity;
(CLUTTER_ACTOR_CLASS (st_drawing_area_parent_class))->paint (self); (CLUTTER_ACTOR_CLASS (st_drawing_area_parent_class))->paint (self);
@ -96,20 +85,25 @@ st_drawing_area_paint (ClutterActor *self)
width = (int)(0.5 + content_box.x2 - content_box.x1); width = (int)(0.5 + content_box.x2 - content_box.x1);
height = (int)(0.5 + content_box.y2 - content_box.y1); height = (int)(0.5 + content_box.y2 - content_box.y1);
if (priv->material == COGL_INVALID_HANDLE) if (priv->pipeline == NULL)
priv->material = cogl_material_new (); {
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
if (priv->texture != COGL_INVALID_HANDLE && priv->pipeline = cogl_pipeline_new (ctx);
}
if (priv->texture != NULL &&
(width != cogl_texture_get_width (priv->texture) || (width != cogl_texture_get_width (priv->texture) ||
height != cogl_texture_get_height (priv->texture))) height != cogl_texture_get_height (priv->texture)))
{ {
cogl_handle_unref (priv->texture); cogl_object_unref (priv->texture);
priv->texture = COGL_INVALID_HANDLE; priv->texture = NULL;
} }
if (width > 0 && height > 0) if (width > 0 && height > 0)
{ {
if (priv->texture == COGL_INVALID_HANDLE) if (priv->texture == NULL)
{ {
priv->texture = cogl_texture_new_with_size (width, height, priv->texture = cogl_texture_new_with_size (width, height,
COGL_TEXTURE_NONE, COGL_TEXTURE_NONE,
@ -141,19 +135,21 @@ st_drawing_area_paint (ClutterActor *self)
} }
} }
cogl_material_set_layer (priv->material, 0, priv->texture); cogl_pipeline_set_layer_texture (priv->pipeline, 0, priv->texture);
if (priv->texture) if (priv->texture)
{ {
paint_opacity = clutter_actor_get_paint_opacity (self); CoglColor color;
cogl_color_set_from_4ub (&color, guint8 paint_opacity;
paint_opacity, paint_opacity, paint_opacity, paint_opacity); CoglFramebuffer *fb = cogl_get_draw_framebuffer ();
cogl_material_set_color (priv->material, &color);
cogl_set_source (priv->material); paint_opacity = clutter_actor_get_paint_opacity (self);
cogl_rectangle_with_texture_coords (content_box.x1, content_box.y1, cogl_color_init_from_4ub (&color, paint_opacity, paint_opacity, paint_opacity, paint_opacity);
content_box.x2, content_box.y2, cogl_pipeline_set_color (priv->pipeline, &color);
0.0f, 0.0f, 1.0f, 1.0f);
cogl_framebuffer_draw_rectangle (fb, priv->pipeline,
content_box.x1, content_box.y1,
content_box.x2, content_box.y2);
} }
} }
@ -195,7 +191,7 @@ st_drawing_area_init (StDrawingArea *area)
{ {
area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area, ST_TYPE_DRAWING_AREA, area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area, ST_TYPE_DRAWING_AREA,
StDrawingAreaPrivate); StDrawingAreaPrivate);
area->priv->texture = COGL_INVALID_HANDLE; area->priv->texture = NULL;
} }
/** /**