Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / media / blink / video_frame_compositor.cc
blob447b6b195bff674d3cb5ca2fd679ba0d59078d46
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/blink/video_frame_compositor.h"
7 #include "media/base/video_frame.h"
9 namespace media {
11 static bool IsOpaque(const scoped_refptr<VideoFrame>& frame) {
12 switch (frame->format()) {
13 case VideoFrame::UNKNOWN:
14 case VideoFrame::YV12:
15 case VideoFrame::YV12J:
16 case VideoFrame::YV12HD:
17 case VideoFrame::YV16:
18 case VideoFrame::I420:
19 case VideoFrame::YV24:
20 case VideoFrame::NV12:
21 return true;
23 case VideoFrame::YV12A:
24 #if defined(VIDEO_HOLE)
25 case VideoFrame::HOLE:
26 #endif // defined(VIDEO_HOLE)
27 case VideoFrame::NATIVE_TEXTURE:
28 case VideoFrame::ARGB:
29 break;
31 return false;
34 VideoFrameCompositor::VideoFrameCompositor(
35 const base::Callback<void(gfx::Size)>& natural_size_changed_cb,
36 const base::Callback<void(bool)>& opacity_changed_cb)
37 : natural_size_changed_cb_(natural_size_changed_cb),
38 opacity_changed_cb_(opacity_changed_cb),
39 client_(NULL) {
42 VideoFrameCompositor::~VideoFrameCompositor() {
43 if (client_)
44 client_->StopUsingProvider();
47 void VideoFrameCompositor::SetVideoFrameProviderClient(
48 cc::VideoFrameProvider::Client* client) {
49 if (client_)
50 client_->StopUsingProvider();
51 client_ = client;
54 scoped_refptr<VideoFrame> VideoFrameCompositor::GetCurrentFrame() {
55 return current_frame_;
58 void VideoFrameCompositor::PutCurrentFrame(
59 const scoped_refptr<VideoFrame>& frame) {
62 void VideoFrameCompositor::UpdateCurrentFrame(
63 const scoped_refptr<VideoFrame>& frame) {
64 if (current_frame_.get() &&
65 current_frame_->natural_size() != frame->natural_size()) {
66 natural_size_changed_cb_.Run(frame->natural_size());
69 if (!current_frame_.get() || IsOpaque(current_frame_) != IsOpaque(frame)) {
70 opacity_changed_cb_.Run(IsOpaque(frame));
73 current_frame_ = frame;
75 if (client_)
76 client_->DidReceiveFrame();
79 } // namespace media