add debugging messages for memory (de)allocation
[swfdec.git] / libswfdec / swfdec_video_movie.c
blobd17c0cb1bd62c9743aba6f14970742d26181f72f
1 /* Swfdec
2 * Copyright (C) 2007 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.
8 *
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
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include "swfdec_video_movie.h"
25 #include "swfdec_player_internal.h"
27 G_DEFINE_TYPE (SwfdecVideoMovie, swfdec_video_movie, SWFDEC_TYPE_MOVIE)
29 static void
30 swfdec_video_movie_update_extents (SwfdecMovie *movie,
31 SwfdecRect *extents)
33 SwfdecVideoMovie *video = SWFDEC_VIDEO_MOVIE (movie);
34 SwfdecRect rect = { 0, 0,
35 SWFDEC_TWIPS_SCALE_FACTOR * video->video->width,
36 SWFDEC_TWIPS_SCALE_FACTOR * video->video->height };
38 swfdec_rect_union (extents, extents, &rect);
41 static void
42 swfdec_video_movie_render (SwfdecMovie *mov, cairo_t *cr,
43 const SwfdecColorTransform *trans, const SwfdecRect *inval)
45 SwfdecVideoMovie *movie = SWFDEC_VIDEO_MOVIE (mov);
47 if (movie->image == NULL)
48 return;
50 cairo_scale (cr,
51 (mov->original_extents.x1 - mov->original_extents.x0) / movie->image_width,
52 (mov->original_extents.y1 - mov->original_extents.y0) / movie->image_height);
53 cairo_set_source_surface (cr, movie->image, 0.0, 0.0);
54 cairo_paint (cr);
57 static void
58 swfdec_video_movie_unset_input (SwfdecVideoMovie *movie)
60 if (movie->input == NULL)
61 return;
63 if (movie->input->disconnect)
64 movie->input->disconnect (movie->input, movie);
65 movie->input = NULL;
68 static void
69 swfdec_video_movie_dispose (GObject *object)
71 SwfdecVideoMovie *movie = SWFDEC_VIDEO_MOVIE (object);
73 swfdec_video_movie_unset_input (movie);
74 if (movie->image) {
75 cairo_surface_destroy (movie->image);
76 movie->image = NULL;
78 g_object_unref (movie->video);
80 G_OBJECT_CLASS (swfdec_video_movie_parent_class)->dispose (object);
83 static gboolean
84 swfdec_video_movie_iterate_end (SwfdecMovie *mov)
86 SwfdecVideoMovie *movie = SWFDEC_VIDEO_MOVIE (mov);
88 if (!SWFDEC_MOVIE_CLASS (swfdec_video_movie_parent_class)->iterate_end (mov))
89 return FALSE;
91 if (movie->input && movie->input->iterate) {
92 movie->input->iterate (movie->input);
95 return TRUE;
98 static void
99 swfdec_video_movie_init_movie (SwfdecMovie *movie)
101 SwfdecPlayer *player = SWFDEC_PLAYER (SWFDEC_AS_OBJECT (movie)->context);
103 swfdec_as_object_set_constructor (SWFDEC_AS_OBJECT (movie), player->Video);
106 static void
107 swfdec_video_movie_class_init (SwfdecVideoMovieClass * g_class)
109 GObjectClass *object_class = G_OBJECT_CLASS (g_class);
110 SwfdecMovieClass *movie_class = SWFDEC_MOVIE_CLASS (g_class);
112 object_class->dispose = swfdec_video_movie_dispose;
114 movie_class->update_extents = swfdec_video_movie_update_extents;
115 movie_class->render = swfdec_video_movie_render;
116 movie_class->init_movie = swfdec_video_movie_init_movie;
117 movie_class->iterate_end = swfdec_video_movie_iterate_end;
120 static void
121 swfdec_video_movie_init (SwfdecVideoMovie * video_movie)
125 void
126 swfdec_video_movie_set_input (SwfdecVideoMovie *movie, SwfdecVideoMovieInput *input)
128 g_return_if_fail (SWFDEC_IS_VIDEO_MOVIE (movie));
130 swfdec_video_movie_unset_input (movie);
131 movie->input = input;
132 if (input == NULL)
133 return;
134 if (input->connect)
135 input->connect (input, movie);
138 void
139 swfdec_video_movie_clear (SwfdecVideoMovie *movie)
141 g_return_if_fail (SWFDEC_IS_VIDEO_MOVIE (movie));
143 if (movie->image == NULL)
144 return;
146 cairo_surface_destroy (movie->image);
147 movie->image = NULL;
148 swfdec_movie_invalidate (SWFDEC_MOVIE (movie));
151 void
152 swfdec_video_movie_new_image (SwfdecVideoMovie *movie, cairo_surface_t *image)
154 g_return_if_fail (SWFDEC_IS_VIDEO_MOVIE (movie));
155 g_return_if_fail (image != NULL);
157 if (movie->image)
158 cairo_surface_destroy (movie->image);
159 cairo_surface_reference (image);
160 movie->image = image;
161 movie->image_width = cairo_image_surface_get_width (image);
162 movie->image_height = cairo_image_surface_get_height (image);
163 swfdec_movie_invalidate (SWFDEC_MOVIE (movie));