Skip to content

Commit

Permalink
Migrate existing usage of gfx:: float conversions to base:: versions.
Browse files Browse the repository at this point in the history
Bug: 1088346
Change-Id: I06a9d2b5d1ea72973a5fef116856383e0c6f5454
AX-Relnotes: n/a.
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2275371
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Colin Blundell <blundell@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Reviewed-by: Philip Rogers <pdr@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: Wei Li <weili@chromium.org>
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: Theresa  <twellington@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784904}
  • Loading branch information
pkasting authored and Commit Bot committed Jul 2, 2020
1 parent 8fb1bae commit fc445b3
Show file tree
Hide file tree
Showing 64 changed files with 277 additions and 278 deletions.
9 changes: 5 additions & 4 deletions android_webview/browser/gfx/browser_view_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/auto_reset.h"
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/supports_user_data.h"
Expand Down Expand Up @@ -738,14 +739,14 @@ void BrowserViewRenderer::SetTotalRootLayerScrollOffset(
// BrowserViewRenderer::ScrollTo.
if (max_scroll_offset_unscaled_.x()) {
scroll_offset.set_x(
gfx::ToRoundedInt((scroll_offset_unscaled.x() * max_offset.x()) /
max_scroll_offset_unscaled_.x()));
base::Round((scroll_offset_unscaled.x() * max_offset.x()) /
max_scroll_offset_unscaled_.x()));
}

if (max_scroll_offset_unscaled_.y()) {
scroll_offset.set_y(
gfx::ToRoundedInt((scroll_offset_unscaled.y() * max_offset.y()) /
max_scroll_offset_unscaled_.y()));
base::Round((scroll_offset_unscaled.y() * max_offset.y()) /
max_scroll_offset_unscaled_.y()));
}

DCHECK_LE(0, scroll_offset.x());
Expand Down
8 changes: 4 additions & 4 deletions ash/wallpaper/wallpaper_base_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include "ash/wallpaper/wallpaper_controller_impl.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/numerics/safe_conversions.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_analysis.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"

namespace ash {

Expand Down Expand Up @@ -89,12 +89,12 @@ void WallpaperBaseView::OnPaint(gfx::Canvas* canvas) {
gfx::Size cropped_size;
if (vertical_ratio > horizontal_ratio) {
cropped_size = gfx::Size(
gfx::ToFlooredInt(static_cast<double>(width()) / vertical_ratio),
base::Floor(static_cast<double>(width()) / vertical_ratio),
wallpaper.height());
} else {
cropped_size = gfx::Size(
wallpaper.width(), gfx::ToFlooredInt(static_cast<double>(height()) /
horizontal_ratio));
wallpaper.width(),
base::Floor(static_cast<double>(height()) / horizontal_ratio));
}

gfx::Rect wallpaper_cropped_rect(wallpaper.size());
Expand Down
6 changes: 3 additions & 3 deletions ash/wallpaper/wallpaper_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string_number_conversions.h"
Expand Down Expand Up @@ -189,13 +190,12 @@ bool ResizeAndEncodeImage(const gfx::ImageSkia& image,
double horizontal_ratio = static_cast<double>(preferred_width) / width;
double vertical_ratio = static_cast<double>(preferred_height) / height;
if (vertical_ratio > horizontal_ratio) {
resized_width =
gfx::ToRoundedInt(static_cast<double>(width) * vertical_ratio);
resized_width = base::Round(static_cast<double>(width) * vertical_ratio);
resized_height = preferred_height;
} else {
resized_width = preferred_width;
resized_height =
gfx::ToRoundedInt(static_cast<double>(height) * horizontal_ratio);
base::Round(static_cast<double>(height) * horizontal_ratio);
}
} else if (layout == WALLPAPER_LAYOUT_STRETCH) {
resized_width = preferred_width;
Expand Down
8 changes: 4 additions & 4 deletions ash/wallpaper/wallpaper_utils/wallpaper_resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "third_party/skia/include/core/SkImage.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/image/image_skia_rep.h"
#include "ui/gfx/skia_util.h"

Expand Down Expand Up @@ -69,11 +69,11 @@ void Resize(const gfx::ImageSkia image,
static_cast<double>(orig_height);

if (vertical_ratio > horizontal_ratio) {
cropped_size = gfx::Size(
gfx::ToRoundedInt(new_width / vertical_ratio), orig_height);
cropped_size =
gfx::Size(base::Round(new_width / vertical_ratio), orig_height);
} else {
cropped_size = gfx::Size(
orig_width, gfx::ToRoundedInt(new_height / horizontal_ratio));
orig_width, base::Round(new_height / horizontal_ratio));
}
wallpaper_rect.ClampToCenteredSize(cropped_size);
SkBitmap sub_image;
Expand Down
12 changes: 6 additions & 6 deletions ash/wm/overview/overview_grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
#include "base/bind.h"
#include "base/containers/unique_ptr_adapters.h"
#include "base/numerics/ranges.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/throughput_tracker.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/transform_util.h"
#include "ui/views/view.h"
Expand Down Expand Up @@ -251,8 +251,8 @@ float GetWantedDropTargetOpacity(

gfx::Insets GetGridInsets(const gfx::Rect& grid_bounds) {
const int horizontal_inset =
gfx::ToFlooredInt(std::min(kOverviewInsetRatio * grid_bounds.width(),
kOverviewInsetRatio * grid_bounds.height()));
base::Floor(std::min(kOverviewInsetRatio * grid_bounds.width(),
kOverviewInsetRatio * grid_bounds.height()));
const int vertical_inset =
horizontal_inset +
kOverviewVerticalInset * (grid_bounds.height() - 2 * horizontal_inset);
Expand Down Expand Up @@ -1536,8 +1536,8 @@ int OverviewGrid::CalculateWidthAndMaybeSetUnclippedBounds(OverviewItem* item,
}
}

int width = std::max(
1, gfx::ToFlooredInt(target_size.width() * scale) + 2 * kWindowMargin);
int width =
std::max(1, base::Floor(target_size.width() * scale) + 2 * kWindowMargin);
switch (grid_fill_mode) {
case OverviewGridWindowFillMode::kLetterBoxed:
width = kExtremeWindowRatioThreshold * height;
Expand Down Expand Up @@ -1574,7 +1574,7 @@ int OverviewGrid::CalculateWidthAndMaybeSetUnclippedBounds(OverviewItem* item,
unclipped_size.set_height(height - 2 * kWindowMargin);
// For horizontal clipping, shrink |width| so that the aspect ratio matches
// that of |split_view_bounds|.
width = std::max(1, gfx::ToFlooredInt(target_aspect_ratio * window_height) +
width = std::max(1, base::Floor(target_aspect_ratio * window_height) +
2 * kWindowMargin);
} else {
// For vertical clipping, we want |height| to stay the same, so calculate
Expand Down
8 changes: 4 additions & 4 deletions ash/wm/overview/overview_window_drag_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "ash/wm/window_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/ranges.h"
#include "base/numerics/safe_conversions.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/display/display.h"
Expand Down Expand Up @@ -725,10 +726,9 @@ SplitViewController::SnapPosition OverviewWindowDragController::GetSnapPosition(
if (!split_view_controller->CanSnapWindow(item_->GetWindow()))
return SplitViewController::NONE;
if (split_view_controller->InSplitViewMode()) {
const int position =
gfx::ToRoundedInt(SplitViewController::IsLayoutHorizontal()
? location_in_screen.x() - area.x()
: location_in_screen.y() - area.y());
const int position = base::Round(SplitViewController::IsLayoutHorizontal()
? location_in_screen.x() - area.x()
: location_in_screen.y() - area.y());
SplitViewController::SnapPosition default_snap_position =
split_view_controller->default_snap_position();
// If we're trying to snap to a position that already has a snapped window:
Expand Down
6 changes: 3 additions & 3 deletions ash/wm/overview/scoped_overview_transform_window_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ash/test/ash_test_base.h"
#include "ash/wm/overview/overview_utils.h"
#include "ash/wm/window_state.h"
#include "base/numerics/safe_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "ui/aura/window.h"
#include "ui/display/display.h"
Expand Down Expand Up @@ -117,9 +118,8 @@ TEST_F(ScopedOverviewTransformWindowTest, TransformedRectIsCenteredWithInset) {
// |bounds| starting before |bounds.x()| and ending after |bounds.right()|.
EXPECT_LE(transformed_rect.x(), bounds.x());
EXPECT_GE(transformed_rect.right(), bounds.right());
EXPECT_GE(
transformed_rect.y() + gfx::ToCeiledInt(scale * inset) - header_height,
bounds.y());
EXPECT_GE(transformed_rect.y() + base::Ceil(scale * inset) - header_height,
bounds.y());
EXPECT_LE(transformed_rect.bottom(), bounds.bottom());
EXPECT_NEAR(transformed_rect.x() - bounds.x(),
bounds.right() - transformed_rect.right(), 1);
Expand Down
22 changes: 11 additions & 11 deletions ash/wm/pip/pip_positioner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/work_area_insets.h"
#include "base/numerics/safe_conversions.h"
#include "ui/aura/window.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/wm/core/coordinate_conversion.h"

namespace ash {
Expand Down Expand Up @@ -86,30 +86,30 @@ gfx::Rect PipPositioner::GetSnapFractionAppliedBounds(
*(window_state->window()->GetProperty(ash::kPipSnapFractionKey));

if (snap_fraction < 1.) {
int offset = movement_area.x() +
gfx::ToRoundedInt(snap_fraction *
(movement_area.width() - bounds.width()));
int offset =
movement_area.x() +
base::Round(snap_fraction * (movement_area.width() - bounds.width()));
return gfx::Rect(offset, movement_area.y(), bounds.width(),
bounds.height());
} else if (snap_fraction < 2.) {
snap_fraction -= 1.;
int offset = movement_area.y() +
gfx::ToRoundedInt(snap_fraction *
(movement_area.height() - bounds.height()));
int offset =
movement_area.y() +
base::Round(snap_fraction * (movement_area.height() - bounds.height()));
return gfx::Rect(movement_area.right() - bounds.width(), offset,
bounds.width(), bounds.height());
} else if (snap_fraction < 3.) {
snap_fraction -= 2.;
int offset = movement_area.x() +
gfx::ToRoundedInt((1. - snap_fraction) *
(movement_area.width() - bounds.width()));
base::Round((1. - snap_fraction) *
(movement_area.width() - bounds.width()));
return gfx::Rect(offset, movement_area.bottom() - bounds.height(),
bounds.width(), bounds.height());
} else {
snap_fraction -= 3.;
int offset = movement_area.y() +
gfx::ToRoundedInt((1. - snap_fraction) *
(movement_area.height() - bounds.height()));
base::Round((1. - snap_fraction) *
(movement_area.height() - bounds.height()));
return gfx::Rect(movement_area.x(), offset, bounds.width(),
bounds.height());
}
Expand Down
3 changes: 2 additions & 1 deletion ash/wm/window_resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ash/wm/window_util.h"
#include "base/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/time/time.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
Expand Down Expand Up @@ -325,7 +326,7 @@ gfx::Point WindowResizer::GetOriginForDrag(int delta_x,
float{details().initial_bounds_in_parent.x()}) /
details().initial_bounds_in_parent.width();
int new_origin_x =
gfx::ToRoundedInt(event_location.x() - ratio * restore_bounds.width());
base::Round(event_location.x() - ratio * restore_bounds.width());
origin.set_x(new_origin_x);

// Windows may not have a widget in tests.
Expand Down
8 changes: 3 additions & 5 deletions cc/layers/nine_patch_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <stddef.h>

#include "base/numerics/safe_conversions.h"
#include "cc/layers/append_quads_data.h"
#include "cc/layers/nine_patch_layer_impl.h"
#include "cc/resources/ui_resource_bitmap.h"
Expand All @@ -18,17 +19,14 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/transform.h"

namespace cc {
namespace {

gfx::Rect ToRoundedIntRect(const gfx::RectF& rect_f) {
return gfx::Rect(gfx::ToRoundedInt(rect_f.x()),
gfx::ToRoundedInt(rect_f.y()),
gfx::ToRoundedInt(rect_f.width()),
gfx::ToRoundedInt(rect_f.height()));
return gfx::Rect(base::Round(rect_f.x()), base::Round(rect_f.y()),
base::Round(rect_f.width()), base::Round(rect_f.height()));
}

void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size,
Expand Down
5 changes: 3 additions & 2 deletions cc/trees/property_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/check_op.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "base/trace_event/traced_value.h"
#include "cc/trees/clip_node.h"
#include "cc/trees/effect_node.h"
Expand Down Expand Up @@ -949,8 +950,8 @@ void EffectTree::TakeCopyRequestsAndTransformToSurface(
.AssignIfValid(&scale_to_y)) {
continue;
}
int scale_from_x = gfx::ToRoundedInt(scale_from_x_f);
int scale_from_y = gfx::ToRoundedInt(scale_from_y_f);
int scale_from_x = base::Round(scale_from_x_f);
int scale_from_y = base::Round(scale_from_y_f);
if (scale_from_x <= 0 || scale_from_y <= 0 || scale_to_x <= 0 ||
scale_to_y <= 0) {
// Transformed scaling ratio became illegal. Drop the request to
Expand Down
4 changes: 1 addition & 3 deletions chrome/browser/extensions/convert_web_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "url/gurl.h"

namespace extensions {
Expand Down Expand Up @@ -200,8 +199,7 @@ std::string ConvertTimeToExtensionVersion(const base::Time& create_time) {
(create_time_exploded.minute * base::Time::kMicrosecondsPerMinute) +
(create_time_exploded.hour * base::Time::kMicrosecondsPerHour));
double day_fraction = micros / base::Time::kMicrosecondsPerDay;
int stamp =
gfx::ToRoundedInt(day_fraction * std::numeric_limits<uint16_t>::max());
int stamp = base::Round(day_fraction * std::numeric_limits<uint16_t>::max());

return base::StringPrintf("%i.%i.%i.%i", create_time_exploded.year,
create_time_exploded.month,
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/google/google_update_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h"
#include "base/sequenced_task_runner.h"
#include "base/sequenced_task_runner_helpers.h"
Expand Down Expand Up @@ -46,7 +47,6 @@
#include "chrome/installer/util/install_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/win/atl_module.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"

namespace {

Expand Down Expand Up @@ -771,9 +771,9 @@ bool UpdateCheckDriver::IsIntermediateState(
SUCCEEDED(current_state->get_totalBytesToDownload(&total_bytes)) &&
total_bytes) {
// 0-50 is downloading.
*progress = gfx::ToFlooredInt((static_cast<double>(bytes_downloaded) /
static_cast<double>(total_bytes)) *
50.0);
*progress = base::Floor((static_cast<double>(bytes_downloaded) /
static_cast<double>(total_bytes)) *
50.0);
}
break;
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/themes/browser_theme_pack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/numerics/safe_conversions.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
Expand All @@ -42,7 +43,6 @@
#include "ui/gfx/color_analysis.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/image/image.h"
Expand Down Expand Up @@ -1251,7 +1251,7 @@ void BrowserThemePack::ReadColorsFromJSON(
double alpha;
int alpha_int;
if (color_list->GetDouble(3, &alpha) && alpha >= 0 && alpha <= 1) {
color = SkColorSetARGB(gfx::ToRoundedInt(alpha * 255), r, g, b);
color = SkColorSetARGB(base::Round<U8CPU>(alpha * 255), r, g, b);
} else if (color_list->GetInteger(3, &alpha_int) &&
(alpha_int == 0 || alpha_int == 1)) {
color = SkColorSetARGB(alpha_int ? 255 : 0, r, g, b);
Expand Down
Loading

0 comments on commit fc445b3

Please sign in to comment.