| 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/layer_tree_host.h" | 5 #include "cc/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "cc/content_layer.h" | 8 #include "cc/content_layer.h" |
| 9 #include "cc/delegated_renderer_layer.h" | 9 #include "cc/delegated_renderer_layer.h" |
| 10 #include "cc/delegated_renderer_layer_impl.h" | 10 #include "cc/delegated_renderer_layer_impl.h" |
| 11 #include "cc/ganesh_context_provider.h" |
| 11 #include "cc/heads_up_display_layer.h" | 12 #include "cc/heads_up_display_layer.h" |
| 12 #include "cc/io_surface_layer.h" | 13 #include "cc/io_surface_layer.h" |
| 13 #include "cc/layer_impl.h" | 14 #include "cc/layer_impl.h" |
| 14 #include "cc/layer_tree_host_impl.h" | 15 #include "cc/layer_tree_host_impl.h" |
| 15 #include "cc/layer_tree_impl.h" | 16 #include "cc/layer_tree_impl.h" |
| 16 #include "cc/picture_layer.h" | 17 #include "cc/picture_layer.h" |
| 17 #include "cc/scrollbar_layer.h" | 18 #include "cc/scrollbar_layer.h" |
| 18 #include "cc/single_thread_proxy.h" | 19 #include "cc/single_thread_proxy.h" |
| 19 #include "cc/test/fake_content_layer.h" | 20 #include "cc/test/fake_content_layer.h" |
| 20 #include "cc/test/fake_content_layer_client.h" | 21 #include "cc/test/fake_content_layer_client.h" |
| 21 #include "cc/test/fake_content_layer_impl.h" | 22 #include "cc/test/fake_content_layer_impl.h" |
| 22 #include "cc/test/fake_output_surface.h" | 23 #include "cc/test/fake_output_surface.h" |
| 23 #include "cc/test/fake_scrollbar_layer.h" | 24 #include "cc/test/fake_scrollbar_layer.h" |
| 24 #include "cc/test/fake_scrollbar_theme_painter.h" | 25 #include "cc/test/fake_scrollbar_theme_painter.h" |
| 25 #include "cc/test/fake_video_frame_provider.h" | 26 #include "cc/test/fake_video_frame_provider.h" |
| 26 #include "cc/test/fake_web_graphics_context_3d.h" | 27 #include "cc/test/fake_web_graphics_context_3d.h" |
| 27 #include "cc/test/fake_web_scrollbar.h" | 28 #include "cc/test/fake_web_scrollbar.h" |
| 28 #include "cc/test/fake_web_scrollbar_theme_geometry.h" | 29 #include "cc/test/fake_web_scrollbar_theme_geometry.h" |
| 29 #include "cc/test/layer_tree_test_common.h" | 30 #include "cc/test/layer_tree_test_common.h" |
| 30 #include "cc/test/render_pass_test_common.h" | 31 #include "cc/test/render_pass_test_common.h" |
| 31 #include "cc/texture_layer.h" | 32 #include "cc/texture_layer.h" |
| 32 #include "cc/video_layer.h" | 33 #include "cc/video_layer.h" |
| 33 #include "cc/video_layer_impl.h" | 34 #include "cc/video_layer_impl.h" |
| 34 #include "gpu/GLES2/gl2extchromium.h" | 35 #include "gpu/GLES2/gl2extchromium.h" |
| 35 #include "media/base/media.h" | 36 #include "media/base/media.h" |
| 37 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" |
| 36 | 38 |
| 37 using media::VideoFrame; | 39 using media::VideoFrame; |
| 38 using WebKit::WebGraphicsContext3D; | 40 using WebKit::WebGraphicsContext3D; |
| 39 | 41 |
| 40 namespace cc { | 42 namespace cc { |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 // These tests deal with losing the 3d graphics context. | 45 // These tests deal with losing the 3d graphics context. |
| 44 class LayerTreeHostContextTest : public ThreadedTest { | 46 class LayerTreeHostContextTest : public ThreadedTest { |
| 45 public: | 47 public: |
| 46 LayerTreeHostContextTest() | 48 LayerTreeHostContextTest() |
| 47 : ThreadedTest(), | 49 : ThreadedTest(), |
| 48 context3d_(NULL), | 50 context3d_(NULL), |
| 49 times_to_fail_create_(0), | 51 times_to_fail_create_(0), |
| 50 times_to_fail_initialize_(0), | 52 times_to_fail_initialize_(0), |
| 51 times_to_lose_on_create_(0), | 53 times_to_lose_on_create_(0), |
| 52 times_to_lose_during_commit_(0), | 54 times_to_lose_during_commit_(0), |
| 53 times_to_lose_during_draw_(0), | 55 times_to_lose_during_draw_(0), |
| 54 times_to_fail_recreate_(0), | 56 times_to_fail_recreate_(0), |
| 55 times_to_fail_reinitialize_(0), | 57 times_to_fail_reinitialize_(0), |
| 56 times_to_lose_on_recreate_(0) { | 58 times_to_lose_on_recreate_(0), |
| 59 times_to_fail_create_offscreen_(0), |
| 60 times_to_lose_on_create_offscreen_(0), |
| 61 times_to_fail_recreate_offscreen_(0), |
| 62 times_to_lose_on_recreate_offscreen_(0), |
| 63 times_to_expect_recreate_retried_(0), |
| 64 times_recreate_retried_(0) { |
| 57 media::InitializeMediaLibraryForTesting(); | 65 media::InitializeMediaLibraryForTesting(); |
| 58 } | 66 } |
| 59 | 67 |
| 60 void LoseContext() { | 68 void LoseContext() { |
| 61 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 69 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
| 62 GL_INNOCENT_CONTEXT_RESET_ARB); | 70 GL_INNOCENT_CONTEXT_RESET_ARB); |
| 63 context3d_ = NULL; | 71 context3d_ = NULL; |
| 64 } | 72 } |
| 65 | 73 |
| 66 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() { | 74 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() { |
| 67 return FakeWebGraphicsContext3D::Create(); | 75 return FakeWebGraphicsContext3D::Create(); |
| 68 } | 76 } |
| 69 | 77 |
| 70 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE { | 78 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE { |
| 71 if (times_to_fail_create_) { | 79 if (times_to_fail_create_) { |
| 72 --times_to_fail_create_; | 80 --times_to_fail_create_; |
| 81 ExpectRecreateToRetry(); |
| 73 return scoped_ptr<OutputSurface>(); | 82 return scoped_ptr<OutputSurface>(); |
| 74 } | 83 } |
| 75 | 84 |
| 76 scoped_ptr<FakeWebGraphicsContext3D> context3d = CreateContext3d(); | 85 scoped_ptr<FakeWebGraphicsContext3D> context3d = CreateContext3d(); |
| 77 context3d_ = context3d.get(); | 86 context3d_ = context3d.get(); |
| 78 | 87 |
| 79 if (times_to_fail_initialize_) { | 88 if (times_to_fail_initialize_) { |
| 80 --times_to_fail_initialize_; | 89 --times_to_fail_initialize_; |
| 81 // Make the context get lost during reinitialization. | 90 // Make the context get lost during reinitialization. |
| 82 // The number of times MakeCurrent succeeds is not important, and | 91 // The number of times MakeCurrent succeeds is not important, and |
| 83 // can be changed if needed to make this pass with future changes. | 92 // can be changed if needed to make this pass with future changes. |
| 84 context3d_->set_times_make_current_succeeds(2); | 93 context3d_->set_times_make_current_succeeds(2); |
| 94 ExpectRecreateToRetry(); |
| 85 } else if (times_to_lose_on_create_) { | 95 } else if (times_to_lose_on_create_) { |
| 86 --times_to_lose_on_create_; | 96 --times_to_lose_on_create_; |
| 87 LoseContext(); | 97 LoseContext(); |
| 98 ExpectRecreateToRetry(); |
| 88 } | 99 } |
| 89 | 100 |
| 90 return FakeOutputSurface::Create3d( | 101 return FakeOutputSurface::Create3d( |
| 91 context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>(); | 102 context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>(); |
| 92 } | 103 } |
| 93 | 104 |
| 94 virtual bool prepareToDrawOnThread( | 105 WebKit::WebGraphicsContext3D* CreateOffscreenContext3d() { |
| 95 LayerTreeHostImpl*, LayerTreeHostImpl::FrameData&, bool result) | 106 DCHECK(!offscreen_context3d_); |
| 96 OVERRIDE { | |
| 97 EXPECT_TRUE(result); | |
| 98 if (!times_to_lose_during_draw_) | |
| 99 return result; | |
| 100 | 107 |
| 101 --times_to_lose_during_draw_; | 108 if (times_to_fail_create_offscreen_) { |
| 102 if (context3d_) | 109 --times_to_fail_create_offscreen_; |
| 103 context3d_->set_times_make_current_succeeds(0); | 110 ExpectRecreateToRetry(); |
| 111 return NULL; |
| 112 } |
| 113 |
| 114 WebKit::WebGraphicsContext3D::Attributes attrs; |
| 115 offscreen_context3d_ = |
| 116 FakeWebGraphicsContext3D::Create(attrs) |
| 117 .PassAs<WebKit::WebGraphicsContext3D>(); |
| 118 DCHECK(offscreen_context3d_); |
| 119 |
| 120 if (times_to_lose_on_create_offscreen_) { |
| 121 --times_to_lose_on_create_offscreen_; |
| 122 offscreen_context3d_->loseContextCHROMIUM( |
| 123 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
| 124 offscreen_context3d_.reset(); |
| 125 ExpectRecreateToRetry(); |
| 126 } |
| 127 |
| 128 return offscreen_context3d_.get(); |
| 129 } |
| 130 |
| 131 // LayerTreeHostClient implementation. |
| 132 virtual WebKit::WebGraphicsContext3D* OffscreenContext3dForMainThread() |
| 133 OVERRIDE { |
| 134 DCHECK(!implThread()); |
| 135 |
| 136 if (!offscreen_context3d_) |
| 137 CreateOffscreenContext3d(); |
| 138 return offscreen_context3d_.get(); |
| 139 } |
| 140 |
| 141 // LayerTreeHostClient implementation. |
| 142 virtual WebKit::WebGraphicsContext3D* OffscreenContext3dForCompositorThread() |
| 143 OVERRIDE { |
| 144 DCHECK(implThread()); |
| 145 |
| 146 if (!offscreen_context3d_) |
| 147 CreateOffscreenContext3d(); |
| 148 return offscreen_context3d_.get(); |
| 149 } |
| 150 |
| 151 // LayerTreeHostClient implementation. |
| 152 virtual GrContext* OffscreenGrContextForMainThread() OVERRIDE { |
| 153 DCHECK(!implThread()); |
| 154 // TODO(danakj): Make a FakeGrContext. |
| 155 return NULL; |
| 156 } |
| 157 |
| 158 // LayerTreeHostClient implementation. |
| 159 virtual GrContext* OffscreenGrContextForCompositorThread() OVERRIDE { |
| 160 DCHECK(implThread()); |
| 161 // TODO(danakj): Make a FakeGrContext. |
| 162 return NULL; |
| 163 } |
| 164 |
| 165 virtual bool prepareToDrawOnThread( |
| 166 LayerTreeHostImpl*, LayerTreeHostImpl::FrameData&, bool result) |
| 167 OVERRIDE { |
| 168 EXPECT_TRUE(result); |
| 169 if (!times_to_lose_during_draw_) |
| 104 return result; | 170 return result; |
| 105 } | 171 |
| 172 --times_to_lose_during_draw_; |
| 173 if (context3d_) |
| 174 context3d_->set_times_make_current_succeeds(0); |
| 175 return result; |
| 176 } |
| 106 | 177 |
| 107 virtual void commitCompleteOnThread(LayerTreeHostImpl *host_impl) OVERRIDE { | 178 virtual void commitCompleteOnThread(LayerTreeHostImpl *host_impl) OVERRIDE { |
| 108 if (!times_to_lose_during_commit_) | 179 if (!times_to_lose_during_commit_) |
| 109 return; | 180 return; |
| 110 --times_to_lose_during_commit_; | 181 --times_to_lose_during_commit_; |
| 111 LoseContext(); | 182 LoseContext(); |
| 112 | 183 |
| 113 times_to_fail_create_ = times_to_fail_recreate_; | 184 times_to_fail_create_ = times_to_fail_recreate_; |
| 114 times_to_fail_recreate_ = 0; | 185 times_to_fail_recreate_ = 0; |
| 115 times_to_fail_initialize_ = times_to_fail_reinitialize_; | 186 times_to_fail_initialize_ = times_to_fail_reinitialize_; |
| 116 times_to_fail_reinitialize_ = 0; | 187 times_to_fail_reinitialize_ = 0; |
| 117 times_to_lose_on_create_ = times_to_lose_on_recreate_; | 188 times_to_lose_on_create_ = times_to_lose_on_recreate_; |
| 118 times_to_lose_on_recreate_ = 0; | 189 times_to_lose_on_recreate_ = 0; |
| 190 times_to_fail_create_offscreen_ = times_to_fail_recreate_offscreen_; |
| 191 times_to_fail_recreate_offscreen_ = 0; |
| 192 times_to_lose_on_create_offscreen_ = times_to_lose_on_recreate_offscreen_; |
| 193 times_to_lose_on_recreate_offscreen_ = 0; |
| 194 } |
| 195 |
| 196 virtual void willRetryRecreateOutputSurface() OVERRIDE { |
| 197 ++times_recreate_retried_; |
| 198 } |
| 199 |
| 200 virtual void TearDown() OVERRIDE { |
| 201 ThreadedTest::TearDown(); |
| 202 EXPECT_EQ(times_to_expect_recreate_retried_, times_recreate_retried_); |
| 203 } |
| 204 |
| 205 void ExpectRecreateToRetry() { |
| 206 ++times_to_expect_recreate_retried_; |
| 119 } | 207 } |
| 120 | 208 |
| 121 protected: | 209 protected: |
| 122 FakeWebGraphicsContext3D* context3d_; | 210 FakeWebGraphicsContext3D* context3d_; |
| 123 int times_to_fail_create_; | 211 int times_to_fail_create_; |
| 124 int times_to_fail_initialize_; | 212 int times_to_fail_initialize_; |
| 125 int times_to_lose_on_create_; | 213 int times_to_lose_on_create_; |
| 126 int times_to_lose_during_commit_; | 214 int times_to_lose_during_commit_; |
| 127 int times_to_lose_during_draw_; | 215 int times_to_lose_during_draw_; |
| 128 int times_to_fail_reinitialize_; | 216 int times_to_fail_reinitialize_; |
| 129 int times_to_fail_recreate_; | 217 int times_to_fail_recreate_; |
| 130 int times_to_lose_on_recreate_; | 218 int times_to_lose_on_recreate_; |
| 219 int times_to_fail_create_offscreen_; |
| 220 int times_to_lose_on_create_offscreen_; |
| 221 int times_to_fail_recreate_offscreen_; |
| 222 int times_to_lose_on_recreate_offscreen_; |
| 223 int times_to_expect_recreate_retried_; |
| 224 int times_recreate_retried_; |
| 225 |
| 226 scoped_ptr<WebKit::WebGraphicsContext3D> offscreen_context3d_; |
| 131 }; | 227 }; |
| 132 | 228 |
| 133 class LayerTreeHostContextTestLostContextSucceeds : | 229 class LayerTreeHostContextTestLostContextSucceeds : |
| 134 public LayerTreeHostContextTest { | 230 public LayerTreeHostContextTest { |
| 135 public: | 231 public: |
| 136 LayerTreeHostContextTestLostContextSucceeds() | 232 LayerTreeHostContextTestLostContextSucceeds() |
| 137 : LayerTreeHostContextTest(), | 233 : LayerTreeHostContextTest(), |
| 138 test_case_(0), | 234 test_case_(0), |
| 139 num_losses_(0), | 235 num_losses_(0), |
| 140 recovered_context_(true) { | 236 recovered_context_(true) { |
| 141 } | 237 } |
| 142 | 238 |
| 143 virtual void beginTest() OVERRIDE { | 239 virtual void beginTest() OVERRIDE { |
| 144 postSetNeedsCommitToMainThread(); | 240 postSetNeedsCommitToMainThread(); |
| 145 } | 241 } |
| 146 | 242 |
| 147 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { | 243 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { |
| 148 EXPECT_TRUE(succeeded); | 244 EXPECT_TRUE(succeeded); |
| 149 ++num_losses_; | 245 ++num_losses_; |
| 150 recovered_context_ = true; | 246 recovered_context_ = true; |
| 151 } | 247 } |
| 152 | 248 |
| 153 virtual void afterTest() OVERRIDE { | 249 virtual void afterTest() OVERRIDE { |
| 154 EXPECT_EQ(8, test_case_); | 250 EXPECT_EQ(12, test_case_); |
| 155 EXPECT_EQ(6 + 10 + 10, num_losses_); | 251 EXPECT_EQ(10 + 10 + 10, num_losses_); |
| 156 } | 252 } |
| 157 | 253 |
| 158 virtual void didCommitAndDrawFrame() OVERRIDE { | 254 virtual void didCommitAndDrawFrame() OVERRIDE { |
| 159 // If the last frame had a context loss, then we'll commit again to | 255 // If the last frame had a context loss, then we'll commit again to |
| 160 // recover. | 256 // recover. |
| 161 if (!recovered_context_) | 257 if (!recovered_context_) |
| 162 return; | 258 return; |
| 163 if (times_to_lose_during_commit_) | 259 if (times_to_lose_during_commit_) |
| 164 return; | 260 return; |
| 165 if (times_to_lose_during_draw_) | 261 if (times_to_lose_during_draw_) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 178 | 274 |
| 179 bool NextTestCase() { | 275 bool NextTestCase() { |
| 180 static const TestCase kTests[] = { | 276 static const TestCase kTests[] = { |
| 181 // Losing the context and failing to recreate it (or losing it again | 277 // Losing the context and failing to recreate it (or losing it again |
| 182 // immediately) a small number of times should succeed. | 278 // immediately) a small number of times should succeed. |
| 183 { 1, // times_to_lose_during_commit | 279 { 1, // times_to_lose_during_commit |
| 184 0, // times_to_lose_during_draw | 280 0, // times_to_lose_during_draw |
| 185 3, // times_to_fail_reinitialize | 281 3, // times_to_fail_reinitialize |
| 186 0, // times_to_fail_recreate | 282 0, // times_to_fail_recreate |
| 187 0, // times_to_lose_on_recreate | 283 0, // times_to_lose_on_recreate |
| 284 0, // times_to_fail_recreate_offscreen; |
| 285 0, // times_to_lose_on_recreate_offscreen; |
| 188 }, | 286 }, |
| 189 { 0, // times_to_lose_during_commit | 287 { 0, // times_to_lose_during_commit |
| 190 1, // times_to_lose_during_draw | 288 1, // times_to_lose_during_draw |
| 191 3, // times_to_fail_reinitialize | 289 3, // times_to_fail_reinitialize |
| 192 0, // times_to_fail_recreate | 290 0, // times_to_fail_recreate |
| 193 0, // times_to_lose_on_recreate | 291 0, // times_to_lose_on_recreate |
| 292 0, // times_to_fail_recreate_offscreen; |
| 293 0, // times_to_lose_on_recreate_offscreen; |
| 194 }, | 294 }, |
| 195 { 1, // times_to_lose_during_commit | 295 { 1, // times_to_lose_during_commit |
| 196 0, // times_to_lose_during_draw | 296 0, // times_to_lose_during_draw |
| 197 0, // times_to_fail_reinitialize | 297 0, // times_to_fail_reinitialize |
| 198 3, // times_to_fail_recreate | 298 3, // times_to_fail_recreate |
| 199 0, // times_to_lose_on_recreate | 299 0, // times_to_lose_on_recreate |
| 300 0, // times_to_fail_recreate_offscreen; |
| 301 0, // times_to_lose_on_recreate_offscreen; |
| 200 }, | 302 }, |
| 201 { 0, // times_to_lose_during_commit | 303 { 0, // times_to_lose_during_commit |
| 202 1, // times_to_lose_during_draw | 304 1, // times_to_lose_during_draw |
| 203 0, // times_to_fail_reinitialize | 305 0, // times_to_fail_reinitialize |
| 204 3, // times_to_fail_recreate | 306 3, // times_to_fail_recreate |
| 205 0, // times_to_lose_on_recreate | 307 0, // times_to_lose_on_recreate |
| 308 0, // times_to_fail_recreate_offscreen; |
| 309 0, // times_to_lose_on_recreate_offscreen; |
| 206 }, | 310 }, |
| 207 { 1, // times_to_lose_during_commit | 311 { 1, // times_to_lose_during_commit |
| 208 0, // times_to_lose_during_draw | 312 0, // times_to_lose_during_draw |
| 209 0, // times_to_fail_reinitialize | 313 0, // times_to_fail_reinitialize |
| 210 0, // times_to_fail_recreate | 314 0, // times_to_fail_recreate |
| 211 3, // times_to_lose_on_recreate | 315 3, // times_to_lose_on_recreate |
| 316 0, // times_to_fail_recreate_offscreen; |
| 317 0, // times_to_lose_on_recreate_offscreen; |
| 212 }, | 318 }, |
| 213 { 0, // times_to_lose_during_commit | 319 { 0, // times_to_lose_during_commit |
| 214 1, // times_to_lose_during_draw | 320 1, // times_to_lose_during_draw |
| 215 0, // times_to_fail_reinitialize | 321 0, // times_to_fail_reinitialize |
| 216 0, // times_to_fail_recreate | 322 0, // times_to_fail_recreate |
| 217 3, // times_to_lose_on_recreate | 323 3, // times_to_lose_on_recreate |
| 324 0, // times_to_fail_recreate_offscreen; |
| 325 0, // times_to_lose_on_recreate_offscreen; |
| 326 }, |
| 327 { 1, // times_to_lose_during_commit |
| 328 0, // times_to_lose_during_draw |
| 329 0, // times_to_fail_reinitialize |
| 330 0, // times_to_fail_recreate |
| 331 0, // times_to_lose_on_recreate |
| 332 3, // times_to_fail_recreate_offscreen; |
| 333 0, // times_to_lose_on_recreate_offscreen; |
| 334 }, |
| 335 { 0, // times_to_lose_during_commit |
| 336 1, // times_to_lose_during_draw |
| 337 0, // times_to_fail_reinitialize |
| 338 0, // times_to_fail_recreate |
| 339 0, // times_to_lose_on_recreate |
| 340 3, // times_to_fail_recreate_offscreen; |
| 341 0, // times_to_lose_on_recreate_offscreen; |
| 342 }, |
| 343 { 1, // times_to_lose_during_commit |
| 344 0, // times_to_lose_during_draw |
| 345 0, // times_to_fail_reinitialize |
| 346 0, // times_to_fail_recreate |
| 347 0, // times_to_lose_on_recreate |
| 348 3, // times_to_fail_recreate_offscreen; |
| 349 0, // times_to_lose_on_recreate_offscreen; |
| 350 }, |
| 351 { 0, // times_to_lose_during_commit |
| 352 1, // times_to_lose_during_draw |
| 353 0, // times_to_fail_reinitialize |
| 354 0, // times_to_fail_recreate |
| 355 0, // times_to_lose_on_recreate |
| 356 0, // times_to_fail_recreate_offscreen; |
| 357 3, // times_to_lose_on_recreate_offscreen; |
| 218 }, | 358 }, |
| 219 // Losing the context and recreating it any number of times should | 359 // Losing the context and recreating it any number of times should |
| 220 // succeed. | 360 // succeed. |
| 221 { 10, // times_to_lose_during_commit | 361 { 10, // times_to_lose_during_commit |
| 222 0, // times_to_lose_during_draw | 362 0, // times_to_lose_during_draw |
| 223 0, // times_to_fail_reinitialize | 363 0, // times_to_fail_reinitialize |
| 224 0, // times_to_fail_recreate | 364 0, // times_to_fail_recreate |
| 225 0, // times_to_lose_on_recreate | 365 0, // times_to_lose_on_recreate |
| 366 0, // times_to_fail_recreate_offscreen; |
| 367 0, // times_to_lose_on_recreate_offscreen; |
| 226 }, | 368 }, |
| 227 { 0, // times_to_lose_during_commit | 369 { 0, // times_to_lose_during_commit |
| 228 10, // times_to_lose_during_draw | 370 10, // times_to_lose_during_draw |
| 229 0, // times_to_fail_reinitialize | 371 0, // times_to_fail_reinitialize |
| 230 0, // times_to_fail_recreate | 372 0, // times_to_fail_recreate |
| 231 0, // times_to_lose_on_recreate | 373 0, // times_to_lose_on_recreate |
| 374 0, // times_to_fail_recreate_offscreen; |
| 375 0, // times_to_lose_on_recreate_offscreen; |
| 232 }, | 376 }, |
| 233 }; | 377 }; |
| 234 | 378 |
| 235 if (test_case_ >= arraysize(kTests)) | 379 if (test_case_ >= arraysize(kTests)) |
| 236 return false; | 380 return false; |
| 237 | 381 |
| 238 times_to_lose_during_commit_ = | 382 times_to_lose_during_commit_ = |
| 239 kTests[test_case_].times_to_lose_during_commit; | 383 kTests[test_case_].times_to_lose_during_commit; |
| 240 times_to_lose_during_draw_ = | 384 times_to_lose_during_draw_ = |
| 241 kTests[test_case_].times_to_lose_during_draw; | 385 kTests[test_case_].times_to_lose_during_draw; |
| 242 times_to_fail_reinitialize_ = kTests[test_case_].times_to_fail_reinitialize; | 386 times_to_fail_reinitialize_ = kTests[test_case_].times_to_fail_reinitialize; |
| 243 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; | 387 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; |
| 244 times_to_lose_on_recreate_ = kTests[test_case_].times_to_lose_on_recreate; | 388 times_to_lose_on_recreate_ = kTests[test_case_].times_to_lose_on_recreate; |
| 389 times_to_fail_recreate_offscreen_ = kTests[test_case_].times_to_fail_recreat
e_offscreen; |
| 390 times_to_lose_on_recreate_offscreen_ = kTests[test_case_].times_to_lose_on_r
ecreate_offscreen; |
| 245 ++test_case_; | 391 ++test_case_; |
| 246 return true; | 392 return true; |
| 247 } | 393 } |
| 248 | 394 |
| 249 struct TestCase { | 395 struct TestCase { |
| 250 int times_to_lose_during_commit; | 396 int times_to_lose_during_commit; |
| 251 int times_to_lose_during_draw; | 397 int times_to_lose_during_draw; |
| 252 int times_to_fail_reinitialize; | 398 int times_to_fail_reinitialize; |
| 253 int times_to_fail_recreate; | 399 int times_to_fail_recreate; |
| 254 int times_to_lose_on_recreate; | 400 int times_to_lose_on_recreate; |
| 401 int times_to_fail_recreate_offscreen; |
| 402 int times_to_lose_on_recreate_offscreen; |
| 255 }; | 403 }; |
| 256 | 404 |
| 257 private: | 405 private: |
| 258 size_t test_case_; | 406 size_t test_case_; |
| 259 int num_losses_; | 407 int num_losses_; |
| 260 bool recovered_context_; | 408 bool recovered_context_; |
| 261 }; | 409 }; |
| 262 | 410 |
| 263 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds) | 411 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds) |
| 264 | 412 |
| 265 class LayerTreeHostContextTestLostContextSucceedsWithContent : | 413 class LayerTreeHostContextTestLostContextSucceedsWithContent : |
| 266 public LayerTreeHostContextTestLostContextSucceeds { | 414 public LayerTreeHostContextTestLostContextSucceeds { |
| 267 public: | 415 public: |
| 268 | 416 |
| 269 LayerTreeHostContextTestLostContextSucceedsWithContent() | 417 LayerTreeHostContextTestLostContextSucceedsWithContent() |
| 270 : LayerTreeHostContextTestLostContextSucceeds() { | 418 : LayerTreeHostContextTestLostContextSucceeds() { |
| 271 } | 419 } |
| 272 | 420 |
| 273 virtual void setupTree() OVERRIDE { | 421 virtual void setupTree() OVERRIDE { |
| 274 root_ = Layer::create(); | 422 root_ = Layer::create(); |
| 275 root_->setBounds(gfx::Size(10, 10)); | 423 root_->setBounds(gfx::Size(10, 10)); |
| 276 root_->setAnchorPoint(gfx::PointF()); | 424 root_->setAnchorPoint(gfx::PointF()); |
| 277 root_->setIsDrawable(true); | 425 root_->setIsDrawable(true); |
| 278 | 426 |
| 279 content_ = FakeContentLayer::Create(&client_); | 427 content_ = FakeContentLayer::Create(&client_); |
| 280 content_->setBounds(gfx::Size(10, 10)); | 428 content_->setBounds(gfx::Size(10, 10)); |
| 281 content_->setAnchorPoint(gfx::PointF()); | 429 content_->setAnchorPoint(gfx::PointF()); |
| 282 content_->setIsDrawable(true); | 430 content_->setIsDrawable(true); |
| 283 if (use_surface_) { | 431 if (use_surface_) { |
| 284 // TODO(danakj): Give the surface a filter to test more code when we can | |
| 285 // do so without crashing in the shared context creation. | |
| 286 content_->setForceRenderSurface(true); | 432 content_->setForceRenderSurface(true); |
| 433 // Filters require us to create an offscreen context. |
| 434 WebKit::WebFilterOperations filters; |
| 435 filters.append(WebKit::WebFilterOperation::createGrayscaleFilter(0.5f)); |
| 436 content_->setFilters(filters); |
| 437 content_->setBackgroundFilters(filters); |
| 287 } | 438 } |
| 288 | 439 |
| 289 root_->addChild(content_); | 440 root_->addChild(content_); |
| 290 | 441 |
| 291 m_layerTreeHost->setRootLayer(root_); | 442 m_layerTreeHost->setRootLayer(root_); |
| 292 LayerTreeHostContextTest::setupTree(); | 443 LayerTreeHostContextTest::setupTree(); |
| 293 } | 444 } |
| 294 | 445 |
| 295 virtual void InvalidateAndSetNeedsCommit() OVERRIDE { | 446 virtual void InvalidateAndSetNeedsCommit() OVERRIDE { |
| 296 // Invalidate the render surface so we don't try to use a cached copy of the | 447 // Invalidate the render surface so we don't try to use a cached copy of the |
| 297 // surface. We want to make sure to test the drawing paths for drawing to | 448 // surface. We want to make sure to test the drawing paths for drawing to |
| 298 // a child surface. | 449 // a child surface. |
| 299 content_->setNeedsDisplay(); | 450 content_->setNeedsDisplay(); |
| 300 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit(); | 451 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit(); |
| 301 } | 452 } |
| 302 | 453 |
| 303 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 454 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 304 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( | 455 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( |
| 305 host_impl->rootLayer()->children()[0]); | 456 host_impl->rootLayer()->children()[0]); |
| 306 // Even though the context was lost, we should have a resource. The | 457 // Even though the context was lost, we should have a resource. The |
| 307 // FakeWebGraphicsContext3D ensures that this resource is created with | 458 // FakeWebGraphicsContext3D ensures that this resource is created with |
| 308 // the active context. | 459 // the active context. |
| 309 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); | 460 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); |
| 461 |
| 462 GaneshContextProvider::ScopedContexts contexts( |
| 463 host_impl->resourceProvider()->ganeshContextProvider()); |
| 464 if (use_surface_) |
| 465 EXPECT_TRUE(contexts.context3d()); |
| 466 else |
| 467 EXPECT_FALSE(contexts.context3d()); |
| 310 } | 468 } |
| 311 | 469 |
| 312 protected: | 470 protected: |
| 313 bool use_surface_; | 471 bool use_surface_; |
| 314 FakeContentLayerClient client_; | 472 FakeContentLayerClient client_; |
| 315 scoped_refptr<Layer> root_; | 473 scoped_refptr<Layer> root_; |
| 316 scoped_refptr<ContentLayer> content_; | 474 scoped_refptr<ContentLayer> content_; |
| 317 }; | 475 }; |
| 318 | 476 |
| 319 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, | 477 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 | 1178 |
| 1021 private: | 1179 private: |
| 1022 int commits_; | 1180 int commits_; |
| 1023 scoped_refptr<FakeScrollbarLayer> scrollbar_layer_; | 1181 scoped_refptr<FakeScrollbarLayer> scrollbar_layer_; |
| 1024 }; | 1182 }; |
| 1025 | 1183 |
| 1026 SINGLE_AND_MULTI_THREAD_TEST_F(ScrollbarLayerLostContext) | 1184 SINGLE_AND_MULTI_THREAD_TEST_F(ScrollbarLayerLostContext) |
| 1027 | 1185 |
| 1028 } // namespace | 1186 } // namespace |
| 1029 } // namespace cc | 1187 } // namespace cc |
| OLD | NEW |