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" |
(...skipping 23 matching lines...) Expand all Loading... |
34 { } | 34 { } |
35 | 35 |
36 virtual ~FakeImageBufferClient() { } | 36 virtual ~FakeImageBufferClient() { } |
37 | 37 |
38 // ImageBufferClient implementation | 38 // ImageBufferClient implementation |
39 virtual void notifySurfaceInvalid() { } | 39 virtual void notifySurfaceInvalid() { } |
40 virtual bool isDirty() { return m_isDirty; }; | 40 virtual bool isDirty() { return m_isDirty; }; |
41 virtual void didFinalizeFrame() | 41 virtual void didFinalizeFrame() |
42 { | 42 { |
43 if (m_isDirty) { | 43 if (m_isDirty) { |
44 blink::Platform::current()->currentThread()->removeTaskObserver(this
); | 44 Platform::current()->currentThread()->removeTaskObserver(this); |
45 m_isDirty = false; | 45 m_isDirty = false; |
46 } | 46 } |
47 ++m_frameCount; | 47 ++m_frameCount; |
48 } | 48 } |
49 | 49 |
50 // TaskObserver implementation | 50 // TaskObserver implementation |
51 virtual void willProcessTask() OVERRIDE { ASSERT_NOT_REACHED(); } | 51 virtual void willProcessTask() OVERRIDE { ASSERT_NOT_REACHED(); } |
52 virtual void didProcessTask() OVERRIDE | 52 virtual void didProcessTask() OVERRIDE |
53 { | 53 { |
54 ASSERT_TRUE(m_isDirty); | 54 ASSERT_TRUE(m_isDirty); |
55 m_imageBuffer->finalizeFrame(); | 55 m_imageBuffer->finalizeFrame(); |
56 ASSERT_FALSE(m_isDirty); | 56 ASSERT_FALSE(m_isDirty); |
57 } | 57 } |
58 | 58 |
59 void fakeDraw() | 59 void fakeDraw() |
60 { | 60 { |
61 if (m_isDirty) | 61 if (m_isDirty) |
62 return; | 62 return; |
63 m_isDirty = true; | 63 m_isDirty = true; |
64 blink::Platform::current()->currentThread()->addTaskObserver(this); | 64 Platform::current()->currentThread()->addTaskObserver(this); |
65 } | 65 } |
66 | 66 |
67 int frameCount() { return m_frameCount; } | 67 int frameCount() { return m_frameCount; } |
68 | 68 |
69 private: | 69 private: |
70 bool m_isDirty; | 70 bool m_isDirty; |
71 ImageBuffer* m_imageBuffer; | 71 ImageBuffer* m_imageBuffer; |
72 int m_frameCount; | 72 int m_frameCount; |
73 }; | 73 }; |
74 | 74 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 namespace { | 206 namespace { |
207 | 207 |
208 // The following test helper class installs a mock platform that provides a mock
WebThread | 208 // The following test helper class installs a mock platform that provides a mock
WebThread |
209 // for the current thread. The Mock thread is capable of queuing a single non-de
layed task | 209 // for the current thread. The Mock thread is capable of queuing a single non-de
layed task |
210 // and registering a single task observer. The run loop exits immediately after
running | 210 // and registering a single task observer. The run loop exits immediately after
running |
211 // the single task. | 211 // the single task. |
212 class AutoInstallCurrentThreadPlatformMock { | 212 class AutoInstallCurrentThreadPlatformMock { |
213 public: | 213 public: |
214 AutoInstallCurrentThreadPlatformMock() | 214 AutoInstallCurrentThreadPlatformMock() |
215 { | 215 { |
216 m_oldPlatform = blink::Platform::current(); | 216 m_oldPlatform = Platform::current(); |
217 blink::Platform::initialize(&m_mockPlatform); | 217 Platform::initialize(&m_mockPlatform); |
218 } | 218 } |
219 | 219 |
220 ~AutoInstallCurrentThreadPlatformMock() | 220 ~AutoInstallCurrentThreadPlatformMock() |
221 { | 221 { |
222 blink::Platform::initialize(m_oldPlatform); | 222 Platform::initialize(m_oldPlatform); |
223 } | 223 } |
224 | 224 |
225 private: | 225 private: |
226 class CurrentThreadMock : public WebThread { | 226 class CurrentThreadMock : public WebThread { |
227 public: | 227 public: |
228 CurrentThreadMock() : m_taskObserver(0), m_task(0) { } | 228 CurrentThreadMock() : m_taskObserver(0), m_task(0) { } |
229 | 229 |
230 virtual ~CurrentThreadMock() | 230 virtual ~CurrentThreadMock() |
231 { | 231 { |
232 EXPECT_EQ((Task*)0, m_task); | 232 EXPECT_EQ((Task*)0, m_task); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 m_taskObserver->didProcessTask(); | 267 m_taskObserver->didProcessTask(); |
268 } | 268 } |
269 | 269 |
270 virtual void exitRunLoop() OVERRIDE { ASSERT_NOT_REACHED(); } | 270 virtual void exitRunLoop() OVERRIDE { ASSERT_NOT_REACHED(); } |
271 | 271 |
272 private: | 272 private: |
273 TaskObserver* m_taskObserver; | 273 TaskObserver* m_taskObserver; |
274 Task* m_task; | 274 Task* m_task; |
275 }; | 275 }; |
276 | 276 |
277 class CurrentThreadPlatformMock : public blink::Platform { | 277 class CurrentThreadPlatformMock : public Platform { |
278 public: | 278 public: |
279 CurrentThreadPlatformMock() { } | 279 CurrentThreadPlatformMock() { } |
280 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t
length) { ASSERT_NOT_REACHED(); } | 280 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t
length) { ASSERT_NOT_REACHED(); } |
281 virtual WebThread* currentThread() OVERRIDE { return &m_currentThread; } | 281 virtual WebThread* currentThread() OVERRIDE { return &m_currentThread; } |
282 private: | 282 private: |
283 CurrentThreadMock m_currentThread; | 283 CurrentThreadMock m_currentThread; |
284 }; | 284 }; |
285 | 285 |
286 CurrentThreadPlatformMock m_mockPlatform; | 286 CurrentThreadPlatformMock m_mockPlatform; |
287 blink::Platform* m_oldPlatform; | 287 Platform* m_oldPlatform; |
288 }; | 288 }; |
289 | 289 |
290 | 290 |
291 #define DEFINE_TEST_TASK_WRAPPER_CLASS(TEST_METHOD)
\ | 291 #define DEFINE_TEST_TASK_WRAPPER_CLASS(TEST_METHOD)
\ |
292 class TestWrapperTask_ ## TEST_METHOD : public blink::WebThread::Task {
\ | 292 class TestWrapperTask_ ## TEST_METHOD : public WebThread::Task {
\ |
293 public:
\ | 293 public:
\ |
294 TestWrapperTask_ ## TEST_METHOD(RecordingImageBufferSurfaceTest* test) :
m_test(test) { } \ | 294 TestWrapperTask_ ## TEST_METHOD(RecordingImageBufferSurfaceTest* test) :
m_test(test) { } \ |
295 virtual void run() OVERRIDE { m_test->TEST_METHOD(); }
\ | 295 virtual void run() OVERRIDE { m_test->TEST_METHOD(); }
\ |
296 private:
\ | 296 private:
\ |
297 RecordingImageBufferSurfaceTest* m_test;
\ | 297 RecordingImageBufferSurfaceTest* m_test;
\ |
298 }; | 298 }; |
299 | 299 |
300 #define CALL_TEST_TASK_WRAPPER(TEST_METHOD)
\ | 300 #define CALL_TEST_TASK_WRAPPER(TEST_METHOD)
\ |
301 {
\ | 301 {
\ |
302 AutoInstallCurrentThreadPlatformMock ctpm;
\ | 302 AutoInstallCurrentThreadPlatformMock ctpm;
\ |
303 blink::Platform::current()->currentThread()->postTask(new TestWrapperTas
k_ ## TEST_METHOD(this)); \ | 303 Platform::current()->currentThread()->postTask(new TestWrapperTask_ ## T
EST_METHOD(this)); \ |
304 blink::Platform::current()->currentThread()->enterRunLoop();
\ | 304 Platform::current()->currentThread()->enterRunLoop();
\ |
305 } | 305 } |
306 | 306 |
307 TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture) | 307 TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture) |
308 { | 308 { |
309 testEmptyPicture(); | 309 testEmptyPicture(); |
310 } | 310 } |
311 | 311 |
312 TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear) | 312 TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear) |
313 { | 313 { |
314 testNoFallbackWithClear(); | 314 testNoFallbackWithClear(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 } | 346 } |
347 | 347 |
348 DEFINE_TEST_TASK_WRAPPER_CLASS(testClearRect) | 348 DEFINE_TEST_TASK_WRAPPER_CLASS(testClearRect) |
349 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) | 349 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) |
350 { | 350 { |
351 CALL_TEST_TASK_WRAPPER(testClearRect); | 351 CALL_TEST_TASK_WRAPPER(testClearRect); |
352 expectDisplayListEnabled(true); | 352 expectDisplayListEnabled(true); |
353 } | 353 } |
354 | 354 |
355 } // namespace | 355 } // namespace |
OLD | NEW |