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

Side by Side Diff: Source/WebKit/chromium/tests/Canvas2DLayerManagerTest.cpp

Issue 15301006: Merged GraphicsContext3DPrivate into GraphicsContext3D (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Removed ExtractWebGraphicsContext3D Created 7 years, 7 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 12 matching lines...) Expand all
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 26
27 #include "core/platform/graphics/chromium/Canvas2DLayerManager.h" 27 #include "core/platform/graphics/chromium/Canvas2DLayerManager.h"
28 28
29 #include <gmock/gmock.h> 29 #include <gmock/gmock.h>
30 #include <gtest/gtest.h> 30 #include <gtest/gtest.h>
31 #include "FakeWebGraphicsContext3D.h" 31 #include "FakeWebGraphicsContext3D.h"
32 #include "SkDevice.h" 32 #include "SkDevice.h"
33 #include "core/platform/chromium/support/GraphicsContext3DPrivate.h" 33 #include "core/platform/graphics/GraphicsContext3D.h"
34 #include <public/Platform.h> 34 #include <public/Platform.h>
35 #include <public/WebThread.h> 35 #include <public/WebThread.h>
36 36
37 using namespace WebCore; 37 using namespace WebCore;
38 using testing::InSequence; 38 using testing::InSequence;
39 using testing::Return; 39 using testing::Return;
40 using testing::Test; 40 using testing::Test;
41 41
42 42
43 class FakeCanvas2DLayerBridge : public Canvas2DLayerBridge { 43 class FakeCanvas2DLayerBridge : public Canvas2DLayerBridge {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return adoptPtr(new SkDeferredCanvas(device.get())); 92 return adoptPtr(new SkDeferredCanvas(device.get()));
93 } 93 }
94 94
95 class Canvas2DLayerManagerTest : public Test { 95 class Canvas2DLayerManagerTest : public Test {
96 protected: 96 protected:
97 void storageAllocationTrackingTest() 97 void storageAllocationTrackingTest()
98 { 98 {
99 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); 99 Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
100 manager.init(10, 10); 100 manager.init(10, 10);
101 { 101 {
102 RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::create GraphicsContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)); 102 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
103 OwnPtr<SkDeferredCanvas> canvas1 = createCanvas(context.get()); 103 OwnPtr<SkDeferredCanvas> canvas1 = createCanvas(context.get());
104 FakeCanvas2DLayerBridge layer1(context, canvas1.get()); 104 FakeCanvas2DLayerBridge layer1(context, canvas1.get());
105 EXPECT_EQ((size_t)0, manager.m_bytesAllocated); 105 EXPECT_EQ((size_t)0, manager.m_bytesAllocated);
106 layer1.storageAllocatedForRecordingChanged(1); 106 layer1.storageAllocatedForRecordingChanged(1);
107 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); 107 EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
108 // Test allocation increase 108 // Test allocation increase
109 layer1.storageAllocatedForRecordingChanged(2); 109 layer1.storageAllocatedForRecordingChanged(2);
110 EXPECT_EQ((size_t)2, manager.m_bytesAllocated); 110 EXPECT_EQ((size_t)2, manager.m_bytesAllocated);
111 // Test allocation decrease 111 // Test allocation decrease
112 layer1.storageAllocatedForRecordingChanged(1); 112 layer1.storageAllocatedForRecordingChanged(1);
113 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); 113 EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
114 { 114 {
115 OwnPtr<SkDeferredCanvas> canvas2 = createCanvas(context.get()); 115 OwnPtr<SkDeferredCanvas> canvas2 = createCanvas(context.get());
116 FakeCanvas2DLayerBridge layer2(context, canvas2.get()); 116 FakeCanvas2DLayerBridge layer2(context, canvas2.get());
117 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); 117 EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
118 // verify multi-layer allocation tracking 118 // verify multi-layer allocation tracking
119 layer2.storageAllocatedForRecordingChanged(2); 119 layer2.storageAllocatedForRecordingChanged(2);
120 EXPECT_EQ((size_t)3, manager.m_bytesAllocated); 120 EXPECT_EQ((size_t)3, manager.m_bytesAllocated);
121 } 121 }
122 // Verify tracking after destruction 122 // Verify tracking after destruction
123 EXPECT_EQ((size_t)1, manager.m_bytesAllocated); 123 EXPECT_EQ((size_t)1, manager.m_bytesAllocated);
124 } 124 }
125 } 125 }
126 126
127 void evictionTest() 127 void evictionTest()
128 { 128 {
129 RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::createGrap hicsContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)); 129 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
130 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); 130 Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
131 manager.init(10, 5); 131 manager.init(10, 5);
132 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get()); 132 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get());
133 FakeCanvas2DLayerBridge layer(context, canvas.get()); 133 FakeCanvas2DLayerBridge layer(context, canvas.get());
134 layer.fakeFreeableBytes(10); 134 layer.fakeFreeableBytes(10);
135 layer.storageAllocatedForRecordingChanged(8); // under the max 135 layer.storageAllocatedForRecordingChanged(8); // under the max
136 EXPECT_EQ(0, layer.m_freeMemoryIfPossibleCount); 136 EXPECT_EQ(0, layer.m_freeMemoryIfPossibleCount);
137 layer.storageAllocatedForRecordingChanged(12); // over the max 137 layer.storageAllocatedForRecordingChanged(12); // over the max
138 EXPECT_EQ(1, layer.m_freeMemoryIfPossibleCount); 138 EXPECT_EQ(1, layer.m_freeMemoryIfPossibleCount);
139 EXPECT_EQ((size_t)3, layer.m_freeableBytes); 139 EXPECT_EQ((size_t)3, layer.m_freeableBytes);
140 EXPECT_EQ(0, layer.m_flushCount); // eviction succeeded without triggeri ng a flush 140 EXPECT_EQ(0, layer.m_flushCount); // eviction succeeded without triggeri ng a flush
141 EXPECT_EQ((size_t)5, layer.bytesAllocated()); 141 EXPECT_EQ((size_t)5, layer.bytesAllocated());
142 } 142 }
143 143
144 void flushEvictionTest() 144 void flushEvictionTest()
145 { 145 {
146 RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::createGrap hicsContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)); 146 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
147 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); 147 Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
148 manager.init(10, 5); 148 manager.init(10, 5);
149 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get()); 149 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get());
150 FakeCanvas2DLayerBridge layer(context, canvas.get()); 150 FakeCanvas2DLayerBridge layer(context, canvas.get());
151 layer.fakeFreeableBytes(1); // Not enough freeable bytes, will cause agg ressive eviction by flushing 151 layer.fakeFreeableBytes(1); // Not enough freeable bytes, will cause agg ressive eviction by flushing
152 layer.storageAllocatedForRecordingChanged(8); // under the max 152 layer.storageAllocatedForRecordingChanged(8); // under the max
153 EXPECT_EQ(0, layer.m_freeMemoryIfPossibleCount); 153 EXPECT_EQ(0, layer.m_freeMemoryIfPossibleCount);
154 layer.storageAllocatedForRecordingChanged(12); // over the max 154 layer.storageAllocatedForRecordingChanged(12); // over the max
155 EXPECT_EQ(2, layer.m_freeMemoryIfPossibleCount); // Two tries, one befor e flush, one after flush 155 EXPECT_EQ(2, layer.m_freeMemoryIfPossibleCount); // Two tries, one befor e flush, one after flush
156 EXPECT_EQ((size_t)0, layer.m_freeableBytes); 156 EXPECT_EQ((size_t)0, layer.m_freeableBytes);
(...skipping 30 matching lines...) Expand all
187 m_test->doDeferredFrameTestTask(m_layer, m_skipCommands); 187 m_test->doDeferredFrameTestTask(m_layer, m_skipCommands);
188 } 188 }
189 private: 189 private:
190 Canvas2DLayerManagerTest* m_test; 190 Canvas2DLayerManagerTest* m_test;
191 FakeCanvas2DLayerBridge* m_layer; 191 FakeCanvas2DLayerBridge* m_layer;
192 bool m_skipCommands; 192 bool m_skipCommands;
193 }; 193 };
194 194
195 void deferredFrameTest() 195 void deferredFrameTest()
196 { 196 {
197 RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::createGrap hicsContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)); 197 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D));
198 Canvas2DLayerManager::get().init(10, 10); 198 Canvas2DLayerManager::get().init(10, 10);
199 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get()); 199 OwnPtr<SkDeferredCanvas> canvas = createCanvas(context.get());
200 FakeCanvas2DLayerBridge fakeLayer(context, canvas.get()); 200 FakeCanvas2DLayerBridge fakeLayer(context, canvas.get());
201 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, &fakeLayer, true)); 201 WebKit::Platform::current()->currentThread()->postTask(new DeferredFrame TestTask(this, &fakeLayer, true));
202 WebKit::Platform::current()->currentThread()->enterRunLoop(); 202 WebKit::Platform::current()->currentThread()->enterRunLoop();
203 // Verify that didProcessTask was called upon completion 203 // Verify that didProcessTask was called upon completion
204 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 204 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
205 // Verify that no flush was performed because frame is fresh 205 // Verify that no flush was performed because frame is fresh
206 EXPECT_EQ(0, fakeLayer.m_flushCount); 206 EXPECT_EQ(0, fakeLayer.m_flushCount);
207 207
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 flushEvictionTest(); 256 flushEvictionTest();
257 } 257 }
258 258
259 TEST_F(Canvas2DLayerManagerTest, testDeferredFrame) 259 TEST_F(Canvas2DLayerManagerTest, testDeferredFrame)
260 { 260 {
261 deferredFrameTest(); 261 deferredFrameTest();
262 } 262 }
263 263
264 } // namespace 264 } // namespace
265 265
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/tests/Canvas2DLayerBridgeTest.cpp ('k') | Source/WebKit/chromium/tests/DrawingBufferTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698