| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // When the context is lost we are not sure if we should still be producing | 243 // When the context is lost we are not sure if we should still be producing |
| 244 // GL frames for the compositor or not, so fail to generate frames. | 244 // GL frames for the compositor or not, so fail to generate frames. |
| 245 gl.setIsContextLost(true); | 245 gl.setIsContextLost(true); |
| 246 | 246 |
| 247 cc::TextureMailbox textureMailbox; | 247 cc::TextureMailbox textureMailbox; |
| 248 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 248 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 249 EXPECT_FALSE( | 249 EXPECT_FALSE( |
| 250 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); | 250 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void prepareMailboxWhenContextIsLostWithFailedRestore() { |
| 254 FakeGLES2Interface gl; |
| 255 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
| 256 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
| 257 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
| 258 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, |
| 259 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, |
| 260 kN32_SkColorType))); |
| 261 |
| 262 // TODO(junov): The PrepareTextureMailbox() method will fail a DCHECK if we |
| 263 // don't do this before calling it the first time when the context is lost. |
| 264 bridge->prepareSurfaceForPaintingIfNeeded(); |
| 265 |
| 266 // When the context is lost we are not sure if we should still be producing |
| 267 // GL frames for the compositor or not, so fail to generate frames. |
| 268 gl.setIsContextLost(true); |
| 269 EXPECT_FALSE(bridge->checkSurfaceValid()); |
| 270 |
| 271 // Restoration will fail because |
| 272 // Platform::createSharedOffscreenGraphicsContext3DProvider() is stubbed |
| 273 // in unit tests. This simulates what would happen when attempting to |
| 274 // restore while the GPU process is down. |
| 275 bridge->restoreSurface(); |
| 276 |
| 277 cc::TextureMailbox textureMailbox; |
| 278 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 279 EXPECT_FALSE( |
| 280 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); |
| 281 } |
| 282 |
| 253 void prepareMailboxAndLoseResourceTest() { | 283 void prepareMailboxAndLoseResourceTest() { |
| 254 // Prepare a mailbox, then report the resource as lost. | 284 // Prepare a mailbox, then report the resource as lost. |
| 255 // This test passes by not crashing and not triggering assertions. | 285 // This test passes by not crashing and not triggering assertions. |
| 256 { | 286 { |
| 257 FakeGLES2Interface gl; | 287 FakeGLES2Interface gl; |
| 258 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = | 288 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
| 259 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 289 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
| 260 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( | 290 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
| 261 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, | 291 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, |
| 262 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, | 292 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 367 } |
| 338 | 368 |
| 339 TEST_F(Canvas2DLayerBridgeTest, NoDrawOnContextLost) { | 369 TEST_F(Canvas2DLayerBridgeTest, NoDrawOnContextLost) { |
| 340 noDrawOnContextLostTest(); | 370 noDrawOnContextLostTest(); |
| 341 } | 371 } |
| 342 | 372 |
| 343 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxWhenContextIsLost) { | 373 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxWhenContextIsLost) { |
| 344 prepareMailboxWhenContextIsLost(); | 374 prepareMailboxWhenContextIsLost(); |
| 345 } | 375 } |
| 346 | 376 |
| 377 TEST_F(Canvas2DLayerBridgeTest, |
| 378 PrepareMailboxWhenContextIsLostWithFailedRestore) { |
| 379 prepareMailboxWhenContextIsLostWithFailedRestore(); |
| 380 } |
| 381 |
| 347 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxAndLoseResource) { | 382 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxAndLoseResource) { |
| 348 prepareMailboxAndLoseResourceTest(); | 383 prepareMailboxAndLoseResourceTest(); |
| 349 } | 384 } |
| 350 | 385 |
| 351 TEST_F(Canvas2DLayerBridgeTest, AccelerationHint) { | 386 TEST_F(Canvas2DLayerBridgeTest, AccelerationHint) { |
| 352 accelerationHintTest(); | 387 accelerationHintTest(); |
| 353 } | 388 } |
| 354 | 389 |
| 355 TEST_F(Canvas2DLayerBridgeTest, FallbackToSoftwareIfContextLost) { | 390 TEST_F(Canvas2DLayerBridgeTest, FallbackToSoftwareIfContextLost) { |
| 356 fallbackToSoftwareIfContextLost(); | 391 fallbackToSoftwareIfContextLost(); |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 } | 1305 } |
| 1271 | 1306 |
| 1272 bool lostResource = false; | 1307 bool lostResource = false; |
| 1273 releaseCallback->Run(gpu::SyncToken(), lostResource); | 1308 releaseCallback->Run(gpu::SyncToken(), lostResource); |
| 1274 | 1309 |
| 1275 EXPECT_EQ(1u, gl.createImageCount()); | 1310 EXPECT_EQ(1u, gl.createImageCount()); |
| 1276 EXPECT_EQ(1u, gl.destroyImageCount()); | 1311 EXPECT_EQ(1u, gl.destroyImageCount()); |
| 1277 } | 1312 } |
| 1278 | 1313 |
| 1279 } // namespace blink | 1314 } // namespace blink |
| OLD | NEW |