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 <set> | 5 #include <set> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "cc/layers/solid_color_layer.h" | 9 #include "cc/layers/solid_color_layer.h" |
10 #include "cc/layers/surface_layer.h" | 10 #include "cc/layers/surface_layer.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 PostSetNeedsCommitToMainThread(); | 172 PostSetNeedsCommitToMainThread(); |
173 } | 173 } |
174 | 174 |
175 void DidCommit() override { | 175 void DidCommit() override { |
176 base::MessageLoopProxy::current()->PostTask( | 176 base::MessageLoopProxy::current()->PostTask( |
177 FROM_HERE, base::Bind(&SurfaceLayerSwapPromise::ChangeTree, | 177 FROM_HERE, base::Bind(&SurfaceLayerSwapPromise::ChangeTree, |
178 base::Unretained(this))); | 178 base::Unretained(this))); |
179 } | 179 } |
180 | 180 |
181 void ChangeTree() { | 181 void ChangeTree() { |
182 base::AutoLock lock(lock_); | |
danakj
2015/01/06 15:57:40
This still means ChangeTree and SwapBuffersOnThrea
sohanjg
2015/01/08 12:05:41
Yes, i have changed DidCommit to DidCommitAndDrawF
| |
182 ++commit_count_; | 183 ++commit_count_; |
183 switch (commit_count_) { | 184 switch (commit_count_) { |
184 case 1: | 185 case 1: |
185 // Remove SurfaceLayer from tree to cause SwapPromise to be created. | 186 // Remove SurfaceLayer from tree to cause SwapPromise to be created. |
186 blank_layer_ = SolidColorLayer::Create(); | 187 blank_layer_ = SolidColorLayer::Create(); |
187 blank_layer_->SetIsDrawable(true); | 188 blank_layer_->SetIsDrawable(true); |
188 blank_layer_->SetBounds(gfx::Size(10, 10)); | 189 blank_layer_->SetBounds(gfx::Size(10, 10)); |
189 layer_tree_host()->SetRootLayer(blank_layer_); | 190 layer_tree_host()->SetRootLayer(blank_layer_); |
190 break; | 191 break; |
191 case 2: | 192 case 2: |
192 break; | 193 break; |
193 default: | 194 default: |
194 NOTREACHED(); | 195 NOTREACHED(); |
195 break; | 196 break; |
196 } | 197 } |
197 } | 198 } |
198 | 199 |
199 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { | 200 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
200 EXPECT_TRUE(result); | 201 EXPECT_TRUE(result); |
201 std::vector<uint32_t>& satisfied = | 202 std::vector<uint32_t>& satisfied = |
202 output_surface()->last_sent_frame().metadata.satisfies_sequences; | 203 output_surface()->last_sent_frame().metadata.satisfies_sequences; |
203 EXPECT_LE(satisfied.size(), 1u); | 204 EXPECT_LE(satisfied.size(), 1u); |
204 if (satisfied.size() == 1) { | 205 if (satisfied.size() == 1) { |
205 // Eventually the one SurfaceSequence should be satisfied, but only | 206 // Eventually the one SurfaceSequence should be satisfied, but only |
206 // after the layer was removed from the tree, and only once. | 207 // after the layer was removed from the tree, and only once. |
208 base::AutoLock lock(lock_); | |
207 EXPECT_EQ(1u, satisfied[0]); | 209 EXPECT_EQ(1u, satisfied[0]); |
208 EXPECT_LE(1, commit_count_); | 210 EXPECT_LE(1, commit_count_); |
209 EXPECT_FALSE(sequence_was_satisfied_); | 211 EXPECT_FALSE(sequence_was_satisfied_); |
210 sequence_was_satisfied_ = true; | 212 sequence_was_satisfied_ = true; |
211 EndTest(); | 213 EndTest(); |
212 } | 214 } |
213 } | 215 } |
214 | 216 |
215 void AfterTest() override { | 217 void AfterTest() override { |
216 EXPECT_TRUE(required_id_ == SurfaceId(1)); | 218 EXPECT_TRUE(required_id_ == SurfaceId(1)); |
217 EXPECT_EQ(1u, required_set_.size()); | 219 EXPECT_EQ(1u, required_set_.size()); |
218 // Sequence should have been satisfied through Swap, not with the | 220 // Sequence should have been satisfied through Swap, not with the |
219 // callback. | 221 // callback. |
220 EXPECT_TRUE(satisfied_sequence_.is_null()); | 222 EXPECT_TRUE(satisfied_sequence_.is_null()); |
221 } | 223 } |
222 | 224 |
223 private: | 225 private: |
224 int commit_count_; | 226 int commit_count_; |
225 bool sequence_was_satisfied_; | 227 bool sequence_was_satisfied_; |
226 scoped_refptr<SurfaceLayer> layer_; | 228 scoped_refptr<SurfaceLayer> layer_; |
227 scoped_refptr<Layer> blank_layer_; | 229 scoped_refptr<Layer> blank_layer_; |
228 SurfaceSequence satisfied_sequence_; | 230 SurfaceSequence satisfied_sequence_; |
229 | 231 |
230 SurfaceId required_id_; | 232 SurfaceId required_id_; |
231 std::set<SurfaceSequence> required_set_; | 233 std::set<SurfaceSequence> required_set_; |
234 base::Lock lock_; | |
232 }; | 235 }; |
233 | 236 |
234 // TODO(jbauman): Reenable on single thread once http://crbug.com/421923 is | 237 // TODO(jbauman): Reenable on single thread once http://crbug.com/421923 is |
235 // fixed. | 238 // fixed. |
236 MULTI_THREAD_TEST_F(SurfaceLayerSwapPromise); | 239 MULTI_THREAD_TEST_F(SurfaceLayerSwapPromise); |
237 | 240 |
238 } // namespace | 241 } // namespace |
239 } // namespace cc | 242 } // namespace cc |
OLD | NEW |