* 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
This commit is contained in:
Stephan Aßmus
2010-09-28 10:57:54 +00:00
parent 7fa49587bc
commit 01e0d3278a
4 changed files with 56 additions and 15 deletions
+14 -5
View File
@@ -157,7 +157,7 @@ VideoView::SetBitmap(const BBitmap* bitmap)
FillRect(fVideoFrame, B_SOLID_LOW); FillRect(fVideoFrame, B_SOLID_LOW);
Sync(); Sync();
// use overlay from here on // use overlay from here on
fOverlayMode = true; _SetOverlayMode(true);
// update restrictions // update restrictions
overlay_restrictions restrictions; overlay_restrictions restrictions;
@@ -180,7 +180,7 @@ VideoView::SetBitmap(const BBitmap* bitmap)
} }
} else if (fOverlayMode } else if (fOverlayMode
&& (bitmap->Flags() & B_BITMAP_WILL_OVERLAY) == 0) { && (bitmap->Flags() & B_BITMAP_WILL_OVERLAY) == 0) {
fOverlayMode = false; _SetOverlayMode(false);
ClearViewOverlay(); ClearViewOverlay();
SetViewColor(B_TRANSPARENT_COLOR); SetViewColor(B_TRANSPARENT_COLOR);
} }
@@ -255,7 +255,7 @@ VideoView::DisableOverlay()
ClearViewOverlay(); ClearViewOverlay();
snooze(20000); snooze(20000);
Sync(); Sync();
fOverlayMode = false; _SetOverlayMode(false);
} }
@@ -315,7 +315,7 @@ VideoView::_DrawBitmap(const BBitmap* bitmap)
{ {
SetDrawingMode(B_OP_COPY); SetDrawingMode(B_OP_COPY);
uint32 options = fUseBilinearScaling ? B_FILTER_BITMAP_BILINEAR : 0; uint32 options = fUseBilinearScaling ? B_FILTER_BITMAP_BILINEAR : 0;
DrawBitmap(bitmap, bitmap->Bounds(), fVideoFrame, options); DrawBitmapAsync(bitmap, bitmap->Bounds(), fVideoFrame, options);
if (fHasSubtitle) { if (fHasSubtitle) {
SetDrawingMode(B_OP_ALPHA); SetDrawingMode(B_OP_ALPHA);
@@ -326,7 +326,7 @@ VideoView::_DrawBitmap(const BBitmap* bitmap)
offset.x = (fVideoFrame.left + fVideoFrame.right offset.x = (fVideoFrame.left + fVideoFrame.right
- subtitleBitmap->Bounds().Width()) / 2; - subtitleBitmap->Bounds().Width()) / 2;
offset.y = fVideoFrame.bottom - subtitleBitmap->Bounds().Height(); offset.y = fVideoFrame.bottom - subtitleBitmap->Bounds().Height();
DrawBitmap(subtitleBitmap, offset); DrawBitmapAsync(subtitleBitmap, offset);
} }
} }
@@ -344,3 +344,12 @@ VideoView::_AdoptGlobalSettings()
Invalidate(); Invalidate();
} }
void
VideoView::_SetOverlayMode(bool overlayMode)
{
fOverlayMode = overlayMode;
fSubtitleBitmap->SetOverlayMode(overlayMode);
}
+1
View File
@@ -56,6 +56,7 @@ public:
private: private:
void _DrawBitmap(const BBitmap* bitmap); void _DrawBitmap(const BBitmap* bitmap);
void _AdoptGlobalSettings(); void _AdoptGlobalSettings();
void _SetOverlayMode(bool overlayMode);
private: private:
BRect fVideoFrame; BRect fVideoFrame;
@@ -18,7 +18,9 @@ SubtitleBitmap::SubtitleBitmap()
: :
fBitmap(NULL), fBitmap(NULL),
fTextView(new BTextView("offscreen text")), 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->SetStylable(true);
fTextView->MakeEditable(false); fTextView->MakeEditable(false);
@@ -60,6 +62,19 @@ SubtitleBitmap::SetVideoBounds(BRect bounds)
fVideoBounds = bounds; fVideoBounds = bounds;
fUseSoftShadow = true;
_GenerateBitmap();
}
void
SubtitleBitmap::SetOverlayMode(bool overlayMode)
{
if (overlayMode == fOverlayMode)
return;
fOverlayMode = overlayMode;
_GenerateBitmap(); _GenerateBitmap();
} }
@@ -81,13 +96,15 @@ SubtitleBitmap::_GenerateBitmap()
BRect bounds; BRect bounds;
float outlineRadius; 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); fBitmap = new BBitmap(bounds, B_BITMAP_ACCEPTS_VIEWS, B_RGBA32);
memset(fBitmap->Bits(), 0, fBitmap->BitsLength()); memset(fBitmap->Bits(), 0, fBitmap->BitsLength());
StackBlurFilter filter;
if (fBitmap->Lock()) { if (fBitmap->Lock()) {
fBitmap->AddChild(fShadowTextView); fBitmap->AddChild(fShadowTextView);
fShadowTextView->ResizeTo(bounds.Width(), bounds.Height()); fShadowTextView->ResizeTo(bounds.Width(), bounds.Height());
@@ -100,14 +117,20 @@ SubtitleBitmap::_GenerateBitmap()
fShadowTextView->Draw(bounds); fShadowTextView->Draw(bounds);
fShadowTextView->PopState(); fShadowTextView->PopState();
fShadowTextView->Sync(); if (!fOverlayMode && fUseSoftShadow) {
fShadowTextView->RemoveSelf(); fShadowTextView->Sync();
StackBlurFilter filter;
filter.Filter(fBitmap, outlineRadius * 2);
}
filter.Filter(fBitmap, outlineRadius * 2); fShadowTextView->RemoveSelf();
fBitmap->AddChild(fTextView); fBitmap->AddChild(fTextView);
fTextView->ResizeTo(bounds.Width(), bounds.Height()); 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->SetViewColor(0, 0, 0, 0);
fTextView->SetDrawingMode(B_OP_ALPHA); fTextView->SetDrawingMode(B_OP_ALPHA);
@@ -122,6 +145,9 @@ SubtitleBitmap::_GenerateBitmap()
fBitmap->Unlock(); 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 void
SubtitleBitmap::_InsertText(BRect& textRect, float& outlineRadius) SubtitleBitmap::_InsertText(BRect& textRect, float& outlineRadius,
bool overlayMode)
{ {
BFont font(be_plain_font); BFont font(be_plain_font);
float fontSize = ceilf((fVideoBounds.Width() * 0.9) / 36); 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); parse_text(fText, fTextView, font, color, true);
font.SetFalseBoldWidth(outlineRadius); font.SetFalseBoldWidth(outlineRadius);
fShadowTextView->ForceFontAliasing(overlayMode);
fShadowTextView->SetText(NULL); fShadowTextView->SetText(NULL);
fShadowTextView->SetFontAndColor(&font, B_FONT_ALL, &shadow); fShadowTextView->SetFontAndColor(&font, B_FONT_ALL, &shadow);
@@ -21,13 +21,14 @@ public:
void SetText(const char* text); void SetText(const char* text);
void SetVideoBounds(BRect bounds); void SetVideoBounds(BRect bounds);
void SetOverlayMode(bool overlayMode);
const BBitmap* Bitmap() const; const BBitmap* Bitmap() const;
private: private:
void _GenerateBitmap(); void _GenerateBitmap();
void _InsertText(BRect& bounds, void _InsertText(BRect& bounds,
float& outlineRadius); float& outlineRadius, bool overlayMode);
private: private:
BBitmap* fBitmap; BBitmap* fBitmap;
@@ -36,6 +37,8 @@ private:
BString fText; BString fText;
BRect fVideoBounds; BRect fVideoBounds;
bool fUseSoftShadow;
bool fOverlayMode;
}; };