Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "cc/resources/resource_pool.h" | 5 #include "cc/resources/resource_pool.h" |
| 6 | 6 |
| 7 #include <iostream> | |
| 8 #include <map> | |
| 9 | |
| 7 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 8 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 9 #include "cc/resources/resource_util.h" | 12 #include "cc/resources/resource_util.h" |
| 10 #include "cc/resources/scoped_resource.h" | 13 #include "cc/resources/scoped_resource.h" |
| 11 #include "cc/test/fake_output_surface.h" | 14 #include "cc/test/fake_output_surface.h" |
| 12 #include "cc/test/fake_output_surface_client.h" | 15 #include "cc/test/fake_output_surface_client.h" |
| 13 #include "cc/test/fake_resource_provider.h" | 16 #include "cc/test/fake_resource_provider.h" |
| 14 #include "cc/test/test_shared_bitmap_manager.h" | 17 #include "cc/test/test_shared_bitmap_manager.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 19 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 // released within 100 ms, give the thread up to 200. | 214 // released within 100 ms, give the thread up to 200. |
| 212 base::RunLoop run_loop; | 215 base::RunLoop run_loop; |
| 213 task_runner_->PostDelayedTask(FROM_HERE, run_loop.QuitClosure(), | 216 task_runner_->PostDelayedTask(FROM_HERE, run_loop.QuitClosure(), |
| 214 base::TimeDelta::FromMillisecondsD(200)); | 217 base::TimeDelta::FromMillisecondsD(200)); |
| 215 run_loop.Run(); | 218 run_loop.Run(); |
| 216 | 219 |
| 217 EXPECT_EQ(0u, resource_provider_->num_resources()); | 220 EXPECT_EQ(0u, resource_provider_->num_resources()); |
| 218 EXPECT_EQ(0u, resource_pool_->GetTotalMemoryUsageForTesting()); | 221 EXPECT_EQ(0u, resource_pool_->GetTotalMemoryUsageForTesting()); |
| 219 } | 222 } |
| 220 | 223 |
| 224 struct TestResource { | |
| 225 explicit TestResource(const gfx::Size& size) { this->size = size; } | |
| 226 | |
| 227 gfx::Size size; | |
| 228 // uint64_t content_id; | |
| 229 }; | |
| 230 | |
| 231 class TestDeque { | |
| 232 public: | |
| 233 TestResource* Acquire(const gfx::Size& size) { | |
| 234 TestResource* resource = nullptr; | |
| 235 for (DQ::iterator it = unused_.begin(); it != unused_.end(); ++it) { | |
| 236 resource = *it; | |
| 237 if (resource->size == size) | |
| 238 return resource; | |
|
danakj
2015/11/09 19:32:51
don't you need to erase from from unused_ here?
prashant.n
2015/11/10 04:10:50
No. Basically test is -
1. create n resources
2.
danakj
2015/11/10 22:12:05
But the actual acquire does erase.
| |
| 239 } | |
| 240 | |
| 241 return new TestResource(size); | |
| 242 } | |
| 243 | |
| 244 void AppendToUnused(TestResource* resource) { unused_.push_front(resource); } | |
| 245 | |
| 246 void RemoveAll() { | |
| 247 for (DQ::iterator it = unused_.begin(); it != unused_.end(); ++it) { | |
| 248 delete *it; | |
| 249 } | |
| 250 unused_.clear(); | |
| 251 } | |
| 252 | |
| 253 private: | |
| 254 typedef std::deque<TestResource*> DQ; | |
| 255 DQ unused_; | |
| 256 }; | |
| 257 | |
| 258 class TestMultiDeque { | |
| 259 public: | |
| 260 TestResource* Acquire(const gfx::Size& size) { | |
| 261 TestResource* resource = nullptr; | |
| 262 Key key = std::make_pair(size.width(), size.height()); | |
| 263 DQM::iterator kit = unused_.find(key); | |
| 264 | |
| 265 if (kit != unused_.end()) { | |
| 266 DQ* dq = kit->second; | |
| 267 | |
| 268 for (DQ::iterator it = dq->begin(); it != dq->end(); ++it) { | |
| 269 resource = *it; | |
| 270 if (resource->size == size) | |
| 271 return resource; | |
|
danakj
2015/11/09 19:32:51
and erase from dq and possibly from unused_ here?
| |
| 272 } | |
| 273 } | |
| 274 | |
| 275 return new TestResource(size); | |
| 276 } | |
| 277 | |
| 278 void AppendToUnused(TestResource* resource) { | |
| 279 Key key = std::make_pair(resource->size.width(), resource->size.height()); | |
| 280 DQM::iterator kit = unused_.find(key); | |
| 281 if (kit != unused_.end()) { | |
| 282 DQ* dq = kit->second; | |
| 283 dq->push_front(resource); | |
| 284 } else { | |
| 285 DQ* dq = new DQ; | |
| 286 dq->push_front(resource); | |
| 287 unused_[key] = dq; | |
| 288 } | |
| 289 } | |
| 290 | |
| 291 void RemoveAll() { | |
| 292 for (DQM::iterator kit = unused_.begin(); kit != unused_.end(); ++kit) { | |
| 293 DQ* dq = kit->second; | |
| 294 for (DQ::iterator it = dq->begin(); it != dq->end(); ++it) { | |
| 295 delete *it; | |
| 296 } | |
| 297 delete dq; | |
| 298 } | |
| 299 unused_.clear(); | |
| 300 } | |
| 301 | |
| 302 private: | |
| 303 typedef std::pair<int, int> Key; | |
| 304 typedef std::deque<TestResource*> DQ; | |
| 305 typedef std::map<Key, DQ*> DQM; | |
| 306 DQM unused_; | |
| 307 }; | |
| 308 | |
| 309 void RunTestDeque(int how_many, int tile_round_up, int tile_size_max) { | |
| 310 TestDeque tdq; | |
| 311 gfx::Size size; | |
| 312 int rounds = tile_size_max / tile_round_up; | |
| 313 const int r_max = rounds * rounds * how_many; | |
| 314 TestResource* resource[r_max]; | |
| 315 | |
| 316 int i = 0; | |
| 317 for (int w = tile_round_up; w <= tile_size_max; w += tile_round_up) { | |
| 318 for (int h = tile_round_up; h <= tile_size_max; h += tile_round_up) { | |
| 319 size = gfx::Size(w, h); | |
| 320 for (int j = 0; j < how_many; ++j) | |
| 321 resource[i++] = tdq.Acquire(size); | |
| 322 } | |
| 323 } | |
| 324 | |
| 325 for (int i = 0; i < r_max; ++i) | |
| 326 tdq.AppendToUnused(resource[i]); | |
|
danakj
2015/11/09 19:32:51
Your results appear to include the cost of creatin
prashant.n
2015/11/10 04:10:50
It was not intentional. I thought creating and app
| |
| 327 | |
| 328 size = gfx::Size(1024, 1024); | |
| 329 for (int k = 0; k < 1000000; ++k) { | |
| 330 TestResource* r = tdq.Acquire(size); | |
| 331 delete r; | |
| 332 } | |
| 333 | |
| 334 tdq.RemoveAll(); | |
| 335 } | |
| 336 | |
| 337 void RunTestMultiDeque(int how_many, int tile_round_up, int tile_size_max) { | |
| 338 TestMultiDeque tdq; | |
| 339 gfx::Size size; | |
| 340 int rounds = tile_size_max / tile_round_up; | |
| 341 const int r_max = rounds * rounds * how_many; | |
| 342 TestResource* resource[r_max]; | |
| 343 | |
| 344 int i = 0; | |
| 345 for (int w = tile_round_up; w <= tile_size_max; w += tile_round_up) { | |
| 346 for (int h = tile_round_up; h <= tile_size_max; h += tile_round_up) { | |
| 347 size = gfx::Size(w, h); | |
| 348 for (int j = 0; j < how_many; ++j) | |
| 349 resource[i++] = tdq.Acquire(size); | |
| 350 } | |
| 351 } | |
| 352 | |
| 353 for (int i = 0; i < r_max; ++i) | |
| 354 tdq.AppendToUnused(resource[i]); | |
| 355 | |
| 356 size = gfx::Size(1024, 1024); | |
| 357 for (int k = 0; k < 1000000; ++k) { | |
| 358 TestResource* r = tdq.Acquire(size); | |
| 359 delete r; | |
| 360 } | |
| 361 | |
| 362 tdq.RemoveAll(); | |
| 363 } | |
| 364 | |
| 365 TEST_F(ResourcePoolTest, TestDequeSingle) { | |
| 366 RunTestDeque(1, 64, 64); | |
| 367 } | |
| 368 | |
| 369 TEST_F(ResourcePoolTest, TestMultiDequeSingle) { | |
| 370 RunTestMultiDeque(1, 64, 64); | |
| 371 } | |
| 372 | |
| 373 TEST_F(ResourcePoolTest, TestDequeManyOfOneSize) { | |
| 374 RunTestDeque(50, 64, 64); | |
| 375 } | |
| 376 | |
| 377 TEST_F(ResourcePoolTest, TestMultiDequeManyOfOneSize) { | |
| 378 RunTestMultiDeque(50, 64, 64); | |
| 379 } | |
| 380 | |
| 381 TEST_F(ResourcePoolTest, TestDequeOneOfEachSize) { | |
| 382 RunTestDeque(1, 64, 512); | |
| 383 } | |
| 384 | |
| 385 TEST_F(ResourcePoolTest, TestMultiDequeOneOfEachSize) { | |
| 386 RunTestMultiDeque(1, 64, 512); | |
| 387 } | |
| 388 | |
| 389 TEST_F(ResourcePoolTest, TestDequeManyOfEachSize) { | |
| 390 RunTestDeque(5, 64, 512); | |
| 391 } | |
| 392 | |
| 393 TEST_F(ResourcePoolTest, TestMultiDequeManyOfEachSize) { | |
| 394 RunTestMultiDeque(5, 64, 512); | |
| 395 } | |
| 396 | |
| 397 TEST_F(ResourcePoolTest, TestDequeTooManyOfEachSize) { | |
| 398 RunTestDeque(20, 64, 512); | |
| 399 } | |
| 400 | |
| 401 TEST_F(ResourcePoolTest, TestMultiDequeTooManyOfEachSize) { | |
| 402 RunTestMultiDeque(20, 64, 512); | |
| 403 } | |
| 404 | |
| 221 } // namespace | 405 } // namespace |
| 222 } // namespace cc | 406 } // namespace cc |
| OLD | NEW |