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

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: bbudge@ nit. Created 4 years, 9 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 ea7370b1729d0f2c306192c33b7a625ffc783efe..b4a8392ff8c848dc9edf9ba0ddd7ce181ad0c7b5 100644
--- a/media/base/video_frame.cc
+++ b/media/base/video_frame.cc
@@ -83,6 +83,18 @@ static bool IsStorageTypeMappable(VideoFrame::StorageType storage_type) {
storage_type == VideoFrame::STORAGE_MOJO_SHARED_BUFFER);
}
+// 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;
+
+ // It is possible to add other planar to planar format conversions here if the
+ // use case is there.
+ return source_format == PIXEL_FORMAT_YV12A &&
+ target_format == PIXEL_FORMAT_I420;
+}
+
// static
bool VideoFrame::IsValidConfig(VideoPixelFormat format,
StorageType storage_type,
@@ -378,32 +390,39 @@ 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 conversion."
+ << 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()));
// Copy all metadata to the wrapped frame.
wrapping_frame->metadata()->MergeMetadataFrom(frame->metadata());
- 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