| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "cc/layers/content_layer.h" | 8 #include "cc/layers/content_layer.h" |
| 9 #include "cc/layers/delegated_frame_provider.h" | 9 #include "cc/layers/delegated_frame_provider.h" |
| 10 #include "cc/layers/delegated_frame_resource_collection.h" | 10 #include "cc/layers/delegated_frame_resource_collection.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 : LayerTreeTest(), | 56 : LayerTreeTest(), |
| 57 context3d_(NULL), | 57 context3d_(NULL), |
| 58 times_to_fail_create_(0), | 58 times_to_fail_create_(0), |
| 59 times_to_lose_during_commit_(0), | 59 times_to_lose_during_commit_(0), |
| 60 times_to_lose_during_draw_(0), | 60 times_to_lose_during_draw_(0), |
| 61 times_to_fail_recreate_(0), | 61 times_to_fail_recreate_(0), |
| 62 times_to_expect_create_failed_(0), | 62 times_to_expect_create_failed_(0), |
| 63 times_create_failed_(0), | 63 times_create_failed_(0), |
| 64 committed_at_least_once_(false), | 64 committed_at_least_once_(false), |
| 65 context_should_support_io_surface_(false), | 65 context_should_support_io_surface_(false), |
| 66 fallback_context_works_(false) { | 66 fallback_context_works_(false), |
| 67 async_output_surface_creation_(false) { |
| 67 media::InitializeMediaLibraryForTesting(); | 68 media::InitializeMediaLibraryForTesting(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void LoseContext() { | 71 void LoseContext() { |
| 71 // For sanity-checking tests, they should only call this when the | 72 // For sanity-checking tests, they should only call this when the |
| 72 // context is not lost. | 73 // context is not lost. |
| 73 CHECK(context3d_); | 74 CHECK(context3d_); |
| 74 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 75 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
| 75 GL_INNOCENT_CONTEXT_RESET_ARB); | 76 GL_INNOCENT_CONTEXT_RESET_ARB); |
| 76 context3d_ = NULL; | 77 context3d_ = NULL; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 TestWebGraphicsContext3D* context3d_; | 147 TestWebGraphicsContext3D* context3d_; |
| 147 int times_to_fail_create_; | 148 int times_to_fail_create_; |
| 148 int times_to_lose_during_commit_; | 149 int times_to_lose_during_commit_; |
| 149 int times_to_lose_during_draw_; | 150 int times_to_lose_during_draw_; |
| 150 int times_to_fail_recreate_; | 151 int times_to_fail_recreate_; |
| 151 int times_to_expect_create_failed_; | 152 int times_to_expect_create_failed_; |
| 152 int times_create_failed_; | 153 int times_create_failed_; |
| 153 bool committed_at_least_once_; | 154 bool committed_at_least_once_; |
| 154 bool context_should_support_io_surface_; | 155 bool context_should_support_io_surface_; |
| 155 bool fallback_context_works_; | 156 bool fallback_context_works_; |
| 157 bool async_output_surface_creation_; |
| 156 }; | 158 }; |
| 157 | 159 |
| 158 class LayerTreeHostContextTestLostContextSucceeds | 160 class LayerTreeHostContextTestLostContextSucceeds |
| 159 : public LayerTreeHostContextTest { | 161 : public LayerTreeHostContextTest { |
| 160 public: | 162 public: |
| 161 LayerTreeHostContextTestLostContextSucceeds() | 163 LayerTreeHostContextTestLostContextSucceeds() |
| 162 : LayerTreeHostContextTest(), | 164 : LayerTreeHostContextTest(), |
| 163 test_case_(0), | 165 test_case_(0), |
| 164 num_losses_(0), | 166 num_losses_(0), |
| 165 num_losses_last_test_case_(-1), | 167 num_losses_last_test_case_(-1), |
| 166 recovered_context_(true), | 168 recovered_context_(true), |
| 167 first_initialized_(false) {} | 169 first_initialized_(false) {} |
| 168 | 170 |
| 169 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 171 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 170 | 172 |
| 173 virtual void RequestNewOutputSurface(bool fallback) OVERRIDE { |
| 174 if (async_output_surface_creation_) { |
| 175 MainThreadTaskRunner()->PostTask( |
| 176 FROM_HERE, |
| 177 base::Bind(&LayerTreeHostContextTestLostContextSucceeds:: |
| 178 CreateAndSetOutputSurface, |
| 179 base::Unretained(this), |
| 180 fallback)); |
| 181 } else { |
| 182 CreateAndSetOutputSurface(fallback); |
| 183 } |
| 184 } |
| 185 |
| 186 void CreateAndSetOutputSurface(bool fallback) { |
| 187 layer_tree_host()->SetOutputSurface( |
| 188 LayerTreeHostContextTest::CreateOutputSurface(fallback)); |
| 189 } |
| 190 |
| 171 virtual void DidInitializeOutputSurface() OVERRIDE { | 191 virtual void DidInitializeOutputSurface() OVERRIDE { |
| 172 if (first_initialized_) | 192 if (first_initialized_) |
| 173 ++num_losses_; | 193 ++num_losses_; |
| 174 else | 194 else |
| 175 first_initialized_ = true; | 195 first_initialized_ = true; |
| 176 | 196 |
| 177 recovered_context_ = true; | 197 recovered_context_ = true; |
| 178 } | 198 } |
| 179 | 199 |
| 180 virtual void AfterTest() OVERRIDE { EXPECT_EQ(7u, test_case_); } | 200 virtual void AfterTest() OVERRIDE { EXPECT_EQ(11u, test_case_); } |
| 181 | 201 |
| 182 virtual void DidCommitAndDrawFrame() OVERRIDE { | 202 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 183 // If the last frame had a context loss, then we'll commit again to | 203 // If the last frame had a context loss, then we'll commit again to |
| 184 // recover. | 204 // recover. |
| 185 if (!recovered_context_) | 205 if (!recovered_context_) |
| 186 return; | 206 return; |
| 187 if (times_to_lose_during_commit_) | 207 if (times_to_lose_during_commit_) |
| 188 return; | 208 return; |
| 189 if (times_to_lose_during_draw_) | 209 if (times_to_lose_during_draw_) |
| 190 return; | 210 return; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 204 | 224 |
| 205 bool NextTestCase() { | 225 bool NextTestCase() { |
| 206 static const TestCase kTests[] = { | 226 static const TestCase kTests[] = { |
| 207 // Losing the context and failing to recreate it (or losing it again | 227 // Losing the context and failing to recreate it (or losing it again |
| 208 // immediately) a small number of times should succeed. | 228 // immediately) a small number of times should succeed. |
| 209 { | 229 { |
| 210 1, // times_to_lose_during_commit | 230 1, // times_to_lose_during_commit |
| 211 0, // times_to_lose_during_draw | 231 0, // times_to_lose_during_draw |
| 212 0, // times_to_fail_recreate | 232 0, // times_to_fail_recreate |
| 213 false, // fallback_context_works | 233 false, // fallback_context_works |
| 234 false, // async_output_surface_creation |
| 214 }, | 235 }, |
| 215 { | 236 { |
| 216 0, // times_to_lose_during_commit | 237 0, // times_to_lose_during_commit |
| 217 1, // times_to_lose_during_draw | 238 1, // times_to_lose_during_draw |
| 218 0, // times_to_fail_recreate | 239 0, // times_to_fail_recreate |
| 219 false, // fallback_context_works | 240 false, // fallback_context_works |
| 241 false, // async_output_surface_creation |
| 220 }, | 242 }, |
| 221 { | 243 { |
| 222 1, // times_to_lose_during_commit | 244 1, // times_to_lose_during_commit |
| 223 0, // times_to_lose_during_draw | 245 0, // times_to_lose_during_draw |
| 224 3, // times_to_fail_recreate | 246 3, // times_to_fail_recreate |
| 225 false, // fallback_context_works | 247 false, // fallback_context_works |
| 248 false, // async_output_surface_creation |
| 226 }, | 249 }, |
| 227 { | 250 { |
| 228 0, // times_to_lose_during_commit | 251 0, // times_to_lose_during_commit |
| 229 1, // times_to_lose_during_draw | 252 1, // times_to_lose_during_draw |
| 230 3, // times_to_fail_recreate | 253 3, // times_to_fail_recreate |
| 231 false, // fallback_context_works | 254 false, // fallback_context_works |
| 255 false, // async_output_surface_creation |
| 256 }, |
| 257 { |
| 258 0, // times_to_lose_during_commit |
| 259 1, // times_to_lose_during_draw |
| 260 3, // times_to_fail_recreate |
| 261 false, // fallback_context_works |
| 262 true, // async_output_surface_creation |
| 232 }, | 263 }, |
| 233 // Losing the context and recreating it any number of times should | 264 // Losing the context and recreating it any number of times should |
| 234 // succeed. | 265 // succeed. |
| 235 { | 266 { |
| 236 10, // times_to_lose_during_commit | 267 10, // times_to_lose_during_commit |
| 237 0, // times_to_lose_during_draw | 268 0, // times_to_lose_during_draw |
| 238 0, // times_to_fail_recreate | 269 0, // times_to_fail_recreate |
| 239 false, // fallback_context_works | 270 false, // fallback_context_works |
| 271 false, // async_output_surface_creation |
| 240 }, | 272 }, |
| 241 { | 273 { |
| 242 0, // times_to_lose_during_commit | 274 0, // times_to_lose_during_commit |
| 243 10, // times_to_lose_during_draw | 275 10, // times_to_lose_during_draw |
| 244 0, // times_to_fail_recreate | 276 0, // times_to_fail_recreate |
| 245 false, // fallback_context_works | 277 false, // fallback_context_works |
| 278 false, // async_output_surface_creation |
| 279 }, |
| 280 { |
| 281 10, // times_to_lose_during_commit |
| 282 0, // times_to_lose_during_draw |
| 283 0, // times_to_fail_recreate |
| 284 false, // fallback_context_works |
| 285 true, // async_output_surface_creation |
| 286 }, |
| 287 { |
| 288 0, // times_to_lose_during_commit |
| 289 10, // times_to_lose_during_draw |
| 290 0, // times_to_fail_recreate |
| 291 false, // fallback_context_works |
| 292 true, // async_output_surface_creation |
| 246 }, | 293 }, |
| 247 // Losing the context, failing to reinitialize it, and making a fallback | 294 // Losing the context, failing to reinitialize it, and making a fallback |
| 248 // context should work. | 295 // context should work. |
| 249 { | 296 { |
| 297 0, // times_to_lose_during_commit |
| 298 1, // times_to_lose_during_draw |
| 299 0, // times_to_fail_recreate |
| 300 true, // fallback_context_works |
| 301 false, // async_output_surface_creation |
| 302 }, |
| 303 { |
| 250 0, // times_to_lose_during_commit | 304 0, // times_to_lose_during_commit |
| 251 1, // times_to_lose_during_draw | 305 1, // times_to_lose_during_draw |
| 252 0, // times_to_fail_recreate | 306 0, // times_to_fail_recreate |
| 253 true, // fallback_context_works | 307 true, // fallback_context_works |
| 308 true, // async_output_surface_creation |
| 254 }, | 309 }, |
| 255 }; | 310 }; |
| 256 | 311 |
| 257 if (test_case_ >= arraysize(kTests)) | 312 if (test_case_ >= arraysize(kTests)) |
| 258 return false; | 313 return false; |
| 259 // Make sure that we lost our context at least once in the last test run so | 314 // Make sure that we lost our context at least once in the last test run so |
| 260 // the test did something. | 315 // the test did something. |
| 261 EXPECT_GT(num_losses_, num_losses_last_test_case_); | 316 EXPECT_GT(num_losses_, num_losses_last_test_case_); |
| 262 num_losses_last_test_case_ = num_losses_; | 317 num_losses_last_test_case_ = num_losses_; |
| 263 | 318 |
| 264 times_to_lose_during_commit_ = | 319 times_to_lose_during_commit_ = |
| 265 kTests[test_case_].times_to_lose_during_commit; | 320 kTests[test_case_].times_to_lose_during_commit; |
| 266 times_to_lose_during_draw_ = kTests[test_case_].times_to_lose_during_draw; | 321 times_to_lose_during_draw_ = kTests[test_case_].times_to_lose_during_draw; |
| 267 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; | 322 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; |
| 268 fallback_context_works_ = kTests[test_case_].fallback_context_works; | 323 fallback_context_works_ = kTests[test_case_].fallback_context_works; |
| 324 async_output_surface_creation_ = |
| 325 kTests[test_case_].async_output_surface_creation; |
| 269 ++test_case_; | 326 ++test_case_; |
| 270 return true; | 327 return true; |
| 271 } | 328 } |
| 272 | 329 |
| 273 struct TestCase { | 330 struct TestCase { |
| 274 int times_to_lose_during_commit; | 331 int times_to_lose_during_commit; |
| 275 int times_to_lose_during_draw; | 332 int times_to_lose_during_draw; |
| 276 int times_to_fail_recreate; | 333 int times_to_fail_recreate; |
| 277 bool fallback_context_works; | 334 bool fallback_context_works; |
| 335 bool async_output_surface_creation; |
| 278 }; | 336 }; |
| 279 | 337 |
| 280 protected: | 338 protected: |
| 281 size_t test_case_; | 339 size_t test_case_; |
| 282 int num_losses_; | 340 int num_losses_; |
| 283 int num_losses_last_test_case_; | 341 int num_losses_last_test_case_; |
| 284 bool recovered_context_; | 342 bool recovered_context_; |
| 285 bool first_initialized_; | 343 bool first_initialized_; |
| 286 }; | 344 }; |
| 287 | 345 |
| (...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1648 virtual void AfterTest() OVERRIDE {} | 1706 virtual void AfterTest() OVERRIDE {} |
| 1649 | 1707 |
| 1650 bool deferred_; | 1708 bool deferred_; |
| 1651 }; | 1709 }; |
| 1652 | 1710 |
| 1653 SINGLE_AND_MULTI_THREAD_TEST_F( | 1711 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1654 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); | 1712 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); |
| 1655 | 1713 |
| 1656 } // namespace | 1714 } // namespace |
| 1657 } // namespace cc | 1715 } // namespace cc |
| OLD | NEW |