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

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

Issue 552423002: Fix crash in Canvas2DLayerBridge after a GPU resource is lost (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: response to review Created 6 years, 3 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterPMColor(300, 15 0)); 174 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterPMColor(300, 15 0));
175 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(surf ace.get())); 175 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(surf ace.get()));
176 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new MockWebGraphicsContext3DProvider(&mainMock)); 176 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new MockWebGraphicsContext3DProvider(&mainMock));
177 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainMockP rovider.release(), canvas.release(), surface, 0, NonOpaque))); 177 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainMockP rovider.release(), canvas.release(), surface, 0, NonOpaque)));
178 bridge->m_lastImageId = 1; 178 bridge->m_lastImageId = 1;
179 179
180 NullWebExternalBitmap bitmap; 180 NullWebExternalBitmap bitmap;
181 bridge->prepareMailbox(0, &bitmap); 181 bridge->prepareMailbox(0, &bitmap);
182 EXPECT_EQ(0u, bridge->m_lastImageId); 182 EXPECT_EQ(0u, bridge->m_lastImageId);
183 } 183 }
184
185 void prepareMailboxAndLoseResourceTest()
186 {
187 MockCanvasContext mainMock;
188 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterPMColor(300, 15 0));
189 bool lostResource = true;
190
191 // Prepare a mailbox, then report the resource as lost.
192 // This test passes by not crashing and not triggering assertions.
193 {
194 WebExternalTextureMailbox mailbox;
195 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create( surface.get()));
196 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock));
197 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), canvas.release(), surface, 0, NonOpaque)));
198 bridge->prepareMailbox(&mailbox, 0);
199 bridge->mailboxReleased(mailbox, lostResource);
200 }
201
202 // Retry with mailbox released while bridge destruction is in progress
203 {
204 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create( surface.get()));
205 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock));
206 WebExternalTextureMailbox mailbox;
207 Canvas2DLayerBridge* rawBridge;
208 {
209 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(m ainMockProvider.release(), canvas.release(), surface, 0, NonOpaque)));
210 bridge->prepareMailbox(&mailbox, 0);
211 rawBridge = bridge.get();
212 } // bridge goes out of scope, but object is kept alive by self refe rences
213 // before fixing crbug.com/411864, the following line you cause a me mory use after free
214 // that sometimes causes a crash in normal builds and crashes consis tently with ASAN.
215 rawBridge->mailboxReleased(mailbox, lostResource); // This should se lf-destruct the bridge.
216 }
217 }
184 }; 218 };
185 219
186 namespace { 220 namespace {
187 221
188 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) 222 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded)
189 { 223 {
190 fullLifecycleTest(); 224 fullLifecycleTest();
191 } 225 }
192 226
193 TEST_F(Canvas2DLayerBridgeTest, testNoDrawOnContextLost) 227 TEST_F(Canvas2DLayerBridgeTest, testNoDrawOnContextLost)
194 { 228 {
195 noDrawOnContextLostTest(); 229 noDrawOnContextLostTest();
196 } 230 }
197 231
198 TEST_F(Canvas2DLayerBridgeTest, prepareMailboxWithBitmapTest) 232 TEST_F(Canvas2DLayerBridgeTest, testPrepareMailboxWithBitmap)
199 { 233 {
200 prepareMailboxWithBitmapTest(); 234 prepareMailboxWithBitmapTest();
201 } 235 }
202 236
237 TEST_F(Canvas2DLayerBridgeTest, testPrepareMailboxAndLoseResource)
238 {
239 prepareMailboxAndLoseResourceTest();
240 }
241
203 } // namespace 242 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698