| 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 "platform/graphics/RecordingImageBufferSurface.h" | 7 #include "platform/graphics/RecordingImageBufferSurface.h" |
| 8 | 8 |
| 9 #include "platform/graphics/GraphicsContext.h" | 9 #include "platform/graphics/GraphicsContext.h" |
| 10 #include "platform/graphics/ImageBuffer.h" | 10 #include "platform/graphics/ImageBuffer.h" |
| 11 #include "platform/graphics/ImageBufferClient.h" | 11 #include "platform/graphics/ImageBufferClient.h" |
| 12 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 12 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
| 13 #include "public/platform/WebThread.h" | 14 #include "public/platform/WebThread.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "third_party/skia/include/core/SkPictureRecorder.h" | 16 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 16 #include "wtf/OwnPtr.h" | 17 #include "wtf/OwnPtr.h" |
| 17 #include "wtf/PassOwnPtr.h" | 18 #include "wtf/PassOwnPtr.h" |
| 18 #include "wtf/RefPtr.h" | 19 #include "wtf/RefPtr.h" |
| 19 | 20 |
| 20 #include <gmock/gmock.h> | 21 #include <gmock/gmock.h> |
| 21 #include <gtest/gtest.h> | 22 #include <gtest/gtest.h> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 67 } |
| 67 | 68 |
| 68 int frameCount() { return m_frameCount; } | 69 int frameCount() { return m_frameCount; } |
| 69 | 70 |
| 70 private: | 71 private: |
| 71 bool m_isDirty; | 72 bool m_isDirty; |
| 72 ImageBuffer* m_imageBuffer; | 73 ImageBuffer* m_imageBuffer; |
| 73 int m_frameCount; | 74 int m_frameCount; |
| 74 }; | 75 }; |
| 75 | 76 |
| 77 class MockSurfaceFactory : public RecordingImageBufferFallbackSurfaceFactory { |
| 78 public: |
| 79 MockSurfaceFactory() : m_createSurfaceCount(0) { } |
| 80 |
| 81 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, Op
acityMode opacityMode) |
| 82 { |
| 83 m_createSurfaceCount++; |
| 84 return adoptPtr(new UnacceleratedImageBufferSurface(size, opacityMode)); |
| 85 } |
| 86 |
| 87 virtual ~MockSurfaceFactory() { } |
| 88 |
| 89 int createSurfaceCount() { return m_createSurfaceCount; } |
| 90 |
| 91 private: |
| 92 int m_createSurfaceCount; |
| 93 }; |
| 94 |
| 76 } // unnamed namespace | 95 } // unnamed namespace |
| 77 | 96 |
| 78 class RecordingImageBufferSurfaceTest : public Test { | 97 class RecordingImageBufferSurfaceTest : public Test { |
| 79 protected: | 98 protected: |
| 80 RecordingImageBufferSurfaceTest() | 99 RecordingImageBufferSurfaceTest() |
| 81 { | 100 { |
| 82 OwnPtr<RecordingImageBufferSurface> testSurface = adoptPtr(new Recording
ImageBufferSurface(IntSize(10, 10))); | 101 OwnPtr<MockSurfaceFactory> surfaceFactory = adoptPtr(new MockSurfaceFact
ory()); |
| 102 m_surfaceFactory = surfaceFactory.get(); |
| 103 OwnPtr<RecordingImageBufferSurface> testSurface = adoptPtr(new Recording
ImageBufferSurface(IntSize(10, 10), surfaceFactory.release())); |
| 83 m_testSurface = testSurface.get(); | 104 m_testSurface = testSurface.get(); |
| 84 // We create an ImageBuffer in order for the testSurface to be | 105 // We create an ImageBuffer in order for the testSurface to be |
| 85 // properly initialized with a GraphicsContext | 106 // properly initialized with a GraphicsContext |
| 86 m_imageBuffer = ImageBuffer::create(testSurface.release()); | 107 m_imageBuffer = ImageBuffer::create(testSurface.release()); |
| 87 EXPECT_FALSE(!m_imageBuffer); | 108 EXPECT_FALSE(!m_imageBuffer); |
| 88 m_fakeImageBufferClient = adoptPtr(new FakeImageBufferClient(m_imageBuff
er.get())); | 109 m_fakeImageBufferClient = adoptPtr(new FakeImageBufferClient(m_imageBuff
er.get())); |
| 89 m_imageBuffer->setClient(m_fakeImageBufferClient.get()); | 110 m_imageBuffer->setClient(m_fakeImageBufferClient.get()); |
| 90 } | 111 } |
| 91 | 112 |
| 92 public: | 113 public: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 118 EXPECT_EQ(2, m_fakeImageBufferClient->frameCount()); | 139 EXPECT_EQ(2, m_fakeImageBufferClient->frameCount()); |
| 119 expectDisplayListEnabled(true); | 140 expectDisplayListEnabled(true); |
| 120 } | 141 } |
| 121 | 142 |
| 122 void testAnimatedWithoutClear() | 143 void testAnimatedWithoutClear() |
| 123 { | 144 { |
| 124 m_testSurface->initializeCurrentFrame(); | 145 m_testSurface->initializeCurrentFrame(); |
| 125 m_fakeImageBufferClient->fakeDraw(); | 146 m_fakeImageBufferClient->fakeDraw(); |
| 126 m_testSurface->getPicture(); | 147 m_testSurface->getPicture(); |
| 127 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); | 148 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); |
| 149 EXPECT_EQ(0, m_surfaceFactory->createSurfaceCount()); |
| 128 expectDisplayListEnabled(true); // first frame has an implicit clear | 150 expectDisplayListEnabled(true); // first frame has an implicit clear |
| 129 m_fakeImageBufferClient->fakeDraw(); | 151 m_fakeImageBufferClient->fakeDraw(); |
| 130 m_testSurface->getPicture(); | 152 m_testSurface->getPicture(); |
| 131 EXPECT_EQ(2, m_fakeImageBufferClient->frameCount()); | 153 EXPECT_EQ(2, m_fakeImageBufferClient->frameCount()); |
| 132 expectDisplayListEnabled(false); | 154 expectDisplayListEnabled(false); |
| 133 } | 155 } |
| 134 | 156 |
| 135 void testFrameFinalizedByTaskObserver1() | 157 void testFrameFinalizedByTaskObserver1() |
| 136 { | 158 { |
| 137 m_testSurface->initializeCurrentFrame(); | 159 m_testSurface->initializeCurrentFrame(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 148 m_fakeImageBufferClient->fakeDraw(); | 170 m_fakeImageBufferClient->fakeDraw(); |
| 149 EXPECT_EQ(2, m_fakeImageBufferClient->frameCount()); | 171 EXPECT_EQ(2, m_fakeImageBufferClient->frameCount()); |
| 150 expectDisplayListEnabled(true); | 172 expectDisplayListEnabled(true); |
| 151 // Display list will be disabled only after exiting the runLoop | 173 // Display list will be disabled only after exiting the runLoop |
| 152 } | 174 } |
| 153 void testFrameFinalizedByTaskObserver2() | 175 void testFrameFinalizedByTaskObserver2() |
| 154 { | 176 { |
| 155 EXPECT_EQ(3, m_fakeImageBufferClient->frameCount()); | 177 EXPECT_EQ(3, m_fakeImageBufferClient->frameCount()); |
| 156 expectDisplayListEnabled(false); | 178 expectDisplayListEnabled(false); |
| 157 m_testSurface->getPicture(); | 179 m_testSurface->getPicture(); |
| 158 EXPECT_EQ(4, m_fakeImageBufferClient->frameCount()); | 180 EXPECT_EQ(3, m_fakeImageBufferClient->frameCount()); |
| 159 expectDisplayListEnabled(false); | 181 expectDisplayListEnabled(false); |
| 160 m_fakeImageBufferClient->fakeDraw(); | 182 m_fakeImageBufferClient->fakeDraw(); |
| 161 EXPECT_EQ(4, m_fakeImageBufferClient->frameCount()); | 183 EXPECT_EQ(3, m_fakeImageBufferClient->frameCount()); |
| 162 expectDisplayListEnabled(false); | 184 expectDisplayListEnabled(false); |
| 163 } | 185 } |
| 164 | 186 |
| 165 void testAnimatedWithClear() | 187 void testAnimatedWithClear() |
| 166 { | 188 { |
| 167 m_testSurface->initializeCurrentFrame(); | 189 m_testSurface->initializeCurrentFrame(); |
| 168 m_testSurface->getPicture(); | 190 m_testSurface->getPicture(); |
| 169 m_testSurface->didClearCanvas(); | 191 m_testSurface->didClearCanvas(); |
| 170 m_fakeImageBufferClient->fakeDraw(); | 192 m_fakeImageBufferClient->fakeDraw(); |
| 171 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); | 193 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 189 m_fakeImageBufferClient->fakeDraw(); | 211 m_fakeImageBufferClient->fakeDraw(); |
| 190 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); | 212 EXPECT_EQ(1, m_fakeImageBufferClient->frameCount()); |
| 191 m_testSurface->getPicture(); | 213 m_testSurface->getPicture(); |
| 192 EXPECT_EQ(2, m_fakeImageBufferClient->frameCount()); | 214 EXPECT_EQ(2, m_fakeImageBufferClient->frameCount()); |
| 193 expectDisplayListEnabled(true); | 215 expectDisplayListEnabled(true); |
| 194 } | 216 } |
| 195 | 217 |
| 196 void expectDisplayListEnabled(bool displayListEnabled) | 218 void expectDisplayListEnabled(bool displayListEnabled) |
| 197 { | 219 { |
| 198 EXPECT_EQ(displayListEnabled, (bool)m_testSurface->m_currentFrame.get())
; | 220 EXPECT_EQ(displayListEnabled, (bool)m_testSurface->m_currentFrame.get())
; |
| 199 EXPECT_EQ(!displayListEnabled, (bool)m_testSurface->m_rasterCanvas.get()
); | 221 EXPECT_EQ(!displayListEnabled, (bool)m_testSurface->m_fallbackSurface.ge
t()); |
| 222 int expectedSurfaceCreationCount = displayListEnabled ? 0 : 1; |
| 223 EXPECT_EQ(expectedSurfaceCreationCount, m_surfaceFactory->createSurfaceC
ount()); |
| 200 } | 224 } |
| 201 | 225 |
| 202 private: | 226 private: |
| 227 MockSurfaceFactory* m_surfaceFactory; |
| 203 RecordingImageBufferSurface* m_testSurface; | 228 RecordingImageBufferSurface* m_testSurface; |
| 204 OwnPtr<FakeImageBufferClient> m_fakeImageBufferClient; | 229 OwnPtr<FakeImageBufferClient> m_fakeImageBufferClient; |
| 205 OwnPtr<ImageBuffer> m_imageBuffer; | 230 OwnPtr<ImageBuffer> m_imageBuffer; |
| 206 }; | 231 }; |
| 207 | 232 |
| 208 namespace { | 233 namespace { |
| 209 | 234 |
| 210 // 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 |
| 211 // 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 |
| 212 // 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 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 } | 378 } |
| 354 | 379 |
| 355 DEFINE_TEST_TASK_WRAPPER_CLASS(testClearRect) | 380 DEFINE_TEST_TASK_WRAPPER_CLASS(testClearRect) |
| 356 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) | 381 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) |
| 357 { | 382 { |
| 358 CALL_TEST_TASK_WRAPPER(testClearRect); | 383 CALL_TEST_TASK_WRAPPER(testClearRect); |
| 359 expectDisplayListEnabled(true); | 384 expectDisplayListEnabled(true); |
| 360 } | 385 } |
| 361 | 386 |
| 362 } // namespace | 387 } // namespace |
| OLD | NEW |