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 "CCSchedulerTestCommon.h" | 9 #include "CCSchedulerTestCommon.h" |
10 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread | 10 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 virtual void beginUploads() OVERRIDE; | 60 virtual void beginUploads() OVERRIDE; |
61 virtual void endUploads() OVERRIDE; | 61 virtual void endUploads() OVERRIDE; |
62 virtual void uploadTexture(cc::CCResourceProvider*, Parameters) OVERRIDE; | 62 virtual void uploadTexture(cc::CCResourceProvider*, Parameters) OVERRIDE; |
63 | 63 |
64 private: | 64 private: |
65 CCTextureUpdateControllerTest* m_test; | 65 CCTextureUpdateControllerTest* m_test; |
66 }; | 66 }; |
67 | 67 |
68 class TextureForUploadTest : public LayerTextureUpdater::Texture { | 68 class TextureForUploadTest : public LayerTextureUpdater::Texture { |
69 public: | 69 public: |
70 TextureForUploadTest() : LayerTextureUpdater::Texture(adoptPtr<CCPrioritized Texture>(0)) { } | 70 TextureForUploadTest() |
71 : LayerTextureUpdater::Texture(adoptPtr<CCPrioritizedTexture>(0)) | |
jamesr
2012/09/19 20:54:37
protip: you can just type "nullptr" instead of ado
| |
72 , m_evicted(false) | |
73 { | |
74 } | |
71 virtual void updateRect(CCResourceProvider*, const IntRect& sourceRect, cons t IntSize& destOffset) { } | 75 virtual void updateRect(CCResourceProvider*, const IntRect& sourceRect, cons t IntSize& destOffset) { } |
76 virtual bool backingResourceWasEvicted() const { return m_evicted; } | |
77 void evictBackingResource() { m_evicted = true; } | |
78 private: | |
79 bool m_evicted; | |
72 }; | 80 }; |
73 | 81 |
74 | 82 |
75 class CCTextureUpdateControllerTest : public Test { | 83 class CCTextureUpdateControllerTest : public Test { |
76 public: | 84 public: |
77 CCTextureUpdateControllerTest() | 85 CCTextureUpdateControllerTest() |
78 : m_queue(adoptPtr(new CCTextureUpdateQueue)) | 86 : m_queue(adoptPtr(new CCTextureUpdateQueue)) |
79 , m_uploader(this) | 87 , m_uploader(this) |
80 , m_compositorInitializer(m_thread.get()) | 88 , m_compositorInitializer(m_thread.get()) |
81 , m_fullUploadCountExpected(0) | 89 , m_fullUploadCountExpected(0) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 } | 158 } |
151 | 159 |
152 protected: | 160 protected: |
153 virtual void SetUp() | 161 virtual void SetUp() |
154 { | 162 { |
155 m_context = FakeWebCompositorOutputSurface::create(adoptPtr(new WebGraph icsContext3DForUploadTest(this))); | 163 m_context = FakeWebCompositorOutputSurface::create(adoptPtr(new WebGraph icsContext3DForUploadTest(this))); |
156 DebugScopedSetImplThread implThread; | 164 DebugScopedSetImplThread implThread; |
157 m_resourceProvider = CCResourceProvider::create(m_context.get(), Unthrot tledUploader); | 165 m_resourceProvider = CCResourceProvider::create(m_context.get(), Unthrot tledUploader); |
158 } | 166 } |
159 | 167 |
160 void appendFullUploadsToUpdateQueue(int count) | 168 |
169 void appendFullUploadsOfIndexedTextureToUpdateQueue(int count, int textureIn dex) | |
161 { | 170 { |
162 m_fullUploadCountExpected += count; | 171 m_fullUploadCountExpected += count; |
163 m_totalUploadCountExpected += count; | 172 m_totalUploadCountExpected += count; |
164 | 173 |
165 const IntRect rect(0, 0, 300, 150); | 174 const IntRect rect(0, 0, 300, 150); |
166 const TextureUploader::Parameters upload = { &m_texture, rect, IntSize() }; | 175 const TextureUploader::Parameters upload = { &m_textures[textureIndex], rect, IntSize() }; |
167 for (int i = 0; i < count; i++) | 176 for (int i = 0; i < count; i++) |
168 m_queue->appendFullUpload(upload); | 177 m_queue->appendFullUpload(upload); |
169 } | 178 } |
170 | 179 |
171 void appendPartialUploadsToUpdateQueue(int count) | 180 void appendFullUploadsToUpdateQueue(int count) |
181 { | |
182 appendFullUploadsOfIndexedTextureToUpdateQueue(count, 0); | |
183 } | |
184 | |
185 void appendPartialUploadsOfIndexedTextureToUpdateQueue(int count, int textur eIndex) | |
172 { | 186 { |
173 m_partialCountExpected += count; | 187 m_partialCountExpected += count; |
174 m_totalUploadCountExpected += count; | 188 m_totalUploadCountExpected += count; |
175 | 189 |
176 const IntRect rect(0, 0, 100, 100); | 190 const IntRect rect(0, 0, 100, 100); |
177 const TextureUploader::Parameters upload = { &m_texture, rect, IntSize() }; | 191 const TextureUploader::Parameters upload = { &m_textures[textureIndex], rect, IntSize() }; |
178 for (int i = 0; i < count; i++) | 192 for (int i = 0; i < count; i++) |
179 m_queue->appendPartialUpload(upload); | 193 m_queue->appendPartialUpload(upload); |
180 } | 194 } |
181 | 195 |
196 void appendPartialUploadsToUpdateQueue(int count) | |
197 { | |
198 appendPartialUploadsOfIndexedTextureToUpdateQueue(count, 0); | |
199 } | |
200 | |
182 void setMaxUploadCountPerUpdate(int count) | 201 void setMaxUploadCountPerUpdate(int count) |
183 { | 202 { |
184 m_maxUploadCountPerUpdate = count; | 203 m_maxUploadCountPerUpdate = count; |
185 } | 204 } |
186 | 205 |
187 protected: | 206 protected: |
188 // Classes required to interact and test the CCTextureUpdateController | 207 // Classes required to interact and test the CCTextureUpdateController |
189 OwnPtr<CCGraphicsContext> m_context; | 208 OwnPtr<CCGraphicsContext> m_context; |
190 OwnPtr<CCResourceProvider> m_resourceProvider; | 209 OwnPtr<CCResourceProvider> m_resourceProvider; |
191 OwnPtr<CCTextureUpdateQueue> m_queue; | 210 OwnPtr<CCTextureUpdateQueue> m_queue; |
192 TextureForUploadTest m_texture; | 211 TextureForUploadTest m_textures[4]; |
193 TextureUploaderForUploadTest m_uploader; | 212 TextureUploaderForUploadTest m_uploader; |
194 OwnPtr<WebThread> m_thread; | 213 OwnPtr<WebThread> m_thread; |
195 WebCompositorInitializer m_compositorInitializer; | 214 WebCompositorInitializer m_compositorInitializer; |
196 | 215 |
197 | 216 |
198 // Properties / expectations of this test | 217 // Properties / expectations of this test |
199 int m_fullUploadCountExpected; | 218 int m_fullUploadCountExpected; |
200 int m_partialCountExpected; | 219 int m_partialCountExpected; |
201 int m_totalUploadCountExpected; | 220 int m_totalUploadCountExpected; |
202 int m_maxUploadCountPerUpdate; | 221 int m_maxUploadCountPerUpdate; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 runPendingTask(&thread, controller.get()); | 502 runPendingTask(&thread, controller.get()); |
484 } | 503 } |
485 | 504 |
486 EXPECT_FALSE(thread.hasPendingTask()); | 505 EXPECT_FALSE(thread.hasPendingTask()); |
487 EXPECT_TRUE(client.readyToFinalizeCalled()); | 506 EXPECT_TRUE(client.readyToFinalizeCalled()); |
488 EXPECT_EQ(2, m_numBeginUploads); | 507 EXPECT_EQ(2, m_numBeginUploads); |
489 EXPECT_EQ(2, m_numEndUploads); | 508 EXPECT_EQ(2, m_numEndUploads); |
490 EXPECT_EQ(2, m_numTotalUploads); | 509 EXPECT_EQ(2, m_numTotalUploads); |
491 } | 510 } |
492 | 511 |
512 TEST_F(CCTextureUpdateControllerTest, ClearUploadsToEvictedResources) | |
513 { | |
514 appendFullUploadsOfIndexedTextureToUpdateQueue(1, 0); | |
515 appendPartialUploadsOfIndexedTextureToUpdateQueue(1, 1); | |
516 appendFullUploadsOfIndexedTextureToUpdateQueue(1, 2); | |
517 appendPartialUploadsOfIndexedTextureToUpdateQueue(1, 3); | |
518 DebugScopedSetImplThread implThread; | |
519 | |
520 m_queue->clearUploadsToEvictedResources(); | |
521 EXPECT_EQ(2u, m_queue->fullUploadSize()); | |
522 EXPECT_EQ(2u, m_queue->partialUploadSize()); | |
523 | |
524 m_textures[0].evictBackingResource(); | |
525 m_queue->clearUploadsToEvictedResources(); | |
526 EXPECT_EQ(1u, m_queue->fullUploadSize()); | |
527 EXPECT_EQ(2u, m_queue->partialUploadSize()); | |
528 | |
529 m_textures[3].evictBackingResource(); | |
530 m_queue->clearUploadsToEvictedResources(); | |
531 EXPECT_EQ(1u, m_queue->fullUploadSize()); | |
532 EXPECT_EQ(1u, m_queue->partialUploadSize()); | |
533 | |
534 m_textures[2].evictBackingResource(); | |
535 m_queue->clearUploadsToEvictedResources(); | |
536 EXPECT_EQ(0u, m_queue->fullUploadSize()); | |
537 EXPECT_EQ(1u, m_queue->partialUploadSize()); | |
538 | |
539 m_textures[1].evictBackingResource(); | |
540 m_queue->clearUploadsToEvictedResources(); | |
541 EXPECT_EQ(0u, m_queue->fullUploadSize()); | |
542 EXPECT_EQ(0u, m_queue->partialUploadSize()); | |
543 } | |
544 | |
493 } // namespace | 545 } // namespace |
OLD | NEW |