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

Side by Side Diff: media/blink/video_frame_compositor_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698