OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 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 | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 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 | 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 | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 | 26 |
27 #include "core/platform/graphics/Canvas2DLayerManager.h" | 27 #include "platform/graphics/Canvas2DLayerManager.h" |
28 | 28 |
29 #include "SkDevice.h" | 29 #include "SkDevice.h" |
30 #include "SkSurface.h" | 30 #include "SkSurface.h" |
31 #include "core/platform/graphics/GraphicsContext3D.h" | 31 #include "platform/graphics/GraphicsContext3D.h" |
32 #include "core/platform/testing/FakeWebGraphicsContext3D.h" | |
33 #include "public/platform/Platform.h" | 32 #include "public/platform/Platform.h" |
34 #include "public/platform/WebThread.h" | 33 #include "public/platform/WebThread.h" |
| 34 #include "web/tests/MockWebGraphicsContext3D.h" |
35 | 35 |
36 #include <gmock/gmock.h> | 36 #include <gmock/gmock.h> |
37 #include <gtest/gtest.h> | 37 #include <gtest/gtest.h> |
38 | 38 |
39 using namespace WebCore; | 39 using namespace WebCore; |
40 using testing::InSequence; | 40 using testing::InSequence; |
41 using testing::Return; | 41 using testing::Return; |
42 using testing::Test; | 42 using testing::Test; |
43 | 43 |
44 | 44 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 return static_cast<FakeCanvas2DLayerBridge*>(layer.get()); | 99 return static_cast<FakeCanvas2DLayerBridge*>(layer.get()); |
100 } | 100 } |
101 | 101 |
102 class Canvas2DLayerManagerTest : public Test { | 102 class Canvas2DLayerManagerTest : public Test { |
103 protected: | 103 protected: |
104 void storageAllocationTrackingTest() | 104 void storageAllocationTrackingTest() |
105 { | 105 { |
106 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); | 106 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); |
107 manager.init(10, 10); | 107 manager.init(10, 10); |
108 { | 108 { |
109 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphic
sContextFromWebContext(adoptPtr(new blink::FakeWebGraphicsContext3D)); | 109 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphic
sContextFromWebContext(adoptPtr(new blink::MockWebGraphicsContext3D)); |
110 RefPtr<SkDeferredCanvas> canvas1(createCanvas(context.get())); | 110 RefPtr<SkDeferredCanvas> canvas1(createCanvas(context.get())); |
111 Canvas2DLayerBridgePtr layer1(adoptRef(new FakeCanvas2DLayerBridge(c
ontext, canvas1.release()))); | 111 Canvas2DLayerBridgePtr layer1(adoptRef(new FakeCanvas2DLayerBridge(c
ontext, canvas1.release()))); |
112 EXPECT_EQ((size_t)0, manager.m_bytesAllocated); | 112 EXPECT_EQ((size_t)0, manager.m_bytesAllocated); |
113 layer1->storageAllocatedForRecordingChanged(1); | 113 layer1->storageAllocatedForRecordingChanged(1); |
114 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); | 114 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); |
115 // Test allocation increase | 115 // Test allocation increase |
116 layer1->storageAllocatedForRecordingChanged(2); | 116 layer1->storageAllocatedForRecordingChanged(2); |
117 EXPECT_EQ((size_t)2, manager.m_bytesAllocated); | 117 EXPECT_EQ((size_t)2, manager.m_bytesAllocated); |
118 // Test allocation decrease | 118 // Test allocation decrease |
119 layer1->storageAllocatedForRecordingChanged(1); | 119 layer1->storageAllocatedForRecordingChanged(1); |
120 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); | 120 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); |
121 { | 121 { |
122 RefPtr<SkDeferredCanvas> canvas2(createCanvas(context.get())); | 122 RefPtr<SkDeferredCanvas> canvas2(createCanvas(context.get())); |
123 Canvas2DLayerBridgePtr layer2(adoptRef(new FakeCanvas2DLayerBrid
ge(context, canvas2.release()))); | 123 Canvas2DLayerBridgePtr layer2(adoptRef(new FakeCanvas2DLayerBrid
ge(context, canvas2.release()))); |
124 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); | 124 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); |
125 // verify multi-layer allocation tracking | 125 // verify multi-layer allocation tracking |
126 layer2->storageAllocatedForRecordingChanged(2); | 126 layer2->storageAllocatedForRecordingChanged(2); |
127 EXPECT_EQ((size_t)3, manager.m_bytesAllocated); | 127 EXPECT_EQ((size_t)3, manager.m_bytesAllocated); |
128 } | 128 } |
129 // Verify tracking after destruction | 129 // Verify tracking after destruction |
130 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); | 130 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 void evictionTest() | 134 void evictionTest() |
135 { | 135 { |
136 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon
textFromWebContext(adoptPtr(new blink::FakeWebGraphicsContext3D)); | 136 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon
textFromWebContext(adoptPtr(new blink::MockWebGraphicsContext3D)); |
137 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); | 137 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); |
138 manager.init(10, 5); | 138 manager.init(10, 5); |
139 RefPtr<SkDeferredCanvas> canvas(createCanvas(context.get())); | 139 RefPtr<SkDeferredCanvas> canvas(createCanvas(context.get())); |
140 Canvas2DLayerBridgePtr layer(adoptRef(new FakeCanvas2DLayerBridge(contex
t, canvas.release()))); | 140 Canvas2DLayerBridgePtr layer(adoptRef(new FakeCanvas2DLayerBridge(contex
t, canvas.release()))); |
141 fake(layer)->fakeFreeableBytes(10); | 141 fake(layer)->fakeFreeableBytes(10); |
142 layer->storageAllocatedForRecordingChanged(8); // under the max | 142 layer->storageAllocatedForRecordingChanged(8); // under the max |
143 EXPECT_EQ(0, fake(layer)->m_freeMemoryIfPossibleCount); | 143 EXPECT_EQ(0, fake(layer)->m_freeMemoryIfPossibleCount); |
144 layer->storageAllocatedForRecordingChanged(12); // over the max | 144 layer->storageAllocatedForRecordingChanged(12); // over the max |
145 EXPECT_EQ(1, fake(layer)->m_freeMemoryIfPossibleCount); | 145 EXPECT_EQ(1, fake(layer)->m_freeMemoryIfPossibleCount); |
146 EXPECT_EQ((size_t)3, fake(layer)->m_freeableBytes); | 146 EXPECT_EQ((size_t)3, fake(layer)->m_freeableBytes); |
147 EXPECT_EQ(0, fake(layer)->m_flushCount); // eviction succeeded without t
riggering a flush | 147 EXPECT_EQ(0, fake(layer)->m_flushCount); // eviction succeeded without t
riggering a flush |
148 EXPECT_EQ((size_t)5, layer->bytesAllocated()); | 148 EXPECT_EQ((size_t)5, layer->bytesAllocated()); |
149 } | 149 } |
150 | 150 |
151 void flushEvictionTest() | 151 void flushEvictionTest() |
152 { | 152 { |
153 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon
textFromWebContext(adoptPtr(new blink::FakeWebGraphicsContext3D)); | 153 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon
textFromWebContext(adoptPtr(new blink::MockWebGraphicsContext3D)); |
154 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); | 154 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); |
155 manager.init(10, 5); | 155 manager.init(10, 5); |
156 RefPtr<SkDeferredCanvas> canvas(createCanvas(context.get())); | 156 RefPtr<SkDeferredCanvas> canvas(createCanvas(context.get())); |
157 Canvas2DLayerBridgePtr layer(adoptRef(new FakeCanvas2DLayerBridge(contex
t, canvas.release()))); | 157 Canvas2DLayerBridgePtr layer(adoptRef(new FakeCanvas2DLayerBridge(contex
t, canvas.release()))); |
158 fake(layer)->fakeFreeableBytes(1); // Not enough freeable bytes, will ca
use aggressive eviction by flushing | 158 fake(layer)->fakeFreeableBytes(1); // Not enough freeable bytes, will ca
use aggressive eviction by flushing |
159 layer->storageAllocatedForRecordingChanged(8); // under the max | 159 layer->storageAllocatedForRecordingChanged(8); // under the max |
160 EXPECT_EQ(0, fake(layer)->m_freeMemoryIfPossibleCount); | 160 EXPECT_EQ(0, fake(layer)->m_freeMemoryIfPossibleCount); |
161 layer->storageAllocatedForRecordingChanged(12); // over the max | 161 layer->storageAllocatedForRecordingChanged(12); // over the max |
162 EXPECT_EQ(2, fake(layer)->m_freeMemoryIfPossibleCount); // Two tries, on
e before flush, one after flush | 162 EXPECT_EQ(2, fake(layer)->m_freeMemoryIfPossibleCount); // Two tries, on
e before flush, one after flush |
163 EXPECT_EQ((size_t)0, fake(layer)->m_freeableBytes); | 163 EXPECT_EQ((size_t)0, fake(layer)->m_freeableBytes); |
(...skipping 30 matching lines...) Expand all Loading... |
194 m_test->doDeferredFrameTestTask(m_layer, m_skipCommands); | 194 m_test->doDeferredFrameTestTask(m_layer, m_skipCommands); |
195 } | 195 } |
196 private: | 196 private: |
197 Canvas2DLayerManagerTest* m_test; | 197 Canvas2DLayerManagerTest* m_test; |
198 FakeCanvas2DLayerBridge* m_layer; | 198 FakeCanvas2DLayerBridge* m_layer; |
199 bool m_skipCommands; | 199 bool m_skipCommands; |
200 }; | 200 }; |
201 | 201 |
202 void deferredFrameTest() | 202 void deferredFrameTest() |
203 { | 203 { |
204 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon
textFromWebContext(adoptPtr(new blink::FakeWebGraphicsContext3D)); | 204 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon
textFromWebContext(adoptPtr(new blink::MockWebGraphicsContext3D)); |
205 Canvas2DLayerManager::get().init(10, 10); | 205 Canvas2DLayerManager::get().init(10, 10); |
206 RefPtr<SkDeferredCanvas> canvas(createCanvas(context.get())); | 206 RefPtr<SkDeferredCanvas> canvas(createCanvas(context.get())); |
207 Canvas2DLayerBridgePtr layer(adoptRef(new FakeCanvas2DLayerBridge(contex
t, canvas.release()))); | 207 Canvas2DLayerBridgePtr layer(adoptRef(new FakeCanvas2DLayerBridge(contex
t, canvas.release()))); |
208 blink::Platform::current()->currentThread()->postTask(new DeferredFrameT
estTask(this, fake(layer), true)); | 208 blink::Platform::current()->currentThread()->postTask(new DeferredFrameT
estTask(this, fake(layer), true)); |
209 blink::Platform::current()->currentThread()->enterRunLoop(); | 209 blink::Platform::current()->currentThread()->enterRunLoop(); |
210 // Verify that didProcessTask was called upon completion | 210 // Verify that didProcessTask was called upon completion |
211 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); | 211 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); |
212 // Verify that no flush was performed because frame is fresh | 212 // Verify that no flush was performed because frame is fresh |
213 EXPECT_EQ(0, fake(layer)->m_flushCount); | 213 EXPECT_EQ(0, fake(layer)->m_flushCount); |
214 | 214 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 flushEvictionTest(); | 253 flushEvictionTest(); |
254 } | 254 } |
255 | 255 |
256 TEST_F(Canvas2DLayerManagerTest, testDeferredFrame) | 256 TEST_F(Canvas2DLayerManagerTest, testDeferredFrame) |
257 { | 257 { |
258 deferredFrameTest(); | 258 deferredFrameTest(); |
259 } | 259 } |
260 | 260 |
261 } // namespace | 261 } // namespace |
262 | 262 |
OLD | NEW |