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

Unified Diff: media/filters/skcanvas_video_renderer.cc

Issue 12157002: Adding YUVA support for enabling Alpha Playback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moving VP8 Alpha Playback behind its own flag Created 7 years, 10 months 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: media/filters/skcanvas_video_renderer.cc
diff --git a/media/filters/skcanvas_video_renderer.cc b/media/filters/skcanvas_video_renderer.cc
index 53b5b2d57081aa69d500a0ba1043c285f445a316..a38fea698c656cc9a8b0964f737df300199fd3f0 100644
--- a/media/filters/skcanvas_video_renderer.cc
+++ b/media/filters/skcanvas_video_renderer.cc
@@ -21,6 +21,17 @@ static bool IsEitherYV12OrYV16OrNative(media::VideoFrame::Format format) {
format == media::VideoFrame::NATIVE_TEXTURE;
}
+static bool IsEitherYV12OrYV12AOrYV16(media::VideoFrame::Format format) {
+ return IsEitherYV12OrYV16(format) ||
+ format == media::VideoFrame::YV12A;
+}
+
+static bool IsEitherYV12OrYV12AOrYV16OrNative(
+ media::VideoFrame::Format format) {
fgalligan1 2013/02/12 01:20:58 nit: 4 space indent.
vigneshv 2013/02/14 19:06:14 Done.
+ return IsEitherYV12OrYV16OrNative(format) ||
+ format == media::VideoFrame::YV12A;
+}
+
// CanFastPaint is a helper method to determine the conditions for fast
// painting. The conditions are:
// 1. No skew in canvas matrix.
@@ -68,9 +79,12 @@ static void FastPaint(
video_frame->stride(media::VideoFrame::kVPlane));
const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(true);
- media::YUVType yuv_type = media::YV16;
+ media::YUVType yuv_type = video_frame->format() == media::VideoFrame::YV12 ||
+ video_frame->format() == media::VideoFrame::YV12A
fgalligan1 2013/02/12 01:20:58 Line up.
vigneshv 2013/02/14 19:06:14 Done.
+ ? media::YV12 : media::YV16;
fgalligan1 2013/02/12 01:20:58 ? should be on the previous line. Then the rest of
vigneshv 2013/02/14 19:06:14 Done.
int y_shift = 0;
- if (video_frame->format() == media::VideoFrame::YV12) {
+ if (video_frame->format() == media::VideoFrame::YV12 ||
+ video_frame->format() == media::VideoFrame::YV12A) {
fgalligan1 2013/02/12 01:20:58 Line up.
vigneshv 2013/02/14 19:06:14 Done.
yuv_type = media::YV12;
y_shift = 1;
}
@@ -170,11 +184,11 @@ static void FastPaint(
static void ConvertVideoFrameToBitmap(
const scoped_refptr<media::VideoFrame>& video_frame,
SkBitmap* bitmap) {
- DCHECK(IsEitherYV12OrYV16OrNative(video_frame->format()))
- << video_frame->format();
- if (IsEitherYV12OrYV16(video_frame->format())) {
+ DCHECK(IsEitherYV12OrYV12AOrYV16OrNative(video_frame->format()))
+ << video_frame->format();
fgalligan1 2013/02/12 01:20:58 nit: 4 space indent.
vigneshv 2013/02/14 19:06:14 Done.
+ if (IsEitherYV12OrYV12AOrYV16(video_frame->format())) {
DCHECK_EQ(video_frame->stride(media::VideoFrame::kUPlane),
- video_frame->stride(media::VideoFrame::kVPlane));
+ video_frame->stride(media::VideoFrame::kVPlane));
fgalligan1 2013/02/12 01:20:58 Line up.
vigneshv 2013/02/14 19:06:14 Done.
}
// Check if |bitmap| needs to be (re)allocated.
@@ -189,10 +203,17 @@ static void ConvertVideoFrameToBitmap(
}
bitmap->lockPixels();
- if (IsEitherYV12OrYV16(video_frame->format())) {
- media::YUVType yuv_type = media::YV16;
+
+ media::YUVType yuv_type;
+ uint8* frame_clip_y;
+ uint8* frame_clip_u;
+ uint8* frame_clip_v;
+ if(IsEitherYV12OrYV12AOrYV16(video_frame->format())) {
+ yuv_type = media::YV16;
+
int y_shift = 0;
- if (video_frame->format() == media::VideoFrame::YV12) {
+ if (video_frame->format() == media::VideoFrame::YV12 ||
+ video_frame->format() == media::VideoFrame::YV12A) {
fgalligan1 2013/02/12 01:20:58 Line up.
vigneshv 2013/02/14 19:06:14 Done.
yuv_type = media::YV12;
y_shift = 1;
}
@@ -208,26 +229,45 @@ static void ConvertVideoFrameToBitmap(
size_t uv_offset = (video_frame->stride(media::VideoFrame::kUPlane) *
(video_frame->visible_rect().y() >> y_shift)) +
(video_frame->visible_rect().x() >> 1);
- uint8* frame_clip_y =
- video_frame->data(media::VideoFrame::kYPlane) + y_offset;
- uint8* frame_clip_u =
- video_frame->data(media::VideoFrame::kUPlane) + uv_offset;
- uint8* frame_clip_v =
- video_frame->data(media::VideoFrame::kVPlane) + uv_offset;
-
- media::ConvertYUVToRGB32(frame_clip_y,
- frame_clip_u,
- frame_clip_v,
- static_cast<uint8*>(bitmap->getPixels()),
- video_frame->visible_rect().width(),
- video_frame->visible_rect().height(),
- video_frame->stride(media::VideoFrame::kYPlane),
- video_frame->stride(media::VideoFrame::kUPlane),
- bitmap->rowBytes(),
- yuv_type);
- } else {
- DCHECK_EQ(video_frame->format(), media::VideoFrame::NATIVE_TEXTURE);
- video_frame->ReadPixelsFromNativeTexture(bitmap->getPixels());
+ frame_clip_y = video_frame->data(media::VideoFrame::kYPlane) + y_offset;
+ frame_clip_u = video_frame->data(media::VideoFrame::kUPlane) + uv_offset;
+ frame_clip_v = video_frame->data(media::VideoFrame::kVPlane) + uv_offset;
+ }
+ switch(video_frame->format()) {
+ case media::VideoFrame::YV12:
+ case media::VideoFrame::YV16:
+ media::ConvertYUVToRGB32(frame_clip_y,
+ frame_clip_u,
+ frame_clip_v,
+ static_cast<uint8*>(bitmap->getPixels()),
+ video_frame->visible_rect().width(),
+ video_frame->visible_rect().height(),
+ video_frame->stride(media::VideoFrame::kYPlane),
+ video_frame->stride(media::VideoFrame::kUPlane),
+ bitmap->rowBytes(),
+ yuv_type);
+ break;
+ case media::VideoFrame::YV12A:
+ media::ConvertYUVAToARGB(frame_clip_y,
+ frame_clip_u,
+ frame_clip_v,
+ video_frame->data(media::VideoFrame::kAPlane),
+ static_cast<uint8*>(bitmap->getPixels()),
+ video_frame->visible_rect().width(),
+ video_frame->visible_rect().height(),
+ video_frame->stride(media::VideoFrame::kYPlane),
+ video_frame->stride(media::VideoFrame::kUPlane),
+ video_frame->stride(media::VideoFrame::kAPlane),
+ bitmap->rowBytes(),
+ media::YV12);
+ break;
+ case media::VideoFrame::NATIVE_TEXTURE:
+ DCHECK_EQ(video_frame->format(), media::VideoFrame::NATIVE_TEXTURE);
+ video_frame->ReadPixelsFromNativeTexture(bitmap->getPixels());
+ break;
+ default:
+ NOTREACHED();
+ break;
}
bitmap->notifyPixelsChanged();
bitmap->unlockPixels();
@@ -255,7 +295,8 @@ void SkCanvasVideoRenderer::Paint(media::VideoFrame* video_frame,
// Paint black rectangle if there isn't a frame available or the
// frame has an unexpected format.
- if (!video_frame || !IsEitherYV12OrYV16OrNative(video_frame->format())) {
+ if (!video_frame ||
+ !IsEitherYV12OrYV12AOrYV16OrNative(video_frame->format())) {
fgalligan1 2013/02/12 01:20:58 Line up.
vigneshv 2013/02/14 19:06:14 Done.
canvas->drawRect(dest, paint);
return;
}

Powered by Google App Engine
This is Rietveld 408576698