diff options
author | Sven Hesse | 2010-08-08 00:37:52 +0000 |
---|---|---|
committer | Sven Hesse | 2010-08-08 00:37:52 +0000 |
commit | 9255d2e2179ee6a2cd63b6d8f521e3b9d8543be6 (patch) | |
tree | 66c9a5498e44a5059596053554398bb5ab4bf83d /graphics/video | |
parent | 863872216f1f0e987640633d339ef62e314d15d4 (diff) | |
download | scummvm-rg350-9255d2e2179ee6a2cd63b6d8f521e3b9d8543be6.tar.gz scummvm-rg350-9255d2e2179ee6a2cd63b6d8f521e3b9d8543be6.tar.bz2 scummvm-rg350-9255d2e2179ee6a2cd63b6d8f521e3b9d8543be6.zip |
VIDEO/GOB: Add setSurfaceMemory() to CoktelDecoder
This allows the video player to directly draw onto its own video
memory without having to blit each frame another time.
Will also be needed for proper handling of transparency in Woodruff.
svn-id: r51857
Diffstat (limited to 'graphics/video')
-rw-r--r-- | graphics/video/coktel_decoder.cpp | 62 | ||||
-rw-r--r-- | graphics/video/coktel_decoder.h | 16 |
2 files changed, 72 insertions, 6 deletions
diff --git a/graphics/video/coktel_decoder.cpp b/graphics/video/coktel_decoder.cpp index 0c5b637c2b..d13e678d44 100644 --- a/graphics/video/coktel_decoder.cpp +++ b/graphics/video/coktel_decoder.cpp @@ -34,7 +34,8 @@ CoktelDecoder::State::State() : left(0), top(0), right(0), bottom(0), flags(0), CoktelDecoder::CoktelDecoder(Audio::Mixer &mixer, Audio::Mixer::SoundType soundType) : - _mixer(&mixer), _soundType(soundType), _width(0), _height(0), _frameCount(0), _paletteDirty(false) { + _mixer(&mixer), _soundType(soundType), _width(0), _height(0), _frameCount(0), + _paletteDirty(false), _ownSurface(true) { memset(_palette, 0, 768); } @@ -42,6 +43,59 @@ CoktelDecoder::CoktelDecoder(Audio::Mixer &mixer, Audio::Mixer::SoundType soundT CoktelDecoder::~CoktelDecoder() { } +void CoktelDecoder::setSurfaceMemory(void *mem, uint16 width, uint16 height, uint8 bpp) { + freeSurface(); + + assert((width > 0) && (height > 0)); + assert(bpp == getPixelFormat().bytesPerPixel); + + _surface.w = width; + _surface.h = height; + _surface.pitch = width * bpp; + _surface.pixels = mem; + _surface.bytesPerPixel = bpp; + + _ownSurface = false; +} + +void CoktelDecoder::setSurfaceMemory() { + freeSurface(); + createSurface(); + + _ownSurface = true; +} + +bool CoktelDecoder::hasSurface() { + return _surface.pixels != 0; +} + +void CoktelDecoder::createSurface() { + if (hasSurface()) + return; + + if ((_width > 0) && (_height > 0)) + _surface.create(_width, _height, getPixelFormat().bytesPerPixel); + + _ownSurface = true; +} + +void CoktelDecoder::freeSurface() { + if (!_ownSurface) { + _surface.w = 0; + _surface.h = 0; + _surface.pitch = 0; + _surface.pixels = 0; + _surface.bytesPerPixel = 0; + } else + _surface.free(); + + _ownSurface = true; +} + +void CoktelDecoder::close() { + freeSurface(); +} + uint16 CoktelDecoder::getWidth() const { return _width; } @@ -129,8 +183,6 @@ bool PreIMDDecoder::load(Common::SeekableReadStream &stream) { _frameCount = _stream->readUint16LE(); - _surface.create(_width, _height, 1); - _videoBufferSize = _width * _height; _videoBuffer = new byte[_videoBufferSize]; @@ -142,7 +194,7 @@ bool PreIMDDecoder::load(Common::SeekableReadStream &stream) { void PreIMDDecoder::close() { reset(); - _surface.free(); + CoktelDecoder::close(); delete _stream; @@ -162,6 +214,8 @@ Surface *PreIMDDecoder::decodeNextFrame() { if (!isVideoLoaded() || endOfVideo()) return 0; + createSurface(); + processFrame(); renderFrame(); diff --git a/graphics/video/coktel_decoder.h b/graphics/video/coktel_decoder.h index b354a5cd9d..ec9acbe879 100644 --- a/graphics/video/coktel_decoder.h +++ b/graphics/video/coktel_decoder.h @@ -64,8 +64,15 @@ public: virtual bool seek(int32 frame, int whence = SEEK_SET, bool restart = false) = 0; + /** Draw directly onto the specified video memory. */ + void setSurfaceMemory(void *mem, uint16 width, uint16 height, uint8 bpp); + /** Reset the video memory. */ + void setSurfaceMemory(); + // VideoDecoder interface + void close(); + uint16 getWidth() const; uint16 getHeight() const; @@ -86,8 +93,15 @@ protected: byte _palette[768]; bool _paletteDirty; + bool _ownSurface; + Surface _surface; + Common::Rational _frameRate; + bool hasSurface(); + void createSurface(); + void freeSurface(); + // FixedRateVideoDecoder interface Common::Rational getFrameRate() const; }; @@ -117,8 +131,6 @@ private: byte *_videoBuffer; uint32 _videoBufferSize; - Surface _surface; - void processFrame(); void renderFrame(); }; |