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

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: Rebase to 165064 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
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 <public/WebThread.h> 16 #include <public/WebThread.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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 57
57 private: 58 private:
58 ResourceUpdateControllerTest* m_test; 59 ResourceUpdateControllerTest* m_test;
59 bool m_supportShallowFlush; 60 bool m_supportShallowFlush;
60 }; 61 };
61 62
62 63
63 class ResourceUpdateControllerTest : public Test { 64 class ResourceUpdateControllerTest : public Test {
64 public: 65 public:
65 ResourceUpdateControllerTest() 66 ResourceUpdateControllerTest()
66 : m_queue(make_scoped_ptr(new ResourceUpdateQueue)) 67 : m_proxy(0)
67 , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool)) 68 , m_queue(make_scoped_ptr(new ResourceUpdateQueue))
69 , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool, &m_proxy))
68 , m_fullUploadCountExpected(0) 70 , m_fullUploadCountExpected(0)
69 , m_partialCountExpected(0) 71 , m_partialCountExpected(0)
70 , m_totalUploadCountExpected(0) 72 , m_totalUploadCountExpected(0)
71 , m_maxUploadCountPerUpdate(0) 73 , m_maxUploadCountPerUpdate(0)
72 , m_numConsecutiveFlushes(0) 74 , m_numConsecutiveFlushes(0)
73 , m_numDanglingUploads(0) 75 , m_numDanglingUploads(0)
74 , m_numTotalUploads(0) 76 , m_numTotalUploads(0)
75 , m_numTotalFlushes(0) 77 , m_numTotalFlushes(0)
76 { 78 {
77 } 79 }
78 80
79 ~ResourceUpdateControllerTest() 81 ~ResourceUpdateControllerTest()
80 { 82 {
81 DebugScopedSetImplThreadAndMainThreadBlocked 83 DebugScopedSetImplThreadAndMainThreadBlocked
82 implThreadAndMainThreadBlocked; 84 implThreadAndMainThreadBlocked(&m_proxy);
83 m_textureManager->clearAllMemory(m_resourceProvider.get()); 85 m_textureManager->clearAllMemory(m_resourceProvider.get());
84 } 86 }
85 87
86 public: 88 public:
87 void onFlush() 89 void onFlush()
88 { 90 {
89 // Check for back-to-back flushes. 91 // Check for back-to-back flushes.
90 EXPECT_EQ(0, m_numConsecutiveFlushes) << "Back-to-back flushes detected. "; 92 EXPECT_EQ(0, m_numConsecutiveFlushes) << "Back-to-back flushes detected. ";
91 93
92 m_numDanglingUploads = 0; 94 m_numDanglingUploads = 0;
(...skipping 22 matching lines...) Expand all
115 m_bitmap.allocPixels(); 117 m_bitmap.allocPixels();
116 118
117 for (int i = 0; i < 4; i++) { 119 for (int i = 0; i < 4; i++) {
118 m_textures[i] = PrioritizedTexture::create( 120 m_textures[i] = PrioritizedTexture::create(
119 m_textureManager.get(), IntSize(300, 150), GL_RGBA); 121 m_textureManager.get(), IntSize(300, 150), GL_RGBA);
120 m_textures[i]->setRequestPriority( 122 m_textures[i]->setRequestPriority(
121 PriorityCalculator::visiblePriority(true)); 123 PriorityCalculator::visiblePriority(true));
122 } 124 }
123 m_textureManager->prioritizeTextures(); 125 m_textureManager->prioritizeTextures();
124 126
125 DebugScopedSetImplThread implThread;
126 m_resourceProvider = ResourceProvider::create(m_context.get()); 127 m_resourceProvider = ResourceProvider::create(m_context.get());
127 } 128 }
128 129
129 130
130 void appendFullUploadsOfIndexedTextureToUpdateQueue(int count, int textureIn dex) 131 void appendFullUploadsOfIndexedTextureToUpdateQueue(int count, int textureIn dex)
131 { 132 {
132 m_fullUploadCountExpected += count; 133 m_fullUploadCountExpected += count;
133 m_totalUploadCountExpected += count; 134 m_totalUploadCountExpected += count;
134 135
135 const IntRect rect(0, 0, 300, 150); 136 const IntRect rect(0, 0, 300, 150);
(...skipping 26 matching lines...) Expand all
162 } 163 }
163 164
164 void setMaxUploadCountPerUpdate(int count) 165 void setMaxUploadCountPerUpdate(int count)
165 { 166 {
166 m_maxUploadCountPerUpdate = count; 167 m_maxUploadCountPerUpdate = count;
167 } 168 }
168 169
169 void updateTextures() 170 void updateTextures()
170 { 171 {
171 DebugScopedSetImplThreadAndMainThreadBlocked 172 DebugScopedSetImplThreadAndMainThreadBlocked
172 implThreadAndMainThreadBlocked; 173 implThreadAndMainThreadBlocked(&m_proxy);
173 scoped_ptr<ResourceUpdateController> updateController = 174 scoped_ptr<ResourceUpdateController> updateController =
174 ResourceUpdateController::create( 175 ResourceUpdateController::create(
175 NULL, 176 NULL,
176 Proxy::implThread(), 177 m_proxy.implThread(),
177 m_queue.Pass(), 178 m_queue.Pass(),
178 m_resourceProvider.get()); 179 m_resourceProvider.get(),
180 m_proxy.hasImplThread());
179 updateController->finalize(); 181 updateController->finalize();
180 } 182 }
181 183
182 protected: 184 protected:
183 // Classes required to interact and test the ResourceUpdateController 185 // Classes required to interact and test the ResourceUpdateController
186 FakeProxy m_proxy;
184 scoped_ptr<GraphicsContext> m_context; 187 scoped_ptr<GraphicsContext> m_context;
185 scoped_ptr<ResourceProvider> m_resourceProvider; 188 scoped_ptr<ResourceProvider> m_resourceProvider;
186 scoped_ptr<ResourceUpdateQueue> m_queue; 189 scoped_ptr<ResourceUpdateQueue> m_queue;
187 scoped_ptr<PrioritizedTexture> m_textures[4]; 190 scoped_ptr<PrioritizedTexture> m_textures[4];
188 scoped_ptr<WebThread> m_thread; 191 scoped_ptr<WebThread> m_thread;
189 scoped_ptr<PrioritizedTextureManager> m_textureManager; 192 scoped_ptr<PrioritizedTextureManager> m_textureManager;
190 SkBitmap m_bitmap; 193 SkBitmap m_bitmap;
191 194
192 // Properties / expectations of this test 195 // Properties / expectations of this test
193 int m_fullUploadCountExpected; 196 int m_fullUploadCountExpected;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 336
334 void setNow(base::TimeTicks time) { m_now = time; } 337 void setNow(base::TimeTicks time) { m_now = time; }
335 virtual base::TimeTicks now() const OVERRIDE { return m_now; } 338 virtual base::TimeTicks now() const OVERRIDE { return m_now; }
336 void setUpdateMoreTexturesTime(base::TimeDelta time) { m_updateMoreTexturesT ime = time; } 339 void setUpdateMoreTexturesTime(base::TimeDelta time) { m_updateMoreTexturesT ime = time; }
337 virtual base::TimeDelta updateMoreTexturesTime() const OVERRIDE { return m_u pdateMoreTexturesTime; } 340 virtual base::TimeDelta updateMoreTexturesTime() const OVERRIDE { return m_u pdateMoreTexturesTime; }
338 void setUpdateMoreTexturesSize(size_t size) { m_updateMoreTexturesSize = siz e; } 341 void setUpdateMoreTexturesSize(size_t size) { m_updateMoreTexturesSize = siz e; }
339 virtual size_t updateMoreTexturesSize() const OVERRIDE { return m_updateMore TexturesSize; } 342 virtual size_t updateMoreTexturesSize() const OVERRIDE { return m_updateMore TexturesSize; }
340 343
341 protected: 344 protected:
342 FakeResourceUpdateController(cc::ResourceUpdateControllerClient* client, cc: :Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resour ceProvider) 345 FakeResourceUpdateController(cc::ResourceUpdateControllerClient* client, cc: :Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resour ceProvider)
343 : cc::ResourceUpdateController(client, thread, queue.Pass(), resourcePro vider) 346 : cc::ResourceUpdateController(client, thread, queue.Pass(), resourcePro vider, false)
344 , m_updateMoreTexturesSize(0) { } 347 , m_updateMoreTexturesSize(0) { }
345 348
346 base::TimeTicks m_now; 349 base::TimeTicks m_now;
347 base::TimeDelta m_updateMoreTexturesTime; 350 base::TimeDelta m_updateMoreTexturesTime;
348 size_t m_updateMoreTexturesSize; 351 size_t m_updateMoreTexturesSize;
349 }; 352 };
350 353
351 static void runPendingTask(FakeThread* thread, FakeResourceUpdateController* con troller) 354 static void runPendingTask(FakeThread* thread, FakeResourceUpdateController* con troller)
352 { 355 {
353 EXPECT_TRUE(thread->hasPendingTask()); 356 EXPECT_TRUE(thread->hasPendingTask());
354 controller->setNow(controller->now() + base::TimeDelta::FromMilliseconds(thr ead->pendingDelayMs())); 357 controller->setNow(controller->now() + base::TimeDelta::FromMilliseconds(thr ead->pendingDelayMs()));
355 thread->runPendingTask(); 358 thread->runPendingTask();
356 } 359 }
357 360
358 TEST_F(ResourceUpdateControllerTest, UpdateMoreTextures) 361 TEST_F(ResourceUpdateControllerTest, UpdateMoreTextures)
359 { 362 {
360 FakeResourceUpdateControllerClient client; 363 FakeResourceUpdateControllerClient client;
361 FakeThread thread; 364 FakeThread thread;
362 365
363 setMaxUploadCountPerUpdate(1); 366 setMaxUploadCountPerUpdate(1);
364 appendFullUploadsToUpdateQueue(3); 367 appendFullUploadsToUpdateQueue(3);
365 appendPartialUploadsToUpdateQueue(0); 368 appendPartialUploadsToUpdateQueue(0);
366 369
367 DebugScopedSetImplThreadAndMainThreadBlocked 370 DebugScopedSetImplThreadAndMainThreadBlocked
368 implThreadAndMainThreadBlocked; 371 implThreadAndMainThreadBlocked(&m_proxy);
369 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); 372 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
370 373
371 controller->setNow( 374 controller->setNow(
372 controller->now() + base::TimeDelta::FromMilliseconds(1)); 375 controller->now() + base::TimeDelta::FromMilliseconds(1));
373 controller->setUpdateMoreTexturesTime( 376 controller->setUpdateMoreTexturesTime(
374 base::TimeDelta::FromMilliseconds(100)); 377 base::TimeDelta::FromMilliseconds(100));
375 controller->setUpdateMoreTexturesSize(1); 378 controller->setUpdateMoreTexturesSize(1);
376 // Not enough time for any updates. 379 // Not enough time for any updates.
377 controller->performMoreUpdates( 380 controller->performMoreUpdates(
378 controller->now() + base::TimeDelta::FromMilliseconds(90)); 381 controller->now() + base::TimeDelta::FromMilliseconds(90));
(...skipping 25 matching lines...) Expand all
404 TEST_F(ResourceUpdateControllerTest, NoMoreUpdates) 407 TEST_F(ResourceUpdateControllerTest, NoMoreUpdates)
405 { 408 {
406 FakeResourceUpdateControllerClient client; 409 FakeResourceUpdateControllerClient client;
407 FakeThread thread; 410 FakeThread thread;
408 411
409 setMaxUploadCountPerUpdate(1); 412 setMaxUploadCountPerUpdate(1);
410 appendFullUploadsToUpdateQueue(2); 413 appendFullUploadsToUpdateQueue(2);
411 appendPartialUploadsToUpdateQueue(0); 414 appendPartialUploadsToUpdateQueue(0);
412 415
413 DebugScopedSetImplThreadAndMainThreadBlocked 416 DebugScopedSetImplThreadAndMainThreadBlocked
414 implThreadAndMainThreadBlocked; 417 implThreadAndMainThreadBlocked(&m_proxy);
415 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); 418 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
416 419
417 controller->setNow( 420 controller->setNow(
418 controller->now() + base::TimeDelta::FromMilliseconds(1)); 421 controller->now() + base::TimeDelta::FromMilliseconds(1));
419 controller->setUpdateMoreTexturesTime( 422 controller->setUpdateMoreTexturesTime(
420 base::TimeDelta::FromMilliseconds(100)); 423 base::TimeDelta::FromMilliseconds(100));
421 controller->setUpdateMoreTexturesSize(1); 424 controller->setUpdateMoreTexturesSize(1);
422 // Enough time for 3 updates but only 2 necessary. 425 // Enough time for 3 updates but only 2 necessary.
423 controller->performMoreUpdates( 426 controller->performMoreUpdates(
424 controller->now() + base::TimeDelta::FromMilliseconds(310)); 427 controller->now() + base::TimeDelta::FromMilliseconds(310));
(...skipping 19 matching lines...) Expand all
444 TEST_F(ResourceUpdateControllerTest, UpdatesCompleteInFiniteTime) 447 TEST_F(ResourceUpdateControllerTest, UpdatesCompleteInFiniteTime)
445 { 448 {
446 FakeResourceUpdateControllerClient client; 449 FakeResourceUpdateControllerClient client;
447 FakeThread thread; 450 FakeThread thread;
448 451
449 setMaxUploadCountPerUpdate(1); 452 setMaxUploadCountPerUpdate(1);
450 appendFullUploadsToUpdateQueue(2); 453 appendFullUploadsToUpdateQueue(2);
451 appendPartialUploadsToUpdateQueue(0); 454 appendPartialUploadsToUpdateQueue(0);
452 455
453 DebugScopedSetImplThreadAndMainThreadBlocked 456 DebugScopedSetImplThreadAndMainThreadBlocked
454 implThreadAndMainThreadBlocked; 457 implThreadAndMainThreadBlocked(&m_proxy);
455 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); 458 scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateContro ller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
456 459
457 controller->setNow( 460 controller->setNow(
458 controller->now() + base::TimeDelta::FromMilliseconds(1)); 461 controller->now() + base::TimeDelta::FromMilliseconds(1));
459 controller->setUpdateMoreTexturesTime( 462 controller->setUpdateMoreTexturesTime(
460 base::TimeDelta::FromMilliseconds(500)); 463 base::TimeDelta::FromMilliseconds(500));
461 controller->setUpdateMoreTexturesSize(1); 464 controller->setUpdateMoreTexturesSize(1);
462 465
463 for (int i = 0; i < 100; i++) { 466 for (int i = 0; i < 100; i++) {
464 if (client.readyToFinalizeCalled()) 467 if (client.readyToFinalizeCalled())
465 break; 468 break;
466 469
467 // Not enough time for any updates. 470 // Not enough time for any updates.
468 controller->performMoreUpdates( 471 controller->performMoreUpdates(
469 controller->now() + base::TimeDelta::FromMilliseconds(400)); 472 controller->now() + base::TimeDelta::FromMilliseconds(400));
470 473
471 if (thread.hasPendingTask()) 474 if (thread.hasPendingTask())
472 runPendingTask(&thread, controller.get()); 475 runPendingTask(&thread, controller.get());
473 } 476 }
474 477
475 EXPECT_FALSE(thread.hasPendingTask()); 478 EXPECT_FALSE(thread.hasPendingTask());
476 EXPECT_TRUE(client.readyToFinalizeCalled()); 479 EXPECT_TRUE(client.readyToFinalizeCalled());
477 EXPECT_EQ(2, m_numTotalUploads); 480 EXPECT_EQ(2, m_numTotalUploads);
478 } 481 }
479 482
480 } // namespace 483 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698