OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/canvas2d/CanvasRenderingContext2D.h" | 5 #include "modules/canvas2d/CanvasRenderingContext2D.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
10 #include "core/html/HTMLCanvasElement.h" | 10 #include "core/html/HTMLCanvasElement.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 .boundingBoxPerimeterDrawCalls[BaseRenderingContext2D::StrokeText] == | 240 .boundingBoxPerimeterDrawCalls[BaseRenderingContext2D::StrokeText] == |
241 0.0); | 241 0.0); |
242 | 242 |
243 // create gradient | 243 // create gradient |
244 CanvasGradient* gradient; | 244 CanvasGradient* gradient; |
245 gradient = context2d()->createLinearGradient(0, 0, 100, 100); | 245 gradient = context2d()->createLinearGradient(0, 0, 100, 100); |
246 context2d()->setFillStyle( | 246 context2d()->setFillStyle( |
247 StringOrCanvasGradientOrCanvasPattern::fromCanvasGradient(gradient)); | 247 StringOrCanvasGradientOrCanvasPattern::fromCanvasGradient(gradient)); |
248 context2d()->fillRect(10, 10, 100, 20); | 248 context2d()->fillRect(10, 10, 100, 20); |
249 EXPECT_EQ(1, context2d()->getUsage().numLinearGradients); | 249 EXPECT_EQ(1, context2d()->getUsage().numLinearGradients); |
250 EXPECT_NEAR(100 * 20, context2d()->getUsage().boundingBoxAreaFillType | 250 EXPECT_NEAR(100 * 20, |
251 [BaseRenderingContext2D::LinearGradientFillType], | 251 context2d()->getUsage().boundingBoxAreaFillType |
| 252 [BaseRenderingContext2D::LinearGradientFillType], |
252 1.0); | 253 1.0); |
253 | 254 |
254 NonThrowableExceptionState exceptionState; | 255 NonThrowableExceptionState exceptionState; |
255 gradient = context2d()->createRadialGradient(0, 0, 100, 100, 200, 200, | 256 gradient = context2d()->createRadialGradient(0, 0, 100, 100, 200, 200, |
256 exceptionState); | 257 exceptionState); |
257 context2d()->setFillStyle( | 258 context2d()->setFillStyle( |
258 StringOrCanvasGradientOrCanvasPattern::fromCanvasGradient(gradient)); | 259 StringOrCanvasGradientOrCanvasPattern::fromCanvasGradient(gradient)); |
259 context2d()->fillRect(10, 10, 100, 20); | 260 context2d()->fillRect(10, 10, 100, 20); |
260 EXPECT_EQ(1, context2d()->getUsage().numLinearGradients); | 261 EXPECT_EQ(1, context2d()->getUsage().numLinearGradients); |
261 EXPECT_EQ(1, context2d()->getUsage().numRadialGradients); | 262 EXPECT_EQ(1, context2d()->getUsage().numRadialGradients); |
262 EXPECT_NEAR(100 * 20, context2d()->getUsage().boundingBoxAreaFillType | 263 EXPECT_NEAR(100 * 20, |
263 [BaseRenderingContext2D::RadialGradientFillType], | 264 context2d()->getUsage().boundingBoxAreaFillType |
| 265 [BaseRenderingContext2D::RadialGradientFillType], |
264 1.0); | 266 1.0); |
265 | 267 |
266 // create pattern | 268 // create pattern |
267 NonThrowableExceptionState exceptionState2; | 269 NonThrowableExceptionState exceptionState2; |
268 CanvasPattern* canvasPattern = context2d()->createPattern( | 270 CanvasPattern* canvasPattern = context2d()->createPattern( |
269 getScriptState(), &m_opaqueBitmap, "repeat-x", exceptionState2); | 271 getScriptState(), &m_opaqueBitmap, "repeat-x", exceptionState2); |
270 StringOrCanvasGradientOrCanvasPattern pattern = | 272 StringOrCanvasGradientOrCanvasPattern pattern = |
271 StringOrCanvasGradientOrCanvasPattern::fromCanvasPattern(canvasPattern); | 273 StringOrCanvasGradientOrCanvasPattern::fromCanvasPattern(canvasPattern); |
272 context2d()->setFillStyle(pattern); | 274 context2d()->setFillStyle(pattern); |
273 context2d()->fillRect(10, 10, 200, 100); | 275 context2d()->fillRect(10, 10, 200, 100); |
(...skipping 11 matching lines...) Expand all Loading... |
285 numReps * 2 + 1, | 287 numReps * 2 + 1, |
286 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::FillPath]); | 288 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::FillPath]); |
287 | 289 |
288 EXPECT_EQ( | 290 EXPECT_EQ( |
289 0, | 291 0, |
290 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::StrokePath]); | 292 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::StrokePath]); |
291 EXPECT_EQ( | 293 EXPECT_EQ( |
292 0, | 294 0, |
293 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::StrokeText]); | 295 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::StrokeText]); |
294 EXPECT_EQ(0, context2d()->getUsage().numPutImageDataCalls); | 296 EXPECT_EQ(0, context2d()->getUsage().numPutImageDataCalls); |
295 EXPECT_EQ(0, context2d() | 297 EXPECT_EQ(0, |
296 ->getUsage() | 298 context2d() |
297 .numDrawCalls[BaseRenderingContext2D::DrawVectorImage]); | 299 ->getUsage() |
298 EXPECT_EQ(0, context2d() | 300 .numDrawCalls[BaseRenderingContext2D::DrawVectorImage]); |
299 ->getUsage() | 301 EXPECT_EQ(0, |
300 .numDrawCalls[BaseRenderingContext2D::DrawBitmapImage]); | 302 context2d() |
| 303 ->getUsage() |
| 304 .numDrawCalls[BaseRenderingContext2D::DrawBitmapImage]); |
301 EXPECT_EQ(0, context2d()->getUsage().numGetImageDataCalls); | 305 EXPECT_EQ(0, context2d()->getUsage().numGetImageDataCalls); |
302 } | 306 } |
303 | 307 |
304 TEST_F(CanvasRenderingContextUsageTrackingTest, StrokeTracking) { | 308 TEST_F(CanvasRenderingContextUsageTrackingTest, StrokeTracking) { |
305 createContext(NonOpaque); | 309 createContext(NonOpaque); |
306 | 310 |
307 int numReps = 100; | 311 int numReps = 100; |
308 for (int i = 0; i < numReps; i++) { | 312 for (int i = 0; i < numReps; i++) { |
309 context2d()->strokeRect(10, 10, 100, 100); | 313 context2d()->strokeRect(10, 10, 100, 100); |
310 | 314 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 .boundingBoxPerimeterDrawCalls[BaseRenderingContext2D::StrokePath], | 359 .boundingBoxPerimeterDrawCalls[BaseRenderingContext2D::StrokePath], |
356 1.0); | 360 1.0); |
357 | 361 |
358 // create gradient | 362 // create gradient |
359 CanvasGradient* gradient; | 363 CanvasGradient* gradient; |
360 gradient = context2d()->createLinearGradient(0, 0, 100, 100); | 364 gradient = context2d()->createLinearGradient(0, 0, 100, 100); |
361 context2d()->setStrokeStyle( | 365 context2d()->setStrokeStyle( |
362 StringOrCanvasGradientOrCanvasPattern::fromCanvasGradient(gradient)); | 366 StringOrCanvasGradientOrCanvasPattern::fromCanvasGradient(gradient)); |
363 context2d()->strokeRect(10, 10, 100, 100); | 367 context2d()->strokeRect(10, 10, 100, 100); |
364 EXPECT_EQ(1, context2d()->getUsage().numLinearGradients); | 368 EXPECT_EQ(1, context2d()->getUsage().numLinearGradients); |
365 EXPECT_NEAR(100 * 100, context2d()->getUsage().boundingBoxAreaFillType | 369 EXPECT_NEAR(100 * 100, |
366 [BaseRenderingContext2D::LinearGradientFillType], | 370 context2d()->getUsage().boundingBoxAreaFillType |
| 371 [BaseRenderingContext2D::LinearGradientFillType], |
367 1.0); | 372 1.0); |
368 | 373 |
369 // create pattern | 374 // create pattern |
370 NonThrowableExceptionState exceptionState; | 375 NonThrowableExceptionState exceptionState; |
371 CanvasPattern* canvasPattern = context2d()->createPattern( | 376 CanvasPattern* canvasPattern = context2d()->createPattern( |
372 getScriptState(), &m_opaqueBitmap, "repeat-x", exceptionState); | 377 getScriptState(), &m_opaqueBitmap, "repeat-x", exceptionState); |
373 StringOrCanvasGradientOrCanvasPattern pattern = | 378 StringOrCanvasGradientOrCanvasPattern pattern = |
374 StringOrCanvasGradientOrCanvasPattern::fromCanvasPattern(canvasPattern); | 379 StringOrCanvasGradientOrCanvasPattern::fromCanvasPattern(canvasPattern); |
375 context2d()->setStrokeStyle(pattern); | 380 context2d()->setStrokeStyle(pattern); |
376 context2d()->strokeRect(10, 10, 100, 100); | 381 context2d()->strokeRect(10, 10, 100, 100); |
(...skipping 11 matching lines...) Expand all Loading... |
388 numReps + 1, | 393 numReps + 1, |
389 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::StrokePath]); | 394 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::StrokePath]); |
390 EXPECT_EQ( | 395 EXPECT_EQ( |
391 0, | 396 0, |
392 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::FillPath]); | 397 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::FillPath]); |
393 EXPECT_EQ(0, context2d()->getUsage().numNonConvexFillPathCalls); | 398 EXPECT_EQ(0, context2d()->getUsage().numNonConvexFillPathCalls); |
394 EXPECT_EQ( | 399 EXPECT_EQ( |
395 0, | 400 0, |
396 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::FillText]); | 401 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::FillText]); |
397 EXPECT_EQ(0, context2d()->getUsage().numPutImageDataCalls); | 402 EXPECT_EQ(0, context2d()->getUsage().numPutImageDataCalls); |
398 EXPECT_EQ(0, context2d() | 403 EXPECT_EQ(0, |
399 ->getUsage() | 404 context2d() |
400 .numDrawCalls[BaseRenderingContext2D::DrawVectorImage]); | 405 ->getUsage() |
401 EXPECT_EQ(0, context2d() | 406 .numDrawCalls[BaseRenderingContext2D::DrawVectorImage]); |
402 ->getUsage() | 407 EXPECT_EQ(0, |
403 .numDrawCalls[BaseRenderingContext2D::DrawBitmapImage]); | 408 context2d() |
| 409 ->getUsage() |
| 410 .numDrawCalls[BaseRenderingContext2D::DrawBitmapImage]); |
404 EXPECT_EQ(0, context2d()->getUsage().numGetImageDataCalls); | 411 EXPECT_EQ(0, context2d()->getUsage().numGetImageDataCalls); |
405 } | 412 } |
406 | 413 |
407 TEST_F(CanvasRenderingContextUsageTrackingTest, ImageTracking) { | 414 TEST_F(CanvasRenderingContextUsageTrackingTest, ImageTracking) { |
408 // Testing draw, put, get and filters | 415 // Testing draw, put, get and filters |
409 createContext(NonOpaque); | 416 createContext(NonOpaque); |
410 NonThrowableExceptionState exceptionState; | 417 NonThrowableExceptionState exceptionState; |
411 | 418 |
412 int numReps = 5; | 419 int numReps = 5; |
413 int imgWidth = 100; | 420 int imgWidth = 100; |
(...skipping 15 matching lines...) Expand all Loading... |
429 context2d()->getUsage().boundingBoxPerimeterDrawCalls | 436 context2d()->getUsage().boundingBoxPerimeterDrawCalls |
430 [BaseRenderingContext2D::DrawBitmapImage], | 437 [BaseRenderingContext2D::DrawBitmapImage], |
431 0.1); | 438 0.1); |
432 | 439 |
433 EXPECT_NEAR( | 440 EXPECT_NEAR( |
434 0.0, | 441 0.0, |
435 context2d() | 442 context2d() |
436 ->getUsage() | 443 ->getUsage() |
437 .boundingBoxAreaDrawCalls[BaseRenderingContext2D::DrawVectorImage], | 444 .boundingBoxAreaDrawCalls[BaseRenderingContext2D::DrawVectorImage], |
438 0.1); | 445 0.1); |
439 EXPECT_NEAR(0.0, context2d()->getUsage().boundingBoxPerimeterDrawCalls | 446 EXPECT_NEAR(0.0, |
440 [BaseRenderingContext2D::DrawVectorImage], | 447 context2d()->getUsage().boundingBoxPerimeterDrawCalls |
| 448 [BaseRenderingContext2D::DrawVectorImage], |
441 0.1); | 449 0.1); |
442 | 450 |
443 context2d()->setFilter("blur(5px)"); | 451 context2d()->setFilter("blur(5px)"); |
444 context2d()->drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 1, 1, 0, 0, | 452 context2d()->drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 1, 1, 0, 0, |
445 10, 10, exceptionState); | 453 10, 10, exceptionState); |
446 | 454 |
447 EXPECT_EQ(numReps, context2d()->getUsage().numPutImageDataCalls); | 455 EXPECT_EQ(numReps, context2d()->getUsage().numPutImageDataCalls); |
448 EXPECT_NE(0, context2d()->getUsage().areaPutImageDataCalls); | 456 EXPECT_NE(0, context2d()->getUsage().areaPutImageDataCalls); |
449 EXPECT_NEAR(numReps * m_fullImageData.get()->width() * | 457 EXPECT_NEAR(numReps * m_fullImageData.get()->width() * |
450 m_fullImageData.get()->height(), | 458 m_fullImageData.get()->height(), |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 for (int i = 0; i < numReps; i++) { | 678 for (int i = 0; i < numReps; i++) { |
671 context2d()->fillRect(10, 10, 100, 100); | 679 context2d()->fillRect(10, 10, 100, 100); |
672 } | 680 } |
673 EXPECT_EQ( | 681 EXPECT_EQ( |
674 numReps, | 682 numReps, |
675 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::FillRect]); | 683 context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::FillRect]); |
676 } | 684 } |
677 | 685 |
678 } // namespace UsageTrackingTests | 686 } // namespace UsageTrackingTests |
679 } // namespace blink | 687 } // namespace blink |
OLD | NEW |