[vlc-commits] windowless-mac: show last frame on pause
Felix Paul Kühne
git at videolan.org
Fri Jun 21 13:28:11 CEST 2013
npapi-vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Fri Jun 21 13:27:59 2013 +0200| [8a21163bab3d641f1e0d0bcaf5ae4a9a6356badc] | committer: Felix Paul Kühne
windowless-mac: show last frame on pause
> http://git.videolan.org/gitweb.cgi/npapi-vlc.git/?a=commit;h=8a21163bab3d641f1e0d0bcaf5ae4a9a6356badc
---
npapi/vlcwindowless_mac.cpp | 77 ++++++++++++++++++++++++++-----------------
npapi/vlcwindowless_mac.h | 3 ++
2 files changed, 49 insertions(+), 31 deletions(-)
diff --git a/npapi/vlcwindowless_mac.cpp b/npapi/vlcwindowless_mac.cpp
index e8bb37e..8c75aae 100644
--- a/npapi/vlcwindowless_mac.cpp
+++ b/npapi/vlcwindowless_mac.cpp
@@ -34,6 +34,8 @@ VlcWindowlessMac::VlcWindowlessMac(NPP instance, NPuint16_t mode) :
VlcWindowlessMac::~VlcWindowlessMac()
{
+ if (lastFrame)
+ CGImageRelease(lastFrame);
CGColorSpaceRelease(colorspace);
}
@@ -161,10 +163,7 @@ bool VlcWindowlessMac::handle_event(void *event)
CGContextClearRect(cgContext, CGRectMake(0, 0, npwindow.width, npwindow.height) );
- if(!VlcPluginBase::player_has_vout())
- return true;
-
- if (m_media_width == 0 || m_media_height == 0) {
+ if (m_media_width == 0 || m_media_height == 0 || (!lastFrame && !VlcPluginBase::playlist_isplaying()) || !get_player().is_open()) {
drawNoPlayback(cgContext);
return true;
}
@@ -176,39 +175,55 @@ bool VlcWindowlessMac::handle_event(void *event)
CGContextScaleCTM(cgContext, 1., -1.);
/* Compute the position of the video */
- float left = (npwindow.width - m_media_width) / 2.;
- float top = (npwindow.height - m_media_height) / 2.;
+ float left = 0;
+ float top = 0;
+
static const size_t kComponentsPerPixel = 4;
static const size_t kBitsPerComponent = sizeof(unsigned char) * 8;
+ CGRect rect;
+
+ if (m_media_width != 0 && m_media_height != 0) {
+ cached_width = m_media_width;
+ cached_height = m_media_height;
+ left = (npwindow.width - m_media_width) / 2.;
+ top = (npwindow.height - m_media_height) / 2.;
+
+ /* fetch frame */
+ CFDataRef dataRef = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
+ (const uint8_t *)&m_frame_buf[0],
+ sizeof(m_frame_buf[0]),
+ kCFAllocatorNull);
+ CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(dataRef);
+ lastFrame = CGImageCreate(m_media_width,
+ m_media_height,
+ kBitsPerComponent,
+ kBitsPerComponent * kComponentsPerPixel,
+ kComponentsPerPixel * m_media_width,
+ colorspace,
+ kCGBitmapByteOrder16Big,
+ dataProvider,
+ NULL,
+ true,
+ kCGRenderingIntentPerceptual);
- /* render frame */
- CFDataRef dataRef = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
- (const uint8_t *)&m_frame_buf[0],
- sizeof(m_frame_buf[0]),
- kCFAllocatorNull);
- CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(dataRef);
- CGImageRef image = CGImageCreate(m_media_width,
- m_media_height,
- kBitsPerComponent,
- kBitsPerComponent * kComponentsPerPixel,
- kComponentsPerPixel * m_media_width,
- colorspace,
- kCGBitmapByteOrder16Big,
- dataProvider,
- NULL,
- true,
- kCGRenderingIntentPerceptual);
- if (!image) {
- CGImageRelease(image);
CGDataProviderRelease(dataProvider);
- CGContextRestoreGState(cgContext);
- return true;
+
+ if (!lastFrame) {
+ fprintf(stderr, "image creation failed\n");
+ CGImageRelease(lastFrame);
+ CGContextRestoreGState(cgContext);
+ return true;
+ }
+
+ rect = CGRectMake(left, top, m_media_width, m_media_height);
+ } else {
+ fprintf(stderr, "drawing old frame again\n");
+ left = (npwindow.width - cached_width) / 2.;
+ top = (npwindow.height - cached_height) / 2.;
+ rect = CGRectMake(left, top, cached_width, cached_width);
}
- CGRect rect = CGRectMake(left, top, m_media_width, m_media_height);
- CGContextDrawImage(cgContext, rect, image);
- CGImageRelease(image);
- CGDataProviderRelease(dataProvider);
+ CGContextDrawImage(cgContext, rect, lastFrame);
CGContextRestoreGState(cgContext);
diff --git a/npapi/vlcwindowless_mac.h b/npapi/vlcwindowless_mac.h
index bd5202c..401fcc8 100644
--- a/npapi/vlcwindowless_mac.h
+++ b/npapi/vlcwindowless_mac.h
@@ -40,6 +40,9 @@ protected:
private:
CGColorSpaceRef colorspace;
+ CGImageRef lastFrame;
+ int cached_width;
+ int cached_height;
};
#endif /* __VLCWINDOWLESS_MAC_H__ */
More information about the vlc-commits
mailing list