| 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/graphics/GraphicsContext.h" | 7 #include "platform/graphics/GraphicsContext.h" |
| 8 #include "platform/graphics/ImageBuffer.h" | 8 #include "platform/graphics/ImageBuffer.h" |
| 9 #include "platform/graphics/ImageBufferClient.h" | 9 #include "platform/graphics/ImageBufferClient.h" |
| 10 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 10 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 11 #include "platform/testing/TestingPlatformSupport.h" | 11 #include "platform/testing/TestingPlatformSupport.h" |
| 12 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
| 13 #include "public/platform/WebTaskRunner.h" | 13 #include "public/platform/WebTaskRunner.h" |
| 14 #include "public/platform/WebThread.h" | 14 #include "public/platform/WebThread.h" |
| 15 #include "public/platform/WebTraceLocation.h" | 15 #include "public/platform/WebTraceLocation.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/skia/include/core/SkCanvas.h" | 18 #include "third_party/skia/include/core/SkCanvas.h" |
| 19 #include "third_party/skia/include/core/SkPictureRecorder.h" | 19 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 20 #include "wtf/PtrUtil.h" | 20 #include "wtf/OwnPtr.h" |
| 21 #include "wtf/PassOwnPtr.h" |
| 21 #include "wtf/RefPtr.h" | 22 #include "wtf/RefPtr.h" |
| 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, public WebThread::TaskOb
server { | 28 class FakeImageBufferClient : public ImageBufferClient, public WebThread::TaskOb
server { |
| 29 public: | 29 public: |
| 30 FakeImageBufferClient(ImageBuffer* imageBuffer) | 30 FakeImageBufferClient(ImageBuffer* imageBuffer) |
| 31 : m_isDirty(false) | 31 : m_isDirty(false) |
| 32 , m_imageBuffer(imageBuffer) | 32 , m_imageBuffer(imageBuffer) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 private: | 71 private: |
| 72 bool m_isDirty; | 72 bool m_isDirty; |
| 73 ImageBuffer* m_imageBuffer; | 73 ImageBuffer* m_imageBuffer; |
| 74 int m_frameCount; | 74 int m_frameCount; |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 class MockSurfaceFactory : public RecordingImageBufferFallbackSurfaceFactory { | 77 class MockSurfaceFactory : public RecordingImageBufferFallbackSurfaceFactory { |
| 78 public: | 78 public: |
| 79 MockSurfaceFactory() : m_createSurfaceCount(0) { } | 79 MockSurfaceFactory() : m_createSurfaceCount(0) { } |
| 80 | 80 |
| 81 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz
e, OpacityMode opacityMode) | 81 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, Op
acityMode opacityMode) |
| 82 { | 82 { |
| 83 m_createSurfaceCount++; | 83 m_createSurfaceCount++; |
| 84 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode)
); | 84 return adoptPtr(new UnacceleratedImageBufferSurface(size, opacityMode)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 virtual ~MockSurfaceFactory() { } | 87 virtual ~MockSurfaceFactory() { } |
| 88 | 88 |
| 89 int createSurfaceCount() { return m_createSurfaceCount; } | 89 int createSurfaceCount() { return m_createSurfaceCount; } |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 int m_createSurfaceCount; | 92 int m_createSurfaceCount; |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 class RecordingImageBufferSurfaceTest : public Test { | 95 class RecordingImageBufferSurfaceTest : public Test { |
| 96 protected: | 96 protected: |
| 97 RecordingImageBufferSurfaceTest() | 97 RecordingImageBufferSurfaceTest() |
| 98 { | 98 { |
| 99 std::unique_ptr<MockSurfaceFactory> surfaceFactory = wrapUnique(new Mock
SurfaceFactory()); | 99 OwnPtr<MockSurfaceFactory> surfaceFactory = adoptPtr(new MockSurfaceFact
ory()); |
| 100 m_surfaceFactory = surfaceFactory.get(); | 100 m_surfaceFactory = surfaceFactory.get(); |
| 101 std::unique_ptr<RecordingImageBufferSurface> testSurface = wrapUnique(ne
w RecordingImageBufferSurface(IntSize(10, 10), std::move(surfaceFactory))); | 101 OwnPtr<RecordingImageBufferSurface> testSurface = adoptPtr(new Recording
ImageBufferSurface(IntSize(10, 10), std::move(surfaceFactory))); |
| 102 m_testSurface = testSurface.get(); | 102 m_testSurface = testSurface.get(); |
| 103 // We create an ImageBuffer in order for the testSurface to be | 103 // We create an ImageBuffer in order for the testSurface to be |
| 104 // properly initialized with a GraphicsContext | 104 // properly initialized with a GraphicsContext |
| 105 m_imageBuffer = ImageBuffer::create(std::move(testSurface)); | 105 m_imageBuffer = ImageBuffer::create(std::move(testSurface)); |
| 106 EXPECT_FALSE(!m_imageBuffer); | 106 EXPECT_FALSE(!m_imageBuffer); |
| 107 m_fakeImageBufferClient = wrapUnique(new FakeImageBufferClient(m_imageBu
ffer.get())); | 107 m_fakeImageBufferClient = adoptPtr(new FakeImageBufferClient(m_imageBuff
er.get())); |
| 108 m_imageBuffer->setClient(m_fakeImageBufferClient.get()); | 108 m_imageBuffer->setClient(m_fakeImageBufferClient.get()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 public: | 111 public: |
| 112 void testEmptyPicture() | 112 void testEmptyPicture() |
| 113 { | 113 { |
| 114 m_testSurface->initializeCurrentFrame(); | 114 m_testSurface->initializeCurrentFrame(); |
| 115 RefPtr<SkPicture> picture = m_testSurface->getPicture(); | 115 RefPtr<SkPicture> picture = m_testSurface->getPicture(); |
| 116 EXPECT_TRUE((bool)picture.get()); | 116 EXPECT_TRUE((bool)picture.get()); |
| 117 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); | 117 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 { | 219 { |
| 220 EXPECT_EQ(displayListEnabled, (bool)m_testSurface->m_currentFrame.get())
; | 220 EXPECT_EQ(displayListEnabled, (bool)m_testSurface->m_currentFrame.get())
; |
| 221 EXPECT_EQ(!displayListEnabled, (bool)m_testSurface->m_fallbackSurface.ge
t()); | 221 EXPECT_EQ(!displayListEnabled, (bool)m_testSurface->m_fallbackSurface.ge
t()); |
| 222 int expectedSurfaceCreationCount = displayListEnabled ? 0 : 1; | 222 int expectedSurfaceCreationCount = displayListEnabled ? 0 : 1; |
| 223 EXPECT_EQ(expectedSurfaceCreationCount, m_surfaceFactory->createSurfaceC
ount()); | 223 EXPECT_EQ(expectedSurfaceCreationCount, m_surfaceFactory->createSurfaceC
ount()); |
| 224 } | 224 } |
| 225 | 225 |
| 226 private: | 226 private: |
| 227 MockSurfaceFactory* m_surfaceFactory; | 227 MockSurfaceFactory* m_surfaceFactory; |
| 228 RecordingImageBufferSurface* m_testSurface; | 228 RecordingImageBufferSurface* m_testSurface; |
| 229 std::unique_ptr<FakeImageBufferClient> m_fakeImageBufferClient; | 229 OwnPtr<FakeImageBufferClient> m_fakeImageBufferClient; |
| 230 std::unique_ptr<ImageBuffer> m_imageBuffer; | 230 OwnPtr<ImageBuffer> m_imageBuffer; |
| 231 }; | 231 }; |
| 232 | 232 |
| 233 namespace { | 233 namespace { |
| 234 | 234 |
| 235 // The following test helper class installs a mock platform that provides a mock
WebThread | 235 // The following test helper class installs a mock platform that provides a mock
WebThread |
| 236 // for the current thread. The Mock thread is capable of queuing a single non-de
layed task | 236 // for the current thread. The Mock thread is capable of queuing a single non-de
layed task |
| 237 // and registering a single task observer. The run loop exits immediately after
running | 237 // and registering a single task observer. The run loop exits immediately after
running |
| 238 // the single task. | 238 // the single task. |
| 239 | 239 |
| 240 class CurrentThreadPlatformMock : public TestingPlatformSupport { | 240 class CurrentThreadPlatformMock : public TestingPlatformSupport { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 expectDisplayListEnabled(true); | 384 expectDisplayListEnabled(true); |
| 385 } | 385 } |
| 386 | 386 |
| 387 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) | 387 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) |
| 388 { | 388 { |
| 389 CALL_TEST_TASK_WRAPPER(testClearRect); | 389 CALL_TEST_TASK_WRAPPER(testClearRect); |
| 390 expectDisplayListEnabled(true); | 390 expectDisplayListEnabled(true); |
| 391 } | 391 } |
| 392 | 392 |
| 393 } // namespace blink | 393 } // namespace blink |
| OLD | NEW |