OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * 1. Redistributions of source code must retain the above copyright | |
8 * notice, this list of conditions and the following disclaimer. | |
9 * 2. Redistributions in binary form must reproduce the above copyright | |
10 * notice, this list of conditions and the following disclaimer in the | |
11 * documentation and/or other materials provided with the distribution. | |
12 * | |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | |
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | |
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
23 */ | |
24 | |
25 #include "config.h" | |
26 | |
27 #include "platform/graphics/Canvas2DLayerBridge.h" | |
28 | |
29 #include "SkDeferredCanvas.h" | |
30 #include "SkSurface.h" | |
31 #include "platform/graphics/ImageBuffer.h" | |
32 #include "public/platform/Platform.h" | |
33 #include "public/platform/WebExternalBitmap.h" | |
34 #include "public/platform/WebGraphicsContext3DProvider.h" | |
35 #include "public/platform/WebThread.h" | |
36 #include "third_party/skia/include/core/SkDevice.h" | |
37 #include "web/tests/MockWebGraphicsContext3D.h" | |
38 #include "wtf/RefPtr.h" | |
39 | |
40 #include <gmock/gmock.h> | |
41 #include <gtest/gtest.h> | |
42 | |
43 using namespace WebCore; | |
44 using namespace blink; | |
45 using testing::InSequence; | |
46 using testing::Return; | |
47 using testing::Test; | |
48 | |
49 namespace { | |
50 | |
51 class MockCanvasContext : public MockWebGraphicsContext3D { | |
52 public: | |
53 MOCK_METHOD0(flush, void(void)); | |
54 MOCK_METHOD0(createTexture, unsigned(void)); | |
55 MOCK_METHOD1(deleteTexture, void(unsigned)); | |
56 }; | |
57 | |
58 class MockWebGraphicsContext3DProvider : public WebGraphicsContext3DProvider { | |
59 public: | |
60 MockWebGraphicsContext3DProvider(WebGraphicsContext3D* context3d) | |
61 : m_context3d(context3d) { } | |
62 | |
63 WebGraphicsContext3D* context3d() | |
64 { | |
65 return m_context3d; | |
66 } | |
67 | |
68 GrContext* grContext() | |
69 { | |
70 return 0; | |
71 } | |
72 | |
73 private: | |
74 WebGraphicsContext3D* m_context3d; | |
75 }; | |
76 | |
77 class Canvas2DLayerBridgePtr { | |
78 public: | |
79 Canvas2DLayerBridgePtr(PassRefPtr<Canvas2DLayerBridge> layerBridge) | |
80 : m_layerBridge(layerBridge) { } | |
81 | |
82 ~Canvas2DLayerBridgePtr() | |
83 { | |
84 m_layerBridge->beginDestruction(); | |
85 } | |
86 | |
87 Canvas2DLayerBridge* operator->() { return m_layerBridge.get(); } | |
88 Canvas2DLayerBridge* get() { return m_layerBridge.get(); } | |
89 | |
90 private: | |
91 RefPtr<Canvas2DLayerBridge> m_layerBridge; | |
92 }; | |
93 | |
94 class NullWebExternalBitmap : public WebExternalBitmap { | |
95 public: | |
96 virtual WebSize size() | |
97 { | |
98 return WebSize(); | |
99 } | |
100 | |
101 virtual void setSize(WebSize) | |
102 { | |
103 } | |
104 | |
105 virtual uint8* pixels() | |
106 { | |
107 return 0; | |
108 } | |
109 }; | |
110 | |
111 } // namespace | |
112 | |
113 class Canvas2DLayerBridgeTest : public Test { | |
114 protected: | |
115 void fullLifecycleTest() | |
116 { | |
117 MockCanvasContext mainMock; | |
118 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); | |
119 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterPMColor(300, 15
0)); | |
120 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(surf
ace.get())); | |
121 | |
122 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
123 | |
124 { | |
125 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM
ockProvider.release(), canvas.release(), 0, NonOpaque))); | |
126 | |
127 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
128 | |
129 EXPECT_CALL(mainMock, flush()); | |
130 unsigned textureId = bridge->getBackingTexture(); | |
131 EXPECT_EQ(textureId, 0u); | |
132 | |
133 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
134 } // bridge goes out of scope here | |
135 | |
136 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
137 } | |
138 | |
139 void prepareMailboxWithBitmapTest() | |
140 { | |
141 MockCanvasContext mainMock; | |
142 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterPMColor(300, 15
0)); | |
143 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(surf
ace.get())); | |
144 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); | |
145 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainMockP
rovider.release(), canvas.release(), 0, NonOpaque))); | |
146 bridge->m_lastImageId = 1; | |
147 | |
148 NullWebExternalBitmap bitmap; | |
149 bridge->prepareMailbox(0, &bitmap); | |
150 EXPECT_EQ(0u, bridge->m_lastImageId); | |
151 } | |
152 }; | |
153 | |
154 namespace { | |
155 | |
156 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) | |
157 { | |
158 fullLifecycleTest(); | |
159 } | |
160 | |
161 TEST_F(Canvas2DLayerBridgeTest, prepareMailboxWithBitmapTest) | |
162 { | |
163 prepareMailboxWithBitmapTest(); | |
164 } | |
165 | |
166 } // namespace | |
OLD | NEW |