Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(776)

Unified Diff: webkit/glue/media/video_renderer_impl.cc

Issue 5878007: Fix black video frames when seeking (which also fixes flashing poster issue). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/glue/media/video_renderer_impl.cc
diff --git a/webkit/glue/media/video_renderer_impl.cc b/webkit/glue/media/video_renderer_impl.cc
index 3bbd626f7ef61961101cf6688ed2ad76fc585502..9f5367fe911e2a45234c49949df75c80c7c5154f 100644
--- a/webkit/glue/media/video_renderer_impl.cc
+++ b/webkit/glue/media/video_renderer_impl.cc
@@ -49,10 +49,36 @@ void VideoRendererImpl::SetRect(const gfx::Rect& rect) {
}
// This method is always called on the renderer's thread.
+bool VideoRendererImpl::GetCurrentBitmap(SkBitmap* bitmap) {
+ scoped_refptr<media::VideoFrame> video_frame;
+ GetCurrentFrame(&video_frame);
+
+ if (!video_frame) {
+ return false;
+ } else {
scherkus (not reviewing) 2010/12/17 18:50:40 nit: de-else/indent this block due to early return
+ if (bitmap->empty() ||
+ bitmap->config() != SkBitmap::kARGB_8888_Config ||
+ bitmap->width() != width() || bitmap->height() != height()) {
+ bitmap->reset();
+ bitmap->setConfig(SkBitmap::kARGB_8888_Config, width(), height());
+ bitmap->allocPixels(NULL, NULL);
+ bitmap->eraseRGB(0xff, 0x00, 0x00);
+ }
+
+ SlowPaintToBitmap(video_frame, bitmap);
+ }
+
+ PutCurrentFrame(video_frame);
+
+ return true;
+}
+
+// This method is always called on the renderer's thread.
void VideoRendererImpl::Paint(skia::PlatformCanvas* canvas,
const gfx::Rect& dest_rect) {
scoped_refptr<media::VideoFrame> video_frame;
GetCurrentFrame(&video_frame);
+
if (!video_frame) {
SkPaint paint;
paint.setColor(SK_ColorBLACK);
@@ -66,7 +92,8 @@ void VideoRendererImpl::Paint(skia::PlatformCanvas* canvas,
if (CanFastPaint(canvas, dest_rect)) {
FastPaint(video_frame, canvas, dest_rect);
} else {
- SlowPaint(video_frame, canvas, dest_rect);
+ SlowPaintToBitmap(video_frame, &bitmap_);
+ CopyBitmapToCanvas(bitmap_, canvas, dest_rect);
}
// Presentation timestamp logging is primarily used to measure performance
@@ -151,9 +178,8 @@ bool VideoRendererImpl::CanFastPaint(skia::PlatformCanvas* canvas,
return false;
}
-void VideoRendererImpl::SlowPaint(media::VideoFrame* video_frame,
- skia::PlatformCanvas* canvas,
- const gfx::Rect& dest_rect) {
+void VideoRendererImpl::SlowPaintToBitmap(media::VideoFrame* video_frame,
+ SkBitmap* bitmap) {
// 1. Convert YUV frame to RGB.
scherkus (not reviewing) 2010/12/17 18:50:40 nit: remove the 1. (or the comment itself, your ca
base::TimeDelta timestamp = video_frame->GetTimestamp();
if (video_frame != last_converted_frame_ ||
@@ -165,37 +191,41 @@ void VideoRendererImpl::SlowPaint(media::VideoFrame* video_frame,
DCHECK(video_frame->stride(media::VideoFrame::kUPlane) ==
video_frame->stride(media::VideoFrame::kVPlane));
DCHECK(video_frame->planes() == media::VideoFrame::kNumYUVPlanes);
- bitmap_.lockPixels();
+ bitmap->lockPixels();
media::YUVType yuv_type =
(video_frame->format() == media::VideoFrame::YV12) ?
media::YV12 : media::YV16;
media::ConvertYUVToRGB32(video_frame->data(media::VideoFrame::kYPlane),
video_frame->data(media::VideoFrame::kUPlane),
video_frame->data(media::VideoFrame::kVPlane),
- static_cast<uint8*>(bitmap_.getPixels()),
+ static_cast<uint8*>(bitmap->getPixels()),
video_frame->width(),
video_frame->height(),
video_frame->stride(media::VideoFrame::kYPlane),
video_frame->stride(media::VideoFrame::kUPlane),
- bitmap_.rowBytes(),
+ bitmap->rowBytes(),
yuv_type);
- bitmap_.unlockPixels();
+ bitmap->unlockPixels();
}
+}
+void VideoRendererImpl::CopyBitmapToCanvas(const SkBitmap& bitmap,
+ skia::PlatformCanvas* canvas,
+ const gfx::Rect& dest_rect) {
// 2. Paint the bitmap to canvas.
scherkus (not reviewing) 2010/12/17 18:50:40 ditto
SkMatrix matrix;
matrix.setTranslate(static_cast<SkScalar>(dest_rect.x()),
static_cast<SkScalar>(dest_rect.y()));
- if (dest_rect.width() != video_size_.width() ||
- dest_rect.height() != video_size_.height()) {
+ if (dest_rect.width() != bitmap_.width() ||
+ dest_rect.height() != bitmap_.height()) {
matrix.preScale(SkIntToScalar(dest_rect.width()) /
- SkIntToScalar(video_size_.width()),
+ SkIntToScalar(bitmap_.width()),
SkIntToScalar(dest_rect.height()) /
- SkIntToScalar(video_size_.height()));
+ SkIntToScalar(bitmap_.height()));
}
SkPaint paint;
paint.setFlags(SkPaint::kFilterBitmap_Flag);
- canvas->drawBitmapMatrix(bitmap_, matrix, &paint);
+ canvas->drawBitmapMatrix(bitmap, matrix, &paint);
}
void VideoRendererImpl::FastPaint(media::VideoFrame* video_frame,
scherkus (not reviewing) 2010/12/17 18:50:40 nit: maybe rename this to FastPaintToCanvas ?

Powered by Google App Engine
This is Rietveld 408576698