From 01e0d3278a2849546efa72c14eacd70854e0bc2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 28 Sep 2010 10:57:54 +0000 Subject: [PATCH] * Use asynchronous bitmap drawing in VideoView. Wouldn't matter much, though. * In SubtitleBitmap, if we ever take too long to generate a subtitle bitmap with the drop-shadow, fall back to outline mode. The StackBlurFilter is extremely fast, though, so there isn't a huge difference. It can fix some jumps in the video when switching subtitles in fullscreen mode, though. * Introduce overlay mode to SubpixelBitmap. It uses the black outline then and disables font anti-aliasing (just for the outline). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38833 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/VideoView.cpp | 19 ++++++-- src/apps/mediaplayer/VideoView.h | 1 + .../mediaplayer/interface/SubtitleBitmap.cpp | 46 +++++++++++++++---- .../mediaplayer/interface/SubtitleBitmap.h | 5 +- 4 files changed, 56 insertions(+), 15 deletions(-) diff --git a/src/apps/mediaplayer/VideoView.cpp b/src/apps/mediaplayer/VideoView.cpp index cc20482054..29fc26c969 100644 --- a/src/apps/mediaplayer/VideoView.cpp +++ b/src/apps/mediaplayer/VideoView.cpp @@ -157,7 +157,7 @@ VideoView::SetBitmap(const BBitmap* bitmap) FillRect(fVideoFrame, B_SOLID_LOW); Sync(); // use overlay from here on - fOverlayMode = true; + _SetOverlayMode(true); // update restrictions overlay_restrictions restrictions; @@ -180,7 +180,7 @@ VideoView::SetBitmap(const BBitmap* bitmap) } } else if (fOverlayMode && (bitmap->Flags() & B_BITMAP_WILL_OVERLAY) == 0) { - fOverlayMode = false; + _SetOverlayMode(false); ClearViewOverlay(); SetViewColor(B_TRANSPARENT_COLOR); } @@ -255,7 +255,7 @@ VideoView::DisableOverlay() ClearViewOverlay(); snooze(20000); Sync(); - fOverlayMode = false; + _SetOverlayMode(false); } @@ -315,7 +315,7 @@ VideoView::_DrawBitmap(const BBitmap* bitmap) { SetDrawingMode(B_OP_COPY); uint32 options = fUseBilinearScaling ? B_FILTER_BITMAP_BILINEAR : 0; - DrawBitmap(bitmap, bitmap->Bounds(), fVideoFrame, options); + DrawBitmapAsync(bitmap, bitmap->Bounds(), fVideoFrame, options); if (fHasSubtitle) { SetDrawingMode(B_OP_ALPHA); @@ -326,7 +326,7 @@ VideoView::_DrawBitmap(const BBitmap* bitmap) offset.x = (fVideoFrame.left + fVideoFrame.right - subtitleBitmap->Bounds().Width()) / 2; offset.y = fVideoFrame.bottom - subtitleBitmap->Bounds().Height(); - DrawBitmap(subtitleBitmap, offset); + DrawBitmapAsync(subtitleBitmap, offset); } } @@ -344,3 +344,12 @@ VideoView::_AdoptGlobalSettings() Invalidate(); } + +void +VideoView::_SetOverlayMode(bool overlayMode) +{ + fOverlayMode = overlayMode; + fSubtitleBitmap->SetOverlayMode(overlayMode); +} + + diff --git a/src/apps/mediaplayer/VideoView.h b/src/apps/mediaplayer/VideoView.h index cdab34876c..fc7222ec44 100644 --- a/src/apps/mediaplayer/VideoView.h +++ b/src/apps/mediaplayer/VideoView.h @@ -56,6 +56,7 @@ public: private: void _DrawBitmap(const BBitmap* bitmap); void _AdoptGlobalSettings(); + void _SetOverlayMode(bool overlayMode); private: BRect fVideoFrame; diff --git a/src/apps/mediaplayer/interface/SubtitleBitmap.cpp b/src/apps/mediaplayer/interface/SubtitleBitmap.cpp index 380b421208..42384f09fd 100644 --- a/src/apps/mediaplayer/interface/SubtitleBitmap.cpp +++ b/src/apps/mediaplayer/interface/SubtitleBitmap.cpp @@ -18,7 +18,9 @@ SubtitleBitmap::SubtitleBitmap() : fBitmap(NULL), fTextView(new BTextView("offscreen text")), - fShadowTextView(new BTextView("offscreen text shadow")) + fShadowTextView(new BTextView("offscreen text shadow")), + fUseSoftShadow(true), + fOverlayMode(false) { fTextView->SetStylable(true); fTextView->MakeEditable(false); @@ -60,6 +62,19 @@ SubtitleBitmap::SetVideoBounds(BRect bounds) fVideoBounds = bounds; + fUseSoftShadow = true; + _GenerateBitmap(); +} + + +void +SubtitleBitmap::SetOverlayMode(bool overlayMode) +{ + if (overlayMode == fOverlayMode) + return; + + fOverlayMode = overlayMode; + _GenerateBitmap(); } @@ -81,13 +96,15 @@ SubtitleBitmap::_GenerateBitmap() BRect bounds; float outlineRadius; - _InsertText(bounds, outlineRadius); + _InsertText(bounds, outlineRadius, fOverlayMode); + + bigtime_t startTime = 0; + if (!fOverlayMode && fUseSoftShadow) + startTime = system_time(); fBitmap = new BBitmap(bounds, B_BITMAP_ACCEPTS_VIEWS, B_RGBA32); memset(fBitmap->Bits(), 0, fBitmap->BitsLength()); - StackBlurFilter filter; - if (fBitmap->Lock()) { fBitmap->AddChild(fShadowTextView); fShadowTextView->ResizeTo(bounds.Width(), bounds.Height()); @@ -100,14 +117,20 @@ SubtitleBitmap::_GenerateBitmap() fShadowTextView->Draw(bounds); fShadowTextView->PopState(); - fShadowTextView->Sync(); - fShadowTextView->RemoveSelf(); + if (!fOverlayMode && fUseSoftShadow) { + fShadowTextView->Sync(); + StackBlurFilter filter; + filter.Filter(fBitmap, outlineRadius * 2); + } - filter.Filter(fBitmap, outlineRadius * 2); + fShadowTextView->RemoveSelf(); fBitmap->AddChild(fTextView); fTextView->ResizeTo(bounds.Width(), bounds.Height()); - fTextView->MoveTo(-outlineRadius / 2, -outlineRadius / 2); + if (!fOverlayMode && fUseSoftShadow) + fTextView->MoveTo(-outlineRadius / 2, -outlineRadius / 2); + else + fTextView->MoveTo(0, 0); fTextView->SetViewColor(0, 0, 0, 0); fTextView->SetDrawingMode(B_OP_ALPHA); @@ -122,6 +145,9 @@ SubtitleBitmap::_GenerateBitmap() fBitmap->Unlock(); } + + if (!fOverlayMode && fUseSoftShadow && system_time() - startTime > 10000) + fUseSoftShadow = false; } @@ -283,7 +309,8 @@ parse_text(const BString& string, BTextView* textView, const BFont& font, void -SubtitleBitmap::_InsertText(BRect& textRect, float& outlineRadius) +SubtitleBitmap::_InsertText(BRect& textRect, float& outlineRadius, + bool overlayMode) { BFont font(be_plain_font); float fontSize = ceilf((fVideoBounds.Width() * 0.9) / 36); @@ -312,6 +339,7 @@ SubtitleBitmap::_InsertText(BRect& textRect, float& outlineRadius) parse_text(fText, fTextView, font, color, true); font.SetFalseBoldWidth(outlineRadius); + fShadowTextView->ForceFontAliasing(overlayMode); fShadowTextView->SetText(NULL); fShadowTextView->SetFontAndColor(&font, B_FONT_ALL, &shadow); diff --git a/src/apps/mediaplayer/interface/SubtitleBitmap.h b/src/apps/mediaplayer/interface/SubtitleBitmap.h index 359dc0eefd..12645e3609 100644 --- a/src/apps/mediaplayer/interface/SubtitleBitmap.h +++ b/src/apps/mediaplayer/interface/SubtitleBitmap.h @@ -21,13 +21,14 @@ public: void SetText(const char* text); void SetVideoBounds(BRect bounds); + void SetOverlayMode(bool overlayMode); const BBitmap* Bitmap() const; private: void _GenerateBitmap(); void _InsertText(BRect& bounds, - float& outlineRadius); + float& outlineRadius, bool overlayMode); private: BBitmap* fBitmap; @@ -36,6 +37,8 @@ private: BString fText; BRect fVideoBounds; + bool fUseSoftShadow; + bool fOverlayMode; };