[gtk+/wip/css: 132/167] borderimage: Change memory management
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/css: 132/167] borderimage: Change memory management
- Date: Sun, 8 Jan 2012 21:33:58 +0000 (UTC)
commit e1e8ad18af86657712a63dcc95e2eb7c97e83fc3
Author: Benjamin Otte <otte redhat com>
Date: Wed Jan 4 04:17:38 2012 +0100
borderimage: Change memory management
Making it a on-stack object simplifies things a lot.
gtk/gtkborderimage.c | 92 +++++++++---------------------------------
gtk/gtkborderimageprivate.h | 19 +++++----
gtk/gtkthemingengine.c | 24 ++++-------
3 files changed, 39 insertions(+), 96 deletions(-)
---
diff --git a/gtk/gtkborderimage.c b/gtk/gtkborderimage.c
index 00ea0c3..f702157 100644
--- a/gtk/gtkborderimage.c
+++ b/gtk/gtkborderimage.c
@@ -35,82 +35,30 @@
*/
#include "fallback-c89.c"
-struct _GtkBorderImage {
- GtkCssImage *source;
-
- GtkBorder slice;
- GtkBorder *width;
- GtkCssBorderImageRepeat repeat;
-
- gint ref_count;
-};
-
-GtkBorderImage *
-_gtk_border_image_new (GtkCssImage *source,
- GtkBorder *slice,
- GtkBorder *width,
- GtkCssBorderImageRepeat *repeat)
-{
- GtkBorderImage *image;
-
- image = g_slice_new0 (GtkBorderImage);
- image->ref_count = 1;
-
- image->source = g_object_ref (source);
-
- if (slice != NULL)
- image->slice = *slice;
-
- if (width != NULL)
- image->width = gtk_border_copy (width);
-
- if (repeat != NULL)
- image->repeat = *repeat;
-
- return image;
-}
-
-GtkBorderImage *
-_gtk_border_image_new_for_engine (GtkThemingEngine *engine)
+gboolean
+_gtk_border_image_init (GtkBorderImage *image,
+ GtkThemingEngine *engine)
{
- GtkCssImage *source;
-
- source = g_value_get_object (_gtk_theming_engine_peek_property (engine, "border-image-source"));
- if (source == NULL)
- return NULL;
-
- return _gtk_border_image_new (source,
- g_value_get_boxed (_gtk_theming_engine_peek_property (engine, "border-image-slice")),
- g_value_get_boxed (_gtk_theming_engine_peek_property (engine, "border-image-width")),
- g_value_get_boxed (_gtk_theming_engine_peek_property (engine, "border-image-repeat")));
-}
-
-GtkBorderImage *
-_gtk_border_image_ref (GtkBorderImage *image)
-{
- g_return_val_if_fail (image != NULL, NULL);
-
- image->ref_count++;
-
- return image;
-}
-
-void
-_gtk_border_image_unref (GtkBorderImage *image)
-{
- g_return_if_fail (image != NULL);
+ GtkBorder *width;
- image->ref_count--;
+ image->source = g_value_get_object (_gtk_theming_engine_peek_property (engine, "border-image-source"));
+ if (image->source == NULL)
+ return FALSE;
- if (image->ref_count == 0)
+ image->slice = *(GtkBorder *) g_value_get_boxed (_gtk_theming_engine_peek_property (engine, "border-image-slice"));
+ width = g_value_get_boxed (_gtk_theming_engine_peek_property (engine, "border-image-width"));
+ if (width)
{
- g_object_unref (image->source);
+ image->width = *width;
+ image->has_width = TRUE;
+ }
+ else
+ image->has_width = FALSE;
- if (image->width != NULL)
- gtk_border_free (image->width);
+ image->repeat = *(GtkCssBorderImageRepeat *) g_value_get_boxed (
+ _gtk_theming_engine_peek_property (engine, "border-image-repeat"));
- g_slice_free (GtkBorderImage, image);
- }
+ return TRUE;
}
typedef struct _GtkBorderImageSliceSize GtkBorderImageSliceSize;
@@ -291,8 +239,8 @@ _gtk_border_image_render (GtkBorderImage *image,
double source_width, source_height;
int h, v;
- if (image->width != NULL)
- border_width = image->width;
+ if (image->has_width)
+ border_width = &image->width;
_gtk_css_image_get_concrete_size (image->source,
0, 0,
diff --git a/gtk/gtkborderimageprivate.h b/gtk/gtkborderimageprivate.h
index a9d19d0..0970811 100644
--- a/gtk/gtkborderimageprivate.h
+++ b/gtk/gtkborderimageprivate.h
@@ -33,14 +33,17 @@ G_BEGIN_DECLS
typedef struct _GtkBorderImage GtkBorderImage;
-GtkBorderImage * _gtk_border_image_new (GtkCssImage *source,
- GtkBorder *slice,
- GtkBorder *width,
- GtkCssBorderImageRepeat *repeat);
-GtkBorderImage * _gtk_border_image_new_for_engine (GtkThemingEngine *engine);
-
-GtkBorderImage * _gtk_border_image_ref (GtkBorderImage *image);
-void _gtk_border_image_unref (GtkBorderImage *image);
+struct _GtkBorderImage {
+ GtkCssImage *source;
+
+ GtkBorder slice;
+ gboolean has_width;
+ GtkBorder width;
+ GtkCssBorderImageRepeat repeat;
+};
+
+gboolean _gtk_border_image_init (GtkBorderImage *image,
+ GtkThemingEngine *engine);
void _gtk_border_image_render (GtkBorderImage *image,
GtkBorder *border_width,
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index edcd5c4..754fe8c 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -1545,24 +1545,20 @@ gtk_theming_engine_render_frame (GtkThemingEngine *engine,
GtkStateFlags flags;
GtkBorderStyle border_style;
GtkJunctionSides junction;
- GtkBorderImage *border_image;
+ GtkBorderImage border_image;
GtkBorder border;
flags = gtk_theming_engine_get_state (engine);
junction = gtk_theming_engine_get_junction_sides (engine);
gtk_theming_engine_get_border (engine, flags, &border);
- border_image = _gtk_border_image_new_for_engine (engine);
gtk_theming_engine_get (engine, flags,
"border-style", &border_style,
NULL);
- if (border_image != NULL)
- {
- _gtk_border_image_render (border_image, &border,
- cr, x, y, width, height);
- _gtk_border_image_unref (border_image);
- }
+ if (_gtk_border_image_init (&border_image, engine))
+ _gtk_border_image_render (&border_image, &border,
+ cr, x, y, width, height);
else if (border_style != GTK_BORDER_STYLE_NONE)
render_frame_internal (engine, cr,
x, y, width, height,
@@ -1912,7 +1908,7 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
gdouble x0, y0, x1, y1, xc, yc, wc, hc;
- GtkBorderImage *border_image;
+ GtkBorderImage border_image;
GtkBorder border;
xc = yc = wc = hc = 0;
@@ -1920,7 +1916,6 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
junction = gtk_theming_engine_get_junction_sides (engine);
gtk_theming_engine_get_border (engine, state, &border);
- border_image = _gtk_border_image_new_for_engine (engine);
gtk_theming_engine_get (engine, state,
"border-top-left-radius", &top_left_radius,
"border-top-right-radius", &top_right_radius,
@@ -1995,12 +1990,9 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
cairo_clip (cr);
- if (border_image != NULL)
- {
- _gtk_border_image_render (border_image, &border,
- cr, x, y, width, height);
- _gtk_border_image_unref (border_image);
- }
+ if (_gtk_border_image_init (&border_image, engine))
+ _gtk_border_image_render (&border_image, &border,
+ cr, x, y, width, height);
else
render_frame_internal (engine, cr,
x, y, width, height,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]