Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: cc/tiles/picture_layer_tiling_set.cc

Issue 1168903003: cc: Fix size_t to int truncations in tiles/ and trees/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/tiles/picture_layer_tiling_set.h ('k') | cc/tiles/picture_layer_tiling_set_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 size_t tilings_size = set_->tilings_.size();
392 static_cast<size_t>(ideal_tiling_) < set_->tilings_.size(); 392 for (ideal_tiling_ = 0; ideal_tiling_ < tilings_size; ++ideal_tiling_) {
393 ++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_ == 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
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 (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
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 size_t tilings_size = tilings_.size();
559 TilingRange high_res_range(0, 0); 554 TilingRange high_res_range(0, 0);
560 TilingRange low_res_range(tilings_.size(), tilings_.size()); 555 TilingRange low_res_range(tilings_.size(), tilings_.size());
561 for (size_t i = 0; i < tilings_.size(); ++i) { 556 for (size_t i = 0; i < tilings_size; ++i) {
562 const PictureLayerTiling* tiling = tilings_[i]; 557 const PictureLayerTiling* tiling = tilings_[i];
563 if (tiling->resolution() == HIGH_RESOLUTION) 558 if (tiling->resolution() == HIGH_RESOLUTION)
564 high_res_range = TilingRange(i, i + 1); 559 high_res_range = TilingRange(i, i + 1);
565 if (tiling->resolution() == LOW_RESOLUTION) 560 if (tiling->resolution() == LOW_RESOLUTION)
566 low_res_range = TilingRange(i, i + 1); 561 low_res_range = TilingRange(i, i + 1);
567 } 562 }
568 563
569 TilingRange range(0, 0); 564 TilingRange range(0, 0);
570 switch (type) { 565 switch (type) {
571 case HIGHER_THAN_HIGH_RES: 566 case HIGHER_THAN_HIGH_RES:
(...skipping 11 matching lines...) Expand all
583 // tiling discussion/fixes. 578 // tiling discussion/fixes.
584 if (high_res_range.start <= low_res_range.start) 579 if (high_res_range.start <= low_res_range.start)
585 range = TilingRange(high_res_range.end, low_res_range.start); 580 range = TilingRange(high_res_range.end, low_res_range.start);
586 else 581 else
587 range = TilingRange(low_res_range.end, high_res_range.start); 582 range = TilingRange(low_res_range.end, high_res_range.start);
588 break; 583 break;
589 case LOW_RES: 584 case LOW_RES:
590 range = low_res_range; 585 range = low_res_range;
591 break; 586 break;
592 case LOWER_THAN_LOW_RES: 587 case LOWER_THAN_LOW_RES:
593 range = TilingRange(low_res_range.end, tilings_.size()); 588 range = TilingRange(low_res_range.end, tilings_size);
594 break; 589 break;
595 } 590 }
596 591
597 DCHECK_LE(range.start, range.end); 592 DCHECK_LE(range.start, range.end);
598 return range; 593 return range;
599 } 594 }
600 595
601 } // namespace cc 596 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/picture_layer_tiling_set.h ('k') | cc/tiles/picture_layer_tiling_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698