Gnash  0.8.11dev
sprite_definition.h
Go to the documentation of this file.
1 // sprite_definition.h: Holds immutable data for a sprite, for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 
21 #ifndef GNASH_SPRITE_DEFINITION_H
22 #define GNASH_SPRITE_DEFINITION_H
23 
24 #include <boost/intrusive_ptr.hpp>
25 #include <cstdint>
26 #include <string>
27 #include <map>
28 #include "movie_definition.h" // for inheritance
29 #include "log.h"
30 #include "SWFRect.h"
31 #include "StringPredicates.h" // StringNoCaseLessThan
32 
33 // Forward declarations
34 namespace gnash {
35  class SWFStream;
36  class as_function;
37  class RunResources;
38 }
39 
40 namespace gnash
41 {
42 
43 
50 {
51 
52 public:
53 
56  //
68  const RunResources& runResources, std::uint16_t id);
69 
72 
73  virtual void incrementLoadedFrames() {
74  ++m_loading_frame;
75  }
76 
77  // overload from movie_definition
78  virtual size_t get_width_pixels() const { return 1; }
79 
80  // overload from movie_definition
81  virtual size_t get_height_pixels() const { return 1; }
82 
83  // overload from movie_definition
84  virtual size_t get_frame_count() const { return m_frame_count; }
85 
90  virtual size_t get_bytes_total() const
91  {
92  return m_movie_def.get_bytes_total();
93  }
94 
99  virtual size_t get_bytes_loaded() const
100  {
101  return m_movie_def.get_bytes_loaded();
102  }
103 
104  virtual float get_frame_rate() const
105  {
106  return m_movie_def.get_frame_rate();
107  }
108 
109  const SWFRect& get_frame_size() const
110  {
111  abort();
112  static const SWFRect unused;
113  return unused;
114  }
115 
116  // Return number of frames loaded (of current sprite)
117  virtual size_t get_loading_frame() const { return m_loading_frame; }
118 
119  virtual int get_version() const
120  {
121  return m_movie_def.get_version();
122  }
123 
125  virtual void add_font(int /*id*/, boost::intrusive_ptr<Font> /*ch*/)
126  {
128  log_swferror(_("add_font tag appears in sprite tags"));
129  );
130  }
131 
133  virtual Font* get_font(int id) const
134  {
135  return m_movie_def.get_font(id);
136  }
137 
139  virtual CachedBitmap* getBitmap(int id) const
140  {
141  return m_movie_def.getBitmap(id);
142  }
143 
145  virtual void addBitmap(int /*id*/, boost::intrusive_ptr<CachedBitmap> /*im*/)
146  {
148  log_swferror(_("add_bitmap_SWF::DefinitionTag appears in sprite tags"));
149  );
150  }
151 
153  virtual sound_sample* get_sound_sample(int id) const
154  {
155  return m_movie_def.get_sound_sample(id);
156  }
157 
159  virtual void add_sound_sample(int id, sound_sample* sam)
160  {
161  // DEFINESOUND tags *are* allowed in a sprite context,
162  // and it is *expected* for them to be registered into
163  // the main dictionary.
164  m_movie_def.add_sound_sample(id,sam);
165  }
166 
167  // See dox in movie_definition.h
168  virtual void set_loading_sound_stream_id(int id)
169  {
170  _loadingSoundStream = id;
171  }
172 
173  // See dox in movie_definition.h
174  virtual int get_loading_sound_stream_id() const
175  {
176  return _loadingSoundStream;
177  }
178 
179  virtual std::uint16_t exportID(const std::string& symbol) const {
180  return m_movie_def.exportID(symbol);
181  }
182 
183  virtual void registerExport(const std::string& s, std::uint16_t id) {
184  m_movie_def.registerExport(s, id);
185  }
186 
191  virtual SWF::DefinitionTag* getDefinitionTag(std::uint16_t id) const
192  {
193  return m_movie_def.getDefinitionTag(id);
194  }
195 
197  virtual void addDisplayObject(std::uint16_t id, SWF::DefinitionTag* c)
198  {
199  m_movie_def.addDisplayObject(id, c);
200  }
201 
202  // Create a (mutable) instance of our definition. The
203  // instance is created to live (temporarily) on some level on
204  // the parent movie's display list.
205  //
206  // overloads from SWF::DefinitionTag
208  DisplayObject* parent) const;
209 
210  // See dox in movie_definition.h
211  virtual void addControlTag(boost::intrusive_ptr<SWF::ControlTag> c)
212  {
213  m_playlist[m_loading_frame].push_back(c);
214  }
215 
216 private:
217 
218  void read(SWFStream& in, const RunResources& runResources);
219 
222  movie_definition& m_movie_def;
223 
224  typedef std::map<size_t, PlayList> PlayListMap;
225 
227  PlayListMap m_playlist;
228 
229  // stores 0-based frame #'s
230  typedef std::map<std::string, size_t, StringNoCaseLessThan> NamedFrameMap;
231  NamedFrameMap _namedFrames;
232 
233  size_t m_frame_count;
234 
235  // Number of frames completely parsed
236  size_t m_loading_frame;
237 
238  // See dox in movie_definition.h
239  virtual void add_frame_name(const std::string& name);
240 
241  // See dox in movie_definition
242  bool get_labeled_frame(const std::string& label, size_t& frame_number)
243  const;
244 
246  const PlayList* getPlaylist(size_t frame_number) const
247  {
248  // Don't access playlist of a frame which has not been
249  // completely parsed yet.
250  //assert(frame_number < m_loading_frame);
251 
252  PlayListMap::const_iterator it = m_playlist.find(frame_number);
253  if ( it == m_playlist.end() ) return nullptr;
254  else return &(it->second);
255  }
256 
257  virtual const std::string& get_url() const
258  {
259  return m_movie_def.get_url();
260  }
261 
266  virtual bool ensure_frame_loaded(size_t framenum) const
267  {
268  // TODO: return false on timeout
269  while ( m_loading_frame < framenum )
270  {
271  log_debug(_("sprite_definition: "
272  "loading of frame %d requested "
273  "(we are at %d/%d)"),
274  framenum, m_loading_frame, m_frame_count);
275  // Could this ever happen ? YES ! See tuner_7_6_0_0_pandora.swf
276  return false;
277  }
278  return true;
279  }
280 
281  int _loadingSoundStream;
282 
283 };
284 
285 
286 } // end of namespace gnash
287 
288 #endif
virtual Font * get_font(int) const
Return the font with given DisplayObject id.
Definition: movie_definition.h:253
virtual void registerExport(const std::string &, std::uint16_t)
Register a symbol to refer to a character id.
Definition: movie_definition.h:390
virtual CachedBitmap * getBitmap(int) const
Get a bitmap from the bitmap dictionary.
Definition: movie_definition.h:329
virtual size_t get_bytes_loaded() const
Return the number of bytes loaded from the stream of the the movie from which this sprite is being re...
Definition: sprite_definition.h:99
Client program&#39;s interface to the definition of a movie or sprite.
Definition: movie_definition.h:95
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:168
A Font resource.
Definition: Font.h:89
virtual void addDisplayObject(std::uint16_t id, SWF::DefinitionTag *c)
Delegate call to associated root movie.
Definition: sprite_definition.h:197
virtual void add_sound_sample(int, sound_sample *)
Add a sound sample DisplayObject in the dictionary, with the specified DisplayObject id...
Definition: movie_definition.h:362
Holds the immutable data for a sprite, as read from as SWF stream. @ should not derive from movie_def...
Definition: sprite_definition.h:49
virtual int get_loading_sound_stream_id() const
Get the currently being loaded sound stream, if any.
Definition: sprite_definition.h:174
~sprite_definition()
Destructor, releases playlist data.
Definition: sprite_definition.cpp:49
virtual const std::string & get_url() const =0
Return the URL of the SWF stream this definition has been read from.
virtual sound_sample * get_sound_sample(int id) const
Delegate call to associated root movie.
Definition: sprite_definition.h:153
virtual Font * get_font(int id) const
Delegate call to associated root movie.
Definition: sprite_definition.h:133
virtual int get_version() const =0
virtual size_t get_loading_frame() const
Returns 1 based index. Ex: if 1 then 1st frame as been fully loaded.
Definition: sprite_definition.h:117
virtual size_t get_height_pixels() const
Frame height in pixels.
Definition: sprite_definition.h:81
virtual size_t get_bytes_total() const =0
Get total number of bytes in (uncompressed for SWF) input stream.
virtual void set_loading_sound_stream_id(int id)
Set the currently being loaded sound stream.
Definition: sprite_definition.h:168
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Immutable data representing the definition of a movie display element.
Definition: DefinitionTag.h:47
virtual float get_frame_rate() const
Definition: sprite_definition.h:104
virtual void add_sound_sample(int id, sound_sample *sam)
Overridden just for complaining about malformed SWF.
Definition: sprite_definition.h:159
virtual CachedBitmap * getBitmap(int id) const
Delegate call to associated root movie.
Definition: sprite_definition.h:139
virtual SWF::DefinitionTag * getDefinitionTag(std::uint16_t id) const
Get a SWF::DefinitionTag from this Sprite&#39;s root movie CharacterDictionary.
Definition: sprite_definition.h:191
#define IF_VERBOSE_MALFORMED_SWF(x)
Definition: log.h:404
Definition: GnashKey.h:149
virtual int get_version() const
Definition: sprite_definition.h:119
virtual void addControlTag(boost::intrusive_ptr< SWF::ControlTag > c)
Add an ControlTag to this movie_definition&#39;s playlist.
Definition: sprite_definition.h:211
virtual float get_frame_rate() const =0
virtual void addDisplayObject(std::uint16_t, DefinitionTag *)
Add a DefinitionTag with given ID to the CharactersDictionary.
Definition: movie_definition.h:233
virtual std::uint16_t exportID(const std::string &) const
Get the id that corresponds to a symbol.
Definition: movie_definition.h:396
virtual DefinitionTag * getDefinitionTag(std::uint16_t) const
Get a DisplayObject from the dictionary.
Definition: movie_definition.h:196
const SWFRect & get_frame_size() const
Return size of frame, in TWIPS.
Definition: sprite_definition.h:109
#define _(String)
Definition: log.h:44
std::uint16_t id() const
The immutable id of the DefinitionTag.
Definition: DefinitionTag.h:76
virtual size_t get_width_pixels() const
Frame width in pixels.
Definition: sprite_definition.h:78
sprite_definition(movie_definition &m, SWFStream &in, const RunResources &runResources, std::uint16_t id)
Read the sprite info from input stream.
Definition: sprite_definition.cpp:110
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:53
std::vector< boost::intrusive_ptr< SWF::ControlTag > > PlayList
Definition: movie_definition.h:98
virtual void incrementLoadedFrames()
Definition: sprite_definition.h:73
virtual void addBitmap(int, boost::intrusive_ptr< CachedBitmap >)
Overridden just for complaining about malformed SWF.
Definition: sprite_definition.h:145
void log_swferror(StringType msg, Args... args)
Definition: log.h:325
virtual size_t get_bytes_total() const
Return total bytes of the movie from which this sprite has been read.
Definition: sprite_definition.h:90
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:49
virtual void add_font(int, boost::intrusive_ptr< Font >)
Overridden just for complaining about malformed SWF.
Definition: sprite_definition.h:125
virtual size_t get_bytes_loaded() const =0
virtual void registerExport(const std::string &s, std::uint16_t id)
Register a symbol to refer to a character id.
Definition: sprite_definition.h:183
virtual std::uint16_t exportID(const std::string &symbol) const
Get the id that corresponds to a symbol.
Definition: sprite_definition.h:179
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:44
virtual size_t get_frame_count() const
Definition: sprite_definition.h:84
Definition: GnashKey.h:159
Definition: GnashKey.h:165
An identifier for a sound sample managed by a sound_handler.
Definition: sound_definition.h:61
A CachedBitmap is created by the renderer in a format of its choosing.
Definition: CachedBitmap.h:37
void log_debug(StringType msg, Args... args)
Definition: log.h:301
std::string name
Definition: LocalConnection_as.cpp:149
SWF stream wrapper class.
Definition: SWFStream.h:58
virtual DisplayObject * createDisplayObject(Global_as &gl, DisplayObject *parent) const
Create a DisplayObject with the given parent.
Definition: sprite_definition.cpp:39
virtual sound_sample * get_sound_sample(int) const
Get the sound sample with given ID.
Definition: movie_definition.h:351