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. 4 5 #include "media/blink/video_frame_compositor.h" 6 7 #include "media/base/video_frame.h" 8 9 namespace media { 10 IsOpaque(const scoped_refptr<VideoFrame> & frame)11static 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::YV16: 17 case VideoFrame::I420: 18 case VideoFrame::YV24: 19 case VideoFrame::NV12: 20 return true; 21 22 case VideoFrame::YV12A: 23 #if defined(VIDEO_HOLE) 24 case VideoFrame::HOLE: 25 #endif // defined(VIDEO_HOLE) 26 case VideoFrame::NATIVE_TEXTURE: 27 break; 28 } 29 return false; 30 } 31 VideoFrameCompositor(const base::Callback<void (gfx::Size)> & natural_size_changed_cb,const base::Callback<void (bool)> & opacity_changed_cb)32VideoFrameCompositor::VideoFrameCompositor( 33 const base::Callback<void(gfx::Size)>& natural_size_changed_cb, 34 const base::Callback<void(bool)>& opacity_changed_cb) 35 : natural_size_changed_cb_(natural_size_changed_cb), 36 opacity_changed_cb_(opacity_changed_cb), 37 client_(NULL) { 38 } 39 ~VideoFrameCompositor()40VideoFrameCompositor::~VideoFrameCompositor() { 41 if (client_) 42 client_->StopUsingProvider(); 43 } 44 SetVideoFrameProviderClient(cc::VideoFrameProvider::Client * client)45void VideoFrameCompositor::SetVideoFrameProviderClient( 46 cc::VideoFrameProvider::Client* client) { 47 if (client_) 48 client_->StopUsingProvider(); 49 client_ = client; 50 } 51 GetCurrentFrame()52scoped_refptr<VideoFrame> VideoFrameCompositor::GetCurrentFrame() { 53 return current_frame_; 54 } 55 PutCurrentFrame(const scoped_refptr<VideoFrame> & frame)56void VideoFrameCompositor::PutCurrentFrame( 57 const scoped_refptr<VideoFrame>& frame) { 58 } 59 UpdateCurrentFrame(const scoped_refptr<VideoFrame> & frame)60void VideoFrameCompositor::UpdateCurrentFrame( 61 const scoped_refptr<VideoFrame>& frame) { 62 if (current_frame_.get() && 63 current_frame_->natural_size() != frame->natural_size()) { 64 natural_size_changed_cb_.Run(frame->natural_size()); 65 } 66 67 if (!current_frame_.get() || IsOpaque(current_frame_) != IsOpaque(frame)) { 68 opacity_changed_cb_.Run(IsOpaque(frame)); 69 } 70 71 current_frame_ = frame; 72 73 if (client_) 74 client_->DidReceiveFrame(); 75 } 76 77 } // namespace media 78