OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/CanvasSurfaceLayerBridge.h" | 5 #include "platform/graphics/CanvasSurfaceLayerBridge.h" |
6 | 6 |
7 #include "cc/surfaces/surface_id.h" | 7 #include "cc/surfaces/surface_id.h" |
8 #include "cc/surfaces/surface_sequence.h" | 8 #include "cc/surfaces/surface_sequence.h" |
9 #include "platform/graphics/CanvasSurfaceLayerBridgeClient.h" | 9 #include "platform/graphics/CanvasSurfaceLayerBridgeClient.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "wtf/PtrUtil.h" | 12 #include "wtf/PtrUtil.h" |
13 #include "wtf/Vector.h" | |
14 #include <memory> | 13 #include <memory> |
15 | 14 |
16 namespace blink { | 15 namespace blink { |
17 | 16 |
18 class FakeOffscreenCanvasSurfaceImpl { | 17 class FakeOffscreenCanvasSurfaceImpl { |
19 public: | 18 public: |
20 FakeOffscreenCanvasSurfaceImpl() {} | 19 FakeOffscreenCanvasSurfaceImpl() {} |
21 ~FakeOffscreenCanvasSurfaceImpl(); | 20 ~FakeOffscreenCanvasSurfaceImpl() {} |
22 | 21 |
23 bool GetSurfaceId(cc::SurfaceId*); | 22 bool GetSurfaceId(cc::SurfaceId*); |
24 void RequestSurfaceCreation(const cc::SurfaceId&); | |
25 | |
26 bool isSurfaceInSurfaceMap(const cc::SurfaceId&); | |
27 | |
28 private: | |
29 Vector<cc::SurfaceId> m_fakeSurfaceMap; | |
30 }; | 23 }; |
31 | 24 |
32 //----------------------------------------------------------------------------- | 25 //----------------------------------------------------------------------------- |
33 | 26 |
34 class MockCanvasSurfaceLayerBridgeClient final : public CanvasSurfaceLayerBridge
Client { | 27 class MockCanvasSurfaceLayerBridgeClient final : public CanvasSurfaceLayerBridge
Client { |
35 public: | 28 public: |
36 explicit MockCanvasSurfaceLayerBridgeClient(FakeOffscreenCanvasSurfaceImpl*)
; | 29 explicit MockCanvasSurfaceLayerBridgeClient(FakeOffscreenCanvasSurfaceImpl*)
; |
37 ~MockCanvasSurfaceLayerBridgeClient() override; | 30 ~MockCanvasSurfaceLayerBridgeClient() override; |
38 | 31 |
39 bool syncGetSurfaceId(cc::SurfaceId*) override; | 32 bool syncGetSurfaceId(cc::SurfaceId*) override; |
40 void asyncRequestSurfaceCreation(const cc::SurfaceId&) override; | |
41 void asyncRequire(const cc::SurfaceId&, const cc::SurfaceSequence&) override
{} | 33 void asyncRequire(const cc::SurfaceId&, const cc::SurfaceSequence&) override
{} |
42 void asyncSatisfy(const cc::SurfaceSequence&) override {} | 34 void asyncSatisfy(const cc::SurfaceSequence&) override {} |
43 | 35 |
44 private: | 36 private: |
45 FakeOffscreenCanvasSurfaceImpl* m_service; | 37 FakeOffscreenCanvasSurfaceImpl* m_service; |
46 cc::SurfaceId m_surfaceId; | 38 cc::SurfaceId m_surfaceId; |
47 }; | 39 }; |
48 | 40 |
49 //----------------------------------------------------------------------------- | 41 //----------------------------------------------------------------------------- |
50 | 42 |
(...skipping 19 matching lines...) Expand all Loading... |
70 | 62 |
71 MockCanvasSurfaceLayerBridgeClient::~MockCanvasSurfaceLayerBridgeClient() | 63 MockCanvasSurfaceLayerBridgeClient::~MockCanvasSurfaceLayerBridgeClient() |
72 { | 64 { |
73 } | 65 } |
74 | 66 |
75 bool MockCanvasSurfaceLayerBridgeClient::syncGetSurfaceId(cc::SurfaceId* surface
IdPtr) | 67 bool MockCanvasSurfaceLayerBridgeClient::syncGetSurfaceId(cc::SurfaceId* surface
IdPtr) |
76 { | 68 { |
77 return m_service->GetSurfaceId(surfaceIdPtr); | 69 return m_service->GetSurfaceId(surfaceIdPtr); |
78 } | 70 } |
79 | 71 |
80 void MockCanvasSurfaceLayerBridgeClient::asyncRequestSurfaceCreation(const cc::S
urfaceId& surfaceId) | |
81 { | |
82 m_service->RequestSurfaceCreation(surfaceId); | |
83 } | |
84 | |
85 FakeOffscreenCanvasSurfaceImpl::~FakeOffscreenCanvasSurfaceImpl() | |
86 { | |
87 m_fakeSurfaceMap.clear(); | |
88 } | |
89 | |
90 bool FakeOffscreenCanvasSurfaceImpl::GetSurfaceId(cc::SurfaceId* surfaceId) | 72 bool FakeOffscreenCanvasSurfaceImpl::GetSurfaceId(cc::SurfaceId* surfaceId) |
91 { | 73 { |
92 *surfaceId = cc::SurfaceId(10, 15, 0); | 74 *surfaceId = cc::SurfaceId(10, 15, 0); |
93 return true; | 75 return true; |
94 } | 76 } |
95 | 77 |
96 void FakeOffscreenCanvasSurfaceImpl::RequestSurfaceCreation(const cc::SurfaceId&
surfaceId) | |
97 { | |
98 m_fakeSurfaceMap.append(surfaceId); | |
99 } | |
100 | |
101 bool FakeOffscreenCanvasSurfaceImpl::isSurfaceInSurfaceMap(const cc::SurfaceId&
surfaceId) | |
102 { | |
103 return m_fakeSurfaceMap.contains(surfaceId); | |
104 } | |
105 | |
106 void CanvasSurfaceLayerBridgeTest::SetUp() | 78 void CanvasSurfaceLayerBridgeTest::SetUp() |
107 { | 79 { |
108 m_surfaceService = wrapUnique(new FakeOffscreenCanvasSurfaceImpl()); | 80 m_surfaceService = wrapUnique(new FakeOffscreenCanvasSurfaceImpl()); |
109 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w MockCanvasSurfaceLayerBridgeClient(m_surfaceService.get())); | 81 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w MockCanvasSurfaceLayerBridgeClient(m_surfaceService.get())); |
110 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); | 82 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); |
111 } | 83 } |
112 | 84 |
113 TEST_F(CanvasSurfaceLayerBridgeTest, SurfaceLayerCreation) | 85 TEST_F(CanvasSurfaceLayerBridgeTest, SurfaceLayerCreation) |
114 { | 86 { |
115 bool success = this->surfaceLayerBridge()->createSurfaceLayer(50, 50); | 87 bool success = this->surfaceLayerBridge()->createSurfaceLayer(50, 50); |
116 EXPECT_TRUE(this->surfaceService()->isSurfaceInSurfaceMap(this->surfaceLayer
Bridge()->getSurfaceId())); | |
117 EXPECT_TRUE(success); | 88 EXPECT_TRUE(success); |
118 } | 89 } |
119 | 90 |
120 } // namespace blink | 91 } // namespace blink |
OLD | NEW |