[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r11610: Prepare for background bitma
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r11610: Prepare for background bitmap loading. |
Date: |
Fri, 06 Nov 2009 23:19:35 +0100 |
User-agent: |
Bazaar (1.16.1) |
------------------------------------------------------------
revno: 11610
committer: Sandro Santilli <address@hidden>
branch nick: trunk
timestamp: Fri 2009-11-06 23:19:35 +0100
message:
Prepare for background bitmap loading.
What this commit does is basically burying non blocking read
of image data inside BitmapMovieDefinition.
The BitmapMovie::advance function will 'ping' the definition till
it states there's nothing more to do. Only then the instance will
fetch the actual bitmap (if any).
The drawback is we don't know image size at start time which means
you'll get an arbitrary 512x512 window when passing an image as first
argument to gnash.
modified:
libcore/BitmapMovie.cpp
libcore/BitmapMovie.h
libcore/impl.cpp
libcore/parser/BitmapMovieDefinition.cpp
libcore/parser/BitmapMovieDefinition.h
=== modified file 'libcore/BitmapMovie.cpp'
--- a/libcore/BitmapMovie.cpp 2009-11-04 15:03:15 +0000
+++ b/libcore/BitmapMovie.cpp 2009-11-06 22:19:35 +0000
@@ -21,7 +21,7 @@
namespace gnash {
-BitmapMovie::BitmapMovie(as_object* object, const BitmapMovieDefinition* def,
+BitmapMovie::BitmapMovie(as_object* object, BitmapMovieDefinition* def,
DisplayObject* parent)
:
Movie(object, def, parent),
@@ -29,10 +29,20 @@
{
assert(def);
assert(object);
- Bitmap* bm = new Bitmap(getRoot(*object), 0, def, this);
-
- const int depth = 1 + DisplayObject::staticDepthOffset;
- placeDisplayObject(bm, depth);
+}
+
+void
+BitmapMovie::advance()
+{
+ if ( ! _def->moreToLoad() )
+ {
+ Bitmap* bm = new Bitmap(getRoot(*object()), 0, _def, this);
+
+ const int depth = 1 + DisplayObject::staticDepthOffset;
+
+ placeDisplayObject(bm, depth);
+ }
+
}
} // namespace gnash
=== modified file 'libcore/BitmapMovie.h'
--- a/libcore/BitmapMovie.h 2009-11-04 15:03:15 +0000
+++ b/libcore/BitmapMovie.h 2009-11-06 22:19:35 +0000
@@ -42,7 +42,7 @@
public:
- BitmapMovie(as_object* object, const BitmapMovieDefinition* def,
+ BitmapMovie(as_object* object, BitmapMovieDefinition* def,
DisplayObject* parent);
virtual ~BitmapMovie() {}
@@ -50,7 +50,7 @@
/// BitmapMovies do need an advance method.
//
/// This may be for play() or other inherited methods.
- virtual void advance() { MovieClip::advance(); }
+ virtual void advance();
virtual float frameRate() const {
return _def->get_frame_rate();
@@ -78,7 +78,7 @@
private:
- const BitmapMovieDefinition* const _def;
+ BitmapMovieDefinition* _def;
};
=== modified file 'libcore/impl.cpp'
--- a/libcore/impl.cpp 2009-07-13 09:04:26 +0000
+++ b/libcore/impl.cpp 2009-11-06 22:19:35 +0000
@@ -46,6 +46,7 @@
#include <map>
#include <memory> // for auto_ptr
#include <algorithm>
+#include <boost/shared_ptr.hpp>
namespace gnash
{
@@ -76,21 +77,10 @@
try
{
- std::auto_ptr<GnashImage> im(
- ImageInput::readImageData(imageData, type));
-
- if (!im.get()) {
- log_error(_("Can't read image file from %s"), url);
- return NULL;
- }
-
Renderer* renderer = r.renderer();
-
BitmapMovieDefinition* mdef =
- new BitmapMovieDefinition(im, renderer, url);
-
+ new BitmapMovieDefinition(imageData, renderer, type, url);
return mdef;
-
}
catch (ParserException& e)
{
=== modified file 'libcore/parser/BitmapMovieDefinition.cpp'
--- a/libcore/parser/BitmapMovieDefinition.cpp 2009-11-04 16:55:59 +0000
+++ b/libcore/parser/BitmapMovieDefinition.cpp 2009-11-06 22:19:35 +0000
@@ -27,6 +27,9 @@
#include "Renderer.h"
#include "Global_as.h"
#include "namedStrings.h"
+#include "GnashException.h"
+#include <boost/shared_ptr.hpp>
+#include <sstream>
namespace gnash {
@@ -37,6 +40,23 @@
return new BitmapMovie(o, this, parent);
}
+BitmapMovieDefinition::BitmapMovieDefinition(
+ boost::shared_ptr<IOChannel> imageData,
+ Renderer* renderer, FileType type, const std::string& url)
+ :
+ _version(6),
+ _framesize(0,0,512*20,512*20), // arbitrary default size (will change)
+ _framecount(1),
+ _framerate(12),
+ _url(url),
+ _bytesTotal(0),
+ _bitmap(0),
+ _inputStream(imageData),
+ _inputFileType(type),
+ _renderer(renderer)
+{
+}
+
BitmapMovieDefinition::BitmapMovieDefinition(std::auto_ptr<GnashImage> image,
Renderer* renderer, const std::string& url)
:
@@ -58,6 +78,40 @@
return 0;
}
+bool
+BitmapMovieDefinition::moreToLoad()
+{
+ // TODO: use a thread for background loading here
+
+ // no more to load if we don't have an input stream
+ if ( ! _inputStream ) return false;
+ // ..... or it's in bad state .....
+ if ( _inputStream->bad() ) return false;
+ // ..... or it's over .....
+ if ( _inputStream->eof() ) return false;
+
+ // This one blocks... (and may throw ?)
+ log_debug("BitmapMovieDefinition starting image loading");
+ std::auto_ptr<GnashImage> im(
+ ImageInput::readImageData(_inputStream, _inputFileType));
+
+ log_debug("BitmapMovieDefinition finished image loading");
+ _inputStream.reset(); // we don't need this anymore
+
+ if (!im.get()) {
+ std::stringstream ss;
+ ss << _("Can't read image file from") << _url;
+ throw ParserException(ss.str());
+ }
+
+ _framesize.set_to_rect(0, 0, im->width()*20, im->height()*20);
+ _bytesTotal = im->size();
+
+ if ( _renderer ) _bitmap = _renderer->createBitmapInfo(im);
+
+ return false;
+}
+
#ifdef GNASH_USE_GC
void
BitmapMovieDefinition::markReachableResources() const
=== modified file 'libcore/parser/BitmapMovieDefinition.h'
--- a/libcore/parser/BitmapMovieDefinition.h 2009-11-04 15:03:15 +0000
+++ b/libcore/parser/BitmapMovieDefinition.h 2009-11-06 22:19:35 +0000
@@ -25,6 +25,8 @@
#include "DynamicShape.h" // for destructor visibility by intrusive_ptr
#include "GnashImage.h"
#include "GnashNumeric.h"
+#include "IOChannel.h"
+#include "gnash.h" // for FileType enum
#include <string>
#include <memory> // for auto_ptr
@@ -60,6 +62,21 @@
BitmapMovieDefinition(std::auto_ptr<GnashImage> image, Renderer*
renderer,
const std::string& url);
+ /// Construct a BitmapMovieDefinition for the given input
+ //
+ /// Will be initialized with the following values
+ ///
+ /// - SWF version 6
+ /// - Framesize 0x0 (to be updated after parsing)
+ /// - Single frame (unlabeled)
+ /// - 12 FPS
+ /// - 0 bytes size (for get_bytes_loaded()/get_bytes_total())
+ /// - provided url
+ ///
+ BitmapMovieDefinition(boost::shared_ptr<IOChannel> image,
+ Renderer* renderer, FileType type,
+ const std::string& url);
+
virtual DisplayObject* createDisplayObject(Global_as&, DisplayObject*)
const;
@@ -124,6 +141,9 @@
return _bitmap.get();
}
+ // Load more if needed, return false if finished loading all
+ bool moreToLoad();
+
protected:
#ifdef GNASH_USE_GC
@@ -147,6 +167,12 @@
size_t _bytesTotal;
boost::intrusive_ptr<BitmapInfo> _bitmap;
+
+ boost::shared_ptr<IOChannel> _inputStream;
+
+ FileType _inputFileType;
+
+ Renderer* _renderer;
};
} // namespace gnash
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r11610: Prepare for background bitmap loading.,
Sandro Santilli <=