2 * Copyright (C) 2008 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
24 #include "swfdec_bitmap_pattern.h"
25 #include "swfdec_debug.h"
26 #include "swfdec_player_internal.h"
27 #include "swfdec_renderer_internal.h"
34 G_DEFINE_TYPE (SwfdecBitmapPattern
, swfdec_bitmap_pattern
, SWFDEC_TYPE_PATTERN
)
35 static guint signals
[LAST_SIGNAL
];
37 static cairo_pattern_t
*
38 swfdec_bitmap_pattern_get_pattern (SwfdecPattern
*pat
, SwfdecRenderer
*renderer
,
39 const SwfdecColorTransform
*ctrans
)
41 SwfdecBitmapPattern
*bitmap
= SWFDEC_BITMAP_PATTERN (pat
);
42 cairo_pattern_t
*pattern
;
44 pattern
= swfdec_bitmap_data_get_pattern (bitmap
->bitmap
, renderer
, ctrans
);
47 cairo_pattern_set_matrix (pattern
, &pat
->transform
);
48 cairo_pattern_set_extend (pattern
, bitmap
->extend
);
49 cairo_pattern_set_filter (pattern
, bitmap
->filter
);
54 swfdec_bitmap_pattern_morph (SwfdecDraw
*dest
, SwfdecDraw
*source
, guint ratio
)
56 SwfdecBitmapPattern
*dpattern
= SWFDEC_BITMAP_PATTERN (dest
);
57 SwfdecBitmapPattern
*spattern
= SWFDEC_BITMAP_PATTERN (source
);
59 dpattern
->bitmap
= g_object_ref (spattern
->bitmap
);
60 dpattern
->extend
= spattern
->extend
;
61 dpattern
->filter
= spattern
->filter
;
63 SWFDEC_DRAW_CLASS (swfdec_bitmap_pattern_parent_class
)->morph (dest
, source
, ratio
);
67 swfdec_bitmap_pattern_invalidate (SwfdecBitmapPattern
*bitmap
)
69 g_signal_emit (bitmap
, signals
[INVALIDATE
], 0);
73 swfdec_bitmap_pattern_dispose (GObject
*object
)
75 SwfdecBitmapPattern
*bitmap
= SWFDEC_BITMAP_PATTERN (object
);
77 g_signal_handlers_disconnect_by_func (bitmap
->bitmap
,
78 swfdec_bitmap_pattern_invalidate
, bitmap
);
79 g_object_unref (bitmap
->bitmap
);
81 G_OBJECT_CLASS (swfdec_bitmap_pattern_parent_class
)->dispose (object
);
85 swfdec_bitmap_pattern_class_init (SwfdecBitmapPatternClass
*klass
)
87 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
88 SwfdecDrawClass
*draw_class
= SWFDEC_DRAW_CLASS (klass
);
89 SwfdecPatternClass
*pattern_class
= SWFDEC_PATTERN_CLASS (klass
);
91 object_class
->dispose
= swfdec_bitmap_pattern_dispose
;
93 signals
[INVALIDATE
] = g_signal_new ("invalidate", G_TYPE_FROM_CLASS (klass
),
94 G_SIGNAL_RUN_LAST
, 0, NULL
, NULL
, g_cclosure_marshal_VOID__VOID
,
97 pattern_class
->get_pattern
= swfdec_bitmap_pattern_get_pattern
;
99 draw_class
->morph
= swfdec_bitmap_pattern_morph
;
103 swfdec_bitmap_pattern_init (SwfdecBitmapPattern
*bitmap
)
105 bitmap
->extend
= CAIRO_EXTEND_REPEAT
;
106 bitmap
->filter
= CAIRO_FILTER_NEAREST
;
110 swfdec_bitmap_pattern_new (SwfdecBitmapData
*bitmap
)
112 SwfdecBitmapPattern
*pattern
;
114 g_return_val_if_fail (SWFDEC_IS_BITMAP_DATA (bitmap
), NULL
);
116 pattern
= g_object_new (SWFDEC_TYPE_BITMAP_PATTERN
, NULL
);
117 pattern
->bitmap
= bitmap
;
118 /* we ref the bitmap here as we are not garbage-collected, and we wanna keep a reference */
119 g_object_ref (bitmap
);
120 g_signal_connect_swapped (pattern
->bitmap
, "invalidate",
121 G_CALLBACK (swfdec_bitmap_pattern_invalidate
), pattern
);
123 return SWFDEC_PATTERN (pattern
);