| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/message_loop/message_loop.h" | |
| 7 #include "cc/layers/video_frame_provider.h" | 6 #include "cc/layers/video_frame_provider.h" |
| 8 #include "media/base/video_frame.h" | 7 #include "media/base/video_frame.h" |
| 9 #include "media/blink/video_frame_compositor.h" | 8 #include "media/blink/video_frame_compositor.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 10 |
| 12 namespace media { | 11 namespace media { |
| 13 | 12 |
| 14 class VideoFrameCompositorTest : public testing::Test, | 13 class VideoFrameCompositorTest : public testing::Test, |
| 15 public cc::VideoFrameProvider::Client { | 14 public cc::VideoFrameProvider::Client { |
| 16 public: | 15 public: |
| 17 VideoFrameCompositorTest() | 16 VideoFrameCompositorTest() |
| 18 : compositor_(new VideoFrameCompositor( | 17 : compositor_(new VideoFrameCompositor( |
| 19 message_loop.task_runner(), | |
| 20 base::Bind(&VideoFrameCompositorTest::NaturalSizeChanged, | 18 base::Bind(&VideoFrameCompositorTest::NaturalSizeChanged, |
| 21 base::Unretained(this)), | 19 base::Unretained(this)), |
| 22 base::Bind(&VideoFrameCompositorTest::OpacityChanged, | 20 base::Bind(&VideoFrameCompositorTest::OpacityChanged, |
| 23 base::Unretained(this)))), | 21 base::Unretained(this)))), |
| 24 did_receive_frame_count_(0), | 22 did_receive_frame_count_(0), |
| 25 natural_size_changed_count_(0), | 23 natural_size_changed_count_(0), |
| 26 opacity_changed_count_(0), | 24 opacity_changed_count_(0), |
| 27 opaque_(false) { | 25 opaque_(false) { |
| 28 compositor_->SetVideoFrameProviderClient(this); | 26 compositor_->SetVideoFrameProviderClient(this); |
| 29 } | 27 } |
| 30 | 28 |
| 31 ~VideoFrameCompositorTest() override { | 29 ~VideoFrameCompositorTest() override { |
| 32 compositor_->SetVideoFrameProviderClient(NULL); | 30 compositor_->SetVideoFrameProviderClient(NULL); |
| 33 } | 31 } |
| 34 | 32 |
| 35 VideoFrameCompositor* compositor() { return compositor_.get(); } | 33 VideoFrameCompositor* compositor() { return compositor_.get(); } |
| 36 int did_receive_frame_count() { return did_receive_frame_count_; } | 34 int did_receive_frame_count() { return did_receive_frame_count_; } |
| 37 int natural_size_changed_count() { return natural_size_changed_count_; } | 35 int natural_size_changed_count() { return natural_size_changed_count_; } |
| 38 gfx::Size natural_size() { return natural_size_; } | 36 gfx::Size natural_size() { return natural_size_; } |
| 39 | 37 |
| 40 int opacity_changed_count() { return opacity_changed_count_; } | 38 int opacity_changed_count() { return opacity_changed_count_; } |
| 41 bool opaque() { return opaque_; } | 39 bool opaque() { return opaque_; } |
| 42 | 40 |
| 43 private: | 41 private: |
| 44 // cc::VideoFrameProvider::Client implementation. | 42 // cc::VideoFrameProvider::Client implementation. |
| 45 void StopUsingProvider() override {} | 43 void StopUsingProvider() override {} |
| 46 void StartRendering() override {}; | |
| 47 void StopRendering() override {}; | |
| 48 void DidReceiveFrame() override { | 44 void DidReceiveFrame() override { |
| 49 ++did_receive_frame_count_; | 45 ++did_receive_frame_count_; |
| 50 } | 46 } |
| 51 void DidUpdateMatrix(const float* matrix) override {} | 47 void DidUpdateMatrix(const float* matrix) override {} |
| 52 | 48 |
| 53 void NaturalSizeChanged(gfx::Size natural_size) { | 49 void NaturalSizeChanged(gfx::Size natural_size) { |
| 54 ++natural_size_changed_count_; | 50 ++natural_size_changed_count_; |
| 55 natural_size_ = natural_size; | 51 natural_size_ = natural_size; |
| 56 } | 52 } |
| 57 | 53 |
| 58 void OpacityChanged(bool opaque) { | 54 void OpacityChanged(bool opaque) { |
| 59 ++opacity_changed_count_; | 55 ++opacity_changed_count_; |
| 60 opaque_ = opaque; | 56 opaque_ = opaque; |
| 61 } | 57 } |
| 62 | 58 |
| 63 base::MessageLoop message_loop; | |
| 64 scoped_ptr<VideoFrameCompositor> compositor_; | 59 scoped_ptr<VideoFrameCompositor> compositor_; |
| 65 int did_receive_frame_count_; | 60 int did_receive_frame_count_; |
| 66 int natural_size_changed_count_; | 61 int natural_size_changed_count_; |
| 67 gfx::Size natural_size_; | 62 gfx::Size natural_size_; |
| 68 int opacity_changed_count_; | 63 int opacity_changed_count_; |
| 69 bool opaque_; | 64 bool opaque_; |
| 70 | 65 |
| 71 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositorTest); | 66 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositorTest); |
| 72 }; | 67 }; |
| 73 | 68 |
| 74 TEST_F(VideoFrameCompositorTest, InitialValues) { | 69 TEST_F(VideoFrameCompositorTest, InitialValues) { |
| 75 EXPECT_FALSE(compositor()->GetCurrentFrame().get()); | 70 EXPECT_FALSE(compositor()->GetCurrentFrame().get()); |
| 76 } | 71 } |
| 77 | 72 |
| 78 TEST_F(VideoFrameCompositorTest, PaintFrameUsingOldRenderingPath) { | 73 TEST_F(VideoFrameCompositorTest, UpdateCurrentFrame) { |
| 79 scoped_refptr<VideoFrame> expected = VideoFrame::CreateEOSFrame(); | 74 scoped_refptr<VideoFrame> expected = VideoFrame::CreateEOSFrame(); |
| 80 | 75 |
| 81 // Should notify compositor synchronously. | 76 // Should notify compositor synchronously. |
| 82 EXPECT_EQ(0, did_receive_frame_count()); | 77 EXPECT_EQ(0, did_receive_frame_count()); |
| 83 compositor()->PaintFrameUsingOldRenderingPath(expected); | 78 compositor()->UpdateCurrentFrame(expected); |
| 84 scoped_refptr<VideoFrame> actual = compositor()->GetCurrentFrame(); | 79 scoped_refptr<VideoFrame> actual = compositor()->GetCurrentFrame(); |
| 85 EXPECT_EQ(expected, actual); | 80 EXPECT_EQ(expected, actual); |
| 86 EXPECT_EQ(1, did_receive_frame_count()); | 81 EXPECT_EQ(1, did_receive_frame_count()); |
| 87 } | 82 } |
| 88 | 83 |
| 89 TEST_F(VideoFrameCompositorTest, NaturalSizeChanged) { | 84 TEST_F(VideoFrameCompositorTest, NaturalSizeChanged) { |
| 90 gfx::Size initial_size(8, 8); | 85 gfx::Size initial_size(8, 8); |
| 91 scoped_refptr<VideoFrame> initial_frame = | 86 scoped_refptr<VideoFrame> initial_frame = |
| 92 VideoFrame::CreateBlackFrame(initial_size); | 87 VideoFrame::CreateBlackFrame(initial_size); |
| 93 | 88 |
| 94 gfx::Size larger_size(16, 16); | 89 gfx::Size larger_size(16, 16); |
| 95 scoped_refptr<VideoFrame> larger_frame = | 90 scoped_refptr<VideoFrame> larger_frame = |
| 96 VideoFrame::CreateBlackFrame(larger_size); | 91 VideoFrame::CreateBlackFrame(larger_size); |
| 97 | 92 |
| 98 // Initial expectations. | 93 // Initial expectations. |
| 99 EXPECT_EQ(0, natural_size().width()); | 94 EXPECT_EQ(0, natural_size().width()); |
| 100 EXPECT_EQ(0, natural_size().height()); | 95 EXPECT_EQ(0, natural_size().height()); |
| 101 EXPECT_EQ(0, natural_size_changed_count()); | 96 EXPECT_EQ(0, natural_size_changed_count()); |
| 102 | 97 |
| 103 // Callback isn't fired for the first frame. | 98 // Callback isn't fired for the first frame. |
| 104 compositor()->PaintFrameUsingOldRenderingPath(initial_frame); | 99 compositor()->UpdateCurrentFrame(initial_frame); |
| 105 EXPECT_EQ(0, natural_size().width()); | 100 EXPECT_EQ(0, natural_size().width()); |
| 106 EXPECT_EQ(0, natural_size().height()); | 101 EXPECT_EQ(0, natural_size().height()); |
| 107 EXPECT_EQ(0, natural_size_changed_count()); | 102 EXPECT_EQ(0, natural_size_changed_count()); |
| 108 | 103 |
| 109 // Callback should be fired once. | 104 // Callback should be fired once. |
| 110 compositor()->PaintFrameUsingOldRenderingPath(larger_frame); | 105 compositor()->UpdateCurrentFrame(larger_frame); |
| 111 EXPECT_EQ(larger_size.width(), natural_size().width()); | 106 EXPECT_EQ(larger_size.width(), natural_size().width()); |
| 112 EXPECT_EQ(larger_size.height(), natural_size().height()); | 107 EXPECT_EQ(larger_size.height(), natural_size().height()); |
| 113 EXPECT_EQ(1, natural_size_changed_count()); | 108 EXPECT_EQ(1, natural_size_changed_count()); |
| 114 | 109 |
| 115 compositor()->PaintFrameUsingOldRenderingPath(larger_frame); | 110 compositor()->UpdateCurrentFrame(larger_frame); |
| 116 EXPECT_EQ(larger_size.width(), natural_size().width()); | 111 EXPECT_EQ(larger_size.width(), natural_size().width()); |
| 117 EXPECT_EQ(larger_size.height(), natural_size().height()); | 112 EXPECT_EQ(larger_size.height(), natural_size().height()); |
| 118 EXPECT_EQ(1, natural_size_changed_count()); | 113 EXPECT_EQ(1, natural_size_changed_count()); |
| 119 | 114 |
| 120 // Callback is fired once more when switching back to initial size. | 115 // Callback is fired once more when switching back to initial size. |
| 121 compositor()->PaintFrameUsingOldRenderingPath(initial_frame); | 116 compositor()->UpdateCurrentFrame(initial_frame); |
| 122 EXPECT_EQ(initial_size.width(), natural_size().width()); | 117 EXPECT_EQ(initial_size.width(), natural_size().width()); |
| 123 EXPECT_EQ(initial_size.height(), natural_size().height()); | 118 EXPECT_EQ(initial_size.height(), natural_size().height()); |
| 124 EXPECT_EQ(2, natural_size_changed_count()); | 119 EXPECT_EQ(2, natural_size_changed_count()); |
| 125 | 120 |
| 126 compositor()->PaintFrameUsingOldRenderingPath(initial_frame); | 121 compositor()->UpdateCurrentFrame(initial_frame); |
| 127 EXPECT_EQ(initial_size.width(), natural_size().width()); | 122 EXPECT_EQ(initial_size.width(), natural_size().width()); |
| 128 EXPECT_EQ(initial_size, natural_size()); | 123 EXPECT_EQ(initial_size, natural_size()); |
| 129 EXPECT_EQ(2, natural_size_changed_count()); | 124 EXPECT_EQ(2, natural_size_changed_count()); |
| 130 } | 125 } |
| 131 | 126 |
| 132 TEST_F(VideoFrameCompositorTest, OpacityChanged) { | 127 TEST_F(VideoFrameCompositorTest, OpacityChanged) { |
| 133 gfx::Size size(8, 8); | 128 gfx::Size size(8, 8); |
| 134 gfx::Rect rect(gfx::Point(0, 0), size); | 129 gfx::Rect rect(gfx::Point(0, 0), size); |
| 135 scoped_refptr<VideoFrame> opaque_frame = VideoFrame::CreateFrame( | 130 scoped_refptr<VideoFrame> opaque_frame = VideoFrame::CreateFrame( |
| 136 VideoFrame::YV12, size, rect, size, base::TimeDelta()); | 131 VideoFrame::YV12, size, rect, size, base::TimeDelta()); |
| 137 scoped_refptr<VideoFrame> not_opaque_frame = VideoFrame::CreateFrame( | 132 scoped_refptr<VideoFrame> not_opaque_frame = VideoFrame::CreateFrame( |
| 138 VideoFrame::YV12A, size, rect, size, base::TimeDelta()); | 133 VideoFrame::YV12A, size, rect, size, base::TimeDelta()); |
| 139 | 134 |
| 140 // Initial expectations. | 135 // Initial expectations. |
| 141 EXPECT_FALSE(opaque()); | 136 EXPECT_FALSE(opaque()); |
| 142 EXPECT_EQ(0, opacity_changed_count()); | 137 EXPECT_EQ(0, opacity_changed_count()); |
| 143 | 138 |
| 144 // Callback is fired for the first frame. | 139 // Callback is fired for the first frame. |
| 145 compositor()->PaintFrameUsingOldRenderingPath(not_opaque_frame); | 140 compositor()->UpdateCurrentFrame(not_opaque_frame); |
| 146 EXPECT_FALSE(opaque()); | 141 EXPECT_FALSE(opaque()); |
| 147 EXPECT_EQ(1, opacity_changed_count()); | 142 EXPECT_EQ(1, opacity_changed_count()); |
| 148 | 143 |
| 149 // Callback shouldn't be first subsequent times with same opaqueness. | 144 // Callback shouldn't be first subsequent times with same opaqueness. |
| 150 compositor()->PaintFrameUsingOldRenderingPath(not_opaque_frame); | 145 compositor()->UpdateCurrentFrame(not_opaque_frame); |
| 151 EXPECT_FALSE(opaque()); | 146 EXPECT_FALSE(opaque()); |
| 152 EXPECT_EQ(1, opacity_changed_count()); | 147 EXPECT_EQ(1, opacity_changed_count()); |
| 153 | 148 |
| 154 // Callback is fired when using opacity changes. | 149 // Callback is fired when using opacity changes. |
| 155 compositor()->PaintFrameUsingOldRenderingPath(opaque_frame); | 150 compositor()->UpdateCurrentFrame(opaque_frame); |
| 156 EXPECT_TRUE(opaque()); | 151 EXPECT_TRUE(opaque()); |
| 157 EXPECT_EQ(2, opacity_changed_count()); | 152 EXPECT_EQ(2, opacity_changed_count()); |
| 158 | 153 |
| 159 // Callback shouldn't be first subsequent times with same opaqueness. | 154 // Callback shouldn't be first subsequent times with same opaqueness. |
| 160 compositor()->PaintFrameUsingOldRenderingPath(opaque_frame); | 155 compositor()->UpdateCurrentFrame(opaque_frame); |
| 161 EXPECT_TRUE(opaque()); | 156 EXPECT_TRUE(opaque()); |
| 162 EXPECT_EQ(2, opacity_changed_count()); | 157 EXPECT_EQ(2, opacity_changed_count()); |
| 163 } | 158 } |
| 164 | 159 |
| 165 } // namespace media | 160 } // namespace media |
| OLD | NEW |