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

Unified Diff: cc/layers/picture_layer_impl.cc

Issue 1321503002: cc: Do not create separate tilings for almost equal scale factors. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/layers/picture_layer_impl.cc
diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc
index 8be30987e03be429d9c3e9919c4dc18c85dc6889..2e0d06158d0f589c6e389791cdaaa5ac702074ba 100644
--- a/cc/layers/picture_layer_impl.cc
+++ b/cc/layers/picture_layer_impl.cc
@@ -49,6 +49,40 @@ const int kMinHeightForGpuRasteredTile = 256;
// of using the same tile size.
const int kTileRoundUp = 64;
+// The precision value for rounding floating points values (of scale factors),
+// to given decimal places so that scale factors which are almost equal (differ
+// by some threshold magnitude of floating point epsilon) are considered as
+// same.
+const int kScalePrecision = 4;
+
+bool VerifyFixedPrecisionValue(float value) {
+ const base::CheckedNumeric<float> checked_factor = pow(10, kScalePrecision);
+ if (!checked_factor.IsValid())
+ return false;
+
+ base::CheckedNumeric<float> checked_value = value;
+ checked_value *= checked_factor.ValueOrDie();
+ if (!checked_value.IsValid())
+ return false;
+
+ checked_value = floor(checked_value.ValueOrDie());
+ checked_value /= checked_factor.ValueOrDie();
+ return checked_value.IsValid();
+}
+
+float GetFixedPrecisionValue(float value) {
+ // Limiting precision 1 <= kScalePrecision <= 8, as floating point precision
+ // of >= 12 gives different values, 8 on a safer side.
+ DCHECK(kScalePrecision >= 1 && kScalePrecision <= 8);
+ DCHECK(VerifyFixedPrecisionValue(value));
+
+ const float factor = pow(10, kScalePrecision);
enne (OOO) 2015/08/27 18:08:34 It is weird to do math with base 10. Surely there
+ value *= factor;
+ value = floor(value);
+ value /= factor;
+ return value;
+}
+
} // namespace
namespace cc {
@@ -902,10 +936,12 @@ void PictureLayerImpl::RecalculateRasterScales() {
float old_raster_page_scale = raster_page_scale_;
float old_raster_source_scale = raster_source_scale_;
- raster_device_scale_ = ideal_device_scale_;
- raster_page_scale_ = ideal_page_scale_;
- raster_source_scale_ = ideal_source_scale_;
- raster_contents_scale_ = ideal_contents_scale_;
+ // Get fixed precision values to avoid creating extra tilings for scales
+ // which are almost equal.
+ raster_device_scale_ = GetFixedPrecisionValue(ideal_device_scale_);
+ raster_page_scale_ = GetFixedPrecisionValue(ideal_page_scale_);
+ raster_source_scale_ = GetFixedPrecisionValue(ideal_source_scale_);
+ raster_contents_scale_ = GetFixedPrecisionValue(ideal_contents_scale_);
enne (OOO) 2015/08/27 18:08:34 Do we really need fixed precision for all of these
// If we're not animating, or leaving an animation, and the
// ideal_source_scale_ changes, then things are unpredictable, and we fix
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698