| 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 "platform/graphics/RecordingImageBufferSurface.h" | 5 #include "platform/graphics/RecordingImageBufferSurface.h" |
| 6 | 6 |
| 7 #include "platform/WebTaskRunner.h" | 7 #include "platform/WebTaskRunner.h" |
| 8 #include "platform/graphics/GraphicsContext.h" | 8 #include "platform/graphics/GraphicsContext.h" |
| 9 #include "platform/graphics/ImageBuffer.h" | 9 #include "platform/graphics/ImageBuffer.h" |
| 10 #include "platform/graphics/ImageBufferClient.h" | 10 #include "platform/graphics/ImageBufferClient.h" |
| 11 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 11 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 12 #include "platform/graphics/paint/PaintCanvas.h" |
| 13 #include "platform/graphics/paint/PaintRecord.h" |
| 12 #include "platform/testing/TestingPlatformSupport.h" | 14 #include "platform/testing/TestingPlatformSupport.h" |
| 13 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
| 14 #include "public/platform/WebThread.h" | 16 #include "public/platform/WebThread.h" |
| 15 #include "public/platform/WebTraceLocation.h" | 17 #include "public/platform/WebTraceLocation.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/skia/include/core/SkCanvas.h" | |
| 19 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
| 20 #include "wtf/PtrUtil.h" | 20 #include "wtf/PtrUtil.h" |
| 21 #include "wtf/RefPtr.h" | 21 #include "wtf/RefPtr.h" |
| 22 #include <memory> | 22 #include <memory> |
| 23 | 23 |
| 24 using testing::Test; | 24 using testing::Test; |
| 25 | 25 |
| 26 namespace blink { | 26 namespace blink { |
| 27 | 27 |
| 28 class FakeImageBufferClient : public ImageBufferClient, | 28 class FakeImageBufferClient : public ImageBufferClient, |
| 29 public WebThread::TaskObserver { | 29 public WebThread::TaskObserver { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 46 } | 46 } |
| 47 | 47 |
| 48 // TaskObserver implementation | 48 // TaskObserver implementation |
| 49 void willProcessTask() override { NOTREACHED(); } | 49 void willProcessTask() override { NOTREACHED(); } |
| 50 void didProcessTask() override { | 50 void didProcessTask() override { |
| 51 ASSERT_TRUE(m_isDirty); | 51 ASSERT_TRUE(m_isDirty); |
| 52 FloatRect dirtyRect(0, 0, 1, 1); | 52 FloatRect dirtyRect(0, 0, 1, 1); |
| 53 m_imageBuffer->finalizeFrame(dirtyRect); | 53 m_imageBuffer->finalizeFrame(dirtyRect); |
| 54 ASSERT_FALSE(m_isDirty); | 54 ASSERT_FALSE(m_isDirty); |
| 55 } | 55 } |
| 56 void restoreCanvasMatrixClipStack(SkCanvas*) const override {} | 56 void restoreCanvasMatrixClipStack(PaintCanvas*) const override {} |
| 57 | 57 |
| 58 void fakeDraw() { | 58 void fakeDraw() { |
| 59 if (m_isDirty) | 59 if (m_isDirty) |
| 60 return; | 60 return; |
| 61 m_isDirty = true; | 61 m_isDirty = true; |
| 62 Platform::current()->currentThread()->addTaskObserver(this); | 62 Platform::current()->currentThread()->addTaskObserver(this); |
| 63 } | 63 } |
| 64 | 64 |
| 65 int frameCount() { return m_frameCount; } | 65 int frameCount() { return m_frameCount; } |
| 66 | 66 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 m_imageBuffer = ImageBuffer::create(std::move(testSurface)); | 108 m_imageBuffer = ImageBuffer::create(std::move(testSurface)); |
| 109 EXPECT_FALSE(!m_imageBuffer); | 109 EXPECT_FALSE(!m_imageBuffer); |
| 110 m_fakeImageBufferClient = | 110 m_fakeImageBufferClient = |
| 111 WTF::wrapUnique(new FakeImageBufferClient(m_imageBuffer.get())); | 111 WTF::wrapUnique(new FakeImageBufferClient(m_imageBuffer.get())); |
| 112 m_imageBuffer->setClient(m_fakeImageBufferClient.get()); | 112 m_imageBuffer->setClient(m_fakeImageBufferClient.get()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 public: | 115 public: |
| 116 void testEmptyPicture() { | 116 void testEmptyPicture() { |
| 117 m_testSurface->initializeCurrentFrame(); | 117 m_testSurface->initializeCurrentFrame(); |
| 118 sk_sp<SkPicture> picture = m_testSurface->getPicture(); | 118 sk_sp<PaintRecord> picture = m_testSurface->getPicture(); |
| 119 EXPECT_TRUE((bool)picture.get()); | 119 EXPECT_TRUE((bool)picture.get()); |
| 120 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); | 120 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); |
| 121 expectDisplayListEnabled(true); | 121 expectDisplayListEnabled(true); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void testNoFallbackWithClear() { | 124 void testNoFallbackWithClear() { |
| 125 m_testSurface->initializeCurrentFrame(); | 125 m_testSurface->initializeCurrentFrame(); |
| 126 m_testSurface->willOverwriteCanvas(); | 126 m_testSurface->willOverwriteCanvas(); |
| 127 m_testSurface->getPicture(); | 127 m_testSurface->getPicture(); |
| 128 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); | 128 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 m_testSurface->willOverwriteCanvas(); | 195 m_testSurface->willOverwriteCanvas(); |
| 196 EXPECT_EQ(2, m_fakeImageBufferClient->frameCount()); | 196 EXPECT_EQ(2, m_fakeImageBufferClient->frameCount()); |
| 197 m_testSurface->getPicture(); | 197 m_testSurface->getPicture(); |
| 198 EXPECT_EQ(3, m_fakeImageBufferClient->frameCount()); | 198 EXPECT_EQ(3, m_fakeImageBufferClient->frameCount()); |
| 199 expectDisplayListEnabled(true); | 199 expectDisplayListEnabled(true); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void testClearRect() { | 202 void testClearRect() { |
| 203 m_testSurface->initializeCurrentFrame(); | 203 m_testSurface->initializeCurrentFrame(); |
| 204 m_testSurface->getPicture(); | 204 m_testSurface->getPicture(); |
| 205 SkPaint clearPaint; | 205 PaintFlags clearPaint; |
| 206 clearPaint.setBlendMode(SkBlendMode::kClear); | 206 clearPaint.setBlendMode(SkBlendMode::kClear); |
| 207 m_imageBuffer->canvas()->drawRect( | 207 m_imageBuffer->canvas()->drawRect( |
| 208 SkRect::MakeWH(m_testSurface->size().width(), | 208 SkRect::MakeWH(m_testSurface->size().width(), |
| 209 m_testSurface->size().height()), | 209 m_testSurface->size().height()), |
| 210 clearPaint); | 210 clearPaint); |
| 211 m_fakeImageBufferClient->fakeDraw(); | 211 m_fakeImageBufferClient->fakeDraw(); |
| 212 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); | 212 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); |
| 213 m_testSurface->getPicture(); | 213 m_testSurface->getPicture(); |
| 214 EXPECT_EQ(2, m_fakeImageBufferClient->frameCount()); | 214 EXPECT_EQ(2, m_fakeImageBufferClient->frameCount()); |
| 215 expectDisplayListEnabled(true); | 215 expectDisplayListEnabled(true); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 CALL_TEST_TASK_WRAPPER(testAnimatedWithClear) | 271 CALL_TEST_TASK_WRAPPER(testAnimatedWithClear) |
| 272 expectDisplayListEnabled(true); | 272 expectDisplayListEnabled(true); |
| 273 } | 273 } |
| 274 | 274 |
| 275 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) { | 275 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) { |
| 276 CALL_TEST_TASK_WRAPPER(testClearRect); | 276 CALL_TEST_TASK_WRAPPER(testClearRect); |
| 277 expectDisplayListEnabled(true); | 277 expectDisplayListEnabled(true); |
| 278 } | 278 } |
| 279 | 279 |
| 280 } // namespace blink | 280 } // namespace blink |
| OLD | NEW |