Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp

Issue 1609343004: Add display list fallback reason histograms for 2D canvas (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adding missing histogram Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 MockCanvasContext mainMock; 150 MockCanvasContext mainMock;
151 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new MockWebGraphicsContext3DProvider(&mainMock)); 151 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new MockWebGraphicsContext3DProvider(&mainMock));
152 152
153 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 153 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
154 154
155 { 155 {
156 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::Dis ableAcceleration))); 156 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::Dis ableAcceleration)));
157 157
158 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 158 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
159 159
160 unsigned textureId = bridge->newImageSnapshot(PreferAcceleration)->g etTextureHandle(true); 160 unsigned textureId = bridge->newImageSnapshot(PreferAcceleration, Sn apshotReasonUnknown)->getTextureHandle(true);
161 EXPECT_EQ(textureId, 0u); 161 EXPECT_EQ(textureId, 0u);
162 162
163 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 163 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
164 } // bridge goes out of scope here 164 } // bridge goes out of scope here
165 165
166 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 166 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
167 } 167 }
168 168
169 void fallbackToSoftwareIfContextLost() 169 void fallbackToSoftwareIfContextLost()
170 { 170 {
(...skipping 21 matching lines...) Expand all
192 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 192 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
193 193
194 { 194 {
195 // No fallback case 195 // No fallback case
196 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock)); 196 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock));
197 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::Ena bleAcceleration))); 197 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::Ena bleAcceleration)));
198 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 198 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
199 EXPECT_TRUE(bridge->checkSurfaceValid()); 199 EXPECT_TRUE(bridge->checkSurfaceValid());
200 EXPECT_TRUE(bridge->isAccelerated()); 200 EXPECT_TRUE(bridge->isAccelerated());
201 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 201 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
202 RefPtr<SkImage> snapshot = bridge->newImageSnapshot(PreferAccelerati on); 202 RefPtr<SkImage> snapshot = bridge->newImageSnapshot(PreferAccelerati on, SnapshotReasonUnknown);
203 EXPECT_TRUE(bridge->isAccelerated()); 203 EXPECT_TRUE(bridge->isAccelerated());
204 EXPECT_TRUE(snapshot->isTextureBacked()); 204 EXPECT_TRUE(snapshot->isTextureBacked());
205 } 205 }
206 206
207 { 207 {
208 // Fallback case 208 // Fallback case
209 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock)); 209 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock));
210 GrContext* gr = mainMockProvider->grContext(); 210 GrContext* gr = mainMockProvider->grContext();
211 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::Ena bleAcceleration))); 211 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::Ena bleAcceleration)));
212 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 212 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
213 EXPECT_TRUE(bridge->checkSurfaceValid()); 213 EXPECT_TRUE(bridge->checkSurfaceValid());
214 EXPECT_TRUE(bridge->isAccelerated()); // We don't yet know that allo cation will fail 214 EXPECT_TRUE(bridge->isAccelerated()); // We don't yet know that allo cation will fail
215 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 215 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
216 gr->abandonContext(); // This will cause SkSurface_Gpu creation to f ail without Canvas2DLayerBridge otherwise detecting that anything was disabled. 216 gr->abandonContext(); // This will cause SkSurface_Gpu creation to f ail without Canvas2DLayerBridge otherwise detecting that anything was disabled.
217 RefPtr<SkImage> snapshot = bridge->newImageSnapshot(PreferAccelerati on); 217 RefPtr<SkImage> snapshot = bridge->newImageSnapshot(PreferAccelerati on, SnapshotReasonUnknown);
218 EXPECT_FALSE(bridge->isAccelerated()); 218 EXPECT_FALSE(bridge->isAccelerated());
219 EXPECT_FALSE(snapshot->isTextureBacked()); 219 EXPECT_FALSE(snapshot->isTextureBacked());
220 } 220 }
221 221
222 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 222 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
223 } 223 }
224 224
225 void noDrawOnContextLostTest() 225 void noDrawOnContextLostTest()
226 { 226 {
227 MockCanvasContext mainMock; 227 MockCanvasContext mainMock;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 { 299 {
300 MockCanvasContext mainMock; 300 MockCanvasContext mainMock;
301 { 301 {
302 302
303 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock)); 303 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock));
304 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 304 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
305 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 300), 0, NonOpaque, Canvas2DLayerBridge::Ena bleAcceleration))); 305 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 300), 0, NonOpaque, Canvas2DLayerBridge::Ena bleAcceleration)));
306 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 306 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
307 SkPaint paint; 307 SkPaint paint;
308 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); 308 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint);
309 RefPtr<SkImage> image = bridge->newImageSnapshot(PreferAcceleration) ; 309 RefPtr<SkImage> image = bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnknown);
310 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 310 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
311 EXPECT_TRUE(bridge->checkSurfaceValid()); 311 EXPECT_TRUE(bridge->checkSurfaceValid());
312 EXPECT_TRUE(bridge->isAccelerated()); 312 EXPECT_TRUE(bridge->isAccelerated());
313 } 313 }
314 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 314 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
315 315
316 { 316 {
317 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock)); 317 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock));
318 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 318 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
319 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 300), 0, NonOpaque, Canvas2DLayerBridge::Ena bleAcceleration))); 319 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 300), 0, NonOpaque, Canvas2DLayerBridge::Ena bleAcceleration)));
320 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 320 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
321 SkPaint paint; 321 SkPaint paint;
322 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); 322 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint);
323 RefPtr<SkImage> image = bridge->newImageSnapshot(PreferNoAcceleratio n); 323 RefPtr<SkImage> image = bridge->newImageSnapshot(PreferNoAcceleratio n, SnapshotReasonUnknown);
324 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 324 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
325 EXPECT_TRUE(bridge->checkSurfaceValid()); 325 EXPECT_TRUE(bridge->checkSurfaceValid());
326 EXPECT_FALSE(bridge->isAccelerated()); 326 EXPECT_FALSE(bridge->isAccelerated());
327 } 327 }
328 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 328 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
329 } 329 }
330 }; 330 };
331 331
332 TEST_F(Canvas2DLayerBridgeTest, FullLifecycleSingleThreaded) 332 TEST_F(Canvas2DLayerBridgeTest, FullLifecycleSingleThreaded)
333 { 333 {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 { 505 {
506 MockCanvasContext mainMock; 506 MockCanvasContext mainMock;
507 OwnPtr<WebThread> testThread = adoptPtr(Platform::current()->createThread("T estThread")); 507 OwnPtr<WebThread> testThread = adoptPtr(Platform::current()->createThread("T estThread"));
508 508
509 // The Canvas2DLayerBridge has to be created on the thread that will use it 509 // The Canvas2DLayerBridge has to be created on the thread that will use it
510 // to avoid WeakPtr thread check issues. 510 // to avoid WeakPtr thread check issues.
511 Canvas2DLayerBridgePtr bridge; 511 Canvas2DLayerBridgePtr bridge;
512 OwnPtr<WebWaitableEvent> bridgeCreatedEvent = adoptPtr(Platform::current()-> createWaitableEvent()); 512 OwnPtr<WebWaitableEvent> bridgeCreatedEvent = adoptPtr(Platform::current()-> createWaitableEvent());
513 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new CreateBridgeTask(&br idge, &mainMock, this, bridgeCreatedEvent.get())); 513 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new CreateBridgeTask(&br idge, &mainMock, this, bridgeCreatedEvent.get()));
514 bridgeCreatedEvent->wait(); 514 bridgeCreatedEvent->wait();
515 bridge->disableDeferral(); 515 bridge->disableDeferral(DisableDeferralReasonUnknown);
516 MockImageBuffer mockImageBuffer; 516 MockImageBuffer mockImageBuffer;
517 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AnyNumber()); 517 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AnyNumber());
518 bridge->setImageBuffer(&mockImageBuffer); 518 bridge->setImageBuffer(&mockImageBuffer);
519 519
520 // Register an alternate Logger for tracking hibernation events 520 // Register an alternate Logger for tracking hibernation events
521 OwnPtr<MockLogger> mockLogger = adoptPtr(new MockLogger); 521 OwnPtr<MockLogger> mockLogger = adoptPtr(new MockLogger);
522 MockLogger* mockLoggerPtr = mockLogger.get(); 522 MockLogger* mockLoggerPtr = mockLogger.get();
523 bridge->setLoggerForTesting(mockLogger.release()); 523 bridge->setLoggerForTesting(mockLogger.release());
524 524
525 // Test entering hibernation 525 // Test entering hibernation
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 637
638 // The Canvas2DLayerBridge has to be created on the thread that will use it 638 // The Canvas2DLayerBridge has to be created on the thread that will use it
639 // to avoid WeakPtr thread check issues. 639 // to avoid WeakPtr thread check issues.
640 Canvas2DLayerBridgePtr bridge; 640 Canvas2DLayerBridgePtr bridge;
641 OwnPtr<WebWaitableEvent> bridgeCreatedEvent = adoptPtr(Platform::current()-> createWaitableEvent()); 641 OwnPtr<WebWaitableEvent> bridgeCreatedEvent = adoptPtr(Platform::current()-> createWaitableEvent());
642 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new CreateBridgeTask(&br idge, &mainMock, this, bridgeCreatedEvent.get())); 642 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new CreateBridgeTask(&br idge, &mainMock, this, bridgeCreatedEvent.get()));
643 bridgeCreatedEvent->wait(); 643 bridgeCreatedEvent->wait();
644 MockImageBuffer mockImageBuffer; 644 MockImageBuffer mockImageBuffer;
645 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AnyNumber()); 645 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AnyNumber());
646 bridge->setImageBuffer(&mockImageBuffer); 646 bridge->setImageBuffer(&mockImageBuffer);
647 bridge->disableDeferral(); 647 bridge->disableDeferral(DisableDeferralReasonUnknown);
648 648
649 // Register an alternate Logger for tracking hibernation events 649 // Register an alternate Logger for tracking hibernation events
650 OwnPtr<MockLogger> mockLogger = adoptPtr(new MockLogger); 650 OwnPtr<MockLogger> mockLogger = adoptPtr(new MockLogger);
651 MockLogger* mockLoggerPtr = mockLogger.get(); 651 MockLogger* mockLoggerPtr = mockLogger.get();
652 bridge->setLoggerForTesting(mockLogger.release()); 652 bridge->setLoggerForTesting(mockLogger.release());
653 653
654 // Test entering hibernation 654 // Test entering hibernation
655 OwnPtr<WebWaitableEvent> hibernationStartedEvent = adoptPtr(Platform::curren t()->createWaitableEvent()); 655 OwnPtr<WebWaitableEvent> hibernationStartedEvent = adoptPtr(Platform::curren t()->createWaitableEvent());
656 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe rnationScheduled)); 656 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe rnationScheduled));
657 EXPECT_CALL(*mockLoggerPtr, didStartHibernating()) 657 EXPECT_CALL(*mockLoggerPtr, didStartHibernating())
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new SetIsHiddenTask(brid ge.get(), true)); 720 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new SetIsHiddenTask(brid ge.get(), true));
721 hibernationStartedEvent->wait(); 721 hibernationStartedEvent->wait();
722 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); 722 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr);
723 ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer); 723 ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer);
724 EXPECT_FALSE(bridge->isAccelerated()); 724 EXPECT_FALSE(bridge->isAccelerated());
725 EXPECT_TRUE(bridge->isHibernating()); 725 EXPECT_TRUE(bridge->isHibernating());
726 726
727 // Disable deferral while background rendering 727 // Disable deferral while background rendering
728 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe rnationEndedWithSwitchToBackgroundRendering)); 728 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe rnationEndedWithSwitchToBackgroundRendering));
729 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1)); 729 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1));
730 bridge->disableDeferral(); 730 bridge->disableDeferral(DisableDeferralReasonUnknown);
731 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); 731 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr);
732 ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer); 732 ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer);
733 EXPECT_FALSE(bridge->isAccelerated()); 733 EXPECT_FALSE(bridge->isAccelerated());
734 EXPECT_FALSE(bridge->isHibernating()); 734 EXPECT_FALSE(bridge->isHibernating());
735 735
736 // Unhide 736 // Unhide
737 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1)); 737 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1));
738 OwnPtr<WebWaitableEvent> unhideEvent = adoptPtr(Platform::current()->createW aitableEvent()); 738 OwnPtr<WebWaitableEvent> unhideEvent = adoptPtr(Platform::current()->createW aitableEvent());
739 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new SetIsHiddenTask(brid ge.get(), false, unhideEvent.get())); 739 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new SetIsHiddenTask(brid ge.get(), false, unhideEvent.get()));
740 unhideEvent->wait(); 740 unhideEvent->wait();
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 // Tear down the bridge on the thread so that 'bridge' can go out of scope 967 // Tear down the bridge on the thread so that 'bridge' can go out of scope
968 // without crashing due to thread checks 968 // without crashing due to thread checks
969 OwnPtr<WebWaitableEvent> bridgeDestroyedEvent = adoptPtr(Platform::current() ->createWaitableEvent()); 969 OwnPtr<WebWaitableEvent> bridgeDestroyedEvent = adoptPtr(Platform::current() ->createWaitableEvent());
970 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new DestroyBridgeTask(&b ridge, bridgeDestroyedEvent.get())); 970 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new DestroyBridgeTask(&b ridge, bridgeDestroyedEvent.get()));
971 bridgeDestroyedEvent->wait(); 971 bridgeDestroyedEvent->wait();
972 972
973 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 973 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
974 } 974 }
975 975
976 } // namespace blink 976 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698