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 "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/fetch/MemoryCache.h" | 8 #include "core/fetch/MemoryCache.h" |
9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
10 #include "core/frame/ImageBitmap.h" | 10 #include "core/frame/ImageBitmap.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 return true; | 247 return true; |
248 } // otherwise overwrites are not tracked | 248 } // otherwise overwrites are not tracked |
249 | 249 |
250 MOCK_METHOD0(willOverwriteCanvas, void()); | 250 MOCK_METHOD0(willOverwriteCanvas, void()); |
251 }; | 251 }; |
252 | 252 |
253 //============================================================================ | 253 //============================================================================ |
254 | 254 |
255 #define TEST_OVERDRAW_SETUP(EXPECTED_OVERDRAWS) \ | 255 #define TEST_OVERDRAW_SETUP(EXPECTED_OVERDRAWS) \ |
256 std::unique_ptr<MockImageBufferSurfaceForOverwriteTesting> mockSurface = \ | 256 std::unique_ptr<MockImageBufferSurfaceForOverwriteTesting> mockSurface = \ |
257 wrapUnique(new MockImageBufferSurfaceForOverwriteTesting( \ | 257 WTF::wrapUnique(new MockImageBufferSurfaceForOverwriteTesting( \ |
258 IntSize(10, 10), NonOpaque)); \ | 258 IntSize(10, 10), NonOpaque)); \ |
259 MockImageBufferSurfaceForOverwriteTesting* surfacePtr = mockSurface.get(); \ | 259 MockImageBufferSurfaceForOverwriteTesting* surfacePtr = mockSurface.get(); \ |
260 canvasElement().createImageBufferUsingSurfaceForTesting( \ | 260 canvasElement().createImageBufferUsingSurfaceForTesting( \ |
261 std::move(mockSurface)); \ | 261 std::move(mockSurface)); \ |
262 EXPECT_CALL(*surfacePtr, willOverwriteCanvas()).Times(EXPECTED_OVERDRAWS); \ | 262 EXPECT_CALL(*surfacePtr, willOverwriteCanvas()).Times(EXPECTED_OVERDRAWS); \ |
263 context2d()->save(); | 263 context2d()->save(); |
264 | 264 |
265 #define TEST_OVERDRAW_FINALIZE \ | 265 #define TEST_OVERDRAW_FINALIZE \ |
266 context2d()->restore(); \ | 266 context2d()->restore(); \ |
267 Mock::VerifyAndClearExpectations(surfacePtr); | 267 Mock::VerifyAndClearExpectations(surfacePtr); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 TEST_OVERDRAW_FINALIZE \ | 300 TEST_OVERDRAW_FINALIZE \ |
301 } while (0) | 301 } while (0) |
302 | 302 |
303 //============================================================================ | 303 //============================================================================ |
304 | 304 |
305 class MockSurfaceFactory : public RecordingImageBufferFallbackSurfaceFactory { | 305 class MockSurfaceFactory : public RecordingImageBufferFallbackSurfaceFactory { |
306 public: | 306 public: |
307 enum FallbackExpectation { ExpectFallback, ExpectNoFallback }; | 307 enum FallbackExpectation { ExpectFallback, ExpectNoFallback }; |
308 static std::unique_ptr<MockSurfaceFactory> create( | 308 static std::unique_ptr<MockSurfaceFactory> create( |
309 FallbackExpectation expectation) { | 309 FallbackExpectation expectation) { |
310 return wrapUnique(new MockSurfaceFactory(expectation)); | 310 return WTF::wrapUnique(new MockSurfaceFactory(expectation)); |
311 } | 311 } |
312 | 312 |
313 std::unique_ptr<ImageBufferSurface> createSurface( | 313 std::unique_ptr<ImageBufferSurface> createSurface( |
314 const IntSize& size, | 314 const IntSize& size, |
315 OpacityMode mode, | 315 OpacityMode mode, |
316 sk_sp<SkColorSpace> colorSpace, | 316 sk_sp<SkColorSpace> colorSpace, |
317 SkColorType colorType) override { | 317 SkColorType colorType) override { |
318 EXPECT_EQ(ExpectFallback, m_expectation); | 318 EXPECT_EQ(ExpectFallback, m_expectation); |
319 m_didFallback = true; | 319 m_didFallback = true; |
320 return wrapUnique(new UnacceleratedImageBufferSurface( | 320 return WTF::wrapUnique(new UnacceleratedImageBufferSurface( |
321 size, mode, InitializeImagePixels, colorSpace, colorType)); | 321 size, mode, InitializeImagePixels, colorSpace, colorType)); |
322 } | 322 } |
323 | 323 |
324 ~MockSurfaceFactory() override { | 324 ~MockSurfaceFactory() override { |
325 if (m_expectation == ExpectFallback) { | 325 if (m_expectation == ExpectFallback) { |
326 EXPECT_TRUE(m_didFallback); | 326 EXPECT_TRUE(m_didFallback); |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 private: | 330 private: |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 fillRect(0, 0, 5, 5)); | 516 fillRect(0, 0, 5, 5)); |
517 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-over")), | 517 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-over")), |
518 fillRect(0, 0, 5, 5)); | 518 fillRect(0, 0, 5, 5)); |
519 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), | 519 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), |
520 fillRect(0, 0, 5, 5)); | 520 fillRect(0, 0, 5, 5)); |
521 } | 521 } |
522 | 522 |
523 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionByDefault) { | 523 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionByDefault) { |
524 createContext(NonOpaque); | 524 createContext(NonOpaque); |
525 std::unique_ptr<RecordingImageBufferSurface> surface = | 525 std::unique_ptr<RecordingImageBufferSurface> surface = |
526 wrapUnique(new RecordingImageBufferSurface( | 526 WTF::wrapUnique(new RecordingImageBufferSurface( |
527 IntSize(10, 10), | 527 IntSize(10, 10), |
528 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 528 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
529 NonOpaque, nullptr)); | 529 NonOpaque, nullptr)); |
530 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 530 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
531 | 531 |
532 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 532 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
533 } | 533 } |
534 | 534 |
535 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderOverdrawLimit) { | 535 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderOverdrawLimit) { |
536 createContext(NonOpaque); | 536 createContext(NonOpaque); |
537 std::unique_ptr<RecordingImageBufferSurface> surface = | 537 std::unique_ptr<RecordingImageBufferSurface> surface = |
538 wrapUnique(new RecordingImageBufferSurface( | 538 WTF::wrapUnique(new RecordingImageBufferSurface( |
539 IntSize(10, 10), | 539 IntSize(10, 10), |
540 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 540 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
541 NonOpaque, nullptr)); | 541 NonOpaque, nullptr)); |
542 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 542 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
543 | 543 |
544 context2d()->setGlobalAlpha(0.5f); // To prevent overdraw optimization | 544 context2d()->setGlobalAlpha(0.5f); // To prevent overdraw optimization |
545 for (int i = 0; | 545 for (int i = 0; |
546 i < ExpensiveCanvasHeuristicParameters::ExpensiveOverdrawThreshold - 1; | 546 i < ExpensiveCanvasHeuristicParameters::ExpensiveOverdrawThreshold - 1; |
547 i++) { | 547 i++) { |
548 context2d()->fillRect(0, 0, 10, 10); | 548 context2d()->fillRect(0, 0, 10, 10); |
549 } | 549 } |
550 | 550 |
551 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 551 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
552 } | 552 } |
553 | 553 |
554 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverOverdrawLimit) { | 554 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverOverdrawLimit) { |
555 createContext(NonOpaque); | 555 createContext(NonOpaque); |
556 std::unique_ptr<RecordingImageBufferSurface> surface = | 556 std::unique_ptr<RecordingImageBufferSurface> surface = |
557 wrapUnique(new RecordingImageBufferSurface( | 557 WTF::wrapUnique(new RecordingImageBufferSurface( |
558 IntSize(10, 10), | 558 IntSize(10, 10), |
559 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 559 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
560 NonOpaque, nullptr)); | 560 NonOpaque, nullptr)); |
561 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 561 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
562 | 562 |
563 context2d()->setGlobalAlpha(0.5f); // To prevent overdraw optimization | 563 context2d()->setGlobalAlpha(0.5f); // To prevent overdraw optimization |
564 for (int i = 0; | 564 for (int i = 0; |
565 i < ExpensiveCanvasHeuristicParameters::ExpensiveOverdrawThreshold; | 565 i < ExpensiveCanvasHeuristicParameters::ExpensiveOverdrawThreshold; |
566 i++) { | 566 i++) { |
567 context2d()->fillRect(0, 0, 10, 10); | 567 context2d()->fillRect(0, 0, 10, 10); |
568 } | 568 } |
569 | 569 |
570 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 570 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
571 } | 571 } |
572 | 572 |
573 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderImageSizeRatioLimit) { | 573 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderImageSizeRatioLimit) { |
574 createContext(NonOpaque); | 574 createContext(NonOpaque); |
575 std::unique_ptr<RecordingImageBufferSurface> surface = | 575 std::unique_ptr<RecordingImageBufferSurface> surface = |
576 wrapUnique(new RecordingImageBufferSurface( | 576 WTF::wrapUnique(new RecordingImageBufferSurface( |
577 IntSize(10, 10), | 577 IntSize(10, 10), |
578 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 578 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
579 NonOpaque, nullptr)); | 579 NonOpaque, nullptr)); |
580 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 580 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
581 | 581 |
582 NonThrowableExceptionState exceptionState; | 582 NonThrowableExceptionState exceptionState; |
583 Element* sourceCanvasElement = | 583 Element* sourceCanvasElement = |
584 document().createElement("canvas", exceptionState); | 584 document().createElement("canvas", exceptionState); |
585 EXPECT_FALSE(exceptionState.hadException()); | 585 EXPECT_FALSE(exceptionState.hadException()); |
586 HTMLCanvasElement* sourceCanvas = | 586 HTMLCanvasElement* sourceCanvas = |
587 static_cast<HTMLCanvasElement*>(sourceCanvasElement); | 587 static_cast<HTMLCanvasElement*>(sourceCanvasElement); |
588 IntSize sourceSize( | 588 IntSize sourceSize( |
589 10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveImageSizeRatio); | 589 10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveImageSizeRatio); |
590 std::unique_ptr<UnacceleratedImageBufferSurface> sourceSurface = | 590 std::unique_ptr<UnacceleratedImageBufferSurface> sourceSurface = |
591 makeUnique<UnacceleratedImageBufferSurface>(sourceSize, NonOpaque); | 591 WTF::makeUnique<UnacceleratedImageBufferSurface>(sourceSize, NonOpaque); |
592 sourceCanvas->createImageBufferUsingSurfaceForTesting( | 592 sourceCanvas->createImageBufferUsingSurfaceForTesting( |
593 std::move(sourceSurface)); | 593 std::move(sourceSurface)); |
594 | 594 |
595 const ImageBitmapOptions defaultOptions; | 595 const ImageBitmapOptions defaultOptions; |
596 Optional<IntRect> cropRect = IntRect(IntPoint(0, 0), sourceSize); | 596 Optional<IntRect> cropRect = IntRect(IntPoint(0, 0), sourceSize); |
597 // Go through an ImageBitmap to avoid triggering a display list fallback | 597 // Go through an ImageBitmap to avoid triggering a display list fallback |
598 ImageBitmap* sourceImageBitmap = | 598 ImageBitmap* sourceImageBitmap = |
599 ImageBitmap::create(sourceCanvas, cropRect, defaultOptions); | 599 ImageBitmap::create(sourceCanvas, cropRect, defaultOptions); |
600 | 600 |
601 context2d()->drawImage(canvasElement().getExecutionContext(), | 601 context2d()->drawImage(canvasElement().getExecutionContext(), |
602 sourceImageBitmap, 0, 0, 1, 1, 0, 0, 1, 1, | 602 sourceImageBitmap, 0, 0, 1, 1, 0, 0, 1, 1, |
603 exceptionState); | 603 exceptionState); |
604 EXPECT_FALSE(exceptionState.hadException()); | 604 EXPECT_FALSE(exceptionState.hadException()); |
605 | 605 |
606 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 606 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
607 } | 607 } |
608 | 608 |
609 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverImageSizeRatioLimit) { | 609 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverImageSizeRatioLimit) { |
610 createContext(NonOpaque); | 610 createContext(NonOpaque); |
611 std::unique_ptr<RecordingImageBufferSurface> surface = | 611 std::unique_ptr<RecordingImageBufferSurface> surface = |
612 wrapUnique(new RecordingImageBufferSurface( | 612 WTF::wrapUnique(new RecordingImageBufferSurface( |
613 IntSize(10, 10), | 613 IntSize(10, 10), |
614 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 614 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
615 NonOpaque, nullptr)); | 615 NonOpaque, nullptr)); |
616 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 616 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
617 | 617 |
618 NonThrowableExceptionState exceptionState; | 618 NonThrowableExceptionState exceptionState; |
619 Element* sourceCanvasElement = | 619 Element* sourceCanvasElement = |
620 document().createElement("canvas", exceptionState); | 620 document().createElement("canvas", exceptionState); |
621 EXPECT_FALSE(exceptionState.hadException()); | 621 EXPECT_FALSE(exceptionState.hadException()); |
622 HTMLCanvasElement* sourceCanvas = | 622 HTMLCanvasElement* sourceCanvas = |
623 static_cast<HTMLCanvasElement*>(sourceCanvasElement); | 623 static_cast<HTMLCanvasElement*>(sourceCanvasElement); |
624 IntSize sourceSize( | 624 IntSize sourceSize( |
625 10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveImageSizeRatio + 1); | 625 10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveImageSizeRatio + 1); |
626 std::unique_ptr<UnacceleratedImageBufferSurface> sourceSurface = | 626 std::unique_ptr<UnacceleratedImageBufferSurface> sourceSurface = |
627 makeUnique<UnacceleratedImageBufferSurface>(sourceSize, NonOpaque); | 627 WTF::makeUnique<UnacceleratedImageBufferSurface>(sourceSize, NonOpaque); |
628 sourceCanvas->createImageBufferUsingSurfaceForTesting( | 628 sourceCanvas->createImageBufferUsingSurfaceForTesting( |
629 std::move(sourceSurface)); | 629 std::move(sourceSurface)); |
630 | 630 |
631 const ImageBitmapOptions defaultOptions; | 631 const ImageBitmapOptions defaultOptions; |
632 Optional<IntRect> cropRect = IntRect(IntPoint(0, 0), sourceSize); | 632 Optional<IntRect> cropRect = IntRect(IntPoint(0, 0), sourceSize); |
633 // Go through an ImageBitmap to avoid triggering a display list fallback | 633 // Go through an ImageBitmap to avoid triggering a display list fallback |
634 ImageBitmap* sourceImageBitmap = | 634 ImageBitmap* sourceImageBitmap = |
635 ImageBitmap::create(sourceCanvas, cropRect, defaultOptions); | 635 ImageBitmap::create(sourceCanvas, cropRect, defaultOptions); |
636 | 636 |
637 context2d()->drawImage(canvasElement().getExecutionContext(), | 637 context2d()->drawImage(canvasElement().getExecutionContext(), |
638 sourceImageBitmap, 0, 0, 1, 1, 0, 0, 1, 1, | 638 sourceImageBitmap, 0, 0, 1, 1, 0, 0, 1, 1, |
639 exceptionState); | 639 exceptionState); |
640 EXPECT_FALSE(exceptionState.hadException()); | 640 EXPECT_FALSE(exceptionState.hadException()); |
641 | 641 |
642 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 642 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
643 } | 643 } |
644 | 644 |
645 TEST_F(CanvasRenderingContext2DTest, | 645 TEST_F(CanvasRenderingContext2DTest, |
646 NoLayerPromotionUnderExpensivePathPointCount) { | 646 NoLayerPromotionUnderExpensivePathPointCount) { |
647 createContext(NonOpaque); | 647 createContext(NonOpaque); |
648 std::unique_ptr<RecordingImageBufferSurface> surface = | 648 std::unique_ptr<RecordingImageBufferSurface> surface = |
649 wrapUnique(new RecordingImageBufferSurface( | 649 WTF::wrapUnique(new RecordingImageBufferSurface( |
650 IntSize(10, 10), | 650 IntSize(10, 10), |
651 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 651 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
652 NonOpaque, nullptr)); | 652 NonOpaque, nullptr)); |
653 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 653 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
654 | 654 |
655 context2d()->beginPath(); | 655 context2d()->beginPath(); |
656 context2d()->moveTo(7, 5); | 656 context2d()->moveTo(7, 5); |
657 for (int i = 1; | 657 for (int i = 1; |
658 i < ExpensiveCanvasHeuristicParameters::ExpensivePathPointCount - 1; | 658 i < ExpensiveCanvasHeuristicParameters::ExpensivePathPointCount - 1; |
659 i++) { | 659 i++) { |
660 float angleRad = | 660 float angleRad = |
661 twoPiFloat * i / | 661 twoPiFloat * i / |
662 (ExpensiveCanvasHeuristicParameters::ExpensivePathPointCount - 1); | 662 (ExpensiveCanvasHeuristicParameters::ExpensivePathPointCount - 1); |
663 context2d()->lineTo(5 + 2 * cos(angleRad), 5 + 2 * sin(angleRad)); | 663 context2d()->lineTo(5 + 2 * cos(angleRad), 5 + 2 * sin(angleRad)); |
664 } | 664 } |
665 context2d()->fill(); | 665 context2d()->fill(); |
666 | 666 |
667 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 667 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
668 } | 668 } |
669 | 669 |
670 TEST_F(CanvasRenderingContext2DTest, | 670 TEST_F(CanvasRenderingContext2DTest, |
671 LayerPromotionOverExpensivePathPointCount) { | 671 LayerPromotionOverExpensivePathPointCount) { |
672 createContext(NonOpaque); | 672 createContext(NonOpaque); |
673 std::unique_ptr<RecordingImageBufferSurface> surface = | 673 std::unique_ptr<RecordingImageBufferSurface> surface = |
674 wrapUnique(new RecordingImageBufferSurface( | 674 WTF::wrapUnique(new RecordingImageBufferSurface( |
675 IntSize(10, 10), | 675 IntSize(10, 10), |
676 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 676 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
677 NonOpaque, nullptr)); | 677 NonOpaque, nullptr)); |
678 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 678 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
679 | 679 |
680 context2d()->beginPath(); | 680 context2d()->beginPath(); |
681 context2d()->moveTo(7, 5); | 681 context2d()->moveTo(7, 5); |
682 for (int i = 1; | 682 for (int i = 1; |
683 i < ExpensiveCanvasHeuristicParameters::ExpensivePathPointCount + 1; | 683 i < ExpensiveCanvasHeuristicParameters::ExpensivePathPointCount + 1; |
684 i++) { | 684 i++) { |
685 float angleRad = | 685 float angleRad = |
686 twoPiFloat * i / | 686 twoPiFloat * i / |
687 (ExpensiveCanvasHeuristicParameters::ExpensivePathPointCount + 1); | 687 (ExpensiveCanvasHeuristicParameters::ExpensivePathPointCount + 1); |
688 context2d()->lineTo(5 + 2 * cos(angleRad), 5 + 2 * sin(angleRad)); | 688 context2d()->lineTo(5 + 2 * cos(angleRad), 5 + 2 * sin(angleRad)); |
689 } | 689 } |
690 context2d()->fill(); | 690 context2d()->fill(); |
691 | 691 |
692 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 692 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
693 } | 693 } |
694 | 694 |
695 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWhenPathIsConcave) { | 695 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWhenPathIsConcave) { |
696 createContext(NonOpaque); | 696 createContext(NonOpaque); |
697 std::unique_ptr<RecordingImageBufferSurface> surface = | 697 std::unique_ptr<RecordingImageBufferSurface> surface = |
698 wrapUnique(new RecordingImageBufferSurface( | 698 WTF::wrapUnique(new RecordingImageBufferSurface( |
699 IntSize(10, 10), | 699 IntSize(10, 10), |
700 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 700 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
701 NonOpaque, nullptr)); | 701 NonOpaque, nullptr)); |
702 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 702 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
703 | 703 |
704 context2d()->beginPath(); | 704 context2d()->beginPath(); |
705 context2d()->moveTo(1, 1); | 705 context2d()->moveTo(1, 1); |
706 context2d()->lineTo(5, 5); | 706 context2d()->lineTo(5, 5); |
707 context2d()->lineTo(9, 1); | 707 context2d()->lineTo(9, 1); |
708 context2d()->lineTo(5, 9); | 708 context2d()->lineTo(5, 9); |
709 context2d()->fill(); | 709 context2d()->fill(); |
710 | 710 |
711 if (ExpensiveCanvasHeuristicParameters::ConcavePathsAreExpensive) { | 711 if (ExpensiveCanvasHeuristicParameters::ConcavePathsAreExpensive) { |
712 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 712 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
713 } else { | 713 } else { |
714 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 714 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
715 } | 715 } |
716 } | 716 } |
717 | 717 |
718 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionWithRectangleClip) { | 718 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionWithRectangleClip) { |
719 createContext(NonOpaque); | 719 createContext(NonOpaque); |
720 std::unique_ptr<RecordingImageBufferSurface> surface = | 720 std::unique_ptr<RecordingImageBufferSurface> surface = |
721 wrapUnique(new RecordingImageBufferSurface( | 721 WTF::wrapUnique(new RecordingImageBufferSurface( |
722 IntSize(10, 10), | 722 IntSize(10, 10), |
723 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 723 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
724 NonOpaque, nullptr)); | 724 NonOpaque, nullptr)); |
725 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 725 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
726 | 726 |
727 context2d()->beginPath(); | 727 context2d()->beginPath(); |
728 context2d()->rect(1, 1, 2, 2); | 728 context2d()->rect(1, 1, 2, 2); |
729 context2d()->clip(); | 729 context2d()->clip(); |
730 context2d()->fillRect(0, 0, 4, 4); | 730 context2d()->fillRect(0, 0, 4, 4); |
731 | 731 |
732 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 732 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
733 } | 733 } |
734 | 734 |
735 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWithComplexClip) { | 735 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWithComplexClip) { |
736 createContext(NonOpaque); | 736 createContext(NonOpaque); |
737 std::unique_ptr<RecordingImageBufferSurface> surface = | 737 std::unique_ptr<RecordingImageBufferSurface> surface = |
738 wrapUnique(new RecordingImageBufferSurface( | 738 WTF::wrapUnique(new RecordingImageBufferSurface( |
739 IntSize(10, 10), | 739 IntSize(10, 10), |
740 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 740 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
741 NonOpaque, nullptr)); | 741 NonOpaque, nullptr)); |
742 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 742 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
743 | 743 |
744 context2d()->beginPath(); | 744 context2d()->beginPath(); |
745 context2d()->moveTo(1, 1); | 745 context2d()->moveTo(1, 1); |
746 context2d()->lineTo(5, 5); | 746 context2d()->lineTo(5, 5); |
747 context2d()->lineTo(9, 1); | 747 context2d()->lineTo(9, 1); |
748 context2d()->lineTo(5, 9); | 748 context2d()->lineTo(5, 9); |
749 context2d()->clip(); | 749 context2d()->clip(); |
750 context2d()->fillRect(0, 0, 4, 4); | 750 context2d()->fillRect(0, 0, 4, 4); |
751 | 751 |
752 if (ExpensiveCanvasHeuristicParameters::ComplexClipsAreExpensive) { | 752 if (ExpensiveCanvasHeuristicParameters::ComplexClipsAreExpensive) { |
753 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 753 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
754 } else { | 754 } else { |
755 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 755 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
756 } | 756 } |
757 } | 757 } |
758 | 758 |
759 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWithBlurredShadow) { | 759 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWithBlurredShadow) { |
760 createContext(NonOpaque); | 760 createContext(NonOpaque); |
761 std::unique_ptr<RecordingImageBufferSurface> surface = | 761 std::unique_ptr<RecordingImageBufferSurface> surface = |
762 wrapUnique(new RecordingImageBufferSurface( | 762 WTF::wrapUnique(new RecordingImageBufferSurface( |
763 IntSize(10, 10), | 763 IntSize(10, 10), |
764 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 764 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
765 NonOpaque, nullptr)); | 765 NonOpaque, nullptr)); |
766 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 766 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
767 | 767 |
768 context2d()->setShadowColor(String("red")); | 768 context2d()->setShadowColor(String("red")); |
769 context2d()->setShadowBlur(1.0f); | 769 context2d()->setShadowBlur(1.0f); |
770 context2d()->fillRect(1, 1, 1, 1); | 770 context2d()->fillRect(1, 1, 1, 1); |
771 | 771 |
772 if (ExpensiveCanvasHeuristicParameters::BlurredShadowsAreExpensive) { | 772 if (ExpensiveCanvasHeuristicParameters::BlurredShadowsAreExpensive) { |
773 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 773 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
774 } else { | 774 } else { |
775 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 775 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
776 } | 776 } |
777 } | 777 } |
778 | 778 |
779 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionWithSharpShadow) { | 779 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionWithSharpShadow) { |
780 createContext(NonOpaque); | 780 createContext(NonOpaque); |
781 std::unique_ptr<RecordingImageBufferSurface> surface = | 781 std::unique_ptr<RecordingImageBufferSurface> surface = |
782 wrapUnique(new RecordingImageBufferSurface( | 782 WTF::wrapUnique(new RecordingImageBufferSurface( |
783 IntSize(10, 10), | 783 IntSize(10, 10), |
784 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 784 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
785 NonOpaque, nullptr)); | 785 NonOpaque, nullptr)); |
786 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 786 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
787 | 787 |
788 context2d()->setShadowColor(String("red")); | 788 context2d()->setShadowColor(String("red")); |
789 context2d()->setShadowOffsetX(1.0f); | 789 context2d()->setShadowOffsetX(1.0f); |
790 context2d()->fillRect(1, 1, 1, 1); | 790 context2d()->fillRect(1, 1, 1, 1); |
791 | 791 |
792 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 792 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
793 } | 793 } |
794 | 794 |
795 TEST_F(CanvasRenderingContext2DTest, NoFallbackWithSmallState) { | 795 TEST_F(CanvasRenderingContext2DTest, NoFallbackWithSmallState) { |
796 createContext(NonOpaque); | 796 createContext(NonOpaque); |
797 std::unique_ptr<RecordingImageBufferSurface> surface = | 797 std::unique_ptr<RecordingImageBufferSurface> surface = |
798 wrapUnique(new RecordingImageBufferSurface( | 798 WTF::wrapUnique(new RecordingImageBufferSurface( |
799 IntSize(10, 10), | 799 IntSize(10, 10), |
800 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 800 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
801 NonOpaque, nullptr)); | 801 NonOpaque, nullptr)); |
802 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 802 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
803 | 803 |
804 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect | 804 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect |
805 for (int i = 0; | 805 for (int i = 0; |
806 i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingStackDepth - 1; | 806 i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingStackDepth - 1; |
807 ++i) { | 807 ++i) { |
808 context2d()->save(); | 808 context2d()->save(); |
809 context2d()->translate(1.0f, 0.0f); | 809 context2d()->translate(1.0f, 0.0f); |
810 } | 810 } |
811 canvasElement().doDeferredPaintInvalidation(); // To close the current frame | 811 canvasElement().doDeferredPaintInvalidation(); // To close the current frame |
812 } | 812 } |
813 | 813 |
814 TEST_F(CanvasRenderingContext2DTest, FallbackWithLargeState) { | 814 TEST_F(CanvasRenderingContext2DTest, FallbackWithLargeState) { |
815 createContext(NonOpaque); | 815 createContext(NonOpaque); |
816 std::unique_ptr<RecordingImageBufferSurface> surface = | 816 std::unique_ptr<RecordingImageBufferSurface> surface = |
817 wrapUnique(new RecordingImageBufferSurface( | 817 WTF::wrapUnique(new RecordingImageBufferSurface( |
818 IntSize(10, 10), | 818 IntSize(10, 10), |
819 MockSurfaceFactory::create(MockSurfaceFactory::ExpectFallback), | 819 MockSurfaceFactory::create(MockSurfaceFactory::ExpectFallback), |
820 NonOpaque, nullptr)); | 820 NonOpaque, nullptr)); |
821 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 821 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
822 | 822 |
823 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect | 823 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect |
824 for (int i = 0; | 824 for (int i = 0; |
825 i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingStackDepth; | 825 i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingStackDepth; |
826 ++i) { | 826 ++i) { |
827 context2d()->save(); | 827 context2d()->save(); |
828 context2d()->translate(1.0f, 0.0f); | 828 context2d()->translate(1.0f, 0.0f); |
829 } | 829 } |
830 canvasElement().doDeferredPaintInvalidation(); // To close the current frame | 830 canvasElement().doDeferredPaintInvalidation(); // To close the current frame |
831 } | 831 } |
832 | 832 |
833 TEST_F(CanvasRenderingContext2DTest, OpaqueDisplayListFallsBackForText) { | 833 TEST_F(CanvasRenderingContext2DTest, OpaqueDisplayListFallsBackForText) { |
834 // Verify that drawing text to an opaque canvas, which is expected to | 834 // Verify that drawing text to an opaque canvas, which is expected to |
835 // render with subpixel text anti-aliasing, results in falling out | 835 // render with subpixel text anti-aliasing, results in falling out |
836 // of display list mode because the current diplay list implementation | 836 // of display list mode because the current diplay list implementation |
837 // does not support pixel geometry settings. | 837 // does not support pixel geometry settings. |
838 // See: crbug.com/583809 | 838 // See: crbug.com/583809 |
839 createContext(Opaque); | 839 createContext(Opaque); |
840 std::unique_ptr<RecordingImageBufferSurface> surface = | 840 std::unique_ptr<RecordingImageBufferSurface> surface = |
841 wrapUnique(new RecordingImageBufferSurface( | 841 WTF::wrapUnique(new RecordingImageBufferSurface( |
842 IntSize(10, 10), | 842 IntSize(10, 10), |
843 MockSurfaceFactory::create(MockSurfaceFactory::ExpectFallback), | 843 MockSurfaceFactory::create(MockSurfaceFactory::ExpectFallback), |
844 Opaque, nullptr)); | 844 Opaque, nullptr)); |
845 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 845 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
846 | 846 |
847 context2d()->fillText("Text", 0, 5); | 847 context2d()->fillText("Text", 0, 5); |
848 } | 848 } |
849 | 849 |
850 TEST_F(CanvasRenderingContext2DTest, | 850 TEST_F(CanvasRenderingContext2DTest, |
851 NonOpaqueDisplayListDoesNotFallBackForText) { | 851 NonOpaqueDisplayListDoesNotFallBackForText) { |
852 createContext(NonOpaque); | 852 createContext(NonOpaque); |
853 std::unique_ptr<RecordingImageBufferSurface> surface = | 853 std::unique_ptr<RecordingImageBufferSurface> surface = |
854 wrapUnique(new RecordingImageBufferSurface( | 854 WTF::wrapUnique(new RecordingImageBufferSurface( |
855 IntSize(10, 10), | 855 IntSize(10, 10), |
856 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), | 856 MockSurfaceFactory::create(MockSurfaceFactory::ExpectNoFallback), |
857 NonOpaque, nullptr)); | 857 NonOpaque, nullptr)); |
858 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 858 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
859 | 859 |
860 context2d()->fillText("Text", 0, 5); | 860 context2d()->fillText("Text", 0, 5); |
861 } | 861 } |
862 | 862 |
863 TEST_F(CanvasRenderingContext2DTest, ImageResourceLifetime) { | 863 TEST_F(CanvasRenderingContext2DTest, ImageResourceLifetime) { |
864 NonThrowableExceptionState nonThrowableExceptionState; | 864 NonThrowableExceptionState nonThrowableExceptionState; |
(...skipping 21 matching lines...) Expand all Loading... |
886 imageSource.setImageBitmap(imageBitmapDerived); | 886 imageSource.setImageBitmap(imageBitmapDerived); |
887 context->drawImage(canvas->getExecutionContext(), imageSource, 0, 0, | 887 context->drawImage(canvas->getExecutionContext(), imageSource, 0, 0, |
888 exceptionState); | 888 exceptionState); |
889 } | 889 } |
890 | 890 |
891 TEST_F(CanvasRenderingContext2DTest, GPUMemoryUpdateForAcceleratedCanvas) { | 891 TEST_F(CanvasRenderingContext2DTest, GPUMemoryUpdateForAcceleratedCanvas) { |
892 createContext(NonOpaque); | 892 createContext(NonOpaque); |
893 | 893 |
894 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> | 894 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> |
895 fakeAccelerateSurface = | 895 fakeAccelerateSurface = |
896 wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( | 896 WTF::wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( |
897 IntSize(10, 10), NonOpaque)); | 897 IntSize(10, 10), NonOpaque)); |
898 FakeAcceleratedImageBufferSurfaceForTesting* fakeAccelerateSurfacePtr = | 898 FakeAcceleratedImageBufferSurfaceForTesting* fakeAccelerateSurfacePtr = |
899 fakeAccelerateSurface.get(); | 899 fakeAccelerateSurface.get(); |
900 canvasElement().createImageBufferUsingSurfaceForTesting( | 900 canvasElement().createImageBufferUsingSurfaceForTesting( |
901 std::move(fakeAccelerateSurface)); | 901 std::move(fakeAccelerateSurface)); |
902 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per | 902 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per |
903 // pixel per buffer, and 2 is an estimate of num of gpu buffers required | 903 // pixel per buffer, and 2 is an estimate of num of gpu buffers required |
904 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); | 904 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); |
905 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); | 905 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); |
906 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); | 906 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); |
907 | 907 |
908 // Switching accelerated mode to non-accelerated mode | 908 // Switching accelerated mode to non-accelerated mode |
909 fakeAccelerateSurfacePtr->setIsAccelerated(false); | 909 fakeAccelerateSurfacePtr->setIsAccelerated(false); |
910 canvasElement().buffer()->updateGPUMemoryUsage(); | 910 canvasElement().buffer()->updateGPUMemoryUsage(); |
911 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); | 911 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); |
912 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); | 912 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); |
913 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); | 913 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); |
914 | 914 |
915 // Switching non-accelerated mode to accelerated mode | 915 // Switching non-accelerated mode to accelerated mode |
916 fakeAccelerateSurfacePtr->setIsAccelerated(true); | 916 fakeAccelerateSurfacePtr->setIsAccelerated(true); |
917 canvasElement().buffer()->updateGPUMemoryUsage(); | 917 canvasElement().buffer()->updateGPUMemoryUsage(); |
918 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); | 918 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); |
919 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); | 919 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); |
920 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); | 920 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); |
921 | 921 |
922 // Creating a different accelerated image buffer | 922 // Creating a different accelerated image buffer |
923 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> | 923 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> |
924 fakeAccelerateSurface2 = | 924 fakeAccelerateSurface2 = |
925 wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( | 925 WTF::wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( |
926 IntSize(10, 5), NonOpaque)); | 926 IntSize(10, 5), NonOpaque)); |
927 std::unique_ptr<ImageBuffer> imageBuffer2 = | 927 std::unique_ptr<ImageBuffer> imageBuffer2 = |
928 ImageBuffer::create(std::move(fakeAccelerateSurface2)); | 928 ImageBuffer::create(std::move(fakeAccelerateSurface2)); |
929 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); | 929 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); |
930 EXPECT_EQ(1200, getGlobalGPUMemoryUsage()); | 930 EXPECT_EQ(1200, getGlobalGPUMemoryUsage()); |
931 EXPECT_EQ(2u, getGlobalAcceleratedImageBufferCount()); | 931 EXPECT_EQ(2u, getGlobalAcceleratedImageBufferCount()); |
932 | 932 |
933 // Tear down the first image buffer that resides in current canvas element | 933 // Tear down the first image buffer that resides in current canvas element |
934 canvasElement().setSize(IntSize(20, 20)); | 934 canvasElement().setSize(IntSize(20, 20)); |
935 Mock::VerifyAndClearExpectations(fakeAccelerateSurfacePtr); | 935 Mock::VerifyAndClearExpectations(fakeAccelerateSurfacePtr); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 RuntimeEnabledFeatures::setCanvas2dFixedRenderingModeEnabled( | 1104 RuntimeEnabledFeatures::setCanvas2dFixedRenderingModeEnabled( |
1105 savedFixedRenderingMode); | 1105 savedFixedRenderingMode); |
1106 } | 1106 } |
1107 | 1107 |
1108 TEST_F(CanvasRenderingContext2DTest, | 1108 TEST_F(CanvasRenderingContext2DTest, |
1109 IsAccelerationOptimalForCanvasContentHeuristic) { | 1109 IsAccelerationOptimalForCanvasContentHeuristic) { |
1110 createContext(NonOpaque); | 1110 createContext(NonOpaque); |
1111 | 1111 |
1112 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> | 1112 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> |
1113 fakeAccelerateSurface = | 1113 fakeAccelerateSurface = |
1114 wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( | 1114 WTF::wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( |
1115 IntSize(10, 10), NonOpaque)); | 1115 IntSize(10, 10), NonOpaque)); |
1116 canvasElement().createImageBufferUsingSurfaceForTesting( | 1116 canvasElement().createImageBufferUsingSurfaceForTesting( |
1117 std::move(fakeAccelerateSurface)); | 1117 std::move(fakeAccelerateSurface)); |
1118 | 1118 |
1119 NonThrowableExceptionState exceptionState; | 1119 NonThrowableExceptionState exceptionState; |
1120 | 1120 |
1121 CanvasRenderingContext2D* context = context2d(); | 1121 CanvasRenderingContext2D* context = context2d(); |
1122 EXPECT_TRUE(context->isAccelerationOptimalForCanvasContent()); | 1122 EXPECT_TRUE(context->isAccelerationOptimalForCanvasContent()); |
1123 | 1123 |
1124 context->fillRect(10, 10, 100, 100); | 1124 context->fillRect(10, 10, 100, 100); |
(...skipping 14 matching lines...) Expand all Loading... |
1139 context->strokeText("Text", 10, 10, 1); // faster with no acceleration | 1139 context->strokeText("Text", 10, 10, 1); // faster with no acceleration |
1140 } | 1140 } |
1141 EXPECT_FALSE(context->isAccelerationOptimalForCanvasContent()); | 1141 EXPECT_FALSE(context->isAccelerationOptimalForCanvasContent()); |
1142 } | 1142 } |
1143 | 1143 |
1144 TEST_F(CanvasRenderingContext2DTest, DisableAcceleration) { | 1144 TEST_F(CanvasRenderingContext2DTest, DisableAcceleration) { |
1145 createContext(NonOpaque); | 1145 createContext(NonOpaque); |
1146 | 1146 |
1147 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> | 1147 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> |
1148 fakeAccelerateSurface = | 1148 fakeAccelerateSurface = |
1149 wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( | 1149 WTF::wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( |
1150 IntSize(10, 10), NonOpaque)); | 1150 IntSize(10, 10), NonOpaque)); |
1151 canvasElement().createImageBufferUsingSurfaceForTesting( | 1151 canvasElement().createImageBufferUsingSurfaceForTesting( |
1152 std::move(fakeAccelerateSurface)); | 1152 std::move(fakeAccelerateSurface)); |
1153 CanvasRenderingContext2D* context = context2d(); | 1153 CanvasRenderingContext2D* context = context2d(); |
1154 | 1154 |
1155 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per | 1155 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per |
1156 // pixel per buffer, and 2 is an estimate of num of gpu buffers required | 1156 // pixel per buffer, and 2 is an estimate of num of gpu buffers required |
1157 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); | 1157 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); |
1158 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); | 1158 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); |
1159 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); | 1159 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); |
1160 | 1160 |
1161 context->fillRect(10, 10, 100, 100); | 1161 context->fillRect(10, 10, 100, 100); |
1162 EXPECT_TRUE(canvasElement().buffer()->isAccelerated()); | 1162 EXPECT_TRUE(canvasElement().buffer()->isAccelerated()); |
1163 | 1163 |
1164 canvasElement().buffer()->disableAcceleration(); | 1164 canvasElement().buffer()->disableAcceleration(); |
1165 EXPECT_FALSE(canvasElement().buffer()->isAccelerated()); | 1165 EXPECT_FALSE(canvasElement().buffer()->isAccelerated()); |
1166 | 1166 |
1167 context->fillRect(10, 10, 100, 100); | 1167 context->fillRect(10, 10, 100, 100); |
1168 | 1168 |
1169 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); | 1169 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); |
1170 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); | 1170 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); |
1171 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); | 1171 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); |
1172 } | 1172 } |
1173 | 1173 |
1174 } // namespace blink | 1174 } // namespace blink |
OLD | NEW |