OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/synchronization/lock.h" | 7 #include "base/synchronization/lock.h" |
8 #include "cc/animation/timing_function.h" | 8 #include "cc/animation/timing_function.h" |
9 #include "cc/layers/content_layer.h" | 9 #include "cc/layers/content_layer.h" |
10 #include "cc/layers/content_layer_client.h" | 10 #include "cc/layers/content_layer_client.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "third_party/khronos/GLES2/gl2.h" | 35 #include "third_party/khronos/GLES2/gl2.h" |
36 #include "third_party/khronos/GLES2/gl2ext.h" | 36 #include "third_party/khronos/GLES2/gl2ext.h" |
37 #include "third_party/skia/include/core/SkPicture.h" | 37 #include "third_party/skia/include/core/SkPicture.h" |
38 #include "ui/gfx/point_conversions.h" | 38 #include "ui/gfx/point_conversions.h" |
39 #include "ui/gfx/size_conversions.h" | 39 #include "ui/gfx/size_conversions.h" |
40 #include "ui/gfx/vector2d_conversions.h" | 40 #include "ui/gfx/vector2d_conversions.h" |
41 | 41 |
42 namespace cc { | 42 namespace cc { |
43 namespace { | 43 namespace { |
44 | 44 |
45 class LayerTreeHostTest : public LayerTreeTest {}; | 45 class LayerTreeHostTest : public LayerTreeTest { |
| 46 }; |
46 | 47 |
47 // Test interleaving of redraws and commits | 48 // Test interleaving of redraws and commits |
48 class LayerTreeHostTestCommitingWithContinuousRedraw : public LayerTreeHostTest
{ | 49 class LayerTreeHostTestCommitingWithContinuousRedraw |
49 public: | 50 : public LayerTreeHostTest { |
50 LayerTreeHostTestCommitingWithContinuousRedraw() | 51 public: |
51 : m_numCompleteCommits(0) | 52 LayerTreeHostTestCommitingWithContinuousRedraw() |
52 , m_numDraws(0) | 53 : num_complete_commits_(0), num_draws_(0) {} |
53 { | 54 |
54 } | 55 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
55 | 56 |
56 virtual void BeginTest() OVERRIDE | 57 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
57 { | 58 num_complete_commits_++; |
58 PostSetNeedsCommitToMainThread(); | 59 if (num_complete_commits_ == 2) |
59 } | 60 EndTest(); |
60 | 61 } |
61 virtual void CommitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | 62 |
62 { | 63 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
63 m_numCompleteCommits++; | 64 if (num_draws_ == 1) |
64 if (m_numCompleteCommits == 2) | 65 PostSetNeedsCommitToMainThread(); |
65 EndTest(); | 66 num_draws_++; |
66 } | 67 PostSetNeedsRedrawToMainThread(); |
67 | 68 } |
68 virtual void DrawLayersOnThread(LayerTreeHostImpl*) OVERRIDE | 69 |
69 { | 70 virtual void AfterTest() OVERRIDE {} |
70 if (m_numDraws == 1) | 71 |
71 PostSetNeedsCommitToMainThread(); | 72 private: |
72 m_numDraws++; | 73 int num_complete_commits_; |
73 PostSetNeedsRedrawToMainThread(); | 74 int num_draws_; |
74 } | 75 }; |
75 | 76 |
76 virtual void AfterTest() OVERRIDE | 77 MULTI_THREAD_TEST_F(LayerTreeHostTestCommitingWithContinuousRedraw); |
77 { | |
78 } | |
79 | |
80 private: | |
81 int m_numCompleteCommits; | |
82 int m_numDraws; | |
83 }; | |
84 | |
85 MULTI_THREAD_TEST_F(LayerTreeHostTestCommitingWithContinuousRedraw) | |
86 | 78 |
87 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1 | 79 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1 |
88 // draw with frame 0. | 80 // draw with frame 0. |
89 class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest { | 81 class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest { |
90 public: | 82 public: |
91 LayerTreeHostTestSetNeedsCommit1() | 83 LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {} |
92 : m_numCommits(0) | 84 |
93 , m_numDraws(0) | 85 virtual void BeginTest() OVERRIDE { |
94 { | 86 PostSetNeedsCommitToMainThread(); |
95 } | 87 PostSetNeedsCommitToMainThread(); |
96 | 88 } |
97 virtual void BeginTest() OVERRIDE | 89 |
98 { | 90 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
99 PostSetNeedsCommitToMainThread(); | 91 num_draws_++; |
100 PostSetNeedsCommitToMainThread(); | 92 if (!impl->active_tree()->source_frame_number()) |
101 } | 93 EndTest(); |
102 | 94 } |
103 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 95 |
104 { | 96 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
105 m_numDraws++; | 97 num_commits_++; |
106 if (!impl->active_tree()->source_frame_number()) | 98 } |
107 EndTest(); | 99 |
108 } | 100 virtual void AfterTest() OVERRIDE { |
109 | 101 EXPECT_GE(1, num_commits_); |
110 virtual void CommitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | 102 EXPECT_GE(1, num_draws_); |
111 { | 103 } |
112 m_numCommits++; | 104 |
113 } | 105 private: |
114 | 106 int num_commits_; |
115 virtual void AfterTest() OVERRIDE | 107 int num_draws_; |
116 { | 108 }; |
117 EXPECT_GE(1, m_numCommits); | 109 |
118 EXPECT_GE(1, m_numDraws); | 110 // MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit1); |
119 } | |
120 | |
121 private: | |
122 int m_numCommits; | |
123 int m_numDraws; | |
124 }; | |
125 | |
126 //MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit1) | |
127 | 111 |
128 // A setNeedsCommit should lead to 1 commit. Issuing a second commit after that | 112 // A setNeedsCommit should lead to 1 commit. Issuing a second commit after that |
129 // first committed frame draws should lead to another commit. | 113 // first committed frame draws should lead to another commit. |
130 class LayerTreeHostTestSetNeedsCommit2 : public LayerTreeHostTest { | 114 class LayerTreeHostTestSetNeedsCommit2 : public LayerTreeHostTest { |
131 public: | 115 public: |
132 LayerTreeHostTestSetNeedsCommit2() | 116 LayerTreeHostTestSetNeedsCommit2() : num_commits_(0), num_draws_(0) {} |
133 : m_numCommits(0) | 117 |
134 , m_numDraws(0) | 118 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
135 { | 119 |
136 } | 120 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
137 | 121 if (impl->active_tree()->source_frame_number() == 0) |
138 virtual void BeginTest() OVERRIDE | 122 PostSetNeedsCommitToMainThread(); |
139 { | 123 else if (impl->active_tree()->source_frame_number() == 1) |
140 PostSetNeedsCommitToMainThread(); | 124 EndTest(); |
141 } | 125 } |
142 | 126 |
143 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 127 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
144 { | 128 num_commits_++; |
145 if (impl->active_tree()->source_frame_number() == 0) | 129 } |
146 PostSetNeedsCommitToMainThread(); | 130 |
147 else if (impl->active_tree()->source_frame_number() == 1) | 131 virtual void AfterTest() OVERRIDE { |
148 EndTest(); | 132 EXPECT_EQ(2, num_commits_); |
149 } | 133 EXPECT_GE(2, num_draws_); |
150 | 134 } |
151 virtual void CommitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | 135 |
152 { | 136 private: |
153 m_numCommits++; | 137 int num_commits_; |
154 } | 138 int num_draws_; |
155 | 139 }; |
156 virtual void AfterTest() OVERRIDE | 140 |
157 { | 141 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2); |
158 EXPECT_EQ(2, m_numCommits); | |
159 EXPECT_GE(2, m_numDraws); | |
160 } | |
161 | |
162 private: | |
163 int m_numCommits; | |
164 int m_numDraws; | |
165 }; | |
166 | |
167 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2) | |
168 | 142 |
169 // 1 setNeedsRedraw after the first commit has completed should lead to 1 | 143 // 1 setNeedsRedraw after the first commit has completed should lead to 1 |
170 // additional draw. | 144 // additional draw. |
171 class LayerTreeHostTestSetNeedsRedraw : public LayerTreeHostTest { | 145 class LayerTreeHostTestSetNeedsRedraw : public LayerTreeHostTest { |
172 public: | 146 public: |
173 LayerTreeHostTestSetNeedsRedraw() | 147 LayerTreeHostTestSetNeedsRedraw() : num_commits_(0), num_draws_(0) {} |
174 : m_numCommits(0) | 148 |
175 , m_numDraws(0) | 149 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
176 { | 150 |
177 } | 151 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
178 | 152 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); |
179 virtual void BeginTest() OVERRIDE | 153 if (!num_draws_) { |
180 { | 154 // Redraw again to verify that the second redraw doesn't commit. |
181 PostSetNeedsCommitToMainThread(); | 155 PostSetNeedsRedrawToMainThread(); |
182 } | 156 } else { |
183 | 157 EndTest(); |
184 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 158 } |
185 { | 159 num_draws_++; |
186 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); | 160 } |
187 if (!m_numDraws) | 161 |
188 PostSetNeedsRedrawToMainThread(); // Redraw again to verify that the
second redraw doesn't commit. | 162 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
189 else | 163 EXPECT_EQ(0, num_draws_); |
190 EndTest(); | 164 num_commits_++; |
191 m_numDraws++; | 165 } |
192 } | 166 |
193 | 167 virtual void AfterTest() OVERRIDE { |
194 virtual void CommitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | 168 EXPECT_GE(2, num_draws_); |
195 { | 169 EXPECT_EQ(1, num_commits_); |
196 EXPECT_EQ(0, m_numDraws); | 170 } |
197 m_numCommits++; | 171 |
198 } | 172 private: |
199 | 173 int num_commits_; |
200 virtual void AfterTest() OVERRIDE | 174 int num_draws_; |
201 { | 175 }; |
202 EXPECT_GE(2, m_numDraws); | 176 |
203 EXPECT_EQ(1, m_numCommits); | 177 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw); |
204 } | |
205 | |
206 private: | |
207 int m_numCommits; | |
208 int m_numDraws; | |
209 }; | |
210 | |
211 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw) | |
212 | 178 |
213 class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { | 179 class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { |
214 public: | 180 public: |
215 LayerTreeHostTestNoExtraCommitFromInvalidate() | 181 LayerTreeHostTestNoExtraCommitFromInvalidate() |
216 : m_rootLayer(ContentLayer::Create(&client_)) | 182 : root_layer_(ContentLayer::Create(&client_)) {} |
217 { | 183 |
218 } | 184 virtual void BeginTest() OVERRIDE { |
219 | 185 root_layer_->SetAutomaticallyComputeRasterScale(false); |
220 virtual void BeginTest() OVERRIDE | 186 root_layer_->SetIsDrawable(true); |
221 { | 187 root_layer_->SetBounds(gfx::Size(1, 1)); |
222 m_rootLayer->SetAutomaticallyComputeRasterScale(false); | 188 layer_tree_host()->SetRootLayer(root_layer_); |
223 m_rootLayer->SetIsDrawable(true); | 189 PostSetNeedsCommitToMainThread(); |
224 m_rootLayer->SetBounds(gfx::Size(1, 1)); | 190 } |
225 layer_tree_host()->SetRootLayer(m_rootLayer); | 191 |
226 PostSetNeedsCommitToMainThread(); | 192 virtual void DidCommit() OVERRIDE { |
227 } | 193 switch (layer_tree_host()->commit_number()) { |
228 | 194 case 1: |
229 virtual void DidCommit() OVERRIDE | 195 // Changing the content bounds will cause a single commit! |
230 { | 196 root_layer_->SetRasterScale(4.f); |
231 switch (layer_tree_host()->commit_number()) { | 197 break; |
232 case 1: | 198 default: |
233 // Changing the content bounds will cause a single commit! | 199 // No extra commits. |
234 m_rootLayer->SetRasterScale(4.0f); | 200 EXPECT_EQ(2, layer_tree_host()->commit_number()); |
235 break; | 201 EndTest(); |
236 default: | 202 } |
237 // No extra commits. | 203 } |
238 EXPECT_EQ(2, layer_tree_host()->commit_number()); | 204 |
239 EndTest(); | 205 virtual void AfterTest() OVERRIDE {} |
240 } | 206 |
241 } | 207 private: |
242 | 208 FakeContentLayerClient client_; |
243 virtual void AfterTest() OVERRIDE | 209 scoped_refptr<ContentLayer> root_layer_; |
244 { | 210 }; |
245 } | 211 |
246 | 212 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate); |
247 private: | |
248 FakeContentLayerClient client_; | |
249 scoped_refptr<ContentLayer> m_rootLayer; | |
250 }; | |
251 | |
252 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate) | |
253 | 213 |
254 class LayerTreeHostTestCompositeAndReadback : public LayerTreeHostTest { | 214 class LayerTreeHostTestCompositeAndReadback : public LayerTreeHostTest { |
255 public: | 215 public: |
256 LayerTreeHostTestCompositeAndReadback() | 216 LayerTreeHostTestCompositeAndReadback() : num_commits_(0) {} |
257 : m_numCommits(0) | 217 |
258 { | 218 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
259 } | 219 |
260 | 220 virtual void DidCommit() OVERRIDE { |
261 virtual void BeginTest() OVERRIDE | 221 num_commits_++; |
262 { | 222 if (num_commits_ == 1) { |
263 PostSetNeedsCommitToMainThread(); | 223 char pixels[4]; |
264 } | 224 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1)); |
265 | 225 } else if (num_commits_ == 2) { |
266 virtual void DidCommit() OVERRIDE | 226 // This is inside the readback. We should get another commit after it. |
267 { | 227 } else if (num_commits_ == 3) { |
268 m_numCommits++; | 228 EndTest(); |
269 if (m_numCommits == 1) { | 229 } else { |
270 char pixels[4]; | 230 NOTREACHED(); |
271 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1,
1)); | 231 } |
272 } else if (m_numCommits == 2) { | 232 } |
273 // This is inside the readback. We should get another commit after i
t. | 233 |
274 } else if (m_numCommits == 3) { | 234 virtual void AfterTest() OVERRIDE {} |
275 EndTest(); | 235 |
276 } else { | 236 private: |
277 NOTREACHED(); | 237 int num_commits_; |
278 } | 238 }; |
279 } | 239 |
280 | 240 MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadback); |
281 virtual void AfterTest() OVERRIDE | 241 |
282 { | 242 class LayerTreeHostTestCompositeAndReadbackBeforePreviousCommitDraws |
283 } | 243 : public LayerTreeHostTest { |
284 | 244 public: |
285 private: | 245 LayerTreeHostTestCompositeAndReadbackBeforePreviousCommitDraws() |
286 int m_numCommits; | 246 : num_commits_(0) {} |
287 }; | 247 |
288 | 248 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
289 MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadback) | 249 |
290 | 250 virtual void DidCommit() OVERRIDE { |
291 class LayerTreeHostTestCompositeAndReadbackBeforePreviousCommitDraws : public La
yerTreeHostTest { | 251 num_commits_++; |
292 public: | 252 if (num_commits_ == 1) { |
293 LayerTreeHostTestCompositeAndReadbackBeforePreviousCommitDraws() | 253 layer_tree_host()->SetNeedsCommit(); |
294 : m_numCommits(0) | 254 } else if (num_commits_ == 2) { |
295 { | 255 char pixels[4]; |
296 } | 256 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1)); |
297 | 257 } else if (num_commits_ == 3) { |
298 virtual void BeginTest() OVERRIDE | 258 // This is inside the readback. We should get another commit after it. |
299 { | 259 } else if (num_commits_ == 4) { |
300 PostSetNeedsCommitToMainThread(); | 260 EndTest(); |
301 } | 261 } else { |
302 | 262 NOTREACHED(); |
303 virtual void DidCommit() OVERRIDE | 263 } |
304 { | 264 } |
305 m_numCommits++; | 265 |
306 if (m_numCommits == 1) { | 266 virtual void AfterTest() OVERRIDE {} |
307 layer_tree_host()->SetNeedsCommit(); | 267 |
308 } else if (m_numCommits == 2) { | 268 private: |
309 char pixels[4]; | 269 int num_commits_; |
310 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1,
1)); | 270 }; |
311 } else if (m_numCommits == 3) { | 271 |
312 // This is inside the readback. We should get another commit after i
t. | 272 MULTI_THREAD_TEST_F( |
313 } else if (m_numCommits == 4) { | 273 LayerTreeHostTestCompositeAndReadbackBeforePreviousCommitDraws); |
314 EndTest(); | 274 |
315 } else { | 275 // If the layerTreeHost says it can't draw, Then we should not try to draw. |
316 NOTREACHED(); | |
317 } | |
318 } | |
319 | |
320 virtual void AfterTest() OVERRIDE | |
321 { | |
322 } | |
323 | |
324 private: | |
325 int m_numCommits; | |
326 }; | |
327 | |
328 MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackBeforePreviousCommitDra
ws) | |
329 | |
330 // If the layerTreeHost says it can't draw, then we should not try to draw. | |
331 class LayerTreeHostTestCanDrawBlocksDrawing : public LayerTreeHostTest { | 276 class LayerTreeHostTestCanDrawBlocksDrawing : public LayerTreeHostTest { |
332 public: | 277 public: |
333 LayerTreeHostTestCanDrawBlocksDrawing() | 278 LayerTreeHostTestCanDrawBlocksDrawing() : num_commits_(0), done_(false) {} |
334 : m_numCommits(0) | 279 |
335 , m_done(false) | 280 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
336 { | 281 |
337 } | 282 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
338 | 283 if (done_) |
339 virtual void BeginTest() OVERRIDE | 284 return; |
340 { | 285 // Only the initial draw should bring us here. |
341 PostSetNeedsCommitToMainThread(); | 286 EXPECT_TRUE(impl->CanDraw()); |
342 } | 287 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); |
343 | 288 } |
344 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 289 |
345 { | 290 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
346 if (m_done) | 291 if (done_) |
347 return; | 292 return; |
348 // Only the initial draw should bring us here. | 293 if (num_commits_ >= 1) { |
349 EXPECT_TRUE(impl->CanDraw()); | 294 // After the first commit, we should not be able to draw. |
350 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); | 295 EXPECT_FALSE(impl->CanDraw()); |
351 } | 296 } |
352 | 297 } |
353 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 298 |
354 { | 299 virtual void DidCommit() OVERRIDE { |
355 if (m_done) | 300 num_commits_++; |
356 return; | 301 if (num_commits_ == 1) { |
357 if (m_numCommits >= 1) { | 302 // Make the viewport empty so the host says it can't draw. |
358 // After the first commit, we should not be able to draw. | 303 layer_tree_host()->SetViewportSize(gfx::Size(0, 0), gfx::Size(0, 0)); |
359 EXPECT_FALSE(impl->CanDraw()); | 304 } else if (num_commits_ == 2) { |
360 } | 305 char pixels[4]; |
361 } | 306 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1)); |
362 | 307 } else if (num_commits_ == 3) { |
363 virtual void DidCommit() OVERRIDE | 308 // Let it draw so we go idle and end the test. |
364 { | 309 layer_tree_host()->SetViewportSize(gfx::Size(1, 1), gfx::Size(1, 1)); |
365 m_numCommits++; | 310 done_ = true; |
366 if (m_numCommits == 1) { | 311 EndTest(); |
367 // Make the viewport empty so the host says it can't draw. | 312 } |
368 layer_tree_host()->SetViewportSize(gfx::Size(0, 0), gfx::Size(0, 0))
; | 313 } |
369 } else if (m_numCommits == 2) { | 314 |
370 char pixels[4]; | 315 virtual void AfterTest() OVERRIDE {} |
371 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1,
1)); | 316 |
372 } else if (m_numCommits == 3) { | 317 private: |
373 // Let it draw so we go idle and end the test. | 318 int num_commits_; |
374 layer_tree_host()->SetViewportSize(gfx::Size(1, 1), gfx::Size(1, 1))
; | 319 bool done_; |
375 m_done = true; | 320 }; |
376 EndTest(); | 321 |
377 } | 322 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestCanDrawBlocksDrawing); |
378 } | |
379 | |
380 virtual void AfterTest() OVERRIDE | |
381 { | |
382 } | |
383 | |
384 private: | |
385 int m_numCommits; | |
386 bool m_done; | |
387 }; | |
388 | |
389 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestCanDrawBlocksDrawing) | |
390 | 323 |
391 // beginLayerWrite should prevent draws from executing until a commit occurs | 324 // beginLayerWrite should prevent draws from executing until a commit occurs |
392 class LayerTreeHostTestWriteLayersRedraw : public LayerTreeHostTest { | 325 class LayerTreeHostTestWriteLayersRedraw : public LayerTreeHostTest { |
393 public: | 326 public: |
394 LayerTreeHostTestWriteLayersRedraw() | 327 LayerTreeHostTestWriteLayersRedraw() : num_commits_(0), num_draws_(0) {} |
395 : m_numCommits(0) | 328 |
396 , m_numDraws(0) | 329 virtual void BeginTest() OVERRIDE { |
397 { | 330 PostAcquireLayerTextures(); |
398 } | 331 PostSetNeedsRedrawToMainThread(); // should be inhibited without blocking |
399 | 332 PostSetNeedsCommitToMainThread(); |
400 virtual void BeginTest() OVERRIDE | 333 } |
401 { | 334 |
402 PostAcquireLayerTextures(); | 335 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
403 PostSetNeedsRedrawToMainThread(); // should be inhibited without blockin
g | 336 num_draws_++; |
404 PostSetNeedsCommitToMainThread(); | 337 EXPECT_EQ(num_draws_, num_commits_); |
405 } | 338 } |
406 | 339 |
407 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 340 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
408 { | 341 num_commits_++; |
409 m_numDraws++; | 342 EndTest(); |
410 EXPECT_EQ(m_numDraws, m_numCommits); | 343 } |
411 } | 344 |
412 | 345 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_commits_); } |
413 virtual void CommitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | 346 |
414 { | 347 private: |
415 m_numCommits++; | 348 int num_commits_; |
416 EndTest(); | 349 int num_draws_; |
417 } | 350 }; |
418 | 351 |
419 virtual void AfterTest() OVERRIDE | 352 MULTI_THREAD_TEST_F(LayerTreeHostTestWriteLayersRedraw); |
420 { | 353 |
421 EXPECT_EQ(1, m_numCommits); | 354 // Verify that when resuming visibility, Requesting layer write permission |
422 } | |
423 | |
424 private: | |
425 int m_numCommits; | |
426 int m_numDraws; | |
427 }; | |
428 | |
429 MULTI_THREAD_TEST_F(LayerTreeHostTestWriteLayersRedraw) | |
430 | |
431 // Verify that when resuming visibility, requesting layer write permission | |
432 // will not deadlock the main thread even though there are not yet any | 355 // will not deadlock the main thread even though there are not yet any |
433 // scheduled redraws. This behavior is critical for reliably surviving tab | 356 // scheduled redraws. This behavior is critical for reliably surviving tab |
434 // switching. There are no failure conditions to this test, it just passes | 357 // switching. There are no failure conditions to this test, it just passes |
435 // by not timing out. | 358 // by not timing out. |
436 class LayerTreeHostTestWriteLayersAfterVisible : public LayerTreeHostTest { | 359 class LayerTreeHostTestWriteLayersAfterVisible : public LayerTreeHostTest { |
437 public: | 360 public: |
438 LayerTreeHostTestWriteLayersAfterVisible() | 361 LayerTreeHostTestWriteLayersAfterVisible() : num_commits_(0) {} |
439 : m_numCommits(0) | 362 |
440 { | 363 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
441 } | 364 |
442 | 365 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
443 virtual void BeginTest() OVERRIDE | 366 num_commits_++; |
444 { | 367 if (num_commits_ == 2) |
445 PostSetNeedsCommitToMainThread(); | 368 EndTest(); |
446 } | 369 else if (num_commits_ < 2) { |
447 | 370 PostSetVisibleToMainThread(false); |
448 virtual void CommitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | 371 PostSetVisibleToMainThread(true); |
449 { | 372 PostAcquireLayerTextures(); |
450 m_numCommits++; | 373 PostSetNeedsCommitToMainThread(); |
451 if (m_numCommits == 2) | 374 } |
452 EndTest(); | 375 } |
453 else if (m_numCommits < 2) { | 376 |
454 PostSetVisibleToMainThread(false); | 377 virtual void AfterTest() OVERRIDE {} |
455 PostSetVisibleToMainThread(true); | 378 |
456 PostAcquireLayerTextures(); | 379 private: |
457 PostSetNeedsCommitToMainThread(); | 380 int num_commits_; |
458 } | 381 }; |
459 } | 382 |
460 | 383 MULTI_THREAD_TEST_F(LayerTreeHostTestWriteLayersAfterVisible); |
461 virtual void AfterTest() OVERRIDE | 384 |
462 { | 385 // A compositeAndReadback while invisible should force a normal commit without |
463 } | 386 // assertion. |
464 | 387 class LayerTreeHostTestCompositeAndReadbackWhileInvisible |
465 private: | 388 : public LayerTreeHostTest { |
466 int m_numCommits; | 389 public: |
467 }; | 390 LayerTreeHostTestCompositeAndReadbackWhileInvisible() : num_commits_(0) {} |
468 | 391 |
469 MULTI_THREAD_TEST_F(LayerTreeHostTestWriteLayersAfterVisible) | 392 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
470 | 393 |
471 // A compositeAndReadback while invisible should force a normal commit without a
ssertion. | 394 virtual void DidCommitAndDrawFrame() OVERRIDE { |
472 class LayerTreeHostTestCompositeAndReadbackWhileInvisible : public LayerTreeHost
Test { | 395 num_commits_++; |
473 public: | 396 if (num_commits_ == 1) { |
474 LayerTreeHostTestCompositeAndReadbackWhileInvisible() | 397 layer_tree_host()->SetVisible(false); |
475 : m_numCommits(0) | 398 layer_tree_host()->SetNeedsCommit(); |
476 { | 399 layer_tree_host()->SetNeedsCommit(); |
477 } | 400 char pixels[4]; |
478 | 401 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1)); |
479 virtual void BeginTest() OVERRIDE | 402 } else { |
480 { | 403 EndTest(); |
481 PostSetNeedsCommitToMainThread(); | 404 } |
482 } | 405 } |
483 | 406 |
484 virtual void DidCommitAndDrawFrame() OVERRIDE | 407 virtual void AfterTest() OVERRIDE {} |
485 { | 408 |
486 m_numCommits++; | 409 private: |
487 if (m_numCommits == 1) { | 410 int num_commits_; |
488 layer_tree_host()->SetVisible(false); | 411 }; |
489 layer_tree_host()->SetNeedsCommit(); | 412 |
490 layer_tree_host()->SetNeedsCommit(); | 413 MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackWhileInvisible); |
491 char pixels[4]; | |
492 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1,
1)); | |
493 } else | |
494 EndTest(); | |
495 | |
496 } | |
497 | |
498 virtual void AfterTest() OVERRIDE | |
499 { | |
500 } | |
501 | |
502 private: | |
503 int m_numCommits; | |
504 }; | |
505 | |
506 MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackWhileInvisible) | |
507 | 414 |
508 class LayerTreeHostTestAbortFrameWhenInvisible : public LayerTreeHostTest { | 415 class LayerTreeHostTestAbortFrameWhenInvisible : public LayerTreeHostTest { |
509 public: | 416 public: |
510 LayerTreeHostTestAbortFrameWhenInvisible() | 417 LayerTreeHostTestAbortFrameWhenInvisible() {} |
511 { | 418 |
512 } | 419 virtual void BeginTest() OVERRIDE { |
513 | 420 // Request a commit (from the main thread), Which will trigger the commit |
514 virtual void BeginTest() OVERRIDE | 421 // flow from the impl side. |
515 { | 422 layer_tree_host()->SetNeedsCommit(); |
516 // Request a commit (from the main thread), which will trigger the commi
t flow from the impl side. | 423 // Then mark ourselves as not visible before processing any more messages |
517 layer_tree_host()->SetNeedsCommit(); | 424 // on the main thread. |
518 // Then mark ourselves as not visible before processing any more message
s on the main thread. | 425 layer_tree_host()->SetVisible(false); |
519 layer_tree_host()->SetVisible(false); | 426 // If we make it without kicking a frame, we pass! |
520 // If we make it without kicking a frame, we pass! | 427 EndTestAfterDelay(1); |
521 EndTestAfterDelay(1); | 428 } |
522 } | 429 |
523 | 430 virtual void Layout() OVERRIDE { |
524 virtual void Layout() OVERRIDE | 431 ASSERT_FALSE(true); |
525 { | 432 EndTest(); |
526 ASSERT_FALSE(true); | 433 } |
527 EndTest(); | 434 |
528 } | 435 virtual void AfterTest() OVERRIDE {} |
529 | 436 |
530 virtual void AfterTest() OVERRIDE | 437 private: |
531 { | 438 }; |
532 } | 439 |
533 | 440 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortFrameWhenInvisible); |
534 private: | 441 |
535 }; | 442 // This test verifies that properties on the layer tree host are commited |
536 | 443 // to the impl side. |
537 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortFrameWhenInvisible) | |
538 | |
539 // This test verifies that properties on the layer tree host are commited to the
impl side. | |
540 class LayerTreeHostTestCommit : public LayerTreeHostTest { | 444 class LayerTreeHostTestCommit : public LayerTreeHostTest { |
541 public: | 445 public: |
542 | 446 |
543 LayerTreeHostTestCommit() { } | 447 LayerTreeHostTestCommit() {} |
544 | 448 |
545 virtual void BeginTest() OVERRIDE | 449 virtual void BeginTest() OVERRIDE { |
546 { | 450 layer_tree_host()->SetViewportSize(gfx::Size(20, 20), gfx::Size(20, 20)); |
547 layer_tree_host()->SetViewportSize(gfx::Size(20, 20), gfx::Size(20, 20))
; | 451 layer_tree_host()->set_background_color(SK_ColorGRAY); |
548 layer_tree_host()->set_background_color(SK_ColorGRAY); | 452 layer_tree_host()->SetPageScaleFactorAndLimits(5.f, 5.f, 5.f); |
549 layer_tree_host()->SetPageScaleFactorAndLimits(5, 5, 5); | 453 |
550 | 454 PostSetNeedsCommitToMainThread(); |
551 PostSetNeedsCommitToMainThread(); | 455 } |
552 } | 456 |
553 | 457 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
554 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 458 EXPECT_EQ(gfx::Size(20, 20), impl->layout_viewport_size()); |
555 { | 459 EXPECT_EQ(SK_ColorGRAY, impl->active_tree()->background_color()); |
556 EXPECT_EQ(gfx::Size(20, 20), impl->layout_viewport_size()); | 460 EXPECT_EQ(5.f, impl->active_tree()->page_scale_factor()); |
557 EXPECT_EQ(SK_ColorGRAY, impl->active_tree()->background_color()); | 461 |
558 EXPECT_EQ(5, impl->active_tree()->page_scale_factor()); | 462 EndTest(); |
559 | 463 } |
560 EndTest(); | 464 |
561 } | 465 virtual void AfterTest() OVERRIDE {} |
562 | 466 }; |
563 virtual void AfterTest() OVERRIDE { } | 467 |
564 }; | 468 MULTI_THREAD_TEST_F(LayerTreeHostTestCommit); |
565 | 469 |
566 MULTI_THREAD_TEST_F(LayerTreeHostTestCommit) | 470 // Verifies that startPageScaleAnimation events propagate correctly |
567 | 471 // from LayerTreeHost to LayerTreeHostImpl in the MT compositor. |
568 // Verifies that startPageScaleAnimation events propagate correctly from LayerTr
eeHost to | |
569 // LayerTreeHostImpl in the MT compositor. | |
570 class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest { | 472 class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest { |
571 public: | 473 public: |
572 | 474 LayerTreeHostTestStartPageScaleAnimation() : animation_requested_(false) {} |
573 LayerTreeHostTestStartPageScaleAnimation() | 475 |
574 : m_animationRequested(false) | 476 virtual void BeginTest() OVERRIDE { |
575 { | 477 layer_tree_host()->root_layer()->SetScrollable(true); |
576 } | 478 layer_tree_host()->root_layer()->SetScrollOffset(gfx::Vector2d()); |
577 | 479 PostSetNeedsCommitToMainThread(); |
578 virtual void BeginTest() OVERRIDE | 480 PostSetNeedsRedrawToMainThread(); |
579 { | 481 } |
580 layer_tree_host()->root_layer()->SetScrollable(true); | 482 |
581 layer_tree_host()->root_layer()->SetScrollOffset(gfx::Vector2d()); | 483 void RequestStartPageScaleAnimation() { |
582 PostSetNeedsCommitToMainThread(); | 484 layer_tree_host()->StartPageScaleAnimation( |
583 PostSetNeedsRedrawToMainThread(); | 485 gfx::Vector2d(), false, 1.25f, base::TimeDelta()); |
584 } | 486 } |
585 | 487 |
586 void requestStartPageScaleAnimation() | 488 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
587 { | 489 impl->active_tree()->root_layer()->SetScrollable(true); |
588 layer_tree_host()->StartPageScaleAnimation(gfx::Vector2d(), false, 1.25,
base::TimeDelta()); | 490 impl->active_tree()->root_layer()->SetScrollOffset(gfx::Vector2d()); |
589 } | 491 impl->active_tree()->SetPageScaleFactorAndLimits( |
590 | 492 impl->active_tree()->page_scale_factor(), 0.5f, 2.f); |
591 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 493 |
592 { | 494 // We request animation only once. |
593 impl->active_tree()->root_layer()->SetScrollable(true); | 495 if (!animation_requested_) { |
594 impl->active_tree()->root_layer()->SetScrollOffset(gfx::Vector2d()); | 496 impl->proxy()->MainThread()->PostTask( |
595 impl->active_tree()->SetPageScaleFactorAndLimits(impl->active_tree()->pa
ge_scale_factor(), 0.5, 2); | 497 base::Bind(&LayerTreeHostTestStartPageScaleAnimation:: |
596 | 498 RequestStartPageScaleAnimation, |
597 // We request animation only once. | 499 base::Unretained(this))); |
598 if (!m_animationRequested) { | 500 animation_requested_ = true; |
599 impl->proxy()->MainThread()->PostTask(base::Bind(&LayerTreeHostTestS
tartPageScaleAnimation::requestStartPageScaleAnimation, base::Unretained(this)))
; | 501 } |
600 m_animationRequested = true; | 502 } |
601 } | 503 |
602 } | 504 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) |
603 | 505 OVERRIDE { |
604 virtual void ApplyScrollAndScale(gfx::Vector2d scrollDelta, float scale) OVE
RRIDE | 506 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset(); |
605 { | 507 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta); |
606 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset(); | 508 layer_tree_host()->SetPageScaleFactorAndLimits(scale, 0.5f, 2.f); |
607 layer_tree_host()->root_layer()->SetScrollOffset(offset + scrollDelta); | 509 } |
608 layer_tree_host()->SetPageScaleFactorAndLimits(scale, 0.5, 2); | 510 |
609 } | 511 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
610 | 512 impl->ProcessScrollDeltas(); |
611 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 513 // We get one commit before the first draw, and the animation doesn't |
612 { | 514 // happen until the second draw. |
613 impl->ProcessScrollDeltas(); | 515 if (impl->active_tree()->source_frame_number() == 1) { |
614 // We get one commit before the first draw, and the animation doesn't ha
ppen until the second draw. | 516 EXPECT_EQ(1.25f, impl->active_tree()->page_scale_factor()); |
615 if (impl->active_tree()->source_frame_number() == 1) { | 517 EndTest(); |
616 EXPECT_EQ(1.25, impl->active_tree()->page_scale_factor()); | 518 } else { |
617 EndTest(); | 519 PostSetNeedsRedrawToMainThread(); |
618 } else | 520 } |
619 PostSetNeedsRedrawToMainThread(); | 521 } |
620 } | 522 |
621 | 523 virtual void AfterTest() OVERRIDE {} |
622 virtual void AfterTest() OVERRIDE | 524 |
623 { | 525 private: |
624 } | 526 bool animation_requested_; |
625 | |
626 private: | |
627 bool m_animationRequested; | |
628 }; | 527 }; |
629 | 528 |
630 // TODO(aelias): This test is currently broken: http://crbug.com/178295 | 529 // TODO(aelias): This test is currently broken: http://crbug.com/178295 |
631 //MULTI_THREAD_TEST_F(LayerTreeHostTestStartPageScaleAnimation) | 530 // MULTI_THREAD_TEST_F(LayerTreeHostTestStartPageScaleAnimation); |
632 | 531 |
633 class LayerTreeHostTestSetVisible : public LayerTreeHostTest { | 532 class LayerTreeHostTestSetVisible : public LayerTreeHostTest { |
634 public: | 533 public: |
635 | 534 |
636 LayerTreeHostTestSetVisible() | 535 LayerTreeHostTestSetVisible() : num_draws_(0) {} |
637 : m_numDraws(0) | 536 |
638 { | 537 virtual void BeginTest() OVERRIDE { |
639 } | 538 PostSetNeedsCommitToMainThread(); |
640 | 539 PostSetVisibleToMainThread(false); |
641 virtual void BeginTest() OVERRIDE | 540 // This is suppressed while we're invisible. |
642 { | 541 PostSetNeedsRedrawToMainThread(); |
643 PostSetNeedsCommitToMainThread(); | 542 // Triggers the redraw. |
644 PostSetVisibleToMainThread(false); | 543 PostSetVisibleToMainThread(true); |
645 PostSetNeedsRedrawToMainThread(); // This is suppressed while we're invi
sible. | 544 } |
646 PostSetVisibleToMainThread(true); // Triggers the redraw. | 545 |
647 } | 546 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
648 | 547 EXPECT_TRUE(impl->visible()); |
649 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 548 ++num_draws_; |
650 { | 549 EndTest(); |
651 EXPECT_TRUE(impl->visible()); | 550 } |
652 ++m_numDraws; | 551 |
653 EndTest(); | 552 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_draws_); } |
654 } | 553 |
655 | 554 private: |
656 virtual void AfterTest() OVERRIDE | 555 int num_draws_; |
657 { | 556 }; |
658 EXPECT_EQ(1, m_numDraws); | 557 |
659 } | 558 MULTI_THREAD_TEST_F(LayerTreeHostTestSetVisible); |
660 | |
661 private: | |
662 int m_numDraws; | |
663 }; | |
664 | |
665 MULTI_THREAD_TEST_F(LayerTreeHostTestSetVisible) | |
666 | 559 |
667 class TestOpacityChangeLayerDelegate : public ContentLayerClient { | 560 class TestOpacityChangeLayerDelegate : public ContentLayerClient { |
668 public: | 561 public: |
669 TestOpacityChangeLayerDelegate() | 562 TestOpacityChangeLayerDelegate() : test_layer_(0) {} |
670 : m_testLayer(0) | 563 |
671 { | 564 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } |
672 } | 565 |
673 | 566 virtual void PaintContents(SkCanvas*, gfx::Rect, gfx::RectF*) OVERRIDE { |
674 void setTestLayer(Layer* testLayer) | 567 // Set layer opacity to 0. |
675 { | 568 if (test_layer_) |
676 m_testLayer = testLayer; | 569 test_layer_->SetOpacity(0.f); |
677 } | 570 } |
678 | 571 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} |
679 virtual void PaintContents(SkCanvas*, gfx::Rect, gfx::RectF*) OVERRIDE | 572 |
680 { | 573 private: |
681 // Set layer opacity to 0. | 574 Layer* test_layer_; |
682 if (m_testLayer) | |
683 m_testLayer->SetOpacity(0); | |
684 } | |
685 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} | |
686 | |
687 private: | |
688 Layer* m_testLayer; | |
689 }; | 575 }; |
690 | 576 |
691 class ContentLayerWithUpdateTracking : public ContentLayer { | 577 class ContentLayerWithUpdateTracking : public ContentLayer { |
692 public: | 578 public: |
693 static scoped_refptr<ContentLayerWithUpdateTracking> Create(ContentLayerClie
nt* client) { return make_scoped_refptr(new ContentLayerWithUpdateTracking(clien
t)); } | 579 static scoped_refptr<ContentLayerWithUpdateTracking> Create( |
694 | 580 ContentLayerClient* client) { |
695 int paintContentsCount() { return m_paintContentsCount; } | 581 return make_scoped_refptr(new ContentLayerWithUpdateTracking(client)); |
696 void resetPaintContentsCount() { m_paintContentsCount = 0; } | 582 } |
697 | 583 |
698 virtual void Update(ResourceUpdateQueue* queue, const OcclusionTracker* occl
usion, RenderingStats* stats) OVERRIDE | 584 int PaintContentsCount() { return paint_contents_count_; } |
699 { | 585 void ResetPaintContentsCount() { paint_contents_count_ = 0; } |
700 ContentLayer::Update(queue, occlusion, stats); | 586 |
701 m_paintContentsCount++; | 587 virtual void Update(ResourceUpdateQueue* queue, |
702 } | 588 const OcclusionTracker* occlusion, |
703 | 589 RenderingStats* stats) OVERRIDE { |
704 private: | 590 ContentLayer::Update(queue, occlusion, stats); |
705 explicit ContentLayerWithUpdateTracking(ContentLayerClient* client) | 591 paint_contents_count_++; |
706 : ContentLayer(client) | 592 } |
707 , m_paintContentsCount(0) | 593 |
708 { | 594 private: |
709 SetAnchorPoint(gfx::PointF(0, 0)); | 595 explicit ContentLayerWithUpdateTracking(ContentLayerClient* client) |
710 SetBounds(gfx::Size(10, 10)); | 596 : ContentLayer(client), paint_contents_count_(0) { |
711 SetIsDrawable(true); | 597 SetAnchorPoint(gfx::PointF(0.f, 0.f)); |
712 } | 598 SetBounds(gfx::Size(10, 10)); |
713 virtual ~ContentLayerWithUpdateTracking() | 599 SetIsDrawable(true); |
714 { | 600 } |
715 } | 601 virtual ~ContentLayerWithUpdateTracking() {} |
716 | 602 |
717 int m_paintContentsCount; | 603 int paint_contents_count_; |
718 }; | 604 }; |
719 | 605 |
720 // Layer opacity change during paint should not prevent compositor resources fro
m being updated during commit. | 606 // Layer opacity change during paint should not prevent compositor resources |
| 607 // from being updated during commit. |
721 class LayerTreeHostTestOpacityChange : public LayerTreeHostTest { | 608 class LayerTreeHostTestOpacityChange : public LayerTreeHostTest { |
722 public: | 609 public: |
723 LayerTreeHostTestOpacityChange() | 610 LayerTreeHostTestOpacityChange() |
724 : m_testOpacityChangeDelegate() | 611 : test_opacity_change_delegate_(), |
725 , m_updateCheckLayer(ContentLayerWithUpdateTracking::Create(&m_testOpaci
tyChangeDelegate)) | 612 update_check_layer_(ContentLayerWithUpdateTracking::Create( |
726 { | 613 &test_opacity_change_delegate_)) { |
727 m_testOpacityChangeDelegate.setTestLayer(m_updateCheckLayer.get()); | 614 test_opacity_change_delegate_.SetTestLayer(update_check_layer_.get()); |
728 } | 615 } |
729 | 616 |
730 virtual void BeginTest() OVERRIDE | 617 virtual void BeginTest() OVERRIDE { |
731 { | 618 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); |
732 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10))
; | 619 layer_tree_host()->root_layer()->AddChild(update_check_layer_); |
733 layer_tree_host()->root_layer()->AddChild(m_updateCheckLayer); | 620 |
734 | 621 PostSetNeedsCommitToMainThread(); |
735 PostSetNeedsCommitToMainThread(); | 622 } |
736 } | 623 |
737 | 624 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
738 virtual void CommitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | 625 EndTest(); |
739 { | 626 } |
740 EndTest(); | 627 |
741 } | 628 virtual void AfterTest() OVERRIDE { |
742 | 629 // Update() should have been called once. |
743 virtual void AfterTest() OVERRIDE | 630 EXPECT_EQ(1, update_check_layer_->PaintContentsCount()); |
744 { | 631 |
745 // Update() should have been called once. | 632 // clear update_check_layer_ so LayerTreeHost dies. |
746 EXPECT_EQ(1, m_updateCheckLayer->paintContentsCount()); | 633 update_check_layer_ = NULL; |
747 | 634 } |
748 // clear m_updateCheckLayer so LayerTreeHost dies. | 635 |
749 m_updateCheckLayer = NULL; | 636 private: |
750 } | 637 TestOpacityChangeLayerDelegate test_opacity_change_delegate_; |
751 | 638 scoped_refptr<ContentLayerWithUpdateTracking> update_check_layer_; |
752 private: | 639 }; |
753 TestOpacityChangeLayerDelegate m_testOpacityChangeDelegate; | 640 |
754 scoped_refptr<ContentLayerWithUpdateTracking> m_updateCheckLayer; | 641 MULTI_THREAD_TEST_F(LayerTreeHostTestOpacityChange); |
755 }; | |
756 | |
757 MULTI_THREAD_TEST_F(LayerTreeHostTestOpacityChange) | |
758 | 642 |
759 class NoScaleContentLayer : public ContentLayer { | 643 class NoScaleContentLayer : public ContentLayer { |
760 public: | 644 public: |
761 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client)
{ return make_scoped_refptr(new NoScaleContentLayer(client)); } | 645 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
762 | 646 return make_scoped_refptr(new NoScaleContentLayer(client)); |
763 virtual void CalculateContentsScale( | 647 } |
764 float ideal_contents_scale, | 648 |
765 bool animating_transform_to_screen, | 649 virtual void CalculateContentsScale(float ideal_contents_scale, |
766 float* contents_scale_x, | 650 bool animating_transform_to_screen, |
767 float* contents_scale_y, | 651 float* contents_scale_x, |
768 gfx::Size* contentBounds) OVERRIDE | 652 float* contents_scale_y, |
769 { | 653 gfx::Size* contentBounds) OVERRIDE { |
770 // Skip over the ContentLayer's method to the base Layer class. | 654 // Skip over the ContentLayer's method to the base Layer class. |
771 Layer::CalculateContentsScale( | 655 Layer::CalculateContentsScale(ideal_contents_scale, |
772 ideal_contents_scale, | 656 animating_transform_to_screen, |
773 animating_transform_to_screen, | 657 contents_scale_x, |
774 contents_scale_x, | 658 contents_scale_y, |
775 contents_scale_y, | 659 contentBounds); |
776 contentBounds); | 660 } |
777 } | 661 |
778 | 662 private: |
779 private: | 663 explicit NoScaleContentLayer(ContentLayerClient* client) |
780 explicit NoScaleContentLayer(ContentLayerClient* client) | 664 : ContentLayer(client) {} |
781 : ContentLayer(client) { } | 665 virtual ~NoScaleContentLayer() {} |
782 virtual ~NoScaleContentLayer() { } | 666 }; |
783 }; | 667 |
784 | 668 class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers |
785 class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers : public LayerTr
eeHostTest { | 669 : public LayerTreeHostTest { |
786 public: | 670 public: |
787 | 671 LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() |
788 LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() | 672 : root_layer_(NoScaleContentLayer::Create(&client_)), |
789 : m_rootLayer(NoScaleContentLayer::Create(&client_)) | 673 child_layer_(ContentLayer::Create(&client_)) {} |
790 , m_childLayer(ContentLayer::Create(&client_)) | 674 |
791 { | 675 virtual void BeginTest() OVERRIDE { |
792 } | 676 layer_tree_host()->SetViewportSize(gfx::Size(40, 40), gfx::Size(60, 60)); |
793 | 677 layer_tree_host()->SetDeviceScaleFactor(1.5); |
794 virtual void BeginTest() OVERRIDE | 678 EXPECT_EQ(gfx::Size(40, 40), layer_tree_host()->layout_viewport_size()); |
795 { | 679 EXPECT_EQ(gfx::Size(60, 60), layer_tree_host()->device_viewport_size()); |
796 layer_tree_host()->SetViewportSize(gfx::Size(40, 40), gfx::Size(60, 60))
; | 680 |
797 layer_tree_host()->SetDeviceScaleFactor(1.5); | 681 root_layer_->AddChild(child_layer_); |
798 EXPECT_EQ(gfx::Size(40, 40), layer_tree_host()->layout_viewport_size()); | 682 |
799 EXPECT_EQ(gfx::Size(60, 60), layer_tree_host()->device_viewport_size()); | 683 root_layer_->SetIsDrawable(true); |
800 | 684 root_layer_->SetBounds(gfx::Size(30, 30)); |
801 m_rootLayer->AddChild(m_childLayer); | 685 root_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); |
802 | 686 |
803 m_rootLayer->SetIsDrawable(true); | 687 child_layer_->SetIsDrawable(true); |
804 m_rootLayer->SetBounds(gfx::Size(30, 30)); | 688 child_layer_->SetPosition(gfx::Point(2, 2)); |
805 m_rootLayer->SetAnchorPoint(gfx::PointF(0, 0)); | 689 child_layer_->SetBounds(gfx::Size(10, 10)); |
806 | 690 child_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); |
807 m_childLayer->SetIsDrawable(true); | 691 |
808 m_childLayer->SetPosition(gfx::Point(2, 2)); | 692 layer_tree_host()->SetRootLayer(root_layer_); |
809 m_childLayer->SetBounds(gfx::Size(10, 10)); | 693 |
810 m_childLayer->SetAnchorPoint(gfx::PointF(0, 0)); | 694 ASSERT_TRUE(layer_tree_host()->InitializeRendererIfNeeded()); |
811 | 695 ResourceUpdateQueue queue; |
812 layer_tree_host()->SetRootLayer(m_rootLayer); | 696 layer_tree_host()->UpdateLayers(&queue, std::numeric_limits<size_t>::max()); |
813 | 697 PostSetNeedsCommitToMainThread(); |
814 ASSERT_TRUE(layer_tree_host()->InitializeRendererIfNeeded()); | 698 } |
815 ResourceUpdateQueue queue; | 699 |
816 layer_tree_host()->UpdateLayers(&queue, std::numeric_limits<size_t>::max
()); | 700 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
817 PostSetNeedsCommitToMainThread(); | 701 // Should only do one commit. |
818 } | 702 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); |
819 | 703 // Device scale factor should come over to impl. |
820 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 704 EXPECT_NEAR(impl->device_scale_factor(), 1.5f, 0.00001f); |
821 { | 705 |
822 // Should only do one commit. | 706 // Both layers are on impl. |
823 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); | 707 ASSERT_EQ(1u, impl->active_tree()->root_layer()->children().size()); |
824 // Device scale factor should come over to impl. | 708 |
825 EXPECT_NEAR(impl->device_scale_factor(), 1.5, 0.00001); | 709 // Device viewport is scaled. |
826 | 710 EXPECT_EQ(gfx::Size(40, 40), impl->layout_viewport_size()); |
827 // Both layers are on impl. | 711 EXPECT_EQ(gfx::Size(60, 60), impl->device_viewport_size()); |
828 ASSERT_EQ(1u, impl->active_tree()->root_layer()->children().size()); | 712 |
829 | 713 LayerImpl* root = impl->active_tree()->root_layer(); |
830 // Device viewport is scaled. | 714 LayerImpl* child = impl->active_tree()->root_layer()->children()[0]; |
831 EXPECT_EQ(gfx::Size(40, 40), impl->layout_viewport_size()); | 715 |
832 EXPECT_EQ(gfx::Size(60, 60), impl->device_viewport_size()); | 716 // Positions remain in layout pixels. |
833 | 717 EXPECT_EQ(gfx::Point(0, 0), root->position()); |
834 LayerImpl* root = impl->active_tree()->root_layer(); | 718 EXPECT_EQ(gfx::Point(2, 2), child->position()); |
835 LayerImpl* child = impl->active_tree()->root_layer()->children()[0]; | 719 |
836 | 720 // Compute all the layer transforms for the frame. |
837 // Positions remain in layout pixels. | 721 LayerTreeHostImpl::FrameData frame_data; |
838 EXPECT_EQ(gfx::Point(0, 0), root->position()); | 722 impl->PrepareToDraw(&frame_data); |
839 EXPECT_EQ(gfx::Point(2, 2), child->position()); | 723 impl->DidDrawAllLayers(frame_data); |
840 | 724 |
841 // Compute all the layer transforms for the frame. | 725 const LayerTreeHostImpl::LayerList& render_surface_layer_list = |
842 LayerTreeHostImpl::FrameData frameData; | 726 *frame_data.render_surface_layer_list; |
843 impl->PrepareToDraw(&frameData); | 727 |
844 impl->DidDrawAllLayers(frameData); | 728 // Both layers should be drawing into the root render surface. |
845 | 729 ASSERT_EQ(1u, render_surface_layer_list.size()); |
846 const LayerTreeHostImpl::LayerList& renderSurfaceLayerList = | 730 ASSERT_EQ(root->render_surface(), |
847 *frameData.render_surface_layer_list; | 731 render_surface_layer_list[0]->render_surface()); |
848 | 732 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
849 // Both layers should be drawing into the root render surface. | 733 |
850 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | 734 // The root render surface is the size of the viewport. |
851 ASSERT_EQ(root->render_surface(), renderSurfaceLayerList[0]->render_surf
ace()); | 735 EXPECT_RECT_EQ(gfx::Rect(0, 0, 60, 60), |
852 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); | 736 root->render_surface()->content_rect()); |
853 | 737 |
854 // The root render surface is the size of the viewport. | 738 // The content bounds of the child should be scaled. |
855 EXPECT_RECT_EQ(gfx::Rect(0, 0, 60, 60), root->render_surface()->content_
rect()); | 739 gfx::Size child_bounds_scaled = |
856 | 740 gfx::ToCeiledSize(gfx::ScaleSize(child->bounds(), 1.5)); |
857 // The content bounds of the child should be scaled. | 741 EXPECT_EQ(child_bounds_scaled, child->content_bounds()); |
858 gfx::Size childBoundsScaled = gfx::ToCeiledSize(gfx::ScaleSize(child->bo
unds(), 1.5)); | 742 |
859 EXPECT_EQ(childBoundsScaled, child->content_bounds()); | 743 gfx::Transform scale_transform; |
860 | 744 scale_transform.Scale(impl->device_scale_factor(), |
861 gfx::Transform scaleTransform; | 745 impl->device_scale_factor()); |
862 scaleTransform.Scale(impl->device_scale_factor(), impl->device_scale_fac
tor()); | 746 |
863 | 747 // The root layer is scaled by 2x. |
864 // The root layer is scaled by 2x. | 748 gfx::Transform root_screen_space_transform = scale_transform; |
865 gfx::Transform rootScreenSpaceTransform = scaleTransform; | 749 gfx::Transform root_draw_transform = scale_transform; |
866 gfx::Transform rootDrawTransform = scaleTransform; | 750 |
867 | 751 EXPECT_EQ(root_draw_transform, root->draw_transform()); |
868 EXPECT_EQ(rootDrawTransform, root->draw_transform()); | 752 EXPECT_EQ(root_screen_space_transform, root->screen_space_transform()); |
869 EXPECT_EQ(rootScreenSpaceTransform, root->screen_space_transform()); | 753 |
870 | 754 // The child is at position 2,2, which is transformed to 3,3 after the scale |
871 // The child is at position 2,2, which is transformed to 3,3 after the s
cale | 755 gfx::Transform child_screen_space_transform; |
872 gfx::Transform childScreenSpaceTransform; | 756 child_screen_space_transform.Translate(3.f, 3.f); |
873 childScreenSpaceTransform.Translate(3, 3); | 757 gfx::Transform child_draw_transform = child_screen_space_transform; |
874 gfx::Transform childDrawTransform = childScreenSpaceTransform; | 758 |
875 | 759 EXPECT_TRANSFORMATION_MATRIX_EQ(child_draw_transform, |
876 EXPECT_TRANSFORMATION_MATRIX_EQ(childDrawTransform, child->draw_transfor
m()); | 760 child->draw_transform()); |
877 EXPECT_TRANSFORMATION_MATRIX_EQ(childScreenSpaceTransform, child->screen
_space_transform()); | 761 EXPECT_TRANSFORMATION_MATRIX_EQ(child_screen_space_transform, |
878 | 762 child->screen_space_transform()); |
879 EndTest(); | 763 |
880 } | 764 EndTest(); |
881 | 765 } |
882 virtual void AfterTest() OVERRIDE | 766 |
883 { | 767 virtual void AfterTest() OVERRIDE { |
884 m_rootLayer = NULL; | 768 root_layer_ = NULL; |
885 m_childLayer = NULL; | 769 child_layer_ = NULL; |
886 } | 770 } |
887 | 771 |
888 private: | 772 private: |
889 FakeContentLayerClient client_; | 773 FakeContentLayerClient client_; |
890 scoped_refptr<NoScaleContentLayer> m_rootLayer; | 774 scoped_refptr<NoScaleContentLayer> root_layer_; |
891 scoped_refptr<ContentLayer> m_childLayer; | 775 scoped_refptr<ContentLayer> child_layer_; |
892 }; | 776 }; |
893 | 777 |
894 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers) | 778 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); |
895 | 779 |
896 // Verify atomicity of commits and reuse of textures. | 780 // Verify atomicity of commits and reuse of textures. |
897 class LayerTreeHostTestAtomicCommit : public LayerTreeHostTest { | 781 class LayerTreeHostTestAtomicCommit : public LayerTreeHostTest { |
898 public: | 782 public: |
899 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE | 783 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 784 // Make sure partial texture updates are turned off. |
| 785 settings->max_partial_texture_updates = 0; |
| 786 // Linear fade animator prevents scrollbars from drawing immediately. |
| 787 settings->use_linear_fade_scrollbar_animator = false; |
| 788 } |
| 789 |
| 790 virtual void SetupTree() OVERRIDE { |
| 791 layer_ = FakeContentLayer::Create(&client_); |
| 792 layer_->SetBounds(gfx::Size(10, 20)); |
| 793 |
| 794 bool paint_scrollbar = true; |
| 795 bool has_thumb = false; |
| 796 scrollbar_ = |
| 797 FakeScrollbarLayer::Create(paint_scrollbar, has_thumb, layer_->id()); |
| 798 scrollbar_->SetPosition(gfx::Point(0, 10)); |
| 799 scrollbar_->SetBounds(gfx::Size(10, 10)); |
| 800 |
| 801 layer_->AddChild(scrollbar_); |
| 802 |
| 803 layer_tree_host()->SetRootLayer(layer_); |
| 804 LayerTreeHostTest::SetupTree(); |
| 805 } |
| 806 |
| 807 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 808 |
| 809 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 810 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); |
| 811 |
| 812 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
| 813 impl->output_surface()->context3d()); |
| 814 |
| 815 switch (impl->active_tree()->source_frame_number()) { |
| 816 case 0: |
| 817 // Number of textures should be one for each layer |
| 818 ASSERT_EQ(2, context->NumTextures()); |
| 819 // Number of textures used for commit should be one for each layer. |
| 820 EXPECT_EQ(2, context->NumUsedTextures()); |
| 821 // Verify that used texture is correct. |
| 822 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); |
| 823 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); |
| 824 |
| 825 context->ResetUsedTextures(); |
| 826 PostSetNeedsCommitToMainThread(); |
| 827 break; |
| 828 case 1: |
| 829 // Number of textures should be doubled as the first textures |
| 830 // are used by impl thread and cannot by used for update. |
| 831 ASSERT_EQ(4, context->NumTextures()); |
| 832 // Number of textures used for commit should still be |
| 833 // one for each layer. |
| 834 EXPECT_EQ(2, context->NumUsedTextures()); |
| 835 // First textures should not have been used. |
| 836 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); |
| 837 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); |
| 838 // New textures should have been used. |
| 839 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); |
| 840 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); |
| 841 |
| 842 context->ResetUsedTextures(); |
| 843 PostSetNeedsCommitToMainThread(); |
| 844 break; |
| 845 case 2: |
| 846 EndTest(); |
| 847 break; |
| 848 default: |
| 849 NOTREACHED(); |
| 850 break; |
| 851 } |
| 852 } |
| 853 |
| 854 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 855 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
| 856 impl->output_surface()->context3d()); |
| 857 |
| 858 // Number of textures used for draw should always be one for each layer. |
| 859 EXPECT_EQ(2, context->NumUsedTextures()); |
| 860 context->ResetUsedTextures(); |
| 861 } |
| 862 |
| 863 virtual void Layout() OVERRIDE { |
| 864 layer_->SetNeedsDisplay(); |
| 865 scrollbar_->SetNeedsDisplay(); |
| 866 } |
| 867 |
| 868 virtual void AfterTest() OVERRIDE {} |
| 869 |
| 870 private: |
| 871 FakeContentLayerClient client_; |
| 872 scoped_refptr<FakeContentLayer> layer_; |
| 873 scoped_refptr<FakeScrollbarLayer> scrollbar_; |
| 874 }; |
| 875 |
| 876 MULTI_THREAD_TEST_F(LayerTreeHostTestAtomicCommit); |
| 877 |
| 878 static void SetLayerPropertiesForTesting(Layer* layer, |
| 879 Layer* parent, |
| 880 const gfx::Transform& transform, |
| 881 gfx::PointF anchor, |
| 882 gfx::PointF position, |
| 883 gfx::Size bounds, |
| 884 bool opaque) { |
| 885 layer->RemoveAllChildren(); |
| 886 if (parent) |
| 887 parent->AddChild(layer); |
| 888 layer->SetTransform(transform); |
| 889 layer->SetAnchorPoint(anchor); |
| 890 layer->SetPosition(position); |
| 891 layer->SetBounds(bounds); |
| 892 layer->SetContentsOpaque(opaque); |
| 893 } |
| 894 |
| 895 class LayerTreeHostTestAtomicCommitWithPartialUpdate |
| 896 : public LayerTreeHostTest { |
| 897 public: |
| 898 LayerTreeHostTestAtomicCommitWithPartialUpdate() : num_commits_(0) {} |
| 899 |
| 900 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 901 // Allow one partial texture update. |
| 902 settings->max_partial_texture_updates = 1; |
| 903 // Linear fade animator prevents scrollbars from drawing immediately. |
| 904 settings->use_linear_fade_scrollbar_animator = false; |
| 905 } |
| 906 |
| 907 virtual void SetupTree() OVERRIDE { |
| 908 parent_ = FakeContentLayer::Create(&client_); |
| 909 parent_->SetBounds(gfx::Size(10, 20)); |
| 910 |
| 911 child_ = FakeContentLayer::Create(&client_); |
| 912 child_->SetPosition(gfx::Point(0, 10)); |
| 913 child_->SetBounds(gfx::Size(3, 10)); |
| 914 |
| 915 bool paint_scrollbar = true; |
| 916 bool has_thumb = false; |
| 917 scrollbar_with_paints_ = |
| 918 FakeScrollbarLayer::Create(paint_scrollbar, has_thumb, parent_->id()); |
| 919 scrollbar_with_paints_->SetPosition(gfx::Point(3, 10)); |
| 920 scrollbar_with_paints_->SetBounds(gfx::Size(3, 10)); |
| 921 |
| 922 paint_scrollbar = false; |
| 923 scrollbar_without_paints_ = |
| 924 FakeScrollbarLayer::Create(paint_scrollbar, has_thumb, parent_->id()); |
| 925 scrollbar_without_paints_->SetPosition(gfx::Point(6, 10)); |
| 926 scrollbar_without_paints_->SetBounds(gfx::Size(3, 10)); |
| 927 |
| 928 parent_->AddChild(child_); |
| 929 parent_->AddChild(scrollbar_with_paints_); |
| 930 parent_->AddChild(scrollbar_without_paints_); |
| 931 |
| 932 layer_tree_host()->SetRootLayer(parent_); |
| 933 LayerTreeHostTest::SetupTree(); |
| 934 } |
| 935 |
| 936 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 937 |
| 938 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 939 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates); |
| 940 |
| 941 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
| 942 impl->output_surface()->context3d()); |
| 943 |
| 944 switch (impl->active_tree()->source_frame_number()) { |
| 945 case 0: |
| 946 // Number of textures should be one for each layer. |
| 947 ASSERT_EQ(4, context->NumTextures()); |
| 948 // Number of textures used for commit should be one for each layer. |
| 949 EXPECT_EQ(4, context->NumUsedTextures()); |
| 950 // Verify that used textures are correct. |
| 951 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); |
| 952 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); |
| 953 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); |
| 954 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); |
| 955 |
| 956 context->ResetUsedTextures(); |
| 957 PostSetNeedsCommitToMainThread(); |
| 958 break; |
| 959 case 1: |
| 960 // Number of textures should be two for each content layer and one |
| 961 // for each scrollbar, since they always do a partial update. |
| 962 ASSERT_EQ(6, context->NumTextures()); |
| 963 // Number of textures used for commit should be one for each content |
| 964 // layer, and one for the scrollbar layer that paints. |
| 965 EXPECT_EQ(3, context->NumUsedTextures()); |
| 966 |
| 967 // First content textures should not have been used. |
| 968 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); |
| 969 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); |
| 970 // The non-painting scrollbar's texture wasn't updated. |
| 971 EXPECT_FALSE(context->UsedTexture(context->TextureAt(2))); |
| 972 // The painting scrollbar's partial update texture was used. |
| 973 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); |
| 974 // New textures should have been used. |
| 975 EXPECT_TRUE(context->UsedTexture(context->TextureAt(4))); |
| 976 EXPECT_TRUE(context->UsedTexture(context->TextureAt(5))); |
| 977 |
| 978 context->ResetUsedTextures(); |
| 979 PostSetNeedsCommitToMainThread(); |
| 980 break; |
| 981 case 2: |
| 982 // Number of textures should be two for each content layer and one |
| 983 // for each scrollbar, since they always do a partial update. |
| 984 ASSERT_EQ(6, context->NumTextures()); |
| 985 // Number of textures used for commit should be one for each content |
| 986 // layer, and one for the scrollbar layer that paints. |
| 987 EXPECT_EQ(3, context->NumUsedTextures()); |
| 988 |
| 989 // The non-painting scrollbar's texture wasn't updated. |
| 990 EXPECT_FALSE(context->UsedTexture(context->TextureAt(2))); |
| 991 // The painting scrollbar does a partial update. |
| 992 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); |
| 993 // One content layer does a partial update also. |
| 994 EXPECT_TRUE(context->UsedTexture(context->TextureAt(4))); |
| 995 EXPECT_FALSE(context->UsedTexture(context->TextureAt(5))); |
| 996 |
| 997 context->ResetUsedTextures(); |
| 998 PostSetNeedsCommitToMainThread(); |
| 999 break; |
| 1000 case 3: |
| 1001 // No textures should be used for commit. |
| 1002 EXPECT_EQ(0, context->NumUsedTextures()); |
| 1003 |
| 1004 context->ResetUsedTextures(); |
| 1005 PostSetNeedsCommitToMainThread(); |
| 1006 break; |
| 1007 case 4: |
| 1008 // Number of textures used for commit should be two. One for the |
| 1009 // content layer, and one for the painting scrollbar. The |
| 1010 // non-painting scrollbar doesn't update its texture. |
| 1011 EXPECT_EQ(2, context->NumUsedTextures()); |
| 1012 |
| 1013 context->ResetUsedTextures(); |
| 1014 PostSetNeedsCommitToMainThread(); |
| 1015 break; |
| 1016 case 5: |
| 1017 EndTest(); |
| 1018 break; |
| 1019 default: |
| 1020 NOTREACHED(); |
| 1021 break; |
| 1022 } |
| 1023 } |
| 1024 |
| 1025 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1026 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
| 1027 impl->output_surface()->context3d()); |
| 1028 |
| 1029 // Number of textures used for drawing should one per layer except for |
| 1030 // frame 3 where the viewport only contains one layer. |
| 1031 if (impl->active_tree()->source_frame_number() == 3) |
| 1032 EXPECT_EQ(1, context->NumUsedTextures()); |
| 1033 else |
| 1034 EXPECT_EQ(4, context->NumUsedTextures()); |
| 1035 |
| 1036 context->ResetUsedTextures(); |
| 1037 } |
| 1038 |
| 1039 virtual void Layout() OVERRIDE { |
| 1040 switch (num_commits_++) { |
| 1041 case 0: |
| 1042 case 1: |
| 1043 parent_->SetNeedsDisplay(); |
| 1044 child_->SetNeedsDisplay(); |
| 1045 scrollbar_with_paints_->SetNeedsDisplay(); |
| 1046 scrollbar_without_paints_->SetNeedsDisplay(); |
| 1047 break; |
| 1048 case 2: |
| 1049 // Damage part of layers. |
| 1050 parent_->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f)); |
| 1051 child_->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f)); |
| 1052 scrollbar_with_paints_->SetNeedsDisplayRect( |
| 1053 gfx::RectF(0.f, 0.f, 5.f, 5.f)); |
| 1054 scrollbar_without_paints_->SetNeedsDisplayRect( |
| 1055 gfx::RectF(0.f, 0.f, 5.f, 5.f)); |
| 1056 break; |
| 1057 case 3: |
| 1058 child_->SetNeedsDisplay(); |
| 1059 scrollbar_with_paints_->SetNeedsDisplay(); |
| 1060 scrollbar_without_paints_->SetNeedsDisplay(); |
| 1061 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), |
| 1062 gfx::Size(10, 10)); |
| 1063 break; |
| 1064 case 4: |
| 1065 layer_tree_host()->SetViewportSize(gfx::Size(10, 20), |
| 1066 gfx::Size(10, 20)); |
| 1067 break; |
| 1068 case 5: |
| 1069 break; |
| 1070 default: |
| 1071 NOTREACHED(); |
| 1072 break; |
| 1073 } |
| 1074 } |
| 1075 |
| 1076 virtual void AfterTest() OVERRIDE {} |
| 1077 |
| 1078 private: |
| 1079 FakeContentLayerClient client_; |
| 1080 scoped_refptr<FakeContentLayer> parent_; |
| 1081 scoped_refptr<FakeContentLayer> child_; |
| 1082 scoped_refptr<FakeScrollbarLayer> scrollbar_with_paints_; |
| 1083 scoped_refptr<FakeScrollbarLayer> scrollbar_without_paints_; |
| 1084 int num_commits_; |
| 1085 }; |
| 1086 |
| 1087 MULTI_THREAD_TEST_F(LayerTreeHostTestAtomicCommitWithPartialUpdate); |
| 1088 |
| 1089 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest { |
| 1090 public: |
| 1091 LayerTreeHostTestFinishAllRendering() : once_(false), draw_count_(0) {} |
| 1092 |
| 1093 virtual void BeginTest() OVERRIDE { |
| 1094 layer_tree_host()->SetNeedsRedraw(); |
| 1095 PostSetNeedsCommitToMainThread(); |
| 1096 } |
| 1097 |
| 1098 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1099 if (once_) |
| 1100 return; |
| 1101 once_ = true; |
| 1102 layer_tree_host()->SetNeedsRedraw(); |
| 1103 layer_tree_host()->AcquireLayerTextures(); |
900 { | 1104 { |
901 // Make sure partial texture updates are turned off. | 1105 base::AutoLock lock(lock_); |
902 settings->max_partial_texture_updates = 0; | 1106 draw_count_ = 0; |
903 // Linear fade animator prevents scrollbars from drawing immediately. | 1107 } |
904 settings->use_linear_fade_scrollbar_animator = false; | 1108 layer_tree_host()->FinishAllRendering(); |
905 } | |
906 | |
907 virtual void SetupTree() OVERRIDE | |
908 { | 1109 { |
909 m_layer = FakeContentLayer::Create(&client_); | 1110 base::AutoLock lock(lock_); |
910 m_layer->SetBounds(gfx::Size(10, 20)); | 1111 EXPECT_EQ(0, draw_count_); |
911 | 1112 } |
912 bool paint_scrollbar = true; | 1113 EndTest(); |
913 bool has_thumb = false; | 1114 } |
914 m_scrollbar = FakeScrollbarLayer::Create( | 1115 |
915 paint_scrollbar, has_thumb, m_layer->id()); | 1116 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
916 m_scrollbar->SetPosition(gfx::Point(0, 10)); | 1117 base::AutoLock lock(lock_); |
917 m_scrollbar->SetBounds(gfx::Size(10, 10)); | 1118 ++draw_count_; |
918 | 1119 } |
919 m_layer->AddChild(m_scrollbar); | 1120 |
920 | 1121 virtual void AfterTest() OVERRIDE {} |
921 layer_tree_host()->SetRootLayer(m_layer); | 1122 |
922 LayerTreeHostTest::SetupTree(); | 1123 private: |
923 } | 1124 bool once_; |
924 | 1125 base::Lock lock_; |
925 virtual void BeginTest() OVERRIDE | 1126 int draw_count_; |
926 { | 1127 }; |
| 1128 |
| 1129 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFinishAllRendering); |
| 1130 |
| 1131 class LayerTreeHostTestCompositeAndReadbackCleanup : public LayerTreeHostTest { |
| 1132 public: |
| 1133 LayerTreeHostTestCompositeAndReadbackCleanup() {} |
| 1134 |
| 1135 virtual void BeginTest() OVERRIDE { |
| 1136 Layer* root_layer = layer_tree_host()->root_layer(); |
| 1137 |
| 1138 char pixels[4]; |
| 1139 layer_tree_host()->CompositeAndReadback(static_cast<void*>(&pixels), |
| 1140 gfx::Rect(0, 0, 1, 1)); |
| 1141 EXPECT_FALSE(root_layer->render_surface()); |
| 1142 |
| 1143 EndTest(); |
| 1144 } |
| 1145 |
| 1146 virtual void AfterTest() OVERRIDE {} |
| 1147 }; |
| 1148 |
| 1149 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackCleanup); |
| 1150 |
| 1151 class LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit |
| 1152 : public LayerTreeHostTest { |
| 1153 public: |
| 1154 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit() |
| 1155 : root_layer_(ContentLayerWithUpdateTracking::Create(&fake_delegate_)), |
| 1156 surface_layer1_( |
| 1157 ContentLayerWithUpdateTracking::Create(&fake_delegate_)), |
| 1158 replica_layer1_( |
| 1159 ContentLayerWithUpdateTracking::Create(&fake_delegate_)), |
| 1160 surface_layer2_( |
| 1161 ContentLayerWithUpdateTracking::Create(&fake_delegate_)), |
| 1162 replica_layer2_( |
| 1163 ContentLayerWithUpdateTracking::Create(&fake_delegate_)) {} |
| 1164 |
| 1165 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 1166 settings->cache_render_pass_contents = true; |
| 1167 } |
| 1168 |
| 1169 virtual void BeginTest() OVERRIDE { |
| 1170 layer_tree_host()->SetViewportSize(gfx::Size(100, 100), |
| 1171 gfx::Size(100, 100)); |
| 1172 |
| 1173 root_layer_->SetBounds(gfx::Size(100, 100)); |
| 1174 surface_layer1_->SetBounds(gfx::Size(100, 100)); |
| 1175 surface_layer1_->SetForceRenderSurface(true); |
| 1176 surface_layer1_->SetOpacity(0.5f); |
| 1177 surface_layer2_->SetBounds(gfx::Size(100, 100)); |
| 1178 surface_layer2_->SetForceRenderSurface(true); |
| 1179 surface_layer2_->SetOpacity(0.5f); |
| 1180 |
| 1181 surface_layer1_->SetReplicaLayer(replica_layer1_.get()); |
| 1182 surface_layer2_->SetReplicaLayer(replica_layer2_.get()); |
| 1183 |
| 1184 root_layer_->AddChild(surface_layer1_); |
| 1185 surface_layer1_->AddChild(surface_layer2_); |
| 1186 layer_tree_host()->SetRootLayer(root_layer_); |
| 1187 |
| 1188 PostSetNeedsCommitToMainThread(); |
| 1189 } |
| 1190 |
| 1191 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1192 Renderer* renderer = host_impl->renderer(); |
| 1193 RenderPass::Id surface1_render_pass_id = host_impl->active_tree() |
| 1194 ->root_layer()->children()[0]->render_surface()->RenderPassId(); |
| 1195 RenderPass::Id surface2_render_pass_id = |
| 1196 host_impl->active_tree()->root_layer()->children()[0]->children()[0] |
| 1197 ->render_surface()->RenderPassId(); |
| 1198 |
| 1199 switch (host_impl->active_tree()->source_frame_number()) { |
| 1200 case 0: |
| 1201 EXPECT_TRUE(renderer->HaveCachedResourcesForRenderPassId( |
| 1202 surface1_render_pass_id)); |
| 1203 EXPECT_TRUE(renderer->HaveCachedResourcesForRenderPassId( |
| 1204 surface2_render_pass_id)); |
| 1205 |
| 1206 // Reduce the memory limit to only fit the root layer and one render |
| 1207 // surface. This prevents any contents drawing into surfaces |
| 1208 // from being allocated. |
| 1209 host_impl->SetManagedMemoryPolicy( |
| 1210 ManagedMemoryPolicy(100 * 100 * 4 * 2)); |
| 1211 break; |
| 1212 case 1: |
| 1213 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( |
| 1214 surface1_render_pass_id)); |
| 1215 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( |
| 1216 surface2_render_pass_id)); |
| 1217 |
| 1218 EndTest(); |
| 1219 break; |
| 1220 } |
| 1221 } |
| 1222 |
| 1223 virtual void AfterTest() OVERRIDE { |
| 1224 EXPECT_EQ(2, root_layer_->PaintContentsCount()); |
| 1225 EXPECT_EQ(2, surface_layer1_->PaintContentsCount()); |
| 1226 EXPECT_EQ(2, surface_layer2_->PaintContentsCount()); |
| 1227 |
| 1228 // Clear layer references so LayerTreeHost dies. |
| 1229 root_layer_ = NULL; |
| 1230 surface_layer1_ = NULL; |
| 1231 replica_layer1_ = NULL; |
| 1232 surface_layer2_ = NULL; |
| 1233 replica_layer2_ = NULL; |
| 1234 } |
| 1235 |
| 1236 private: |
| 1237 FakeContentLayerClient fake_delegate_; |
| 1238 scoped_refptr<ContentLayerWithUpdateTracking> root_layer_; |
| 1239 scoped_refptr<ContentLayerWithUpdateTracking> surface_layer1_; |
| 1240 scoped_refptr<ContentLayerWithUpdateTracking> replica_layer1_; |
| 1241 scoped_refptr<ContentLayerWithUpdateTracking> surface_layer2_; |
| 1242 scoped_refptr<ContentLayerWithUpdateTracking> replica_layer2_; |
| 1243 }; |
| 1244 |
| 1245 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1246 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit); |
| 1247 |
| 1248 class EvictionTestLayer : public Layer { |
| 1249 public: |
| 1250 static scoped_refptr<EvictionTestLayer> Create() { |
| 1251 return make_scoped_refptr(new EvictionTestLayer()); |
| 1252 } |
| 1253 |
| 1254 virtual void Update(ResourceUpdateQueue*, |
| 1255 const OcclusionTracker*, |
| 1256 RenderingStats*) OVERRIDE; |
| 1257 virtual bool DrawsContent() const OVERRIDE { return true; } |
| 1258 |
| 1259 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) |
| 1260 OVERRIDE; |
| 1261 virtual void PushPropertiesTo(LayerImpl* impl) OVERRIDE; |
| 1262 virtual void SetTexturePriorities(const PriorityCalculator&) OVERRIDE; |
| 1263 |
| 1264 bool HaveBackingTexture() const { |
| 1265 return texture_.get() ? texture_->have_backing_texture() : false; |
| 1266 } |
| 1267 |
| 1268 private: |
| 1269 EvictionTestLayer() : Layer() {} |
| 1270 virtual ~EvictionTestLayer() {} |
| 1271 |
| 1272 void CreateTextureIfNeeded() { |
| 1273 if (texture_.get()) |
| 1274 return; |
| 1275 texture_ = PrioritizedResource::Create( |
| 1276 layer_tree_host()->contents_texture_manager()); |
| 1277 texture_->SetDimensions(gfx::Size(10, 10), GL_RGBA); |
| 1278 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); |
| 1279 } |
| 1280 |
| 1281 scoped_ptr<PrioritizedResource> texture_; |
| 1282 SkBitmap bitmap_; |
| 1283 }; |
| 1284 |
| 1285 class EvictionTestLayerImpl : public LayerImpl { |
| 1286 public: |
| 1287 static scoped_ptr<EvictionTestLayerImpl> Create(LayerTreeImpl* tree_impl, |
| 1288 int id) { |
| 1289 return make_scoped_ptr(new EvictionTestLayerImpl(tree_impl, id)); |
| 1290 } |
| 1291 virtual ~EvictionTestLayerImpl() {} |
| 1292 |
| 1293 virtual void AppendQuads(QuadSink* quad_sink, |
| 1294 AppendQuadsData* append_quads_data) OVERRIDE { |
| 1295 ASSERT_TRUE(has_texture_); |
| 1296 ASSERT_NE(0u, layer_tree_impl()->resource_provider()->num_resources()); |
| 1297 } |
| 1298 |
| 1299 void SetHasTexture(bool has_texture) { has_texture_ = has_texture; } |
| 1300 |
| 1301 private: |
| 1302 EvictionTestLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 1303 : LayerImpl(tree_impl, id), has_texture_(false) {} |
| 1304 |
| 1305 bool has_texture_; |
| 1306 }; |
| 1307 |
| 1308 void EvictionTestLayer::SetTexturePriorities(const PriorityCalculator&) { |
| 1309 CreateTextureIfNeeded(); |
| 1310 if (!texture_.get()) |
| 1311 return; |
| 1312 texture_->set_request_priority(PriorityCalculator::UIPriority(true)); |
| 1313 } |
| 1314 |
| 1315 void EvictionTestLayer::Update(ResourceUpdateQueue* queue, |
| 1316 const OcclusionTracker*, |
| 1317 RenderingStats*) { |
| 1318 CreateTextureIfNeeded(); |
| 1319 if (!texture_.get()) |
| 1320 return; |
| 1321 |
| 1322 gfx::Rect full_rect(0, 0, 10, 10); |
| 1323 ResourceUpdate upload = ResourceUpdate::Create( |
| 1324 texture_.get(), &bitmap_, full_rect, full_rect, gfx::Vector2d()); |
| 1325 queue->AppendFullUpload(upload); |
| 1326 } |
| 1327 |
| 1328 scoped_ptr<LayerImpl> EvictionTestLayer::CreateLayerImpl( |
| 1329 LayerTreeImpl* tree_impl) { |
| 1330 return EvictionTestLayerImpl::Create(tree_impl, layer_id_) |
| 1331 .PassAs<LayerImpl>(); |
| 1332 } |
| 1333 |
| 1334 void EvictionTestLayer::PushPropertiesTo(LayerImpl* layer_impl) { |
| 1335 Layer::PushPropertiesTo(layer_impl); |
| 1336 |
| 1337 EvictionTestLayerImpl* test_layer_impl = |
| 1338 static_cast<EvictionTestLayerImpl*>(layer_impl); |
| 1339 test_layer_impl->SetHasTexture(texture_->have_backing_texture()); |
| 1340 } |
| 1341 |
| 1342 class LayerTreeHostTestEvictTextures : public LayerTreeHostTest { |
| 1343 public: |
| 1344 LayerTreeHostTestEvictTextures() |
| 1345 : layer_(EvictionTestLayer::Create()), |
| 1346 impl_for_evict_textures_(0), |
| 1347 num_commits_(0) {} |
| 1348 |
| 1349 virtual void BeginTest() OVERRIDE { |
| 1350 layer_tree_host()->SetRootLayer(layer_); |
| 1351 layer_tree_host()->SetViewportSize(gfx::Size(10, 20), gfx::Size(10, 20)); |
| 1352 |
| 1353 gfx::Transform identity_matrix; |
| 1354 SetLayerPropertiesForTesting(layer_.get(), |
| 1355 0, |
| 1356 identity_matrix, |
| 1357 gfx::PointF(0.f, 0.f), |
| 1358 gfx::PointF(0.f, 0.f), |
| 1359 gfx::Size(10, 20), |
| 1360 true); |
| 1361 |
| 1362 PostSetNeedsCommitToMainThread(); |
| 1363 } |
| 1364 |
| 1365 void PostEvictTextures() { |
| 1366 DCHECK(ImplThread()); |
| 1367 ImplThread()->PostTask( |
| 1368 base::Bind(&LayerTreeHostTestEvictTextures::EvictTexturesOnImplThread, |
| 1369 base::Unretained(this))); |
| 1370 } |
| 1371 |
| 1372 void EvictTexturesOnImplThread() { |
| 1373 DCHECK(impl_for_evict_textures_); |
| 1374 impl_for_evict_textures_->EnforceManagedMemoryPolicy( |
| 1375 ManagedMemoryPolicy(0)); |
| 1376 } |
| 1377 |
| 1378 // Commit 1: Just commit and draw normally, then post an eviction at the end |
| 1379 // that will trigger a commit. |
| 1380 // Commit 2: Triggered by the eviction, let it go through and then set |
| 1381 // needsCommit. |
| 1382 // Commit 3: Triggered by the setNeedsCommit. In Layout(), post an eviction |
| 1383 // task, which will be handled before the commit. Don't set needsCommit, it |
| 1384 // should have been posted. A frame should not be drawn (note, |
| 1385 // didCommitAndDrawFrame may be called anyway). |
| 1386 // Commit 4: Triggered by the eviction, let it go through and then set |
| 1387 // needsCommit. |
| 1388 // Commit 5: Triggered by the setNeedsCommit, post an eviction task in |
| 1389 // Layout(), a frame should not be drawn but a commit will be posted. |
| 1390 // Commit 6: Triggered by the eviction, post an eviction task in |
| 1391 // Layout(), which will be a noop, letting the commit (which recreates the |
| 1392 // textures) go through and draw a frame, then end the test. |
| 1393 // |
| 1394 // Commits 1+2 test the eviction recovery path where eviction happens outside |
| 1395 // of the beginFrame/commit pair. |
| 1396 // Commits 3+4 test the eviction recovery path where eviction happens inside |
| 1397 // the beginFrame/commit pair. |
| 1398 // Commits 5+6 test the path where an eviction happens during the eviction |
| 1399 // recovery path. |
| 1400 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1401 switch (num_commits_) { |
| 1402 case 1: |
| 1403 EXPECT_TRUE(layer_->HaveBackingTexture()); |
| 1404 PostEvictTextures(); |
| 1405 break; |
| 1406 case 2: |
| 1407 EXPECT_TRUE(layer_->HaveBackingTexture()); |
| 1408 layer_tree_host()->SetNeedsCommit(); |
| 1409 break; |
| 1410 case 3: |
| 1411 break; |
| 1412 case 4: |
| 1413 EXPECT_TRUE(layer_->HaveBackingTexture()); |
| 1414 layer_tree_host()->SetNeedsCommit(); |
| 1415 break; |
| 1416 case 5: |
| 1417 break; |
| 1418 case 6: |
| 1419 EXPECT_TRUE(layer_->HaveBackingTexture()); |
| 1420 EndTest(); |
| 1421 break; |
| 1422 default: |
| 1423 NOTREACHED(); |
| 1424 break; |
| 1425 } |
| 1426 } |
| 1427 |
| 1428 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1429 impl_for_evict_textures_ = impl; |
| 1430 } |
| 1431 |
| 1432 virtual void Layout() OVERRIDE { |
| 1433 ++num_commits_; |
| 1434 switch (num_commits_) { |
| 1435 case 1: |
| 1436 case 2: |
| 1437 break; |
| 1438 case 3: |
| 1439 PostEvictTextures(); |
| 1440 break; |
| 1441 case 4: |
| 1442 // We couldn't check in didCommitAndDrawFrame on commit 3, |
| 1443 // so check here. |
| 1444 EXPECT_FALSE(layer_->HaveBackingTexture()); |
| 1445 break; |
| 1446 case 5: |
| 1447 PostEvictTextures(); |
| 1448 break; |
| 1449 case 6: |
| 1450 // We couldn't check in didCommitAndDrawFrame on commit 5, |
| 1451 // so check here. |
| 1452 EXPECT_FALSE(layer_->HaveBackingTexture()); |
| 1453 PostEvictTextures(); |
| 1454 break; |
| 1455 default: |
| 1456 NOTREACHED(); |
| 1457 break; |
| 1458 } |
| 1459 } |
| 1460 |
| 1461 virtual void AfterTest() OVERRIDE {} |
| 1462 |
| 1463 private: |
| 1464 FakeContentLayerClient client_; |
| 1465 scoped_refptr<EvictionTestLayer> layer_; |
| 1466 LayerTreeHostImpl* impl_for_evict_textures_; |
| 1467 int num_commits_; |
| 1468 }; |
| 1469 |
| 1470 MULTI_THREAD_TEST_F(LayerTreeHostTestEvictTextures); |
| 1471 |
| 1472 class LayerTreeHostTestContinuousCommit : public LayerTreeHostTest { |
| 1473 public: |
| 1474 LayerTreeHostTestContinuousCommit() |
| 1475 : num_commit_complete_(0), num_draw_layers_(0) {} |
| 1476 |
| 1477 virtual void BeginTest() OVERRIDE { |
| 1478 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); |
| 1479 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); |
| 1480 |
| 1481 PostSetNeedsCommitToMainThread(); |
| 1482 } |
| 1483 |
| 1484 virtual void DidCommit() OVERRIDE { |
| 1485 if (num_draw_layers_ == 2) |
| 1486 return; |
| 1487 PostSetNeedsCommitToMainThread(); |
| 1488 } |
| 1489 |
| 1490 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1491 if (num_draw_layers_ == 1) |
| 1492 num_commit_complete_++; |
| 1493 } |
| 1494 |
| 1495 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1496 num_draw_layers_++; |
| 1497 if (num_draw_layers_ == 2) |
| 1498 EndTest(); |
| 1499 } |
| 1500 |
| 1501 virtual void AfterTest() OVERRIDE { |
| 1502 // Check that we didn't commit twice between first and second draw. |
| 1503 EXPECT_EQ(1, num_commit_complete_); |
| 1504 } |
| 1505 |
| 1506 private: |
| 1507 int num_commit_complete_; |
| 1508 int num_draw_layers_; |
| 1509 }; |
| 1510 |
| 1511 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousCommit); |
| 1512 |
| 1513 class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { |
| 1514 public: |
| 1515 LayerTreeHostTestContinuousInvalidate() |
| 1516 : num_commit_complete_(0), num_draw_layers_(0) {} |
| 1517 |
| 1518 virtual void BeginTest() OVERRIDE { |
| 1519 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); |
| 1520 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); |
| 1521 |
| 1522 content_layer_ = ContentLayer::Create(&fake_delegate_); |
| 1523 content_layer_->SetBounds(gfx::Size(10, 10)); |
| 1524 content_layer_->SetPosition(gfx::PointF(0.f, 0.f)); |
| 1525 content_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); |
| 1526 content_layer_->SetIsDrawable(true); |
| 1527 layer_tree_host()->root_layer()->AddChild(content_layer_); |
| 1528 |
| 1529 PostSetNeedsCommitToMainThread(); |
| 1530 } |
| 1531 |
| 1532 virtual void DidCommit() OVERRIDE { |
| 1533 if (num_draw_layers_ == 2) |
| 1534 return; |
| 1535 content_layer_->SetNeedsDisplay(); |
| 1536 } |
| 1537 |
| 1538 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1539 if (num_draw_layers_ == 1) |
| 1540 num_commit_complete_++; |
| 1541 } |
| 1542 |
| 1543 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1544 num_draw_layers_++; |
| 1545 if (num_draw_layers_ == 2) |
| 1546 EndTest(); |
| 1547 } |
| 1548 |
| 1549 virtual void AfterTest() OVERRIDE { |
| 1550 // Check that we didn't commit twice between first and second draw. |
| 1551 EXPECT_EQ(1, num_commit_complete_); |
| 1552 |
| 1553 // Clear layer references so LayerTreeHost dies. |
| 1554 content_layer_ = NULL; |
| 1555 } |
| 1556 |
| 1557 private: |
| 1558 FakeContentLayerClient fake_delegate_; |
| 1559 scoped_refptr<Layer> content_layer_; |
| 1560 int num_commit_complete_; |
| 1561 int num_draw_layers_; |
| 1562 }; |
| 1563 |
| 1564 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate); |
| 1565 |
| 1566 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { |
| 1567 public: |
| 1568 LayerTreeHostTestDeferCommits() |
| 1569 : num_commits_deferred_(0), num_complete_commits_(0) {} |
| 1570 |
| 1571 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 1572 |
| 1573 virtual void DidDeferCommit() OVERRIDE { |
| 1574 num_commits_deferred_++; |
| 1575 layer_tree_host()->SetDeferCommits(false); |
| 1576 } |
| 1577 |
| 1578 virtual void DidCommit() OVERRIDE { |
| 1579 num_complete_commits_++; |
| 1580 switch (num_complete_commits_) { |
| 1581 case 1: |
| 1582 EXPECT_EQ(0, num_commits_deferred_); |
| 1583 layer_tree_host()->SetDeferCommits(true); |
927 PostSetNeedsCommitToMainThread(); | 1584 PostSetNeedsCommitToMainThread(); |
928 } | 1585 break; |
929 | 1586 case 2: |
930 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 1587 EndTest(); |
931 { | 1588 break; |
932 ASSERT_EQ(0u, | 1589 default: |
933 layer_tree_host()->settings().max_partial_texture_updates); | 1590 NOTREACHED(); |
934 | 1591 break; |
935 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D
*>(impl->output_surface()->context3d()); | 1592 } |
936 | 1593 } |
937 switch (impl->active_tree()->source_frame_number()) { | 1594 |
938 case 0: | 1595 virtual void AfterTest() OVERRIDE { |
939 // Number of textures should be one for each layer | 1596 EXPECT_EQ(1, num_commits_deferred_); |
940 ASSERT_EQ(2, context->NumTextures()); | 1597 EXPECT_EQ(2, num_complete_commits_); |
941 // Number of textures used for commit should be one for each layer. | 1598 } |
942 EXPECT_EQ(2, context->NumUsedTextures()); | 1599 |
943 // Verify that used texture is correct. | 1600 private: |
944 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); | 1601 int num_commits_deferred_; |
945 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); | 1602 int num_complete_commits_; |
946 | 1603 }; |
947 context->ResetUsedTextures(); | 1604 |
948 PostSetNeedsCommitToMainThread(); | 1605 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); |
949 break; | 1606 |
950 case 1: | 1607 class LayerTreeHostWithProxy : public LayerTreeHost { |
951 // Number of textures should be doubled as the first textures | 1608 public: |
952 // are used by impl thread and cannot by used for update. | 1609 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, |
953 ASSERT_EQ(4, context->NumTextures()); | 1610 const LayerTreeSettings& settings, |
954 // Number of textures used for commit should still be one for each l
ayer. | 1611 scoped_ptr<Proxy> proxy) |
955 EXPECT_EQ(2, context->NumUsedTextures()); | 1612 : LayerTreeHost(client, settings) { |
956 // First textures should not have been used. | 1613 EXPECT_TRUE(InitializeForTesting(proxy.Pass())); |
957 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); | 1614 } |
958 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); | 1615 }; |
959 // New textures should have been used. | 1616 |
960 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); | 1617 TEST(LayerTreeHostTest, LimitPartialUpdates) { |
961 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); | 1618 // When partial updates are not allowed, max updates should be 0. |
962 | 1619 { |
963 context->ResetUsedTextures(); | 1620 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
964 PostSetNeedsCommitToMainThread(); | 1621 |
965 break; | 1622 scoped_ptr<FakeProxy> proxy = |
966 case 2: | 1623 make_scoped_ptr(new FakeProxy(scoped_ptr<Thread>())); |
967 EndTest(); | 1624 proxy->GetRendererCapabilities().allow_partial_texture_updates = false; |
968 break; | 1625 proxy->SetMaxPartialTextureUpdates(5); |
969 default: | 1626 |
970 NOTREACHED(); | 1627 LayerTreeSettings settings; |
971 break; | 1628 settings.max_partial_texture_updates = 10; |
972 } | 1629 |
973 } | 1630 LayerTreeHostWithProxy host(&client, settings, proxy.PassAs<Proxy>()); |
974 | 1631 EXPECT_TRUE(host.InitializeRendererIfNeeded()); |
975 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 1632 |
976 { | 1633 EXPECT_EQ(0u, host.settings().max_partial_texture_updates); |
977 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D
*>(impl->output_surface()->context3d()); | 1634 } |
978 | 1635 |
979 // Number of textures used for draw should always be one for each layer. | 1636 // When partial updates are allowed, |
980 EXPECT_EQ(2, context->NumUsedTextures()); | 1637 // max updates should be limited by the proxy. |
981 context->ResetUsedTextures(); | 1638 { |
982 } | 1639 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
983 | 1640 |
984 virtual void Layout() OVERRIDE | 1641 scoped_ptr<FakeProxy> proxy = |
985 { | 1642 make_scoped_ptr(new FakeProxy(scoped_ptr<Thread>())); |
986 m_layer->SetNeedsDisplay(); | 1643 proxy->GetRendererCapabilities().allow_partial_texture_updates = true; |
987 m_scrollbar->SetNeedsDisplay(); | 1644 proxy->SetMaxPartialTextureUpdates(5); |
988 } | 1645 |
989 | 1646 LayerTreeSettings settings; |
990 virtual void AfterTest() OVERRIDE | 1647 settings.max_partial_texture_updates = 10; |
991 { | 1648 |
992 } | 1649 LayerTreeHostWithProxy host(&client, settings, proxy.PassAs<Proxy>()); |
993 | 1650 EXPECT_TRUE(host.InitializeRendererIfNeeded()); |
994 private: | 1651 |
995 FakeContentLayerClient client_; | 1652 EXPECT_EQ(5u, host.settings().max_partial_texture_updates); |
996 scoped_refptr<FakeContentLayer> m_layer; | 1653 } |
997 scoped_refptr<FakeScrollbarLayer> m_scrollbar; | 1654 |
998 }; | 1655 // When partial updates are allowed, |
999 | 1656 // max updates should also be limited by the settings. |
1000 MULTI_THREAD_TEST_F(LayerTreeHostTestAtomicCommit) | 1657 { |
1001 | 1658 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
1002 static void setLayerPropertiesForTesting(Layer* layer, Layer* parent, const gfx:
:Transform& transform, const gfx::PointF& anchor, const gfx::PointF& position, c
onst gfx::Size& bounds, bool opaque) | 1659 |
1003 { | 1660 scoped_ptr<FakeProxy> proxy = |
1004 layer->RemoveAllChildren(); | 1661 make_scoped_ptr(new FakeProxy(scoped_ptr<Thread>())); |
1005 if (parent) | 1662 proxy->GetRendererCapabilities().allow_partial_texture_updates = true; |
1006 parent->AddChild(layer); | 1663 proxy->SetMaxPartialTextureUpdates(20); |
1007 layer->SetTransform(transform); | 1664 |
1008 layer->SetAnchorPoint(anchor); | 1665 LayerTreeSettings settings; |
1009 layer->SetPosition(position); | 1666 settings.max_partial_texture_updates = 10; |
1010 layer->SetBounds(bounds); | 1667 |
1011 layer->SetContentsOpaque(opaque); | 1668 LayerTreeHostWithProxy host(&client, settings, proxy.PassAs<Proxy>()); |
| 1669 EXPECT_TRUE(host.InitializeRendererIfNeeded()); |
| 1670 |
| 1671 EXPECT_EQ(10u, host.settings().max_partial_texture_updates); |
| 1672 } |
1012 } | 1673 } |
1013 | 1674 |
1014 class LayerTreeHostTestAtomicCommitWithPartialUpdate : public LayerTreeHostTest
{ | 1675 TEST(LayerTreeHostTest, PartialUpdatesWithGLRenderer) { |
1015 public: | 1676 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
1016 LayerTreeHostTestAtomicCommitWithPartialUpdate() | 1677 |
1017 : m_numCommits(0) | 1678 LayerTreeSettings settings; |
1018 { | 1679 settings.max_partial_texture_updates = 4; |
1019 } | 1680 |
1020 | 1681 scoped_ptr<LayerTreeHost> host = |
1021 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE | 1682 LayerTreeHost::Create(&client, settings, scoped_ptr<Thread>()); |
1022 { | 1683 EXPECT_TRUE(host->InitializeRendererIfNeeded()); |
1023 // Allow one partial texture update. | 1684 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); |
1024 settings->max_partial_texture_updates = 1; | 1685 } |
1025 // Linear fade animator prevents scrollbars from drawing immediately. | 1686 |
1026 settings->use_linear_fade_scrollbar_animator = false; | 1687 TEST(LayerTreeHostTest, PartialUpdatesWithSoftwareRenderer) { |
1027 } | 1688 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_SOFTWARE); |
1028 | 1689 |
1029 virtual void SetupTree() OVERRIDE | 1690 LayerTreeSettings settings; |
1030 { | 1691 settings.max_partial_texture_updates = 4; |
1031 parent_ = FakeContentLayer::Create(&client_); | 1692 |
1032 parent_->SetBounds(gfx::Size(10, 20)); | 1693 scoped_ptr<LayerTreeHost> host = |
1033 | 1694 LayerTreeHost::Create(&client, settings, scoped_ptr<Thread>()); |
1034 m_child = FakeContentLayer::Create(&client_); | 1695 EXPECT_TRUE(host->InitializeRendererIfNeeded()); |
1035 m_child->SetPosition(gfx::Point(0, 10)); | 1696 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); |
1036 m_child->SetBounds(gfx::Size(3, 10)); | 1697 } |
1037 | 1698 |
1038 bool paint_scrollbar = true; | 1699 TEST(LayerTreeHostTest, PartialUpdatesWithDelegatingRendererAndGLContent) { |
1039 bool has_thumb = false; | 1700 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_3D); |
1040 m_scrollbarWithPaints = FakeScrollbarLayer::Create( | 1701 |
1041 paint_scrollbar, has_thumb, parent_->id()); | 1702 LayerTreeSettings settings; |
1042 m_scrollbarWithPaints->SetPosition(gfx::Point(3, 10)); | 1703 settings.max_partial_texture_updates = 4; |
1043 m_scrollbarWithPaints->SetBounds(gfx::Size(3, 10)); | 1704 |
1044 | 1705 scoped_ptr<LayerTreeHost> host = |
1045 paint_scrollbar = false; | 1706 LayerTreeHost::Create(&client, settings, scoped_ptr<Thread>()); |
1046 m_scrollbarWithoutPaints = FakeScrollbarLayer::Create( | 1707 EXPECT_TRUE(host->InitializeRendererIfNeeded()); |
1047 paint_scrollbar, has_thumb, parent_->id()); | 1708 EXPECT_EQ(0u, host->settings().max_partial_texture_updates); |
1048 m_scrollbarWithoutPaints->SetPosition(gfx::Point(6, 10)); | 1709 } |
1049 m_scrollbarWithoutPaints->SetBounds(gfx::Size(3, 10)); | 1710 |
1050 | 1711 TEST(LayerTreeHostTest, |
1051 parent_->AddChild(m_child); | 1712 PartialUpdatesWithDelegatingRendererAndSoftwareContent) { |
1052 parent_->AddChild(m_scrollbarWithPaints); | 1713 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_SOFTWARE); |
1053 parent_->AddChild(m_scrollbarWithoutPaints); | 1714 |
1054 | 1715 LayerTreeSettings settings; |
1055 layer_tree_host()->SetRootLayer(parent_); | 1716 settings.max_partial_texture_updates = 4; |
1056 LayerTreeHostTest::SetupTree(); | 1717 |
1057 } | 1718 scoped_ptr<LayerTreeHost> host = |
1058 | 1719 LayerTreeHost::Create(&client, settings, scoped_ptr<Thread>()); |
1059 virtual void BeginTest() OVERRIDE | 1720 EXPECT_TRUE(host->InitializeRendererIfNeeded()); |
1060 { | 1721 EXPECT_EQ(0u, host->settings().max_partial_texture_updates); |
| 1722 } |
| 1723 |
| 1724 class LayerTreeHostTestCapturePicture : public LayerTreeHostTest { |
| 1725 public: |
| 1726 LayerTreeHostTestCapturePicture() |
| 1727 : bounds_(gfx::Size(100, 100)), |
| 1728 layer_(PictureLayer::Create(&content_client_)) {} |
| 1729 |
| 1730 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 1731 settings->impl_side_painting = true; |
| 1732 } |
| 1733 |
| 1734 class FillRectContentLayerClient : public ContentLayerClient { |
| 1735 public: |
| 1736 virtual void PaintContents(SkCanvas* canvas, |
| 1737 gfx::Rect clip, |
| 1738 gfx::RectF* opaque) OVERRIDE { |
| 1739 SkPaint paint; |
| 1740 paint.setColor(SK_ColorGREEN); |
| 1741 |
| 1742 SkRect rect = SkRect::MakeWH(canvas->getDeviceSize().width(), |
| 1743 canvas->getDeviceSize().height()); |
| 1744 *opaque = gfx::RectF(rect.width(), rect.height()); |
| 1745 canvas->drawRect(rect, paint); |
| 1746 } |
| 1747 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} |
| 1748 }; |
| 1749 |
| 1750 virtual void BeginTest() OVERRIDE { |
| 1751 layer_->SetIsDrawable(true); |
| 1752 layer_->SetBounds(bounds_); |
| 1753 layer_tree_host()->SetViewportSize(bounds_, bounds_); |
| 1754 layer_tree_host()->SetRootLayer(layer_); |
| 1755 |
| 1756 EXPECT_TRUE(layer_tree_host()->InitializeRendererIfNeeded()); |
| 1757 PostSetNeedsCommitToMainThread(); |
| 1758 } |
| 1759 |
| 1760 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1761 picture_ = layer_tree_host()->CapturePicture(); |
| 1762 EndTest(); |
| 1763 } |
| 1764 |
| 1765 virtual void AfterTest() OVERRIDE { |
| 1766 EXPECT_EQ(bounds_, gfx::Size(picture_->width(), picture_->height())); |
| 1767 |
| 1768 SkBitmap bitmap; |
| 1769 bitmap.setConfig( |
| 1770 SkBitmap::kARGB_8888_Config, bounds_.width(), bounds_.height()); |
| 1771 bitmap.allocPixels(); |
| 1772 bitmap.eraseARGB(0, 0, 0, 0); |
| 1773 SkCanvas canvas(bitmap); |
| 1774 |
| 1775 picture_->draw(&canvas); |
| 1776 |
| 1777 bitmap.lockPixels(); |
| 1778 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
| 1779 EXPECT_EQ(SK_ColorGREEN, pixels[0]); |
| 1780 bitmap.unlockPixels(); |
| 1781 } |
| 1782 |
| 1783 private: |
| 1784 gfx::Size bounds_; |
| 1785 FillRectContentLayerClient content_client_; |
| 1786 scoped_refptr<PictureLayer> layer_; |
| 1787 skia::RefPtr<SkPicture> picture_; |
| 1788 }; |
| 1789 |
| 1790 MULTI_THREAD_TEST_F(LayerTreeHostTestCapturePicture); |
| 1791 |
| 1792 class LayerTreeHostTestMaxPendingFrames : public LayerTreeHostTest { |
| 1793 public: |
| 1794 LayerTreeHostTestMaxPendingFrames() : LayerTreeHostTest() {} |
| 1795 |
| 1796 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE { |
| 1797 if (delegating_renderer_) |
| 1798 return FakeOutputSurface::CreateDelegating3d().PassAs<OutputSurface>(); |
| 1799 return FakeOutputSurface::Create3d().PassAs<OutputSurface>(); |
| 1800 } |
| 1801 |
| 1802 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 1803 |
| 1804 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1805 DCHECK(host_impl->proxy()->HasImplThread()); |
| 1806 |
| 1807 const ThreadProxy* proxy = static_cast<ThreadProxy*>(host_impl->proxy()); |
| 1808 if (delegating_renderer_) { |
| 1809 EXPECT_EQ(1, proxy->MaxFramesPendingForTesting()); |
| 1810 } else { |
| 1811 EXPECT_EQ(FrameRateController::DEFAULT_MAX_FRAMES_PENDING, |
| 1812 proxy->MaxFramesPendingForTesting()); |
| 1813 } |
| 1814 EndTest(); |
| 1815 } |
| 1816 |
| 1817 virtual void AfterTest() OVERRIDE {} |
| 1818 |
| 1819 protected: |
| 1820 bool delegating_renderer_; |
| 1821 }; |
| 1822 |
| 1823 TEST_F(LayerTreeHostTestMaxPendingFrames, DelegatingRenderer) { |
| 1824 delegating_renderer_ = true; |
| 1825 RunTest(true); |
| 1826 } |
| 1827 |
| 1828 TEST_F(LayerTreeHostTestMaxPendingFrames, GLRenderer) { |
| 1829 delegating_renderer_ = false; |
| 1830 RunTest(true); |
| 1831 } |
| 1832 |
| 1833 class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted |
| 1834 : public LayerTreeHostTest { |
| 1835 public: |
| 1836 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted() |
| 1837 : root_layer_(FakeContentLayer::Create(&client_)), |
| 1838 child_layer1_(FakeContentLayer::Create(&client_)), |
| 1839 child_layer2_(FakeContentLayer::Create(&client_)), |
| 1840 num_commits_(0) {} |
| 1841 |
| 1842 virtual void BeginTest() OVERRIDE { |
| 1843 layer_tree_host()->SetViewportSize(gfx::Size(100, 100), |
| 1844 gfx::Size(100, 100)); |
| 1845 root_layer_->SetBounds(gfx::Size(100, 100)); |
| 1846 child_layer1_->SetBounds(gfx::Size(100, 100)); |
| 1847 child_layer2_->SetBounds(gfx::Size(100, 100)); |
| 1848 root_layer_->AddChild(child_layer1_); |
| 1849 root_layer_->AddChild(child_layer2_); |
| 1850 layer_tree_host()->SetRootLayer(root_layer_); |
| 1851 PostSetNeedsCommitToMainThread(); |
| 1852 } |
| 1853 |
| 1854 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, |
| 1855 bool visible) OVERRIDE { |
| 1856 // One backing should remain unevicted. |
| 1857 EXPECT_EQ(100 * 100 * 4 * 1, |
| 1858 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); |
| 1859 // Make sure that contents textures are marked as having been |
| 1860 // purged. |
| 1861 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged()); |
| 1862 // End the test in this state. |
| 1863 EndTest(); |
| 1864 } |
| 1865 |
| 1866 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1867 ++num_commits_; |
| 1868 switch (num_commits_) { |
| 1869 case 1: |
| 1870 // All three backings should have memory. |
| 1871 EXPECT_EQ( |
| 1872 100 * 100 * 4 * 3, |
| 1873 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); |
| 1874 // Set a new policy that will kick out 1 of the 3 resources. |
| 1875 // Because a resource was evicted, a commit will be kicked off. |
| 1876 host_impl->SetManagedMemoryPolicy( |
| 1877 ManagedMemoryPolicy(100 * 100 * 4 * 2, |
| 1878 ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING, |
| 1879 100 * 100 * 4 * 1, |
| 1880 ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING)); |
| 1881 break; |
| 1882 case 2: |
| 1883 // Only two backings should have memory. |
| 1884 EXPECT_EQ( |
| 1885 100 * 100 * 4 * 2, |
| 1886 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); |
| 1887 // Become backgrounded, which will cause 1 more resource to be |
| 1888 // evicted. |
| 1889 PostSetVisibleToMainThread(false); |
| 1890 break; |
| 1891 default: |
| 1892 // No further commits should happen because this is not visible |
| 1893 // anymore. |
| 1894 NOTREACHED(); |
| 1895 break; |
| 1896 } |
| 1897 } |
| 1898 |
| 1899 virtual void AfterTest() OVERRIDE {} |
| 1900 |
| 1901 private: |
| 1902 FakeContentLayerClient client_; |
| 1903 scoped_refptr<FakeContentLayer> root_layer_; |
| 1904 scoped_refptr<FakeContentLayer> child_layer1_; |
| 1905 scoped_refptr<FakeContentLayer> child_layer2_; |
| 1906 int num_commits_; |
| 1907 }; |
| 1908 |
| 1909 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1910 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); |
| 1911 |
| 1912 class LayerTreeHostTestPinchZoomScrollbarCreation : public LayerTreeHostTest { |
| 1913 public: |
| 1914 LayerTreeHostTestPinchZoomScrollbarCreation() |
| 1915 : root_layer_(ContentLayer::Create(&client_)) {} |
| 1916 |
| 1917 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 1918 settings->use_pinch_zoom_scrollbars = true; |
| 1919 } |
| 1920 |
| 1921 virtual void BeginTest() OVERRIDE { |
| 1922 root_layer_->SetIsDrawable(true); |
| 1923 root_layer_->SetBounds(gfx::Size(100, 100)); |
| 1924 layer_tree_host()->SetRootLayer(root_layer_); |
| 1925 PostSetNeedsCommitToMainThread(); |
| 1926 } |
| 1927 |
| 1928 virtual void DidCommit() OVERRIDE { |
| 1929 // We always expect two pinch-zoom scrollbar layers. |
| 1930 ASSERT_EQ(2, root_layer_->children().size()); |
| 1931 |
| 1932 // Pinch-zoom scrollbar layers always have invalid scrollLayerIds. |
| 1933 ScrollbarLayer* layer1 = root_layer_->children()[0]->ToScrollbarLayer(); |
| 1934 ASSERT_TRUE(layer1); |
| 1935 EXPECT_EQ(Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID, |
| 1936 layer1->scroll_layer_id()); |
| 1937 EXPECT_EQ(0.f, layer1->opacity()); |
| 1938 EXPECT_TRUE(layer1->OpacityCanAnimateOnImplThread()); |
| 1939 EXPECT_TRUE(layer1->DrawsContent()); |
| 1940 |
| 1941 ScrollbarLayer* layer2 = root_layer_->children()[1]->ToScrollbarLayer(); |
| 1942 ASSERT_TRUE(layer2); |
| 1943 EXPECT_EQ(Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID, |
| 1944 layer2->scroll_layer_id()); |
| 1945 EXPECT_EQ(0.f, layer2->opacity()); |
| 1946 EXPECT_TRUE(layer2->OpacityCanAnimateOnImplThread()); |
| 1947 EXPECT_TRUE(layer2->DrawsContent()); |
| 1948 |
| 1949 EndTest(); |
| 1950 } |
| 1951 |
| 1952 virtual void AfterTest() OVERRIDE {} |
| 1953 |
| 1954 private: |
| 1955 FakeContentLayerClient client_; |
| 1956 scoped_refptr<ContentLayer> root_layer_; |
| 1957 }; |
| 1958 |
| 1959 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPinchZoomScrollbarCreation); |
| 1960 |
| 1961 class LayerTreeHostTestPinchZoomScrollbarResize : public LayerTreeHostTest { |
| 1962 public: |
| 1963 LayerTreeHostTestPinchZoomScrollbarResize() |
| 1964 : root_layer_(ContentLayer::Create(&client_)), num_commits_(0) {} |
| 1965 |
| 1966 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 1967 settings->use_pinch_zoom_scrollbars = true; |
| 1968 } |
| 1969 |
| 1970 virtual void BeginTest() OVERRIDE { |
| 1971 root_layer_->SetIsDrawable(true); |
| 1972 root_layer_->SetBounds(gfx::Size(100, 100)); |
| 1973 layer_tree_host()->SetRootLayer(root_layer_); |
| 1974 layer_tree_host()->SetViewportSize(gfx::Size(100, 100), |
| 1975 gfx::Size(100, 100)); |
| 1976 PostSetNeedsCommitToMainThread(); |
| 1977 } |
| 1978 |
| 1979 virtual void DidCommit() OVERRIDE { |
| 1980 num_commits_++; |
| 1981 |
| 1982 ScrollbarLayer* layer1 = root_layer_->children()[0]->ToScrollbarLayer(); |
| 1983 ASSERT_TRUE(layer1); |
| 1984 ScrollbarLayer* layer2 = root_layer_->children()[1]->ToScrollbarLayer(); |
| 1985 ASSERT_TRUE(layer2); |
| 1986 |
| 1987 // Get scrollbar thickness from horizontal scrollbar's height. |
| 1988 int thickness = layer1->bounds().height(); |
| 1989 |
| 1990 if (!layer1->Orientation() == WebKit::WebScrollbar::Horizontal) |
| 1991 std::swap(layer1, layer2); |
| 1992 |
| 1993 gfx::Size viewport_size = layer_tree_host()->layout_viewport_size(); |
| 1994 EXPECT_EQ(viewport_size.width() - thickness, layer1->bounds().width()); |
| 1995 EXPECT_EQ(viewport_size.height() - thickness, layer2->bounds().height()); |
| 1996 |
| 1997 switch (num_commits_) { |
| 1998 case 1: |
| 1999 // Resizing the viewport should also resize the pinch-zoom scrollbars. |
| 2000 layer_tree_host()->SetViewportSize(gfx::Size(120, 150), |
| 2001 gfx::Size(120, 150)); |
| 2002 break; |
| 2003 default: |
| 2004 EndTest(); |
| 2005 } |
| 2006 } |
| 2007 |
| 2008 virtual void AfterTest() OVERRIDE {} |
| 2009 |
| 2010 private: |
| 2011 FakeContentLayerClient client_; |
| 2012 scoped_refptr<ContentLayer> root_layer_; |
| 2013 int num_commits_; |
| 2014 }; |
| 2015 |
| 2016 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPinchZoomScrollbarResize); |
| 2017 |
| 2018 class LayerTreeHostTestPinchZoomScrollbarNewRootLayer |
| 2019 : public LayerTreeHostTest { |
| 2020 public: |
| 2021 LayerTreeHostTestPinchZoomScrollbarNewRootLayer() |
| 2022 : root_layer_(ContentLayer::Create(&client_)), num_commits_(0) {} |
| 2023 |
| 2024 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 2025 settings->use_pinch_zoom_scrollbars = true; |
| 2026 } |
| 2027 |
| 2028 virtual void BeginTest() OVERRIDE { |
| 2029 root_layer_->SetIsDrawable(true); |
| 2030 root_layer_->SetBounds(gfx::Size(100, 100)); |
| 2031 layer_tree_host()->SetRootLayer(root_layer_); |
| 2032 PostSetNeedsCommitToMainThread(); |
| 2033 } |
| 2034 |
| 2035 virtual void DidCommit() OVERRIDE { |
| 2036 num_commits_++; |
| 2037 |
| 2038 // We always expect two pinch-zoom scrollbar layers. |
| 2039 ASSERT_EQ(2, root_layer_->children().size()); |
| 2040 |
| 2041 // Pinch-zoom scrollbar layers always have invalid scrollLayerIds. |
| 2042 ScrollbarLayer* layer1 = root_layer_->children()[0]->ToScrollbarLayer(); |
| 2043 ASSERT_TRUE(layer1); |
| 2044 EXPECT_EQ(Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID, |
| 2045 layer1->scroll_layer_id()); |
| 2046 EXPECT_EQ(0.f, layer1->opacity()); |
| 2047 EXPECT_TRUE(layer1->DrawsContent()); |
| 2048 |
| 2049 ScrollbarLayer* layer2 = root_layer_->children()[1]->ToScrollbarLayer(); |
| 2050 ASSERT_TRUE(layer2); |
| 2051 EXPECT_EQ(Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID, |
| 2052 layer2->scroll_layer_id()); |
| 2053 EXPECT_EQ(0.f, layer2->opacity()); |
| 2054 EXPECT_TRUE(layer2->DrawsContent()); |
| 2055 |
| 2056 if (num_commits_ == 1) { |
| 2057 // Create a new root layer and attach to tree to verify the pinch |
| 2058 // zoom scrollbars get correctly re-attached. |
| 2059 root_layer_ = ContentLayer::Create(&client_); |
| 2060 root_layer_->SetIsDrawable(true); |
| 2061 root_layer_->SetBounds(gfx::Size(100, 100)); |
| 2062 layer_tree_host()->SetRootLayer(root_layer_); |
| 2063 PostSetNeedsCommitToMainThread(); |
| 2064 } else { |
| 2065 EndTest(); |
| 2066 } |
| 2067 } |
| 2068 |
| 2069 virtual void AfterTest() OVERRIDE {} |
| 2070 |
| 2071 private: |
| 2072 FakeContentLayerClient client_; |
| 2073 scoped_refptr<ContentLayer> root_layer_; |
| 2074 int num_commits_; |
| 2075 }; |
| 2076 |
| 2077 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPinchZoomScrollbarNewRootLayer); |
| 2078 |
| 2079 class LayerTreeHostTestLCDNotification : public LayerTreeHostTest { |
| 2080 public: |
| 2081 class NotificationClient : public ContentLayerClient { |
| 2082 public: |
| 2083 NotificationClient() |
| 2084 : layer_(0), paint_count_(0), lcd_notification_count_(0) {} |
| 2085 |
| 2086 void set_layer(Layer* layer) { layer_ = layer; } |
| 2087 int paint_count() const { return paint_count_; } |
| 2088 int lcd_notification_count() const { return lcd_notification_count_; } |
| 2089 |
| 2090 virtual void PaintContents(SkCanvas* canvas, |
| 2091 gfx::Rect clip, |
| 2092 gfx::RectF* opaque) OVERRIDE { |
| 2093 ++paint_count_; |
| 2094 } |
| 2095 virtual void DidChangeLayerCanUseLCDText() OVERRIDE { |
| 2096 ++lcd_notification_count_; |
| 2097 layer_->SetNeedsDisplay(); |
| 2098 } |
| 2099 |
| 2100 private: |
| 2101 Layer* layer_; |
| 2102 int paint_count_; |
| 2103 int lcd_notification_count_; |
| 2104 }; |
| 2105 |
| 2106 virtual void SetupTree() OVERRIDE { |
| 2107 scoped_refptr<ContentLayer> root_layer = ContentLayer::Create(&client_); |
| 2108 root_layer->SetIsDrawable(true); |
| 2109 root_layer->SetBounds(gfx::Size(1, 1)); |
| 2110 |
| 2111 layer_tree_host()->SetRootLayer(root_layer); |
| 2112 client_.set_layer(root_layer.get()); |
| 2113 |
| 2114 // The expecations are based on the assumption that the default |
| 2115 // LCD settings are: |
| 2116 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); |
| 2117 EXPECT_FALSE(root_layer->can_use_lcd_text()); |
| 2118 |
| 2119 LayerTreeHostTest::SetupTree(); |
| 2120 } |
| 2121 |
| 2122 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 2123 virtual void AfterTest() OVERRIDE {} |
| 2124 |
| 2125 virtual void DidCommit() OVERRIDE { |
| 2126 switch (layer_tree_host()->commit_number()) { |
| 2127 case 1: |
| 2128 // The first update consists one LCD notification and one paint. |
| 2129 EXPECT_EQ(1, client_.lcd_notification_count()); |
| 2130 EXPECT_EQ(1, client_.paint_count()); |
| 2131 // LCD text must have been enabled on the layer. |
| 2132 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
1061 PostSetNeedsCommitToMainThread(); | 2133 PostSetNeedsCommitToMainThread(); |
1062 } | 2134 break; |
1063 | 2135 case 2: |
1064 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 2136 // Since nothing changed on layer, there should be no notification |
1065 { | 2137 // or paint on the second update. |
1066 ASSERT_EQ(1u, | 2138 EXPECT_EQ(1, client_.lcd_notification_count()); |
1067 layer_tree_host()->settings().max_partial_texture_updates); | 2139 EXPECT_EQ(1, client_.paint_count()); |
1068 | 2140 // LCD text must not have changed. |
1069 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D
*>(impl->output_surface()->context3d()); | 2141 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
1070 | 2142 // Change layer opacity that should trigger lcd notification. |
1071 switch (impl->active_tree()->source_frame_number()) { | 2143 layer_tree_host()->root_layer()->SetOpacity(.5f); |
1072 case 0: | 2144 // No need to request a commit - setting opacity will do it. |
1073 // Number of textures should be one for each layer. | 2145 break; |
1074 ASSERT_EQ(4, context->NumTextures()); | 2146 default: |
1075 // Number of textures used for commit should be one for each layer. | 2147 // Verify that there is not extra commit due to layer invalidation. |
1076 EXPECT_EQ(4, context->NumUsedTextures()); | 2148 EXPECT_EQ(3, layer_tree_host()->commit_number()); |
1077 // Verify that used textures are correct. | 2149 // LCD notification count should have incremented due to |
1078 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); | 2150 // change in layer opacity. |
1079 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); | 2151 EXPECT_EQ(2, client_.lcd_notification_count()); |
1080 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); | 2152 // Paint count should be incremented due to invalidation. |
1081 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); | 2153 EXPECT_EQ(2, client_.paint_count()); |
1082 | 2154 // LCD text must have been disabled on the layer due to opacity. |
1083 context->ResetUsedTextures(); | 2155 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
1084 PostSetNeedsCommitToMainThread(); | |
1085 break; | |
1086 case 1: | |
1087 // Number of textures should be two for each content layer and one | |
1088 // for each scrollbar, since they always do a partial update. | |
1089 ASSERT_EQ(6, context->NumTextures()); | |
1090 // Number of textures used for commit should be one for each content | |
1091 // layer, and one for the scrollbar layer that paints. | |
1092 EXPECT_EQ(3, context->NumUsedTextures()); | |
1093 | |
1094 // First content textures should not have been used. | |
1095 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); | |
1096 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); | |
1097 // The non-painting scrollbar's texture wasn't updated. | |
1098 EXPECT_FALSE(context->UsedTexture(context->TextureAt(2))); | |
1099 // The painting scrollbar's partial update texture was used. | |
1100 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); | |
1101 // New textures should have been used. | |
1102 EXPECT_TRUE(context->UsedTexture(context->TextureAt(4))); | |
1103 EXPECT_TRUE(context->UsedTexture(context->TextureAt(5))); | |
1104 | |
1105 context->ResetUsedTextures(); | |
1106 PostSetNeedsCommitToMainThread(); | |
1107 break; | |
1108 case 2: | |
1109 // Number of textures should be two for each content layer and one | |
1110 // for each scrollbar, since they always do a partial update. | |
1111 ASSERT_EQ(6, context->NumTextures()); | |
1112 // Number of textures used for commit should be one for each content | |
1113 // layer, and one for the scrollbar layer that paints. | |
1114 EXPECT_EQ(3, context->NumUsedTextures()); | |
1115 | |
1116 // The non-painting scrollbar's texture wasn't updated. | |
1117 EXPECT_FALSE(context->UsedTexture(context->TextureAt(2))); | |
1118 // The painting scrollbar does a partial update. | |
1119 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3))); | |
1120 // One content layer does a partial update also. | |
1121 EXPECT_TRUE(context->UsedTexture(context->TextureAt(4))); | |
1122 EXPECT_FALSE(context->UsedTexture(context->TextureAt(5))); | |
1123 | |
1124 context->ResetUsedTextures(); | |
1125 PostSetNeedsCommitToMainThread(); | |
1126 break; | |
1127 case 3: | |
1128 // No textures should be used for commit. | |
1129 EXPECT_EQ(0, context->NumUsedTextures()); | |
1130 | |
1131 context->ResetUsedTextures(); | |
1132 PostSetNeedsCommitToMainThread(); | |
1133 break; | |
1134 case 4: | |
1135 // Number of textures used for commit should be two. One for the | |
1136 // content layer, and one for the painting scrollbar. The | |
1137 // non-painting scrollbar doesn't update its texture. | |
1138 EXPECT_EQ(2, context->NumUsedTextures()); | |
1139 | |
1140 context->ResetUsedTextures(); | |
1141 PostSetNeedsCommitToMainThread(); | |
1142 break; | |
1143 case 5: | |
1144 EndTest(); | |
1145 break; | |
1146 default: | |
1147 NOTREACHED(); | |
1148 break; | |
1149 } | |
1150 } | |
1151 | |
1152 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | |
1153 { | |
1154 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D
*>(impl->output_surface()->context3d()); | |
1155 | |
1156 // Number of textures used for drawing should one per layer except for | |
1157 // frame 3 where the viewport only contains one layer. | |
1158 if (impl->active_tree()->source_frame_number() == 3) | |
1159 EXPECT_EQ(1, context->NumUsedTextures()); | |
1160 else | |
1161 EXPECT_EQ(4, context->NumUsedTextures()); | |
1162 | |
1163 context->ResetUsedTextures(); | |
1164 } | |
1165 | |
1166 virtual void Layout() OVERRIDE | |
1167 { | |
1168 switch (m_numCommits++) { | |
1169 case 0: | |
1170 case 1: | |
1171 parent_->SetNeedsDisplay(); | |
1172 m_child->SetNeedsDisplay(); | |
1173 m_scrollbarWithPaints->SetNeedsDisplay(); | |
1174 m_scrollbarWithoutPaints->SetNeedsDisplay(); | |
1175 break; | |
1176 case 2: | |
1177 // Damage part of layers. | |
1178 parent_->SetNeedsDisplayRect(gfx::RectF(0, 0, 5, 5)); | |
1179 m_child->SetNeedsDisplayRect(gfx::RectF(0, 0, 5, 5)); | |
1180 m_scrollbarWithPaints->SetNeedsDisplayRect(gfx::RectF(0, 0, 5, 5)); | |
1181 m_scrollbarWithoutPaints->SetNeedsDisplayRect(gfx::RectF(0, 0, 5, 5)
); | |
1182 break; | |
1183 case 3: | |
1184 m_child->SetNeedsDisplay(); | |
1185 m_scrollbarWithPaints->SetNeedsDisplay(); | |
1186 m_scrollbarWithoutPaints->SetNeedsDisplay(); | |
1187 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10,
10)); | |
1188 break; | |
1189 case 4: | |
1190 layer_tree_host()->SetViewportSize(gfx::Size(10, 20), gfx::Size(10,
20)); | |
1191 break; | |
1192 case 5: | |
1193 break; | |
1194 default: | |
1195 NOTREACHED(); | |
1196 break; | |
1197 } | |
1198 } | |
1199 | |
1200 virtual void AfterTest() OVERRIDE | |
1201 { | |
1202 } | |
1203 | |
1204 private: | |
1205 FakeContentLayerClient client_; | |
1206 scoped_refptr<FakeContentLayer> parent_; | |
1207 scoped_refptr<FakeContentLayer> m_child; | |
1208 scoped_refptr<FakeScrollbarLayer> m_scrollbarWithPaints; | |
1209 scoped_refptr<FakeScrollbarLayer> m_scrollbarWithoutPaints; | |
1210 int m_numCommits; | |
1211 }; | |
1212 | |
1213 MULTI_THREAD_TEST_F(LayerTreeHostTestAtomicCommitWithPartialUpdate) | |
1214 | |
1215 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest { | |
1216 public: | |
1217 LayerTreeHostTestFinishAllRendering() | |
1218 : m_once(false) | |
1219 , m_drawCount(0) | |
1220 { | |
1221 } | |
1222 | |
1223 virtual void BeginTest() OVERRIDE | |
1224 { | |
1225 layer_tree_host()->SetNeedsRedraw(); | |
1226 PostSetNeedsCommitToMainThread(); | |
1227 } | |
1228 | |
1229 virtual void DidCommitAndDrawFrame() OVERRIDE | |
1230 { | |
1231 if (m_once) | |
1232 return; | |
1233 m_once = true; | |
1234 layer_tree_host()->SetNeedsRedraw(); | |
1235 layer_tree_host()->AcquireLayerTextures(); | |
1236 { | |
1237 base::AutoLock lock(m_lock); | |
1238 m_drawCount = 0; | |
1239 } | |
1240 layer_tree_host()->FinishAllRendering(); | |
1241 { | |
1242 base::AutoLock lock(m_lock); | |
1243 EXPECT_EQ(0, m_drawCount); | |
1244 } | |
1245 EndTest(); | 2156 EndTest(); |
1246 } | 2157 break; |
1247 | 2158 } |
1248 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 2159 } |
1249 { | 2160 |
1250 base::AutoLock lock(m_lock); | 2161 private: |
1251 ++m_drawCount; | 2162 NotificationClient client_; |
1252 } | 2163 }; |
1253 | 2164 |
1254 virtual void AfterTest() OVERRIDE | 2165 SINGLE_THREAD_TEST_F(LayerTreeHostTestLCDNotification); |
1255 { | |
1256 } | |
1257 private: | |
1258 | |
1259 bool m_once; | |
1260 base::Lock m_lock; | |
1261 int m_drawCount; | |
1262 }; | |
1263 | |
1264 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFinishAllRendering) | |
1265 | |
1266 class LayerTreeHostTestCompositeAndReadbackCleanup : public LayerTreeHostTest { | |
1267 public: | |
1268 LayerTreeHostTestCompositeAndReadbackCleanup() { } | |
1269 | |
1270 virtual void BeginTest() OVERRIDE | |
1271 { | |
1272 Layer* rootLayer = layer_tree_host()->root_layer(); | |
1273 | |
1274 char pixels[4]; | |
1275 layer_tree_host()->CompositeAndReadback(static_cast<void*>(&pixels), gfx
::Rect(0, 0, 1, 1)); | |
1276 EXPECT_FALSE(rootLayer->render_surface()); | |
1277 | |
1278 EndTest(); | |
1279 } | |
1280 | |
1281 virtual void AfterTest() OVERRIDE | |
1282 { | |
1283 } | |
1284 }; | |
1285 | |
1286 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackCleanup) | |
1287 | |
1288 class LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit : public L
ayerTreeHostTest { | |
1289 public: | |
1290 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit() | |
1291 : m_rootLayer(ContentLayerWithUpdateTracking::Create(&m_fakeDelegate)) | |
1292 , m_surfaceLayer1(ContentLayerWithUpdateTracking::Create(&m_fakeDelegate
)) | |
1293 , m_replicaLayer1(ContentLayerWithUpdateTracking::Create(&m_fakeDelegate
)) | |
1294 , m_surfaceLayer2(ContentLayerWithUpdateTracking::Create(&m_fakeDelegate
)) | |
1295 , m_replicaLayer2(ContentLayerWithUpdateTracking::Create(&m_fakeDelegate
)) | |
1296 { | |
1297 } | |
1298 | |
1299 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE | |
1300 { | |
1301 settings->cache_render_pass_contents = true; | |
1302 } | |
1303 | |
1304 virtual void BeginTest() OVERRIDE | |
1305 { | |
1306 layer_tree_host()->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 1
00)); | |
1307 | |
1308 m_rootLayer->SetBounds(gfx::Size(100, 100)); | |
1309 m_surfaceLayer1->SetBounds(gfx::Size(100, 100)); | |
1310 m_surfaceLayer1->SetForceRenderSurface(true); | |
1311 m_surfaceLayer1->SetOpacity(0.5); | |
1312 m_surfaceLayer2->SetBounds(gfx::Size(100, 100)); | |
1313 m_surfaceLayer2->SetForceRenderSurface(true); | |
1314 m_surfaceLayer2->SetOpacity(0.5); | |
1315 | |
1316 m_surfaceLayer1->SetReplicaLayer(m_replicaLayer1.get()); | |
1317 m_surfaceLayer2->SetReplicaLayer(m_replicaLayer2.get()); | |
1318 | |
1319 m_rootLayer->AddChild(m_surfaceLayer1); | |
1320 m_surfaceLayer1->AddChild(m_surfaceLayer2); | |
1321 layer_tree_host()->SetRootLayer(m_rootLayer); | |
1322 | |
1323 PostSetNeedsCommitToMainThread(); | |
1324 } | |
1325 | |
1326 virtual void DrawLayersOnThread(LayerTreeHostImpl* hostImpl) OVERRIDE | |
1327 { | |
1328 Renderer* renderer = hostImpl->renderer(); | |
1329 RenderPass::Id surface1RenderPassId = hostImpl->active_tree()->root_laye
r()->children()[0]->render_surface()->RenderPassId(); | |
1330 RenderPass::Id surface2RenderPassId = hostImpl->active_tree()->root_laye
r()->children()[0]->children()[0]->render_surface()->RenderPassId(); | |
1331 | |
1332 switch (hostImpl->active_tree()->source_frame_number()) { | |
1333 case 0: | |
1334 EXPECT_TRUE(renderer->HaveCachedResourcesForRenderPassId(surface1Ren
derPassId)); | |
1335 EXPECT_TRUE(renderer->HaveCachedResourcesForRenderPassId(surface2Ren
derPassId)); | |
1336 | |
1337 // Reduce the memory limit to only fit the root layer and one render
surface. This | |
1338 // prevents any contents drawing into surfaces from being allocated. | |
1339 hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy(100 * 100 * 4 *
2)); | |
1340 break; | |
1341 case 1: | |
1342 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId(surface1Re
nderPassId)); | |
1343 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId(surface2Re
nderPassId)); | |
1344 | |
1345 EndTest(); | |
1346 break; | |
1347 } | |
1348 } | |
1349 | |
1350 virtual void AfterTest() OVERRIDE | |
1351 { | |
1352 EXPECT_EQ(2, m_rootLayer->paintContentsCount()); | |
1353 EXPECT_EQ(2, m_surfaceLayer1->paintContentsCount()); | |
1354 EXPECT_EQ(2, m_surfaceLayer2->paintContentsCount()); | |
1355 | |
1356 // Clear layer references so LayerTreeHost dies. | |
1357 m_rootLayer = NULL; | |
1358 m_surfaceLayer1 = NULL; | |
1359 m_replicaLayer1 = NULL; | |
1360 m_surfaceLayer2 = NULL; | |
1361 m_replicaLayer2 = NULL; | |
1362 } | |
1363 | |
1364 private: | |
1365 FakeContentLayerClient m_fakeDelegate; | |
1366 scoped_refptr<ContentLayerWithUpdateTracking> m_rootLayer; | |
1367 scoped_refptr<ContentLayerWithUpdateTracking> m_surfaceLayer1; | |
1368 scoped_refptr<ContentLayerWithUpdateTracking> m_replicaLayer1; | |
1369 scoped_refptr<ContentLayerWithUpdateTracking> m_surfaceLayer2; | |
1370 scoped_refptr<ContentLayerWithUpdateTracking> m_replicaLayer2; | |
1371 }; | |
1372 | |
1373 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSurfaceNotAllocatedForLayersOuts
ideMemoryLimit) | |
1374 | |
1375 class EvictionTestLayer : public Layer { | |
1376 public: | |
1377 static scoped_refptr<EvictionTestLayer> Create() { return make_scoped_refptr
(new EvictionTestLayer()); } | |
1378 | |
1379 virtual void Update(ResourceUpdateQueue*, const OcclusionTracker*, Rendering
Stats*) OVERRIDE; | |
1380 virtual bool DrawsContent() const OVERRIDE { return true; } | |
1381 | |
1382 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* treeImpl) OVERR
IDE; | |
1383 virtual void PushPropertiesTo(LayerImpl*) OVERRIDE; | |
1384 virtual void SetTexturePriorities(const PriorityCalculator&) OVERRIDE; | |
1385 | |
1386 bool haveBackingTexture() const { return m_texture.get() ? m_texture->have_b
acking_texture() : false; } | |
1387 | |
1388 private: | |
1389 EvictionTestLayer() : Layer() { } | |
1390 virtual ~EvictionTestLayer() { } | |
1391 | |
1392 void createTextureIfNeeded() | |
1393 { | |
1394 if (m_texture.get()) | |
1395 return; | |
1396 m_texture = PrioritizedResource::Create(layer_tree_host()->contents_text
ure_manager()); | |
1397 m_texture->SetDimensions(gfx::Size(10, 10), GL_RGBA); | |
1398 m_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); | |
1399 } | |
1400 | |
1401 scoped_ptr<PrioritizedResource> m_texture; | |
1402 SkBitmap m_bitmap; | |
1403 }; | |
1404 | |
1405 class EvictionTestLayerImpl : public LayerImpl { | |
1406 public: | |
1407 static scoped_ptr<EvictionTestLayerImpl> Create(LayerTreeImpl* treeImpl, int
id) | |
1408 { | |
1409 return make_scoped_ptr(new EvictionTestLayerImpl(treeImpl, id)); | |
1410 } | |
1411 virtual ~EvictionTestLayerImpl() { } | |
1412 | |
1413 virtual void AppendQuads(QuadSink* quad_sink, | |
1414 AppendQuadsData* append_quads_data) OVERRIDE | |
1415 { | |
1416 ASSERT_TRUE(m_hasTexture); | |
1417 ASSERT_NE(0u, layer_tree_impl()->resource_provider()->num_resources()); | |
1418 } | |
1419 | |
1420 void setHasTexture(bool hasTexture) { m_hasTexture = hasTexture; } | |
1421 | |
1422 private: | |
1423 EvictionTestLayerImpl(LayerTreeImpl* treeImpl, int id) | |
1424 : LayerImpl(treeImpl, id) | |
1425 , m_hasTexture(false) { } | |
1426 | |
1427 bool m_hasTexture; | |
1428 }; | |
1429 | |
1430 void EvictionTestLayer::SetTexturePriorities(const PriorityCalculator&) | |
1431 { | |
1432 createTextureIfNeeded(); | |
1433 if (!m_texture.get()) | |
1434 return; | |
1435 m_texture->set_request_priority(PriorityCalculator::UIPriority(true)); | |
1436 } | |
1437 | |
1438 void EvictionTestLayer::Update(ResourceUpdateQueue* queue, const OcclusionTracke
r*, RenderingStats*) | |
1439 { | |
1440 createTextureIfNeeded(); | |
1441 if (!m_texture.get()) | |
1442 return; | |
1443 | |
1444 gfx::Rect fullRect(0, 0, 10, 10); | |
1445 ResourceUpdate upload = ResourceUpdate::Create( | |
1446 m_texture.get(), &m_bitmap, fullRect, fullRect, gfx::Vector2d()); | |
1447 queue->AppendFullUpload(upload); | |
1448 } | |
1449 | |
1450 scoped_ptr<LayerImpl> EvictionTestLayer::CreateLayerImpl(LayerTreeImpl* treeImpl
) | |
1451 { | |
1452 return EvictionTestLayerImpl::Create(treeImpl, layer_id_).PassAs<LayerImpl>(
); | |
1453 } | |
1454 | |
1455 void EvictionTestLayer::PushPropertiesTo(LayerImpl* layerImpl) | |
1456 { | |
1457 Layer::PushPropertiesTo(layerImpl); | |
1458 | |
1459 EvictionTestLayerImpl* testLayerImpl = static_cast<EvictionTestLayerImpl*>(l
ayerImpl); | |
1460 testLayerImpl->setHasTexture(m_texture->have_backing_texture()); | |
1461 } | |
1462 | |
1463 class LayerTreeHostTestEvictTextures : public LayerTreeHostTest { | |
1464 public: | |
1465 LayerTreeHostTestEvictTextures() | |
1466 : m_layer(EvictionTestLayer::Create()) | |
1467 , m_implForEvictTextures(0) | |
1468 , m_numCommits(0) | |
1469 { | |
1470 } | |
1471 | |
1472 virtual void BeginTest() OVERRIDE | |
1473 { | |
1474 layer_tree_host()->SetRootLayer(m_layer); | |
1475 layer_tree_host()->SetViewportSize(gfx::Size(10, 20), gfx::Size(10, 20))
; | |
1476 | |
1477 gfx::Transform identityMatrix; | |
1478 setLayerPropertiesForTesting(m_layer.get(), 0, identityMatrix, gfx::Poin
tF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 20), true); | |
1479 | |
1480 PostSetNeedsCommitToMainThread(); | |
1481 } | |
1482 | |
1483 void postEvictTextures() | |
1484 { | |
1485 DCHECK(ImplThread()); | |
1486 ImplThread()->PostTask(base::Bind(&LayerTreeHostTestEvictTextures::evict
TexturesOnImplThread, | |
1487 base::Unretained(this))); | |
1488 } | |
1489 | |
1490 void evictTexturesOnImplThread() | |
1491 { | |
1492 DCHECK(m_implForEvictTextures); | |
1493 m_implForEvictTextures->EnforceManagedMemoryPolicy(ManagedMemoryPolicy(0
)); | |
1494 } | |
1495 | |
1496 // Commit 1: Just commit and draw normally, then post an eviction at the end | |
1497 // that will trigger a commit. | |
1498 // Commit 2: Triggered by the eviction, let it go through and then set | |
1499 // needsCommit. | |
1500 // Commit 3: Triggered by the setNeedsCommit. In Layout(), post an eviction | |
1501 // task, which will be handled before the commit. Don't set needsCommit, it | |
1502 // should have been posted. A frame should not be drawn (note, | |
1503 // didCommitAndDrawFrame may be called anyway). | |
1504 // Commit 4: Triggered by the eviction, let it go through and then set | |
1505 // needsCommit. | |
1506 // Commit 5: Triggered by the setNeedsCommit, post an eviction task in | |
1507 // Layout(), a frame should not be drawn but a commit will be posted. | |
1508 // Commit 6: Triggered by the eviction, post an eviction task in | |
1509 // Layout(), which will be a noop, letting the commit (which recreates the | |
1510 // textures) go through and draw a frame, then end the test. | |
1511 // | |
1512 // Commits 1+2 test the eviction recovery path where eviction happens outsid
e | |
1513 // of the beginFrame/commit pair. | |
1514 // Commits 3+4 test the eviction recovery path where eviction happens inside | |
1515 // the beginFrame/commit pair. | |
1516 // Commits 5+6 test the path where an eviction happens during the eviction | |
1517 // recovery path. | |
1518 virtual void DidCommitAndDrawFrame() OVERRIDE | |
1519 { | |
1520 switch (m_numCommits) { | |
1521 case 1: | |
1522 EXPECT_TRUE(m_layer->haveBackingTexture()); | |
1523 postEvictTextures(); | |
1524 break; | |
1525 case 2: | |
1526 EXPECT_TRUE(m_layer->haveBackingTexture()); | |
1527 layer_tree_host()->SetNeedsCommit(); | |
1528 break; | |
1529 case 3: | |
1530 break; | |
1531 case 4: | |
1532 EXPECT_TRUE(m_layer->haveBackingTexture()); | |
1533 layer_tree_host()->SetNeedsCommit(); | |
1534 break; | |
1535 case 5: | |
1536 break; | |
1537 case 6: | |
1538 EXPECT_TRUE(m_layer->haveBackingTexture()); | |
1539 EndTest(); | |
1540 break; | |
1541 default: | |
1542 NOTREACHED(); | |
1543 break; | |
1544 } | |
1545 } | |
1546 | |
1547 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | |
1548 { | |
1549 m_implForEvictTextures = impl; | |
1550 } | |
1551 | |
1552 virtual void Layout() OVERRIDE | |
1553 { | |
1554 ++m_numCommits; | |
1555 switch (m_numCommits) { | |
1556 case 1: | |
1557 case 2: | |
1558 break; | |
1559 case 3: | |
1560 postEvictTextures(); | |
1561 break; | |
1562 case 4: | |
1563 // We couldn't check in didCommitAndDrawFrame on commit 3, so check
here. | |
1564 EXPECT_FALSE(m_layer->haveBackingTexture()); | |
1565 break; | |
1566 case 5: | |
1567 postEvictTextures(); | |
1568 break; | |
1569 case 6: | |
1570 // We couldn't check in didCommitAndDrawFrame on commit 5, so check
here. | |
1571 EXPECT_FALSE(m_layer->haveBackingTexture()); | |
1572 postEvictTextures(); | |
1573 break; | |
1574 default: | |
1575 NOTREACHED(); | |
1576 break; | |
1577 } | |
1578 } | |
1579 | |
1580 virtual void AfterTest() OVERRIDE | |
1581 { | |
1582 } | |
1583 | |
1584 private: | |
1585 FakeContentLayerClient client_; | |
1586 scoped_refptr<EvictionTestLayer> m_layer; | |
1587 LayerTreeHostImpl* m_implForEvictTextures; | |
1588 int m_numCommits; | |
1589 }; | |
1590 | |
1591 MULTI_THREAD_TEST_F(LayerTreeHostTestEvictTextures) | |
1592 | |
1593 class LayerTreeHostTestContinuousCommit : public LayerTreeHostTest { | |
1594 public: | |
1595 LayerTreeHostTestContinuousCommit() | |
1596 : m_numCommitComplete(0) | |
1597 , m_numDrawLayers(0) | |
1598 { | |
1599 } | |
1600 | |
1601 virtual void BeginTest() OVERRIDE | |
1602 { | |
1603 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10))
; | |
1604 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); | |
1605 | |
1606 PostSetNeedsCommitToMainThread(); | |
1607 } | |
1608 | |
1609 virtual void DidCommit() OVERRIDE | |
1610 { | |
1611 if (m_numDrawLayers == 2) | |
1612 return; | |
1613 PostSetNeedsCommitToMainThread(); | |
1614 } | |
1615 | |
1616 virtual void CommitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | |
1617 { | |
1618 if (m_numDrawLayers == 1) | |
1619 m_numCommitComplete++; | |
1620 } | |
1621 | |
1622 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | |
1623 { | |
1624 m_numDrawLayers++; | |
1625 if (m_numDrawLayers == 2) | |
1626 EndTest(); | |
1627 } | |
1628 | |
1629 virtual void AfterTest() OVERRIDE | |
1630 { | |
1631 // Check that we didn't commit twice between first and second draw. | |
1632 EXPECT_EQ(1, m_numCommitComplete); | |
1633 } | |
1634 | |
1635 private: | |
1636 int m_numCommitComplete; | |
1637 int m_numDrawLayers; | |
1638 }; | |
1639 | |
1640 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousCommit) | |
1641 | |
1642 class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { | |
1643 public: | |
1644 LayerTreeHostTestContinuousInvalidate() | |
1645 : m_numCommitComplete(0) | |
1646 , m_numDrawLayers(0) | |
1647 { | |
1648 } | |
1649 | |
1650 virtual void BeginTest() OVERRIDE | |
1651 { | |
1652 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10))
; | |
1653 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); | |
1654 | |
1655 m_contentLayer = ContentLayer::Create(&m_fakeDelegate); | |
1656 m_contentLayer->SetBounds(gfx::Size(10, 10)); | |
1657 m_contentLayer->SetPosition(gfx::PointF(0, 0)); | |
1658 m_contentLayer->SetAnchorPoint(gfx::PointF(0, 0)); | |
1659 m_contentLayer->SetIsDrawable(true); | |
1660 layer_tree_host()->root_layer()->AddChild(m_contentLayer); | |
1661 | |
1662 PostSetNeedsCommitToMainThread(); | |
1663 } | |
1664 | |
1665 virtual void DidCommit() OVERRIDE | |
1666 { | |
1667 if (m_numDrawLayers == 2) | |
1668 return; | |
1669 m_contentLayer->SetNeedsDisplay(); | |
1670 } | |
1671 | |
1672 virtual void CommitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | |
1673 { | |
1674 if (m_numDrawLayers == 1) | |
1675 m_numCommitComplete++; | |
1676 } | |
1677 | |
1678 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | |
1679 { | |
1680 m_numDrawLayers++; | |
1681 if (m_numDrawLayers == 2) | |
1682 EndTest(); | |
1683 } | |
1684 | |
1685 virtual void AfterTest() OVERRIDE | |
1686 { | |
1687 // Check that we didn't commit twice between first and second draw. | |
1688 EXPECT_EQ(1, m_numCommitComplete); | |
1689 | |
1690 // Clear layer references so LayerTreeHost dies. | |
1691 m_contentLayer = NULL; | |
1692 } | |
1693 | |
1694 private: | |
1695 FakeContentLayerClient m_fakeDelegate; | |
1696 scoped_refptr<Layer> m_contentLayer; | |
1697 int m_numCommitComplete; | |
1698 int m_numDrawLayers; | |
1699 }; | |
1700 | |
1701 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate) | |
1702 | |
1703 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { | |
1704 public: | |
1705 LayerTreeHostTestDeferCommits() | |
1706 : m_numCommitsDeferred(0) | |
1707 , m_numCompleteCommits(0) | |
1708 { | |
1709 } | |
1710 | |
1711 virtual void BeginTest() OVERRIDE | |
1712 { | |
1713 PostSetNeedsCommitToMainThread(); | |
1714 } | |
1715 | |
1716 virtual void DidDeferCommit() OVERRIDE | |
1717 { | |
1718 m_numCommitsDeferred++; | |
1719 layer_tree_host()->SetDeferCommits(false); | |
1720 } | |
1721 | |
1722 virtual void DidCommit() OVERRIDE | |
1723 { | |
1724 m_numCompleteCommits++; | |
1725 switch (m_numCompleteCommits) { | |
1726 case 1: | |
1727 EXPECT_EQ(0, m_numCommitsDeferred); | |
1728 layer_tree_host()->SetDeferCommits(true); | |
1729 PostSetNeedsCommitToMainThread(); | |
1730 break; | |
1731 case 2: | |
1732 EndTest(); | |
1733 break; | |
1734 default: | |
1735 NOTREACHED(); | |
1736 break; | |
1737 } | |
1738 } | |
1739 | |
1740 virtual void AfterTest() OVERRIDE | |
1741 { | |
1742 EXPECT_EQ(1, m_numCommitsDeferred); | |
1743 EXPECT_EQ(2, m_numCompleteCommits); | |
1744 } | |
1745 | |
1746 private: | |
1747 int m_numCommitsDeferred; | |
1748 int m_numCompleteCommits; | |
1749 }; | |
1750 | |
1751 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits) | |
1752 | |
1753 class LayerTreeHostWithProxy : public LayerTreeHost { | |
1754 public: | |
1755 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, const LayerTreeSetti
ngs& settings, scoped_ptr<Proxy> proxy) | |
1756 : LayerTreeHost(client, settings) | |
1757 { | |
1758 EXPECT_TRUE(InitializeForTesting(proxy.Pass())); | |
1759 } | |
1760 }; | |
1761 | |
1762 TEST(LayerTreeHostTest, LimitPartialUpdates) | |
1763 { | |
1764 // When partial updates are not allowed, max updates should be 0. | |
1765 { | |
1766 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | |
1767 | |
1768 scoped_ptr<FakeProxy> proxy = make_scoped_ptr(new FakeProxy(scoped_ptr<T
hread>())); | |
1769 proxy->GetRendererCapabilities().allow_partial_texture_updates = false; | |
1770 proxy->SetMaxPartialTextureUpdates(5); | |
1771 | |
1772 LayerTreeSettings settings; | |
1773 settings.max_partial_texture_updates = 10; | |
1774 | |
1775 LayerTreeHostWithProxy host(&client, settings, proxy.PassAs<Proxy>()); | |
1776 EXPECT_TRUE(host.InitializeRendererIfNeeded()); | |
1777 | |
1778 EXPECT_EQ(0u, host.settings().max_partial_texture_updates); | |
1779 } | |
1780 | |
1781 // When partial updates are allowed, max updates should be limited by the pr
oxy. | |
1782 { | |
1783 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | |
1784 | |
1785 scoped_ptr<FakeProxy> proxy = make_scoped_ptr(new FakeProxy(scoped_ptr<T
hread>())); | |
1786 proxy->GetRendererCapabilities().allow_partial_texture_updates = true; | |
1787 proxy->SetMaxPartialTextureUpdates(5); | |
1788 | |
1789 LayerTreeSettings settings; | |
1790 settings.max_partial_texture_updates = 10; | |
1791 | |
1792 LayerTreeHostWithProxy host(&client, settings, proxy.PassAs<Proxy>()); | |
1793 EXPECT_TRUE(host.InitializeRendererIfNeeded()); | |
1794 | |
1795 EXPECT_EQ(5u, host.settings().max_partial_texture_updates); | |
1796 } | |
1797 | |
1798 // When partial updates are allowed, max updates should also be limited by t
he settings. | |
1799 { | |
1800 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | |
1801 | |
1802 scoped_ptr<FakeProxy> proxy = make_scoped_ptr(new FakeProxy(scoped_ptr<T
hread>())); | |
1803 proxy->GetRendererCapabilities().allow_partial_texture_updates = true; | |
1804 proxy->SetMaxPartialTextureUpdates(20); | |
1805 | |
1806 LayerTreeSettings settings; | |
1807 settings.max_partial_texture_updates = 10; | |
1808 | |
1809 LayerTreeHostWithProxy host(&client, settings, proxy.PassAs<Proxy>()); | |
1810 EXPECT_TRUE(host.InitializeRendererIfNeeded()); | |
1811 | |
1812 EXPECT_EQ(10u, host.settings().max_partial_texture_updates); | |
1813 } | |
1814 } | |
1815 | |
1816 TEST(LayerTreeHostTest, PartialUpdatesWithGLRenderer) | |
1817 { | |
1818 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | |
1819 | |
1820 LayerTreeSettings settings; | |
1821 settings.max_partial_texture_updates = 4; | |
1822 | |
1823 scoped_ptr<LayerTreeHost> host = LayerTreeHost::Create(&client, settings, sc
oped_ptr<Thread>()); | |
1824 EXPECT_TRUE(host->InitializeRendererIfNeeded()); | |
1825 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); | |
1826 } | |
1827 | |
1828 TEST(LayerTreeHostTest, PartialUpdatesWithSoftwareRenderer) | |
1829 { | |
1830 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_SOFTWARE); | |
1831 | |
1832 LayerTreeSettings settings; | |
1833 settings.max_partial_texture_updates = 4; | |
1834 | |
1835 scoped_ptr<LayerTreeHost> host = LayerTreeHost::Create(&client, settings, sc
oped_ptr<Thread>()); | |
1836 EXPECT_TRUE(host->InitializeRendererIfNeeded()); | |
1837 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); | |
1838 } | |
1839 | |
1840 TEST(LayerTreeHostTest, PartialUpdatesWithDelegatingRendererAndGLContent) | |
1841 { | |
1842 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_3D); | |
1843 | |
1844 LayerTreeSettings settings; | |
1845 settings.max_partial_texture_updates = 4; | |
1846 | |
1847 scoped_ptr<LayerTreeHost> host = LayerTreeHost::Create(&client, settings, sc
oped_ptr<Thread>()); | |
1848 EXPECT_TRUE(host->InitializeRendererIfNeeded()); | |
1849 EXPECT_EQ(0u, host->settings().max_partial_texture_updates); | |
1850 } | |
1851 | |
1852 TEST(LayerTreeHostTest, PartialUpdatesWithDelegatingRendererAndSoftwareContent) | |
1853 { | |
1854 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_SOFTWARE); | |
1855 | |
1856 LayerTreeSettings settings; | |
1857 settings.max_partial_texture_updates = 4; | |
1858 | |
1859 scoped_ptr<LayerTreeHost> host = LayerTreeHost::Create(&client, settings, sc
oped_ptr<Thread>()); | |
1860 EXPECT_TRUE(host->InitializeRendererIfNeeded()); | |
1861 EXPECT_EQ(0u, host->settings().max_partial_texture_updates); | |
1862 } | |
1863 | |
1864 class LayerTreeHostTestCapturePicture : public LayerTreeHostTest { | |
1865 public: | |
1866 LayerTreeHostTestCapturePicture() | |
1867 : bounds_(gfx::Size(100, 100)) | |
1868 , m_layer(PictureLayer::Create(&m_contentClient)) | |
1869 { | |
1870 } | |
1871 | |
1872 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE | |
1873 { | |
1874 settings->impl_side_painting = true; | |
1875 } | |
1876 | |
1877 class FillRectContentLayerClient : public ContentLayerClient { | |
1878 public: | |
1879 virtual void PaintContents(SkCanvas* canvas, gfx::Rect clip, gfx::RectF*
opaque) OVERRIDE | |
1880 { | |
1881 SkPaint paint; | |
1882 paint.setColor(SK_ColorGREEN); | |
1883 | |
1884 SkRect rect = SkRect::MakeWH(canvas->getDeviceSize().width(), canvas
->getDeviceSize().height()); | |
1885 *opaque = gfx::RectF(rect.width(), rect.height()); | |
1886 canvas->drawRect(rect, paint); | |
1887 } | |
1888 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} | |
1889 }; | |
1890 | |
1891 virtual void BeginTest() OVERRIDE | |
1892 { | |
1893 m_layer->SetIsDrawable(true); | |
1894 m_layer->SetBounds(bounds_); | |
1895 layer_tree_host()->SetViewportSize(bounds_, bounds_); | |
1896 layer_tree_host()->SetRootLayer(m_layer); | |
1897 | |
1898 EXPECT_TRUE(layer_tree_host()->InitializeRendererIfNeeded()); | |
1899 PostSetNeedsCommitToMainThread(); | |
1900 } | |
1901 | |
1902 virtual void DidCommitAndDrawFrame() OVERRIDE | |
1903 { | |
1904 m_picture = layer_tree_host()->CapturePicture(); | |
1905 EndTest(); | |
1906 } | |
1907 | |
1908 virtual void AfterTest() OVERRIDE | |
1909 { | |
1910 EXPECT_EQ(bounds_, gfx::Size(m_picture->width(), m_picture->height())); | |
1911 | |
1912 SkBitmap bitmap; | |
1913 bitmap.setConfig(SkBitmap::kARGB_8888_Config, bounds_.width(), bounds_.h
eight()); | |
1914 bitmap.allocPixels(); | |
1915 bitmap.eraseARGB(0, 0, 0, 0); | |
1916 SkCanvas canvas(bitmap); | |
1917 | |
1918 m_picture->draw(&canvas); | |
1919 | |
1920 bitmap.lockPixels(); | |
1921 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | |
1922 EXPECT_EQ(SK_ColorGREEN, pixels[0]); | |
1923 bitmap.unlockPixels(); | |
1924 } | |
1925 | |
1926 private: | |
1927 gfx::Size bounds_; | |
1928 FillRectContentLayerClient m_contentClient; | |
1929 scoped_refptr<PictureLayer> m_layer; | |
1930 skia::RefPtr<SkPicture> m_picture; | |
1931 }; | |
1932 | |
1933 MULTI_THREAD_TEST_F(LayerTreeHostTestCapturePicture); | |
1934 | |
1935 class LayerTreeHostTestMaxPendingFrames : public LayerTreeHostTest { | |
1936 public: | |
1937 LayerTreeHostTestMaxPendingFrames() | |
1938 : LayerTreeHostTest() | |
1939 { | |
1940 } | |
1941 | |
1942 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE | |
1943 { | |
1944 if (m_delegatingRenderer) | |
1945 return FakeOutputSurface::CreateDelegating3d().PassAs<OutputSurface>
(); | |
1946 return FakeOutputSurface::Create3d().PassAs<OutputSurface>(); | |
1947 } | |
1948 | |
1949 virtual void BeginTest() OVERRIDE | |
1950 { | |
1951 PostSetNeedsCommitToMainThread(); | |
1952 } | |
1953 | |
1954 virtual void DrawLayersOnThread(LayerTreeHostImpl* hostImpl) OVERRIDE | |
1955 { | |
1956 DCHECK(hostImpl->proxy()->HasImplThread()); | |
1957 | |
1958 const ThreadProxy* proxy = static_cast<ThreadProxy*>(hostImpl->proxy()); | |
1959 if (m_delegatingRenderer) | |
1960 EXPECT_EQ(1, proxy->MaxFramesPendingForTesting()); | |
1961 else | |
1962 EXPECT_EQ(FrameRateController::DEFAULT_MAX_FRAMES_PENDING, proxy->Ma
xFramesPendingForTesting()); | |
1963 EndTest(); | |
1964 } | |
1965 | |
1966 virtual void AfterTest() OVERRIDE | |
1967 { | |
1968 } | |
1969 | |
1970 protected: | |
1971 bool m_delegatingRenderer; | |
1972 }; | |
1973 | |
1974 TEST_F(LayerTreeHostTestMaxPendingFrames, DelegatingRenderer) | |
1975 { | |
1976 m_delegatingRenderer = true; | |
1977 RunTest(true); | |
1978 } | |
1979 | |
1980 TEST_F(LayerTreeHostTestMaxPendingFrames, GLRenderer) | |
1981 { | |
1982 m_delegatingRenderer = false; | |
1983 RunTest(true); | |
1984 } | |
1985 | |
1986 class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted : public LayerTreeHo
stTest { | |
1987 public: | |
1988 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted() | |
1989 : m_rootLayer(FakeContentLayer::Create(&client_)) | |
1990 , m_childLayer1(FakeContentLayer::Create(&client_)) | |
1991 , m_childLayer2(FakeContentLayer::Create(&client_)) | |
1992 , m_numCommits(0) | |
1993 { | |
1994 } | |
1995 | |
1996 virtual void BeginTest() OVERRIDE | |
1997 { | |
1998 layer_tree_host()->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 1
00)); | |
1999 m_rootLayer->SetBounds(gfx::Size(100, 100)); | |
2000 m_childLayer1->SetBounds(gfx::Size(100, 100)); | |
2001 m_childLayer2->SetBounds(gfx::Size(100, 100)); | |
2002 m_rootLayer->AddChild(m_childLayer1); | |
2003 m_rootLayer->AddChild(m_childLayer2); | |
2004 layer_tree_host()->SetRootLayer(m_rootLayer); | |
2005 PostSetNeedsCommitToMainThread(); | |
2006 } | |
2007 | |
2008 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* hostImpl, bool visib
le) OVERRIDE | |
2009 { | |
2010 // One backing should remain unevicted. | |
2011 EXPECT_EQ( | |
2012 100 * 100 * 4 * 1, | |
2013 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); | |
2014 // Make sure that contents textures are marked as having been | |
2015 // purged. | |
2016 EXPECT_TRUE(hostImpl->active_tree()->ContentsTexturesPurged()); | |
2017 // End the test in this state. | |
2018 EndTest(); | |
2019 } | |
2020 | |
2021 virtual void CommitCompleteOnThread(LayerTreeHostImpl* hostImpl) OVERRIDE | |
2022 { | |
2023 ++m_numCommits; | |
2024 switch(m_numCommits) { | |
2025 case 1: | |
2026 // All three backings should have memory. | |
2027 EXPECT_EQ( | |
2028 100 * 100 * 4 * 3, | |
2029 layer_tree_host()->contents_texture_manager()->MemoryUseBytes())
; | |
2030 // Set a new policy that will kick out 1 of the 3 resources. | |
2031 // Because a resource was evicted, a commit will be kicked off. | |
2032 hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy( | |
2033 100 * 100 * 4 * 2, | |
2034 ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING, | |
2035 100 * 100 * 4 * 1, | |
2036 ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING)); | |
2037 break; | |
2038 case 2: | |
2039 // Only two backings should have memory. | |
2040 EXPECT_EQ( | |
2041 100 * 100 * 4 * 2, | |
2042 layer_tree_host()->contents_texture_manager()->MemoryUseBytes())
; | |
2043 // Become backgrounded, which will cause 1 more resource to be | |
2044 // evicted. | |
2045 PostSetVisibleToMainThread(false); | |
2046 break; | |
2047 default: | |
2048 // No further commits should happen because this is not visible | |
2049 // anymore. | |
2050 NOTREACHED(); | |
2051 break; | |
2052 } | |
2053 } | |
2054 | |
2055 virtual void AfterTest() OVERRIDE | |
2056 { | |
2057 } | |
2058 | |
2059 private: | |
2060 FakeContentLayerClient client_; | |
2061 scoped_refptr<FakeContentLayer> m_rootLayer; | |
2062 scoped_refptr<FakeContentLayer> m_childLayer1; | |
2063 scoped_refptr<FakeContentLayer> m_childLayer2; | |
2064 int m_numCommits; | |
2065 }; | |
2066 | |
2067 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestShutdownWithOnlySomeResourcesEvi
cted) | |
2068 | |
2069 class LayerTreeHostTestPinchZoomScrollbarCreation : public LayerTreeHostTest { | |
2070 public: | |
2071 LayerTreeHostTestPinchZoomScrollbarCreation() | |
2072 : m_rootLayer(ContentLayer::Create(&client_)) | |
2073 { | |
2074 } | |
2075 | |
2076 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE | |
2077 { | |
2078 settings->use_pinch_zoom_scrollbars = true; | |
2079 } | |
2080 | |
2081 virtual void BeginTest() OVERRIDE | |
2082 { | |
2083 m_rootLayer->SetIsDrawable(true); | |
2084 m_rootLayer->SetBounds(gfx::Size(100, 100)); | |
2085 layer_tree_host()->SetRootLayer(m_rootLayer); | |
2086 PostSetNeedsCommitToMainThread(); | |
2087 } | |
2088 | |
2089 virtual void DidCommit() OVERRIDE | |
2090 { | |
2091 // We always expect two pinch-zoom scrollbar layers. | |
2092 ASSERT_TRUE(2 == m_rootLayer->children().size()); | |
2093 | |
2094 // Pinch-zoom scrollbar layers always have invalid scrollLayerIds. | |
2095 ScrollbarLayer* layer1 = m_rootLayer->children()[0]->ToScrollbarLayer(); | |
2096 ASSERT_TRUE(layer1); | |
2097 EXPECT_EQ(Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID, layer1->scroll_layer_i
d()); | |
2098 EXPECT_EQ(0, layer1->opacity()); | |
2099 EXPECT_TRUE(layer1->OpacityCanAnimateOnImplThread()); | |
2100 EXPECT_TRUE(layer1->DrawsContent()); | |
2101 | |
2102 ScrollbarLayer* layer2 = m_rootLayer->children()[1]->ToScrollbarLayer(); | |
2103 ASSERT_TRUE(layer2); | |
2104 EXPECT_EQ(Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID, layer2->scroll_layer_i
d()); | |
2105 EXPECT_EQ(0, layer2->opacity()); | |
2106 EXPECT_TRUE(layer2->OpacityCanAnimateOnImplThread()); | |
2107 EXPECT_TRUE(layer2->DrawsContent()); | |
2108 | |
2109 EndTest(); | |
2110 } | |
2111 | |
2112 virtual void AfterTest() OVERRIDE | |
2113 { | |
2114 } | |
2115 | |
2116 private: | |
2117 FakeContentLayerClient client_; | |
2118 scoped_refptr<ContentLayer> m_rootLayer; | |
2119 }; | |
2120 | |
2121 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPinchZoomScrollbarCreation) | |
2122 | |
2123 class LayerTreeHostTestPinchZoomScrollbarResize : public LayerTreeHostTest { | |
2124 public: | |
2125 LayerTreeHostTestPinchZoomScrollbarResize() | |
2126 : m_rootLayer(ContentLayer::Create(&client_)) | |
2127 , m_numCommits(0) | |
2128 { | |
2129 } | |
2130 | |
2131 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE | |
2132 { | |
2133 settings->use_pinch_zoom_scrollbars = true; | |
2134 } | |
2135 | |
2136 virtual void BeginTest() OVERRIDE | |
2137 { | |
2138 m_rootLayer->SetIsDrawable(true); | |
2139 m_rootLayer->SetBounds(gfx::Size(100, 100)); | |
2140 layer_tree_host()->SetRootLayer(m_rootLayer); | |
2141 layer_tree_host()->SetViewportSize(gfx::Size(100, 100), | |
2142 gfx::Size(100, 100)); | |
2143 PostSetNeedsCommitToMainThread(); | |
2144 } | |
2145 | |
2146 virtual void DidCommit() OVERRIDE | |
2147 { | |
2148 m_numCommits++; | |
2149 | |
2150 ScrollbarLayer* layer1 = m_rootLayer->children()[0]->ToScrollbarLayer(); | |
2151 ASSERT_TRUE(layer1); | |
2152 ScrollbarLayer* layer2 = m_rootLayer->children()[1]->ToScrollbarLayer(); | |
2153 ASSERT_TRUE(layer2); | |
2154 | |
2155 // Get scrollbar thickness from horizontal scrollbar's height. | |
2156 int thickness = layer1->bounds().height(); | |
2157 | |
2158 if (!layer1->Orientation() == WebKit::WebScrollbar::Horizontal) | |
2159 std::swap(layer1, layer2); | |
2160 | |
2161 gfx::Size viewportSize = layer_tree_host()->layout_viewport_size(); | |
2162 EXPECT_EQ(viewportSize.width() - thickness, layer1->bounds().width()); | |
2163 EXPECT_EQ(viewportSize.height() - thickness, layer2->bounds().height()); | |
2164 | |
2165 switch (m_numCommits) { | |
2166 case 1: | |
2167 // Resizing the viewport should also resize the pinch-zoom scrollbars. | |
2168 layer_tree_host()->SetViewportSize(gfx::Size(120, 150), | |
2169 gfx::Size(120, 150)); | |
2170 break; | |
2171 default: | |
2172 EndTest(); | |
2173 } | |
2174 } | |
2175 | |
2176 virtual void AfterTest() OVERRIDE | |
2177 { | |
2178 } | |
2179 | |
2180 private: | |
2181 FakeContentLayerClient client_; | |
2182 scoped_refptr<ContentLayer> m_rootLayer; | |
2183 int m_numCommits; | |
2184 }; | |
2185 | |
2186 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPinchZoomScrollbarResize) | |
2187 | |
2188 class LayerTreeHostTestPinchZoomScrollbarNewRootLayer : public LayerTreeHostTest
{ | |
2189 public: | |
2190 LayerTreeHostTestPinchZoomScrollbarNewRootLayer() | |
2191 : m_rootLayer(ContentLayer::Create(&client_)) | |
2192 , m_numCommits(0) | |
2193 { | |
2194 } | |
2195 | |
2196 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE | |
2197 { | |
2198 settings->use_pinch_zoom_scrollbars = true; | |
2199 } | |
2200 | |
2201 virtual void BeginTest() OVERRIDE | |
2202 { | |
2203 m_rootLayer->SetIsDrawable(true); | |
2204 m_rootLayer->SetBounds(gfx::Size(100, 100)); | |
2205 layer_tree_host()->SetRootLayer(m_rootLayer); | |
2206 PostSetNeedsCommitToMainThread(); | |
2207 } | |
2208 | |
2209 virtual void DidCommit() OVERRIDE | |
2210 { | |
2211 m_numCommits++; | |
2212 | |
2213 // We always expect two pinch-zoom scrollbar layers. | |
2214 ASSERT_TRUE(2 == m_rootLayer->children().size()); | |
2215 | |
2216 // Pinch-zoom scrollbar layers always have invalid scrollLayerIds. | |
2217 ScrollbarLayer* layer1 = m_rootLayer->children()[0]->ToScrollbarLayer(); | |
2218 ASSERT_TRUE(layer1); | |
2219 EXPECT_EQ(Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID, layer1->scroll_layer_i
d()); | |
2220 EXPECT_EQ(0, layer1->opacity()); | |
2221 EXPECT_TRUE(layer1->DrawsContent()); | |
2222 | |
2223 ScrollbarLayer* layer2 = m_rootLayer->children()[1]->ToScrollbarLayer(); | |
2224 ASSERT_TRUE(layer2); | |
2225 EXPECT_EQ(Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID, layer2->scroll_layer_i
d()); | |
2226 EXPECT_EQ(0, layer2->opacity()); | |
2227 EXPECT_TRUE(layer2->DrawsContent()); | |
2228 | |
2229 if (m_numCommits == 1) { | |
2230 // Create a new root layer and attach to tree to verify the pinch | |
2231 // zoom scrollbars get correctly re-attached. | |
2232 m_rootLayer = ContentLayer::Create(&client_); | |
2233 m_rootLayer->SetIsDrawable(true); | |
2234 m_rootLayer->SetBounds(gfx::Size(100, 100)); | |
2235 layer_tree_host()->SetRootLayer(m_rootLayer); | |
2236 PostSetNeedsCommitToMainThread(); | |
2237 } else | |
2238 EndTest(); | |
2239 } | |
2240 | |
2241 virtual void AfterTest() OVERRIDE | |
2242 { | |
2243 } | |
2244 | |
2245 private: | |
2246 FakeContentLayerClient client_; | |
2247 scoped_refptr<ContentLayer> m_rootLayer; | |
2248 int m_numCommits; | |
2249 }; | |
2250 | |
2251 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPinchZoomScrollbarNewRootLayer) | |
2252 | |
2253 class LayerTreeHostTestLCDNotification : public LayerTreeHostTest { | |
2254 public: | |
2255 class NotificationClient : public ContentLayerClient { | |
2256 public: | |
2257 NotificationClient() | |
2258 : layer_(0) | |
2259 , paint_count_(0) | |
2260 , lcd_notification_count_(0) | |
2261 { | |
2262 } | |
2263 | |
2264 void set_layer(Layer* layer) { layer_ = layer; } | |
2265 int paint_count() const { return paint_count_; } | |
2266 int lcd_notification_count() const { return lcd_notification_count_; } | |
2267 | |
2268 virtual void PaintContents(SkCanvas* canvas, | |
2269 gfx::Rect clip, | |
2270 gfx::RectF* opaque) OVERRIDE | |
2271 { | |
2272 ++paint_count_; | |
2273 } | |
2274 virtual void DidChangeLayerCanUseLCDText() OVERRIDE | |
2275 { | |
2276 ++lcd_notification_count_; | |
2277 layer_->SetNeedsDisplay(); | |
2278 } | |
2279 | |
2280 private: | |
2281 Layer* layer_; | |
2282 int paint_count_; | |
2283 int lcd_notification_count_; | |
2284 }; | |
2285 | |
2286 virtual void SetupTree() OVERRIDE | |
2287 { | |
2288 scoped_refptr<ContentLayer> root_layer = ContentLayer::Create(&client_); | |
2289 root_layer->SetIsDrawable(true); | |
2290 root_layer->SetBounds(gfx::Size(1, 1)); | |
2291 | |
2292 layer_tree_host()->SetRootLayer(root_layer); | |
2293 client_.set_layer(root_layer.get()); | |
2294 | |
2295 // The expecations are based on the assumption that the default | |
2296 // LCD settings are: | |
2297 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); | |
2298 EXPECT_FALSE(root_layer->can_use_lcd_text()); | |
2299 | |
2300 LayerTreeHostTest::SetupTree(); | |
2301 } | |
2302 | |
2303 virtual void BeginTest() OVERRIDE | |
2304 { | |
2305 PostSetNeedsCommitToMainThread(); | |
2306 } | |
2307 virtual void AfterTest() OVERRIDE { } | |
2308 | |
2309 virtual void DidCommit() OVERRIDE | |
2310 { | |
2311 switch (layer_tree_host()->commit_number()) { | |
2312 case 1: | |
2313 // The first update consists one LCD notification and one paint. | |
2314 EXPECT_EQ(1, client_.lcd_notification_count()); | |
2315 EXPECT_EQ(1, client_.paint_count()); | |
2316 // LCD text must have been enabled on the layer. | |
2317 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | |
2318 PostSetNeedsCommitToMainThread(); | |
2319 break; | |
2320 case 2: | |
2321 // Since nothing changed on layer, there should be no notification | |
2322 // or paint on the second update. | |
2323 EXPECT_EQ(1, client_.lcd_notification_count()); | |
2324 EXPECT_EQ(1, client_.paint_count()); | |
2325 // LCD text must not have changed. | |
2326 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | |
2327 // Change layer opacity that should trigger lcd notification. | |
2328 layer_tree_host()->root_layer()->SetOpacity(0.5); | |
2329 // No need to request a commit - setting opacity will do it. | |
2330 break; | |
2331 default: | |
2332 // Verify that there is not extra commit due to layer invalidation. | |
2333 EXPECT_EQ(3, layer_tree_host()->commit_number()); | |
2334 // LCD notification count should have incremented due to | |
2335 // change in layer opacity. | |
2336 EXPECT_EQ(2, client_.lcd_notification_count()); | |
2337 // Paint count should be incremented due to invalidation. | |
2338 EXPECT_EQ(2, client_.paint_count()); | |
2339 // LCD text must have been disabled on the layer due to opacity. | |
2340 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); | |
2341 EndTest(); | |
2342 break; | |
2343 } | |
2344 } | |
2345 | |
2346 private: | |
2347 NotificationClient client_; | |
2348 }; | |
2349 | |
2350 SINGLE_THREAD_TEST_F(LayerTreeHostTestLCDNotification) | |
2351 | 2166 |
2352 } // namespace | 2167 } // namespace |
2353 } // namespace cc | 2168 } // namespace cc |
OLD | NEW |