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

Side by Side Diff: cc/texture_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: Address code review comments and fix all cc_unittests 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/texture_update_controller.h" 7 #include "cc/texture_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 "cc/test/web_compositor_initializer.h" 15 #include "cc/test/web_compositor_initializer.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include <public/WebThread.h> 17 #include <public/WebThread.h>
17 18
18 using namespace cc; 19 using namespace cc;
19 using namespace WebKit; 20 using namespace WebKit;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 58
58 private: 59 private:
59 TextureUpdateControllerTest* m_test; 60 TextureUpdateControllerTest* m_test;
60 bool m_supportShallowFlush; 61 bool m_supportShallowFlush;
61 }; 62 };
62 63
63 64
64 class TextureUpdateControllerTest : public Test { 65 class TextureUpdateControllerTest : public Test {
65 public: 66 public:
66 TextureUpdateControllerTest() 67 TextureUpdateControllerTest()
67 : m_queue(make_scoped_ptr(new TextureUpdateQueue)) 68 : m_proxy(0)
68 , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool)) 69 , m_queue(make_scoped_ptr(new TextureUpdateQueue))
70 , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool, &m_proxy))
69 , m_compositorInitializer(m_thread.get()) 71 , m_compositorInitializer(m_thread.get())
70 , m_fullUploadCountExpected(0) 72 , m_fullUploadCountExpected(0)
71 , m_partialCountExpected(0) 73 , m_partialCountExpected(0)
72 , m_totalUploadCountExpected(0) 74 , m_totalUploadCountExpected(0)
73 , m_maxUploadCountPerUpdate(0) 75 , m_maxUploadCountPerUpdate(0)
74 , m_numConsecutiveFlushes(0) 76 , m_numConsecutiveFlushes(0)
75 , m_numDanglingUploads(0) 77 , m_numDanglingUploads(0)
76 , m_numTotalUploads(0) 78 , m_numTotalUploads(0)
77 , m_numTotalFlushes(0) 79 , m_numTotalFlushes(0)
78 { 80 {
79 } 81 }
80 82
81 ~TextureUpdateControllerTest() 83 ~TextureUpdateControllerTest()
82 { 84 {
83 DebugScopedSetImplThreadAndMainThreadBlocked 85 DebugScopedSetImplThreadAndMainThreadBlocked
84 implThreadAndMainThreadBlocked; 86 implThreadAndMainThreadBlocked(&m_proxy);
85 m_textureManager->clearAllMemory(m_resourceProvider.get()); 87 m_textureManager->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 22 matching lines...) Expand all
117 m_bitmap.allocPixels(); 119 m_bitmap.allocPixels();
118 120
119 for (int i = 0; i < 4; i++) { 121 for (int i = 0; i < 4; i++) {
120 m_textures[i] = PrioritizedTexture::create( 122 m_textures[i] = PrioritizedTexture::create(
121 m_textureManager.get(), IntSize(300, 150), GL_RGBA); 123 m_textureManager.get(), IntSize(300, 150), GL_RGBA);
122 m_textures[i]->setRequestPriority( 124 m_textures[i]->setRequestPriority(
123 PriorityCalculator::visiblePriority(true)); 125 PriorityCalculator::visiblePriority(true));
124 } 126 }
125 m_textureManager->prioritizeTextures(); 127 m_textureManager->prioritizeTextures();
126 128
127 DebugScopedSetImplThread implThread;
128 m_resourceProvider = ResourceProvider::create(m_context.get()); 129 m_resourceProvider = ResourceProvider::create(m_context.get());
129 } 130 }
130 131
131 132
132 void appendFullUploadsOfIndexedTextureToUpdateQueue(int count, int textureIn dex) 133 void appendFullUploadsOfIndexedTextureToUpdateQueue(int count, int textureIn dex)
133 { 134 {
134 m_fullUploadCountExpected += count; 135 m_fullUploadCountExpected += count;
135 m_totalUploadCountExpected += count; 136 m_totalUploadCountExpected += count;
136 137
137 const IntRect rect(0, 0, 300, 150); 138 const IntRect rect(0, 0, 300, 150);
(...skipping 26 matching lines...) Expand all
164 } 165 }
165 166
166 void setMaxUploadCountPerUpdate(int count) 167 void setMaxUploadCountPerUpdate(int count)
167 { 168 {
168 m_maxUploadCountPerUpdate = count; 169 m_maxUploadCountPerUpdate = count;
169 } 170 }
170 171
171 void updateTextures() 172 void updateTextures()
172 { 173 {
173 DebugScopedSetImplThreadAndMainThreadBlocked 174 DebugScopedSetImplThreadAndMainThreadBlocked
174 implThreadAndMainThreadBlocked; 175 implThreadAndMainThreadBlocked(&m_proxy);
175 scoped_ptr<TextureUpdateController> updateController = 176 scoped_ptr<TextureUpdateController> updateController =
176 TextureUpdateController::create( 177 TextureUpdateController::create(
177 NULL, 178 NULL,
178 Proxy::implThread(), 179 m_proxy.implThread(),
179 m_queue.Pass(), 180 m_queue.Pass(),
180 m_resourceProvider.get()); 181 m_resourceProvider.get(),
182 m_proxy.hasImplThread());
181 updateController->finalize(); 183 updateController->finalize();
182 } 184 }
183 185
184 protected: 186 protected:
185 // Classes required to interact and test the TextureUpdateController 187 // Classes required to interact and test the TextureUpdateController
188 FakeProxy m_proxy;
186 scoped_ptr<GraphicsContext> m_context; 189 scoped_ptr<GraphicsContext> m_context;
187 scoped_ptr<ResourceProvider> m_resourceProvider; 190 scoped_ptr<ResourceProvider> m_resourceProvider;
188 scoped_ptr<TextureUpdateQueue> m_queue; 191 scoped_ptr<TextureUpdateQueue> m_queue;
189 scoped_ptr<PrioritizedTexture> m_textures[4]; 192 scoped_ptr<PrioritizedTexture> m_textures[4];
190 scoped_ptr<WebThread> m_thread; 193 scoped_ptr<WebThread> m_thread;
191 WebCompositorInitializer m_compositorInitializer; 194 WebCompositorInitializer m_compositorInitializer;
192 scoped_ptr<PrioritizedTextureManager> m_textureManager; 195 scoped_ptr<PrioritizedTextureManager> m_textureManager;
193 SkBitmap m_bitmap; 196 SkBitmap m_bitmap;
194 197
195 // Properties / expectations of this test 198 // Properties / expectations of this test
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 339
337 void setNow(base::TimeTicks time) { m_now = time; } 340 void setNow(base::TimeTicks time) { m_now = time; }
338 virtual base::TimeTicks now() const OVERRIDE { return m_now; } 341 virtual base::TimeTicks now() const OVERRIDE { return m_now; }
339 void setUpdateMoreTexturesTime(base::TimeDelta time) { m_updateMoreTexturesT ime = time; } 342 void setUpdateMoreTexturesTime(base::TimeDelta time) { m_updateMoreTexturesT ime = time; }
340 virtual base::TimeDelta updateMoreTexturesTime() const OVERRIDE { return m_u pdateMoreTexturesTime; } 343 virtual base::TimeDelta updateMoreTexturesTime() const OVERRIDE { return m_u pdateMoreTexturesTime; }
341 void setUpdateMoreTexturesSize(size_t size) { m_updateMoreTexturesSize = siz e; } 344 void setUpdateMoreTexturesSize(size_t size) { m_updateMoreTexturesSize = siz e; }
342 virtual size_t updateMoreTexturesSize() const OVERRIDE { return m_updateMore TexturesSize; } 345 virtual size_t updateMoreTexturesSize() const OVERRIDE { return m_updateMore TexturesSize; }
343 346
344 protected: 347 protected:
345 FakeTextureUpdateController(cc::TextureUpdateControllerClient* client, cc::T hread* thread, scoped_ptr<TextureUpdateQueue> queue, ResourceProvider* resourceP rovider) 348 FakeTextureUpdateController(cc::TextureUpdateControllerClient* client, cc::T hread* thread, scoped_ptr<TextureUpdateQueue> queue, ResourceProvider* resourceP rovider)
346 : cc::TextureUpdateController(client, thread, queue.Pass(), resourceProv ider) 349 : cc::TextureUpdateController(client, thread, queue.Pass(), resourceProv ider, false)
347 , m_updateMoreTexturesSize(0) { } 350 , m_updateMoreTexturesSize(0) { }
348 351
349 base::TimeTicks m_now; 352 base::TimeTicks m_now;
350 base::TimeDelta m_updateMoreTexturesTime; 353 base::TimeDelta m_updateMoreTexturesTime;
351 size_t m_updateMoreTexturesSize; 354 size_t m_updateMoreTexturesSize;
352 }; 355 };
353 356
354 static void runPendingTask(FakeThread* thread, FakeTextureUpdateController* cont roller) 357 static void runPendingTask(FakeThread* thread, FakeTextureUpdateController* cont roller)
355 { 358 {
356 EXPECT_TRUE(thread->hasPendingTask()); 359 EXPECT_TRUE(thread->hasPendingTask());
357 controller->setNow(controller->now() + base::TimeDelta::FromMilliseconds(thr ead->pendingDelayMs())); 360 controller->setNow(controller->now() + base::TimeDelta::FromMilliseconds(thr ead->pendingDelayMs()));
358 thread->runPendingTask(); 361 thread->runPendingTask();
359 } 362 }
360 363
361 TEST_F(TextureUpdateControllerTest, UpdateMoreTextures) 364 TEST_F(TextureUpdateControllerTest, UpdateMoreTextures)
362 { 365 {
363 FakeTextureUpdateControllerClient client; 366 FakeTextureUpdateControllerClient client;
364 FakeThread thread; 367 FakeThread thread;
365 368
366 setMaxUploadCountPerUpdate(1); 369 setMaxUploadCountPerUpdate(1);
367 appendFullUploadsToUpdateQueue(3); 370 appendFullUploadsToUpdateQueue(3);
368 appendPartialUploadsToUpdateQueue(0); 371 appendPartialUploadsToUpdateQueue(0);
369 372
370 DebugScopedSetImplThreadAndMainThreadBlocked 373 DebugScopedSetImplThreadAndMainThreadBlocked
371 implThreadAndMainThreadBlocked; 374 implThreadAndMainThreadBlocked(&m_proxy);
372 scoped_ptr<FakeTextureUpdateController> controller(FakeTextureUpdateControll er::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); 375 scoped_ptr<FakeTextureUpdateController> controller(FakeTextureUpdateControll er::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
373 376
374 controller->setNow( 377 controller->setNow(
375 controller->now() + base::TimeDelta::FromMilliseconds(1)); 378 controller->now() + base::TimeDelta::FromMilliseconds(1));
376 controller->setUpdateMoreTexturesTime( 379 controller->setUpdateMoreTexturesTime(
377 base::TimeDelta::FromMilliseconds(100)); 380 base::TimeDelta::FromMilliseconds(100));
378 controller->setUpdateMoreTexturesSize(1); 381 controller->setUpdateMoreTexturesSize(1);
379 // Not enough time for any updates. 382 // Not enough time for any updates.
380 controller->performMoreUpdates( 383 controller->performMoreUpdates(
381 controller->now() + base::TimeDelta::FromMilliseconds(90)); 384 controller->now() + base::TimeDelta::FromMilliseconds(90));
(...skipping 25 matching lines...) Expand all
407 TEST_F(TextureUpdateControllerTest, NoMoreUpdates) 410 TEST_F(TextureUpdateControllerTest, NoMoreUpdates)
408 { 411 {
409 FakeTextureUpdateControllerClient client; 412 FakeTextureUpdateControllerClient client;
410 FakeThread thread; 413 FakeThread thread;
411 414
412 setMaxUploadCountPerUpdate(1); 415 setMaxUploadCountPerUpdate(1);
413 appendFullUploadsToUpdateQueue(2); 416 appendFullUploadsToUpdateQueue(2);
414 appendPartialUploadsToUpdateQueue(0); 417 appendPartialUploadsToUpdateQueue(0);
415 418
416 DebugScopedSetImplThreadAndMainThreadBlocked 419 DebugScopedSetImplThreadAndMainThreadBlocked
417 implThreadAndMainThreadBlocked; 420 implThreadAndMainThreadBlocked(&m_proxy);
418 scoped_ptr<FakeTextureUpdateController> controller(FakeTextureUpdateControll er::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); 421 scoped_ptr<FakeTextureUpdateController> controller(FakeTextureUpdateControll er::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
419 422
420 controller->setNow( 423 controller->setNow(
421 controller->now() + base::TimeDelta::FromMilliseconds(1)); 424 controller->now() + base::TimeDelta::FromMilliseconds(1));
422 controller->setUpdateMoreTexturesTime( 425 controller->setUpdateMoreTexturesTime(
423 base::TimeDelta::FromMilliseconds(100)); 426 base::TimeDelta::FromMilliseconds(100));
424 controller->setUpdateMoreTexturesSize(1); 427 controller->setUpdateMoreTexturesSize(1);
425 // Enough time for 3 updates but only 2 necessary. 428 // Enough time for 3 updates but only 2 necessary.
426 controller->performMoreUpdates( 429 controller->performMoreUpdates(
427 controller->now() + base::TimeDelta::FromMilliseconds(310)); 430 controller->now() + base::TimeDelta::FromMilliseconds(310));
(...skipping 19 matching lines...) Expand all
447 TEST_F(TextureUpdateControllerTest, UpdatesCompleteInFiniteTime) 450 TEST_F(TextureUpdateControllerTest, UpdatesCompleteInFiniteTime)
448 { 451 {
449 FakeTextureUpdateControllerClient client; 452 FakeTextureUpdateControllerClient client;
450 FakeThread thread; 453 FakeThread thread;
451 454
452 setMaxUploadCountPerUpdate(1); 455 setMaxUploadCountPerUpdate(1);
453 appendFullUploadsToUpdateQueue(2); 456 appendFullUploadsToUpdateQueue(2);
454 appendPartialUploadsToUpdateQueue(0); 457 appendPartialUploadsToUpdateQueue(0);
455 458
456 DebugScopedSetImplThreadAndMainThreadBlocked 459 DebugScopedSetImplThreadAndMainThreadBlocked
457 implThreadAndMainThreadBlocked; 460 implThreadAndMainThreadBlocked(&m_proxy);
458 scoped_ptr<FakeTextureUpdateController> controller(FakeTextureUpdateControll er::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); 461 scoped_ptr<FakeTextureUpdateController> controller(FakeTextureUpdateControll er::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get()));
459 462
460 controller->setNow( 463 controller->setNow(
461 controller->now() + base::TimeDelta::FromMilliseconds(1)); 464 controller->now() + base::TimeDelta::FromMilliseconds(1));
462 controller->setUpdateMoreTexturesTime( 465 controller->setUpdateMoreTexturesTime(
463 base::TimeDelta::FromMilliseconds(500)); 466 base::TimeDelta::FromMilliseconds(500));
464 controller->setUpdateMoreTexturesSize(1); 467 controller->setUpdateMoreTexturesSize(1);
465 468
466 for (int i = 0; i < 100; i++) { 469 for (int i = 0; i < 100; i++) {
467 if (client.readyToFinalizeCalled()) 470 if (client.readyToFinalizeCalled())
468 break; 471 break;
469 472
470 // Not enough time for any updates. 473 // Not enough time for any updates.
471 controller->performMoreUpdates( 474 controller->performMoreUpdates(
472 controller->now() + base::TimeDelta::FromMilliseconds(400)); 475 controller->now() + base::TimeDelta::FromMilliseconds(400));
473 476
474 if (thread.hasPendingTask()) 477 if (thread.hasPendingTask())
475 runPendingTask(&thread, controller.get()); 478 runPendingTask(&thread, controller.get());
476 } 479 }
477 480
478 EXPECT_FALSE(thread.hasPendingTask()); 481 EXPECT_FALSE(thread.hasPendingTask());
479 EXPECT_TRUE(client.readyToFinalizeCalled()); 482 EXPECT_TRUE(client.readyToFinalizeCalled());
480 EXPECT_EQ(2, m_numTotalUploads); 483 EXPECT_EQ(2, m_numTotalUploads);
481 } 484 }
482 485
483 } // namespace 486 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698