| Index: third_party/WebKit/Source/platform/graphics/RecordingImageBufferSurfaceTest.cpp
|
| diff --git a/third_party/WebKit/Source/platform/graphics/RecordingImageBufferSurfaceTest.cpp b/third_party/WebKit/Source/platform/graphics/RecordingImageBufferSurfaceTest.cpp
|
| index f532ed74d67875cc3174b7e51375523f0e254d9c..7e6e1435156c2429a998d88856cfae9d95d29a3a 100644
|
| --- a/third_party/WebKit/Source/platform/graphics/RecordingImageBufferSurfaceTest.cpp
|
| +++ b/third_party/WebKit/Source/platform/graphics/RecordingImageBufferSurfaceTest.cpp
|
| @@ -25,51 +25,6 @@ using testing::Test;
|
|
|
| namespace blink {
|
|
|
| -class FakeImageBufferClient : public ImageBufferClient,
|
| - public WebThread::TaskObserver {
|
| - public:
|
| - FakeImageBufferClient(ImageBuffer* imageBuffer)
|
| - : m_isDirty(false), m_imageBuffer(imageBuffer), m_frameCount(0) {}
|
| -
|
| - ~FakeImageBufferClient() override {}
|
| -
|
| - // ImageBufferClient implementation
|
| - void notifySurfaceInvalid() override {}
|
| - bool isDirty() override { return m_isDirty; }
|
| - void didDisableAcceleration() override {}
|
| - void didFinalizeFrame() override {
|
| - if (m_isDirty) {
|
| - Platform::current()->currentThread()->removeTaskObserver(this);
|
| - m_isDirty = false;
|
| - }
|
| - ++m_frameCount;
|
| - }
|
| -
|
| - // TaskObserver implementation
|
| - void willProcessTask() override { NOTREACHED(); }
|
| - void didProcessTask() override {
|
| - ASSERT_TRUE(m_isDirty);
|
| - FloatRect dirtyRect(0, 0, 1, 1);
|
| - m_imageBuffer->finalizeFrame(dirtyRect);
|
| - ASSERT_FALSE(m_isDirty);
|
| - }
|
| - void restoreCanvasMatrixClipStack(SkCanvas*) const override {}
|
| -
|
| - void fakeDraw() {
|
| - if (m_isDirty)
|
| - return;
|
| - m_isDirty = true;
|
| - Platform::current()->currentThread()->addTaskObserver(this);
|
| - }
|
| -
|
| - int frameCount() { return m_frameCount; }
|
| -
|
| - private:
|
| - bool m_isDirty;
|
| - ImageBuffer* m_imageBuffer;
|
| - int m_frameCount;
|
| -};
|
| -
|
| class MockSurfaceFactory : public RecordingImageBufferFallbackSurfaceFactory {
|
| public:
|
| MockSurfaceFactory() : m_createSurfaceCount(0) {}
|
| @@ -107,113 +62,13 @@ class RecordingImageBufferSurfaceTest : public Test {
|
| // properly initialized with a GraphicsContext
|
| m_imageBuffer = ImageBuffer::create(std::move(testSurface));
|
| EXPECT_FALSE(!m_imageBuffer);
|
| - m_fakeImageBufferClient =
|
| - WTF::wrapUnique(new FakeImageBufferClient(m_imageBuffer.get()));
|
| - m_imageBuffer->setClient(m_fakeImageBufferClient.get());
|
| - }
|
| -
|
| - public:
|
| - void testEmptyPicture() {
|
| - m_testSurface->initializeCurrentFrame();
|
| - sk_sp<SkPicture> picture = m_testSurface->getPicture();
|
| - EXPECT_TRUE((bool)picture.get());
|
| - EXPECT_EQ(1, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(true);
|
| - }
|
| -
|
| - void testNoFallbackWithClear() {
|
| - m_testSurface->initializeCurrentFrame();
|
| - m_testSurface->willOverwriteCanvas();
|
| - m_testSurface->getPicture();
|
| - EXPECT_EQ(1, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(true);
|
| - }
|
| -
|
| - void testNonAnimatedCanvasUpdate() {
|
| m_testSurface->initializeCurrentFrame();
|
| - // Acquire picture twice to simulate a static canvas: nothing drawn between
|
| - // updates.
|
| - m_fakeImageBufferClient->fakeDraw();
|
| - m_testSurface->getPicture();
|
| - m_testSurface->getPicture();
|
| - EXPECT_EQ(2, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(true);
|
| }
|
|
|
| - void testAnimatedWithoutClear() {
|
| - m_testSurface->initializeCurrentFrame();
|
| - m_fakeImageBufferClient->fakeDraw();
|
| - m_testSurface->getPicture();
|
| - EXPECT_EQ(1, m_fakeImageBufferClient->frameCount());
|
| - EXPECT_EQ(0, m_surfaceFactory->createSurfaceCount());
|
| - expectDisplayListEnabled(true); // first frame has an implicit clear
|
| - m_fakeImageBufferClient->fakeDraw();
|
| - m_testSurface->getPicture();
|
| - EXPECT_EQ(2, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(false);
|
| - }
|
| -
|
| - void testFrameFinalizedByTaskObserver1() {
|
| - m_testSurface->initializeCurrentFrame();
|
| - expectDisplayListEnabled(true);
|
| - m_testSurface->getPicture();
|
| - EXPECT_EQ(1, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(true);
|
| - m_fakeImageBufferClient->fakeDraw();
|
| - EXPECT_EQ(1, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(true);
|
| - m_testSurface->getPicture();
|
| - EXPECT_EQ(2, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(true);
|
| - m_fakeImageBufferClient->fakeDraw();
|
| - EXPECT_EQ(2, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(true);
|
| - // Display list will be disabled only after exiting the runLoop
|
| - }
|
| - void testFrameFinalizedByTaskObserver2() {
|
| - EXPECT_EQ(3, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(false);
|
| - m_testSurface->getPicture();
|
| - EXPECT_EQ(3, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(false);
|
| - m_fakeImageBufferClient->fakeDraw();
|
| - EXPECT_EQ(3, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(false);
|
| - }
|
| -
|
| - void testAnimatedWithClear() {
|
| - m_testSurface->initializeCurrentFrame();
|
| - m_testSurface->getPicture();
|
| - m_testSurface->willOverwriteCanvas();
|
| - m_fakeImageBufferClient->fakeDraw();
|
| - EXPECT_EQ(1, m_fakeImageBufferClient->frameCount());
|
| - m_testSurface->getPicture();
|
| - EXPECT_EQ(2, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(true);
|
| - // clear after use
|
| - m_fakeImageBufferClient->fakeDraw();
|
| - m_testSurface->willOverwriteCanvas();
|
| - EXPECT_EQ(2, m_fakeImageBufferClient->frameCount());
|
| - m_testSurface->getPicture();
|
| - EXPECT_EQ(3, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(true);
|
| - }
|
| -
|
| - void testClearRect() {
|
| - m_testSurface->initializeCurrentFrame();
|
| - m_testSurface->getPicture();
|
| - SkPaint clearPaint;
|
| - clearPaint.setBlendMode(SkBlendMode::kClear);
|
| - m_imageBuffer->canvas()->drawRect(
|
| - SkRect::MakeWH(m_testSurface->size().width(),
|
| - m_testSurface->size().height()),
|
| - clearPaint);
|
| - m_fakeImageBufferClient->fakeDraw();
|
| - EXPECT_EQ(1, m_fakeImageBufferClient->frameCount());
|
| - m_testSurface->getPicture();
|
| - EXPECT_EQ(2, m_fakeImageBufferClient->frameCount());
|
| - expectDisplayListEnabled(true);
|
| - }
|
| + public:
|
| + RecordingImageBufferSurface* testSurface() { return m_testSurface; }
|
| + int createSurfaceCount() { return m_surfaceFactory->createSurfaceCount(); }
|
| + SkCanvas* canvas() { return m_imageBuffer->canvas(); }
|
|
|
| void expectDisplayListEnabled(bool displayListEnabled) {
|
| EXPECT_EQ(displayListEnabled, (bool)m_testSurface->m_currentFrame.get());
|
| @@ -227,53 +82,62 @@ class RecordingImageBufferSurfaceTest : public Test {
|
| private:
|
| MockSurfaceFactory* m_surfaceFactory;
|
| RecordingImageBufferSurface* m_testSurface;
|
| - std::unique_ptr<FakeImageBufferClient> m_fakeImageBufferClient;
|
| std::unique_ptr<ImageBuffer> m_imageBuffer;
|
| };
|
|
|
| -#define CALL_TEST_TASK_WRAPPER(TEST_METHOD) \
|
| - { \
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> \
|
| - platform; \
|
| - Platform::current()->currentThread()->getWebTaskRunner()->postTask( \
|
| - BLINK_FROM_HERE, \
|
| - WTF::bind(&RecordingImageBufferSurfaceTest::TEST_METHOD, \
|
| - WTF::unretained(this))); \
|
| - platform->runUntilIdle(); \
|
| - }
|
| -
|
| TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture) {
|
| - testEmptyPicture();
|
| + sk_sp<SkPicture> picture = testSurface()->getPicture();
|
| + EXPECT_TRUE((bool)picture.get());
|
| + expectDisplayListEnabled(true);
|
| }
|
|
|
| TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear) {
|
| - testNoFallbackWithClear();
|
| + testSurface()->willOverwriteCanvas();
|
| + testSurface()->getPicture();
|
| + expectDisplayListEnabled(true);
|
| }
|
|
|
| TEST_F(RecordingImageBufferSurfaceTest, testNonAnimatedCanvasUpdate) {
|
| - CALL_TEST_TASK_WRAPPER(testNonAnimatedCanvasUpdate)
|
| + // Acquire picture twice to simulate a static canvas: nothing drawn between
|
| + // updates.
|
| + testSurface()->didDraw(FloatRect(0, 0, 1, 1));
|
| + testSurface()->getPicture();
|
| + testSurface()->getPicture();
|
| expectDisplayListEnabled(true);
|
| }
|
|
|
| TEST_F(RecordingImageBufferSurfaceTest, testAnimatedWithoutClear) {
|
| - CALL_TEST_TASK_WRAPPER(testAnimatedWithoutClear)
|
| - expectDisplayListEnabled(false);
|
| -}
|
| -
|
| -TEST_F(RecordingImageBufferSurfaceTest, testFrameFinalizedByTaskObserver) {
|
| - CALL_TEST_TASK_WRAPPER(testFrameFinalizedByTaskObserver1)
|
| - expectDisplayListEnabled(false);
|
| - CALL_TEST_TASK_WRAPPER(testFrameFinalizedByTaskObserver2)
|
| + testSurface()->didDraw(FloatRect(0, 0, 1, 1));
|
| + testSurface()->getPicture();
|
| + EXPECT_EQ(0, createSurfaceCount());
|
| + expectDisplayListEnabled(true); // first frame has an implicit clear
|
| + testSurface()->didDraw(FloatRect(0, 0, 1, 1));
|
| + testSurface()->getPicture();
|
| expectDisplayListEnabled(false);
|
| }
|
|
|
| TEST_F(RecordingImageBufferSurfaceTest, testAnimatedWithClear) {
|
| - CALL_TEST_TASK_WRAPPER(testAnimatedWithClear)
|
| + testSurface()->getPicture();
|
| + testSurface()->willOverwriteCanvas();
|
| + testSurface()->didDraw(FloatRect(0, 0, 1, 1));
|
| + testSurface()->getPicture();
|
| + expectDisplayListEnabled(true);
|
| + // clear after use
|
| + testSurface()->didDraw(FloatRect(0, 0, 1, 1));
|
| + testSurface()->willOverwriteCanvas();
|
| + testSurface()->getPicture();
|
| expectDisplayListEnabled(true);
|
| }
|
|
|
| TEST_F(RecordingImageBufferSurfaceTest, testClearRect) {
|
| - CALL_TEST_TASK_WRAPPER(testClearRect);
|
| + testSurface()->getPicture();
|
| + SkPaint clearPaint;
|
| + clearPaint.setBlendMode(SkBlendMode::kClear);
|
| + canvas()->drawRect(SkRect::MakeWH(testSurface()->size().width(),
|
| + testSurface()->size().height()),
|
| + clearPaint);
|
| + testSurface()->didDraw(FloatRect(0, 0, 1, 1));
|
| + testSurface()->getPicture();
|
| expectDisplayListEnabled(true);
|
| }
|
|
|
|
|