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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 { | 154 { |
155 // Fallback case. | 155 // Fallback case. |
156 FakeGLES2Interface gl; | 156 FakeGLES2Interface gl; |
157 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = | 157 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
158 wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 158 wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
159 GrContext* gr = contextProvider->grContext(); | 159 GrContext* gr = contextProvider->grContext(); |
160 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( | 160 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
161 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, | 161 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, |
162 Canvas2DLayerBridge::EnableAcceleration, nullptr))); | 162 Canvas2DLayerBridge::EnableAcceleration, nullptr))); |
163 EXPECT_TRUE(bridge->checkSurfaceValid()); | 163 EXPECT_TRUE(bridge->checkSurfaceValid()); |
164 EXPECT_TRUE( | 164 EXPECT_TRUE(bridge->isAccelerated()); // We don't yet know that |
165 bridge | 165 // allocation will fail. |
166 ->isAccelerated()); // We don't yet know that allocation will fai
l | |
167 // This will cause SkSurface_Gpu creation to fail without | 166 // This will cause SkSurface_Gpu creation to fail without |
168 // Canvas2DLayerBridge otherwise detecting that anything was disabled. | 167 // Canvas2DLayerBridge otherwise detecting that anything was disabled. |
169 gr->abandonContext(); | 168 gr->abandonContext(); |
170 sk_sp<SkImage> snapshot = | 169 sk_sp<SkImage> snapshot = |
171 bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnitTests); | 170 bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnitTests); |
172 EXPECT_FALSE(bridge->isAccelerated()); | 171 EXPECT_FALSE(bridge->isAccelerated()); |
173 EXPECT_FALSE(snapshot->isTextureBacked()); | 172 EXPECT_FALSE(snapshot->isTextureBacked()); |
174 } | 173 } |
175 } | 174 } |
176 | 175 |
177 void noDrawOnContextLostTest() { | 176 void noDrawOnContextLostTest() { |
178 FakeGLES2Interface gl; | 177 FakeGLES2Interface gl; |
179 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = | 178 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
180 wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 179 wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
181 | 180 |
182 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( | 181 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
183 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, | 182 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, |
184 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr))); | 183 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr))); |
185 EXPECT_TRUE(bridge->checkSurfaceValid()); | 184 EXPECT_TRUE(bridge->checkSurfaceValid()); |
186 SkPaint paint; | 185 SkPaint paint; |
187 uint32_t genID = bridge->getOrCreateSurface()->generationID(); | 186 uint32_t genID = bridge->getOrCreateSurface()->generationID(); |
188 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 187 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
189 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); | 188 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); |
190 gl.setIsContextLost(true); | 189 gl.setIsContextLost(true); |
191 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); | 190 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); |
192 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 191 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
193 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); | 192 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); |
194 // This results in the internal surface being torn down in response to the c
ontext loss. | 193 // This results in the internal surface being torn down in response to the |
| 194 // context loss. |
195 EXPECT_FALSE(bridge->checkSurfaceValid()); | 195 EXPECT_FALSE(bridge->checkSurfaceValid()); |
196 EXPECT_EQ(nullptr, bridge->getOrCreateSurface()); | 196 EXPECT_EQ(nullptr, bridge->getOrCreateSurface()); |
197 // The following passes by not crashing | 197 // The following passes by not crashing |
198 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 198 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
199 bridge->flush(); | 199 bridge->flush(); |
200 } | 200 } |
201 | 201 |
202 void prepareMailboxWhenContextIsLost() { | 202 void prepareMailboxWhenContextIsLost() { |
203 FakeGLES2Interface gl; | 203 FakeGLES2Interface gl; |
204 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = | 204 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
205 wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 205 wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
206 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( | 206 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
207 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, | 207 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, |
208 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr))); | 208 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr))); |
209 | 209 |
210 // TODO(junov): The PrepareTextureMailbox() method will fail a DCHECK if we
don't | 210 // TODO(junov): The PrepareTextureMailbox() method will fail a DCHECK if we |
211 // do this before calling it the first time when the context is lost. | 211 // don't do this before calling it the first time when the context is lost. |
212 bridge->prepareSurfaceForPaintingIfNeeded(); | 212 bridge->prepareSurfaceForPaintingIfNeeded(); |
213 | 213 |
214 // When the context is lost we are not sure if we should be producing GL fra
mes for the | 214 // When the context is lost we are not sure if we should still be producing |
215 // compositor still or not, so fail to generate frames. | 215 // GL frames for the compositor or not, so fail to generate frames. |
216 gl.setIsContextLost(true); | 216 gl.setIsContextLost(true); |
217 | 217 |
218 cc::TextureMailbox textureMailbox; | 218 cc::TextureMailbox textureMailbox; |
219 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 219 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
220 EXPECT_FALSE( | 220 EXPECT_FALSE( |
221 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); | 221 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); |
222 } | 222 } |
223 | 223 |
224 void prepareMailboxAndLoseResourceTest() { | 224 void prepareMailboxAndLoseResourceTest() { |
225 // Prepare a mailbox, then report the resource as lost. | 225 // Prepare a mailbox, then report the resource as lost. |
(...skipping 22 matching lines...) Expand all Loading... |
248 wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 248 wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
249 | 249 |
250 cc::TextureMailbox textureMailbox; | 250 cc::TextureMailbox textureMailbox; |
251 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 251 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
252 | 252 |
253 { | 253 { |
254 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( | 254 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
255 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, | 255 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, |
256 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr))); | 256 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr))); |
257 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback); | 257 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback); |
258 // |bridge| goes out of scope and would normally be destroyed, but objec
t is kept alive by self references. | 258 // |bridge| goes out of scope and would normally be destroyed, but |
| 259 // object is kept alive by self references. |
259 } | 260 } |
260 | 261 |
261 // Before fixing crbug.com/411864, the following line you cause a memory u
se after free | |
262 // that sometimes causes a crash in normal builds and crashes consistently
with ASAN. | |
263 // This should cause the bridge to be destroyed. | 262 // This should cause the bridge to be destroyed. |
264 bool lostResource = true; | 263 bool lostResource = true; |
| 264 // Before fixing crbug.com/411864, the following line would cause a memory |
| 265 // use after free that sometimes caused a crash in normal builds and |
| 266 // crashed consistently with ASAN. |
265 releaseCallback->Run(gpu::SyncToken(), lostResource); | 267 releaseCallback->Run(gpu::SyncToken(), lostResource); |
266 } | 268 } |
267 } | 269 } |
268 | 270 |
269 void accelerationHintTest() { | 271 void accelerationHintTest() { |
270 { | 272 { |
271 FakeGLES2Interface gl; | 273 FakeGLES2Interface gl; |
272 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = | 274 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
273 wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 275 wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
274 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( | 276 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 EXPECT_FALSE( | 1210 EXPECT_FALSE( |
1209 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); | 1211 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); |
1210 EXPECT_TRUE(bridge->checkSurfaceValid()); | 1212 EXPECT_TRUE(bridge->checkSurfaceValid()); |
1211 | 1213 |
1212 // Tear down the bridge on the thread so that 'bridge' can go out of scope | 1214 // Tear down the bridge on the thread so that 'bridge' can go out of scope |
1213 // without crashing due to thread checks | 1215 // without crashing due to thread checks |
1214 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); | 1216 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
1215 } | 1217 } |
1216 | 1218 |
1217 } // namespace blink | 1219 } // namespace blink |
OLD | NEW |