Chromium Code Reviews| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 MOCK_METHOD1(deleteTexture, void(unsigned)); | 51 MOCK_METHOD1(deleteTexture, void(unsigned)); |
| 52 | 52 |
| 53 virtual GrGLInterface* onCreateGrGLInterface() OVERRIDE { return 0; } | 53 virtual GrGLInterface* onCreateGrGLInterface() OVERRIDE { return 0; } |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 class MockWebTextureUpdater : public WebTextureUpdater { | 56 class MockWebTextureUpdater : public WebTextureUpdater { |
| 57 public: | 57 public: |
| 58 MOCK_METHOD3(appendCopy, void(unsigned, unsigned, WebSize)); | 58 MOCK_METHOD3(appendCopy, void(unsigned, unsigned, WebSize)); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 class FakeCanvas2DLayerBridge : public Canvas2DLayerBridge { | |
| 62 public: | |
| 63 static PassOwnPtr<FakeCanvas2DLayerBridge> create(PassRefPtr<GraphicsContext 3D> context, SkDeferredCanvas* canvas, OpacityMode opacityMode, ThreadMode threa dMode) | |
| 64 { | |
| 65 return adoptPtr(new FakeCanvas2DLayerBridge(context, canvas, opacityMode , threadMode)); | |
| 66 } | |
| 67 | |
| 68 void setFakeSharedContext(PassRefPtr<GraphicsContext3D> context) | |
| 69 { | |
| 70 m_fakeSharedContext = context; | |
| 71 } | |
| 72 protected: | |
| 73 virtual PassRefPtr<GraphicsContext3D> getSharedContext() const OVERRIDE | |
| 74 { | |
| 75 return m_fakeSharedContext; | |
| 76 } | |
| 77 | |
| 78 FakeCanvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, SkDeferredCan vas* canvas, OpacityMode opacityMode, ThreadMode threadMode) : | |
| 79 Canvas2DLayerBridge(context, canvas, opacityMode, threadMode) | |
| 80 { | |
| 81 m_fakeSharedContext = m_context; | |
| 82 } | |
| 83 | |
| 84 RefPtr<GraphicsContext3D> m_fakeSharedContext; | |
| 85 }; | |
| 86 | |
| 61 } // namespace | 87 } // namespace |
| 62 | 88 |
| 63 class Canvas2DLayerBridgeTest : public Test { | 89 class Canvas2DLayerBridgeTest : public Test { |
| 64 protected: | 90 protected: |
| 65 void fullLifecycleTest(Canvas2DLayerBridge::ThreadMode threadMode) | 91 void fullLifecycleTest(Canvas2DLayerBridge::ThreadMode threadMode) |
| 66 { | 92 { |
| 67 RefPtr<GraphicsContext3D> mainContext = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new MockCanvasContext)); | 93 RefPtr<GraphicsContext3D> mainContext = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new MockCanvasContext)); |
| 68 | 94 |
| 69 MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(mainConte xt->webContext()); | 95 MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(mainConte xt->webContext()); |
| 70 | 96 |
| 71 MockWebTextureUpdater updater; | 97 MockWebTextureUpdater updater; |
| 72 | 98 |
| 73 SkDevice device(SkBitmap::kARGB_8888_Config, 300, 150); | 99 SkDevice device(SkBitmap::kARGB_8888_Config, 300, 150); |
| 74 SkDeferredCanvas canvas(&device); | 100 SkDeferredCanvas canvas(&device); |
| 75 | 101 |
| 76 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 102 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 77 | 103 |
| 78 OwnPtr<Canvas2DLayerBridge> bridge = Canvas2DLayerBridge::create(mainCon text.release(), &canvas, Canvas2DLayerBridge::NonOpaque, threadMode); | 104 OwnPtr<Canvas2DLayerBridge> bridge = FakeCanvas2DLayerBridge::create(mai nContext.release(), &canvas, Canvas2DLayerBridge::NonOpaque, threadMode); |
| 79 | 105 |
| 80 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 106 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 81 | 107 |
| 82 EXPECT_CALL(mainMock, flush()); | 108 EXPECT_CALL(mainMock, flush()); |
| 83 unsigned textureId = bridge->backBufferTexture(); | 109 unsigned textureId = bridge->backBufferTexture(); |
| 84 EXPECT_TRUE(textureId == 0); | 110 EXPECT_TRUE(textureId == 0); |
| 85 | 111 |
| 86 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 112 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 87 | 113 |
| 88 bridge.clear(); | 114 bridge.clear(); |
| 89 | 115 |
| 90 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 116 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 91 ::testing::Mock::VerifyAndClearExpectations(&updater); | 117 ::testing::Mock::VerifyAndClearExpectations(&updater); |
| 92 } | 118 } |
| 119 | |
| 120 void contextLostTest() | |
| 121 { | |
| 122 // This test fakes a context loss by substituting the shared context for a new one. | |
| 123 // This simulates what happens when the shared context successfully reco veres | |
|
Stephen White
2013/05/31 17:13:34
Nit: recovers
| |
| 124 // after a graphics reset. | |
| 125 RefPtr<GraphicsContext3D> mainContext = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new MockCanvasContext)); | |
| 126 MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(mainConte xt->webContext()); | |
| 127 | |
| 128 RefPtr<GraphicsContext3D> substituteContext = GraphicsContext3D::createG raphicsContextFromWebContext(adoptPtr(new MockCanvasContext)); | |
| 129 MockCanvasContext& substituteMock = *static_cast<MockCanvasContext*>(mai nContext->webContext()); | |
| 130 | |
| 131 MockWebTextureUpdater updater; | |
| 132 | |
| 133 SkDevice device(SkBitmap::kARGB_8888_Config, 300, 150); | |
| 134 SkDeferredCanvas canvas(&device); | |
| 135 OwnPtr<FakeCanvas2DLayerBridge> bridge = FakeCanvas2DLayerBridge::create (mainContext, &canvas, Canvas2DLayerBridge::NonOpaque, Canvas2DLayerBridge::Sing leThread); | |
| 136 | |
| 137 EXPECT_TRUE(bridge->m_context == mainContext); | |
| 138 bridge->prepareForDraw(); | |
| 139 EXPECT_TRUE(bridge->m_context == mainContext); | |
| 140 | |
| 141 bridge->setFakeSharedContext(substituteContext); // installing an altern at | |
| 142 bridge->prepareForDraw(); | |
| 143 // m_context set to 0 shows that bridge detected lost context and attemp ted | |
| 144 // to recover. Recovery aborts because the fake context does not provide a grContext. | |
|
jamesr
2013/05/31 18:15:45
hmm, so are there any tests that cover a successfu
| |
| 145 EXPECT_EQ(bridge->m_context.get(), (WebCore::GraphicsContext3D*)0); | |
| 146 | |
| 147 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 148 ::testing::Mock::VerifyAndClearExpectations(&substituteMock); | |
| 149 } | |
| 93 }; | 150 }; |
| 94 | 151 |
| 95 namespace { | 152 namespace { |
| 96 | 153 |
| 97 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) | 154 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) |
| 98 { | 155 { |
| 99 fullLifecycleTest(Canvas2DLayerBridge::SingleThread); | 156 fullLifecycleTest(Canvas2DLayerBridge::SingleThread); |
| 100 } | 157 } |
| 101 | 158 |
| 102 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleThreaded) | 159 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleThreaded) |
| 103 { | 160 { |
| 104 fullLifecycleTest(Canvas2DLayerBridge::Threaded); | 161 fullLifecycleTest(Canvas2DLayerBridge::Threaded); |
| 105 } | 162 } |
| 106 | 163 |
| 164 TEST_F(Canvas2DLayerBridgeTest, testContextLost) | |
| 165 { | |
| 166 contextLostTest(); | |
| 167 } | |
| 168 | |
| 107 } // namespace | 169 } // namespace |
| OLD | NEW |