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