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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/platform/graphics/chromium/Canvas2DLayerManagerTest.cpp
diff --git a/Source/core/platform/graphics/chromium/Canvas2DLayerManagerTest.cpp b/Source/core/platform/graphics/chromium/Canvas2DLayerManagerTest.cpp
index 33e9ca69642579fbfb4e04a0152811091f6e91bb..969af3a8063f6905371a4d2912c0eb070130a700 100644
--- a/Source/core/platform/graphics/chromium/Canvas2DLayerManagerTest.cpp
+++ b/Source/core/platform/graphics/chromium/Canvas2DLayerManagerTest.cpp
@@ -109,22 +109,22 @@ protected:
{
RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
OwnPtr<SkDeferredCanvas> canvas1 = createCanvas(context.get());
- FakeCanvas2DLayerBridge layer1(context, canvas1.get());
+ RefPtr<FakeCanvas2DLayerBridge> layer1 = adoptRef(new FakeCanvas2DLayerBridge(context, canvas1.get()));
EXPECT_EQ((size_t)0, manager.m_bytesAllocated);
- layer1.storageAllocatedForRecordingChanged(1);
+ layer1->storageAllocatedForRecordingChanged(1);
EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
// Test allocation increase
- layer1.storageAllocatedForRecordingChanged(2);
+ layer1->storageAllocatedForRecordingChanged(2);
EXPECT_EQ((size_t)2, manager.m_bytesAllocated);
// Test allocation decrease
- layer1.storageAllocatedForRecordingChanged(1);
+ layer1->storageAllocatedForRecordingChanged(1);
EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
{
OwnPtr<SkDeferredCanvas> canvas2 = createCanvas(context.get());
- FakeCanvas2DLayerBridge layer2(context, canvas2.get());
+ RefPtr<FakeCanvas2DLayerBridge> layer2 = adoptRef(new FakeCanvas2DLayerBridge(context, canvas2.get()));
EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
// verify multi-layer allocation tracking
- layer2.storageAllocatedForRecordingChanged(2);
+ layer2->storageAllocatedForRecordingChanged(2);
EXPECT_EQ((size_t)3, manager.m_bytesAllocated);
}
// Verify tracking after destruction
@@ -138,15 +138,15 @@ protected:
Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
manager.init(10, 5);
OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get());
- FakeCanvas2DLayerBridge layer(context, canvas.get());
- layer.fakeFreeableBytes(10);
- layer.storageAllocatedForRecordingChanged(8); // under the max
- EXPECT_EQ(0, layer.m_freeMemoryIfPossibleCount);
- layer.storageAllocatedForRecordingChanged(12); // over the max
- EXPECT_EQ(1, layer.m_freeMemoryIfPossibleCount);
- EXPECT_EQ((size_t)3, layer.m_freeableBytes);
- EXPECT_EQ(0, layer.m_flushCount); // eviction succeeded without triggering a flush
- EXPECT_EQ((size_t)5, layer.bytesAllocated());
+ RefPtr<FakeCanvas2DLayerBridge> layer = adoptRef(new FakeCanvas2DLayerBridge(context, canvas.get()));
+ layer->fakeFreeableBytes(10);
+ layer->storageAllocatedForRecordingChanged(8); // under the max
+ EXPECT_EQ(0, layer->m_freeMemoryIfPossibleCount);
+ layer->storageAllocatedForRecordingChanged(12); // over the max
+ EXPECT_EQ(1, layer->m_freeMemoryIfPossibleCount);
+ EXPECT_EQ((size_t)3, layer->m_freeableBytes);
+ EXPECT_EQ(0, layer->m_flushCount); // eviction succeeded without triggering a flush
+ EXPECT_EQ((size_t)5, layer->bytesAllocated());
}
void flushEvictionTest()
@@ -155,16 +155,16 @@ protected:
Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
manager.init(10, 5);
OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get());
- FakeCanvas2DLayerBridge layer(context, canvas.get());
- layer.fakeFreeableBytes(1); // Not enough freeable bytes, will cause aggressive eviction by flushing
- layer.storageAllocatedForRecordingChanged(8); // under the max
- EXPECT_EQ(0, layer.m_freeMemoryIfPossibleCount);
- layer.storageAllocatedForRecordingChanged(12); // over the max
- EXPECT_EQ(2, layer.m_freeMemoryIfPossibleCount); // Two tries, one before flush, one after flush
- EXPECT_EQ((size_t)0, layer.m_freeableBytes);
- EXPECT_EQ(1, layer.m_flushCount); // flush was attempted
- EXPECT_EQ((size_t)11, layer.bytesAllocated()); // flush drops the layer from manager's tracking list
- EXPECT_FALSE(manager.isInList(&layer));
+ RefPtr<FakeCanvas2DLayerBridge> layer = adoptRef(new FakeCanvas2DLayerBridge(context, canvas.get()));
+ layer->fakeFreeableBytes(1); // Not enough freeable bytes, will cause aggressive eviction by flushing
+ layer->storageAllocatedForRecordingChanged(8); // under the max
+ EXPECT_EQ(0, layer->m_freeMemoryIfPossibleCount);
+ layer->storageAllocatedForRecordingChanged(12); // over the max
+ EXPECT_EQ(2, layer->m_freeMemoryIfPossibleCount); // Two tries, one before flush, one after flush
+ EXPECT_EQ((size_t)0, layer->m_freeableBytes);
+ EXPECT_EQ(1, layer->m_flushCount); // flush was attempted
+ EXPECT_EQ((size_t)11, layer->bytesAllocated()); // flush drops the layer from manager's tracking list
+ EXPECT_FALSE(manager.isInList(layer.get()));
}
void doDeferredFrameTestTask(FakeCanvas2DLayerBridge* layer, bool skipCommands)
@@ -205,35 +205,35 @@ protected:
RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
Canvas2DLayerManager::get().init(10, 10);
OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get());
- FakeCanvas2DLayerBridge fakeLayer(context, canvas.get());
- WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, &fakeLayer, true));
+ RefPtr<FakeCanvas2DLayerBridge> fakeLayer = adoptRef(new FakeCanvas2DLayerBridge(context, canvas.get()));
+ WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, fakeLayer.get(), true));
WebKit::Platform::current()->currentThread()->enterRunLoop();
// Verify that didProcessTask was called upon completion
EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
// Verify that no flush was performed because frame is fresh
- EXPECT_EQ(0, fakeLayer.m_flushCount);
+ EXPECT_EQ(0, fakeLayer->m_flushCount);
// Verify that no flushes are triggered as long as frame are fresh
- WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, &fakeLayer, true));
+ WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, fakeLayer.get(), true));
WebKit::Platform::current()->currentThread()->enterRunLoop();
EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
- EXPECT_EQ(0, fakeLayer.m_flushCount);
+ EXPECT_EQ(0, fakeLayer->m_flushCount);
- WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, &fakeLayer, true));
+ WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, fakeLayer.get(), true));
WebKit::Platform::current()->currentThread()->enterRunLoop();
EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
- EXPECT_EQ(0, fakeLayer.m_flushCount);
+ EXPECT_EQ(0, fakeLayer->m_flushCount);
// Verify that a flush is triggered when queue is accumulating a multi-frame backlog.
- WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, &fakeLayer, false));
+ WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, fakeLayer.get(), false));
WebKit::Platform::current()->currentThread()->enterRunLoop();
EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
- EXPECT_EQ(1, fakeLayer.m_flushCount);
+ EXPECT_EQ(1, fakeLayer->m_flushCount);
- WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, &fakeLayer, false));
+ WebKit::Platform::current()->currentThread()->postTask(new DeferredFrameTestTask(this, fakeLayer.get(), false));
WebKit::Platform::current()->currentThread()->enterRunLoop();
EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
- EXPECT_EQ(2, fakeLayer.m_flushCount);
+ EXPECT_EQ(2, fakeLayer->m_flushCount);
}
};

Powered by Google App Engine
This is Rietveld 408576698