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

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

Issue 2825183002: Plumb CanvasColorParams to canvas image classes (Closed)
Patch Set: Require both runtime flags Created 3 years, 8 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 acceleration_mode) { 126 Canvas2DLayerBridge::AccelerationMode acceleration_mode) {
127 RefPtr<Canvas2DLayerBridge> bridge = AdoptRef(new Canvas2DLayerBridge( 127 RefPtr<Canvas2DLayerBridge> bridge = AdoptRef(
128 std::move(provider), size, 0, kNonOpaque, acceleration_mode, 128 new Canvas2DLayerBridge(std::move(provider), size, 0, kNonOpaque,
129 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)); 129 acceleration_mode, CanvasColorParams()));
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> context_provider = 137 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
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(context_provider), IntSize(300, 150), 0, kNonOpaque, 141 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque,
142 Canvas2DLayerBridge::kDisableAcceleration, 142 Canvas2DLayerBridge::kDisableAcceleration, CanvasColorParams())));
143 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
144 143
145 const GrGLTextureInfo* texture_info = 144 const GrGLTextureInfo* texture_info =
146 skia::GrBackendObjectToGrGLTextureInfo( 145 skia::GrBackendObjectToGrGLTextureInfo(
147 bridge 146 bridge
148 ->NewImageSnapshot(kPreferAcceleration, 147 ->NewImageSnapshot(kPreferAcceleration,
149 kSnapshotReasonUnitTests) 148 kSnapshotReasonUnitTests)
150 ->getTextureHandle(true)); 149 ->getTextureHandle(true));
151 EXPECT_EQ(texture_info, nullptr); 150 EXPECT_EQ(texture_info, nullptr);
152 bridge.Clear(); 151 bridge.Clear();
153 } 152 }
154 153
155 void FallbackToSoftwareIfContextLost() { 154 void FallbackToSoftwareIfContextLost() {
156 FakeGLES2Interface gl; 155 FakeGLES2Interface gl;
157 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = 156 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
158 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 157 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
159 158
160 gl.setIsContextLost(true); 159 gl.setIsContextLost(true);
161 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( 160 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
162 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, 161 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque,
163 Canvas2DLayerBridge::kEnableAcceleration, gfx::ColorSpace::CreateSRGB(), 162 Canvas2DLayerBridge::kEnableAcceleration, CanvasColorParams())));
164 false, kN32_SkColorType)));
165 EXPECT_TRUE(bridge->CheckSurfaceValid()); 163 EXPECT_TRUE(bridge->CheckSurfaceValid());
166 EXPECT_FALSE(bridge->IsAccelerated()); 164 EXPECT_FALSE(bridge->IsAccelerated());
167 } 165 }
168 166
169 void FallbackToSoftwareOnFailedTextureAlloc() { 167 void FallbackToSoftwareOnFailedTextureAlloc() {
170 { 168 {
171 // No fallback case. 169 // No fallback case.
172 FakeGLES2Interface gl; 170 FakeGLES2Interface gl;
173 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = 171 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
174 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 172 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
175 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( 173 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
176 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, 174 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque,
177 Canvas2DLayerBridge::kEnableAcceleration, 175 Canvas2DLayerBridge::kEnableAcceleration, CanvasColorParams())));
178 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
179 EXPECT_TRUE(bridge->CheckSurfaceValid()); 176 EXPECT_TRUE(bridge->CheckSurfaceValid());
180 EXPECT_TRUE(bridge->IsAccelerated()); 177 EXPECT_TRUE(bridge->IsAccelerated());
181 sk_sp<SkImage> snapshot = bridge->NewImageSnapshot( 178 sk_sp<SkImage> snapshot = bridge->NewImageSnapshot(
182 kPreferAcceleration, kSnapshotReasonUnitTests); 179 kPreferAcceleration, kSnapshotReasonUnitTests);
183 EXPECT_TRUE(bridge->IsAccelerated()); 180 EXPECT_TRUE(bridge->IsAccelerated());
184 EXPECT_TRUE(snapshot->isTextureBacked()); 181 EXPECT_TRUE(snapshot->isTextureBacked());
185 } 182 }
186 183
187 { 184 {
188 // Fallback case. 185 // Fallback case.
189 FakeGLES2Interface gl; 186 FakeGLES2Interface gl;
190 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = 187 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
191 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 188 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
192 GrContext* gr = context_provider->GetGrContext(); 189 GrContext* gr = context_provider->GetGrContext();
193 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( 190 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
194 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, 191 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque,
195 Canvas2DLayerBridge::kEnableAcceleration, 192 Canvas2DLayerBridge::kEnableAcceleration, CanvasColorParams())));
196 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
197 EXPECT_TRUE(bridge->CheckSurfaceValid()); 193 EXPECT_TRUE(bridge->CheckSurfaceValid());
198 EXPECT_TRUE(bridge->IsAccelerated()); // We don't yet know that 194 EXPECT_TRUE(bridge->IsAccelerated()); // We don't yet know that
199 // allocation will fail. 195 // allocation will fail.
200 // This will cause SkSurface_Gpu creation to fail without 196 // This will cause SkSurface_Gpu creation to fail without
201 // Canvas2DLayerBridge otherwise detecting that anything was disabled. 197 // Canvas2DLayerBridge otherwise detecting that anything was disabled.
202 gr->abandonContext(); 198 gr->abandonContext();
203 sk_sp<SkImage> snapshot = bridge->NewImageSnapshot( 199 sk_sp<SkImage> snapshot = bridge->NewImageSnapshot(
204 kPreferAcceleration, kSnapshotReasonUnitTests); 200 kPreferAcceleration, kSnapshotReasonUnitTests);
205 EXPECT_FALSE(bridge->IsAccelerated()); 201 EXPECT_FALSE(bridge->IsAccelerated());
206 EXPECT_FALSE(snapshot->isTextureBacked()); 202 EXPECT_FALSE(snapshot->isTextureBacked());
207 } 203 }
208 } 204 }
209 205
210 void NoDrawOnContextLostTest() { 206 void NoDrawOnContextLostTest() {
211 FakeGLES2Interface gl; 207 FakeGLES2Interface gl;
212 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = 208 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
213 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 209 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
214 210
215 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( 211 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
216 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, 212 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque,
217 Canvas2DLayerBridge::kForceAccelerationForTesting, 213 Canvas2DLayerBridge::kForceAccelerationForTesting,
218 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType))); 214 CanvasColorParams())));
219 EXPECT_TRUE(bridge->CheckSurfaceValid()); 215 EXPECT_TRUE(bridge->CheckSurfaceValid());
220 PaintFlags flags; 216 PaintFlags flags;
221 uint32_t gen_id = bridge->GetOrCreateSurface()->generationID(); 217 uint32_t gen_id = bridge->GetOrCreateSurface()->generationID();
222 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); 218 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags);
223 EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID()); 219 EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID());
224 gl.setIsContextLost(true); 220 gl.setIsContextLost(true);
225 EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID()); 221 EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID());
226 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); 222 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags);
227 EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID()); 223 EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID());
228 // This results in the internal surface being torn down in response to the 224 // This results in the internal surface being torn down in response to the
229 // context loss. 225 // context loss.
230 EXPECT_FALSE(bridge->CheckSurfaceValid()); 226 EXPECT_FALSE(bridge->CheckSurfaceValid());
231 EXPECT_EQ(nullptr, bridge->GetOrCreateSurface()); 227 EXPECT_EQ(nullptr, bridge->GetOrCreateSurface());
232 // The following passes by not crashing 228 // The following passes by not crashing
233 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); 229 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags);
234 bridge->Flush(); 230 bridge->Flush();
235 } 231 }
236 232
237 void PrepareMailboxWhenContextIsLost() { 233 void PrepareMailboxWhenContextIsLost() {
238 FakeGLES2Interface gl; 234 FakeGLES2Interface gl;
239 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = 235 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
240 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 236 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
241 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( 237 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
242 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, 238 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque,
243 Canvas2DLayerBridge::kForceAccelerationForTesting, 239 Canvas2DLayerBridge::kForceAccelerationForTesting,
244 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType))); 240 CanvasColorParams())));
245 241
246 EXPECT_TRUE(bridge->IsAccelerated()); 242 EXPECT_TRUE(bridge->IsAccelerated());
247 243
248 // When the context is lost we are not sure if we should still be producing 244 // When the context is lost we are not sure if we should still be producing
249 // GL frames for the compositor or not, so fail to generate frames. 245 // GL frames for the compositor or not, so fail to generate frames.
250 gl.setIsContextLost(true); 246 gl.setIsContextLost(true);
251 247
252 cc::TextureMailbox texture_mailbox; 248 cc::TextureMailbox texture_mailbox;
253 std::unique_ptr<cc::SingleReleaseCallback> release_callback; 249 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
254 EXPECT_FALSE( 250 EXPECT_FALSE(
255 bridge->PrepareTextureMailbox(&texture_mailbox, &release_callback)); 251 bridge->PrepareTextureMailbox(&texture_mailbox, &release_callback));
256 } 252 }
257 253
258 void PrepareMailboxWhenContextIsLostWithFailedRestore() { 254 void PrepareMailboxWhenContextIsLostWithFailedRestore() {
259 FakeGLES2Interface gl; 255 FakeGLES2Interface gl;
260 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = 256 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
261 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 257 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
262 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( 258 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
263 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, 259 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque,
264 Canvas2DLayerBridge::kForceAccelerationForTesting, 260 Canvas2DLayerBridge::kForceAccelerationForTesting,
265 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType))); 261 CanvasColorParams())));
266 262
267 bridge->GetOrCreateSurface(); 263 bridge->GetOrCreateSurface();
268 EXPECT_TRUE(bridge->CheckSurfaceValid()); 264 EXPECT_TRUE(bridge->CheckSurfaceValid());
269 // When the context is lost we are not sure if we should still be producing 265 // When the context is lost we are not sure if we should still be producing
270 // GL frames for the compositor or not, so fail to generate frames. 266 // GL frames for the compositor or not, so fail to generate frames.
271 gl.setIsContextLost(true); 267 gl.setIsContextLost(true);
272 EXPECT_FALSE(bridge->CheckSurfaceValid()); 268 EXPECT_FALSE(bridge->CheckSurfaceValid());
273 269
274 // Restoration will fail because 270 // Restoration will fail because
275 // Platform::createSharedOffscreenGraphicsContext3DProvider() is stubbed 271 // Platform::createSharedOffscreenGraphicsContext3DProvider() is stubbed
(...skipping 10 matching lines...) Expand all
286 void PrepareMailboxAndLoseResourceTest() { 282 void PrepareMailboxAndLoseResourceTest() {
287 // Prepare a mailbox, then report the resource as lost. 283 // Prepare a mailbox, then report the resource as lost.
288 // This test passes by not crashing and not triggering assertions. 284 // This test passes by not crashing and not triggering assertions.
289 { 285 {
290 FakeGLES2Interface gl; 286 FakeGLES2Interface gl;
291 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = 287 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
292 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 288 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
293 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( 289 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
294 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, 290 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque,
295 Canvas2DLayerBridge::kForceAccelerationForTesting, 291 Canvas2DLayerBridge::kForceAccelerationForTesting,
296 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType))); 292 CanvasColorParams())));
297 293
298 cc::TextureMailbox texture_mailbox; 294 cc::TextureMailbox texture_mailbox;
299 std::unique_ptr<cc::SingleReleaseCallback> release_callback; 295 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
300 EXPECT_TRUE( 296 EXPECT_TRUE(
301 bridge->PrepareTextureMailbox(&texture_mailbox, &release_callback)); 297 bridge->PrepareTextureMailbox(&texture_mailbox, &release_callback));
302 298
303 bool lost_resource = true; 299 bool lost_resource = true;
304 release_callback->Run(gpu::SyncToken(), lost_resource); 300 release_callback->Run(gpu::SyncToken(), lost_resource);
305 } 301 }
306 302
307 // Retry with mailbox released while bridge destruction is in progress. 303 // Retry with mailbox released while bridge destruction is in progress.
308 { 304 {
309 FakeGLES2Interface gl; 305 FakeGLES2Interface gl;
310 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = 306 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
311 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 307 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
312 308
313 cc::TextureMailbox texture_mailbox; 309 cc::TextureMailbox texture_mailbox;
314 std::unique_ptr<cc::SingleReleaseCallback> release_callback; 310 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
315 311
316 { 312 {
317 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( 313 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
318 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, 314 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque,
319 Canvas2DLayerBridge::kForceAccelerationForTesting, 315 Canvas2DLayerBridge::kForceAccelerationForTesting,
320 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType))); 316 CanvasColorParams())));
321 bridge->PrepareTextureMailbox(&texture_mailbox, &release_callback); 317 bridge->PrepareTextureMailbox(&texture_mailbox, &release_callback);
322 // |bridge| goes out of scope and would normally be destroyed, but 318 // |bridge| goes out of scope and would normally be destroyed, but
323 // object is kept alive by self references. 319 // object is kept alive by self references.
324 } 320 }
325 321
326 // This should cause the bridge to be destroyed. 322 // This should cause the bridge to be destroyed.
327 bool lost_resource = true; 323 bool lost_resource = true;
328 // Before fixing crbug.com/411864, the following line would cause a memory 324 // Before fixing crbug.com/411864, the following line would cause a memory
329 // use after free that sometimes caused a crash in normal builds and 325 // use after free that sometimes caused a crash in normal builds and
330 // crashed consistently with ASAN. 326 // crashed consistently with ASAN.
331 release_callback->Run(gpu::SyncToken(), lost_resource); 327 release_callback->Run(gpu::SyncToken(), lost_resource);
332 } 328 }
333 } 329 }
334 330
335 void AccelerationHintTest() { 331 void AccelerationHintTest() {
336 { 332 {
337 FakeGLES2Interface gl; 333 FakeGLES2Interface gl;
338 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = 334 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
339 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 335 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
340 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( 336 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
341 std::move(context_provider), IntSize(300, 300), 0, kNonOpaque, 337 std::move(context_provider), IntSize(300, 300), 0, kNonOpaque,
342 Canvas2DLayerBridge::kEnableAcceleration, 338 Canvas2DLayerBridge::kEnableAcceleration, CanvasColorParams())));
343 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
344 PaintFlags flags; 339 PaintFlags flags;
345 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); 340 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags);
346 sk_sp<SkImage> image = bridge->NewImageSnapshot(kPreferAcceleration, 341 sk_sp<SkImage> image = bridge->NewImageSnapshot(kPreferAcceleration,
347 kSnapshotReasonUnitTests); 342 kSnapshotReasonUnitTests);
348 EXPECT_TRUE(bridge->CheckSurfaceValid()); 343 EXPECT_TRUE(bridge->CheckSurfaceValid());
349 EXPECT_TRUE(bridge->IsAccelerated()); 344 EXPECT_TRUE(bridge->IsAccelerated());
350 } 345 }
351 346
352 { 347 {
353 FakeGLES2Interface gl; 348 FakeGLES2Interface gl;
354 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = 349 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
355 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 350 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
356 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( 351 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
357 std::move(context_provider), IntSize(300, 300), 0, kNonOpaque, 352 std::move(context_provider), IntSize(300, 300), 0, kNonOpaque,
358 Canvas2DLayerBridge::kEnableAcceleration, 353 Canvas2DLayerBridge::kEnableAcceleration, CanvasColorParams())));
359 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
360 PaintFlags flags; 354 PaintFlags flags;
361 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); 355 bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags);
362 sk_sp<SkImage> image = bridge->NewImageSnapshot(kPreferNoAcceleration, 356 sk_sp<SkImage> image = bridge->NewImageSnapshot(kPreferNoAcceleration,
363 kSnapshotReasonUnitTests); 357 kSnapshotReasonUnitTests);
364 EXPECT_TRUE(bridge->CheckSurfaceValid()); 358 EXPECT_TRUE(bridge->CheckSurfaceValid());
365 EXPECT_FALSE(bridge->IsAccelerated()); 359 EXPECT_FALSE(bridge->IsAccelerated());
366 } 360 }
367 } 361 }
368 }; 362 };
369 363
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = 1307 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
1314 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 1308 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
1315 1309
1316 cc::TextureMailbox texture_mailbox; 1310 cc::TextureMailbox texture_mailbox;
1317 std::unique_ptr<cc::SingleReleaseCallback> release_callback; 1311 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
1318 1312
1319 { 1313 {
1320 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( 1314 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
1321 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, 1315 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque,
1322 Canvas2DLayerBridge::kForceAccelerationForTesting, 1316 Canvas2DLayerBridge::kForceAccelerationForTesting,
1323 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType))); 1317 CanvasColorParams())));
1324 bridge->PrepareTextureMailbox(&texture_mailbox, &release_callback); 1318 bridge->PrepareTextureMailbox(&texture_mailbox, &release_callback);
1325 } 1319 }
1326 1320
1327 bool lost_resource = false; 1321 bool lost_resource = false;
1328 release_callback->Run(gpu::SyncToken(), lost_resource); 1322 release_callback->Run(gpu::SyncToken(), lost_resource);
1329 1323
1330 EXPECT_EQ(1u, gl.CreateImageCount()); 1324 EXPECT_EQ(1u, gl.CreateImageCount());
1331 EXPECT_EQ(1u, gl.DestroyImageCount()); 1325 EXPECT_EQ(1u, gl.DestroyImageCount());
1332 } 1326 }
1333 1327
1334 class FlushMockGLES2Interface : public gpu::gles2::GLES2InterfaceStub { 1328 class FlushMockGLES2Interface : public gpu::gles2::GLES2InterfaceStub {
1335 public: 1329 public:
1336 MOCK_METHOD0(Flush, void()); 1330 MOCK_METHOD0(Flush, void());
1337 }; 1331 };
1338 1332
1339 TEST_F(Canvas2DLayerBridgeTest, NoUnnecessaryFlushes) { 1333 TEST_F(Canvas2DLayerBridgeTest, NoUnnecessaryFlushes) {
1340 FlushMockGLES2Interface gl; 1334 FlushMockGLES2Interface gl;
1341 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = 1335 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
1342 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 1336 WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
1343 1337
1344 EXPECT_CALL(gl, Flush()).Times(0); 1338 EXPECT_CALL(gl, Flush()).Times(0);
1345 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( 1339 Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
1346 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, 1340 std::move(context_provider), IntSize(300, 150), 0, kNonOpaque,
1347 Canvas2DLayerBridge::kForceAccelerationForTesting, 1341 Canvas2DLayerBridge::kForceAccelerationForTesting, CanvasColorParams())));
1348 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
1349 EXPECT_FALSE(bridge->HasRecordedDrawCommands()); 1342 EXPECT_FALSE(bridge->HasRecordedDrawCommands());
1350 ::testing::Mock::VerifyAndClearExpectations(&gl); 1343 ::testing::Mock::VerifyAndClearExpectations(&gl);
1351 1344
1352 EXPECT_CALL(gl, Flush()).Times(0); 1345 EXPECT_CALL(gl, Flush()).Times(0);
1353 bridge->DidDraw(FloatRect(0, 0, 1, 1)); 1346 bridge->DidDraw(FloatRect(0, 0, 1, 1));
1354 EXPECT_TRUE(bridge->HasRecordedDrawCommands()); 1347 EXPECT_TRUE(bridge->HasRecordedDrawCommands());
1355 ::testing::Mock::VerifyAndClearExpectations(&gl); 1348 ::testing::Mock::VerifyAndClearExpectations(&gl);
1356 1349
1357 EXPECT_CALL(gl, Flush()).Times(1); 1350 EXPECT_CALL(gl, Flush()).Times(1);
1358 bridge->FlushGpu(); 1351 bridge->FlushGpu();
(...skipping 27 matching lines...) Expand all
1386 EXPECT_FALSE(bridge->HasRecordedDrawCommands()); 1379 EXPECT_FALSE(bridge->HasRecordedDrawCommands());
1387 ::testing::Mock::VerifyAndClearExpectations(&gl); 1380 ::testing::Mock::VerifyAndClearExpectations(&gl);
1388 1381
1389 EXPECT_CALL(gl, Flush()).Times(1); 1382 EXPECT_CALL(gl, Flush()).Times(1);
1390 bridge->FlushGpu(); 1383 bridge->FlushGpu();
1391 EXPECT_FALSE(bridge->HasRecordedDrawCommands()); 1384 EXPECT_FALSE(bridge->HasRecordedDrawCommands());
1392 ::testing::Mock::VerifyAndClearExpectations(&gl); 1385 ::testing::Mock::VerifyAndClearExpectations(&gl);
1393 } 1386 }
1394 1387
1395 } // namespace blink 1388 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698