OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <memory> | 7 #include <memory> |
8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 }; | 355 }; |
356 | 356 |
357 //============================================================================ | 357 //============================================================================ |
358 | 358 |
359 TEST_F(CanvasRenderingContext2DTest, detectOverdrawWithFillRect) { | 359 TEST_F(CanvasRenderingContext2DTest, detectOverdrawWithFillRect) { |
360 createContext(NonOpaque); | 360 createContext(NonOpaque); |
361 | 361 |
362 TEST_OVERDRAW_1(1, fillRect(-1, -1, 12, 12)); | 362 TEST_OVERDRAW_1(1, fillRect(-1, -1, 12, 12)); |
363 TEST_OVERDRAW_1(1, fillRect(0, 0, 10, 10)); | 363 TEST_OVERDRAW_1(1, fillRect(0, 0, 10, 10)); |
364 TEST_OVERDRAW_1( | 364 TEST_OVERDRAW_1( |
365 0, strokeRect(0, 0, 10, | 365 0, |
366 10)); // stroking instead of filling does not overwrite | 366 strokeRect(0, 0, 10, |
| 367 10)); // stroking instead of filling does not overwrite |
367 TEST_OVERDRAW_2(0, setGlobalAlpha(0.5f), fillRect(0, 0, 10, 10)); | 368 TEST_OVERDRAW_2(0, setGlobalAlpha(0.5f), fillRect(0, 0, 10, 10)); |
368 TEST_OVERDRAW_1(0, fillRect(0, 0, 9, 9)); | 369 TEST_OVERDRAW_1(0, fillRect(0, 0, 9, 9)); |
369 TEST_OVERDRAW_2(0, translate(1, 1), fillRect(0, 0, 10, 10)); | 370 TEST_OVERDRAW_2(0, translate(1, 1), fillRect(0, 0, 10, 10)); |
370 TEST_OVERDRAW_2(1, translate(1, 1), fillRect(-1, -1, 10, 10)); | 371 TEST_OVERDRAW_2(1, translate(1, 1), fillRect(-1, -1, 10, 10)); |
371 TEST_OVERDRAW_2(1, setFillStyle(opaqueGradient()), fillRect(0, 0, 10, 10)); | 372 TEST_OVERDRAW_2(1, setFillStyle(opaqueGradient()), fillRect(0, 0, 10, 10)); |
372 TEST_OVERDRAW_2(0, setFillStyle(alphaGradient()), fillRect(0, 0, 10, 10)); | 373 TEST_OVERDRAW_2(0, setFillStyle(alphaGradient()), fillRect(0, 0, 10, 10)); |
373 TEST_OVERDRAW_3(0, setGlobalAlpha(0.5), setFillStyle(opaqueGradient()), | 374 TEST_OVERDRAW_3(0, setGlobalAlpha(0.5), setFillStyle(opaqueGradient()), |
374 fillRect(0, 0, 10, 10)); | 375 fillRect(0, 0, 10, 10)); |
375 TEST_OVERDRAW_3(1, setGlobalAlpha(0.5f), | 376 TEST_OVERDRAW_3(1, setGlobalAlpha(0.5f), |
376 setGlobalCompositeOperation(String("copy")), | 377 setGlobalCompositeOperation(String("copy")), |
(...skipping 17 matching lines...) Expand all Loading... |
394 TEST_OVERDRAW_2(1, translate(1, 1), clearRect(-1, -1, 10, 10)); | 395 TEST_OVERDRAW_2(1, translate(1, 1), clearRect(-1, -1, 10, 10)); |
395 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("destination-in")), | 396 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("destination-in")), |
396 clearRect(0, 0, 10, 10)); // composite op ignored | 397 clearRect(0, 0, 10, 10)); // composite op ignored |
397 TEST_OVERDRAW_3(0, rect(0, 0, 5, 5), clip(), clearRect(0, 0, 10, 10)); | 398 TEST_OVERDRAW_3(0, rect(0, 0, 5, 5), clip(), clearRect(0, 0, 10, 10)); |
398 } | 399 } |
399 | 400 |
400 TEST_F(CanvasRenderingContext2DTest, detectOverdrawWithDrawImage) { | 401 TEST_F(CanvasRenderingContext2DTest, detectOverdrawWithDrawImage) { |
401 createContext(NonOpaque); | 402 createContext(NonOpaque); |
402 NonThrowableExceptionState exceptionState; | 403 NonThrowableExceptionState exceptionState; |
403 | 404 |
404 TEST_OVERDRAW_1(1, drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, | 405 TEST_OVERDRAW_1(1, |
405 0, 0, 10, 10, exceptionState)); | 406 drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, 0, |
| 407 0, 10, 10, exceptionState)); |
406 EXPECT_FALSE(exceptionState.hadException()); | 408 EXPECT_FALSE(exceptionState.hadException()); |
407 TEST_OVERDRAW_1(1, drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 1, 1, 0, | 409 TEST_OVERDRAW_1(1, |
408 0, 10, 10, exceptionState)); | 410 drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 1, 1, 0, 0, |
| 411 10, 10, exceptionState)); |
409 EXPECT_FALSE(exceptionState.hadException()); | 412 EXPECT_FALSE(exceptionState.hadException()); |
410 TEST_OVERDRAW_2(0, setGlobalAlpha(0.5f), | 413 TEST_OVERDRAW_2(0, setGlobalAlpha(0.5f), |
411 drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, 0, | 414 drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, 0, |
412 0, 10, 10, exceptionState)); | 415 0, 10, 10, exceptionState)); |
413 EXPECT_FALSE(exceptionState.hadException()); | 416 EXPECT_FALSE(exceptionState.hadException()); |
414 TEST_OVERDRAW_1(0, drawImage(getScriptState(), &m_alphaBitmap, 0, 0, 10, 10, | 417 TEST_OVERDRAW_1(0, |
415 0, 0, 10, 10, exceptionState)); | 418 drawImage(getScriptState(), &m_alphaBitmap, 0, 0, 10, 10, 0, |
| 419 0, 10, 10, exceptionState)); |
416 EXPECT_FALSE(exceptionState.hadException()); | 420 EXPECT_FALSE(exceptionState.hadException()); |
417 TEST_OVERDRAW_2(0, setGlobalAlpha(0.5f), | 421 TEST_OVERDRAW_2(0, setGlobalAlpha(0.5f), |
418 drawImage(getScriptState(), &m_alphaBitmap, 0, 0, 10, 10, 0, | 422 drawImage(getScriptState(), &m_alphaBitmap, 0, 0, 10, 10, 0, |
419 0, 10, 10, exceptionState)); | 423 0, 10, 10, exceptionState)); |
420 EXPECT_FALSE(exceptionState.hadException()); | 424 EXPECT_FALSE(exceptionState.hadException()); |
421 TEST_OVERDRAW_1(0, drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, | 425 TEST_OVERDRAW_1(0, |
422 1, 0, 10, 10, exceptionState)); | 426 drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, 1, |
| 427 0, 10, 10, exceptionState)); |
423 EXPECT_FALSE(exceptionState.hadException()); | 428 EXPECT_FALSE(exceptionState.hadException()); |
424 TEST_OVERDRAW_1(0, drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, | 429 TEST_OVERDRAW_1(0, |
425 0, 0, 9, 9, exceptionState)); | 430 drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, 0, |
| 431 0, 9, 9, exceptionState)); |
426 EXPECT_FALSE(exceptionState.hadException()); | 432 EXPECT_FALSE(exceptionState.hadException()); |
427 TEST_OVERDRAW_1(1, drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, | 433 TEST_OVERDRAW_1(1, |
428 0, 0, 11, 11, exceptionState)); | 434 drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, 0, |
| 435 0, 11, 11, exceptionState)); |
429 EXPECT_FALSE(exceptionState.hadException()); | 436 EXPECT_FALSE(exceptionState.hadException()); |
430 TEST_OVERDRAW_2(1, translate(-1, 0), | 437 TEST_OVERDRAW_2(1, translate(-1, 0), |
431 drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, 1, | 438 drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, 1, |
432 0, 10, 10, exceptionState)); | 439 0, 10, 10, exceptionState)); |
433 EXPECT_FALSE(exceptionState.hadException()); | 440 EXPECT_FALSE(exceptionState.hadException()); |
434 TEST_OVERDRAW_2(0, translate(-1, 0), | 441 TEST_OVERDRAW_2(0, translate(-1, 0), |
435 drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, 0, | 442 drawImage(getScriptState(), &m_opaqueBitmap, 0, 0, 10, 10, 0, |
436 0, 10, 10, exceptionState)); | 443 0, 10, 10, exceptionState)); |
437 EXPECT_FALSE(exceptionState.hadException()); | 444 EXPECT_FALSE(exceptionState.hadException()); |
438 TEST_OVERDRAW_2( | 445 TEST_OVERDRAW_2( |
(...skipping 16 matching lines...) Expand all Loading... |
455 EXPECT_FALSE(exceptionState.hadException()); | 462 EXPECT_FALSE(exceptionState.hadException()); |
456 } | 463 } |
457 | 464 |
458 TEST_F(CanvasRenderingContext2DTest, detectOverdrawWithPutImageData) { | 465 TEST_F(CanvasRenderingContext2DTest, detectOverdrawWithPutImageData) { |
459 createContext(NonOpaque); | 466 createContext(NonOpaque); |
460 NonThrowableExceptionState exceptionState; | 467 NonThrowableExceptionState exceptionState; |
461 | 468 |
462 // Test putImageData | 469 // Test putImageData |
463 TEST_OVERDRAW_1(1, putImageData(m_fullImageData.get(), 0, 0, exceptionState)); | 470 TEST_OVERDRAW_1(1, putImageData(m_fullImageData.get(), 0, 0, exceptionState)); |
464 EXPECT_FALSE(exceptionState.hadException()); | 471 EXPECT_FALSE(exceptionState.hadException()); |
465 TEST_OVERDRAW_1(1, putImageData(m_fullImageData.get(), 0, 0, 0, 0, 10, 10, | 472 TEST_OVERDRAW_1( |
466 exceptionState)); | 473 1, |
| 474 putImageData(m_fullImageData.get(), 0, 0, 0, 0, 10, 10, exceptionState)); |
467 EXPECT_FALSE(exceptionState.hadException()); | 475 EXPECT_FALSE(exceptionState.hadException()); |
468 TEST_OVERDRAW_1( | 476 TEST_OVERDRAW_1( |
469 0, putImageData(m_fullImageData.get(), 0, 0, 1, 1, 8, 8, exceptionState)); | 477 0, putImageData(m_fullImageData.get(), 0, 0, 1, 1, 8, 8, exceptionState)); |
470 EXPECT_FALSE(exceptionState.hadException()); | 478 EXPECT_FALSE(exceptionState.hadException()); |
471 TEST_OVERDRAW_2(1, setGlobalAlpha(0.5f), | 479 TEST_OVERDRAW_2(1, setGlobalAlpha(0.5f), |
472 putImageData(m_fullImageData.get(), 0, 0, | 480 putImageData(m_fullImageData.get(), 0, 0, |
473 exceptionState)); // alpha has no effect | 481 exceptionState)); // alpha has no effect |
474 EXPECT_FALSE(exceptionState.hadException()); | 482 EXPECT_FALSE(exceptionState.hadException()); |
475 TEST_OVERDRAW_1(0, | 483 TEST_OVERDRAW_1(0, |
476 putImageData(m_partialImageData.get(), 0, 0, exceptionState)); | 484 putImageData(m_partialImageData.get(), 0, 0, exceptionState)); |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 TestVariantCount = 2, | 1026 TestVariantCount = 2, |
1019 }; | 1027 }; |
1020 | 1028 |
1021 for (int testVariant = 0; testVariant < TestVariantCount; testVariant++) { | 1029 for (int testVariant = 0; testVariant < TestVariantCount; testVariant++) { |
1022 int delta = testVariant == LargeTextureDisablesAcceleration ? 1 : -1; | 1030 int delta = testVariant == LargeTextureDisablesAcceleration ? 1 : -1; |
1023 int srcSize = | 1031 int srcSize = |
1024 std::sqrt(static_cast<float>(ExpensiveCanvasHeuristicParameters:: | 1032 std::sqrt(static_cast<float>(ExpensiveCanvasHeuristicParameters:: |
1025 DrawImageTextureUploadSoftSizeLimit)) + | 1033 DrawImageTextureUploadSoftSizeLimit)) + |
1026 delta; | 1034 delta; |
1027 int dstSize = | 1035 int dstSize = |
1028 srcSize / std::sqrt(static_cast<float>( | 1036 srcSize / |
1029 ExpensiveCanvasHeuristicParameters:: | 1037 std::sqrt(static_cast<float>( |
1030 DrawImageTextureUploadSoftSizeLimitScaleThreshold)) - | 1038 ExpensiveCanvasHeuristicParameters:: |
| 1039 DrawImageTextureUploadSoftSizeLimitScaleThreshold)) - |
1031 delta; | 1040 delta; |
1032 | 1041 |
1033 createContext(NonOpaque); | 1042 createContext(NonOpaque); |
1034 FakeGLES2Interface gl; | 1043 FakeGLES2Interface gl; |
1035 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider( | 1044 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider( |
1036 new FakeWebGraphicsContext3DProvider(&gl)); | 1045 new FakeWebGraphicsContext3DProvider(&gl)); |
1037 IntSize size(dstSize, dstSize); | 1046 IntSize size(dstSize, dstSize); |
1038 RefPtr<Canvas2DLayerBridge> bridge = | 1047 RefPtr<Canvas2DLayerBridge> bridge = |
1039 makeBridge(std::move(contextProvider), size, | 1048 makeBridge(std::move(contextProvider), size, |
1040 Canvas2DLayerBridge::EnableAcceleration); | 1049 Canvas2DLayerBridge::EnableAcceleration); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1351 | 1360 |
1352 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled( | 1361 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled( |
1353 experimentalCanvasFeaturesRuntimeFlag); | 1362 experimentalCanvasFeaturesRuntimeFlag); |
1354 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled( | 1363 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled( |
1355 colorCorrectRenderingRuntimeFlag); | 1364 colorCorrectRenderingRuntimeFlag); |
1356 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled( | 1365 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled( |
1357 colorCorrectRenderingDefaultModeRuntimeFlag); | 1366 colorCorrectRenderingDefaultModeRuntimeFlag); |
1358 } | 1367 } |
1359 | 1368 |
1360 } // namespace blink | 1369 } // namespace blink |
OLD | NEW |