| 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 "CCTextureUpdateController.h" | 7 #include "CCTextureUpdateController.h" |
| 8 | 8 |
| 9 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread | 9 #include "CCSingleThreadProxy.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 CCTextureUpdateControllerTest; | 29 class TextureUpdateControllerTest; |
| 30 | 30 |
| 31 class WebGraphicsContext3DForUploadTest : public FakeWebGraphicsContext3D { | 31 class WebGraphicsContext3DForUploadTest : public FakeWebGraphicsContext3D { |
| 32 public: | 32 public: |
| 33 WebGraphicsContext3DForUploadTest(CCTextureUpdateControllerTest *test) | 33 WebGraphicsContext3DForUploadTest(TextureUpdateControllerTest *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 GrGLInterface* onCreateGrGLInterface() { return 0; } | 40 virtual GrGLInterface* onCreateGrGLInterface() { return 0; } |
| 41 | 41 |
| 42 virtual WebString getString(WGC3Denum name) | 42 virtual WebString getString(WGC3Denum name) |
| 43 { | 43 { |
| 44 if (m_supportShallowFlush) | 44 if (m_supportShallowFlush) |
| 45 return WebString("GL_CHROMIUM_shallow_flush"); | 45 return WebString("GL_CHROMIUM_shallow_flush"); |
| 46 return WebString(""); | 46 return WebString(""); |
| 47 } | 47 } |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 CCTextureUpdateControllerTest* m_test; | 50 TextureUpdateControllerTest* m_test; |
| 51 bool m_supportShallowFlush; | 51 bool m_supportShallowFlush; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 | 54 |
| 55 class TextureUploaderForUploadTest : public FakeTextureUploader { | 55 class TextureUploaderForUploadTest : public FakeTextureUploader { |
| 56 public: | 56 public: |
| 57 TextureUploaderForUploadTest(CCTextureUpdateControllerTest *test) : m_test(t
est) { } | 57 TextureUploaderForUploadTest(TextureUpdateControllerTest *test) : m_test(tes
t) { } |
| 58 | 58 |
| 59 virtual void uploadTexture(cc::CCResourceProvider*, Parameters) OVERRIDE; | 59 virtual void uploadTexture(cc::ResourceProvider*, Parameters) OVERRIDE; |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 CCTextureUpdateControllerTest* m_test; | 62 TextureUpdateControllerTest* m_test; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 class CCTextureUpdateControllerTest : public Test { | 65 class TextureUpdateControllerTest : public Test { |
| 66 public: | 66 public: |
| 67 CCTextureUpdateControllerTest() | 67 TextureUpdateControllerTest() |
| 68 : m_queue(make_scoped_ptr(new CCTextureUpdateQueue)) | 68 : m_queue(make_scoped_ptr(new TextureUpdateQueue)) |
| 69 , m_uploader(this) | 69 , m_uploader(this) |
| 70 , m_compositorInitializer(m_thread.get()) | 70 , m_compositorInitializer(m_thread.get()) |
| 71 , m_fullUploadCountExpected(0) | 71 , m_fullUploadCountExpected(0) |
| 72 , m_partialCountExpected(0) | 72 , m_partialCountExpected(0) |
| 73 , m_totalUploadCountExpected(0) | 73 , m_totalUploadCountExpected(0) |
| 74 , m_maxUploadCountPerUpdate(0) | 74 , m_maxUploadCountPerUpdate(0) |
| 75 , m_numConsecutiveFlushes(0) | 75 , m_numConsecutiveFlushes(0) |
| 76 , m_numDanglingUploads(0) | 76 , m_numDanglingUploads(0) |
| 77 , m_numTotalUploads(0) | 77 , m_numTotalUploads(0) |
| 78 , m_numTotalFlushes(0) | 78 , m_numTotalFlushes(0) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 101 m_numConsecutiveFlushes = 0; | 101 m_numConsecutiveFlushes = 0; |
| 102 m_numDanglingUploads++; | 102 m_numDanglingUploads++; |
| 103 m_numTotalUploads++; | 103 m_numTotalUploads++; |
| 104 } | 104 } |
| 105 | 105 |
| 106 protected: | 106 protected: |
| 107 virtual void SetUp() | 107 virtual void SetUp() |
| 108 { | 108 { |
| 109 m_context = FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::We
bGraphicsContext3D>(new WebGraphicsContext3DForUploadTest(this))); | 109 m_context = FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::We
bGraphicsContext3D>(new WebGraphicsContext3DForUploadTest(this))); |
| 110 DebugScopedSetImplThread implThread; | 110 DebugScopedSetImplThread implThread; |
| 111 m_resourceProvider = CCResourceProvider::create(m_context.get()); | 111 m_resourceProvider = ResourceProvider::create(m_context.get()); |
| 112 for (int i = 0; i < 4; i++) | 112 for (int i = 0; i < 4; i++) |
| 113 m_textures[i] = CCPrioritizedTexture::create( | 113 m_textures[i] = PrioritizedTexture::create( |
| 114 NULL, IntSize(256, 256), GL_RGBA); | 114 NULL, IntSize(256, 256), GL_RGBA); |
| 115 } | 115 } |
| 116 | 116 |
| 117 | 117 |
| 118 void appendFullUploadsOfIndexedTextureToUpdateQueue(int count, int textureIn
dex) | 118 void appendFullUploadsOfIndexedTextureToUpdateQueue(int count, int textureIn
dex) |
| 119 { | 119 { |
| 120 m_fullUploadCountExpected += count; | 120 m_fullUploadCountExpected += count; |
| 121 m_totalUploadCountExpected += count; | 121 m_totalUploadCountExpected += count; |
| 122 | 122 |
| 123 const IntRect rect(0, 0, 300, 150); | 123 const IntRect rect(0, 0, 300, 150); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 147 appendPartialUploadsOfIndexedTextureToUpdateQueue(count, 0); | 147 appendPartialUploadsOfIndexedTextureToUpdateQueue(count, 0); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void setMaxUploadCountPerUpdate(int count) | 150 void setMaxUploadCountPerUpdate(int count) |
| 151 { | 151 { |
| 152 m_maxUploadCountPerUpdate = count; | 152 m_maxUploadCountPerUpdate = count; |
| 153 } | 153 } |
| 154 | 154 |
| 155 void updateTextures() | 155 void updateTextures() |
| 156 { | 156 { |
| 157 scoped_ptr<CCTextureUpdateController> updateController = | 157 scoped_ptr<TextureUpdateController> updateController = |
| 158 CCTextureUpdateController::create( | 158 TextureUpdateController::create( |
| 159 NULL, | 159 NULL, |
| 160 CCProxy::implThread(), | 160 Proxy::implThread(), |
| 161 m_queue.Pass(), | 161 m_queue.Pass(), |
| 162 m_resourceProvider.get(), | 162 m_resourceProvider.get(), |
| 163 &m_uploader); | 163 &m_uploader); |
| 164 updateController->finalize(); | 164 updateController->finalize(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 protected: | 167 protected: |
| 168 // Classes required to interact and test the CCTextureUpdateController | 168 // Classes required to interact and test the TextureUpdateController |
| 169 scoped_ptr<CCGraphicsContext> m_context; | 169 scoped_ptr<GraphicsContext> m_context; |
| 170 scoped_ptr<CCResourceProvider> m_resourceProvider; | 170 scoped_ptr<ResourceProvider> m_resourceProvider; |
| 171 scoped_ptr<CCTextureUpdateQueue> m_queue; | 171 scoped_ptr<TextureUpdateQueue> m_queue; |
| 172 scoped_ptr<CCPrioritizedTexture> m_textures[4]; | 172 scoped_ptr<PrioritizedTexture> m_textures[4]; |
| 173 TextureUploaderForUploadTest m_uploader; | 173 TextureUploaderForUploadTest m_uploader; |
| 174 scoped_ptr<WebThread> m_thread; | 174 scoped_ptr<WebThread> m_thread; |
| 175 WebCompositorInitializer m_compositorInitializer; | 175 WebCompositorInitializer m_compositorInitializer; |
| 176 | 176 |
| 177 | 177 |
| 178 // Properties / expectations of this test | 178 // Properties / expectations of this test |
| 179 int m_fullUploadCountExpected; | 179 int m_fullUploadCountExpected; |
| 180 int m_partialCountExpected; | 180 int m_partialCountExpected; |
| 181 int m_totalUploadCountExpected; | 181 int m_totalUploadCountExpected; |
| 182 int m_maxUploadCountPerUpdate; | 182 int m_maxUploadCountPerUpdate; |
| 183 | 183 |
| 184 // Dynamic properties of this test | 184 // Dynamic properties of this test |
| 185 int m_numConsecutiveFlushes; | 185 int m_numConsecutiveFlushes; |
| 186 int m_numDanglingUploads; | 186 int m_numDanglingUploads; |
| 187 int m_numTotalUploads; | 187 int m_numTotalUploads; |
| 188 int m_numTotalFlushes; | 188 int m_numTotalFlushes; |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 void WebGraphicsContext3DForUploadTest::flush(void) | 191 void WebGraphicsContext3DForUploadTest::flush(void) |
| 192 { | 192 { |
| 193 m_test->onFlush(); | 193 m_test->onFlush(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void WebGraphicsContext3DForUploadTest::shallowFlushCHROMIUM(void) | 196 void WebGraphicsContext3DForUploadTest::shallowFlushCHROMIUM(void) |
| 197 { | 197 { |
| 198 m_test->onFlush(); | 198 m_test->onFlush(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void TextureUploaderForUploadTest::uploadTexture(cc::CCResourceProvider*, Parame
ters) | 201 void TextureUploaderForUploadTest::uploadTexture(cc::ResourceProvider*, Paramete
rs) |
| 202 { | 202 { |
| 203 m_test->onUpload(); | 203 m_test->onUpload(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 // ZERO UPLOADS TESTS | 206 // ZERO UPLOADS TESTS |
| 207 TEST_F(CCTextureUpdateControllerTest, ZeroUploads) | 207 TEST_F(TextureUpdateControllerTest, ZeroUploads) |
| 208 { | 208 { |
| 209 appendFullUploadsToUpdateQueue(0); | 209 appendFullUploadsToUpdateQueue(0); |
| 210 appendPartialUploadsToUpdateQueue(0); | 210 appendPartialUploadsToUpdateQueue(0); |
| 211 DebugScopedSetImplThread implThread; | 211 DebugScopedSetImplThread implThread; |
| 212 updateTextures(); | 212 updateTextures(); |
| 213 | 213 |
| 214 EXPECT_EQ(0, m_numTotalFlushes); | 214 EXPECT_EQ(0, m_numTotalFlushes); |
| 215 EXPECT_EQ(0, m_numTotalUploads); | 215 EXPECT_EQ(0, m_numTotalUploads); |
| 216 } | 216 } |
| 217 | 217 |
| 218 | 218 |
| 219 // ONE UPLOAD TESTS | 219 // ONE UPLOAD TESTS |
| 220 TEST_F(CCTextureUpdateControllerTest, OneFullUpload) | 220 TEST_F(TextureUpdateControllerTest, OneFullUpload) |
| 221 { | 221 { |
| 222 appendFullUploadsToUpdateQueue(1); | 222 appendFullUploadsToUpdateQueue(1); |
| 223 appendPartialUploadsToUpdateQueue(0); | 223 appendPartialUploadsToUpdateQueue(0); |
| 224 DebugScopedSetImplThread implThread; | 224 DebugScopedSetImplThread implThread; |
| 225 updateTextures(); | 225 updateTextures(); |
| 226 | 226 |
| 227 EXPECT_EQ(1, m_numTotalFlushes); | 227 EXPECT_EQ(1, m_numTotalFlushes); |
| 228 EXPECT_EQ(1, m_numTotalUploads); | 228 EXPECT_EQ(1, m_numTotalUploads); |
| 229 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; | 229 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; |
| 230 } | 230 } |
| 231 | 231 |
| 232 TEST_F(CCTextureUpdateControllerTest, OnePartialUpload) | 232 TEST_F(TextureUpdateControllerTest, OnePartialUpload) |
| 233 { | 233 { |
| 234 appendFullUploadsToUpdateQueue(0); | 234 appendFullUploadsToUpdateQueue(0); |
| 235 appendPartialUploadsToUpdateQueue(1); | 235 appendPartialUploadsToUpdateQueue(1); |
| 236 DebugScopedSetImplThread implThread; | 236 DebugScopedSetImplThread implThread; |
| 237 updateTextures(); | 237 updateTextures(); |
| 238 | 238 |
| 239 EXPECT_EQ(1, m_numTotalFlushes); | 239 EXPECT_EQ(1, m_numTotalFlushes); |
| 240 EXPECT_EQ(1, m_numTotalUploads); | 240 EXPECT_EQ(1, m_numTotalUploads); |
| 241 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; | 241 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; |
| 242 } | 242 } |
| 243 | 243 |
| 244 TEST_F(CCTextureUpdateControllerTest, OneFullOnePartialUpload) | 244 TEST_F(TextureUpdateControllerTest, OneFullOnePartialUpload) |
| 245 { | 245 { |
| 246 appendFullUploadsToUpdateQueue(1); | 246 appendFullUploadsToUpdateQueue(1); |
| 247 appendPartialUploadsToUpdateQueue(1); | 247 appendPartialUploadsToUpdateQueue(1); |
| 248 DebugScopedSetImplThread implThread; | 248 DebugScopedSetImplThread implThread; |
| 249 updateTextures(); | 249 updateTextures(); |
| 250 | 250 |
| 251 EXPECT_EQ(1, m_numTotalFlushes); | 251 EXPECT_EQ(1, m_numTotalFlushes); |
| 252 EXPECT_EQ(2, m_numTotalUploads); | 252 EXPECT_EQ(2, m_numTotalUploads); |
| 253 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; | 253 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; |
| 254 } | 254 } |
| 255 | 255 |
| 256 | 256 |
| 257 // This class of tests upload a number of textures that is a multiple of the flu
sh period. | 257 // This class of tests upload a number of textures that is a multiple of the flu
sh period. |
| 258 const int fullUploadFlushMultipler = 7; | 258 const int fullUploadFlushMultipler = 7; |
| 259 const int fullCount = fullUploadFlushMultipler * kFlushPeriodFull; | 259 const int fullCount = fullUploadFlushMultipler * kFlushPeriodFull; |
| 260 | 260 |
| 261 const int partialUploadFlushMultipler = 11; | 261 const int partialUploadFlushMultipler = 11; |
| 262 const int partialCount = partialUploadFlushMultipler * kFlushPeriodPartial; | 262 const int partialCount = partialUploadFlushMultipler * kFlushPeriodPartial; |
| 263 | 263 |
| 264 TEST_F(CCTextureUpdateControllerTest, ManyFullUploads) | 264 TEST_F(TextureUpdateControllerTest, ManyFullUploads) |
| 265 { | 265 { |
| 266 appendFullUploadsToUpdateQueue(fullCount); | 266 appendFullUploadsToUpdateQueue(fullCount); |
| 267 appendPartialUploadsToUpdateQueue(0); | 267 appendPartialUploadsToUpdateQueue(0); |
| 268 DebugScopedSetImplThread implThread; | 268 DebugScopedSetImplThread implThread; |
| 269 updateTextures(); | 269 updateTextures(); |
| 270 | 270 |
| 271 EXPECT_EQ(fullUploadFlushMultipler, m_numTotalFlushes); | 271 EXPECT_EQ(fullUploadFlushMultipler, m_numTotalFlushes); |
| 272 EXPECT_EQ(fullCount, m_numTotalUploads); | 272 EXPECT_EQ(fullCount, m_numTotalUploads); |
| 273 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; | 273 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; |
| 274 } | 274 } |
| 275 | 275 |
| 276 TEST_F(CCTextureUpdateControllerTest, ManyPartialUploads) | 276 TEST_F(TextureUpdateControllerTest, ManyPartialUploads) |
| 277 { | 277 { |
| 278 appendFullUploadsToUpdateQueue(0); | 278 appendFullUploadsToUpdateQueue(0); |
| 279 appendPartialUploadsToUpdateQueue(partialCount); | 279 appendPartialUploadsToUpdateQueue(partialCount); |
| 280 DebugScopedSetImplThread implThread; | 280 DebugScopedSetImplThread implThread; |
| 281 updateTextures(); | 281 updateTextures(); |
| 282 | 282 |
| 283 EXPECT_EQ(partialUploadFlushMultipler, m_numTotalFlushes); | 283 EXPECT_EQ(partialUploadFlushMultipler, m_numTotalFlushes); |
| 284 EXPECT_EQ(partialCount, m_numTotalUploads); | 284 EXPECT_EQ(partialCount, m_numTotalUploads); |
| 285 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; | 285 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; |
| 286 } | 286 } |
| 287 | 287 |
| 288 TEST_F(CCTextureUpdateControllerTest, ManyFullManyPartialUploads) | 288 TEST_F(TextureUpdateControllerTest, ManyFullManyPartialUploads) |
| 289 { | 289 { |
| 290 appendFullUploadsToUpdateQueue(fullCount); | 290 appendFullUploadsToUpdateQueue(fullCount); |
| 291 appendPartialUploadsToUpdateQueue(partialCount); | 291 appendPartialUploadsToUpdateQueue(partialCount); |
| 292 DebugScopedSetImplThread implThread; | 292 DebugScopedSetImplThread implThread; |
| 293 updateTextures(); | 293 updateTextures(); |
| 294 | 294 |
| 295 EXPECT_EQ(fullUploadFlushMultipler + partialUploadFlushMultipler, m_numTotal
Flushes); | 295 EXPECT_EQ(fullUploadFlushMultipler + partialUploadFlushMultipler, m_numTotal
Flushes); |
| 296 EXPECT_EQ(fullCount + partialCount, m_numTotalUploads); | 296 EXPECT_EQ(fullCount + partialCount, m_numTotalUploads); |
| 297 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; | 297 EXPECT_EQ(0, m_numDanglingUploads) << "Last upload wasn't followed by a flus
h."; |
| 298 } | 298 } |
| 299 | 299 |
| 300 class FakeCCTextureUpdateControllerClient : public cc::CCTextureUpdateController
Client { | 300 class FakeTextureUpdateControllerClient : public cc::TextureUpdateControllerClie
nt { |
| 301 public: | 301 public: |
| 302 FakeCCTextureUpdateControllerClient() { reset(); } | 302 FakeTextureUpdateControllerClient() { reset(); } |
| 303 void reset() { m_readyToFinalizeCalled = false; } | 303 void reset() { m_readyToFinalizeCalled = false; } |
| 304 bool readyToFinalizeCalled() const { return m_readyToFinalizeCalled; } | 304 bool readyToFinalizeCalled() const { return m_readyToFinalizeCalled; } |
| 305 | 305 |
| 306 virtual void readyToFinalizeTextureUpdates() OVERRIDE { m_readyToFinalizeCal
led = true; } | 306 virtual void readyToFinalizeTextureUpdates() OVERRIDE { m_readyToFinalizeCal
led = true; } |
| 307 | 307 |
| 308 protected: | 308 protected: |
| 309 bool m_readyToFinalizeCalled; | 309 bool m_readyToFinalizeCalled; |
| 310 }; | 310 }; |
| 311 | 311 |
| 312 class FakeCCTextureUpdateController : public cc::CCTextureUpdateController { | 312 class FakeTextureUpdateController : public cc::TextureUpdateController { |
| 313 public: | 313 public: |
| 314 static scoped_ptr<FakeCCTextureUpdateController> create(cc::CCTextureUpdateC
ontrollerClient* client, cc::CCThread* thread, scoped_ptr<CCTextureUpdateQueue>
queue, CCResourceProvider* resourceProvider, TextureUploader* uploader) | 314 static scoped_ptr<FakeTextureUpdateController> create(cc::TextureUpdateContr
ollerClient* client, cc::Thread* thread, scoped_ptr<TextureUpdateQueue> queue, R
esourceProvider* resourceProvider, TextureUploader* uploader) |
| 315 { | 315 { |
| 316 return make_scoped_ptr(new FakeCCTextureUpdateController(client, thread,
queue.Pass(), resourceProvider, uploader)); | 316 return make_scoped_ptr(new FakeTextureUpdateController(client, thread, q
ueue.Pass(), resourceProvider, uploader)); |
| 317 } | 317 } |
| 318 | 318 |
| 319 void setNow(base::TimeTicks time) { m_now = time; } | 319 void setNow(base::TimeTicks time) { m_now = time; } |
| 320 virtual base::TimeTicks now() const OVERRIDE { return m_now; } | 320 virtual base::TimeTicks now() const OVERRIDE { return m_now; } |
| 321 void setUpdateMoreTexturesTime(base::TimeDelta time) { m_updateMoreTexturesT
ime = time; } | 321 void setUpdateMoreTexturesTime(base::TimeDelta time) { m_updateMoreTexturesT
ime = time; } |
| 322 virtual base::TimeDelta updateMoreTexturesTime() const OVERRIDE { return m_u
pdateMoreTexturesTime; } | 322 virtual base::TimeDelta updateMoreTexturesTime() const OVERRIDE { return m_u
pdateMoreTexturesTime; } |
| 323 void setUpdateMoreTexturesSize(size_t size) { m_updateMoreTexturesSize = siz
e; } | 323 void setUpdateMoreTexturesSize(size_t size) { m_updateMoreTexturesSize = siz
e; } |
| 324 virtual size_t updateMoreTexturesSize() const OVERRIDE { return m_updateMore
TexturesSize; } | 324 virtual size_t updateMoreTexturesSize() const OVERRIDE { return m_updateMore
TexturesSize; } |
| 325 | 325 |
| 326 protected: | 326 protected: |
| 327 FakeCCTextureUpdateController(cc::CCTextureUpdateControllerClient* client, c
c::CCThread* thread, scoped_ptr<CCTextureUpdateQueue> queue, CCResourceProvider*
resourceProvider, TextureUploader* uploader) | 327 FakeTextureUpdateController(cc::TextureUpdateControllerClient* client, cc::T
hread* thread, scoped_ptr<TextureUpdateQueue> queue, ResourceProvider* resourceP
rovider, TextureUploader* uploader) |
| 328 : cc::CCTextureUpdateController(client, thread, queue.Pass(), resourcePr
ovider, uploader) | 328 : cc::TextureUpdateController(client, thread, queue.Pass(), resourceProv
ider, uploader) |
| 329 , m_updateMoreTexturesSize(0) { } | 329 , m_updateMoreTexturesSize(0) { } |
| 330 | 330 |
| 331 base::TimeTicks m_now; | 331 base::TimeTicks m_now; |
| 332 base::TimeDelta m_updateMoreTexturesTime; | 332 base::TimeDelta m_updateMoreTexturesTime; |
| 333 size_t m_updateMoreTexturesSize; | 333 size_t m_updateMoreTexturesSize; |
| 334 }; | 334 }; |
| 335 | 335 |
| 336 static void runPendingTask(FakeCCThread* thread, FakeCCTextureUpdateController*
controller) | 336 static void runPendingTask(FakeThread* thread, FakeTextureUpdateController* cont
roller) |
| 337 { | 337 { |
| 338 EXPECT_TRUE(thread->hasPendingTask()); | 338 EXPECT_TRUE(thread->hasPendingTask()); |
| 339 controller->setNow(controller->now() + base::TimeDelta::FromMilliseconds(thr
ead->pendingDelayMs())); | 339 controller->setNow(controller->now() + base::TimeDelta::FromMilliseconds(thr
ead->pendingDelayMs())); |
| 340 thread->runPendingTask(); | 340 thread->runPendingTask(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 TEST_F(CCTextureUpdateControllerTest, UpdateMoreTextures) | 343 TEST_F(TextureUpdateControllerTest, UpdateMoreTextures) |
| 344 { | 344 { |
| 345 FakeCCTextureUpdateControllerClient client; | 345 FakeTextureUpdateControllerClient client; |
| 346 FakeCCThread thread; | 346 FakeThread thread; |
| 347 | 347 |
| 348 setMaxUploadCountPerUpdate(1); | 348 setMaxUploadCountPerUpdate(1); |
| 349 appendFullUploadsToUpdateQueue(3); | 349 appendFullUploadsToUpdateQueue(3); |
| 350 appendPartialUploadsToUpdateQueue(0); | 350 appendPartialUploadsToUpdateQueue(0); |
| 351 | 351 |
| 352 DebugScopedSetImplThread implThread; | 352 DebugScopedSetImplThread implThread; |
| 353 scoped_ptr<FakeCCTextureUpdateController> controller(FakeCCTextureUpdateCont
roller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get(), &m_up
loader)); | 353 scoped_ptr<FakeTextureUpdateController> controller(FakeTextureUpdateControll
er::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get(), &m_upload
er)); |
| 354 | 354 |
| 355 controller->setNow( | 355 controller->setNow( |
| 356 controller->now() + base::TimeDelta::FromMilliseconds(1)); | 356 controller->now() + base::TimeDelta::FromMilliseconds(1)); |
| 357 controller->setUpdateMoreTexturesTime( | 357 controller->setUpdateMoreTexturesTime( |
| 358 base::TimeDelta::FromMilliseconds(100)); | 358 base::TimeDelta::FromMilliseconds(100)); |
| 359 controller->setUpdateMoreTexturesSize(1); | 359 controller->setUpdateMoreTexturesSize(1); |
| 360 // Not enough time for any updates. | 360 // Not enough time for any updates. |
| 361 controller->performMoreUpdates( | 361 controller->performMoreUpdates( |
| 362 controller->now() + base::TimeDelta::FromMilliseconds(90)); | 362 controller->now() + base::TimeDelta::FromMilliseconds(90)); |
| 363 EXPECT_FALSE(thread.hasPendingTask()); | 363 EXPECT_FALSE(thread.hasPendingTask()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 378 // Enough time for 2 updates. | 378 // Enough time for 2 updates. |
| 379 controller->performMoreUpdates( | 379 controller->performMoreUpdates( |
| 380 controller->now() + base::TimeDelta::FromMilliseconds(220)); | 380 controller->now() + base::TimeDelta::FromMilliseconds(220)); |
| 381 runPendingTask(&thread, controller.get()); | 381 runPendingTask(&thread, controller.get()); |
| 382 runPendingTask(&thread, controller.get()); | 382 runPendingTask(&thread, controller.get()); |
| 383 EXPECT_FALSE(thread.hasPendingTask()); | 383 EXPECT_FALSE(thread.hasPendingTask()); |
| 384 EXPECT_TRUE(client.readyToFinalizeCalled()); | 384 EXPECT_TRUE(client.readyToFinalizeCalled()); |
| 385 EXPECT_EQ(3, m_numTotalUploads); | 385 EXPECT_EQ(3, m_numTotalUploads); |
| 386 } | 386 } |
| 387 | 387 |
| 388 TEST_F(CCTextureUpdateControllerTest, NoMoreUpdates) | 388 TEST_F(TextureUpdateControllerTest, NoMoreUpdates) |
| 389 { | 389 { |
| 390 FakeCCTextureUpdateControllerClient client; | 390 FakeTextureUpdateControllerClient client; |
| 391 FakeCCThread thread; | 391 FakeThread thread; |
| 392 | 392 |
| 393 setMaxUploadCountPerUpdate(1); | 393 setMaxUploadCountPerUpdate(1); |
| 394 appendFullUploadsToUpdateQueue(2); | 394 appendFullUploadsToUpdateQueue(2); |
| 395 appendPartialUploadsToUpdateQueue(0); | 395 appendPartialUploadsToUpdateQueue(0); |
| 396 | 396 |
| 397 DebugScopedSetImplThread implThread; | 397 DebugScopedSetImplThread implThread; |
| 398 scoped_ptr<FakeCCTextureUpdateController> controller(FakeCCTextureUpdateCont
roller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get(), &m_up
loader)); | 398 scoped_ptr<FakeTextureUpdateController> controller(FakeTextureUpdateControll
er::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get(), &m_upload
er)); |
| 399 | 399 |
| 400 controller->setNow( | 400 controller->setNow( |
| 401 controller->now() + base::TimeDelta::FromMilliseconds(1)); | 401 controller->now() + base::TimeDelta::FromMilliseconds(1)); |
| 402 controller->setUpdateMoreTexturesTime( | 402 controller->setUpdateMoreTexturesTime( |
| 403 base::TimeDelta::FromMilliseconds(100)); | 403 base::TimeDelta::FromMilliseconds(100)); |
| 404 controller->setUpdateMoreTexturesSize(1); | 404 controller->setUpdateMoreTexturesSize(1); |
| 405 // Enough time for 3 updates but only 2 necessary. | 405 // Enough time for 3 updates but only 2 necessary. |
| 406 controller->performMoreUpdates( | 406 controller->performMoreUpdates( |
| 407 controller->now() + base::TimeDelta::FromMilliseconds(310)); | 407 controller->now() + base::TimeDelta::FromMilliseconds(310)); |
| 408 runPendingTask(&thread, controller.get()); | 408 runPendingTask(&thread, controller.get()); |
| 409 runPendingTask(&thread, controller.get()); | 409 runPendingTask(&thread, controller.get()); |
| 410 EXPECT_FALSE(thread.hasPendingTask()); | 410 EXPECT_FALSE(thread.hasPendingTask()); |
| 411 EXPECT_TRUE(client.readyToFinalizeCalled()); | 411 EXPECT_TRUE(client.readyToFinalizeCalled()); |
| 412 EXPECT_EQ(2, m_numTotalUploads); | 412 EXPECT_EQ(2, m_numTotalUploads); |
| 413 | 413 |
| 414 controller->setUpdateMoreTexturesTime( | 414 controller->setUpdateMoreTexturesTime( |
| 415 base::TimeDelta::FromMilliseconds(100)); | 415 base::TimeDelta::FromMilliseconds(100)); |
| 416 controller->setUpdateMoreTexturesSize(1); | 416 controller->setUpdateMoreTexturesSize(1); |
| 417 // Enough time for updates but no more updates left. | 417 // Enough time for updates but no more updates left. |
| 418 controller->performMoreUpdates( | 418 controller->performMoreUpdates( |
| 419 controller->now() + base::TimeDelta::FromMilliseconds(310)); | 419 controller->now() + base::TimeDelta::FromMilliseconds(310)); |
| 420 // 0-delay task used to call readyToFinalizeTextureUpdates(). | 420 // 0-delay task used to call readyToFinalizeTextureUpdates(). |
| 421 runPendingTask(&thread, controller.get()); | 421 runPendingTask(&thread, controller.get()); |
| 422 EXPECT_FALSE(thread.hasPendingTask()); | 422 EXPECT_FALSE(thread.hasPendingTask()); |
| 423 EXPECT_TRUE(client.readyToFinalizeCalled()); | 423 EXPECT_TRUE(client.readyToFinalizeCalled()); |
| 424 EXPECT_EQ(2, m_numTotalUploads); | 424 EXPECT_EQ(2, m_numTotalUploads); |
| 425 } | 425 } |
| 426 | 426 |
| 427 TEST_F(CCTextureUpdateControllerTest, UpdatesCompleteInFiniteTime) | 427 TEST_F(TextureUpdateControllerTest, UpdatesCompleteInFiniteTime) |
| 428 { | 428 { |
| 429 FakeCCTextureUpdateControllerClient client; | 429 FakeTextureUpdateControllerClient client; |
| 430 FakeCCThread thread; | 430 FakeThread thread; |
| 431 | 431 |
| 432 setMaxUploadCountPerUpdate(1); | 432 setMaxUploadCountPerUpdate(1); |
| 433 appendFullUploadsToUpdateQueue(2); | 433 appendFullUploadsToUpdateQueue(2); |
| 434 appendPartialUploadsToUpdateQueue(0); | 434 appendPartialUploadsToUpdateQueue(0); |
| 435 | 435 |
| 436 DebugScopedSetImplThread implThread; | 436 DebugScopedSetImplThread implThread; |
| 437 scoped_ptr<FakeCCTextureUpdateController> controller(FakeCCTextureUpdateCont
roller::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get(), &m_up
loader)); | 437 scoped_ptr<FakeTextureUpdateController> controller(FakeTextureUpdateControll
er::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get(), &m_upload
er)); |
| 438 | 438 |
| 439 controller->setNow( | 439 controller->setNow( |
| 440 controller->now() + base::TimeDelta::FromMilliseconds(1)); | 440 controller->now() + base::TimeDelta::FromMilliseconds(1)); |
| 441 controller->setUpdateMoreTexturesTime( | 441 controller->setUpdateMoreTexturesTime( |
| 442 base::TimeDelta::FromMilliseconds(500)); | 442 base::TimeDelta::FromMilliseconds(500)); |
| 443 controller->setUpdateMoreTexturesSize(1); | 443 controller->setUpdateMoreTexturesSize(1); |
| 444 | 444 |
| 445 for (int i = 0; i < 100; i++) { | 445 for (int i = 0; i < 100; i++) { |
| 446 if (client.readyToFinalizeCalled()) | 446 if (client.readyToFinalizeCalled()) |
| 447 break; | 447 break; |
| 448 | 448 |
| 449 // Not enough time for any updates. | 449 // Not enough time for any updates. |
| 450 controller->performMoreUpdates( | 450 controller->performMoreUpdates( |
| 451 controller->now() + base::TimeDelta::FromMilliseconds(400)); | 451 controller->now() + base::TimeDelta::FromMilliseconds(400)); |
| 452 | 452 |
| 453 if (thread.hasPendingTask()) | 453 if (thread.hasPendingTask()) |
| 454 runPendingTask(&thread, controller.get()); | 454 runPendingTask(&thread, controller.get()); |
| 455 } | 455 } |
| 456 | 456 |
| 457 EXPECT_FALSE(thread.hasPendingTask()); | 457 EXPECT_FALSE(thread.hasPendingTask()); |
| 458 EXPECT_TRUE(client.readyToFinalizeCalled()); | 458 EXPECT_TRUE(client.readyToFinalizeCalled()); |
| 459 EXPECT_EQ(2, m_numTotalUploads); | 459 EXPECT_EQ(2, m_numTotalUploads); |
| 460 } | 460 } |
| 461 | 461 |
| 462 } // namespace | 462 } // namespace |
| OLD | NEW |