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

Side by Side Diff: cc/resource_update_controller_unittest.cc

Issue 11347019: cc: Maximize pending updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 1 month 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 | « cc/resource_update_controller.cc ('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 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 6
7 #include "cc/resource_update_controller.h" 7 #include "cc/resource_update_controller.h"
8 8
9 #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread 9 #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread
10 #include "cc/test/fake_web_compositor_output_surface.h" 10 #include "cc/test/fake_web_compositor_output_surface.h"
11 #include "cc/test/fake_web_graphics_context_3d.h" 11 #include "cc/test/fake_web_graphics_context_3d.h"
12 #include "cc/test/scheduler_test_common.h" 12 #include "cc/test/scheduler_test_common.h"
13 #include "cc/test/tiled_layer_test_common.h" 13 #include "cc/test/tiled_layer_test_common.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/khronos/GLES2/gl2ext.h"
15 16
16 using namespace cc; 17 using namespace cc;
17 using namespace WebKit; 18 using namespace WebKit;
18 using namespace WebKitTests; 19 using namespace WebKitTests;
19 using testing::Test; 20 using testing::Test;
20 21
21 namespace { 22 namespace {
22 23
23 const int kFlushPeriodFull = 4; 24 const int kFlushPeriodFull = 4;
24 const int kFlushPeriodPartial = kFlushPeriodFull; 25 const int kFlushPeriodPartial = kFlushPeriodFull;
(...skipping 20 matching lines...) Expand all
45 const void* pixels); 46 const void* pixels);
46 virtual GrGLInterface* onCreateGrGLInterface() { return 0; } 47 virtual GrGLInterface* onCreateGrGLInterface() { return 0; }
47 48
48 virtual WebString getString(WGC3Denum name) 49 virtual WebString getString(WGC3Denum name)
49 { 50 {
50 if (m_supportShallowFlush) 51 if (m_supportShallowFlush)
51 return WebString("GL_CHROMIUM_shallow_flush"); 52 return WebString("GL_CHROMIUM_shallow_flush");
52 return WebString(""); 53 return WebString("");
53 } 54 }
54 55
56 virtual void getQueryObjectuivEXT(WebGLId, WGC3Denum, WGC3Duint*);
57
55 private: 58 private:
56 ResourceUpdateControllerTest* m_test; 59 ResourceUpdateControllerTest* m_test;
57 bool m_supportShallowFlush; 60 bool m_supportShallowFlush;
58 }; 61 };
59 62
60 63
61 class ResourceUpdateControllerTest : public Test { 64 class ResourceUpdateControllerTest : public Test {
62 public: 65 public:
63 ResourceUpdateControllerTest() 66 ResourceUpdateControllerTest()
64 : m_queue(make_scoped_ptr(new ResourceUpdateQueue)) 67 : m_queue(make_scoped_ptr(new ResourceUpdateQueue))
65 , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool)) 68 , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool))
66 , m_fullUploadCountExpected(0) 69 , m_fullUploadCountExpected(0)
67 , m_partialCountExpected(0) 70 , m_partialCountExpected(0)
68 , m_totalUploadCountExpected(0) 71 , m_totalUploadCountExpected(0)
69 , m_maxUploadCountPerUpdate(0) 72 , m_maxUploadCountPerUpdate(0)
70 , m_numConsecutiveFlushes(0) 73 , m_numConsecutiveFlushes(0)
71 , m_numDanglingUploads(0) 74 , m_numDanglingUploads(0)
72 , m_numTotalUploads(0) 75 , m_numTotalUploads(0)
73 , m_numTotalFlushes(0) 76 , m_numTotalFlushes(0)
77 , m_queryResultsAvailable(0)
74 { 78 {
75 } 79 }
76 80
77 ~ResourceUpdateControllerTest() 81 ~ResourceUpdateControllerTest()
78 { 82 {
79 DebugScopedSetImplThreadAndMainThreadBlocked 83 DebugScopedSetImplThreadAndMainThreadBlocked
80 implThreadAndMainThreadBlocked; 84 implThreadAndMainThreadBlocked;
81 m_textureManager->clearAllMemory(m_resourceProvider.get()); 85 m_textureManager->clearAllMemory(m_resourceProvider.get());
82 } 86 }
83 87
(...skipping 14 matching lines...) Expand all
98 if (m_numTotalUploads < m_fullUploadCountExpected) 102 if (m_numTotalUploads < m_fullUploadCountExpected)
99 EXPECT_LT(m_numDanglingUploads, kFlushPeriodFull) << "Too many conse cutive full uploads detected."; 103 EXPECT_LT(m_numDanglingUploads, kFlushPeriodFull) << "Too many conse cutive full uploads detected.";
100 else 104 else
101 EXPECT_LT(m_numDanglingUploads, kFlushPeriodPartial) << "Too many co nsecutive partial uploads detected."; 105 EXPECT_LT(m_numDanglingUploads, kFlushPeriodPartial) << "Too many co nsecutive partial uploads detected.";
102 106
103 m_numConsecutiveFlushes = 0; 107 m_numConsecutiveFlushes = 0;
104 m_numDanglingUploads++; 108 m_numDanglingUploads++;
105 m_numTotalUploads++; 109 m_numTotalUploads++;
106 } 110 }
107 111
112 bool isQueryResultAvailable()
113 {
114 if (!m_queryResultsAvailable)
115 return false;
116
117 m_queryResultsAvailable--;
118 return true;
119 }
120
108 protected: 121 protected:
109 virtual void SetUp() 122 virtual void SetUp()
110 { 123 {
111 m_context = FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::We bGraphicsContext3D>(new WebGraphicsContext3DForUploadTest(this))); 124 m_context = FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::We bGraphicsContext3D>(new WebGraphicsContext3DForUploadTest(this)));
112 m_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 300, 150); 125 m_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 300, 150);
113 m_bitmap.allocPixels(); 126 m_bitmap.allocPixels();
114 127
115 for (int i = 0; i < 4; i++) { 128 for (int i = 0; i < 4; i++) {
116 m_textures[i] = PrioritizedTexture::create( 129 m_textures[i] = PrioritizedTexture::create(
117 m_textureManager.get(), gfx::Size(300, 150), GL_RGBA); 130 m_textureManager.get(), gfx::Size(300, 150), GL_RGBA);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 implThreadAndMainThreadBlocked; 183 implThreadAndMainThreadBlocked;
171 scoped_ptr<ResourceUpdateController> updateController = 184 scoped_ptr<ResourceUpdateController> updateController =
172 ResourceUpdateController::create( 185 ResourceUpdateController::create(
173 NULL, 186 NULL,
174 Proxy::implThread(), 187 Proxy::implThread(),
175 m_queue.Pass(), 188 m_queue.Pass(),
176 m_resourceProvider.get()); 189 m_resourceProvider.get());
177 updateController->finalize(); 190 updateController->finalize();
178 } 191 }
179 192
193 void makeQueryResultAvailable()
194 {
195 m_queryResultsAvailable++;
196 }
197
180 protected: 198 protected:
181 // Classes required to interact and test the ResourceUpdateController 199 // Classes required to interact and test the ResourceUpdateController
182 scoped_ptr<GraphicsContext> m_context; 200 scoped_ptr<GraphicsContext> m_context;
183 scoped_ptr<ResourceProvider> m_resourceProvider; 201 scoped_ptr<ResourceProvider> m_resourceProvider;
184 scoped_ptr<ResourceUpdateQueue> m_queue; 202 scoped_ptr<ResourceUpdateQueue> m_queue;
185 scoped_ptr<PrioritizedTexture> m_textures[4]; 203 scoped_ptr<PrioritizedTexture> m_textures[4];
186 scoped_ptr<PrioritizedTextureManager> m_textureManager; 204 scoped_ptr<PrioritizedTextureManager> m_textureManager;
187 SkBitmap m_bitmap; 205 SkBitmap m_bitmap;
206 int m_queryResultsAvailable;
188 207
189 // Properties / expectations of this test 208 // Properties / expectations of this test
190 int m_fullUploadCountExpected; 209 int m_fullUploadCountExpected;
191 int m_partialCountExpected; 210 int m_partialCountExpected;
192 int m_totalUploadCountExpected; 211 int m_totalUploadCountExpected;
193 int m_maxUploadCountPerUpdate; 212 int m_maxUploadCountPerUpdate;
194 213
195 // Dynamic properties of this test 214 // Dynamic properties of this test
196 int m_numConsecutiveFlushes; 215 int m_numConsecutiveFlushes;
197 int m_numDanglingUploads; 216 int m_numDanglingUploads;
(...skipping 17 matching lines...) Expand all
215 WGC3Dint yoffset, 234 WGC3Dint yoffset,
216 WGC3Dsizei width, 235 WGC3Dsizei width,
217 WGC3Dsizei height, 236 WGC3Dsizei height,
218 WGC3Denum format, 237 WGC3Denum format,
219 WGC3Denum type, 238 WGC3Denum type,
220 const void* pixels) 239 const void* pixels)
221 { 240 {
222 m_test->onUpload(); 241 m_test->onUpload();
223 } 242 }
224 243
244 void WebGraphicsContext3DForUploadTest::getQueryObjectuivEXT(
245 WebGLId,
246 WGC3Denum pname,
247 WGC3Duint* params) {
248 if (pname == GL_QUERY_RESULT_AVAILABLE_EXT)
249 *params = m_test->isQueryResultAvailable();
250 }
251
225 // ZERO UPLOADS TESTS 252 // ZERO UPLOADS TESTS
226 TEST_F(ResourceUpdateControllerTest, ZeroUploads) 253 TEST_F(ResourceUpdateControllerTest, ZeroUploads)
227 { 254 {
228 appendFullUploadsToUpdateQueue(0); 255 appendFullUploadsToUpdateQueue(0);
229 appendPartialUploadsToUpdateQueue(0); 256 appendPartialUploadsToUpdateQueue(0);
230 updateTextures(); 257 updateTextures();
231 258
232 EXPECT_EQ(0, m_numTotalFlushes); 259 EXPECT_EQ(0, m_numTotalFlushes);
233 EXPECT_EQ(0, m_numTotalUploads); 260 EXPECT_EQ(0, m_numTotalUploads);
234 } 261 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 controller->performMoreUpdates( 401 controller->performMoreUpdates(
375 controller->now() + base::TimeDelta::FromMilliseconds(90)); 402 controller->now() + base::TimeDelta::FromMilliseconds(90));
376 EXPECT_FALSE(thread.hasPendingTask()); 403 EXPECT_FALSE(thread.hasPendingTask());
377 404
378 controller->setUpdateMoreTexturesTime( 405 controller->setUpdateMoreTexturesTime(
379 base::TimeDelta::FromMilliseconds(100)); 406 base::TimeDelta::FromMilliseconds(100));
380 controller->setUpdateMoreTexturesSize(1); 407 controller->setUpdateMoreTexturesSize(1);
381 // Only enough time for 1 update. 408 // Only enough time for 1 update.
382 controller->performMoreUpdates( 409 controller->performMoreUpdates(
383 controller->now() + base::TimeDelta::FromMilliseconds(120)); 410 controller->now() + base::TimeDelta::FromMilliseconds(120));
384 runPendingTask(&thread, controller.get());
385 EXPECT_FALSE(thread.hasPendingTask()); 411 EXPECT_FALSE(thread.hasPendingTask());
386 EXPECT_EQ(1, m_numTotalUploads); 412 EXPECT_EQ(1, m_numTotalUploads);
387 413
414 // Complete one upload.
415 makeQueryResultAvailable();
416
388 controller->setUpdateMoreTexturesTime( 417 controller->setUpdateMoreTexturesTime(
389 base::TimeDelta::FromMilliseconds(100)); 418 base::TimeDelta::FromMilliseconds(100));
390 controller->setUpdateMoreTexturesSize(1); 419 controller->setUpdateMoreTexturesSize(1);
391 // Enough time for 2 updates. 420 // Enough time for 2 updates.
392 controller->performMoreUpdates( 421 controller->performMoreUpdates(
393 controller->now() + base::TimeDelta::FromMilliseconds(220)); 422 controller->now() + base::TimeDelta::FromMilliseconds(220));
394 runPendingTask(&thread, controller.get()); 423 runPendingTask(&thread, controller.get());
395 runPendingTask(&thread, controller.get());
396 EXPECT_FALSE(thread.hasPendingTask()); 424 EXPECT_FALSE(thread.hasPendingTask());
397 EXPECT_TRUE(client.readyToFinalizeCalled()); 425 EXPECT_TRUE(client.readyToFinalizeCalled());
398 EXPECT_EQ(3, m_numTotalUploads); 426 EXPECT_EQ(3, m_numTotalUploads);
399 } 427 }
400 428
401 TEST_F(ResourceUpdateControllerTest, NoMoreUpdates) 429 TEST_F(ResourceUpdateControllerTest, NoMoreUpdates)
402 { 430 {
403 FakeResourceUpdateControllerClient client; 431 FakeResourceUpdateControllerClient client;
404 FakeThread thread; 432 FakeThread thread;
405 433
406 setMaxUploadCountPerUpdate(1); 434 setMaxUploadCountPerUpdate(1);
407 appendFullUploadsToUpdateQueue(2); 435 appendFullUploadsToUpdateQueue(2);
408 appendPartialUploadsToUpdateQueue(0); 436 appendPartialUploadsToUpdateQueue(0);
409 437
410 DebugScopedSetImplThreadAndMainThreadBlocked 438 DebugScopedSetImplThreadAndMainThreadBlocked
411 implThreadAndMainThreadBlocked; 439 implThreadAndMainThreadBlocked;
412 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); 440 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
413 441
414 controller->setNow( 442 controller->setNow(
415 controller->now() + base::TimeDelta::FromMilliseconds(1)); 443 controller->now() + base::TimeDelta::FromMilliseconds(1));
416 controller->setUpdateMoreTexturesTime( 444 controller->setUpdateMoreTexturesTime(
417 base::TimeDelta::FromMilliseconds(100)); 445 base::TimeDelta::FromMilliseconds(100));
418 controller->setUpdateMoreTexturesSize(1); 446 controller->setUpdateMoreTexturesSize(1);
419 // Enough time for 3 updates but only 2 necessary. 447 // Enough time for 3 updates but only 2 necessary.
420 controller->performMoreUpdates( 448 controller->performMoreUpdates(
421 controller->now() + base::TimeDelta::FromMilliseconds(310)); 449 controller->now() + base::TimeDelta::FromMilliseconds(310));
422 runPendingTask(&thread, controller.get()); 450 runPendingTask(&thread, controller.get());
423 runPendingTask(&thread, controller.get());
424 EXPECT_FALSE(thread.hasPendingTask()); 451 EXPECT_FALSE(thread.hasPendingTask());
425 EXPECT_TRUE(client.readyToFinalizeCalled()); 452 EXPECT_TRUE(client.readyToFinalizeCalled());
426 EXPECT_EQ(2, m_numTotalUploads); 453 EXPECT_EQ(2, m_numTotalUploads);
427 454
428 controller->setUpdateMoreTexturesTime( 455 controller->setUpdateMoreTexturesTime(
429 base::TimeDelta::FromMilliseconds(100)); 456 base::TimeDelta::FromMilliseconds(100));
430 controller->setUpdateMoreTexturesSize(1); 457 controller->setUpdateMoreTexturesSize(1);
431 // Enough time for updates but no more updates left. 458 // Enough time for updates but no more updates left.
432 controller->performMoreUpdates( 459 controller->performMoreUpdates(
433 controller->now() + base::TimeDelta::FromMilliseconds(310)); 460 controller->now() + base::TimeDelta::FromMilliseconds(310));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 if (thread.hasPendingTask()) 495 if (thread.hasPendingTask())
469 runPendingTask(&thread, controller.get()); 496 runPendingTask(&thread, controller.get());
470 } 497 }
471 498
472 EXPECT_FALSE(thread.hasPendingTask()); 499 EXPECT_FALSE(thread.hasPendingTask());
473 EXPECT_TRUE(client.readyToFinalizeCalled()); 500 EXPECT_TRUE(client.readyToFinalizeCalled());
474 EXPECT_EQ(2, m_numTotalUploads); 501 EXPECT_EQ(2, m_numTotalUploads);
475 } 502 }
476 503
477 } // anonymous namespace 504 } // anonymous namespace
OLDNEW
« no previous file with comments | « cc/resource_update_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698