| 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 83dfa093a9c10d07469444f2e2a6dfe5bf4284a3..1cf2f89aeedea14f6c9a6ca570914655026be58f 100644
|
| --- a/Source/core/platform/graphics/chromium/Canvas2DLayerManagerTest.cpp
|
| +++ b/Source/core/platform/graphics/chromium/Canvas2DLayerManagerTest.cpp
|
| @@ -28,6 +28,7 @@
|
|
|
| #include "SkDevice.h"
|
| #include "core/platform/graphics/GraphicsContext3D.h"
|
| +#include "core/platform/graphics/chromium/Canvas2DLayerBridgeTestHelper.h"
|
| #include "core/tests/FakeWebGraphicsContext3D.h"
|
| #include "public/platform/Platform.h"
|
| #include "public/platform/WebThread.h"
|
| @@ -43,14 +44,6 @@ using testing::Test;
|
|
|
| class FakeCanvas2DLayerBridge : public Canvas2DLayerBridge {
|
| public:
|
| - FakeCanvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, SkDeferredCanvas* canvas)
|
| - : Canvas2DLayerBridge(context, canvas, NonOpaque)
|
| - , m_freeableBytes(0)
|
| - , m_freeMemoryIfPossibleCount(0)
|
| - , m_flushCount(0)
|
| - {
|
| - }
|
| -
|
| virtual size_t storageAllocatedForRecording() OVERRIDE
|
| {
|
| // Because the fake layer has no canvas to query, just
|
| @@ -82,17 +75,30 @@ public:
|
| m_flushCount++;
|
| }
|
|
|
| + static PassOwnPtr<FakeCanvas2DLayerBridge> create(const IntSize& size)
|
| + {
|
| + OwnPtr<Canvas2DLayerBridgeTestHelper> helper = adoptPtr(new Canvas2DLayerBridgeTestHelper);
|
| + bool success;
|
| + OwnPtr<FakeCanvas2DLayerBridge> bridge = adoptPtr(new FakeCanvas2DLayerBridge(helper.release(), size, &success));
|
| + if (!success)
|
| + bridge.clear();
|
| + return bridge.release();
|
| + }
|
| +
|
| public:
|
| size_t m_freeableBytes;
|
| int m_freeMemoryIfPossibleCount;
|
| int m_flushCount;
|
| -};
|
|
|
| -static PassOwnPtr<SkDeferredCanvas> createCanvas(GraphicsContext3D* context)
|
| -{
|
| - SkAutoTUnref<SkDevice> device(new SkDevice(SkBitmap::kARGB_8888_Config, 1, 1));
|
| - return adoptPtr(new SkDeferredCanvas(device.get()));
|
| -}
|
| +private:
|
| + FakeCanvas2DLayerBridge(PassOwnPtr<Canvas2DLayerBridge::Helper> helper, const IntSize& size, bool* success)
|
| + : Canvas2DLayerBridge(helper, size, NonOpaque, success)
|
| + , m_freeableBytes(0)
|
| + , m_freeMemoryIfPossibleCount(0)
|
| + , m_flushCount(0)
|
| + {
|
| + }
|
| +};
|
|
|
| class Canvas2DLayerManagerTest : public Test {
|
| protected:
|
| @@ -101,24 +107,21 @@ protected:
|
| Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
|
| manager.init(10, 10);
|
| {
|
| - RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
|
| - OwnPtr<SkDeferredCanvas> canvas1 = createCanvas(context.get());
|
| - FakeCanvas2DLayerBridge layer1(context, canvas1.get());
|
| + OwnPtr<FakeCanvas2DLayerBridge> layer1 = FakeCanvas2DLayerBridge::create(IntSize(1, 1));
|
| 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());
|
| + OwnPtr<FakeCanvas2DLayerBridge> layer2 = FakeCanvas2DLayerBridge::create(IntSize(1, 1));
|
| 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
|
| @@ -128,37 +131,33 @@ protected:
|
|
|
| void evictionTest()
|
| {
|
| - RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
|
| 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());
|
| + OwnPtr<FakeCanvas2DLayerBridge> layer = FakeCanvas2DLayerBridge::create(IntSize(1, 1));
|
| + 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()
|
| {
|
| - RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
|
| 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));
|
| + OwnPtr<FakeCanvas2DLayerBridge> layer = FakeCanvas2DLayerBridge::create(IntSize(1, 1));
|
| + 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)
|
| @@ -196,38 +195,36 @@ protected:
|
|
|
| void deferredFrameTest()
|
| {
|
| - 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));
|
| + OwnPtr<FakeCanvas2DLayerBridge> fakeLayer = FakeCanvas2DLayerBridge::create(IntSize(1, 1));
|
| + 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);
|
| }
|
| };
|
|
|
|
|