| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "core/html/canvas/CanvasRenderingContext2D.h" | 7 #include "core/html/canvas/CanvasRenderingContext2D.h" |
| 8 | 8 |
| 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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 561 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
| 562 } | 562 } |
| 563 | 563 |
| 564 TEST_F(CanvasRenderingContext2DTest, NoFallbackWithSmallState) | 564 TEST_F(CanvasRenderingContext2DTest, NoFallbackWithSmallState) |
| 565 { | 565 { |
| 566 createContext(NonOpaque); | 566 createContext(NonOpaque); |
| 567 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); | 567 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 568 canvasElement().createImageBufferUsingSurfaceForTesting(surface.release()); | 568 canvasElement().createImageBufferUsingSurfaceForTesting(surface.release()); |
| 569 | 569 |
| 570 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect | 570 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect |
| 571 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingSt
ackDepth - 2; ++i) { | 571 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingSt
ackDepth - 1; ++i) { |
| 572 context2d()->save(); | 572 context2d()->save(); |
| 573 context2d()->translate(1.0f, 0.0f); | 573 context2d()->translate(1.0f, 0.0f); |
| 574 } | 574 } |
| 575 canvasElement().doDeferredPaintInvalidation(); // To close the current frame | 575 canvasElement().doDeferredPaintInvalidation(); // To close the current frame |
| 576 } | 576 } |
| 577 | 577 |
| 578 TEST_F(CanvasRenderingContext2DTest, FallbackWithLargeState) | 578 TEST_F(CanvasRenderingContext2DTest, FallbackWithLargeState) |
| 579 { | 579 { |
| 580 createContext(NonOpaque); | 580 createContext(NonOpaque); |
| 581 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tFallback), NonOpaque)); | 581 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tFallback), NonOpaque)); |
| 582 canvasElement().createImageBufferUsingSurfaceForTesting(surface.release()); | 582 canvasElement().createImageBufferUsingSurfaceForTesting(surface.release()); |
| 583 | 583 |
| 584 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect | 584 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect |
| 585 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingSt
ackDepth - 1; ++i) { | 585 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingSt
ackDepth; ++i) { |
| 586 context2d()->save(); | 586 context2d()->save(); |
| 587 context2d()->translate(1.0f, 0.0f); | 587 context2d()->translate(1.0f, 0.0f); |
| 588 } | 588 } |
| 589 canvasElement().doDeferredPaintInvalidation(); // To close the current frame | 589 canvasElement().doDeferredPaintInvalidation(); // To close the current frame |
| 590 } | 590 } |
| 591 | 591 |
| 592 TEST_F(CanvasRenderingContext2DTest, CanvasObserver) | 592 TEST_F(CanvasRenderingContext2DTest, CanvasObserver) |
| 593 { | 593 { |
| 594 createContext(NonOpaque); | 594 createContext(NonOpaque); |
| 595 OwnPtrWillBeRawPtr<MockCanvasObserver> observer = MockCanvasObserver::create
(); | 595 OwnPtrWillBeRawPtr<MockCanvasObserver> observer = MockCanvasObserver::create
(); |
| 596 canvasElement().addObserver(observer.get()); | 596 canvasElement().addObserver(observer.get()); |
| 597 | 597 |
| 598 // The canvasChanged notification must be immediate, and not deferred until
paint time | 598 // The canvasChanged notification must be immediate, and not deferred until
paint time |
| 599 // because offscreen canvases, which are not painted, also need to emit noti
fications. | 599 // because offscreen canvases, which are not painted, also need to emit noti
fications. |
| 600 EXPECT_CALL(*observer, canvasChanged(&canvasElement(), FloatRect(0, 0, 1, 1)
)).Times(1); | 600 EXPECT_CALL(*observer, canvasChanged(&canvasElement(), FloatRect(0, 0, 1, 1)
)).Times(1); |
| 601 context2d()->fillRect(0, 0, 1, 1); | 601 context2d()->fillRect(0, 0, 1, 1); |
| 602 Mock::VerifyAndClearExpectations(observer.get()); | 602 Mock::VerifyAndClearExpectations(observer.get()); |
| 603 | 603 |
| 604 canvasElement().removeObserver(observer.get()); | 604 canvasElement().removeObserver(observer.get()); |
| 605 } | 605 } |
| 606 | 606 |
| 607 } // unnamed namespace | 607 } // unnamed namespace |
| OLD | NEW |