Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: Source/core/platform/graphics/chromium/Canvas2DLayerManagerTest.cpp

Issue 22929012: Change Canvas2DLayerBridge to stay alive until last mailbox is returned. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixing unit tests Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 class Canvas2DLayerManagerTest : public Test { 103 class Canvas2DLayerManagerTest : public Test {
104 protected: 104 protected:
105 void storageAllocationTrackingTest() 105 void storageAllocationTrackingTest()
106 { 106 {
107 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); 107 Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
108 manager.init(10, 10); 108 manager.init(10, 10);
109 { 109 {
110 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)); 110 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
111 OwnPtr<SkDeferredCanvas> canvas1 = createCanvas(context.get()); 111 OwnPtr<SkDeferredCanvas> canvas1 = createCanvas(context.get());
112 FakeCanvas2DLayerBridge layer1(context, canvas1.get()); 112 RefPtr<FakeCanvas2DLayerBridge> layer1 = adoptRef(new FakeCanvas2DLa yerBridge(context, canvas1.get()));
113 EXPECT_EQ((size_t)0, manager.m_bytesAllocated); 113 EXPECT_EQ((size_t)0, manager.m_bytesAllocated);
114 layer1.storageAllocatedForRecordingChanged(1); 114 layer1->storageAllocatedForRecordingChanged(1);
115 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); 115 EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
116 // Test allocation increase 116 // Test allocation increase
117 layer1.storageAllocatedForRecordingChanged(2); 117 layer1->storageAllocatedForRecordingChanged(2);
118 EXPECT_EQ((size_t)2, manager.m_bytesAllocated); 118 EXPECT_EQ((size_t)2, manager.m_bytesAllocated);
119 // Test allocation decrease 119 // Test allocation decrease
120 layer1.storageAllocatedForRecordingChanged(1); 120 layer1->storageAllocatedForRecordingChanged(1);
121 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); 121 EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
122 { 122 {
123 OwnPtr<SkDeferredCanvas> canvas2 = createCanvas(context.get()); 123 OwnPtr<SkDeferredCanvas> canvas2 = createCanvas(context.get());
124 FakeCanvas2DLayerBridge layer2(context, canvas2.get()); 124 RefPtr<FakeCanvas2DLayerBridge> layer2 = adoptRef(new FakeCanvas 2DLayerBridge(context, canvas2.get()));
125 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); 125 EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
126 // verify multi-layer allocation tracking 126 // verify multi-layer allocation tracking
127 layer2.storageAllocatedForRecordingChanged(2); 127 layer2->storageAllocatedForRecordingChanged(2);
128 EXPECT_EQ((size_t)3, manager.m_bytesAllocated); 128 EXPECT_EQ((size_t)3, manager.m_bytesAllocated);
129 } 129 }
130 // Verify tracking after destruction 130 // Verify tracking after destruction
131 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); 131 EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
132 } 132 }
133 } 133 }
134 134
135 void evictionTest() 135 void evictionTest()
136 { 136 {
137 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)); 137 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
138 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); 138 Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
139 manager.init(10, 5); 139 manager.init(10, 5);
140 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get()); 140 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get());
141 FakeCanvas2DLayerBridge layer(context, canvas.get()); 141 RefPtr<FakeCanvas2DLayerBridge> layer = adoptRef(new FakeCanvas2DLayerBr idge(context, canvas.get()));
142 layer.fakeFreeableBytes(10); 142 layer->fakeFreeableBytes(10);
143 layer.storageAllocatedForRecordingChanged(8); // under the max 143 layer->storageAllocatedForRecordingChanged(8); // under the max
144 EXPECT_EQ(0, layer.m_freeMemoryIfPossibleCount); 144 EXPECT_EQ(0, layer->m_freeMemoryIfPossibleCount);
145 layer.storageAllocatedForRecordingChanged(12); // over the max 145 layer->storageAllocatedForRecordingChanged(12); // over the max
146 EXPECT_EQ(1, layer.m_freeMemoryIfPossibleCount); 146 EXPECT_EQ(1, layer->m_freeMemoryIfPossibleCount);
147 EXPECT_EQ((size_t)3, layer.m_freeableBytes); 147 EXPECT_EQ((size_t)3, layer->m_freeableBytes);
148 EXPECT_EQ(0, layer.m_flushCount); // eviction succeeded without triggeri ng a flush 148 EXPECT_EQ(0, layer->m_flushCount); // eviction succeeded without trigger ing a flush
149 EXPECT_EQ((size_t)5, layer.bytesAllocated()); 149 EXPECT_EQ((size_t)5, layer->bytesAllocated());
150 } 150 }
151 151
152 void flushEvictionTest() 152 void flushEvictionTest()
153 { 153 {
154 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)); 154 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
155 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); 155 Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
156 manager.init(10, 5); 156 manager.init(10, 5);
157 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get()); 157 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get());
158 FakeCanvas2DLayerBridge layer(context, canvas.get()); 158 RefPtr<FakeCanvas2DLayerBridge> layer = adoptRef(new FakeCanvas2DLayerBr idge(context, canvas.get()));
159 layer.fakeFreeableBytes(1); // Not enough freeable bytes, will cause agg ressive eviction by flushing 159 layer->fakeFreeableBytes(1); // Not enough freeable bytes, will cause ag gressive eviction by flushing
160 layer.storageAllocatedForRecordingChanged(8); // under the max 160 layer->storageAllocatedForRecordingChanged(8); // under the max
161 EXPECT_EQ(0, layer.m_freeMemoryIfPossibleCount); 161 EXPECT_EQ(0, layer->m_freeMemoryIfPossibleCount);
162 layer.storageAllocatedForRecordingChanged(12); // over the max 162 layer->storageAllocatedForRecordingChanged(12); // over the max
163 EXPECT_EQ(2, layer.m_freeMemoryIfPossibleCount); // Two tries, one befor e flush, one after flush 163 EXPECT_EQ(2, layer->m_freeMemoryIfPossibleCount); // Two tries, one befo re flush, one after flush
164 EXPECT_EQ((size_t)0, layer.m_freeableBytes); 164 EXPECT_EQ((size_t)0, layer->m_freeableBytes);
165 EXPECT_EQ(1, layer.m_flushCount); // flush was attempted 165 EXPECT_EQ(1, layer->m_flushCount); // flush was attempted
166 EXPECT_EQ((size_t)11, layer.bytesAllocated()); // flush drops the layer from manager's tracking list 166 EXPECT_EQ((size_t)11, layer->bytesAllocated()); // flush drops the layer from manager's tracking list
167 EXPECT_FALSE(manager.isInList(&layer)); 167 EXPECT_FALSE(manager.isInList(layer.get()));
168 } 168 }
169 169
170 void doDeferredFrameTestTask(FakeCanvas2DLayerBridge* layer, bool skipComman ds) 170 void doDeferredFrameTestTask(FakeCanvas2DLayerBridge* layer, bool skipComman ds)
171 { 171 {
172 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 172 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
173 layer->contextAcquired(); 173 layer->contextAcquired();
174 layer->storageAllocatedForRecordingChanged(1); 174 layer->storageAllocatedForRecordingChanged(1);
175 EXPECT_TRUE(Canvas2DLayerManager::get().m_taskObserverActive); 175 EXPECT_TRUE(Canvas2DLayerManager::get().m_taskObserverActive);
176 if (skipCommands) { 176 if (skipCommands) {
177 layer->contextAcquired(); 177 layer->contextAcquired();
(...skipping 20 matching lines...) Expand all
198 Canvas2DLayerManagerTest* m_test; 198 Canvas2DLayerManagerTest* m_test;
199 FakeCanvas2DLayerBridge* m_layer; 199 FakeCanvas2DLayerBridge* m_layer;
200 bool m_skipCommands; 200 bool m_skipCommands;
201 }; 201 };
202 202
203 void deferredFrameTest() 203 void deferredFrameTest()
204 { 204 {
205 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)); 205 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
206 Canvas2DLayerManager::get().init(10, 10); 206 Canvas2DLayerManager::get().init(10, 10);
207 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get()); 207 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get());
208 FakeCanvas2DLayerBridge fakeLayer(context, canvas.get()); 208 RefPtr<FakeCanvas2DLayerBridge> fakeLayer = adoptRef(new FakeCanvas2DLay erBridge(context, canvas.get()));
209 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, &fakeLayer, true)); 209 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, fakeLayer.get(), true));
210 WebKit::Platform::current()->currentThread()->enterRunLoop(); 210 WebKit::Platform::current()->currentThread()->enterRunLoop();
211 // Verify that didProcessTask was called upon completion 211 // Verify that didProcessTask was called upon completion
212 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 212 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
213 // Verify that no flush was performed because frame is fresh 213 // Verify that no flush was performed because frame is fresh
214 EXPECT_EQ(0, fakeLayer.m_flushCount); 214 EXPECT_EQ(0, fakeLayer->m_flushCount);
215 215
216 // Verify that no flushes are triggered as long as frame are fresh 216 // Verify that no flushes are triggered as long as frame are fresh
217 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, &fakeLayer, true)); 217 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, fakeLayer.get(), true));
218 WebKit::Platform::current()->currentThread()->enterRunLoop(); 218 WebKit::Platform::current()->currentThread()->enterRunLoop();
219 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 219 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
220 EXPECT_EQ(0, fakeLayer.m_flushCount); 220 EXPECT_EQ(0, fakeLayer->m_flushCount);
221 221
222 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, &fakeLayer, true)); 222 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, fakeLayer.get(), true));
223 WebKit::Platform::current()->currentThread()->enterRunLoop(); 223 WebKit::Platform::current()->currentThread()->enterRunLoop();
224 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 224 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
225 EXPECT_EQ(0, fakeLayer.m_flushCount); 225 EXPECT_EQ(0, fakeLayer->m_flushCount);
226 226
227 // Verify that a flush is triggered when queue is accumulating a multi-f rame backlog. 227 // Verify that a flush is triggered when queue is accumulating a multi-f rame backlog.
228 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, &fakeLayer, false)); 228 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, fakeLayer.get(), false));
229 WebKit::Platform::current()->currentThread()->enterRunLoop(); 229 WebKit::Platform::current()->currentThread()->enterRunLoop();
230 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 230 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
231 EXPECT_EQ(1, fakeLayer.m_flushCount); 231 EXPECT_EQ(1, fakeLayer->m_flushCount);
232 232
233 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, &fakeLayer, false)); 233 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, fakeLayer.get(), false));
234 WebKit::Platform::current()->currentThread()->enterRunLoop(); 234 WebKit::Platform::current()->currentThread()->enterRunLoop();
235 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 235 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
236 EXPECT_EQ(2, fakeLayer.m_flushCount); 236 EXPECT_EQ(2, fakeLayer->m_flushCount);
237 } 237 }
238 }; 238 };
239 239
240 namespace { 240 namespace {
241 241
242 TEST_F(Canvas2DLayerManagerTest, testStorageAllocationTracking) 242 TEST_F(Canvas2DLayerManagerTest, testStorageAllocationTracking)
243 { 243 {
244 storageAllocationTrackingTest(); 244 storageAllocationTrackingTest();
245 } 245 }
246 246
247 TEST_F(Canvas2DLayerManagerTest, testEviction) 247 TEST_F(Canvas2DLayerManagerTest, testEviction)
248 { 248 {
249 evictionTest(); 249 evictionTest();
250 } 250 }
251 251
252 TEST_F(Canvas2DLayerManagerTest, testFlushEviction) 252 TEST_F(Canvas2DLayerManagerTest, testFlushEviction)
253 { 253 {
254 flushEvictionTest(); 254 flushEvictionTest();
255 } 255 }
256 256
257 TEST_F(Canvas2DLayerManagerTest, testDeferredFrame) 257 TEST_F(Canvas2DLayerManagerTest, testDeferredFrame)
258 { 258 {
259 deferredFrameTest(); 259 deferredFrameTest();
260 } 260 }
261 261
262 } // namespace 262 } // namespace
263 263
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698