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