| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 "cc/test/begin_frame_args_test.h" | |
| 6 #include "cc/test/layer_tree_test.h" | |
| 7 | |
| 8 namespace cc { | |
| 9 | |
| 10 class RemoteChannelTest : public LayerTreeTest { | |
| 11 protected: | |
| 12 RemoteChannelTest() | |
| 13 : calls_received_(0), calls_received_on_both_server_and_client_(0) {} | |
| 14 | |
| 15 ~RemoteChannelTest() override {} | |
| 16 | |
| 17 void BeginTest() override { | |
| 18 DCHECK(IsRemoteTest()); | |
| 19 BeginChannelTest(); | |
| 20 } | |
| 21 virtual void BeginChannelTest() {} | |
| 22 | |
| 23 int calls_received_; | |
| 24 | |
| 25 // Since LayerTreeHost on engine and client share a common LayerTreeHostClient | |
| 26 // for unit tests, there are some functions called twice. This variable keep | |
| 27 // tracks of those function calls. | |
| 28 int calls_received_on_both_server_and_client_; | |
| 29 | |
| 30 private: | |
| 31 DISALLOW_COPY_AND_ASSIGN(RemoteChannelTest); | |
| 32 }; | |
| 33 | |
| 34 class RemoteChannelTestInitializationAndShutdown : public RemoteChannelTest { | |
| 35 void SetVisibleOnImpl(bool visible) override { calls_received_++; } | |
| 36 | |
| 37 void RequestNewOutputSurface() override { | |
| 38 LayerTreeTest::RequestNewOutputSurface(); | |
| 39 calls_received_++; | |
| 40 } | |
| 41 | |
| 42 void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override { | |
| 43 calls_received_++; | |
| 44 } | |
| 45 | |
| 46 void DidInitializeOutputSurface() override { | |
| 47 calls_received_++; | |
| 48 EndTest(); | |
| 49 } | |
| 50 | |
| 51 void FinishGLOnImpl() override { calls_received_++; } | |
| 52 | |
| 53 // On initialization and shutdown, each of the above calls should happen only | |
| 54 // once. | |
| 55 void AfterTest() override { EXPECT_EQ(5, calls_received_); } | |
| 56 }; | |
| 57 | |
| 58 REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestInitializationAndShutdown); | |
| 59 | |
| 60 class RemoteChannelTestMainThreadStoppedFlinging : public RemoteChannelTest { | |
| 61 void BeginChannelTest() override { proxy()->MainThreadHasStoppedFlinging(); } | |
| 62 | |
| 63 void MainThreadHasStoppedFlingingOnImpl() override { | |
| 64 calls_received_++; | |
| 65 EndTest(); | |
| 66 } | |
| 67 | |
| 68 void AfterTest() override { EXPECT_EQ(1, calls_received_); } | |
| 69 }; | |
| 70 | |
| 71 REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestMainThreadStoppedFlinging); | |
| 72 | |
| 73 class RemoteChannelTestDeferCommits : public RemoteChannelTest { | |
| 74 void BeginChannelTest() override { DispatchSetDeferCommits(true); } | |
| 75 | |
| 76 void SetDeferCommitsOnImpl(bool defer_commits) override { | |
| 77 EXPECT_TRUE(defer_commits); | |
| 78 calls_received_++; | |
| 79 EndTest(); | |
| 80 } | |
| 81 | |
| 82 void AfterTest() override { EXPECT_EQ(1, calls_received_); } | |
| 83 }; | |
| 84 | |
| 85 REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestDeferCommits); | |
| 86 | |
| 87 class RemoteChannelTestNeedsRedraw : public RemoteChannelTest { | |
| 88 public: | |
| 89 RemoteChannelTestNeedsRedraw() | |
| 90 : damaged_rect_(4, 5), device_viewport_size_(0, 0) {} | |
| 91 | |
| 92 void BeginChannelTest() override { | |
| 93 device_viewport_size_ = | |
| 94 gfx::Rect(remote_client_layer_tree_host()->device_viewport_size()); | |
| 95 layer_tree_host()->SetNeedsRedrawRect(damaged_rect_); | |
| 96 } | |
| 97 | |
| 98 void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) override { | |
| 99 calls_received_++; | |
| 100 if (calls_received_ == 1) { | |
| 101 EXPECT_EQ(damaged_rect_, damage_rect); | |
| 102 } else { | |
| 103 // The second call is received after the output surface is successfully | |
| 104 // initialized. | |
| 105 EXPECT_EQ(device_viewport_size_, damage_rect); | |
| 106 EndTest(); | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 void AfterTest() override { EXPECT_EQ(2, calls_received_); } | |
| 111 | |
| 112 gfx::Rect damaged_rect_; | |
| 113 gfx::Rect device_viewport_size_; | |
| 114 }; | |
| 115 | |
| 116 REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestNeedsRedraw); | |
| 117 | |
| 118 class RemoteChannelTestReleaseOutputSurface : public RemoteChannelTest { | |
| 119 void DidInitializeOutputSurface() override { | |
| 120 SetVisibleOnLayerTreeHost(false); | |
| 121 ReleaseOutputSurfaceOnLayerTreeHost(); | |
| 122 } | |
| 123 | |
| 124 void ReleaseOutputSurfaceOnImpl() override { | |
| 125 calls_received_++; | |
| 126 EndTest(); | |
| 127 } | |
| 128 | |
| 129 void AfterTest() override { EXPECT_EQ(1, calls_received_); } | |
| 130 }; | |
| 131 | |
| 132 REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestReleaseOutputSurface); | |
| 133 | |
| 134 class RemoteChannelTestCommit : public RemoteChannelTest { | |
| 135 void BeginChannelTest() override { | |
| 136 layer_tree_host()->SetViewportSize(viewport_size_); | |
| 137 PostSetNeedsCommitToMainThread(); | |
| 138 } | |
| 139 | |
| 140 void SetNeedsCommitOnImpl() override { | |
| 141 calls_received_++; | |
| 142 EXPECT_EQ(1, calls_received_); | |
| 143 } | |
| 144 | |
| 145 void ReceivedBeginMainFrame() override { | |
| 146 calls_received_++; | |
| 147 EXPECT_EQ(2, calls_received_); | |
| 148 } | |
| 149 | |
| 150 void StartCommitOnImpl() override { | |
| 151 calls_received_++; | |
| 152 EXPECT_EQ(3, calls_received_); | |
| 153 } | |
| 154 | |
| 155 void DidCommitAndDrawFrame() override { | |
| 156 calls_received_on_both_server_and_client_++; | |
| 157 } | |
| 158 | |
| 159 void DidCompleteSwapBuffers() override { | |
| 160 calls_received_on_both_server_and_client_++; | |
| 161 if (calls_received_on_both_server_and_client_ == 4) | |
| 162 EndTest(); | |
| 163 } | |
| 164 | |
| 165 void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | |
| 166 // Ensure that we serialized and deserialized the LayerTreeHost for the | |
| 167 // commit. | |
| 168 EXPECT_EQ(viewport_size_, host_impl->device_viewport_size()); | |
| 169 } | |
| 170 | |
| 171 void AfterTest() override { | |
| 172 EXPECT_EQ(3, calls_received_); | |
| 173 EXPECT_EQ(4, calls_received_on_both_server_and_client_); | |
| 174 } | |
| 175 | |
| 176 const gfx::Size viewport_size_ = gfx::Size(5, 3); | |
| 177 }; | |
| 178 | |
| 179 REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestCommit); | |
| 180 | |
| 181 class RemoteChannelTestBeginMainFrameAborted : public RemoteChannelTest { | |
| 182 void BeginChannelTest() override { PostSetNeedsCommitToMainThread(); } | |
| 183 | |
| 184 void ScheduledActionWillSendBeginMainFrame() override { | |
| 185 PostSetDeferCommitsToMainThread(true); | |
| 186 } | |
| 187 | |
| 188 void BeginMainFrameAbortedOnImpl(CommitEarlyOutReason reason) override { | |
| 189 EXPECT_EQ(reason, CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT); | |
| 190 calls_received_++; | |
| 191 EndTest(); | |
| 192 } | |
| 193 | |
| 194 void AfterTest() override { EXPECT_EQ(1, calls_received_); } | |
| 195 }; | |
| 196 | |
| 197 REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestBeginMainFrameAborted); | |
| 198 | |
| 199 class RemoteChannelTestReleaseOutputSurfaceDuringCommit | |
| 200 : public RemoteChannelTest { | |
| 201 public: | |
| 202 RemoteChannelTestReleaseOutputSurfaceDuringCommit() | |
| 203 : output_surface_initialized_count_(0), commit_count_(0) {} | |
| 204 void BeginChannelTest() override { PostSetNeedsCommitToMainThread(); } | |
| 205 | |
| 206 void DidInitializeOutputSurface() override { | |
| 207 ++output_surface_initialized_count_; | |
| 208 | |
| 209 switch (output_surface_initialized_count_) { | |
| 210 case 1: | |
| 211 // No commits can be performed before the first output surface is | |
| 212 // initialized. The Scheduler should not send BeginMainFrames. | |
| 213 EXPECT_EQ(0, commit_count_); | |
| 214 break; | |
| 215 case 2: | |
| 216 // When the first BeginMainFrame is received on the server, we release | |
| 217 // the output surface on the client. The RemoteChannelImpl on the client | |
| 218 // will queue the commit received till a new output surface is | |
| 219 // initialized, so we shouldn't see any commits till a second output | |
| 220 // surface is provided to the LTH. | |
| 221 EXPECT_EQ(0, commit_count_); | |
| 222 break; | |
| 223 } | |
| 224 } | |
| 225 | |
| 226 void ReceivedBeginMainFrame() override { | |
| 227 if (commit_count_ == 0) { | |
| 228 // Release the output surface before we respond to the BeginMainFrame. | |
| 229 // We perform the test only for the first BeginMainFrame request. | |
| 230 SetVisibleOnLayerTreeHost(false); | |
| 231 ReleaseOutputSurfaceOnLayerTreeHost(); | |
| 232 SetVisibleOnLayerTreeHost(true); | |
| 233 } | |
| 234 } | |
| 235 | |
| 236 void StartCommitOnImpl() override { | |
| 237 ++commit_count_; | |
| 238 if (commit_count_ == 1) { | |
| 239 // If this is the first commit, then the output surface must have been | |
| 240 // initialized twice. | |
| 241 EXPECT_EQ(2, output_surface_initialized_count_); | |
| 242 EndTest(); | |
| 243 } | |
| 244 } | |
| 245 | |
| 246 void AfterTest() override {} | |
| 247 | |
| 248 // Accessed on the main thread and the impl thread, when the main thread is | |
| 249 // blocked. | |
| 250 int output_surface_initialized_count_; | |
| 251 int commit_count_; | |
| 252 }; | |
| 253 | |
| 254 REMOTE_DIRECT_RENDERER_TEST_F( | |
| 255 RemoteChannelTestReleaseOutputSurfaceDuringCommit); | |
| 256 | |
| 257 } // namespace cc | |
| OLD | NEW |