| 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" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "cc/layers/video_frame_provider.h" | 7 #include "cc/layers/video_frame_provider.h" |
| 8 #include "content/renderer/media/video_frame_compositor.h" | 8 #include "content/renderer/media/video_frame_compositor.h" |
| 9 #include "media/base/video_frame.h" | 9 #include "media/base/video_frame.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 int did_receive_frame_count_; | 59 int did_receive_frame_count_; |
| 60 int natural_size_changed_count_; | 60 int natural_size_changed_count_; |
| 61 gfx::Size natural_size_; | 61 gfx::Size natural_size_; |
| 62 | 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositorTest); | 63 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositorTest); |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 TEST_F(VideoFrameCompositorTest, InitialValues) { | 66 TEST_F(VideoFrameCompositorTest, InitialValues) { |
| 67 EXPECT_TRUE(compositor()->GetVideoFrameProvider()); | 67 EXPECT_TRUE(compositor()->GetVideoFrameProvider()); |
| 68 EXPECT_FALSE(compositor()->GetCurrentFrame()); | 68 EXPECT_FALSE(compositor()->GetCurrentFrame()); |
| 69 EXPECT_EQ(0u, compositor()->GetFramesDroppedBeforeComposite()); | 69 EXPECT_EQ(0u, compositor()->GetFramesDroppedBeforeCompositorWasNotified()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 TEST_F(VideoFrameCompositorTest, UpdateCurrentFrame) { | 72 TEST_F(VideoFrameCompositorTest, UpdateCurrentFrame) { |
| 73 scoped_refptr<VideoFrame> expected = VideoFrame::CreateEOSFrame(); | 73 scoped_refptr<VideoFrame> expected = VideoFrame::CreateEOSFrame(); |
| 74 | 74 |
| 75 compositor()->UpdateCurrentFrame(expected); | 75 compositor()->UpdateCurrentFrame(expected); |
| 76 scoped_refptr<VideoFrame> actual = compositor()->GetCurrentFrame(); | 76 scoped_refptr<VideoFrame> actual = compositor()->GetCurrentFrame(); |
| 77 EXPECT_EQ(expected, actual); | 77 EXPECT_EQ(expected, actual); |
| 78 | 78 |
| 79 // Should notify compositor asynchronously. | 79 // Should notify compositor asynchronously. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 EXPECT_EQ(initial_size.width(), natural_size().width()); | 118 EXPECT_EQ(initial_size.width(), natural_size().width()); |
| 119 EXPECT_EQ(initial_size.height(), natural_size().height()); | 119 EXPECT_EQ(initial_size.height(), natural_size().height()); |
| 120 EXPECT_EQ(2, natural_size_changed_count()); | 120 EXPECT_EQ(2, natural_size_changed_count()); |
| 121 | 121 |
| 122 compositor()->UpdateCurrentFrame(initial_frame); | 122 compositor()->UpdateCurrentFrame(initial_frame); |
| 123 EXPECT_EQ(initial_size.width(), natural_size().width()); | 123 EXPECT_EQ(initial_size.width(), natural_size().width()); |
| 124 EXPECT_EQ(initial_size, natural_size()); | 124 EXPECT_EQ(initial_size, natural_size()); |
| 125 EXPECT_EQ(2, natural_size_changed_count()); | 125 EXPECT_EQ(2, natural_size_changed_count()); |
| 126 } | 126 } |
| 127 | 127 |
| 128 TEST_F(VideoFrameCompositorTest, GetFramesDroppedBeforeComposite) { | 128 TEST_F(VideoFrameCompositorTest, GetFramesDroppedBeforeCompositorWasNotified) { |
| 129 scoped_refptr<VideoFrame> frame = VideoFrame::CreateEOSFrame(); | 129 scoped_refptr<VideoFrame> frame = VideoFrame::CreateEOSFrame(); |
| 130 | 130 |
| 131 compositor()->UpdateCurrentFrame(frame); | 131 compositor()->UpdateCurrentFrame(frame); |
| 132 EXPECT_EQ(0, did_receive_frame_count()); | 132 EXPECT_EQ(0, did_receive_frame_count()); |
| 133 EXPECT_EQ(0u, compositor()->GetFramesDroppedBeforeComposite()); | 133 EXPECT_EQ(0u, compositor()->GetFramesDroppedBeforeCompositorWasNotified()); |
| 134 | 134 |
| 135 // Should not increment if we finished notifying the compositor but didn't | 135 // Should not increment if we finished notifying the compositor. |
| 136 // composite the frame. | |
| 137 // | 136 // |
| 138 // This covers the scenario where the region we're rendering isn't | 137 // This covers the normal scenario where the compositor is getting |
| 139 // visible so there wasn't a need to composite. | 138 // notifications in a timely manner. |
| 140 message_loop()->RunUntilIdle(); | 139 message_loop()->RunUntilIdle(); |
| 141 compositor()->UpdateCurrentFrame(frame); | 140 compositor()->UpdateCurrentFrame(frame); |
| 142 EXPECT_EQ(1, did_receive_frame_count()); | 141 EXPECT_EQ(1, did_receive_frame_count()); |
| 143 EXPECT_EQ(0u, compositor()->GetFramesDroppedBeforeComposite()); | 142 EXPECT_EQ(0u, compositor()->GetFramesDroppedBeforeCompositorWasNotified()); |
| 144 | 143 |
| 145 // Should not increment if we didn't finish notifying the compositor but still | 144 // Should increment if we didn't notify the compositor. |
| 146 // managed to composite the frame. | |
| 147 // | 145 // |
| 148 // This covers the scenario where something else may have notified the | 146 // This covers the scenario where the compositor is falling behind. |
| 149 // compositor and managed to composite the current frame. | 147 // Consider it dropped. |
| 150 message_loop()->RunUntilIdle(); | |
| 151 provider()->GetCurrentFrame(); | |
| 152 provider()->PutCurrentFrame(NULL); | |
| 153 compositor()->UpdateCurrentFrame(frame); | |
| 154 EXPECT_EQ(2, did_receive_frame_count()); | |
| 155 EXPECT_EQ(0u, compositor()->GetFramesDroppedBeforeComposite()); | |
| 156 | |
| 157 // Should increment if we didn't notify the compositor and didn't composite | |
| 158 // the frame. | |
| 159 // | |
| 160 // This covers the scenario where we didn't even finish notifying nor | |
| 161 // compositing the current frame before updating. Consider it dropped. | |
| 162 message_loop()->RunUntilIdle(); | 148 message_loop()->RunUntilIdle(); |
| 163 compositor()->UpdateCurrentFrame(frame); | 149 compositor()->UpdateCurrentFrame(frame); |
| 164 compositor()->UpdateCurrentFrame(frame); | 150 compositor()->UpdateCurrentFrame(frame); |
| 165 EXPECT_EQ(3, did_receive_frame_count()); | 151 EXPECT_EQ(2, did_receive_frame_count()); |
| 166 EXPECT_EQ(1u, compositor()->GetFramesDroppedBeforeComposite()); | 152 EXPECT_EQ(1u, compositor()->GetFramesDroppedBeforeCompositorWasNotified()); |
| 167 | 153 |
| 168 // Shouldn't overflow. | 154 // Shouldn't overflow. |
| 169 compositor()->SetFramesDroppedBeforeCompositeForTesting(kuint32max); | 155 compositor()->SetFramesDroppedBeforeCompositorWasNotifiedForTesting( |
| 156 kuint32max); |
| 170 compositor()->UpdateCurrentFrame(frame); | 157 compositor()->UpdateCurrentFrame(frame); |
| 171 EXPECT_EQ(kuint32max, compositor()->GetFramesDroppedBeforeComposite()); | 158 EXPECT_EQ(kuint32max, |
| 159 compositor()->GetFramesDroppedBeforeCompositorWasNotified()); |
| 172 } | 160 } |
| 173 | 161 |
| 174 } // namespace content | 162 } // namespace content |
| OLD | NEW |