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