Chromium Code Reviews| 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 "cc/tiles/picture_layer_tiling_set.h" | 5 #include "cc/tiles/picture_layer_tiling_set.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 } | 378 } |
| 379 | 379 |
| 380 PictureLayerTilingSet::CoverageIterator::CoverageIterator( | 380 PictureLayerTilingSet::CoverageIterator::CoverageIterator( |
| 381 const PictureLayerTilingSet* set, | 381 const PictureLayerTilingSet* set, |
| 382 float contents_scale, | 382 float contents_scale, |
| 383 const gfx::Rect& content_rect, | 383 const gfx::Rect& content_rect, |
| 384 float ideal_contents_scale) | 384 float ideal_contents_scale) |
| 385 : set_(set), | 385 : set_(set), |
| 386 contents_scale_(contents_scale), | 386 contents_scale_(contents_scale), |
| 387 ideal_contents_scale_(ideal_contents_scale), | 387 ideal_contents_scale_(ideal_contents_scale), |
| 388 current_tiling_(-1) { | 388 current_tiling_(std::numeric_limits<size_t>::max()) { |
| 389 missing_region_.Union(content_rect); | 389 missing_region_.Union(content_rect); |
| 390 | 390 |
| 391 for (ideal_tiling_ = 0; | 391 for (ideal_tiling_ = 0; ideal_tiling_ < set_->tilings_.size(); |
|
danakj
2015/06/09 17:39:49
can you cache the size up here so we only call it
vmpstr
2015/06/09 18:37:17
Done.
| |
| 392 static_cast<size_t>(ideal_tiling_) < set_->tilings_.size(); | |
| 393 ++ideal_tiling_) { | 392 ++ideal_tiling_) { |
| 394 PictureLayerTiling* tiling = set_->tilings_[ideal_tiling_]; | 393 PictureLayerTiling* tiling = set_->tilings_[ideal_tiling_]; |
| 395 if (tiling->contents_scale() < ideal_contents_scale_) { | 394 if (tiling->contents_scale() < ideal_contents_scale_) { |
| 396 if (ideal_tiling_ > 0) | 395 if (ideal_tiling_ > 0) |
| 397 ideal_tiling_--; | 396 ideal_tiling_--; |
| 398 break; | 397 break; |
| 399 } | 398 } |
| 400 } | 399 } |
| 401 | 400 |
| 402 DCHECK_LE(set_->tilings_.size(), | 401 if (ideal_tiling_ == set->tilings_.size() && ideal_tiling_ > 0) |
| 403 static_cast<size_t>(std::numeric_limits<int>::max())); | |
| 404 | |
| 405 int num_tilings = set_->tilings_.size(); | |
| 406 if (ideal_tiling_ == num_tilings && ideal_tiling_ > 0) | |
| 407 ideal_tiling_--; | 402 ideal_tiling_--; |
| 408 | 403 |
| 409 ++(*this); | 404 ++(*this); |
| 410 } | 405 } |
| 411 | 406 |
| 412 PictureLayerTilingSet::CoverageIterator::~CoverageIterator() { | 407 PictureLayerTilingSet::CoverageIterator::~CoverageIterator() { |
| 413 } | 408 } |
| 414 | 409 |
| 415 gfx::Rect PictureLayerTilingSet::CoverageIterator::geometry_rect() const { | 410 gfx::Rect PictureLayerTilingSet::CoverageIterator::geometry_rect() const { |
| 416 if (!tiling_iter_) { | 411 if (!tiling_iter_) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 440 } | 435 } |
| 441 | 436 |
| 442 TileResolution PictureLayerTilingSet::CoverageIterator::resolution() const { | 437 TileResolution PictureLayerTilingSet::CoverageIterator::resolution() const { |
| 443 const PictureLayerTiling* tiling = CurrentTiling(); | 438 const PictureLayerTiling* tiling = CurrentTiling(); |
| 444 DCHECK(tiling); | 439 DCHECK(tiling); |
| 445 return tiling->resolution(); | 440 return tiling->resolution(); |
| 446 } | 441 } |
| 447 | 442 |
| 448 PictureLayerTiling* PictureLayerTilingSet::CoverageIterator::CurrentTiling() | 443 PictureLayerTiling* PictureLayerTilingSet::CoverageIterator::CurrentTiling() |
| 449 const { | 444 const { |
| 450 if (current_tiling_ < 0) | 445 if (current_tiling_ == std::numeric_limits<size_t>::max()) |
| 451 return NULL; | 446 return NULL; |
| 452 if (static_cast<size_t>(current_tiling_) >= set_->tilings_.size()) | 447 if (static_cast<size_t>(current_tiling_) >= set_->tilings_.size()) |
| 453 return NULL; | 448 return NULL; |
| 454 return set_->tilings_[current_tiling_]; | 449 return set_->tilings_[current_tiling_]; |
| 455 } | 450 } |
| 456 | 451 |
| 457 int PictureLayerTilingSet::CoverageIterator::NextTiling() const { | 452 size_t PictureLayerTilingSet::CoverageIterator::NextTiling() const { |
| 458 // Order returned by this method is: | 453 // Order returned by this method is: |
| 459 // 1. Ideal tiling index | 454 // 1. Ideal tiling index |
| 460 // 2. Tiling index < Ideal in decreasing order (higher res than ideal) | 455 // 2. Tiling index < Ideal in decreasing order (higher res than ideal) |
| 461 // 3. Tiling index > Ideal in increasing order (lower res than ideal) | 456 // 3. Tiling index > Ideal in increasing order (lower res than ideal) |
| 462 // 4. Tiling index > tilings.size() (invalid index) | 457 // 4. Tiling index > tilings.size() (invalid index) |
| 463 if (current_tiling_ < 0) | 458 if (current_tiling_ == std::numeric_limits<size_t>::max()) |
| 464 return ideal_tiling_; | 459 return ideal_tiling_; |
| 465 else if (current_tiling_ > ideal_tiling_) | 460 else if (current_tiling_ > ideal_tiling_) |
| 466 return current_tiling_ + 1; | 461 return current_tiling_ + 1; |
| 467 else if (current_tiling_) | 462 else if (current_tiling_) |
| 468 return current_tiling_ - 1; | 463 return current_tiling_ - 1; |
| 469 else | 464 else |
| 470 return ideal_tiling_ + 1; | 465 return ideal_tiling_ + 1; |
| 471 } | 466 } |
| 472 | 467 |
| 473 PictureLayerTilingSet::CoverageIterator& | 468 PictureLayerTilingSet::CoverageIterator& |
| 474 PictureLayerTilingSet::CoverageIterator::operator++() { | 469 PictureLayerTilingSet::CoverageIterator::operator++() { |
| 475 bool first_time = current_tiling_ < 0; | 470 bool first_time = current_tiling_ == std::numeric_limits<size_t>::max(); |
| 476 | 471 |
| 477 if (!*this && !first_time) | 472 if (!*this && !first_time) |
| 478 return *this; | 473 return *this; |
| 479 | 474 |
| 480 if (tiling_iter_) | 475 if (tiling_iter_) |
| 481 ++tiling_iter_; | 476 ++tiling_iter_; |
| 482 | 477 |
| 483 // Loop until we find a valid place to stop. | 478 // Loop until we find a valid place to stop. |
| 484 while (true) { | 479 while (true) { |
| 485 while (tiling_iter_ && | 480 while (tiling_iter_ && |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 499 missing_region_.Clear(); | 494 missing_region_.Clear(); |
| 500 region_iter_ = Region::Iterator(current_region_); | 495 region_iter_ = Region::Iterator(current_region_); |
| 501 | 496 |
| 502 // All done and all filled. | 497 // All done and all filled. |
| 503 if (!region_iter_.has_rect()) { | 498 if (!region_iter_.has_rect()) { |
| 504 current_tiling_ = set_->tilings_.size(); | 499 current_tiling_ = set_->tilings_.size(); |
| 505 return *this; | 500 return *this; |
| 506 } | 501 } |
| 507 | 502 |
| 508 // No more valid tiles, return this checkerboard rect. | 503 // No more valid tiles, return this checkerboard rect. |
| 509 if (current_tiling_ >= static_cast<int>(set_->tilings_.size())) | 504 if (current_tiling_ >= set_->tilings_.size()) |
| 510 return *this; | 505 return *this; |
| 511 } | 506 } |
| 512 | 507 |
| 513 // Pop a rect off. If there are no more tilings, then these will be | 508 // Pop a rect off. If there are no more tilings, then these will be |
| 514 // treated as geometry with null tiles that the caller can checkerboard. | 509 // treated as geometry with null tiles that the caller can checkerboard. |
| 515 gfx::Rect last_rect = region_iter_.rect(); | 510 gfx::Rect last_rect = region_iter_.rect(); |
| 516 region_iter_.next(); | 511 region_iter_.next(); |
| 517 | 512 |
| 518 // Done, found next checkerboard rect to return. | 513 // Done, found next checkerboard rect to return. |
| 519 if (current_tiling_ >= static_cast<int>(set_->tilings_.size())) | 514 if (current_tiling_ >= set_->tilings_.size()) |
| 520 return *this; | 515 return *this; |
| 521 | 516 |
| 522 // Construct a new iterator for the next tiling, but we need to loop | 517 // Construct a new iterator for the next tiling, but we need to loop |
| 523 // again until we get to a valid one. | 518 // again until we get to a valid one. |
| 524 tiling_iter_ = PictureLayerTiling::CoverageIterator( | 519 tiling_iter_ = PictureLayerTiling::CoverageIterator( |
| 525 set_->tilings_[current_tiling_], | 520 set_->tilings_[current_tiling_], |
| 526 contents_scale_, | 521 contents_scale_, |
| 527 last_rect); | 522 last_rect); |
| 528 } | 523 } |
| 529 | 524 |
| 530 return *this; | 525 return *this; |
| 531 } | 526 } |
| 532 | 527 |
| 533 PictureLayerTilingSet::CoverageIterator::operator bool() const { | 528 PictureLayerTilingSet::CoverageIterator::operator bool() const { |
| 534 return current_tiling_ < static_cast<int>(set_->tilings_.size()) || | 529 return current_tiling_ < set_->tilings_.size() || region_iter_.has_rect(); |
| 535 region_iter_.has_rect(); | |
| 536 } | 530 } |
| 537 | 531 |
| 538 void PictureLayerTilingSet::AsValueInto( | 532 void PictureLayerTilingSet::AsValueInto( |
| 539 base::trace_event::TracedValue* state) const { | 533 base::trace_event::TracedValue* state) const { |
| 540 for (size_t i = 0; i < tilings_.size(); ++i) { | 534 for (size_t i = 0; i < tilings_.size(); ++i) { |
| 541 state->BeginDictionary(); | 535 state->BeginDictionary(); |
| 542 tilings_[i]->AsValueInto(state); | 536 tilings_[i]->AsValueInto(state); |
| 543 state->EndDictionary(); | 537 state->EndDictionary(); |
| 544 } | 538 } |
| 545 } | 539 } |
| 546 | 540 |
| 547 size_t PictureLayerTilingSet::GPUMemoryUsageInBytes() const { | 541 size_t PictureLayerTilingSet::GPUMemoryUsageInBytes() const { |
| 548 size_t amount = 0; | 542 size_t amount = 0; |
| 549 for (size_t i = 0; i < tilings_.size(); ++i) | 543 for (size_t i = 0; i < tilings_.size(); ++i) |
| 550 amount += tilings_[i]->GPUMemoryUsageInBytes(); | 544 amount += tilings_[i]->GPUMemoryUsageInBytes(); |
| 551 return amount; | 545 return amount; |
| 552 } | 546 } |
| 553 | 547 |
| 554 PictureLayerTilingSet::TilingRange PictureLayerTilingSet::GetTilingRange( | 548 PictureLayerTilingSet::TilingRange PictureLayerTilingSet::GetTilingRange( |
| 555 TilingRangeType type) const { | 549 TilingRangeType type) const { |
| 556 // Doesn't seem to be the case right now but if it ever becomes a performance | 550 // Doesn't seem to be the case right now but if it ever becomes a performance |
| 557 // problem to compute these ranges each time this function is called, we can | 551 // problem to compute these ranges each time this function is called, we can |
| 558 // compute them only when the tiling set has changed instead. | 552 // compute them only when the tiling set has changed instead. |
| 553 DCHECK_LE(tilings_.size(), | |
|
danakj
2015/06/09 17:39:49
Wat. You went to all the trouble to use size_t eve
vmpstr
2015/06/09 18:37:17
I have fixed this.
| |
| 554 static_cast<size_t>(std::numeric_limits<int>::max())); | |
| 555 int tilings_size = static_cast<int>(tilings_.size()); | |
| 559 TilingRange high_res_range(0, 0); | 556 TilingRange high_res_range(0, 0); |
| 560 TilingRange low_res_range(tilings_.size(), tilings_.size()); | 557 TilingRange low_res_range(tilings_.size(), tilings_.size()); |
| 561 for (size_t i = 0; i < tilings_.size(); ++i) { | 558 for (int i = 0; i < tilings_size; ++i) { |
| 562 const PictureLayerTiling* tiling = tilings_[i]; | 559 const PictureLayerTiling* tiling = tilings_[i]; |
| 563 if (tiling->resolution() == HIGH_RESOLUTION) | 560 if (tiling->resolution() == HIGH_RESOLUTION) |
| 564 high_res_range = TilingRange(i, i + 1); | 561 high_res_range = TilingRange(i, i + 1); |
| 565 if (tiling->resolution() == LOW_RESOLUTION) | 562 if (tiling->resolution() == LOW_RESOLUTION) |
| 566 low_res_range = TilingRange(i, i + 1); | 563 low_res_range = TilingRange(i, i + 1); |
| 567 } | 564 } |
| 568 | 565 |
| 569 TilingRange range(0, 0); | 566 TilingRange range(0, 0); |
| 570 switch (type) { | 567 switch (type) { |
| 571 case HIGHER_THAN_HIGH_RES: | 568 case HIGHER_THAN_HIGH_RES: |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 583 // tiling discussion/fixes. | 580 // tiling discussion/fixes. |
| 584 if (high_res_range.start <= low_res_range.start) | 581 if (high_res_range.start <= low_res_range.start) |
| 585 range = TilingRange(high_res_range.end, low_res_range.start); | 582 range = TilingRange(high_res_range.end, low_res_range.start); |
| 586 else | 583 else |
| 587 range = TilingRange(low_res_range.end, high_res_range.start); | 584 range = TilingRange(low_res_range.end, high_res_range.start); |
| 588 break; | 585 break; |
| 589 case LOW_RES: | 586 case LOW_RES: |
| 590 range = low_res_range; | 587 range = low_res_range; |
| 591 break; | 588 break; |
| 592 case LOWER_THAN_LOW_RES: | 589 case LOWER_THAN_LOW_RES: |
| 593 range = TilingRange(low_res_range.end, tilings_.size()); | 590 range = TilingRange(low_res_range.end, tilings_size); |
| 594 break; | 591 break; |
| 595 } | 592 } |
| 596 | 593 |
| 597 DCHECK_LE(range.start, range.end); | 594 DCHECK_LE(range.start, range.end); |
| 598 return range; | 595 return range; |
| 599 } | 596 } |
| 600 | 597 |
| 601 } // namespace cc | 598 } // namespace cc |
| OLD | NEW |