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_movie.h"
25 #include "swfdec_debug.h"
26 #include "swfdec_player_internal.h"
28 G_DEFINE_TYPE (SwfdecBitmapMovie
, swfdec_bitmap_movie
, SWFDEC_TYPE_MOVIE
)
31 swfdec_bitmap_movie_update_extents (SwfdecMovie
*movie
,
34 SwfdecBitmapMovie
*bitmap
= SWFDEC_BITMAP_MOVIE (movie
);
35 SwfdecRect rect
= { 0, 0, 0, 0 };
37 if (bitmap
->bitmap
->surface
== NULL
)
40 rect
.x1
= cairo_image_surface_get_width (bitmap
->bitmap
->surface
) * SWFDEC_TWIPS_SCALE_FACTOR
;
41 rect
.y1
= cairo_image_surface_get_height (bitmap
->bitmap
->surface
) * SWFDEC_TWIPS_SCALE_FACTOR
;
43 swfdec_rect_union (extents
, extents
, &rect
);
47 swfdec_bitmap_movie_render (SwfdecMovie
*movie
, cairo_t
*cr
,
48 const SwfdecColorTransform
*trans
)
50 SwfdecBitmapMovie
*bitmap
= SWFDEC_BITMAP_MOVIE (movie
);
52 if (bitmap
->bitmap
->surface
== NULL
)
55 cairo_scale (cr
, SWFDEC_TWIPS_SCALE_FACTOR
, SWFDEC_TWIPS_SCALE_FACTOR
);
56 if (swfdec_color_transform_is_mask (trans
)) {
57 SWFDEC_FIXME ("does attachBitmap mask?");
58 cairo_set_source_rgb (cr
, 0, 0, 0);
59 cairo_rectangle (cr
, 0, 0,
60 cairo_image_surface_get_width (bitmap
->bitmap
->surface
),
61 cairo_image_surface_get_height (bitmap
->bitmap
->surface
));
63 } else if (swfdec_color_transform_is_identity (trans
)) {
64 cairo_set_source_surface (cr
, bitmap
->bitmap
->surface
, 0, 0);
66 } else if (swfdec_color_transform_is_alpha (trans
)) {
67 cairo_set_source_surface (cr
, bitmap
->bitmap
->surface
, 0, 0);
68 cairo_paint_with_alpha (cr
, trans
->aa
/ 255.0);
70 SWFDEC_FIXME ("properly color-transform bitmap");
71 cairo_set_source_surface (cr
, bitmap
->bitmap
->surface
, 0, 0);
77 swfdec_bitmap_movie_invalidate (SwfdecMovie
*movie
, const cairo_matrix_t
*matrix
, gboolean last
)
79 SwfdecBitmapMovie
*bitmap
= SWFDEC_BITMAP_MOVIE (movie
);
80 SwfdecRect rect
= { 0, 0, 0, 0 };
82 if (bitmap
->bitmap
->surface
== NULL
)
85 rect
.x1
= cairo_image_surface_get_width (bitmap
->bitmap
->surface
) * SWFDEC_TWIPS_SCALE_FACTOR
;
86 rect
.y1
= cairo_image_surface_get_height (bitmap
->bitmap
->surface
) * SWFDEC_TWIPS_SCALE_FACTOR
;
88 swfdec_rect_transform (&rect
, &rect
, matrix
);
89 swfdec_player_invalidate (SWFDEC_PLAYER (swfdec_gc_object_get_context (movie
)), &rect
);
93 swfdec_bitmap_movie_contains (SwfdecMovie
*movie
, double x
, double y
,
100 swfdec_bitmap_movie_mark (SwfdecGcObject
*object
)
102 SwfdecBitmapMovie
*bitmap
= SWFDEC_BITMAP_MOVIE (object
);
104 swfdec_gc_object_mark (bitmap
->bitmap
);
106 SWFDEC_GC_OBJECT_CLASS (swfdec_bitmap_movie_parent_class
)->mark (object
);
110 swfdec_bitmap_movie_dispose (GObject
*object
)
112 SwfdecBitmapMovie
*bitmap
= SWFDEC_BITMAP_MOVIE (object
);
114 g_signal_handlers_disconnect_by_func (bitmap
->bitmap
,
115 swfdec_movie_invalidate_last
, bitmap
);
116 g_object_unref (bitmap
->bitmap
);
118 G_OBJECT_CLASS (swfdec_bitmap_movie_parent_class
)->dispose (object
);
122 swfdec_bitmap_movie_class_init (SwfdecBitmapMovieClass
* g_class
)
124 GObjectClass
*object_class
= G_OBJECT_CLASS (g_class
);
125 SwfdecGcObjectClass
*gc_class
= SWFDEC_GC_OBJECT_CLASS (g_class
);
126 SwfdecMovieClass
*movie_class
= SWFDEC_MOVIE_CLASS (g_class
);
128 object_class
->dispose
= swfdec_bitmap_movie_dispose
;
130 gc_class
->mark
= swfdec_bitmap_movie_mark
;
132 movie_class
->update_extents
= swfdec_bitmap_movie_update_extents
;
133 movie_class
->render
= swfdec_bitmap_movie_render
;
134 movie_class
->invalidate
= swfdec_bitmap_movie_invalidate
;
135 movie_class
->contains
= swfdec_bitmap_movie_contains
;
139 swfdec_bitmap_movie_init (SwfdecBitmapMovie
* bitmap_movie
)
144 swfdec_bitmap_movie_new (SwfdecMovie
*parent
, SwfdecBitmapData
*bitmap
, int depth
)
146 SwfdecBitmapMovie
*movie
;
148 g_return_val_if_fail (SWFDEC_IS_MOVIE (parent
), NULL
);
149 g_return_val_if_fail (SWFDEC_IS_BITMAP_DATA (bitmap
), NULL
);
151 movie
= g_object_new (SWFDEC_TYPE_BITMAP_MOVIE
,
152 "context", swfdec_gc_object_get_context (parent
), "depth", depth
,
153 "parent", parent
, "resource", parent
->resource
, NULL
);
154 movie
->bitmap
= bitmap
;
155 /* we ref the bitmap here to enforce the order for destruction, which makes our signals work */
156 g_object_ref (bitmap
);
157 /* FIXME: be smarter in what we invalidate, use the rectangle */
158 g_signal_connect_swapped (movie
->bitmap
, "invalidate",
159 G_CALLBACK (swfdec_movie_invalidate_last
), movie
);
161 return SWFDEC_MOVIE (movie
);