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

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: Trivial fix for layout test failure Created 7 years, 3 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
« no previous file with comments | « Source/core/platform/graphics/chromium/Canvas2DLayerBridgeTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 { 93 {
94 SkImage::Info info = { 94 SkImage::Info info = {
95 1, 95 1,
96 1, 96 1,
97 SkImage::kPMColor_ColorType, 97 SkImage::kPMColor_ColorType,
98 SkImage::kPremul_AlphaType, 98 SkImage::kPremul_AlphaType,
99 }; 99 };
100 return adoptPtr(SkDeferredCanvas::Create(SkSurface::NewRaster(info))); 100 return adoptPtr(SkDeferredCanvas::Create(SkSurface::NewRaster(info)));
101 } 101 }
102 102
103 FakeCanvas2DLayerBridge* fake(const Canvas2DLayerBridgePtr& layer)
104 {
105 return static_cast<FakeCanvas2DLayerBridge*>(layer.get());
106 }
107
103 class Canvas2DLayerManagerTest : public Test { 108 class Canvas2DLayerManagerTest : public Test {
104 protected: 109 protected:
105 void storageAllocationTrackingTest() 110 void storageAllocationTrackingTest()
106 { 111 {
107 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); 112 Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
108 manager.init(10, 10); 113 manager.init(10, 10);
109 { 114 {
110 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)); 115 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
111 OwnPtr<SkDeferredCanvas> canvas1 = createCanvas(context.get()); 116 OwnPtr<SkDeferredCanvas> canvas1 = createCanvas(context.get());
112 FakeCanvas2DLayerBridge layer1(context, canvas1.get()); 117 Canvas2DLayerBridgePtr layer1(adoptRef(new FakeCanvas2DLayerBridge(c ontext, canvas1.get())));
113 EXPECT_EQ((size_t)0, manager.m_bytesAllocated); 118 EXPECT_EQ((size_t)0, manager.m_bytesAllocated);
114 layer1.storageAllocatedForRecordingChanged(1); 119 layer1->storageAllocatedForRecordingChanged(1);
115 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); 120 EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
116 // Test allocation increase 121 // Test allocation increase
117 layer1.storageAllocatedForRecordingChanged(2); 122 layer1->storageAllocatedForRecordingChanged(2);
118 EXPECT_EQ((size_t)2, manager.m_bytesAllocated); 123 EXPECT_EQ((size_t)2, manager.m_bytesAllocated);
119 // Test allocation decrease 124 // Test allocation decrease
120 layer1.storageAllocatedForRecordingChanged(1); 125 layer1->storageAllocatedForRecordingChanged(1);
121 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); 126 EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
122 { 127 {
123 OwnPtr<SkDeferredCanvas> canvas2 = createCanvas(context.get()); 128 OwnPtr<SkDeferredCanvas> canvas2 = createCanvas(context.get());
124 FakeCanvas2DLayerBridge layer2(context, canvas2.get()); 129 Canvas2DLayerBridgePtr layer2(adoptRef(new FakeCanvas2DLayerBrid ge(context, canvas2.get())));
125 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); 130 EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
126 // verify multi-layer allocation tracking 131 // verify multi-layer allocation tracking
127 layer2.storageAllocatedForRecordingChanged(2); 132 layer2->storageAllocatedForRecordingChanged(2);
128 EXPECT_EQ((size_t)3, manager.m_bytesAllocated); 133 EXPECT_EQ((size_t)3, manager.m_bytesAllocated);
129 } 134 }
130 // Verify tracking after destruction 135 // Verify tracking after destruction
131 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); 136 EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
132 } 137 }
133 } 138 }
134 139
135 void evictionTest() 140 void evictionTest()
136 { 141 {
137 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)); 142 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
138 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); 143 Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
139 manager.init(10, 5); 144 manager.init(10, 5);
140 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get()); 145 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get());
141 FakeCanvas2DLayerBridge layer(context, canvas.get()); 146 Canvas2DLayerBridgePtr layer(adoptRef(new FakeCanvas2DLayerBridge(contex t, canvas.get())));
142 layer.fakeFreeableBytes(10); 147 fake(layer)->fakeFreeableBytes(10);
143 layer.storageAllocatedForRecordingChanged(8); // under the max 148 layer->storageAllocatedForRecordingChanged(8); // under the max
144 EXPECT_EQ(0, layer.m_freeMemoryIfPossibleCount); 149 EXPECT_EQ(0, fake(layer)->m_freeMemoryIfPossibleCount);
145 layer.storageAllocatedForRecordingChanged(12); // over the max 150 layer->storageAllocatedForRecordingChanged(12); // over the max
146 EXPECT_EQ(1, layer.m_freeMemoryIfPossibleCount); 151 EXPECT_EQ(1, fake(layer)->m_freeMemoryIfPossibleCount);
147 EXPECT_EQ((size_t)3, layer.m_freeableBytes); 152 EXPECT_EQ((size_t)3, fake(layer)->m_freeableBytes);
148 EXPECT_EQ(0, layer.m_flushCount); // eviction succeeded without triggeri ng a flush 153 EXPECT_EQ(0, fake(layer)->m_flushCount); // eviction succeeded without t riggering a flush
149 EXPECT_EQ((size_t)5, layer.bytesAllocated()); 154 EXPECT_EQ((size_t)5, layer->bytesAllocated());
150 } 155 }
151 156
152 void flushEvictionTest() 157 void flushEvictionTest()
153 { 158 {
154 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)); 159 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
155 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); 160 Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
156 manager.init(10, 5); 161 manager.init(10, 5);
157 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get()); 162 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get());
158 FakeCanvas2DLayerBridge layer(context, canvas.get()); 163 Canvas2DLayerBridgePtr layer(adoptRef(new FakeCanvas2DLayerBridge(contex t, canvas.get())));
159 layer.fakeFreeableBytes(1); // Not enough freeable bytes, will cause agg ressive eviction by flushing 164 fake(layer)->fakeFreeableBytes(1); // Not enough freeable bytes, will ca use aggressive eviction by flushing
160 layer.storageAllocatedForRecordingChanged(8); // under the max 165 layer->storageAllocatedForRecordingChanged(8); // under the max
161 EXPECT_EQ(0, layer.m_freeMemoryIfPossibleCount); 166 EXPECT_EQ(0, fake(layer)->m_freeMemoryIfPossibleCount);
162 layer.storageAllocatedForRecordingChanged(12); // over the max 167 layer->storageAllocatedForRecordingChanged(12); // over the max
163 EXPECT_EQ(2, layer.m_freeMemoryIfPossibleCount); // Two tries, one befor e flush, one after flush 168 EXPECT_EQ(2, fake(layer)->m_freeMemoryIfPossibleCount); // Two tries, on e before flush, one after flush
164 EXPECT_EQ((size_t)0, layer.m_freeableBytes); 169 EXPECT_EQ((size_t)0, fake(layer)->m_freeableBytes);
165 EXPECT_EQ(1, layer.m_flushCount); // flush was attempted 170 EXPECT_EQ(1, fake(layer)->m_flushCount); // flush was attempted
166 EXPECT_EQ((size_t)11, layer.bytesAllocated()); // flush drops the layer from manager's tracking list 171 EXPECT_EQ((size_t)11, layer->bytesAllocated()); // flush drops the layer from manager's tracking list
167 EXPECT_FALSE(manager.isInList(&layer)); 172 EXPECT_FALSE(manager.isInList(layer.get()));
168 } 173 }
169 174
170 void doDeferredFrameTestTask(FakeCanvas2DLayerBridge* layer, bool skipComman ds) 175 void doDeferredFrameTestTask(FakeCanvas2DLayerBridge* layer, bool skipComman ds)
171 { 176 {
172 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 177 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
173 layer->contextAcquired(); 178 layer->contextAcquired();
174 layer->storageAllocatedForRecordingChanged(1); 179 layer->storageAllocatedForRecordingChanged(1);
175 EXPECT_TRUE(Canvas2DLayerManager::get().m_taskObserverActive); 180 EXPECT_TRUE(Canvas2DLayerManager::get().m_taskObserverActive);
176 if (skipCommands) { 181 if (skipCommands) {
177 layer->contextAcquired(); 182 layer->contextAcquired();
(...skipping 20 matching lines...) Expand all
198 Canvas2DLayerManagerTest* m_test; 203 Canvas2DLayerManagerTest* m_test;
199 FakeCanvas2DLayerBridge* m_layer; 204 FakeCanvas2DLayerBridge* m_layer;
200 bool m_skipCommands; 205 bool m_skipCommands;
201 }; 206 };
202 207
203 void deferredFrameTest() 208 void deferredFrameTest()
204 { 209 {
205 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)); 210 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
206 Canvas2DLayerManager::get().init(10, 10); 211 Canvas2DLayerManager::get().init(10, 10);
207 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get()); 212 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get());
208 FakeCanvas2DLayerBridge fakeLayer(context, canvas.get()); 213 Canvas2DLayerBridgePtr layer(adoptRef(new FakeCanvas2DLayerBridge(contex t, canvas.get())));
209 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, &fakeLayer, true)); 214 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, fake(layer), true));
210 WebKit::Platform::current()->currentThread()->enterRunLoop(); 215 WebKit::Platform::current()->currentThread()->enterRunLoop();
211 // Verify that didProcessTask was called upon completion 216 // Verify that didProcessTask was called upon completion
212 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 217 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
213 // Verify that no flush was performed because frame is fresh 218 // Verify that no flush was performed because frame is fresh
214 EXPECT_EQ(0, fakeLayer.m_flushCount); 219 EXPECT_EQ(0, fake(layer)->m_flushCount);
215 220
216 // Verify that no flushes are triggered as long as frame are fresh 221 // Verify that no flushes are triggered as long as frame are fresh
217 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, &fakeLayer, true)); 222 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, fake(layer), true));
218 WebKit::Platform::current()->currentThread()->enterRunLoop(); 223 WebKit::Platform::current()->currentThread()->enterRunLoop();
219 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 224 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
220 EXPECT_EQ(0, fakeLayer.m_flushCount); 225 EXPECT_EQ(0, fake(layer)->m_flushCount);
221 226
222 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, &fakeLayer, true)); 227 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, fake(layer), true));
223 WebKit::Platform::current()->currentThread()->enterRunLoop(); 228 WebKit::Platform::current()->currentThread()->enterRunLoop();
224 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 229 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
225 EXPECT_EQ(0, fakeLayer.m_flushCount); 230 EXPECT_EQ(0, fake(layer)->m_flushCount);
226 231
227 // Verify that a flush is triggered when queue is accumulating a multi-f rame backlog. 232 // 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)); 233 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, fake(layer), false));
229 WebKit::Platform::current()->currentThread()->enterRunLoop(); 234 WebKit::Platform::current()->currentThread()->enterRunLoop();
230 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 235 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
231 EXPECT_EQ(1, fakeLayer.m_flushCount); 236 EXPECT_EQ(1, fake(layer)->m_flushCount);
232 237
233 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, &fakeLayer, false)); 238 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, fake(layer), false));
234 WebKit::Platform::current()->currentThread()->enterRunLoop(); 239 WebKit::Platform::current()->currentThread()->enterRunLoop();
235 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 240 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
236 EXPECT_EQ(2, fakeLayer.m_flushCount); 241 EXPECT_EQ(2, fake(layer)->m_flushCount);
237 } 242 }
238 }; 243 };
239 244
240 namespace { 245 namespace {
241 246
242 TEST_F(Canvas2DLayerManagerTest, testStorageAllocationTracking) 247 TEST_F(Canvas2DLayerManagerTest, testStorageAllocationTracking)
243 { 248 {
244 storageAllocationTrackingTest(); 249 storageAllocationTrackingTest();
245 } 250 }
246 251
247 TEST_F(Canvas2DLayerManagerTest, testEviction) 252 TEST_F(Canvas2DLayerManagerTest, testEviction)
248 { 253 {
249 evictionTest(); 254 evictionTest();
250 } 255 }
251 256
252 TEST_F(Canvas2DLayerManagerTest, testFlushEviction) 257 TEST_F(Canvas2DLayerManagerTest, testFlushEviction)
253 { 258 {
254 flushEvictionTest(); 259 flushEvictionTest();
255 } 260 }
256 261
257 TEST_F(Canvas2DLayerManagerTest, testDeferredFrame) 262 TEST_F(Canvas2DLayerManagerTest, testDeferredFrame)
258 { 263 {
259 deferredFrameTest(); 264 deferredFrameTest();
260 } 265 }
261 266
262 } // namespace 267 } // namespace
263 268
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/chromium/Canvas2DLayerBridgeTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698