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

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

Issue 2660393002: Use gfx::ColorSpace instead of SkColorSpace in Blink (Closed)
Patch Set: Rebase (again) Created 3 years, 10 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
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 }; 117 };
118 118
119 } // anonymous namespace 119 } // anonymous namespace
120 120
121 class Canvas2DLayerBridgeTest : public Test { 121 class Canvas2DLayerBridgeTest : public Test {
122 public: 122 public:
123 PassRefPtr<Canvas2DLayerBridge> makeBridge( 123 PassRefPtr<Canvas2DLayerBridge> makeBridge(
124 std::unique_ptr<FakeWebGraphicsContext3DProvider> provider, 124 std::unique_ptr<FakeWebGraphicsContext3DProvider> provider,
125 const IntSize& size, 125 const IntSize& size,
126 Canvas2DLayerBridge::AccelerationMode accelerationMode) { 126 Canvas2DLayerBridge::AccelerationMode accelerationMode) {
127 RefPtr<Canvas2DLayerBridge> bridge = adoptRef( 127 RefPtr<Canvas2DLayerBridge> bridge = adoptRef(new Canvas2DLayerBridge(
128 new Canvas2DLayerBridge(std::move(provider), size, 0, NonOpaque, 128 std::move(provider), size, 0, NonOpaque, accelerationMode,
129 accelerationMode, nullptr, kN32_SkColorType)); 129 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType));
130 bridge->dontUseIdleSchedulingForTesting(); 130 bridge->dontUseIdleSchedulingForTesting();
131 return bridge.release(); 131 return bridge.release();
132 } 132 }
133 133
134 protected: 134 protected:
135 void fullLifecycleTest() { 135 void fullLifecycleTest() {
136 FakeGLES2Interface gl; 136 FakeGLES2Interface gl;
137 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 137 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
138 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 138 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
139 139
140 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 140 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
141 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 141 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
142 Canvas2DLayerBridge::DisableAcceleration, nullptr, kN32_SkColorType))); 142 Canvas2DLayerBridge::DisableAcceleration, gfx::ColorSpace::CreateSRGB(),
143 false, kN32_SkColorType)));
143 144
144 const GrGLTextureInfo* textureInfo = skia::GrBackendObjectToGrGLTextureInfo( 145 const GrGLTextureInfo* textureInfo = skia::GrBackendObjectToGrGLTextureInfo(
145 bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnitTests) 146 bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnitTests)
146 ->getTextureHandle(true)); 147 ->getTextureHandle(true));
147 EXPECT_EQ(textureInfo, nullptr); 148 EXPECT_EQ(textureInfo, nullptr);
148 bridge.clear(); 149 bridge.clear();
149 } 150 }
150 151
151 void fallbackToSoftwareIfContextLost() { 152 void fallbackToSoftwareIfContextLost() {
152 FakeGLES2Interface gl; 153 FakeGLES2Interface gl;
153 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 154 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
154 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 155 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
155 156
156 gl.setIsContextLost(true); 157 gl.setIsContextLost(true);
157 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 158 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
158 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 159 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
159 Canvas2DLayerBridge::EnableAcceleration, nullptr, kN32_SkColorType))); 160 Canvas2DLayerBridge::EnableAcceleration, gfx::ColorSpace::CreateSRGB(),
161 false, kN32_SkColorType)));
160 EXPECT_TRUE(bridge->checkSurfaceValid()); 162 EXPECT_TRUE(bridge->checkSurfaceValid());
161 EXPECT_FALSE(bridge->isAccelerated()); 163 EXPECT_FALSE(bridge->isAccelerated());
162 } 164 }
163 165
164 void fallbackToSoftwareOnFailedTextureAlloc() { 166 void fallbackToSoftwareOnFailedTextureAlloc() {
165 { 167 {
166 // No fallback case. 168 // No fallback case.
167 FakeGLES2Interface gl; 169 FakeGLES2Interface gl;
168 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 170 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
169 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 171 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
170 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 172 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
171 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 173 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
172 Canvas2DLayerBridge::EnableAcceleration, nullptr, kN32_SkColorType))); 174 Canvas2DLayerBridge::EnableAcceleration,
175 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
173 EXPECT_TRUE(bridge->checkSurfaceValid()); 176 EXPECT_TRUE(bridge->checkSurfaceValid());
174 EXPECT_TRUE(bridge->isAccelerated()); 177 EXPECT_TRUE(bridge->isAccelerated());
175 sk_sp<SkImage> snapshot = 178 sk_sp<SkImage> snapshot =
176 bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnitTests); 179 bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnitTests);
177 EXPECT_TRUE(bridge->isAccelerated()); 180 EXPECT_TRUE(bridge->isAccelerated());
178 EXPECT_TRUE(snapshot->isTextureBacked()); 181 EXPECT_TRUE(snapshot->isTextureBacked());
179 } 182 }
180 183
181 { 184 {
182 // Fallback case. 185 // Fallback case.
183 FakeGLES2Interface gl; 186 FakeGLES2Interface gl;
184 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 187 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
185 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 188 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
186 GrContext* gr = contextProvider->grContext(); 189 GrContext* gr = contextProvider->grContext();
187 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 190 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
188 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 191 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
189 Canvas2DLayerBridge::EnableAcceleration, nullptr, kN32_SkColorType))); 192 Canvas2DLayerBridge::EnableAcceleration,
193 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
190 EXPECT_TRUE(bridge->checkSurfaceValid()); 194 EXPECT_TRUE(bridge->checkSurfaceValid());
191 EXPECT_TRUE(bridge->isAccelerated()); // We don't yet know that 195 EXPECT_TRUE(bridge->isAccelerated()); // We don't yet know that
192 // allocation will fail. 196 // allocation will fail.
193 // This will cause SkSurface_Gpu creation to fail without 197 // This will cause SkSurface_Gpu creation to fail without
194 // Canvas2DLayerBridge otherwise detecting that anything was disabled. 198 // Canvas2DLayerBridge otherwise detecting that anything was disabled.
195 gr->abandonContext(); 199 gr->abandonContext();
196 sk_sp<SkImage> snapshot = 200 sk_sp<SkImage> snapshot =
197 bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnitTests); 201 bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnitTests);
198 EXPECT_FALSE(bridge->isAccelerated()); 202 EXPECT_FALSE(bridge->isAccelerated());
199 EXPECT_FALSE(snapshot->isTextureBacked()); 203 EXPECT_FALSE(snapshot->isTextureBacked());
200 } 204 }
201 } 205 }
202 206
203 void noDrawOnContextLostTest() { 207 void noDrawOnContextLostTest() {
204 FakeGLES2Interface gl; 208 FakeGLES2Interface gl;
205 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 209 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
206 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 210 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
207 211
208 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 212 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
209 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 213 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
210 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, 214 Canvas2DLayerBridge::ForceAccelerationForTesting,
211 kN32_SkColorType))); 215 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
212 EXPECT_TRUE(bridge->checkSurfaceValid()); 216 EXPECT_TRUE(bridge->checkSurfaceValid());
213 PaintFlags paint; 217 PaintFlags paint;
214 uint32_t genID = bridge->getOrCreateSurface()->generationID(); 218 uint32_t genID = bridge->getOrCreateSurface()->generationID();
215 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); 219 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint);
216 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); 220 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID());
217 gl.setIsContextLost(true); 221 gl.setIsContextLost(true);
218 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); 222 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID());
219 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); 223 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint);
220 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); 224 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID());
221 // This results in the internal surface being torn down in response to the 225 // This results in the internal surface being torn down in response to the
222 // context loss. 226 // context loss.
223 EXPECT_FALSE(bridge->checkSurfaceValid()); 227 EXPECT_FALSE(bridge->checkSurfaceValid());
224 EXPECT_EQ(nullptr, bridge->getOrCreateSurface()); 228 EXPECT_EQ(nullptr, bridge->getOrCreateSurface());
225 // The following passes by not crashing 229 // The following passes by not crashing
226 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); 230 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint);
227 bridge->flush(); 231 bridge->flush();
228 } 232 }
229 233
230 void prepareMailboxWhenContextIsLost() { 234 void prepareMailboxWhenContextIsLost() {
231 FakeGLES2Interface gl; 235 FakeGLES2Interface gl;
232 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 236 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
233 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 237 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
234 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 238 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
235 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 239 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
236 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, 240 Canvas2DLayerBridge::ForceAccelerationForTesting,
237 kN32_SkColorType))); 241 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
238 242
239 // TODO(junov): The PrepareTextureMailbox() method will fail a DCHECK if we 243 // TODO(junov): The PrepareTextureMailbox() method will fail a DCHECK if we
240 // don't do this before calling it the first time when the context is lost. 244 // don't do this before calling it the first time when the context is lost.
241 bridge->prepareSurfaceForPaintingIfNeeded(); 245 bridge->prepareSurfaceForPaintingIfNeeded();
242 246
243 // When the context is lost we are not sure if we should still be producing 247 // When the context is lost we are not sure if we should still be producing
244 // GL frames for the compositor or not, so fail to generate frames. 248 // GL frames for the compositor or not, so fail to generate frames.
245 gl.setIsContextLost(true); 249 gl.setIsContextLost(true);
246 250
247 cc::TextureMailbox textureMailbox; 251 cc::TextureMailbox textureMailbox;
248 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; 252 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback;
249 EXPECT_FALSE( 253 EXPECT_FALSE(
250 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); 254 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback));
251 } 255 }
252 256
253 void prepareMailboxWhenContextIsLostWithFailedRestore() { 257 void prepareMailboxWhenContextIsLostWithFailedRestore() {
254 FakeGLES2Interface gl; 258 FakeGLES2Interface gl;
255 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 259 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
256 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 260 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
257 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 261 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
258 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 262 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
259 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, 263 Canvas2DLayerBridge::ForceAccelerationForTesting,
260 kN32_SkColorType))); 264 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
261 265
262 // TODO(junov): The PrepareTextureMailbox() method will fail a DCHECK if we 266 // TODO(junov): The PrepareTextureMailbox() method will fail a DCHECK if we
263 // don't do this before calling it the first time when the context is lost. 267 // don't do this before calling it the first time when the context is lost.
264 bridge->prepareSurfaceForPaintingIfNeeded(); 268 bridge->prepareSurfaceForPaintingIfNeeded();
265 269
266 // When the context is lost we are not sure if we should still be producing 270 // When the context is lost we are not sure if we should still be producing
267 // GL frames for the compositor or not, so fail to generate frames. 271 // GL frames for the compositor or not, so fail to generate frames.
268 gl.setIsContextLost(true); 272 gl.setIsContextLost(true);
269 EXPECT_FALSE(bridge->checkSurfaceValid()); 273 EXPECT_FALSE(bridge->checkSurfaceValid());
270 274
(...skipping 11 matching lines...) Expand all
282 286
283 void prepareMailboxAndLoseResourceTest() { 287 void prepareMailboxAndLoseResourceTest() {
284 // Prepare a mailbox, then report the resource as lost. 288 // Prepare a mailbox, then report the resource as lost.
285 // This test passes by not crashing and not triggering assertions. 289 // This test passes by not crashing and not triggering assertions.
286 { 290 {
287 FakeGLES2Interface gl; 291 FakeGLES2Interface gl;
288 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 292 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
289 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 293 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
290 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 294 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
291 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 295 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
292 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, 296 Canvas2DLayerBridge::ForceAccelerationForTesting,
293 kN32_SkColorType))); 297 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
294 298
295 cc::TextureMailbox textureMailbox; 299 cc::TextureMailbox textureMailbox;
296 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; 300 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback;
297 EXPECT_TRUE( 301 EXPECT_TRUE(
298 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); 302 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback));
299 303
300 bool lostResource = true; 304 bool lostResource = true;
301 releaseCallback->Run(gpu::SyncToken(), lostResource); 305 releaseCallback->Run(gpu::SyncToken(), lostResource);
302 } 306 }
303 307
304 // Retry with mailbox released while bridge destruction is in progress. 308 // Retry with mailbox released while bridge destruction is in progress.
305 { 309 {
306 FakeGLES2Interface gl; 310 FakeGLES2Interface gl;
307 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 311 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
308 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 312 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
309 313
310 cc::TextureMailbox textureMailbox; 314 cc::TextureMailbox textureMailbox;
311 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; 315 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback;
312 316
313 { 317 {
314 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 318 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
315 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 319 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
316 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, 320 Canvas2DLayerBridge::ForceAccelerationForTesting,
317 kN32_SkColorType))); 321 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
318 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback); 322 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback);
319 // |bridge| goes out of scope and would normally be destroyed, but 323 // |bridge| goes out of scope and would normally be destroyed, but
320 // object is kept alive by self references. 324 // object is kept alive by self references.
321 } 325 }
322 326
323 // This should cause the bridge to be destroyed. 327 // This should cause the bridge to be destroyed.
324 bool lostResource = true; 328 bool lostResource = true;
325 // Before fixing crbug.com/411864, the following line would cause a memory 329 // Before fixing crbug.com/411864, the following line would cause a memory
326 // use after free that sometimes caused a crash in normal builds and 330 // use after free that sometimes caused a crash in normal builds and
327 // crashed consistently with ASAN. 331 // crashed consistently with ASAN.
328 releaseCallback->Run(gpu::SyncToken(), lostResource); 332 releaseCallback->Run(gpu::SyncToken(), lostResource);
329 } 333 }
330 } 334 }
331 335
332 void accelerationHintTest() { 336 void accelerationHintTest() {
333 { 337 {
334 FakeGLES2Interface gl; 338 FakeGLES2Interface gl;
335 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 339 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
336 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 340 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
337 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 341 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
338 std::move(contextProvider), IntSize(300, 300), 0, NonOpaque, 342 std::move(contextProvider), IntSize(300, 300), 0, NonOpaque,
339 Canvas2DLayerBridge::EnableAcceleration, nullptr, kN32_SkColorType))); 343 Canvas2DLayerBridge::EnableAcceleration,
344 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
340 PaintFlags paint; 345 PaintFlags paint;
341 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); 346 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint);
342 sk_sp<SkImage> image = 347 sk_sp<SkImage> image =
343 bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnitTests); 348 bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnitTests);
344 EXPECT_TRUE(bridge->checkSurfaceValid()); 349 EXPECT_TRUE(bridge->checkSurfaceValid());
345 EXPECT_TRUE(bridge->isAccelerated()); 350 EXPECT_TRUE(bridge->isAccelerated());
346 } 351 }
347 352
348 { 353 {
349 FakeGLES2Interface gl; 354 FakeGLES2Interface gl;
350 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 355 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
351 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 356 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
352 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 357 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
353 std::move(contextProvider), IntSize(300, 300), 0, NonOpaque, 358 std::move(contextProvider), IntSize(300, 300), 0, NonOpaque,
354 Canvas2DLayerBridge::EnableAcceleration, nullptr, kN32_SkColorType))); 359 Canvas2DLayerBridge::EnableAcceleration,
360 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
355 PaintFlags paint; 361 PaintFlags paint;
356 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); 362 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint);
357 sk_sp<SkImage> image = bridge->newImageSnapshot(PreferNoAcceleration, 363 sk_sp<SkImage> image = bridge->newImageSnapshot(PreferNoAcceleration,
358 SnapshotReasonUnitTests); 364 SnapshotReasonUnitTests);
359 EXPECT_TRUE(bridge->checkSurfaceValid()); 365 EXPECT_TRUE(bridge->checkSurfaceValid());
360 EXPECT_FALSE(bridge->isAccelerated()); 366 EXPECT_FALSE(bridge->isAccelerated());
361 } 367 }
362 } 368 }
363 }; 369 };
364 370
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 ScopedTestingPlatformSupport<FakePlatformSupport> platform; 1298 ScopedTestingPlatformSupport<FakePlatformSupport> platform;
1293 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 1299 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
1294 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 1300 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
1295 1301
1296 cc::TextureMailbox textureMailbox; 1302 cc::TextureMailbox textureMailbox;
1297 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; 1303 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback;
1298 1304
1299 { 1305 {
1300 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 1306 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
1301 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 1307 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
1302 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, 1308 Canvas2DLayerBridge::ForceAccelerationForTesting,
1303 kN32_SkColorType))); 1309 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
1304 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback); 1310 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback);
1305 } 1311 }
1306 1312
1307 bool lostResource = false; 1313 bool lostResource = false;
1308 releaseCallback->Run(gpu::SyncToken(), lostResource); 1314 releaseCallback->Run(gpu::SyncToken(), lostResource);
1309 1315
1310 EXPECT_EQ(1u, gl.createImageCount()); 1316 EXPECT_EQ(1u, gl.createImageCount());
1311 EXPECT_EQ(1u, gl.destroyImageCount()); 1317 EXPECT_EQ(1u, gl.destroyImageCount());
1312 } 1318 }
1313 1319
1314 class FlushMockGLES2Interface : public gpu::gles2::GLES2InterfaceStub { 1320 class FlushMockGLES2Interface : public gpu::gles2::GLES2InterfaceStub {
1315 public: 1321 public:
1316 MOCK_METHOD0(Flush, void()); 1322 MOCK_METHOD0(Flush, void());
1317 }; 1323 };
1318 1324
1319 TEST_F(Canvas2DLayerBridgeTest, NoUnnecessaryFlushes) { 1325 TEST_F(Canvas2DLayerBridgeTest, NoUnnecessaryFlushes) {
1320 FlushMockGLES2Interface gl; 1326 FlushMockGLES2Interface gl;
1321 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 1327 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
1322 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 1328 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
1323 1329
1324 EXPECT_CALL(gl, Flush()).Times(0); 1330 EXPECT_CALL(gl, Flush()).Times(0);
1325 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 1331 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
1326 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 1332 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
1327 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, 1333 Canvas2DLayerBridge::ForceAccelerationForTesting,
1328 kN32_SkColorType))); 1334 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
1329 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); 1335 EXPECT_FALSE(bridge->hasRecordedDrawCommands());
1330 ::testing::Mock::VerifyAndClearExpectations(&gl); 1336 ::testing::Mock::VerifyAndClearExpectations(&gl);
1331 1337
1332 EXPECT_CALL(gl, Flush()).Times(0); 1338 EXPECT_CALL(gl, Flush()).Times(0);
1333 bridge->didDraw(FloatRect(0, 0, 1, 1)); 1339 bridge->didDraw(FloatRect(0, 0, 1, 1));
1334 EXPECT_TRUE(bridge->hasRecordedDrawCommands()); 1340 EXPECT_TRUE(bridge->hasRecordedDrawCommands());
1335 ::testing::Mock::VerifyAndClearExpectations(&gl); 1341 ::testing::Mock::VerifyAndClearExpectations(&gl);
1336 1342
1337 EXPECT_CALL(gl, Flush()).Times(1); 1343 EXPECT_CALL(gl, Flush()).Times(1);
1338 bridge->flushGpu(); 1344 bridge->flushGpu();
(...skipping 27 matching lines...) Expand all
1366 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); 1372 EXPECT_FALSE(bridge->hasRecordedDrawCommands());
1367 ::testing::Mock::VerifyAndClearExpectations(&gl); 1373 ::testing::Mock::VerifyAndClearExpectations(&gl);
1368 1374
1369 EXPECT_CALL(gl, Flush()).Times(1); 1375 EXPECT_CALL(gl, Flush()).Times(1);
1370 bridge->flushGpu(); 1376 bridge->flushGpu();
1371 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); 1377 EXPECT_FALSE(bridge->hasRecordedDrawCommands());
1372 ::testing::Mock::VerifyAndClearExpectations(&gl); 1378 ::testing::Mock::VerifyAndClearExpectations(&gl);
1373 } 1379 }
1374 1380
1375 } // namespace blink 1381 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698