| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 2061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2072 void AfterTest() override {} | 2072 void AfterTest() override {} |
| 2073 | 2073 |
| 2074 private: | 2074 private: |
| 2075 gfx::ScrollOffset initial_scroll_; | 2075 gfx::ScrollOffset initial_scroll_; |
| 2076 gfx::ScrollOffset second_scroll_; | 2076 gfx::ScrollOffset second_scroll_; |
| 2077 gfx::Vector2dF scroll_amount_; | 2077 gfx::Vector2dF scroll_amount_; |
| 2078 }; | 2078 }; |
| 2079 | 2079 |
| 2080 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostScrollTestPropertyTreeUpdate); | 2080 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostScrollTestPropertyTreeUpdate); |
| 2081 | 2081 |
| 2082 // Disabled due to flakes/crashes, see https://crbug.com/697652. | 2082 class LayerTreeHostScrollTestImplSideInvalidation |
| 2083 class DISABLED_LayerTreeHostScrollTestImplSideInvalidation | |
| 2084 : public LayerTreeHostScrollTest { | 2083 : public LayerTreeHostScrollTest { |
| 2085 void BeginTest() override { | 2084 void BeginTest() override { |
| 2086 layer_tree_host()->outer_viewport_scroll_layer()->set_did_scroll_callback( | 2085 layer_tree_host()->outer_viewport_scroll_layer()->set_did_scroll_callback( |
| 2087 base::Bind(&DISABLED_LayerTreeHostScrollTestImplSideInvalidation:: | 2086 base::Bind(&LayerTreeHostScrollTestImplSideInvalidation:: |
| 2088 DidScrollOuterViewport, | 2087 DidScrollOuterViewport, |
| 2089 base::Unretained(this))); | 2088 base::Unretained(this))); |
| 2090 PostSetNeedsCommitToMainThread(); | 2089 PostSetNeedsCommitToMainThread(); |
| 2091 } | 2090 } |
| 2092 | 2091 |
| 2093 void DidScrollOuterViewport(const gfx::ScrollOffset& offset) { | 2092 void DidScrollOuterViewport(const gfx::ScrollOffset& offset) { |
| 2094 // Defer responding to the main frame until an impl-side pending tree is | 2093 // Defer responding to the main frame until an impl-side pending tree is |
| 2095 // created for the invalidation request. | 2094 // created for the invalidation request. |
| 2096 { | 2095 { |
| 2097 CompletionEvent completion; | 2096 CompletionEvent completion; |
| 2098 task_runner_provider()->ImplThreadTaskRunner()->PostTask( | 2097 task_runner_provider()->ImplThreadTaskRunner()->PostTask( |
| 2099 FROM_HERE, | 2098 FROM_HERE, base::Bind(&LayerTreeHostScrollTestImplSideInvalidation:: |
| 2100 base::Bind(&DISABLED_LayerTreeHostScrollTestImplSideInvalidation:: | 2099 WaitForInvalidationOnImplThread, |
| 2101 WaitForInvalidationOnImplThread, | 2100 base::Unretained(this), &completion)); |
| 2102 base::Unretained(this), &completion)); | |
| 2103 completion.Wait(); | 2101 completion.Wait(); |
| 2104 } | 2102 } |
| 2105 | 2103 |
| 2106 switch (++num_of_deltas_) { | 2104 switch (++num_of_deltas_) { |
| 2107 case 1: { | 2105 case 1: { |
| 2108 // First set of deltas is here. The impl thread will scroll to the | 2106 // First set of deltas is here. The impl thread will scroll to the |
| 2109 // second case on activation, so add a delta from the main thread that | 2107 // second case on activation, so add a delta from the main thread that |
| 2110 // takes us to the final value. | 2108 // takes us to the final value. |
| 2111 Layer* outer_viewport_layer = | 2109 Layer* outer_viewport_layer = |
| 2112 layer_tree_host()->outer_viewport_scroll_layer(); | 2110 layer_tree_host()->outer_viewport_scroll_layer(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2164 // after this tree is activated. | 2162 // after this tree is activated. |
| 2165 host_impl->RequestImplSideInvalidation(); | 2163 host_impl->RequestImplSideInvalidation(); |
| 2166 break; | 2164 break; |
| 2167 default: | 2165 default: |
| 2168 NOTREACHED(); | 2166 NOTREACHED(); |
| 2169 } | 2167 } |
| 2170 } | 2168 } |
| 2171 | 2169 |
| 2172 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, | 2170 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, |
| 2173 CommitEarlyOutReason reason) override { | 2171 CommitEarlyOutReason reason) override { |
| 2174 // The aborted main frame is bound to come after the fourth activation, | 2172 EXPECT_EQ(CommitEarlyOutReason::FINISHED_NO_UPDATES, reason); |
| 2175 // since the activation should occur synchronously after the impl-side | 2173 EXPECT_EQ(3, num_of_main_frames_); |
| 2176 // invalidation, and the main thread is released after this activation. It | 2174 EXPECT_EQ(outer_viewport_offsets_[2], host_impl->active_tree() |
| 2177 // should leave the scroll offset unchanged. | 2175 ->OuterViewportScrollLayer() |
| 2178 EXPECT_EQ(reason, CommitEarlyOutReason::FINISHED_NO_UPDATES); | 2176 ->CurrentScrollOffset()); |
| 2179 EXPECT_EQ(num_of_activations_, 4); | |
| 2180 EXPECT_EQ(num_of_main_frames_, 3); | |
| 2181 EXPECT_EQ(host_impl->active_tree() | |
| 2182 ->OuterViewportScrollLayer() | |
| 2183 ->CurrentScrollOffset(), | |
| 2184 outer_viewport_offsets_[2]); | |
| 2185 EndTest(); | |
| 2186 } | 2177 } |
| 2187 | 2178 |
| 2188 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 2179 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 2189 switch (++num_of_activations_) { | 2180 switch (++num_of_activations_) { |
| 2190 case 1: | 2181 case 1: |
| 2191 // Now that we have the active tree, scroll a layer and ask for a commit | 2182 // Now that we have the active tree, scroll a layer and ask for a commit |
| 2192 // to send a BeginMainFrame with the scroll delta to the main thread. | 2183 // to send a BeginMainFrame with the scroll delta to the main thread. |
| 2193 host_impl->active_tree() | 2184 host_impl->active_tree() |
| 2194 ->OuterViewportScrollLayer() | 2185 ->OuterViewportScrollLayer() |
| 2195 ->SetCurrentScrollOffset(outer_viewport_offsets_[0]); | 2186 ->SetCurrentScrollOffset(outer_viewport_offsets_[0]); |
| 2196 host_impl->SetNeedsCommit(); | 2187 host_impl->SetNeedsCommit(); |
| 2197 break; | 2188 break; |
| 2198 case 2: | 2189 case 2: |
| 2199 // The second activation is from an impl-side pending tree so the source | 2190 // The second activation is from an impl-side pending tree so the source |
| 2200 // frame number on the active tree remains unchanged, and the scroll | 2191 // frame number on the active tree remains unchanged, and the scroll |
| 2201 // offset on the active tree should also remain unchanged. | 2192 // offset on the active tree should also remain unchanged. |
| 2202 EXPECT_EQ(host_impl->active_tree()->source_frame_number(), 0); | 2193 EXPECT_EQ(0, host_impl->active_tree()->source_frame_number()); |
| 2203 EXPECT_EQ(host_impl->active_tree() | 2194 EXPECT_EQ(outer_viewport_offsets_[1], host_impl->active_tree() |
| 2204 ->OuterViewportScrollLayer() | 2195 ->OuterViewportScrollLayer() |
| 2205 ->CurrentScrollOffset(), | 2196 ->CurrentScrollOffset()); |
| 2206 outer_viewport_offsets_[1]); | |
| 2207 break; | 2197 break; |
| 2208 case 3: | 2198 case 3: |
| 2209 // The third activation is from a commit. The scroll offset on the | 2199 // The third activation is from a commit. The scroll offset on the |
| 2210 // active tree should include deltas sent from the main thread. | 2200 // active tree should include deltas sent from the main thread. |
| 2211 EXPECT_EQ(host_impl->active_tree()->source_frame_number(), 1); | 2201 EXPECT_EQ(host_impl->active_tree()->source_frame_number(), 1); |
| 2212 EXPECT_EQ(host_impl->active_tree() | 2202 EXPECT_EQ(host_impl->active_tree() |
| 2213 ->OuterViewportScrollLayer() | 2203 ->OuterViewportScrollLayer() |
| 2214 ->CurrentScrollOffset(), | 2204 ->CurrentScrollOffset(), |
| 2215 outer_viewport_offsets_[2]); | 2205 outer_viewport_offsets_[2]); |
| 2216 break; | 2206 break; |
| 2217 case 4: | 2207 case 4: |
| 2218 // The fourth activation is from an impl-side pending tree, which should | 2208 // The fourth activation is from an impl-side pending tree, which should |
| 2219 // leave the scroll offset unchanged. | 2209 // leave the scroll offset unchanged. |
| 2220 EXPECT_EQ(host_impl->active_tree()->source_frame_number(), 1); | 2210 EXPECT_EQ(1, host_impl->active_tree()->source_frame_number()); |
| 2221 EXPECT_EQ(host_impl->active_tree() | 2211 EXPECT_EQ(outer_viewport_offsets_[2], host_impl->active_tree() |
| 2222 ->OuterViewportScrollLayer() | 2212 ->OuterViewportScrollLayer() |
| 2223 ->CurrentScrollOffset(), | 2213 ->CurrentScrollOffset()); |
| 2224 outer_viewport_offsets_[2]); | |
| 2225 break; | 2214 break; |
| 2226 default: | 2215 default: |
| 2227 NOTREACHED(); | 2216 NOTREACHED(); |
| 2228 } | 2217 } |
| 2229 } | 2218 } |
| 2230 | 2219 |
| 2220 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 2221 if (++num_of_draws_ == 4) |
| 2222 EndTest(); |
| 2223 } |
| 2224 |
| 2231 void AfterTest() override { | 2225 void AfterTest() override { |
| 2232 EXPECT_EQ(num_of_activations_, 4); | 2226 EXPECT_EQ(4, num_of_activations_); |
| 2233 EXPECT_EQ(num_of_deltas_, 2); | 2227 EXPECT_EQ(2, num_of_deltas_); |
| 2234 EXPECT_EQ(num_of_main_frames_, 3); | 2228 EXPECT_EQ(3, num_of_main_frames_); |
| 2235 } | 2229 } |
| 2236 | 2230 |
| 2237 const gfx::ScrollOffset outer_viewport_offsets_[3] = { | 2231 const gfx::ScrollOffset outer_viewport_offsets_[3] = { |
| 2238 gfx::ScrollOffset(20, 20), gfx::ScrollOffset(50, 50), | 2232 gfx::ScrollOffset(20, 20), gfx::ScrollOffset(50, 50), |
| 2239 gfx::ScrollOffset(70, 70)}; | 2233 gfx::ScrollOffset(70, 70)}; |
| 2240 | 2234 |
| 2241 // Impl thread. | 2235 // Impl thread. |
| 2242 int num_of_activations_ = 0; | 2236 int num_of_activations_ = 0; |
| 2237 int num_of_draws_ = 0; |
| 2243 int num_of_main_frames_ = 0; | 2238 int num_of_main_frames_ = 0; |
| 2244 bool invalidated_on_impl_thread_ = false; | 2239 bool invalidated_on_impl_thread_ = false; |
| 2245 CompletionEvent* impl_side_invalidation_event_ = nullptr; | 2240 CompletionEvent* impl_side_invalidation_event_ = nullptr; |
| 2246 | 2241 |
| 2247 // Main thread. | 2242 // Main thread. |
| 2248 int num_of_deltas_ = 0; | 2243 int num_of_deltas_ = 0; |
| 2249 }; | 2244 }; |
| 2250 | 2245 |
| 2251 MULTI_THREAD_TEST_F(DISABLED_LayerTreeHostScrollTestImplSideInvalidation); | 2246 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestImplSideInvalidation); |
| 2252 | 2247 |
| 2253 } // namespace | 2248 } // namespace |
| 2254 } // namespace cc | 2249 } // namespace cc |
| OLD | NEW |