| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 ->getTextureHandle(true)); | 149 ->getTextureHandle(true)); |
| 150 EXPECT_EQ(texture_info, nullptr); | 150 EXPECT_EQ(texture_info, nullptr); |
| 151 bridge.Clear(); | 151 bridge.Clear(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void FallbackToSoftwareIfContextLost() { | 154 void FallbackToSoftwareIfContextLost() { |
| 155 FakeGLES2Interface gl; | 155 FakeGLES2Interface gl; |
| 156 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = | 156 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = |
| 157 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 157 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
| 158 | 158 |
| 159 gl.setIsContextLost(true); | 159 gl.SetIsContextLost(true); |
| 160 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( | 160 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( |
| 161 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, | 161 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, |
| 162 Canvas2DLayerBridge::kEnableAcceleration, CanvasColorParams()))); | 162 Canvas2DLayerBridge::kEnableAcceleration, CanvasColorParams()))); |
| 163 EXPECT_TRUE(bridge->CheckSurfaceValid()); | 163 EXPECT_TRUE(bridge->CheckSurfaceValid()); |
| 164 EXPECT_FALSE(bridge->IsAccelerated()); | 164 EXPECT_FALSE(bridge->IsAccelerated()); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void FallbackToSoftwareOnFailedTextureAlloc() { | 167 void FallbackToSoftwareOnFailedTextureAlloc() { |
| 168 { | 168 { |
| 169 // No fallback case. | 169 // No fallback case. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 210 |
| 211 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( | 211 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( |
| 212 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, | 212 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, |
| 213 Canvas2DLayerBridge::kForceAccelerationForTesting, | 213 Canvas2DLayerBridge::kForceAccelerationForTesting, |
| 214 CanvasColorParams()))); | 214 CanvasColorParams()))); |
| 215 EXPECT_TRUE(bridge->CheckSurfaceValid()); | 215 EXPECT_TRUE(bridge->CheckSurfaceValid()); |
| 216 PaintFlags flags; | 216 PaintFlags flags; |
| 217 uint32_t gen_id = bridge->GetOrCreateSurface()->generationID(); | 217 uint32_t gen_id = bridge->GetOrCreateSurface()->generationID(); |
| 218 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); | 218 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); |
| 219 EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID()); | 219 EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID()); |
| 220 gl.setIsContextLost(true); | 220 gl.SetIsContextLost(true); |
| 221 EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID()); | 221 EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID()); |
| 222 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); | 222 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); |
| 223 EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID()); | 223 EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID()); |
| 224 // This results in the internal surface being torn down in response to the | 224 // This results in the internal surface being torn down in response to the |
| 225 // context loss. | 225 // context loss. |
| 226 EXPECT_FALSE(bridge->CheckSurfaceValid()); | 226 EXPECT_FALSE(bridge->CheckSurfaceValid()); |
| 227 EXPECT_EQ(nullptr, bridge->GetOrCreateSurface()); | 227 EXPECT_EQ(nullptr, bridge->GetOrCreateSurface()); |
| 228 // The following passes by not crashing | 228 // The following passes by not crashing |
| 229 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); | 229 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); |
| 230 bridge->Flush(); | 230 bridge->Flush(); |
| 231 } | 231 } |
| 232 | 232 |
| 233 void PrepareMailboxWhenContextIsLost() { | 233 void PrepareMailboxWhenContextIsLost() { |
| 234 FakeGLES2Interface gl; | 234 FakeGLES2Interface gl; |
| 235 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = | 235 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = |
| 236 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 236 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
| 237 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( | 237 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( |
| 238 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, | 238 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, |
| 239 Canvas2DLayerBridge::kForceAccelerationForTesting, | 239 Canvas2DLayerBridge::kForceAccelerationForTesting, |
| 240 CanvasColorParams()))); | 240 CanvasColorParams()))); |
| 241 | 241 |
| 242 EXPECT_TRUE(bridge->IsAccelerated()); | 242 EXPECT_TRUE(bridge->IsAccelerated()); |
| 243 | 243 |
| 244 // When the context is lost we are not sure if we should still be producing | 244 // When the context is lost we are not sure if we should still be producing |
| 245 // GL frames for the compositor or not, so fail to generate frames. | 245 // GL frames for the compositor or not, so fail to generate frames. |
| 246 gl.setIsContextLost(true); | 246 gl.SetIsContextLost(true); |
| 247 | 247 |
| 248 cc::TextureMailbox texture_mailbox; | 248 cc::TextureMailbox texture_mailbox; |
| 249 std::unique_ptr<cc::SingleReleaseCallback> release_callback; | 249 std::unique_ptr<cc::SingleReleaseCallback> release_callback; |
| 250 EXPECT_FALSE( | 250 EXPECT_FALSE( |
| 251 bridge->PrepareTextureMailbox(&texture_mailbox, &release_callback)); | 251 bridge->PrepareTextureMailbox(&texture_mailbox, &release_callback)); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void PrepareMailboxWhenContextIsLostWithFailedRestore() { | 254 void PrepareMailboxWhenContextIsLostWithFailedRestore() { |
| 255 FakeGLES2Interface gl; | 255 FakeGLES2Interface gl; |
| 256 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = | 256 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = |
| 257 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 257 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
| 258 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( | 258 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( |
| 259 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, | 259 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, |
| 260 Canvas2DLayerBridge::kForceAccelerationForTesting, | 260 Canvas2DLayerBridge::kForceAccelerationForTesting, |
| 261 CanvasColorParams()))); | 261 CanvasColorParams()))); |
| 262 | 262 |
| 263 bridge->GetOrCreateSurface(); | 263 bridge->GetOrCreateSurface(); |
| 264 EXPECT_TRUE(bridge->CheckSurfaceValid()); | 264 EXPECT_TRUE(bridge->CheckSurfaceValid()); |
| 265 // When the context is lost we are not sure if we should still be producing | 265 // When the context is lost we are not sure if we should still be producing |
| 266 // GL frames for the compositor or not, so fail to generate frames. | 266 // GL frames for the compositor or not, so fail to generate frames. |
| 267 gl.setIsContextLost(true); | 267 gl.SetIsContextLost(true); |
| 268 EXPECT_FALSE(bridge->CheckSurfaceValid()); | 268 EXPECT_FALSE(bridge->CheckSurfaceValid()); |
| 269 | 269 |
| 270 // Restoration will fail because | 270 // Restoration will fail because |
| 271 // Platform::createSharedOffscreenGraphicsContext3DProvider() is stubbed | 271 // Platform::createSharedOffscreenGraphicsContext3DProvider() is stubbed |
| 272 // in unit tests. This simulates what would happen when attempting to | 272 // in unit tests. This simulates what would happen when attempting to |
| 273 // restore while the GPU process is down. | 273 // restore while the GPU process is down. |
| 274 bridge->RestoreSurface(); | 274 bridge->RestoreSurface(); |
| 275 | 275 |
| 276 cc::TextureMailbox texture_mailbox; | 276 cc::TextureMailbox texture_mailbox; |
| 277 std::unique_ptr<cc::SingleReleaseCallback> release_callback; | 277 std::unique_ptr<cc::SingleReleaseCallback> release_callback; |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 // to avoid WeakPtr thread check issues. | 1161 // to avoid WeakPtr thread check issues. |
| 1162 Canvas2DLayerBridgePtr bridge; | 1162 Canvas2DLayerBridgePtr bridge; |
| 1163 PostAndWaitCreateBridgeTask(BLINK_FROM_HERE, test_thread.get(), &bridge, &gl, | 1163 PostAndWaitCreateBridgeTask(BLINK_FROM_HERE, test_thread.get(), &bridge, &gl, |
| 1164 this); | 1164 this); |
| 1165 | 1165 |
| 1166 // Register an alternate Logger for tracking hibernation events | 1166 // Register an alternate Logger for tracking hibernation events |
| 1167 std::unique_ptr<MockLogger> mock_logger = WTF::WrapUnique(new MockLogger); | 1167 std::unique_ptr<MockLogger> mock_logger = WTF::WrapUnique(new MockLogger); |
| 1168 MockLogger* mock_logger_ptr = mock_logger.get(); | 1168 MockLogger* mock_logger_ptr = mock_logger.get(); |
| 1169 bridge->SetLoggerForTesting(std::move(mock_logger)); | 1169 bridge->SetLoggerForTesting(std::move(mock_logger)); |
| 1170 | 1170 |
| 1171 gl.setIsContextLost(true); | 1171 gl.SetIsContextLost(true); |
| 1172 // Test entering hibernation | 1172 // Test entering hibernation |
| 1173 std::unique_ptr<WaitableEvent> hibernation_aborted_event = | 1173 std::unique_ptr<WaitableEvent> hibernation_aborted_event = |
| 1174 WTF::MakeUnique<WaitableEvent>(); | 1174 WTF::MakeUnique<WaitableEvent>(); |
| 1175 EXPECT_CALL( | 1175 EXPECT_CALL( |
| 1176 *mock_logger_ptr, | 1176 *mock_logger_ptr, |
| 1177 ReportHibernationEvent(Canvas2DLayerBridge::kHibernationScheduled)); | 1177 ReportHibernationEvent(Canvas2DLayerBridge::kHibernationScheduled)); |
| 1178 EXPECT_CALL(*mock_logger_ptr, | 1178 EXPECT_CALL(*mock_logger_ptr, |
| 1179 ReportHibernationEvent( | 1179 ReportHibernationEvent( |
| 1180 Canvas2DLayerBridge::kHibernationAbortedDueGpuContextLoss)) | 1180 Canvas2DLayerBridge::kHibernationAbortedDueGpuContextLoss)) |
| 1181 .WillOnce(testing::InvokeWithoutArgs(hibernation_aborted_event.get(), | 1181 .WillOnce(testing::InvokeWithoutArgs(hibernation_aborted_event.get(), |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 EXPECT_FALSE(bridge->HasRecordedDrawCommands()); | 1379 EXPECT_FALSE(bridge->HasRecordedDrawCommands()); |
| 1380 ::testing::Mock::VerifyAndClearExpectations(&gl); | 1380 ::testing::Mock::VerifyAndClearExpectations(&gl); |
| 1381 | 1381 |
| 1382 EXPECT_CALL(gl, Flush()).Times(1); | 1382 EXPECT_CALL(gl, Flush()).Times(1); |
| 1383 bridge->FlushGpu(); | 1383 bridge->FlushGpu(); |
| 1384 EXPECT_FALSE(bridge->HasRecordedDrawCommands()); | 1384 EXPECT_FALSE(bridge->HasRecordedDrawCommands()); |
| 1385 ::testing::Mock::VerifyAndClearExpectations(&gl); | 1385 ::testing::Mock::VerifyAndClearExpectations(&gl); |
| 1386 } | 1386 } |
| 1387 | 1387 |
| 1388 } // namespace blink | 1388 } // namespace blink |
| OLD | NEW |