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

Side by Side Diff: cc/resource_update_controller_unittest.cc

Issue 11232051: Remove static thread pointers from CC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Apply code review comments 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
« no previous file with comments | « cc/resource_update_controller.cc ('k') | cc/scoped_texture_unittest.cc » ('j') | 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_proxy.h"
10 #include "cc/test/fake_web_compositor_output_surface.h" 11 #include "cc/test/fake_web_compositor_output_surface.h"
11 #include "cc/test/fake_web_graphics_context_3d.h" 12 #include "cc/test/fake_web_graphics_context_3d.h"
12 #include "cc/test/scheduler_test_common.h" 13 #include "cc/test/scheduler_test_common.h"
13 #include "cc/test/tiled_layer_test_common.h" 14 #include "cc/test/tiled_layer_test_common.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/khronos/GLES2/gl2ext.h" 16 #include "third_party/khronos/GLES2/gl2ext.h"
16 17
17 using namespace cc; 18 using namespace cc;
18 using namespace WebKit; 19 using namespace WebKit;
19 using namespace WebKitTests; 20 using namespace WebKitTests;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 58
58 private: 59 private:
59 ResourceUpdateControllerTest* m_test; 60 ResourceUpdateControllerTest* m_test;
60 bool m_supportShallowFlush; 61 bool m_supportShallowFlush;
61 }; 62 };
62 63
63 64
64 class ResourceUpdateControllerTest : public Test { 65 class ResourceUpdateControllerTest : public Test {
65 public: 66 public:
66 ResourceUpdateControllerTest() 67 ResourceUpdateControllerTest()
67 : m_queue(make_scoped_ptr(new ResourceUpdateQueue)) 68 : m_proxy(scoped_ptr<Thread>(NULL))
68 , m_resourceManager(PrioritizedResourceManager::create(60*1024*1024, 102 4, Renderer::ContentPool)) 69 , m_queue(make_scoped_ptr(new ResourceUpdateQueue))
70 , m_resourceManager(PrioritizedResourceManager::create(60*1024*1024, 102 4, Renderer::ContentPool, &m_proxy))
69 , m_fullUploadCountExpected(0) 71 , m_fullUploadCountExpected(0)
70 , m_partialCountExpected(0) 72 , m_partialCountExpected(0)
71 , m_totalUploadCountExpected(0) 73 , m_totalUploadCountExpected(0)
72 , m_maxUploadCountPerUpdate(0) 74 , m_maxUploadCountPerUpdate(0)
73 , m_numConsecutiveFlushes(0) 75 , m_numConsecutiveFlushes(0)
74 , m_numDanglingUploads(0) 76 , m_numDanglingUploads(0)
75 , m_numTotalUploads(0) 77 , m_numTotalUploads(0)
76 , m_numTotalFlushes(0) 78 , m_numTotalFlushes(0)
77 , m_queryResultsAvailable(0) 79 , m_queryResultsAvailable(0)
78 { 80 {
79 } 81 }
80 82
81 ~ResourceUpdateControllerTest() 83 ~ResourceUpdateControllerTest()
82 { 84 {
83 DebugScopedSetImplThreadAndMainThreadBlocked 85 DebugScopedSetImplThreadAndMainThreadBlocked
84 implThreadAndMainThreadBlocked; 86 implThreadAndMainThreadBlocked(&m_proxy);
85 m_resourceManager->clearAllMemory(m_resourceProvider.get()); 87 m_resourceManager->clearAllMemory(m_resourceProvider.get());
86 } 88 }
87 89
88 public: 90 public:
89 void onFlush() 91 void onFlush()
90 { 92 {
91 // Check for back-to-back flushes. 93 // Check for back-to-back flushes.
92 EXPECT_EQ(0, m_numConsecutiveFlushes) << "Back-to-back flushes detected. "; 94 EXPECT_EQ(0, m_numConsecutiveFlushes) << "Back-to-back flushes detected. ";
93 95
94 m_numDanglingUploads = 0; 96 m_numDanglingUploads = 0;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 m_bitmap.allocPixels(); 128 m_bitmap.allocPixels();
127 129
128 for (int i = 0; i < 4; i++) { 130 for (int i = 0; i < 4; i++) {
129 m_textures[i] = PrioritizedResource::create( 131 m_textures[i] = PrioritizedResource::create(
130 m_resourceManager.get(), gfx::Size(300, 150), GL_RGBA); 132 m_resourceManager.get(), gfx::Size(300, 150), GL_RGBA);
131 m_textures[i]->setRequestPriority( 133 m_textures[i]->setRequestPriority(
132 PriorityCalculator::visiblePriority(true)); 134 PriorityCalculator::visiblePriority(true));
133 } 135 }
134 m_resourceManager->prioritizeTextures(); 136 m_resourceManager->prioritizeTextures();
135 137
136 DebugScopedSetImplThread implThread;
137 m_resourceProvider = ResourceProvider::create(m_context.get()); 138 m_resourceProvider = ResourceProvider::create(m_context.get());
138 } 139 }
139 140
140 141
141 void appendFullUploadsOfIndexedTextureToUpdateQueue(int count, int textureIn dex) 142 void appendFullUploadsOfIndexedTextureToUpdateQueue(int count, int textureIn dex)
142 { 143 {
143 m_fullUploadCountExpected += count; 144 m_fullUploadCountExpected += count;
144 m_totalUploadCountExpected += count; 145 m_totalUploadCountExpected += count;
145 146
146 const gfx::Rect rect(0, 0, 300, 150); 147 const gfx::Rect rect(0, 0, 300, 150);
(...skipping 26 matching lines...) Expand all
173 } 174 }
174 175
175 void setMaxUploadCountPerUpdate(int count) 176 void setMaxUploadCountPerUpdate(int count)
176 { 177 {
177 m_maxUploadCountPerUpdate = count; 178 m_maxUploadCountPerUpdate = count;
178 } 179 }
179 180
180 void updateTextures() 181 void updateTextures()
181 { 182 {
182 DebugScopedSetImplThreadAndMainThreadBlocked 183 DebugScopedSetImplThreadAndMainThreadBlocked
183 implThreadAndMainThreadBlocked; 184 implThreadAndMainThreadBlocked(&m_proxy);
184 scoped_ptr<ResourceUpdateController> updateController = 185 scoped_ptr<ResourceUpdateController> updateController =
185 ResourceUpdateController::create( 186 ResourceUpdateController::create(
186 NULL, 187 NULL,
187 Proxy::implThread(), 188 m_proxy.implThread(),
188 m_queue.Pass(), 189 m_queue.Pass(),
189 m_resourceProvider.get()); 190 m_resourceProvider.get(),
191 m_proxy.hasImplThread());
190 updateController->finalize(); 192 updateController->finalize();
191 } 193 }
192 194
193 void makeQueryResultAvailable() 195 void makeQueryResultAvailable()
194 { 196 {
195 m_queryResultsAvailable++; 197 m_queryResultsAvailable++;
196 } 198 }
197 199
198 protected: 200 protected:
199 // Classes required to interact and test the ResourceUpdateController 201 // Classes required to interact and test the ResourceUpdateController
202 FakeProxy m_proxy;
200 scoped_ptr<GraphicsContext> m_context; 203 scoped_ptr<GraphicsContext> m_context;
201 scoped_ptr<ResourceProvider> m_resourceProvider; 204 scoped_ptr<ResourceProvider> m_resourceProvider;
202 scoped_ptr<ResourceUpdateQueue> m_queue; 205 scoped_ptr<ResourceUpdateQueue> m_queue;
203 scoped_ptr<PrioritizedResource> m_textures[4]; 206 scoped_ptr<PrioritizedResource> m_textures[4];
204 scoped_ptr<PrioritizedResourceManager> m_resourceManager; 207 scoped_ptr<PrioritizedResourceManager> m_resourceManager;
205 SkBitmap m_bitmap; 208 SkBitmap m_bitmap;
206 int m_queryResultsAvailable; 209 int m_queryResultsAvailable;
207 210
208 // Properties / expectations of this test 211 // Properties / expectations of this test
209 int m_fullUploadCountExpected; 212 int m_fullUploadCountExpected;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 360
358 void setNow(base::TimeTicks time) { m_now = time; } 361 void setNow(base::TimeTicks time) { m_now = time; }
359 virtual base::TimeTicks now() const OVERRIDE { return m_now; } 362 virtual base::TimeTicks now() const OVERRIDE { return m_now; }
360 void setUpdateMoreTexturesTime(base::TimeDelta time) { m_updateMoreTexturesT ime = time; } 363 void setUpdateMoreTexturesTime(base::TimeDelta time) { m_updateMoreTexturesT ime = time; }
361 virtual base::TimeDelta updateMoreTexturesTime() const OVERRIDE { return m_u pdateMoreTexturesTime; } 364 virtual base::TimeDelta updateMoreTexturesTime() const OVERRIDE { return m_u pdateMoreTexturesTime; }
362 void setUpdateMoreTexturesSize(size_t size) { m_updateMoreTexturesSize = siz e; } 365 void setUpdateMoreTexturesSize(size_t size) { m_updateMoreTexturesSize = siz e; }
363 virtual size_t updateMoreTexturesSize() const OVERRIDE { return m_updateMore TexturesSize; } 366 virtual size_t updateMoreTexturesSize() const OVERRIDE { return m_updateMore TexturesSize; }
364 367
365 protected: 368 protected:
366 FakeResourceUpdateController(cc::ResourceUpdateControllerClient* client, cc: :Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resour ceProvider) 369 FakeResourceUpdateController(cc::ResourceUpdateControllerClient* client, cc: :Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resour ceProvider)
367 : cc::ResourceUpdateController(client, thread, queue.Pass(), resourcePro vider) 370 : cc::ResourceUpdateController(client, thread, queue.Pass(), resourcePro vider, false)
368 , m_updateMoreTexturesSize(0) { } 371 , m_updateMoreTexturesSize(0) { }
369 372
370 base::TimeTicks m_now; 373 base::TimeTicks m_now;
371 base::TimeDelta m_updateMoreTexturesTime; 374 base::TimeDelta m_updateMoreTexturesTime;
372 size_t m_updateMoreTexturesSize; 375 size_t m_updateMoreTexturesSize;
373 }; 376 };
374 377
375 static void runPendingTask(FakeThread* thread, FakeResourceUpdateController* con troller) 378 static void runPendingTask(FakeThread* thread, FakeResourceUpdateController* con troller)
376 { 379 {
377 EXPECT_TRUE(thread->hasPendingTask()); 380 EXPECT_TRUE(thread->hasPendingTask());
378 controller->setNow(controller->now() + base::TimeDelta::FromMilliseconds(thr ead->pendingDelayMs())); 381 controller->setNow(controller->now() + base::TimeDelta::FromMilliseconds(thr ead->pendingDelayMs()));
379 thread->runPendingTask(); 382 thread->runPendingTask();
380 } 383 }
381 384
382 TEST_F(ResourceUpdateControllerTest, UpdateMoreTextures) 385 TEST_F(ResourceUpdateControllerTest, UpdateMoreTextures)
383 { 386 {
384 FakeResourceUpdateControllerClient client; 387 FakeResourceUpdateControllerClient client;
385 FakeThread thread; 388 FakeThread thread;
386 389
387 setMaxUploadCountPerUpdate(1); 390 setMaxUploadCountPerUpdate(1);
388 appendFullUploadsToUpdateQueue(3); 391 appendFullUploadsToUpdateQueue(3);
389 appendPartialUploadsToUpdateQueue(0); 392 appendPartialUploadsToUpdateQueue(0);
390 393
391 DebugScopedSetImplThreadAndMainThreadBlocked 394 DebugScopedSetImplThreadAndMainThreadBlocked
392 implThreadAndMainThreadBlocked; 395 implThreadAndMainThreadBlocked(&m_proxy);
393 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); 396 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
394 397
395 controller->setNow( 398 controller->setNow(
396 controller->now() + base::TimeDelta::FromMilliseconds(1)); 399 controller->now() + base::TimeDelta::FromMilliseconds(1));
397 controller->setUpdateMoreTexturesTime( 400 controller->setUpdateMoreTexturesTime(
398 base::TimeDelta::FromMilliseconds(100)); 401 base::TimeDelta::FromMilliseconds(100));
399 controller->setUpdateMoreTexturesSize(1); 402 controller->setUpdateMoreTexturesSize(1);
400 // Not enough time for any updates. 403 // Not enough time for any updates.
401 controller->performMoreUpdates( 404 controller->performMoreUpdates(
402 controller->now() + base::TimeDelta::FromMilliseconds(90)); 405 controller->now() + base::TimeDelta::FromMilliseconds(90));
(...skipping 26 matching lines...) Expand all
429 TEST_F(ResourceUpdateControllerTest, NoMoreUpdates) 432 TEST_F(ResourceUpdateControllerTest, NoMoreUpdates)
430 { 433 {
431 FakeResourceUpdateControllerClient client; 434 FakeResourceUpdateControllerClient client;
432 FakeThread thread; 435 FakeThread thread;
433 436
434 setMaxUploadCountPerUpdate(1); 437 setMaxUploadCountPerUpdate(1);
435 appendFullUploadsToUpdateQueue(2); 438 appendFullUploadsToUpdateQueue(2);
436 appendPartialUploadsToUpdateQueue(0); 439 appendPartialUploadsToUpdateQueue(0);
437 440
438 DebugScopedSetImplThreadAndMainThreadBlocked 441 DebugScopedSetImplThreadAndMainThreadBlocked
439 implThreadAndMainThreadBlocked; 442 implThreadAndMainThreadBlocked(&m_proxy);
440 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); 443 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
441 444
442 controller->setNow( 445 controller->setNow(
443 controller->now() + base::TimeDelta::FromMilliseconds(1)); 446 controller->now() + base::TimeDelta::FromMilliseconds(1));
444 controller->setUpdateMoreTexturesTime( 447 controller->setUpdateMoreTexturesTime(
445 base::TimeDelta::FromMilliseconds(100)); 448 base::TimeDelta::FromMilliseconds(100));
446 controller->setUpdateMoreTexturesSize(1); 449 controller->setUpdateMoreTexturesSize(1);
447 // Enough time for 3 updates but only 2 necessary. 450 // Enough time for 3 updates but only 2 necessary.
448 controller->performMoreUpdates( 451 controller->performMoreUpdates(
449 controller->now() + base::TimeDelta::FromMilliseconds(310)); 452 controller->now() + base::TimeDelta::FromMilliseconds(310));
(...skipping 18 matching lines...) Expand all
468 TEST_F(ResourceUpdateControllerTest, UpdatesCompleteInFiniteTime) 471 TEST_F(ResourceUpdateControllerTest, UpdatesCompleteInFiniteTime)
469 { 472 {
470 FakeResourceUpdateControllerClient client; 473 FakeResourceUpdateControllerClient client;
471 FakeThread thread; 474 FakeThread thread;
472 475
473 setMaxUploadCountPerUpdate(1); 476 setMaxUploadCountPerUpdate(1);
474 appendFullUploadsToUpdateQueue(2); 477 appendFullUploadsToUpdateQueue(2);
475 appendPartialUploadsToUpdateQueue(0); 478 appendPartialUploadsToUpdateQueue(0);
476 479
477 DebugScopedSetImplThreadAndMainThreadBlocked 480 DebugScopedSetImplThreadAndMainThreadBlocked
478 implThreadAndMainThreadBlocked; 481 implThreadAndMainThreadBlocked(&m_proxy);
479 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); 482 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
480 483
481 controller->setNow( 484 controller->setNow(
482 controller->now() + base::TimeDelta::FromMilliseconds(1)); 485 controller->now() + base::TimeDelta::FromMilliseconds(1));
483 controller->setUpdateMoreTexturesTime( 486 controller->setUpdateMoreTexturesTime(
484 base::TimeDelta::FromMilliseconds(500)); 487 base::TimeDelta::FromMilliseconds(500));
485 controller->setUpdateMoreTexturesSize(1); 488 controller->setUpdateMoreTexturesSize(1);
486 489
487 for (int i = 0; i < 100; i++) { 490 for (int i = 0; i < 100; i++) {
488 if (client.readyToFinalizeCalled()) 491 if (client.readyToFinalizeCalled())
489 break; 492 break;
490 493
491 // Not enough time for any updates. 494 // Not enough time for any updates.
492 controller->performMoreUpdates( 495 controller->performMoreUpdates(
493 controller->now() + base::TimeDelta::FromMilliseconds(400)); 496 controller->now() + base::TimeDelta::FromMilliseconds(400));
494 497
495 if (thread.hasPendingTask()) 498 if (thread.hasPendingTask())
496 runPendingTask(&thread, controller.get()); 499 runPendingTask(&thread, controller.get());
497 } 500 }
498 501
499 EXPECT_FALSE(thread.hasPendingTask()); 502 EXPECT_FALSE(thread.hasPendingTask());
500 EXPECT_TRUE(client.readyToFinalizeCalled()); 503 EXPECT_TRUE(client.readyToFinalizeCalled());
501 EXPECT_EQ(2, m_numTotalUploads); 504 EXPECT_EQ(2, m_numTotalUploads);
502 } 505 }
503 506
504 } // anonymous namespace 507 } // anonymous namespace
OLDNEW
« no previous file with comments | « cc/resource_update_controller.cc ('k') | cc/scoped_texture_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698