From 550cf8fa5ca62a1097f7803bacdc83edfe79bd2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 23 Oct 2010 20:57:25 +0000 Subject: [PATCH] Wait for the vertical retrace before blitting a bitmap, should avoid tearing in the video on supported graphics drivers. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39094 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/VideoView.cpp | 20 ++++++++++++++++++-- src/apps/mediaplayer/VideoView.h | 4 ++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/apps/mediaplayer/VideoView.cpp b/src/apps/mediaplayer/VideoView.cpp index 402dc922eb..876cd31423 100644 --- a/src/apps/mediaplayer/VideoView.cpp +++ b/src/apps/mediaplayer/VideoView.cpp @@ -8,10 +8,10 @@ #include -#include - #include +#include #include +#include #include #include "Settings.h" @@ -39,6 +39,8 @@ VideoView::VideoView(BRect frame, const char* name, uint32 resizeMask) fHasSubtitle(false), fSubtitleChanged(false), + fScreen(NULL), + fGlobalSettingsListener(this) { SetViewColor(B_TRANSPARENT_COLOR); @@ -63,6 +65,15 @@ VideoView::~VideoView() { Settings::Default()->RemoveListener(&fGlobalSettingsListener); delete fSubtitleBitmap; + delete fScreen; +} + + +void +VideoView::AttachedToWindow() +{ + delete fScreen; + fScreen = new BScreen(Window()); } @@ -367,6 +378,11 @@ VideoView::_DrawBitmap(const BBitmap* bitmap) { SetDrawingMode(B_OP_COPY); uint32 options = fUseBilinearScaling ? B_FILTER_BITMAP_BILINEAR : 0; + + // We don't care if the graphics driver actually supports this. + // On supported graphics hardware, this should avoid tearing. + fScreen->WaitForRetrace(); + DrawBitmapAsync(bitmap, bitmap->Bounds(), fVideoFrame, options); } diff --git a/src/apps/mediaplayer/VideoView.h b/src/apps/mediaplayer/VideoView.h index 4eb7372c79..35a207ec25 100644 --- a/src/apps/mediaplayer/VideoView.h +++ b/src/apps/mediaplayer/VideoView.h @@ -17,6 +17,7 @@ enum { }; +class BScreen; class SubtitleBitmap; @@ -27,6 +28,7 @@ public: virtual ~VideoView(); // BView interface + virtual void AttachedToWindow(); virtual void Draw(BRect updateRect); virtual void MessageReceived(BMessage* message); virtual void Pulse(); @@ -76,6 +78,8 @@ private: bool fHasSubtitle; bool fSubtitleChanged; + BScreen* fScreen; + // Settings values: ListenerAdapter fGlobalSettingsListener; bool fUseOverlays;