OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "cc/resources/single_release_callback.h" | 28 #include "cc/resources/single_release_callback.h" |
29 #include "cc/resources/texture_mailbox.h" | 29 #include "cc/resources/texture_mailbox.h" |
30 #include "cc/test/test_gpu_memory_buffer_manager.h" | 30 #include "cc/test/test_gpu_memory_buffer_manager.h" |
31 #include "gpu/command_buffer/client/gles2_interface.h" | 31 #include "gpu/command_buffer/client/gles2_interface.h" |
32 #include "gpu/command_buffer/common/capabilities.h" | 32 #include "gpu/command_buffer/common/capabilities.h" |
33 #include "platform/CrossThreadFunctional.h" | 33 #include "platform/CrossThreadFunctional.h" |
34 #include "platform/WaitableEvent.h" | 34 #include "platform/WaitableEvent.h" |
35 #include "platform/WebTaskRunner.h" | 35 #include "platform/WebTaskRunner.h" |
36 #include "platform/graphics/ImageBuffer.h" | 36 #include "platform/graphics/ImageBuffer.h" |
37 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 37 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 38 #include "platform/graphics/paint/PaintFlags.h" |
| 39 #include "platform/graphics/paint/PaintSurface.h" |
38 #include "platform/graphics/test/FakeGLES2Interface.h" | 40 #include "platform/graphics/test/FakeGLES2Interface.h" |
39 #include "platform/graphics/test/FakeWebGraphicsContext3DProvider.h" | 41 #include "platform/graphics/test/FakeWebGraphicsContext3DProvider.h" |
40 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
41 #include "public/platform/WebExternalBitmap.h" | 43 #include "public/platform/WebExternalBitmap.h" |
42 #include "public/platform/WebScheduler.h" | 44 #include "public/platform/WebScheduler.h" |
43 #include "public/platform/WebThread.h" | 45 #include "public/platform/WebThread.h" |
44 #include "public/platform/WebTraceLocation.h" | 46 #include "public/platform/WebTraceLocation.h" |
45 #include "skia/ext/texture_handle.h" | 47 #include "skia/ext/texture_handle.h" |
46 #include "testing/gmock/include/gmock/gmock.h" | 48 #include "testing/gmock/include/gmock/gmock.h" |
47 #include "testing/gtest/include/gtest/gtest.h" | 49 #include "testing/gtest/include/gtest/gtest.h" |
48 #include "third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h" | 50 #include "third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h" |
49 #include "third_party/skia/include/core/SkCanvas.h" | |
50 #include "third_party/skia/include/core/SkSurface.h" | |
51 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" | 51 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" |
52 #include "wtf/PtrUtil.h" | 52 #include "wtf/PtrUtil.h" |
53 #include "wtf/RefPtr.h" | 53 #include "wtf/RefPtr.h" |
54 | 54 |
55 #include <memory> | 55 #include <memory> |
56 | 56 |
57 using testing::AnyNumber; | 57 using testing::AnyNumber; |
58 using testing::AtLeast; | 58 using testing::AtLeast; |
59 using testing::InSequence; | 59 using testing::InSequence; |
60 using testing::Return; | 60 using testing::Return; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 void noDrawOnContextLostTest() { | 203 void noDrawOnContextLostTest() { |
204 FakeGLES2Interface gl; | 204 FakeGLES2Interface gl; |
205 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = | 205 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
206 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 206 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
207 | 207 |
208 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( | 208 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
209 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, | 209 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, |
210 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, | 210 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, |
211 kN32_SkColorType))); | 211 kN32_SkColorType))); |
212 EXPECT_TRUE(bridge->checkSurfaceValid()); | 212 EXPECT_TRUE(bridge->checkSurfaceValid()); |
213 SkPaint paint; | 213 PaintFlags paint; |
214 uint32_t genID = bridge->getOrCreateSurface()->generationID(); | 214 uint32_t genID = bridge->getOrCreateSurface()->generationID(); |
215 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 215 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
216 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); | 216 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); |
217 gl.setIsContextLost(true); | 217 gl.setIsContextLost(true); |
218 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); | 218 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); |
219 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 219 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
220 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); | 220 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); |
221 // This results in the internal surface being torn down in response to the | 221 // This results in the internal surface being torn down in response to the |
222 // context loss. | 222 // context loss. |
223 EXPECT_FALSE(bridge->checkSurfaceValid()); | 223 EXPECT_FALSE(bridge->checkSurfaceValid()); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 } | 330 } |
331 | 331 |
332 void accelerationHintTest() { | 332 void accelerationHintTest() { |
333 { | 333 { |
334 FakeGLES2Interface gl; | 334 FakeGLES2Interface gl; |
335 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = | 335 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
336 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 336 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
337 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( | 337 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
338 std::move(contextProvider), IntSize(300, 300), 0, NonOpaque, | 338 std::move(contextProvider), IntSize(300, 300), 0, NonOpaque, |
339 Canvas2DLayerBridge::EnableAcceleration, nullptr, kN32_SkColorType))); | 339 Canvas2DLayerBridge::EnableAcceleration, nullptr, kN32_SkColorType))); |
340 SkPaint paint; | 340 PaintFlags paint; |
341 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 341 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
342 sk_sp<SkImage> image = | 342 sk_sp<SkImage> image = |
343 bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnitTests); | 343 bridge->newImageSnapshot(PreferAcceleration, SnapshotReasonUnitTests); |
344 EXPECT_TRUE(bridge->checkSurfaceValid()); | 344 EXPECT_TRUE(bridge->checkSurfaceValid()); |
345 EXPECT_TRUE(bridge->isAccelerated()); | 345 EXPECT_TRUE(bridge->isAccelerated()); |
346 } | 346 } |
347 | 347 |
348 { | 348 { |
349 FakeGLES2Interface gl; | 349 FakeGLES2Interface gl; |
350 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = | 350 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
351 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 351 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
352 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( | 352 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
353 std::move(contextProvider), IntSize(300, 300), 0, NonOpaque, | 353 std::move(contextProvider), IntSize(300, 300), 0, NonOpaque, |
354 Canvas2DLayerBridge::EnableAcceleration, nullptr, kN32_SkColorType))); | 354 Canvas2DLayerBridge::EnableAcceleration, nullptr, kN32_SkColorType))); |
355 SkPaint paint; | 355 PaintFlags paint; |
356 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 356 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
357 sk_sp<SkImage> image = bridge->newImageSnapshot(PreferNoAcceleration, | 357 sk_sp<SkImage> image = bridge->newImageSnapshot(PreferNoAcceleration, |
358 SnapshotReasonUnitTests); | 358 SnapshotReasonUnitTests); |
359 EXPECT_TRUE(bridge->checkSurfaceValid()); | 359 EXPECT_TRUE(bridge->checkSurfaceValid()); |
360 EXPECT_FALSE(bridge->isAccelerated()); | 360 EXPECT_FALSE(bridge->isAccelerated()); |
361 } | 361 } |
362 } | 362 } |
363 }; | 363 }; |
364 | 364 |
365 TEST_F(Canvas2DLayerBridgeTest, FullLifecycleSingleThreaded) { | 365 TEST_F(Canvas2DLayerBridgeTest, FullLifecycleSingleThreaded) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 postSetIsHiddenTask(location, testThread, bridge, value, doneEvent.get()); | 488 postSetIsHiddenTask(location, testThread, bridge, value, doneEvent.get()); |
489 doneEvent->wait(); | 489 doneEvent->wait(); |
490 } | 490 } |
491 | 491 |
492 class MockImageBuffer : public ImageBuffer { | 492 class MockImageBuffer : public ImageBuffer { |
493 public: | 493 public: |
494 MockImageBuffer() | 494 MockImageBuffer() |
495 : ImageBuffer(WTF::wrapUnique( | 495 : ImageBuffer(WTF::wrapUnique( |
496 new UnacceleratedImageBufferSurface(IntSize(1, 1)))) {} | 496 new UnacceleratedImageBufferSurface(IntSize(1, 1)))) {} |
497 | 497 |
498 MOCK_CONST_METHOD1(resetCanvas, void(SkCanvas*)); | 498 MOCK_CONST_METHOD1(resetCanvas, void(PaintCanvas*)); |
499 | 499 |
500 virtual ~MockImageBuffer() {} | 500 virtual ~MockImageBuffer() {} |
501 }; | 501 }; |
502 | 502 |
503 #if CANVAS2D_HIBERNATION_ENABLED | 503 #if CANVAS2D_HIBERNATION_ENABLED |
504 TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycle) | 504 TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycle) |
505 #else | 505 #else |
506 TEST_F(Canvas2DLayerBridgeTest, DISABLED_HibernationLifeCycle) | 506 TEST_F(Canvas2DLayerBridgeTest, DISABLED_HibernationLifeCycle) |
507 #endif | 507 #endif |
508 { | 508 { |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); | 1366 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); |
1367 ::testing::Mock::VerifyAndClearExpectations(&gl); | 1367 ::testing::Mock::VerifyAndClearExpectations(&gl); |
1368 | 1368 |
1369 EXPECT_CALL(gl, Flush()).Times(1); | 1369 EXPECT_CALL(gl, Flush()).Times(1); |
1370 bridge->flushGpu(); | 1370 bridge->flushGpu(); |
1371 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); | 1371 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); |
1372 ::testing::Mock::VerifyAndClearExpectations(&gl); | 1372 ::testing::Mock::VerifyAndClearExpectations(&gl); |
1373 } | 1373 } |
1374 | 1374 |
1375 } // namespace blink | 1375 } // namespace blink |
OLD | NEW |