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

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: git cl web Created 4 years, 10 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 { 507 {
508 MockCanvasContext mainMock; 508 MockCanvasContext mainMock;
509 OwnPtr<WebThread> testThread = adoptPtr(Platform::current()->createThread("T estThread")); 509 OwnPtr<WebThread> testThread = adoptPtr(Platform::current()->createThread("T estThread"));
510 510
511 // The Canvas2DLayerBridge has to be created on the thread that will use it 511 // The Canvas2DLayerBridge has to be created on the thread that will use it
512 // to avoid WeakPtr thread check issues. 512 // to avoid WeakPtr thread check issues.
513 Canvas2DLayerBridgePtr bridge; 513 Canvas2DLayerBridgePtr bridge;
514 OwnPtr<WebWaitableEvent> bridgeCreatedEvent = adoptPtr(Platform::current()-> createWaitableEvent()); 514 OwnPtr<WebWaitableEvent> bridgeCreatedEvent = adoptPtr(Platform::current()-> createWaitableEvent());
515 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new CreateBridgeTask(&br idge, &mainMock, this, bridgeCreatedEvent.get())); 515 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new CreateBridgeTask(&br idge, &mainMock, this, bridgeCreatedEvent.get()));
516 bridgeCreatedEvent->wait(); 516 bridgeCreatedEvent->wait();
517 bridge->disableDeferral(); 517 bridge->disableDeferral(DisableDeferralReasonUnknown);
518 MockImageBuffer mockImageBuffer; 518 MockImageBuffer mockImageBuffer;
519 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AnyNumber()); 519 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AnyNumber());
520 bridge->setImageBuffer(&mockImageBuffer); 520 bridge->setImageBuffer(&mockImageBuffer);
521 521
522 // Register an alternate Logger for tracking hibernation events 522 // Register an alternate Logger for tracking hibernation events
523 OwnPtr<MockLogger> mockLogger = adoptPtr(new MockLogger); 523 OwnPtr<MockLogger> mockLogger = adoptPtr(new MockLogger);
524 MockLogger* mockLoggerPtr = mockLogger.get(); 524 MockLogger* mockLoggerPtr = mockLogger.get();
525 bridge->setLoggerForTesting(mockLogger.release()); 525 bridge->setLoggerForTesting(mockLogger.release());
526 526
527 // Test entering hibernation 527 // Test entering hibernation
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 644
645 // The Canvas2DLayerBridge has to be created on the thread that will use it 645 // The Canvas2DLayerBridge has to be created on the thread that will use it
646 // to avoid WeakPtr thread check issues. 646 // to avoid WeakPtr thread check issues.
647 Canvas2DLayerBridgePtr bridge; 647 Canvas2DLayerBridgePtr bridge;
648 OwnPtr<WebWaitableEvent> bridgeCreatedEvent = adoptPtr(Platform::current()-> createWaitableEvent()); 648 OwnPtr<WebWaitableEvent> bridgeCreatedEvent = adoptPtr(Platform::current()-> createWaitableEvent());
649 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new CreateBridgeTask(&br idge, &mainMock, this, bridgeCreatedEvent.get())); 649 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new CreateBridgeTask(&br idge, &mainMock, this, bridgeCreatedEvent.get()));
650 bridgeCreatedEvent->wait(); 650 bridgeCreatedEvent->wait();
651 MockImageBuffer mockImageBuffer; 651 MockImageBuffer mockImageBuffer;
652 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AnyNumber()); 652 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AnyNumber());
653 bridge->setImageBuffer(&mockImageBuffer); 653 bridge->setImageBuffer(&mockImageBuffer);
654 bridge->disableDeferral(); 654 bridge->disableDeferral(DisableDeferralReasonUnknown);
655 655
656 // Register an alternate Logger for tracking hibernation events 656 // Register an alternate Logger for tracking hibernation events
657 OwnPtr<MockLogger> mockLogger = adoptPtr(new MockLogger); 657 OwnPtr<MockLogger> mockLogger = adoptPtr(new MockLogger);
658 MockLogger* mockLoggerPtr = mockLogger.get(); 658 MockLogger* mockLoggerPtr = mockLogger.get();
659 bridge->setLoggerForTesting(mockLogger.release()); 659 bridge->setLoggerForTesting(mockLogger.release());
660 660
661 // Test entering hibernation 661 // Test entering hibernation
662 OwnPtr<WebWaitableEvent> hibernationStartedEvent = adoptPtr(Platform::curren t()->createWaitableEvent()); 662 OwnPtr<WebWaitableEvent> hibernationStartedEvent = adoptPtr(Platform::curren t()->createWaitableEvent());
663 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe rnationScheduled)); 663 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe rnationScheduled));
664 EXPECT_CALL(*mockLoggerPtr, didStartHibernating()) 664 EXPECT_CALL(*mockLoggerPtr, didStartHibernating())
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 hibernationStartedEvent->wait(); 731 hibernationStartedEvent->wait();
732 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); 732 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr);
733 ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer); 733 ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer);
734 EXPECT_FALSE(bridge->isAccelerated()); 734 EXPECT_FALSE(bridge->isAccelerated());
735 EXPECT_TRUE(bridge->isHibernating()); 735 EXPECT_TRUE(bridge->isHibernating());
736 EXPECT_TRUE(bridge->checkSurfaceValid()); 736 EXPECT_TRUE(bridge->checkSurfaceValid());
737 737
738 // Disable deferral while background rendering 738 // Disable deferral while background rendering
739 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe rnationEndedWithSwitchToBackgroundRendering)); 739 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe rnationEndedWithSwitchToBackgroundRendering));
740 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1)); 740 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1));
741 bridge->disableDeferral(); 741 bridge->disableDeferral(DisableDeferralReasonUnknown);
742 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); 742 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr);
743 ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer); 743 ::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer);
744 EXPECT_FALSE(bridge->isAccelerated()); 744 EXPECT_FALSE(bridge->isAccelerated());
745 EXPECT_FALSE(bridge->isHibernating()); 745 EXPECT_FALSE(bridge->isHibernating());
746 EXPECT_TRUE(bridge->checkSurfaceValid()); 746 EXPECT_TRUE(bridge->checkSurfaceValid());
747 747
748 // Unhide 748 // Unhide
749 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1)); 749 EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1));
750 OwnPtr<WebWaitableEvent> unhideEvent = adoptPtr(Platform::current()->createW aitableEvent()); 750 OwnPtr<WebWaitableEvent> unhideEvent = adoptPtr(Platform::current()->createW aitableEvent());
751 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new SetIsHiddenTask(brid ge.get(), false, unhideEvent.get())); 751 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new SetIsHiddenTask(brid ge.get(), false, unhideEvent.get()));
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 EXPECT_TRUE(bridge->checkSurfaceValid()); 1069 EXPECT_TRUE(bridge->checkSurfaceValid());
1070 1070
1071 // Tear down the bridge on the thread so that 'bridge' can go out of scope 1071 // Tear down the bridge on the thread so that 'bridge' can go out of scope
1072 // without crashing due to thread checks 1072 // without crashing due to thread checks
1073 OwnPtr<WebWaitableEvent> bridgeDestroyedEvent = adoptPtr(Platform::current() ->createWaitableEvent()); 1073 OwnPtr<WebWaitableEvent> bridgeDestroyedEvent = adoptPtr(Platform::current() ->createWaitableEvent());
1074 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new DestroyBridgeTask(&b ridge, bridgeDestroyedEvent.get())); 1074 testThread->taskRunner()->postTask(BLINK_FROM_HERE, new DestroyBridgeTask(&b ridge, bridgeDestroyedEvent.get()));
1075 bridgeDestroyedEvent->wait(); 1075 bridgeDestroyedEvent->wait();
1076 } 1076 }
1077 1077
1078 } // namespace blink 1078 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698