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"
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
:
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
:
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
),
42 VideoFrameCompositor::~VideoFrameCompositor() {
44 client_
->StopUsingProvider();
47 void VideoFrameCompositor::SetVideoFrameProviderClient(
48 cc::VideoFrameProvider::Client
* client
) {
50 client_
->StopUsingProvider();
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
;
76 client_
->DidReceiveFrame();