| 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" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // We create an ImageBuffer in order for the testSurface to be | 61 // We create an ImageBuffer in order for the testSurface to be |
| 62 // properly initialized with a GraphicsContext | 62 // properly initialized with a GraphicsContext |
| 63 m_imageBuffer = ImageBuffer::create(std::move(testSurface)); | 63 m_imageBuffer = ImageBuffer::create(std::move(testSurface)); |
| 64 EXPECT_FALSE(!m_imageBuffer); | 64 EXPECT_FALSE(!m_imageBuffer); |
| 65 m_testSurface->initializeCurrentFrame(); | 65 m_testSurface->initializeCurrentFrame(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 public: | 68 public: |
| 69 RecordingImageBufferSurface* testSurface() { return m_testSurface; } | 69 RecordingImageBufferSurface* testSurface() { return m_testSurface; } |
| 70 int createSurfaceCount() { return m_surfaceFactory->createSurfaceCount(); } | 70 int createSurfaceCount() { return m_surfaceFactory->createSurfaceCount(); } |
| 71 SkCanvas* canvas() { return m_imageBuffer->canvas(); } | 71 PaintCanvas* canvas() { return m_imageBuffer->canvas(); } |
| 72 | 72 |
| 73 void expectDisplayListEnabled(bool displayListEnabled) { | 73 void expectDisplayListEnabled(bool displayListEnabled) { |
| 74 EXPECT_EQ(displayListEnabled, (bool)m_testSurface->m_currentFrame.get()); | 74 EXPECT_EQ(displayListEnabled, (bool)m_testSurface->m_currentFrame.get()); |
| 75 EXPECT_EQ(!displayListEnabled, | 75 EXPECT_EQ(!displayListEnabled, |
| 76 (bool)m_testSurface->m_fallbackSurface.get()); | 76 (bool)m_testSurface->m_fallbackSurface.get()); |
| 77 int expectedSurfaceCreationCount = displayListEnabled ? 0 : 1; | 77 int expectedSurfaceCreationCount = displayListEnabled ? 0 : 1; |
| 78 EXPECT_EQ(expectedSurfaceCreationCount, | 78 EXPECT_EQ(expectedSurfaceCreationCount, |
| 79 m_surfaceFactory->createSurfaceCount()); | 79 m_surfaceFactory->createSurfaceCount()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 MockSurfaceFactory* m_surfaceFactory; | 83 MockSurfaceFactory* m_surfaceFactory; |
| 84 RecordingImageBufferSurface* m_testSurface; | 84 RecordingImageBufferSurface* m_testSurface; |
| 85 std::unique_ptr<ImageBuffer> m_imageBuffer; | 85 std::unique_ptr<ImageBuffer> m_imageBuffer; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture) { | 88 TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture) { |
| 89 sk_sp<SkPicture> picture = testSurface()->getRecord(); | 89 sk_sp<PaintRecord> record = testSurface()->getRecord(); |
| 90 EXPECT_TRUE((bool)picture.get()); | 90 EXPECT_TRUE(record.get()); |
| 91 expectDisplayListEnabled(true); | 91 expectDisplayListEnabled(true); |
| 92 } | 92 } |
| 93 | 93 |
| 94 TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear) { | 94 TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear) { |
| 95 testSurface()->willOverwriteCanvas(); | 95 testSurface()->willOverwriteCanvas(); |
| 96 testSurface()->getRecord(); | 96 testSurface()->getRecord(); |
| 97 expectDisplayListEnabled(true); | 97 expectDisplayListEnabled(true); |
| 98 } | 98 } |
| 99 | 99 |
| 100 TEST_F(RecordingImageBufferSurfaceTest, testNonAnimatedCanvasUpdate) { | 100 TEST_F(RecordingImageBufferSurfaceTest, testNonAnimatedCanvasUpdate) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 124 expectDisplayListEnabled(true); | 124 expectDisplayListEnabled(true); |
| 125 // clear after use | 125 // clear after use |
| 126 testSurface()->didDraw(FloatRect(0, 0, 1, 1)); | 126 testSurface()->didDraw(FloatRect(0, 0, 1, 1)); |
| 127 testSurface()->willOverwriteCanvas(); | 127 testSurface()->willOverwriteCanvas(); |
| 128 testSurface()->getRecord(); | 128 testSurface()->getRecord(); |
| 129 expectDisplayListEnabled(true); | 129 expectDisplayListEnabled(true); |
| 130 } | 130 } |
| 131 | 131 |
| 132 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) { | 132 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) { |
| 133 testSurface()->getRecord(); | 133 testSurface()->getRecord(); |
| 134 SkPaint clearPaint; | 134 PaintFlags clearFlags; |
| 135 clearPaint.setBlendMode(SkBlendMode::kClear); | 135 clearFlags.setBlendMode(SkBlendMode::kClear); |
| 136 canvas()->drawRect(SkRect::MakeWH(testSurface()->size().width(), | 136 canvas()->drawRect(SkRect::MakeWH(testSurface()->size().width(), |
| 137 testSurface()->size().height()), | 137 testSurface()->size().height()), |
| 138 clearPaint); | 138 clearFlags); |
| 139 testSurface()->didDraw(FloatRect(0, 0, 1, 1)); | 139 testSurface()->didDraw(FloatRect(0, 0, 1, 1)); |
| 140 testSurface()->getRecord(); | 140 testSurface()->getRecord(); |
| 141 expectDisplayListEnabled(true); | 141 expectDisplayListEnabled(true); |
| 142 } | 142 } |
| 143 | 143 |
| 144 } // namespace blink | 144 } // namespace blink |
| OLD | NEW |