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

Side by Side Diff: Source/WebKit/chromium/tests/Canvas2DLayerBridgeTest.cpp

Issue 16032003: Fixing Canvas2DLayerBridge to handle lost graphics contexts (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added assertions on m_layer to verify that init was called Created 7 years, 6 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 | Annotate | Revision Log
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
80 {
81 m_fakeSharedContext = m_context;
82 init(opacityMode, threadMode);
83 }
84
85 RefPtr<GraphicsContext3D> m_fakeSharedContext;
86 };
87
61 } // namespace 88 } // namespace
62 89
63 class Canvas2DLayerBridgeTest : public Test { 90 class Canvas2DLayerBridgeTest : public Test {
64 protected: 91 protected:
65 void fullLifecycleTest(Canvas2DLayerBridge::ThreadMode threadMode) 92 void fullLifecycleTest(Canvas2DLayerBridge::ThreadMode threadMode)
66 { 93 {
67 RefPtr<GraphicsContext3D> mainContext = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new MockCanvasContext)); 94 RefPtr<GraphicsContext3D> mainContext = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new MockCanvasContext));
68 95
69 MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(mainConte xt->webContext()); 96 MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(mainConte xt->webContext());
70 97
71 MockWebTextureUpdater updater; 98 MockWebTextureUpdater updater;
72 99
73 SkDevice device(SkBitmap::kARGB_8888_Config, 300, 150); 100 SkDevice device(SkBitmap::kARGB_8888_Config, 300, 150);
74 SkDeferredCanvas canvas(&device); 101 SkDeferredCanvas canvas(&device);
75 102
76 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 103 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
77 104
78 OwnPtr<Canvas2DLayerBridge> bridge = Canvas2DLayerBridge::create(mainCon text.release(), &canvas, Canvas2DLayerBridge::NonOpaque, threadMode); 105 OwnPtr<Canvas2DLayerBridge> bridge = FakeCanvas2DLayerBridge::create(mai nContext.release(), &canvas, Canvas2DLayerBridge::NonOpaque, threadMode);
79 106
80 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 107 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
81 108
82 EXPECT_CALL(mainMock, flush()); 109 EXPECT_CALL(mainMock, flush());
83 unsigned textureId = bridge->backBufferTexture(); 110 unsigned textureId = bridge->backBufferTexture();
84 EXPECT_TRUE(textureId == 0); 111 EXPECT_TRUE(textureId == 0);
85 112
86 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 113 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
87 114
88 bridge.clear(); 115 bridge.clear();
89 116
90 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 117 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
91 ::testing::Mock::VerifyAndClearExpectations(&updater); 118 ::testing::Mock::VerifyAndClearExpectations(&updater);
92 } 119 }
120
121 void contextLostTest()
Stephen White 2013/05/31 15:06:18 Thanks for the new test!
122 {
123 // This test fakes a context loss by substituting the shared context for a new,
124 // Which simulated what happens when the shared context successfully rec overes
Stephen White 2013/05/31 15:06:18 Nit: "for a new, Which simulated what happens" i c
125 // after a lost context.
126 RefPtr<GraphicsContext3D> mainContext = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new MockCanvasContext));
127 MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(mainConte xt->webContext());
128
129 RefPtr<GraphicsContext3D> substituteContext = GraphicsContext3D::createG raphicsContextFromWebContext(adoptPtr(new MockCanvasContext));
130 MockCanvasContext& substituteMock = *static_cast<MockCanvasContext*>(mai nContext->webContext());
131
132 MockWebTextureUpdater updater;
133
134 SkDevice device(SkBitmap::kARGB_8888_Config, 300, 150);
135 SkDeferredCanvas canvas(&device);
136 OwnPtr<FakeCanvas2DLayerBridge> bridge = FakeCanvas2DLayerBridge::create (mainContext, &canvas, Canvas2DLayerBridge::NonOpaque, Canvas2DLayerBridge::Sing leThread);
137
138 EXPECT_TRUE(bridge->m_context == mainContext);
139 bridge->prepareForDraw();
140 EXPECT_TRUE(bridge->m_context == mainContext);
141
142 bridge->setFakeSharedContext(substituteContext); // installing an altern at
143 bridge->prepareForDraw();
144 // m_context set to 0 shows that bridge detected lost context and attemp ted
145 // to recover. Recovery aborts because the fake context does not provide a grContext.
146 EXPECT_EQ(bridge->m_context.get(), (WebCore::GraphicsContext3D*)0);
147
148 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
149 ::testing::Mock::VerifyAndClearExpectations(&substituteMock);
150 }
93 }; 151 };
94 152
95 namespace { 153 namespace {
96 154
97 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) 155 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded)
98 { 156 {
99 fullLifecycleTest(Canvas2DLayerBridge::SingleThread); 157 fullLifecycleTest(Canvas2DLayerBridge::SingleThread);
100 } 158 }
101 159
102 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleThreaded) 160 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleThreaded)
103 { 161 {
104 fullLifecycleTest(Canvas2DLayerBridge::Threaded); 162 fullLifecycleTest(Canvas2DLayerBridge::Threaded);
105 } 163 }
106 164
165 TEST_F(Canvas2DLayerBridgeTest, testContextLost)
166 {
167 contextLostTest();
168 }
169
107 } // namespace 170 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698