| 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/texture_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 "cc/test/web_compositor_initializer.h" | 14 #include "cc/test/web_compositor_initializer.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include <public/WebThread.h> | 16 #include <public/WebThread.h> |
| 17 | 17 |
| 18 using namespace cc; | 18 using namespace cc; |
| 19 using namespace WebKit; | 19 using namespace WebKit; |
| 20 using namespace WebKitTests; | 20 using namespace WebKitTests; |
| 21 using testing::Test; | 21 using testing::Test; |
| 22 | 22 |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const int kFlushPeriodFull = 4; | 26 const int kFlushPeriodFull = 4; |
| 27 const int kFlushPeriodPartial = kFlushPeriodFull; | 27 const int kFlushPeriodPartial = kFlushPeriodFull; |
| 28 | 28 |
| 29 class TextureUpdateControllerTest; | 29 class ResourceUpdateControllerTest; |
| 30 | 30 |
| 31 class WebGraphicsContext3DForUploadTest : public FakeWebGraphicsContext3D { | 31 class WebGraphicsContext3DForUploadTest : public FakeWebGraphicsContext3D { |
| 32 public: | 32 public: |
| 33 WebGraphicsContext3DForUploadTest(TextureUpdateControllerTest *test) | 33 WebGraphicsContext3DForUploadTest(ResourceUpdateControllerTest *test) |
| 34 : m_test(test) | 34 : m_test(test) |
| 35 , m_supportShallowFlush(true) | 35 , m_supportShallowFlush(true) |
| 36 { } | 36 { } |
| 37 | 37 |
| 38 virtual void flush(void); | 38 virtual void flush(void); |
| 39 virtual void shallowFlushCHROMIUM(void); | 39 virtual void shallowFlushCHROMIUM(void); |
| 40 virtual void texSubImage2D(WGC3Denum target, | 40 virtual void texSubImage2D(WGC3Denum target, |
| 41 WGC3Dint level, | 41 WGC3Dint level, |
| 42 WGC3Dint xoffset, | 42 WGC3Dint xoffset, |
| 43 WGC3Dint yoffset, | 43 WGC3Dint yoffset, |
| 44 WGC3Dsizei width, | 44 WGC3Dsizei width, |
| 45 WGC3Dsizei height, | 45 WGC3Dsizei height, |
| 46 WGC3Denum format, | 46 WGC3Denum format, |
| 47 WGC3Denum type, | 47 WGC3Denum type, |
| 48 const void* pixels); | 48 const void* pixels); |
| 49 virtual GrGLInterface* onCreateGrGLInterface() { return 0; } | 49 virtual GrGLInterface* onCreateGrGLInterface() { return 0; } |
| 50 | 50 |
| 51 virtual WebString getString(WGC3Denum name) | 51 virtual WebString getString(WGC3Denum name) |
| 52 { | 52 { |
| 53 if (m_supportShallowFlush) | 53 if (m_supportShallowFlush) |
| 54 return WebString("GL_CHROMIUM_shallow_flush"); | 54 return WebString("GL_CHROMIUM_shallow_flush"); |
| 55 return WebString(""); | 55 return WebString(""); |
| 56 } | 56 } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 TextureUpdateControllerTest* m_test; | 59 ResourceUpdateControllerTest* m_test; |
| 60 bool m_supportShallowFlush; | 60 bool m_supportShallowFlush; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 | 63 |
| 64 class TextureUpdateControllerTest : public Test { | 64 class ResourceUpdateControllerTest : public Test { |
| 65 public: | 65 public: |
| 66 TextureUpdateControllerTest() | 66 ResourceUpdateControllerTest() |
| 67 : m_queue(make_scoped_ptr(new TextureUpdateQueue)) | 67 : m_queue(make_scoped_ptr(new ResourceUpdateQueue)) |
| 68 , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024,
Renderer::ContentPool)) | 68 , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024,
Renderer::ContentPool)) |
| 69 , m_compositorInitializer(m_thread.get()) | 69 , m_compositorInitializer(m_thread.get()) |
| 70 , m_fullUploadCountExpected(0) | 70 , m_fullUploadCountExpected(0) |
| 71 , m_partialCountExpected(0) | 71 , m_partialCountExpected(0) |
| 72 , m_totalUploadCountExpected(0) | 72 , m_totalUploadCountExpected(0) |
| 73 , m_maxUploadCountPerUpdate(0) | 73 , m_maxUploadCountPerUpdate(0) |
| 74 , m_numConsecutiveFlushes(0) | 74 , m_numConsecutiveFlushes(0) |
| 75 , m_numDanglingUploads(0) | 75 , m_numDanglingUploads(0) |
| 76 , m_numTotalUploads(0) | 76 , m_numTotalUploads(0) |
| 77 , m_numTotalFlushes(0) | 77 , m_numTotalFlushes(0) |
| 78 { | 78 { |
| 79 } | 79 } |
| 80 | 80 |
| 81 ~TextureUpdateControllerTest() | 81 ~ResourceUpdateControllerTest() |
| 82 { | 82 { |
| 83 DebugScopedSetImplThreadAndMainThreadBlocked | 83 DebugScopedSetImplThreadAndMainThreadBlocked |
| 84 implThreadAndMainThreadBlocked; | 84 implThreadAndMainThreadBlocked; |
| 85 m_textureManager->clearAllMemory(m_resourceProvider.get()); | 85 m_textureManager->clearAllMemory(m_resourceProvider.get()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 public: | 88 public: |
| 89 void onFlush() | 89 void onFlush() |
| 90 { | 90 { |
| 91 // Check for back-to-back flushes. | 91 // Check for back-to-back flushes. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 void setMaxUploadCountPerUpdate(int count) | 166 void setMaxUploadCountPerUpdate(int count) |
| 167 { | 167 { |
| 168 m_maxUploadCountPerUpdate = count; | 168 m_maxUploadCountPerUpdate = count; |
| 169 } | 169 } |
| 170 | 170 |
| 171 void updateTextures() | 171 void updateTextures() |
| 172 { | 172 { |
| 173 DebugScopedSetImplThreadAndMainThreadBlocked | 173 DebugScopedSetImplThreadAndMainThreadBlocked |
| 174 implThreadAndMainThreadBlocked; | 174 implThreadAndMainThreadBlocked; |
| 175 scoped_ptr<TextureUpdateController> updateController = | 175 scoped_ptr<ResourceUpdateController> updateController = |
| 176 TextureUpdateController::create( | 176 ResourceUpdateController::create( |
| 177 NULL, | 177 NULL, |
| 178 Proxy::implThread(), | 178 Proxy::implThread(), |
| 179 m_queue.Pass(), | 179 m_queue.Pass(), |
| 180 m_resourceProvider.get()); | 180 m_resourceProvider.get()); |
| 181 updateController->finalize(); | 181 updateController->finalize(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 protected: | 184 protected: |
| 185 // Classes required to interact and test the TextureUpdateController | 185 // Classes required to interact and test the ResourceUpdateController |
| 186 scoped_ptr<GraphicsContext> m_context; | 186 scoped_ptr<GraphicsContext> m_context; |
| 187 scoped_ptr<ResourceProvider> m_resourceProvider; | 187 scoped_ptr<ResourceProvider> m_resourceProvider; |
| 188 scoped_ptr<TextureUpdateQueue> m_queue; | 188 scoped_ptr<ResourceUpdateQueue> m_queue; |
| 189 scoped_ptr<PrioritizedTexture> m_textures[4]; | 189 scoped_ptr<PrioritizedTexture> m_textures[4]; |
| 190 scoped_ptr<WebThread> m_thread; | 190 scoped_ptr<WebThread> m_thread; |
| 191 WebCompositorInitializer m_compositorInitializer; | 191 WebCompositorInitializer m_compositorInitializer; |
| 192 scoped_ptr<PrioritizedTextureManager> m_textureManager; | 192 scoped_ptr<PrioritizedTextureManager> m_textureManager; |
| 193 SkBitmap m_bitmap; | 193 SkBitmap m_bitmap; |
| 194 | 194 |
| 195 // Properties / expectations of this test | 195 // Properties / expectations of this test |
| 196 int m_fullUploadCountExpected; | 196 int m_fullUploadCountExpected; |
| 197 int m_partialCountExpected; | 197 int m_partialCountExpected; |
| 198 int m_totalUploadCountExpected; | 198 int m_totalUploadCountExpected; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 222 WGC3Dsizei width, | 222 WGC3Dsizei width, |
| 223 WGC3Dsizei height, | 223 WGC3Dsizei height, |
| 224 WGC3Denum format, | 224 WGC3Denum format, |
| 225 WGC3Denum type, | 225 WGC3Denum type, |
| 226 const void* pixels) | 226 const void* pixels) |
| 227 { | 227 { |
| 228 m_test->onUpload(); | 228 m_test->onUpload(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 // ZERO UPLOADS TESTS | 231 // ZERO UPLOADS TESTS |
| 232 TEST_F(TextureUpdateControllerTest, ZeroUploads) | 232 TEST_F(ResourceUpdateControllerTest, ZeroUploads) |
| 233 { | 233 { |
| 234 appendFullUploadsToUpdateQueue(0); | 234 appendFullUploadsToUpdateQueue(0); |
| 235 appendPartialUploadsToUpdateQueue(0); | 235 appendPartialUploadsToUpdateQueue(0); |
| 236 updateTextures(); | 236 updateTextures(); |
| 237 | 237 |
| 238 EXPECT_EQ(0, m_numTotalFlushes); | 238 EXPECT_EQ(0, m_numTotalFlushes); |
| 239 EXPECT_EQ(0, m_numTotalUploads); | 239 EXPECT_EQ(0, m_numTotalUploads); |
| 240 } | 240 } |
| 241 | 241 |
| 242 | 242 |
| 243 // ONE UPLOAD TESTS | 243 // ONE UPLOAD TESTS |
| 244 TEST_F(TextureUpdateControllerTest, OneFullUpload) | 244 TEST_F(ResourceUpdateControllerTest, OneFullUpload) |
| 245 { | 245 { |
| 246 appendFullUploadsToUpdateQueue(1); | 246 appendFullUploadsToUpdateQueue(1); |
| 247 appendPartialUploadsToUpdateQueue(0); | 247 appendPartialUploadsToUpdateQueue(0); |
| 248 updateTextures(); | 248 updateTextures(); |
| 249 | 249 |
| 250 EXPECT_EQ(1, m_numTotalFlushes); | 250 EXPECT_EQ(1, m_numTotalFlushes); |
| 251 EXPECT_EQ(1, m_numTotalUploads); | 251 EXPECT_EQ(1, m_numTotalUploads); |
| 252 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; | 252 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; |
| 253 } | 253 } |
| 254 | 254 |
| 255 TEST_F(TextureUpdateControllerTest, OnePartialUpload) | 255 TEST_F(ResourceUpdateControllerTest, OnePartialUpload) |
| 256 { | 256 { |
| 257 appendFullUploadsToUpdateQueue(0); | 257 appendFullUploadsToUpdateQueue(0); |
| 258 appendPartialUploadsToUpdateQueue(1); | 258 appendPartialUploadsToUpdateQueue(1); |
| 259 updateTextures(); | 259 updateTextures(); |
| 260 | 260 |
| 261 EXPECT_EQ(1, m_numTotalFlushes); | 261 EXPECT_EQ(1, m_numTotalFlushes); |
| 262 EXPECT_EQ(1, m_numTotalUploads); | 262 EXPECT_EQ(1, m_numTotalUploads); |
| 263 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; | 263 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; |
| 264 } | 264 } |
| 265 | 265 |
| 266 TEST_F(TextureUpdateControllerTest, OneFullOnePartialUpload) | 266 TEST_F(ResourceUpdateControllerTest, OneFullOnePartialUpload) |
| 267 { | 267 { |
| 268 appendFullUploadsToUpdateQueue(1); | 268 appendFullUploadsToUpdateQueue(1); |
| 269 appendPartialUploadsToUpdateQueue(1); | 269 appendPartialUploadsToUpdateQueue(1); |
| 270 updateTextures(); | 270 updateTextures(); |
| 271 | 271 |
| 272 EXPECT_EQ(1, m_numTotalFlushes); | 272 EXPECT_EQ(1, m_numTotalFlushes); |
| 273 EXPECT_EQ(2, m_numTotalUploads); | 273 EXPECT_EQ(2, m_numTotalUploads); |
| 274 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; | 274 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; |
| 275 } | 275 } |
| 276 | 276 |
| 277 | 277 |
| 278 // This class of tests upload a number of textures that is a multiple of the flu
sh period. | 278 // This class of tests upload a number of textures that is a multiple of the flu
sh period. |
| 279 const int fullUploadFlushMultipler = 7; | 279 const int fullUploadFlushMultipler = 7; |
| 280 const int fullCount = fullUploadFlushMultipler * kFlushPeriodFull; | 280 const int fullCount = fullUploadFlushMultipler * kFlushPeriodFull; |
| 281 | 281 |
| 282 const int partialUploadFlushMultipler = 11; | 282 const int partialUploadFlushMultipler = 11; |
| 283 const int partialCount = partialUploadFlushMultipler * kFlushPeriodPartial; | 283 const int partialCount = partialUploadFlushMultipler * kFlushPeriodPartial; |
| 284 | 284 |
| 285 TEST_F(TextureUpdateControllerTest, ManyFullUploads) | 285 TEST_F(ResourceUpdateControllerTest, ManyFullUploads) |
| 286 { | 286 { |
| 287 appendFullUploadsToUpdateQueue(fullCount); | 287 appendFullUploadsToUpdateQueue(fullCount); |
| 288 appendPartialUploadsToUpdateQueue(0); | 288 appendPartialUploadsToUpdateQueue(0); |
| 289 updateTextures(); | 289 updateTextures(); |
| 290 | 290 |
| 291 EXPECT_EQ(fullUploadFlushMultipler, m_numTotalFlushes); | 291 EXPECT_EQ(fullUploadFlushMultipler, m_numTotalFlushes); |
| 292 EXPECT_EQ(fullCount, m_numTotalUploads); | 292 EXPECT_EQ(fullCount, m_numTotalUploads); |
| 293 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; | 293 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; |
| 294 } | 294 } |
| 295 | 295 |
| 296 TEST_F(TextureUpdateControllerTest, ManyPartialUploads) | 296 TEST_F(ResourceUpdateControllerTest, ManyPartialUploads) |
| 297 { | 297 { |
| 298 appendFullUploadsToUpdateQueue(0); | 298 appendFullUploadsToUpdateQueue(0); |
| 299 appendPartialUploadsToUpdateQueue(partialCount); | 299 appendPartialUploadsToUpdateQueue(partialCount); |
| 300 updateTextures(); | 300 updateTextures(); |
| 301 | 301 |
| 302 EXPECT_EQ(partialUploadFlushMultipler, m_numTotalFlushes); | 302 EXPECT_EQ(partialUploadFlushMultipler, m_numTotalFlushes); |
| 303 EXPECT_EQ(partialCount, m_numTotalUploads); | 303 EXPECT_EQ(partialCount, m_numTotalUploads); |
| 304 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; | 304 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; |
| 305 } | 305 } |
| 306 | 306 |
| 307 TEST_F(TextureUpdateControllerTest, ManyFullManyPartialUploads) | 307 TEST_F(ResourceUpdateControllerTest, ManyFullManyPartialUploads) |
| 308 { | 308 { |
| 309 appendFullUploadsToUpdateQueue(fullCount); | 309 appendFullUploadsToUpdateQueue(fullCount); |
| 310 appendPartialUploadsToUpdateQueue(partialCount); | 310 appendPartialUploadsToUpdateQueue(partialCount); |
| 311 updateTextures(); | 311 updateTextures(); |
| 312 | 312 |
| 313 EXPECT_EQ(fullUploadFlushMultipler + partialUploadFlushMultipler, m_numTotal
Flushes); | 313 EXPECT_EQ(fullUploadFlushMultipler + partialUploadFlushMultipler, m_numTotal
Flushes); |
| 314 EXPECT_EQ(fullCount + partialCount, m_numTotalUploads); | 314 EXPECT_EQ(fullCount + partialCount, m_numTotalUploads); |
| 315 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; | 315 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; |
| 316 } | 316 } |
| 317 | 317 |
| 318 class FakeTextureUpdateControllerClient : public cc::TextureUpdateControllerClie
nt { | 318 class FakeResourceUpdateControllerClient : public cc::ResourceUpdateControllerCl
ient { |
| 319 public: | 319 public: |
| 320 FakeTextureUpdateControllerClient() { reset(); } | 320 FakeResourceUpdateControllerClient() { reset(); } |
| 321 void reset() { m_readyToFinalizeCalled = false; } | 321 void reset() { m_readyToFinalizeCalled = false; } |
| 322 bool readyToFinalizeCalled() const { return m_readyToFinalizeCalled; } | 322 bool readyToFinalizeCalled() const { return m_readyToFinalizeCalled; } |
| 323 | 323 |
| 324 virtual void readyToFinalizeTextureUpdates() OVERRIDE { m_readyToFinalizeCal
led = true; } | 324 virtual void readyToFinalizeTextureUpdates() OVERRIDE { m_readyToFinalizeCal
led = true; } |
| 325 | 325 |
| 326 protected: | 326 protected: |
| 327 bool m_readyToFinalizeCalled; | 327 bool m_readyToFinalizeCalled; |
| 328 }; | 328 }; |
| 329 | 329 |
| 330 class FakeTextureUpdateController : public cc::TextureUpdateController { | 330 class FakeResourceUpdateController : public cc::ResourceUpdateController { |
| 331 public: | 331 public: |
| 332 static scoped_ptr<FakeTextureUpdateController> create(cc::TextureUpdateContr
ollerClient* client, cc::Thread* thread, scoped_ptr<TextureUpdateQueue> queue, R
esourceProvider* resourceProvider) | 332 static scoped_ptr<FakeResourceUpdateController> create(cc::ResourceUpdateCon
trollerClient* client, cc::Thread* thread, scoped_ptr<ResourceUpdateQueue> queue
, ResourceProvider* resourceProvider) |
| 333 { | 333 { |
| 334 return make_scoped_ptr(new FakeTextureUpdateController(client, thread, q
ueue.Pass(), resourceProvider)); | 334 return make_scoped_ptr(new FakeResourceUpdateController(client, thread,
queue.Pass(), resourceProvider)); |
| 335 } | 335 } |
| 336 | 336 |
| 337 void setNow(base::TimeTicks time) { m_now = time; } | 337 void setNow(base::TimeTicks time) { m_now = time; } |
| 338 virtual base::TimeTicks now() const OVERRIDE { return m_now; } | 338 virtual base::TimeTicks now() const OVERRIDE { return m_now; } |
| 339 void setUpdateMoreTexturesTime(base::TimeDelta time) { m_updateMoreTexturesT
ime = time; } | 339 void setUpdateMoreTexturesTime(base::TimeDelta time) { m_updateMoreTexturesT
ime = time; } |
| 340 virtual base::TimeDelta updateMoreTexturesTime() const OVERRIDE { return m_u
pdateMoreTexturesTime; } | 340 virtual base::TimeDelta updateMoreTexturesTime() const OVERRIDE { return m_u
pdateMoreTexturesTime; } |
| 341 void setUpdateMoreTexturesSize(size_t size) { m_updateMoreTexturesSize = siz
e; } | 341 void setUpdateMoreTexturesSize(size_t size) { m_updateMoreTexturesSize = siz
e; } |
| 342 virtual size_t updateMoreTexturesSize() const OVERRIDE { return m_updateMore
TexturesSize; } | 342 virtual size_t updateMoreTexturesSize() const OVERRIDE { return m_updateMore
TexturesSize; } |
| 343 | 343 |
| 344 protected: | 344 protected: |
| 345 FakeTextureUpdateController(cc::TextureUpdateControllerClient* client, cc::T
hread* thread, scoped_ptr<TextureUpdateQueue> queue, ResourceProvider* resourceP
rovider) | 345 FakeResourceUpdateController(cc::ResourceUpdateControllerClient* client, cc:
:Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resour
ceProvider) |
| 346 : cc::TextureUpdateController(client, thread, queue.Pass(), resourceProv
ider) | 346 : cc::ResourceUpdateController(client, thread, queue.Pass(), resourcePro
vider) |
| 347 , m_updateMoreTexturesSize(0) { } | 347 , m_updateMoreTexturesSize(0) { } |
| 348 | 348 |
| 349 base::TimeTicks m_now; | 349 base::TimeTicks m_now; |
| 350 base::TimeDelta m_updateMoreTexturesTime; | 350 base::TimeDelta m_updateMoreTexturesTime; |
| 351 size_t m_updateMoreTexturesSize; | 351 size_t m_updateMoreTexturesSize; |
| 352 }; | 352 }; |
| 353 | 353 |
| 354 static void runPendingTask(FakeThread* thread, FakeTextureUpdateController* cont
roller) | 354 static void runPendingTask(FakeThread* thread, FakeResourceUpdateController* con
troller) |
| 355 { | 355 { |
| 356 EXPECT_TRUE(thread->hasPendingTask()); | 356 EXPECT_TRUE(thread->hasPendingTask()); |
| 357 controller->setNow(controller->now() + base::TimeDelta::FromMilliseconds(thr
ead->pendingDelayMs())); | 357 controller->setNow(controller->now() + base::TimeDelta::FromMilliseconds(thr
ead->pendingDelayMs())); |
| 358 thread->runPendingTask(); | 358 thread->runPendingTask(); |
| 359 } | 359 } |
| 360 | 360 |
| 361 TEST_F(TextureUpdateControllerTest, UpdateMoreTextures) | 361 TEST_F(ResourceUpdateControllerTest, UpdateMoreTextures) |
| 362 { | 362 { |
| 363 FakeTextureUpdateControllerClient client; | 363 FakeResourceUpdateControllerClient client; |
| 364 FakeThread thread; | 364 FakeThread thread; |
| 365 | 365 |
| 366 setMaxUploadCountPerUpdate(1); | 366 setMaxUploadCountPerUpdate(1); |
| 367 appendFullUploadsToUpdateQueue(3); | 367 appendFullUploadsToUpdateQueue(3); |
| 368 appendPartialUploadsToUpdateQueue(0); | 368 appendPartialUploadsToUpdateQueue(0); |
| 369 | 369 |
| 370 DebugScopedSetImplThreadAndMainThreadBlocked | 370 DebugScopedSetImplThreadAndMainThreadBlocked |
| 371 implThreadAndMainThreadBlocked; | 371 implThreadAndMainThreadBlocked; |
| 372 scoped_ptr<FakeTextureUpdateController> controller(FakeTextureUpdateControll
er::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())); |
| 373 | 373 |
| 374 controller->setNow( | 374 controller->setNow( |
| 375 controller->now() + base::TimeDelta::FromMilliseconds(1)); | 375 controller->now() + base::TimeDelta::FromMilliseconds(1)); |
| 376 controller->setUpdateMoreTexturesTime( | 376 controller->setUpdateMoreTexturesTime( |
| 377 base::TimeDelta::FromMilliseconds(100)); | 377 base::TimeDelta::FromMilliseconds(100)); |
| 378 controller->setUpdateMoreTexturesSize(1); | 378 controller->setUpdateMoreTexturesSize(1); |
| 379 // Not enough time for any updates. | 379 // Not enough time for any updates. |
| 380 controller->performMoreUpdates( | 380 controller->performMoreUpdates( |
| 381 controller->now() + base::TimeDelta::FromMilliseconds(90)); | 381 controller->now() + base::TimeDelta::FromMilliseconds(90)); |
| 382 EXPECT_FALSE(thread.hasPendingTask()); | 382 EXPECT_FALSE(thread.hasPendingTask()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 397 // Enough time for 2 updates. | 397 // Enough time for 2 updates. |
| 398 controller->performMoreUpdates( | 398 controller->performMoreUpdates( |
| 399 controller->now() + base::TimeDelta::FromMilliseconds(220)); | 399 controller->now() + base::TimeDelta::FromMilliseconds(220)); |
| 400 runPendingTask(&thread, controller.get()); | 400 runPendingTask(&thread, controller.get()); |
| 401 runPendingTask(&thread, controller.get()); | 401 runPendingTask(&thread, controller.get()); |
| 402 EXPECT_FALSE(thread.hasPendingTask()); | 402 EXPECT_FALSE(thread.hasPendingTask()); |
| 403 EXPECT_TRUE(client.readyToFinalizeCalled()); | 403 EXPECT_TRUE(client.readyToFinalizeCalled()); |
| 404 EXPECT_EQ(3, m_numTotalUploads); | 404 EXPECT_EQ(3, m_numTotalUploads); |
| 405 } | 405 } |
| 406 | 406 |
| 407 TEST_F(TextureUpdateControllerTest, NoMoreUpdates) | 407 TEST_F(ResourceUpdateControllerTest, NoMoreUpdates) |
| 408 { | 408 { |
| 409 FakeTextureUpdateControllerClient client; | 409 FakeResourceUpdateControllerClient client; |
| 410 FakeThread thread; | 410 FakeThread thread; |
| 411 | 411 |
| 412 setMaxUploadCountPerUpdate(1); | 412 setMaxUploadCountPerUpdate(1); |
| 413 appendFullUploadsToUpdateQueue(2); | 413 appendFullUploadsToUpdateQueue(2); |
| 414 appendPartialUploadsToUpdateQueue(0); | 414 appendPartialUploadsToUpdateQueue(0); |
| 415 | 415 |
| 416 DebugScopedSetImplThreadAndMainThreadBlocked | 416 DebugScopedSetImplThreadAndMainThreadBlocked |
| 417 implThreadAndMainThreadBlocked; | 417 implThreadAndMainThreadBlocked; |
| 418 scoped_ptr<FakeTextureUpdateController> controller(FakeTextureUpdateControll
er::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())); |
| 419 | 419 |
| 420 controller->setNow( | 420 controller->setNow( |
| 421 controller->now() + base::TimeDelta::FromMilliseconds(1)); | 421 controller->now() + base::TimeDelta::FromMilliseconds(1)); |
| 422 controller->setUpdateMoreTexturesTime( | 422 controller->setUpdateMoreTexturesTime( |
| 423 base::TimeDelta::FromMilliseconds(100)); | 423 base::TimeDelta::FromMilliseconds(100)); |
| 424 controller->setUpdateMoreTexturesSize(1); | 424 controller->setUpdateMoreTexturesSize(1); |
| 425 // Enough time for 3 updates but only 2 necessary. | 425 // Enough time for 3 updates but only 2 necessary. |
| 426 controller->performMoreUpdates( | 426 controller->performMoreUpdates( |
| 427 controller->now() + base::TimeDelta::FromMilliseconds(310)); | 427 controller->now() + base::TimeDelta::FromMilliseconds(310)); |
| 428 runPendingTask(&thread, controller.get()); | 428 runPendingTask(&thread, controller.get()); |
| 429 runPendingTask(&thread, controller.get()); | 429 runPendingTask(&thread, controller.get()); |
| 430 EXPECT_FALSE(thread.hasPendingTask()); | 430 EXPECT_FALSE(thread.hasPendingTask()); |
| 431 EXPECT_TRUE(client.readyToFinalizeCalled()); | 431 EXPECT_TRUE(client.readyToFinalizeCalled()); |
| 432 EXPECT_EQ(2, m_numTotalUploads); | 432 EXPECT_EQ(2, m_numTotalUploads); |
| 433 | 433 |
| 434 controller->setUpdateMoreTexturesTime( | 434 controller->setUpdateMoreTexturesTime( |
| 435 base::TimeDelta::FromMilliseconds(100)); | 435 base::TimeDelta::FromMilliseconds(100)); |
| 436 controller->setUpdateMoreTexturesSize(1); | 436 controller->setUpdateMoreTexturesSize(1); |
| 437 // Enough time for updates but no more updates left. | 437 // Enough time for updates but no more updates left. |
| 438 controller->performMoreUpdates( | 438 controller->performMoreUpdates( |
| 439 controller->now() + base::TimeDelta::FromMilliseconds(310)); | 439 controller->now() + base::TimeDelta::FromMilliseconds(310)); |
| 440 // 0-delay task used to call readyToFinalizeTextureUpdates(). | 440 // 0-delay task used to call readyToFinalizeTextureUpdates(). |
| 441 runPendingTask(&thread, controller.get()); | 441 runPendingTask(&thread, controller.get()); |
| 442 EXPECT_FALSE(thread.hasPendingTask()); | 442 EXPECT_FALSE(thread.hasPendingTask()); |
| 443 EXPECT_TRUE(client.readyToFinalizeCalled()); | 443 EXPECT_TRUE(client.readyToFinalizeCalled()); |
| 444 EXPECT_EQ(2, m_numTotalUploads); | 444 EXPECT_EQ(2, m_numTotalUploads); |
| 445 } | 445 } |
| 446 | 446 |
| 447 TEST_F(TextureUpdateControllerTest, UpdatesCompleteInFiniteTime) | 447 TEST_F(ResourceUpdateControllerTest, UpdatesCompleteInFiniteTime) |
| 448 { | 448 { |
| 449 FakeTextureUpdateControllerClient client; | 449 FakeResourceUpdateControllerClient client; |
| 450 FakeThread thread; | 450 FakeThread thread; |
| 451 | 451 |
| 452 setMaxUploadCountPerUpdate(1); | 452 setMaxUploadCountPerUpdate(1); |
| 453 appendFullUploadsToUpdateQueue(2); | 453 appendFullUploadsToUpdateQueue(2); |
| 454 appendPartialUploadsToUpdateQueue(0); | 454 appendPartialUploadsToUpdateQueue(0); |
| 455 | 455 |
| 456 DebugScopedSetImplThreadAndMainThreadBlocked | 456 DebugScopedSetImplThreadAndMainThreadBlocked |
| 457 implThreadAndMainThreadBlocked; | 457 implThreadAndMainThreadBlocked; |
| 458 scoped_ptr<FakeTextureUpdateController> controller(FakeTextureUpdateControll
er::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())); |
| 459 | 459 |
| 460 controller->setNow( | 460 controller->setNow( |
| 461 controller->now() + base::TimeDelta::FromMilliseconds(1)); | 461 controller->now() + base::TimeDelta::FromMilliseconds(1)); |
| 462 controller->setUpdateMoreTexturesTime( | 462 controller->setUpdateMoreTexturesTime( |
| 463 base::TimeDelta::FromMilliseconds(500)); | 463 base::TimeDelta::FromMilliseconds(500)); |
| 464 controller->setUpdateMoreTexturesSize(1); | 464 controller->setUpdateMoreTexturesSize(1); |
| 465 | 465 |
| 466 for (int i = 0; i < 100; i++) { | 466 for (int i = 0; i < 100; i++) { |
| 467 if (client.readyToFinalizeCalled()) | 467 if (client.readyToFinalizeCalled()) |
| 468 break; | 468 break; |
| 469 | 469 |
| 470 // Not enough time for any updates. | 470 // Not enough time for any updates. |
| 471 controller->performMoreUpdates( | 471 controller->performMoreUpdates( |
| 472 controller->now() + base::TimeDelta::FromMilliseconds(400)); | 472 controller->now() + base::TimeDelta::FromMilliseconds(400)); |
| 473 | 473 |
| 474 if (thread.hasPendingTask()) | 474 if (thread.hasPendingTask()) |
| 475 runPendingTask(&thread, controller.get()); | 475 runPendingTask(&thread, controller.get()); |
| 476 } | 476 } |
| 477 | 477 |
| 478 EXPECT_FALSE(thread.hasPendingTask()); | 478 EXPECT_FALSE(thread.hasPendingTask()); |
| 479 EXPECT_TRUE(client.readyToFinalizeCalled()); | 479 EXPECT_TRUE(client.readyToFinalizeCalled()); |
| 480 EXPECT_EQ(2, m_numTotalUploads); | 480 EXPECT_EQ(2, m_numTotalUploads); |
| 481 } | 481 } |
| 482 | 482 |
| 483 } // namespace | 483 } // namespace |
| OLD | NEW |