Commit 6d052148 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Convert nested min/max calls to base::ClampToRange() in cc/.

Bug: 1000055
Change-Id: I2ad15b7167db4e90ca80761c42de1d00ef08b41c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1792789
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: enne <enne@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694912}
parent a31d7d44
......@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/ranges.h"
#include "cc/animation/timing_function.h"
#include "cc/base/time_util.h"
#include "ui/gfx/animation/tween.h"
......@@ -46,7 +47,7 @@ static float MaximumDimension(const gfx::Vector2dF& delta) {
static std::unique_ptr<TimingFunction> EaseOutWithInitialVelocity(
double velocity) {
// Clamp velocity to a sane value.
velocity = std::min(std::max(velocity, -1000.0), 1000.0);
velocity = base::ClampToRange(velocity, -1000.0, 1000.0);
// Based on CubicBezierTimingFunction::EaseType::EASE_IN_OUT preset
// with first control point scaled.
......@@ -92,15 +93,14 @@ base::TimeDelta ScrollOffsetAnimationCurve::SegmentDuration(
break;
case DurationBehavior::DELTA_BASED:
duration =
std::min(double(std::sqrt(std::abs(MaximumDimension(delta)))),
kDeltaBasedMaxDuration);
std::min<double>(std::sqrt(std::abs(MaximumDimension(delta))),
kDeltaBasedMaxDuration);
break;
case DurationBehavior::INVERSE_DELTA:
duration = std::min(
std::max(kInverseDeltaOffset +
std::abs(MaximumDimension(delta)) * kInverseDeltaSlope,
kInverseDeltaMinDuration),
kInverseDeltaMaxDuration);
duration = kInverseDeltaOffset +
std::abs(MaximumDimension(delta)) * kInverseDeltaSlope;
duration = base::ClampToRange(duration, kInverseDeltaMinDuration,
kInverseDeltaMaxDuration);
break;
case DurationBehavior::CONSTANT_VELOCITY:
duration =
......
......@@ -11,6 +11,7 @@
#include <xmmintrin.h>
#endif
#include "base/numerics/ranges.h"
#include "base/trace_event/traced_value.h"
#include "base/values.h"
#include "ui/gfx/geometry/angle_conversions.h"
......@@ -613,7 +614,7 @@ float MathUtil::SmallestAngleBetweenVectors(const gfx::Vector2dF& v1,
const gfx::Vector2dF& v2) {
double dot_product = gfx::DotProduct(v1, v2) / v1.Length() / v2.Length();
// Clamp to compensate for rounding errors.
dot_product = std::max(-1.0, std::min(1.0, dot_product));
dot_product = base::ClampToRange(dot_product, -1.0, 1.0);
return static_cast<float>(gfx::RadToDeg(std::acos(dot_product)));
}
......
......@@ -6,6 +6,7 @@
#include <algorithm>
#include "base/numerics/ranges.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/vector2d.h"
......@@ -79,7 +80,7 @@ int TilingData::TileXIndexFromSrcCoord(int src_position) const {
DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0);
int x = (src_position - border_texels_) /
(max_texture_size_.width() - 2 * border_texels_);
return std::min(std::max(x, 0), num_tiles_x_ - 1);
return base::ClampToRange(x, 0, num_tiles_x_ - 1);
}
int TilingData::TileYIndexFromSrcCoord(int src_position) const {
......@@ -89,7 +90,7 @@ int TilingData::TileYIndexFromSrcCoord(int src_position) const {
DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0);
int y = (src_position - border_texels_) /
(max_texture_size_.height() - 2 * border_texels_);
return std::min(std::max(y, 0), num_tiles_y_ - 1);
return base::ClampToRange(y, 0, num_tiles_y_ - 1);
}
int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const {
......@@ -99,7 +100,7 @@ int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const {
DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0);
int inner_tile_size = max_texture_size_.width() - 2 * border_texels_;
int x = (src_position - 2 * border_texels_) / inner_tile_size;
return std::min(std::max(x, 0), num_tiles_x_ - 1);
return base::ClampToRange(x, 0, num_tiles_x_ - 1);
}
int TilingData::FirstBorderTileYIndexFromSrcCoord(int src_position) const {
......@@ -109,7 +110,7 @@ int TilingData::FirstBorderTileYIndexFromSrcCoord(int src_position) const {
DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0);
int inner_tile_size = max_texture_size_.height() - 2 * border_texels_;
int y = (src_position - 2 * border_texels_) / inner_tile_size;
return std::min(std::max(y, 0), num_tiles_y_ - 1);
return base::ClampToRange(y, 0, num_tiles_y_ - 1);
}
int TilingData::LastBorderTileXIndexFromSrcCoord(int src_position) const {
......@@ -119,7 +120,7 @@ int TilingData::LastBorderTileXIndexFromSrcCoord(int src_position) const {
DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0);
int inner_tile_size = max_texture_size_.width() - 2 * border_texels_;
int x = src_position / inner_tile_size;
return std::min(std::max(x, 0), num_tiles_x_ - 1);
return base::ClampToRange(x, 0, num_tiles_x_ - 1);
}
int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const {
......@@ -129,7 +130,7 @@ int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const {
DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0);
int inner_tile_size = max_texture_size_.height() - 2 * border_texels_;
int y = src_position / inner_tile_size;
return std::min(std::max(y, 0), num_tiles_y_ - 1);
return base::ClampToRange(y, 0, num_tiles_y_ - 1);
}
IndexRect TilingData::TileAroundIndexRect(const gfx::Rect& center_rect) const {
......
......@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/bind.h"
#include "base/numerics/ranges.h"
#include "base/time/time.h"
#include "cc/trees/layer_tree_impl.h"
......@@ -162,7 +163,7 @@ float ScrollbarAnimationController::AnimationProgressAtTime(
base::TimeTicks now) {
base::TimeDelta delta = now - last_awaken_time_;
float progress = delta.InSecondsF() / fade_duration_.InSecondsF();
return std::max(std::min(progress, 1.f), 0.f);
return base::ClampToRange(progress, 0.0f, 1.0f);
}
void ScrollbarAnimationController::RunAnimationFrame(float progress) {
......
......@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/memory/ptr_util.h"
#include "base/numerics/ranges.h"
#include "base/time/time.h"
#include "cc/input/scrollbar_animation_controller.h"
#include "cc/layers/layer_impl.h"
......@@ -95,7 +96,7 @@ float SingleScrollbarAnimationControllerThinning::AnimationProgressAtTime(
base::TimeTicks now) {
base::TimeDelta delta = now - last_awaken_time_;
float progress = delta.InSecondsF() / Duration().InSecondsF();
return std::max(std::min(progress, 1.f), 0.f);
return base::ClampToRange(progress, 0.0f, 1.0f);
}
const base::TimeDelta& SingleScrollbarAnimationControllerThinning::Duration() {
......
......@@ -14,6 +14,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/numerics/ranges.h"
#include "base/time/time.h"
#include "base/trace_event/traced_value.h"
#include "build/build_config.h"
......@@ -1125,7 +1126,7 @@ void PictureLayerImpl::RecalculateRasterScales() {
float min_scale = MinimumContentsScale();
float max_scale = std::max(1.f, MinimumContentsScale());
float clamped_ideal_source_scale_ =
std::max(min_scale, std::min(ideal_source_scale_, max_scale));
base::ClampToRange(ideal_source_scale_, min_scale, max_scale);
while (raster_source_scale_ < clamped_ideal_source_scale_)
raster_source_scale_ *= 2.f;
......@@ -1133,7 +1134,7 @@ void PictureLayerImpl::RecalculateRasterScales() {
raster_source_scale_ /= 2.f;
raster_source_scale_ =
std::max(min_scale, std::min(raster_source_scale_, max_scale));
base::ClampToRange(raster_source_scale_, min_scale, max_scale);
raster_page_scale_ = 1.f;
raster_device_scale_ = 1.f;
......@@ -1450,9 +1451,8 @@ void PictureLayerImpl::UpdateIdealScales() {
ideal_contents_scale_ =
GetIdealContentsScale() * external_page_scale_factor;
}
ideal_contents_scale_ =
std::min(kMaxIdealContentsScale,
std::max(ideal_contents_scale_, min_contents_scale));
ideal_contents_scale_ = base::ClampToRange(
ideal_contents_scale_, min_contents_scale, kMaxIdealContentsScale);
ideal_source_scale_ =
ideal_contents_scale_ / ideal_page_scale_ / ideal_device_scale_;
}
......
......@@ -5,6 +5,8 @@
#include "cc/layers/scrollbar_layer_impl_base.h"
#include <algorithm>
#include "base/numerics/ranges.h"
#include "cc/trees/effect_node.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/scroll_node.h"
......@@ -213,7 +215,7 @@ gfx::Rect ScrollbarLayerImplBase::ComputeThumbQuadRectWithThumbThicknessScale(
float maximum = scroll_layer_length() - clip_layer_length();
// With the length known, we can compute the thumb's position.
float clamped_current_pos = std::min(std::max(current_pos(), 0.f), maximum);
float clamped_current_pos = base::ClampToRange(current_pos(), 0.0f, maximum);
int thumb_offset = TrackStart();
if (maximum > 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment