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

Unified Diff: media/base/video_frame.cc

Issue 1737253002: Handle Alpha channel in Canvas capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mcasas@ comments. Created 4 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
« no previous file with comments | « media/base/video_frame.h ('k') | media/base/video_frame_pool.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/video_frame.cc
diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc
index 4dedd82d10b20633d091bd24aebd31b203c32719..0b23ef1529b5e9e73503cec13b5b3274e0b6db32 100644
--- a/media/base/video_frame.cc
+++ b/media/base/video_frame.cc
@@ -200,6 +200,25 @@ static int BytesPerElement(VideoPixelFormat format, size_t plane) {
return 0;
}
+// Checks if |source_format| can be wrapped into a |target_format| frame.
+static bool AreValidPixelFormatsForWrap(VideoPixelFormat source_format,
+ VideoPixelFormat target_format) {
+ if (source_format == target_format)
+ return true;
+
+ switch (source_format) {
+ case PIXEL_FORMAT_YV12A:
+ switch (target_format) {
+ case PIXEL_FORMAT_I420:
+ return true;
+ default:
+ return false;
+ }
+ default:
+ return false;
+ }
+}
+
// static
bool VideoFrame::IsValidConfig(VideoPixelFormat format,
StorageType storage_type,
@@ -495,33 +514,41 @@ scoped_refptr<VideoFrame> VideoFrame::WrapCVPixelBuffer(
// static
scoped_refptr<VideoFrame> VideoFrame::WrapVideoFrame(
- const scoped_refptr<VideoFrame>& frame,
- const gfx::Rect& visible_rect,
- const gfx::Size& natural_size) {
+ const scoped_refptr<VideoFrame>& frame,
+ VideoPixelFormat format,
+ const gfx::Rect& visible_rect,
+ const gfx::Size& natural_size) {
// Frames with textures need mailbox info propagated, and there's no support
// for that here yet, see http://crbug/362521.
CHECK(!frame->HasTextures());
-
DCHECK(frame->visible_rect().Contains(visible_rect));
- if (!IsValidConfig(frame->format(), frame->storage_type(),
- frame->coded_size(), visible_rect, natural_size)) {
+ if (!AreValidPixelFormatsForWrap(frame->format(), format)) {
+ LOG(DFATAL) << __FUNCTION__ << " Invalid format conversions."
mcasas 2016/03/02 22:01:10 micro-nit: s/conversions./conversion: /
emircan 2016/03/03 22:05:58 Done.
+ << VideoPixelFormatToString(frame->format()) << " to "
+ << VideoPixelFormatToString(format);
+ return nullptr;
+ }
+
+ if (!IsValidConfig(format, frame->storage_type(), frame->coded_size(),
+ visible_rect, natural_size)) {
LOG(DFATAL) << __FUNCTION__ << " Invalid config."
- << ConfigToString(frame->format(), frame->storage_type(),
+ << ConfigToString(format, frame->storage_type(),
frame->coded_size(), visible_rect,
natural_size);
return nullptr;
}
- scoped_refptr<VideoFrame> wrapping_frame(new VideoFrame(
- frame->format(), frame->storage_type(), frame->coded_size(), visible_rect,
- natural_size, frame->timestamp()));
+ scoped_refptr<VideoFrame> wrapping_frame(
+ new VideoFrame(format, frame->storage_type(), frame->coded_size(),
+ visible_rect, natural_size, frame->timestamp()));
+ // Investigate if we can copy the whole metadata, see http://crbug/591138.
if (frame->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)) {
wrapping_frame->metadata()->SetBoolean(VideoFrameMetadata::END_OF_STREAM,
- true);
+ true);
}
- for (size_t i = 0; i < NumPlanes(frame->format()); ++i) {
+ for (size_t i = 0; i < NumPlanes(format); ++i) {
wrapping_frame->strides_[i] = frame->stride(i);
wrapping_frame->data_[i] = frame->data(i);
}
« no previous file with comments | « media/base/video_frame.h ('k') | media/base/video_frame_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698