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

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

Issue 2295343005: Improve PictureLayerTiling::CoverageIterator to handle rounding more precisely (Closed)
Patch Set: Created 4 years, 3 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/base/tiling_data.cc ('k') | no next file » | 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.h" 5 #include "cc/tiles/picture_layer_tiling.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 left_(0), 398 left_(0),
399 top_(0), 399 top_(0),
400 right_(-1), 400 right_(-1),
401 bottom_(-1) { 401 bottom_(-1) {
402 DCHECK(tiling_); 402 DCHECK(tiling_);
403 if (dest_rect_.IsEmpty()) 403 if (dest_rect_.IsEmpty())
404 return; 404 return;
405 405
406 dest_to_content_scale_ = tiling_->contents_scale_ / dest_scale; 406 dest_to_content_scale_ = tiling_->contents_scale_ / dest_scale;
407 407
408 gfx::Rect content_rect = 408 SkRect content_rect;
enne (OOO) 2016/09/02 19:04:54 What's with SkRect here?
trchen 2016/09/02 23:06:54 LTRB rect is also preferred here. I'll covert it t
409 gfx::ScaleToEnclosingRect(dest_rect_, 409 SkMatrix::MakeScale(dest_to_content_scale_)
410 dest_to_content_scale_, 410 .mapRectScaleTranslate(&content_rect, gfx::RectToSkRect(dest_rect_));
411 dest_to_content_scale_); 411 // Shrink rect by 1/512 to avoid generating empty tiles due to FP error.
enne (OOO) 2016/09/02 19:04:54 Sorry, but I'm not sure I follow this.
trchen 2016/09/02 23:06:54 It is for avoid hitting DCHECK on line #487. Alth
412 float epsilon = 1.f / 512.f;
413 content_rect.inset(epsilon, epsilon);
412 // IndexFromSrcCoord clamps to valid tile ranges, so it's necessary to 414 // IndexFromSrcCoord clamps to valid tile ranges, so it's necessary to
413 // check for non-intersection first. 415 // check for non-intersection first.
414 content_rect.Intersect(gfx::Rect(tiling_->tiling_size())); 416 if (!content_rect.intersect(
415 if (content_rect.IsEmpty()) 417 gfx::RectToSkRect(gfx::Rect(tiling_->tiling_size()))))
416 return; 418 return;
417 419
418 left_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(content_rect.x()); 420 left_ = tiling_->tiling_data_.LastBorderTileXIndexFromSrcCoord(
enne (OOO) 2016/09/02 19:04:54 Can you leave some comments about where the 0.5 is
trchen 2016/09/02 23:06:54 Acknowledged. It is difference between sample poi
419 top_ = tiling_->tiling_data_.TileYIndexFromSrcCoord(content_rect.y()); 421 floorf(content_rect.left() - 0.5f));
420 right_ = tiling_->tiling_data_.TileXIndexFromSrcCoord( 422 top_ = tiling_->tiling_data_.LastBorderTileYIndexFromSrcCoord(
421 content_rect.right() - 1); 423 floorf(content_rect.top() - 0.5f));
422 bottom_ = tiling_->tiling_data_.TileYIndexFromSrcCoord( 424 right_ = std::max(tiling_->tiling_data_.FirstBorderTileXIndexFromSrcCoord(
423 content_rect.bottom() - 1); 425 ceilf(content_rect.right() - 0.5f)),
426 left_);
427 bottom_ = std::max(tiling_->tiling_data_.FirstBorderTileYIndexFromSrcCoord(
428 ceilf(content_rect.bottom() - 0.5f)),
429 top_);
424 430
425 tile_i_ = left_ - 1; 431 tile_i_ = left_ - 1;
426 tile_j_ = top_; 432 tile_j_ = top_;
427 ++(*this); 433 ++(*this);
428 } 434 }
429 435
430 PictureLayerTiling::CoverageIterator::~CoverageIterator() { 436 PictureLayerTiling::CoverageIterator::~CoverageIterator() {
431 } 437 }
432 438
433 PictureLayerTiling::CoverageIterator& 439 PictureLayerTiling::CoverageIterator&
(...skipping 14 matching lines...) Expand all
448 } 454 }
449 } 455 }
450 456
451 current_tile_ = tiling_->TileAt(tile_i_, tile_j_); 457 current_tile_ = tiling_->TileAt(tile_i_, tile_j_);
452 458
453 // Calculate the current geometry rect. Due to floating point rounding 459 // Calculate the current geometry rect. Due to floating point rounding
454 // and ToEnclosingRect, tiles might overlap in destination space on the 460 // and ToEnclosingRect, tiles might overlap in destination space on the
455 // edges. 461 // edges.
456 gfx::Rect last_geometry_rect = current_geometry_rect_; 462 gfx::Rect last_geometry_rect = current_geometry_rect_;
457 463
458 gfx::Rect content_rect = tiling_->tiling_data_.TileBounds(tile_i_, tile_j_); 464 // Important: To ensure no seams between tiles due to FP error, intermediate
enne (OOO) 2016/09/02 19:04:54 I would rather do the computations using gfx::Rect
trchen 2016/09/02 23:06:54 Acknowledged.
459 465 // computation needs to be done in SkRect instead of gfx::RectF. It is
460 current_geometry_rect_ = 466 // because SkRect stores LTRB internally instead of XYWH.
461 gfx::ScaleToEnclosingRect(content_rect, 1 / dest_to_content_scale_); 467 SkRect texel_extent =
468 gfx::RectFToSkRect(tiling_->tiling_data_.TexelExtent(tile_i_, tile_j_));
469 SkMatrix::MakeScale(1 / dest_to_content_scale_)
470 .mapRectScaleTranslate(&texel_extent, texel_extent);
471 SkIRect geometry_rect;
472 texel_extent.roundIn(&geometry_rect);
473 // Extend external edges. Sample coordinates beyond the extent of texels
474 // will be clamped, but will be assigned transparency by AA fragment shaders.
475 {
476 const TilingData& data = tiling_->tiling_data_;
477 int l = tile_i_ ? geometry_rect.left() : 0;
478 int t = tile_j_ ? geometry_rect.top() : 0;
479 int r = (tile_i_ == data.num_tiles_x() - 1) ? data.tiling_size().width()
enne (OOO) 2016/09/02 19:04:54 Why do you need this conditional here?
trchen 2016/09/02 23:06:54 Extend the right edge to layer bound like the left
480 : geometry_rect.right();
481 int b = (tile_j_ == data.num_tiles_y() - 1) ? data.tiling_size().height()
482 : geometry_rect.bottom();
483 current_geometry_rect_ = gfx::Rect(l, t, r - l, b - t);
484 }
462 485
463 current_geometry_rect_.Intersect(dest_rect_); 486 current_geometry_rect_.Intersect(dest_rect_);
464 DCHECK(!current_geometry_rect_.IsEmpty()); 487 DCHECK(!current_geometry_rect_.IsEmpty());
465 488
466 if (first_time) 489 if (first_time)
467 return *this; 490 return *this;
468 491
469 // Iteration happens left->right, top->bottom. Running off the bottom-right 492 // Iteration happens left->right, top->bottom. Running off the bottom-right
470 // edge is handled by the intersection above with dest_rect_. Here we make 493 // edge is handled by the intersection above with dest_rect_. Here we make
471 // sure that the new current geometry rect doesn't overlap with the last. 494 // sure that the new current geometry rect doesn't overlap with the last.
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { 902 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const {
880 size_t amount = 0; 903 size_t amount = 0;
881 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 904 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
882 const Tile* tile = it->second.get(); 905 const Tile* tile = it->second.get();
883 amount += tile->GPUMemoryUsageInBytes(); 906 amount += tile->GPUMemoryUsageInBytes();
884 } 907 }
885 return amount; 908 return amount;
886 } 909 }
887 910
888 } // namespace cc 911 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/tiling_data.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698