| 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 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); | 793 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); |
| 794 EXPECT_FALSE(bridge->isAccelerated()); | 794 EXPECT_FALSE(bridge->isAccelerated()); |
| 795 EXPECT_TRUE(bridge->isHibernating()); | 795 EXPECT_TRUE(bridge->isHibernating()); |
| 796 EXPECT_TRUE(bridge->checkSurfaceValid()); | 796 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 797 | 797 |
| 798 // Tear down the bridge while hibernating | 798 // Tear down the bridge while hibernating |
| 799 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationEndedWithTeardown)); | 799 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationEndedWithTeardown)); |
| 800 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); | 800 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
| 801 } | 801 } |
| 802 | 802 |
| 803 #if CANVAS2D_HIBERNATION_ENABLED |
| 804 TEST_F(Canvas2DLayerBridgeTest, SnapshotWhileHibernating) |
| 805 #else |
| 806 TEST_F(Canvas2DLayerBridgeTest, DISABLED_SnapshotWhileHibernating) |
| 807 #endif |
| 808 { |
| 809 FakeGLES2Interface gl; |
| 810 OwnPtr<WebThread> testThread = adoptPtr(Platform::current()->createThread("T
estThread")); |
| 811 |
| 812 // The Canvas2DLayerBridge has to be created on the thread that will use it |
| 813 // to avoid WeakPtr thread check issues. |
| 814 Canvas2DLayerBridgePtr bridge; |
| 815 postAndWaitCreateBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge, &gl,
this); |
| 816 |
| 817 // Register an alternate Logger for tracking hibernation events |
| 818 OwnPtr<MockLogger> mockLogger = adoptPtr(new MockLogger); |
| 819 MockLogger* mockLoggerPtr = mockLogger.get(); |
| 820 bridge->setLoggerForTesting(std::move(mockLogger)); |
| 821 |
| 822 // Test entering hibernation |
| 823 OwnPtr<WaitableEvent> hibernationStartedEvent = adoptPtr(new WaitableEvent()
); |
| 824 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationScheduled)); |
| 825 EXPECT_CALL(*mockLoggerPtr, didStartHibernating()) |
| 826 .WillOnce(testing::Invoke(hibernationStartedEvent.get(), &WaitableEvent:
:signal)); |
| 827 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true); |
| 828 hibernationStartedEvent->wait(); |
| 829 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); |
| 830 EXPECT_FALSE(bridge->isAccelerated()); |
| 831 EXPECT_TRUE(bridge->isHibernating()); |
| 832 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 833 |
| 834 // Take a snapshot and verify that it is not accelerated due to hibernation |
| 835 RefPtr<SkImage> image = bridge->newImageSnapshot(PreferAcceleration, Snapsho
tReasonUnknown); |
| 836 EXPECT_FALSE(image->isTextureBacked()); |
| 837 image.clear(); |
| 838 |
| 839 // Verify that taking a snapshot did not affect the state of bridge |
| 840 EXPECT_FALSE(bridge->isAccelerated()); |
| 841 EXPECT_TRUE(bridge->isHibernating()); |
| 842 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 843 |
| 844 // End hibernation normally |
| 845 OwnPtr<WaitableEvent> hibernationEndedEvent = adoptPtr(new WaitableEvent()); |
| 846 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationEndedNormally)) |
| 847 .WillOnce(testing::InvokeWithoutArgs(hibernationEndedEvent.get(), &Waita
bleEvent::signal)); |
| 848 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), false); |
| 849 hibernationEndedEvent->wait(); |
| 850 |
| 851 // Tear down the bridge while hibernating |
| 852 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
| 853 } |
| 854 |
| 803 class IdleFenceTask : public WebThread::IdleTask { | 855 class IdleFenceTask : public WebThread::IdleTask { |
| 804 public: | 856 public: |
| 805 IdleFenceTask(WaitableEvent* doneEvent) | 857 IdleFenceTask(WaitableEvent* doneEvent) |
| 806 : m_doneEvent(doneEvent) | 858 : m_doneEvent(doneEvent) |
| 807 { } | 859 { } |
| 808 | 860 |
| 809 virtual ~IdleFenceTask() { } | 861 virtual ~IdleFenceTask() { } |
| 810 | 862 |
| 811 void run(double /*deadline*/) override | 863 void run(double /*deadline*/) override |
| 812 { | 864 { |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 // Test prepareMailbox while background rendering | 1093 // Test prepareMailbox while background rendering |
| 1042 WebExternalTextureMailbox mailbox; | 1094 WebExternalTextureMailbox mailbox; |
| 1043 EXPECT_FALSE(bridge->prepareMailbox(&mailbox, 0)); | 1095 EXPECT_FALSE(bridge->prepareMailbox(&mailbox, 0)); |
| 1044 EXPECT_TRUE(bridge->checkSurfaceValid()); | 1096 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 1045 | 1097 |
| 1046 // Tear down the bridge on the thread so that 'bridge' can go out of scope | 1098 // Tear down the bridge on the thread so that 'bridge' can go out of scope |
| 1047 // without crashing due to thread checks | 1099 // without crashing due to thread checks |
| 1048 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); | 1100 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
| 1049 } | 1101 } |
| 1050 | 1102 |
| 1103 |
| 1051 } // namespace blink | 1104 } // namespace blink |
| OLD | NEW |