summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-20 21:54:52 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-20 21:54:52 +0000
commitd24adc83e7de8b042739c96f37588dee5ba091b3 (patch)
treee82cf26051eb22ce33a61a3f2816c39e6135675f
parentfc28c977a4969a3ff4c4e8dee98fe67ce111ed86 (diff)
downloadchromium_src-d24adc83e7de8b042739c96f37588dee5ba091b3.zip
chromium_src-d24adc83e7de8b042739c96f37588dee5ba091b3.tar.gz
chromium_src-d24adc83e7de8b042739c96f37588dee5ba091b3.tar.bz2
Revert 224473 "Remove dependency on ui::ScaleFactor from ui/gfx"
> Remove dependency on ui::ScaleFactor from ui/gfx > > As part of the work to removed dependencies on ui/base from ui/gfx I have > changed the public api to Canvas, ImageSkia, ImageSkiaRep and ImagePNGRep > to take float scale values instead of ui::ScaleFactor. > > The notion of supported scale factors has been broken into 2 parts. > ui::SetSupportedScaleFactors remains and calls the > new ImageSkia::SetSupportedScales(). > > The initialization of the supported scale factors has been moved from layout.h > into ResourceBundle, and is done explicitly in tests that don't use > ResourceBundle. > > BUG=103304 > R=ben@chromium.org, oshima@chromium.org, sky@chromium.org > > Review URL: https://codereview.chromium.org/24175004 TBR=davemoore@chromium.org Review URL: https://codereview.chromium.org/24262008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224499 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--apps/shell_window.cc2
-rw-r--r--ash/desktop_background/wallpaper_resizer_unittest.cc6
-rw-r--r--ash/display/mirror_window_controller.cc5
-rw-r--r--ash/drag_drop/drag_drop_controller_unittest.cc2
-rw-r--r--ash/drag_drop/drag_image_view.cc8
-rw-r--r--ash/launcher/launcher_delegate.h4
-rw-r--r--ash/launcher/launcher_item_delegate_manager.cc2
-rw-r--r--ash/shell/app_list.cc3
-rw-r--r--ash/shell/window_watcher.cc3
-rw-r--r--ash/system/chromeos/network/network_icon.cc14
-rw-r--r--ash/wm/frame_painter.cc2
-rw-r--r--chrome/browser/android/provider/chrome_browser_provider.cc3
-rw-r--r--chrome/browser/chromeos/extensions/wallpaper_api.cc2
-rw-r--r--chrome/browser/chromeos/extensions/wallpaper_private_api.cc4
-rw-r--r--chrome/browser/chromeos/login/helper.cc4
-rw-r--r--chrome/browser/chromeos/login/wallpaper_manager.cc2
-rw-r--r--chrome/browser/extensions/api/extension_action/browser_action_apitest.cc45
-rw-r--r--chrome/browser/extensions/api/extension_action/extension_action_api.cc14
-rw-r--r--chrome/browser/extensions/api/notifications/notifications_api.cc3
-rw-r--r--chrome/browser/extensions/app_icon_loader_impl.cc2
-rw-r--r--chrome/browser/extensions/extension_action.cc12
-rw-r--r--chrome/browser/extensions/extension_action_icon_factory_unittest.cc43
-rw-r--r--chrome/browser/extensions/extension_icon_image.cc29
-rw-r--r--chrome/browser/extensions/extension_icon_image.h3
-rw-r--r--chrome/browser/extensions/extension_icon_image_unittest.cc82
-rw-r--r--chrome/browser/extensions/extension_icon_manager.cc2
-rw-r--r--chrome/browser/extensions/extension_install_prompt.cc7
-rw-r--r--chrome/browser/extensions/extension_uninstall_dialog.cc7
-rw-r--r--chrome/browser/extensions/extension_web_ui.cc2
-rw-r--r--chrome/browser/extensions/image_loader.cc3
-rw-r--r--chrome/browser/favicon/favicon_handler.cc4
-rw-r--r--chrome/browser/favicon/favicon_handler_unittest.cc6
-rw-r--r--chrome/browser/favicon/favicon_service.cc4
-rw-r--r--chrome/browser/favicon/favicon_util.cc21
-rw-r--r--chrome/browser/history/select_favicon_frames.cc7
-rw-r--r--chrome/browser/history/select_favicon_frames_unittest.cc19
-rw-r--r--chrome/browser/profiles/profile_info_util.cc11
-rw-r--r--chrome/browser/speech/speech_recognition_bubble.cc20
-rw-r--r--chrome/browser/speech/speech_recognition_bubble.h2
-rw-r--r--chrome/browser/sync/test/integration/bookmarks_helper.cc10
-rw-r--r--chrome/browser/sync/test/integration/single_client_bookmarks_sync_test.cc2
-rw-r--r--chrome/browser/sync/test/integration/two_client_bookmarks_sync_test.cc2
-rw-r--r--chrome/browser/task_manager/browser_process_resource_provider.cc3
-rw-r--r--chrome/browser/themes/browser_theme_pack.cc49
-rw-r--r--chrome/browser/themes/browser_theme_pack_unittest.cc28
-rw-r--r--chrome/browser/thumbnails/content_analysis_unittest.cc12
-rw-r--r--chrome/browser/thumbnails/content_based_thumbnailing_algorithm_unittest.cc2
-rw-r--r--chrome/browser/thumbnails/render_widget_snapshot_taker.cc2
-rw-r--r--chrome/browser/thumbnails/simple_thumbnail_crop.cc8
-rw-r--r--chrome/browser/thumbnails/simple_thumbnail_crop_unittest.cc14
-rw-r--r--chrome/browser/ui/app_list/search/common/url_icon_source.cc8
-rw-r--r--chrome/browser/ui/app_list/search/common/url_icon_source.h3
-rw-r--r--chrome/browser/ui/app_list/search/people/people_result.cc2
-rw-r--r--chrome/browser/ui/app_list/search/webstore/webstore_result.cc2
-rw-r--r--chrome/browser/ui/ash/launcher/launcher_item_controller.h1
-rw-r--r--chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc2
-rw-r--r--chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm2
-rw-r--r--chrome/browser/ui/cocoa/panels/panel_stack_window_cocoa.mm2
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm2
-rw-r--r--chrome/browser/ui/gtk/avatar_menu_item_gtk.cc3
-rw-r--r--chrome/browser/ui/gtk/gtk_theme_service.cc2
-rw-r--r--chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc2
-rw-r--r--chrome/browser/ui/gtk/panels/panel_gtk.cc2
-rw-r--r--chrome/browser/ui/libgtk2ui/gtk2_ui.cc2
-rw-r--r--chrome/browser/ui/metro_pin_tab_helper_win.cc4
-rw-r--r--chrome/browser/ui/toolbar/wrench_icon_painter_unittest.cc2
-rw-r--r--chrome/browser/ui/views/dropdown_bar_view.cc2
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc2
-rw-r--r--chrome/browser/ui/views/frame/opaque_browser_frame_view_layout_unittest.cc4
-rw-r--r--chrome/browser/ui/views/location_bar/content_setting_image_view.cc3
-rw-r--r--chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc3
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_win.cc2
-rw-r--r--chrome/browser/ui/views/panels/panel_frame_view.cc2
-rw-r--r--chrome/browser/ui/views/panels/taskbar_window_thumbnailer_win.cc2
-rw-r--r--chrome/browser/ui/views/tab_icon_view.cc3
-rw-r--r--chrome/browser/ui/views/tabs/dragged_tab_view.cc2
-rw-r--r--chrome/browser/ui/views/tabs/tab.cc15
-rw-r--r--chrome/browser/ui/views/tabs/tab_strip.cc13
-rw-r--r--chrome/browser/ui/web_applications/web_app_ui.cc2
-rw-r--r--chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc2
-rw-r--r--chrome/browser/ui/webui/chromeos/login/network_dropdown.cc5
-rw-r--r--chrome/browser/ui/webui/fileicon_source.cc7
-rw-r--r--chrome/browser/ui/webui/ntp/ntp_login_handler.cc3
-rw-r--r--chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc5
-rw-r--r--chrome/common/badge_util.cc2
-rw-r--r--chrome/common/icon_with_badge_image_source.cc1
-rw-r--r--chrome/renderer/pepper/pepper_pdf_host.cc7
-rw-r--r--content/browser/aura/software_output_device_win.cc2
-rw-r--r--content/browser/renderer_host/backing_store_aura.cc4
-rw-r--r--content/browser/renderer_host/dip_util.cc2
-rw-r--r--content/browser/renderer_host/render_view_host_impl.cc4
-rw-r--r--content/browser/renderer_host/render_widget_host_unittest.cc2
-rw-r--r--content/browser/renderer_host/render_widget_host_view_android.cc2
-rw-r--r--content/browser/renderer_host/render_widget_host_view_browsertest.cc2
-rw-r--r--content/browser/renderer_host/render_widget_host_view_mac.mm2
-rw-r--r--content/browser/renderer_host/render_widget_host_view_win.cc2
-rw-r--r--content/browser/renderer_host/test_render_view_host.cc5
-rw-r--r--content/browser/renderer_host/test_render_view_host.h4
-rw-r--r--content/browser/web_contents/web_contents_view_aura.cc6
-rw-r--r--content/renderer/pepper/pepper_plugin_instance_impl.cc6
-rw-r--r--ui/app_list/views/app_list_item_view.cc2
-rw-r--r--ui/app_list/views/app_list_main_view.cc9
-rw-r--r--ui/app_list/views/cached_label.cc2
-rw-r--r--ui/base/clipboard/clipboard_gtk.cc3
-rw-r--r--ui/base/clipboard/clipboard_mac.mm2
-rw-r--r--ui/base/clipboard/clipboard_win.cc2
-rw-r--r--ui/base/cursor/cursor_loader_x11.cc4
-rw-r--r--ui/base/cursor/cursors_aura.cc2
-rw-r--r--ui/base/layout.cc181
-rw-r--r--ui/base/layout.h35
-rw-r--r--ui/base/layout_mac.mm2
-rw-r--r--ui/base/layout_unittest.cc99
-rw-r--r--ui/base/resource/resource_bundle.cc102
-rw-r--r--ui/base/resource/resource_bundle.h7
-rw-r--r--ui/base/resource/resource_bundle_ios.mm4
-rw-r--r--ui/base/resource/resource_bundle_unittest.cc51
-rw-r--r--ui/base/resource/resource_bundle_win.cc2
-rw-r--r--ui/base/x/x11_util.cc2
-rw-r--r--ui/compositor/layer.cc2
-rw-r--r--ui/gfx/canvas.cc48
-rw-r--r--ui/gfx/canvas.h32
-rw-r--r--ui/gfx/canvas_paint_gtk.cc4
-rw-r--r--ui/gfx/canvas_paint_mac.mm5
-rw-r--r--ui/gfx/canvas_paint_win.cc2
-rw-r--r--ui/gfx/canvas_skia.cc4
-rw-r--r--ui/gfx/color_analysis_unittest.cc8
-rw-r--r--ui/gfx/image/canvas_image_source.cc6
-rw-r--r--ui/gfx/image/canvas_image_source.h3
-rw-r--r--ui/gfx/image/image.cc24
-rw-r--r--ui/gfx/image/image_ios.mm18
-rw-r--r--ui/gfx/image/image_mac.mm4
-rw-r--r--ui/gfx/image/image_mac_unittest.mm66
-rw-r--r--ui/gfx/image/image_png_rep.cc7
-rw-r--r--ui/gfx/image/image_png_rep.h6
-rw-r--r--ui/gfx/image/image_skia.cc114
-rw-r--r--ui/gfx/image/image_skia.h34
-rw-r--r--ui/gfx/image/image_skia_operations.cc96
-rw-r--r--ui/gfx/image/image_skia_rep.cc23
-rw-r--r--ui/gfx/image/image_skia_rep.h12
-rw-r--r--ui/gfx/image/image_skia_source.h13
-rw-r--r--ui/gfx/image/image_skia_unittest.cc68
-rw-r--r--ui/gfx/image/image_skia_util_ios.h11
-rw-r--r--ui/gfx/image/image_skia_util_ios.mm18
-rw-r--r--ui/gfx/image/image_skia_util_mac.mm14
-rw-r--r--ui/gfx/image/image_unittest.cc86
-rw-r--r--ui/gfx/image/image_unittest_util.cc36
-rw-r--r--ui/gfx/image/image_unittest_util.h5
-rw-r--r--ui/gfx/image/image_util.cc4
-rw-r--r--ui/gfx/skia_util.cc2
-rw-r--r--ui/gfx/win/dpi.cc2
-rw-r--r--ui/message_center/views/notification_view.cc3
-rw-r--r--ui/native_theme/native_theme_base.cc10
-rw-r--r--ui/views/controls/button/image_button.h1
-rw-r--r--ui/views/controls/glow_hover_controller.cc2
-rw-r--r--ui/views/controls/menu/menu_win.cc3
-rw-r--r--ui/views/controls/menu/native_menu_win.cc4
-rw-r--r--ui/views/drag_utils.cc14
-rw-r--r--ui/views/win/hwnd_message_handler.cc6
-rw-r--r--ui/webui/web_ui_util.cc2
159 files changed, 1040 insertions, 1010 deletions
diff --git a/apps/shell_window.cc b/apps/shell_window.cc
index cd8ddd0..44a3858 100644
--- a/apps/shell_window.cc
+++ b/apps/shell_window.cc
@@ -457,7 +457,7 @@ void ShellWindow::UpdateExtensionAppIcon() {
// Triggers actual image loading with 1x resources. The 2x resource will
// be handled by IconImage class when requested.
- app_icon_image_->image_skia().GetRepresentation(1.0f);
+ app_icon_image_->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
}
void ShellWindow::CloseContents(WebContents* contents) {
diff --git a/ash/desktop_background/wallpaper_resizer_unittest.cc b/ash/desktop_background/wallpaper_resizer_unittest.cc
index 8447307..5761b67 100644
--- a/ash/desktop_background/wallpaper_resizer_unittest.cc
+++ b/ash/desktop_background/wallpaper_resizer_unittest.cc
@@ -104,14 +104,16 @@ TEST_F(WallpaperResizerTest, BasicResize) {
for (int i = 0; i < length; i++) {
WallpaperLayout layout = layouts[i];
- gfx::ImageSkia small_image(gfx::ImageSkiaRep(gfx::Size(10, 20), 1.0f));
+ gfx::ImageSkia small_image(gfx::ImageSkiaRep(gfx::Size(10, 20),
+ ui::SCALE_FACTOR_100P));
gfx::ImageSkia resized_small = Resize(small_image, gfx::Size(800, 600),
layout);
EXPECT_EQ(10, resized_small.width());
EXPECT_EQ(20, resized_small.height());
- gfx::ImageSkia large_image(gfx::ImageSkiaRep(gfx::Size(1000, 1000), 1.0f));
+ gfx::ImageSkia large_image(gfx::ImageSkiaRep(gfx::Size(1000, 1000),
+ ui::SCALE_FACTOR_100P));
gfx::ImageSkia resized_large = Resize(large_image, gfx::Size(800, 600),
layout);
EXPECT_EQ(800, resized_large.width());
diff --git a/ash/display/mirror_window_controller.cc b/ash/display/mirror_window_controller.cc
index d7cd6f0..2de135a 100644
--- a/ash/display/mirror_window_controller.cc
+++ b/ash/display/mirror_window_controller.cc
@@ -127,8 +127,10 @@ class CursorWindowDelegate : public aura::WindowDelegate {
// take 2x's image and paint as if it's 1x image.
void SetCursorImage(const gfx::ImageSkia& image,
const gfx::Display& display) {
+ device_scale_factor_ =
+ ui::GetScaleFactorFromScale(display.device_scale_factor());
const gfx::ImageSkiaRep& image_rep =
- image.GetRepresentation(display.device_scale_factor());
+ image.GetRepresentation(device_scale_factor_);
size_ = image_rep.pixel_size();
cursor_image_ = gfx::ImageSkia::CreateFrom1xBitmap(image_rep.sk_bitmap());
}
@@ -137,6 +139,7 @@ class CursorWindowDelegate : public aura::WindowDelegate {
private:
gfx::ImageSkia cursor_image_;
+ ui::ScaleFactor device_scale_factor_;
gfx::Size size_;
DISALLOW_COPY_AND_ASSIGN(CursorWindowDelegate);
diff --git a/ash/drag_drop/drag_drop_controller_unittest.cc b/ash/drag_drop/drag_drop_controller_unittest.cc
index 0cd770e..ba46192 100644
--- a/ash/drag_drop/drag_drop_controller_unittest.cc
+++ b/ash/drag_drop/drag_drop_controller_unittest.cc
@@ -77,7 +77,7 @@ class DragTestView : public views::View {
virtual void WriteDragData(const gfx::Point& p,
OSExchangeData* data) OVERRIDE {
data->SetString(UTF8ToUTF16("I am being dragged"));
- gfx::ImageSkiaRep image_rep(gfx::Size(10, 20), 1.0f);
+ gfx::ImageSkiaRep image_rep(gfx::Size(10, 20), ui::SCALE_FACTOR_100P);
gfx::ImageSkia image_skia(image_rep);
drag_utils::SetDragImageOnDataObject(
diff --git a/ash/drag_drop/drag_image_view.cc b/ash/drag_drop/drag_image_view.cc
index 84eef1e..5d0f2be 100644
--- a/ash/drag_drop/drag_image_view.cc
+++ b/ash/drag_drop/drag_image_view.cc
@@ -90,17 +90,21 @@ void DragImageView::OnPaint(gfx::Canvas* canvas) {
device_scale = ui::GetDeviceScaleFactor(
widget_->GetNativeView()->layer());
}
+ ui::ScaleFactor device_scale_factor =
+ ui::GetScaleFactorFromScale(device_scale);
+
// The drag image already has device scale factor applied. But
// |widget_size_| is in DIP units.
gfx::Size scaled_widget_size = gfx::ToRoundedSize(
gfx::ScaleSize(widget_size_, device_scale));
- gfx::ImageSkiaRep image_rep = GetImage().GetRepresentation(device_scale);
+ gfx::ImageSkiaRep image_rep = GetImage().GetRepresentation(
+ device_scale_factor);
if (image_rep.is_null())
return;
SkBitmap scaled = skia::ImageOperations::Resize(
image_rep.sk_bitmap(), skia::ImageOperations::RESIZE_LANCZOS3,
scaled_widget_size.width(), scaled_widget_size.height());
- gfx::ImageSkia image_skia(gfx::ImageSkiaRep(scaled, device_scale));
+ gfx::ImageSkia image_skia(gfx::ImageSkiaRep(scaled, device_scale_factor));
canvas->DrawImageInt(image_skia, 0, 0);
}
}
diff --git a/ash/launcher/launcher_delegate.h b/ash/launcher/launcher_delegate.h
index 41d0c29..06e0445 100644
--- a/ash/launcher/launcher_delegate.h
+++ b/ash/launcher/launcher_delegate.h
@@ -8,10 +8,6 @@
#include "ash/ash_export.h"
#include "ash/launcher/launcher_types.h"
-namespace aura {
-class Window;
-}
-
namespace ash {
class Launcher;
diff --git a/ash/launcher/launcher_item_delegate_manager.cc b/ash/launcher/launcher_item_delegate_manager.cc
index 1708fe6..65fb0f0 100644
--- a/ash/launcher/launcher_item_delegate_manager.cc
+++ b/ash/launcher/launcher_item_delegate_manager.cc
@@ -4,8 +4,6 @@
#include "ash/launcher/launcher_item_delegate_manager.h"
-#include "base/logging.h"
-
namespace ash {
LauncherItemDelegateManager::LauncherItemDelegateManager() {
diff --git a/ash/shell/app_list.cc b/ash/shell/app_list.cc
index 25306b3..f0dae34 100644
--- a/ash/shell/app_list.cc
+++ b/ash/shell/app_list.cc
@@ -204,7 +204,8 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
const base::string16 icon_text = ASCIIToUTF16("ash");
const gfx::Size icon_size(32, 32);
- gfx::Canvas canvas(icon_size, 1.0f, false /* is_opaque */);
+ gfx::Canvas canvas(icon_size, ui::SCALE_FACTOR_100P,
+ false /* is_opaque */);
canvas.DrawStringInt(icon_text,
gfx::Font(),
SK_ColorBLACK,
diff --git a/ash/shell/window_watcher.cc b/ash/shell/window_watcher.cc
index f076483..4dfcea4 100644
--- a/ash/shell/window_watcher.cc
+++ b/ash/shell/window_watcher.cc
@@ -118,7 +118,8 @@ void WindowWatcher::OnWindowAdded(aura::Window* new_window) {
image_count == 1 ? 255 : 0,
image_count == 2 ? 255 : 0);
image_count = (image_count + 1) % 3;
- item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f));
+ item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap,
+ ui::SCALE_FACTOR_100P));
model->Add(item);
}
diff --git a/ash/system/chromeos/network/network_icon.cc b/ash/system/chromeos/network/network_icon.cc
index 7e64bbe..7cb009a 100644
--- a/ash/system/chromeos/network/network_icon.cc
+++ b/ash/system/chromeos/network/network_icon.cc
@@ -196,12 +196,13 @@ class EmptyImageSource: public gfx::ImageSkiaSource {
: size_(size) {
}
- virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- gfx::Size pixel_size = gfx::ToFlooredSize(gfx::ScaleSize(size_, scale));
+ virtual gfx::ImageSkiaRep GetImageForScale(
+ ui::ScaleFactor scale_factor) OVERRIDE {
+ gfx::Size pixel_size = gfx::ToFlooredSize(
+ gfx::ScaleSize(size_, ui::GetScaleFactorScale(scale_factor)));
SkBitmap empty_bitmap = GetEmptyBitmap(pixel_size);
- return gfx::ImageSkiaRep(empty_bitmap, scale);
+ return gfx::ImageSkiaRep(empty_bitmap, scale_factor);
}
-
private:
const gfx::Size size_;
@@ -219,8 +220,9 @@ class NetworkIconImageSource : public gfx::ImageSkiaSource {
// TODO(pkotwicz): Figure out what to do when a new image resolution becomes
// available.
- virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale);
+ virtual gfx::ImageSkiaRep GetImageForScale(
+ ui::ScaleFactor scale_factor) OVERRIDE {
+ gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale_factor);
if (icon_rep.is_null())
return gfx::ImageSkiaRep();
gfx::Canvas canvas(icon_rep, false);
diff --git a/ash/wm/frame_painter.cc b/ash/wm/frame_painter.cc
index 0e53e33..b27fc7b 100644
--- a/ash/wm/frame_painter.cc
+++ b/ash/wm/frame_painter.cc
@@ -136,7 +136,7 @@ void PaintFrameImagesInRoundRect(gfx::Canvas* canvas,
top_left_corner_radius, top_right_corner_radius, 0);
}
} else {
- gfx::Canvas temporary_canvas(bounds.size(), canvas->image_scale(), false);
+ gfx::Canvas temporary_canvas(bounds.size(), canvas->scale_factor(), false);
temporary_canvas.TileImageInt(*frame_image,
image_inset_x, 0,
0, 0,
diff --git a/chrome/browser/android/provider/chrome_browser_provider.cc b/chrome/browser/android/provider/chrome_browser_provider.cc
index 2f82c13..f319c66 100644
--- a/chrome/browser/android/provider/chrome_browser_provider.cc
+++ b/chrome/browser/android/provider/chrome_browser_provider.cc
@@ -39,7 +39,6 @@
#include "sql/statement.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h"
-#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/favicon_size.h"
using base::android::AttachCurrentThread;
@@ -677,7 +676,7 @@ class BookmarkIconFetchTask : public FaviconServiceTask {
url,
chrome::FAVICON | chrome::TOUCH_ICON,
gfx::kFaviconSize),
- ResourceBundle::GetSharedInstance().GetMaxScaleFactor(),
+ ui::GetMaxScaleFactor(),
base::Bind(
&BookmarkIconFetchTask::OnFaviconRetrieved,
base::Unretained(this)),
diff --git a/chrome/browser/chromeos/extensions/wallpaper_api.cc b/chrome/browser/chromeos/extensions/wallpaper_api.cc
index 1f0f785..7bf7679 100644
--- a/chrome/browser/chromeos/extensions/wallpaper_api.cc
+++ b/chrome/browser/chromeos/extensions/wallpaper_api.cc
@@ -72,7 +72,7 @@ void WallpaperSetWallpaperFunction::OnWallpaperDecoded(
unsafe_wallpaper_decoder_ = NULL;
if (generate_thumbnail_) {
- wallpaper.EnsureRepsForSupportedScales();
+ wallpaper.EnsureRepsForSupportedScaleFactors();
scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.DeepCopy());
// Generates thumbnail before call api function callback. We can then
// request thumbnail in the javascript callback.
diff --git a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
index 9448649..27c82cf 100644
--- a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
+++ b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
@@ -370,7 +370,7 @@ void WallpaperPrivateSetWallpaperFunction::SaveToFile() {
sequence_token_));
std::string file_name = GURL(url_).ExtractFileName();
if (SaveData(chrome::DIR_CHROMEOS_WALLPAPERS, file_name, image_data_)) {
- wallpaper_.EnsureRepsForSupportedScales();
+ wallpaper_.EnsureRepsForSupportedScaleFactors();
scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper_.DeepCopy());
// ImageSkia is not RefCountedThreadSafe. Use a deep copied ImageSkia if
// post to another thread.
@@ -502,7 +502,7 @@ void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded(
unsafe_wallpaper_decoder_ = NULL;
if (generate_thumbnail_) {
- wallpaper.EnsureRepsForSupportedScales();
+ wallpaper.EnsureRepsForSupportedScaleFactors();
scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.DeepCopy());
// Generates thumbnail before call api function callback. We can then
// request thumbnail in the javascript callback.
diff --git a/chrome/browser/chromeos/login/helper.cc b/chrome/browser/chromeos/login/helper.cc
index c75fb09..58e85a0 100644
--- a/chrome/browser/chromeos/login/helper.cc
+++ b/chrome/browser/chromeos/login/helper.cc
@@ -15,7 +15,6 @@
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/screen.h"
namespace chromeos {
@@ -37,7 +36,8 @@ int GetCurrentUserImageSize() {
float scale_factor = gfx::Display::GetForcedDeviceScaleFactor();
if (scale_factor > 1.0f)
return static_cast<int>(scale_factor * kBaseUserImageSize);
- return kBaseUserImageSize * gfx::ImageSkia::GetMaxSupportedScale();
+ return kBaseUserImageSize *
+ ui::GetScaleFactorScale(ui::GetMaxScaleFactor());
}
namespace login {
diff --git a/chrome/browser/chromeos/login/wallpaper_manager.cc b/chrome/browser/chromeos/login/wallpaper_manager.cc
index 3920d71..3692a2a 100644
--- a/chrome/browser/chromeos/login/wallpaper_manager.cc
+++ b/chrome/browser/chromeos/login/wallpaper_manager.cc
@@ -420,7 +420,7 @@ void WallpaperManager::SetCustomWallpaper(const std::string& username,
bool is_persistent =
!UserManager::Get()->IsUserNonCryptohomeDataEphemeral(username);
- wallpaper.image().EnsureRepsForSupportedScales();
+ wallpaper.image().EnsureRepsForSupportedScaleFactors();
scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy());
WallpaperInfo wallpaper_info = {
diff --git a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
index 0601780..f9785f8 100644
--- a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
+++ b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
@@ -59,9 +59,9 @@ gfx::ImageSkia AddBackgroundForViews(const gfx::ImageSkia& icon) {
bool ImagesAreEqualAtScale(const gfx::ImageSkia& i1,
const gfx::ImageSkia& i2,
- float scale) {
- SkBitmap bitmap1 = i1.GetRepresentation(scale).sk_bitmap();
- SkBitmap bitmap2 = i2.GetRepresentation(scale).sk_bitmap();
+ ui::ScaleFactor scale_factor) {
+ SkBitmap bitmap1 = i1.GetRepresentation(scale_factor).sk_bitmap();
+ SkBitmap bitmap2 = i2.GetRepresentation(scale_factor).sk_bitmap();
return gfx::BitmapsAreEqual(bitmap1, bitmap2);
}
@@ -136,7 +136,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
std::vector<ui::ScaleFactor> supported_scale_factors;
supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
- ui::SetSupportedScaleFactors(supported_scale_factors);
+ ui::test::SetSupportedScaleFactors(supported_scale_factors);
#endif
// We should not be creating icons asynchronously, so we don't need an
@@ -171,12 +171,13 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
EXPECT_GT(action_icon_current_id, action_icon_last_id);
action_icon_last_id = action_icon_current_id;
- EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
+ EXPECT_FALSE(
+ action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- 1.0f));
+ ui::SCALE_FACTOR_100P));
// Tell the extension to update the icon using path.
GetBrowserActionsBar().Press(0);
@@ -189,12 +190,12 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
action_icon_last_id = action_icon_current_id;
EXPECT_FALSE(
- action_icon.ToImageSkia()->HasRepresentation(2.0f));
+ action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- 1.0f));
+ ui::SCALE_FACTOR_100P));
// Tell the extension to update the icon using dictionary of ImageData
// objects.
@@ -207,12 +208,13 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
EXPECT_GT(action_icon_current_id, action_icon_last_id);
action_icon_last_id = action_icon_current_id;
- EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
+ EXPECT_TRUE(
+ action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- 1.0f));
+ ui::SCALE_FACTOR_100P));
// Tell the extension to update the icon using dictionary of paths.
GetBrowserActionsBar().Press(0);
@@ -224,12 +226,13 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
EXPECT_GT(action_icon_current_id, action_icon_last_id);
action_icon_last_id = action_icon_current_id;
- EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
+ EXPECT_TRUE(
+ action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- 1.0f));
+ ui::SCALE_FACTOR_100P));
// Tell the extension to update the icon using dictionary of ImageData
// objects, but setting only size 19.
@@ -242,12 +245,13 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
EXPECT_GT(action_icon_current_id, action_icon_last_id);
action_icon_last_id = action_icon_current_id;
- EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
+ EXPECT_FALSE(
+ action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- 1.0f));
+ ui::SCALE_FACTOR_100P));
// Tell the extension to update the icon using dictionary of paths, but
// setting only size 19.
@@ -260,12 +264,13 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
EXPECT_GT(action_icon_current_id, action_icon_last_id);
action_icon_last_id = action_icon_current_id;
- EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
+ EXPECT_FALSE(
+ action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- 1.0f));
+ ui::SCALE_FACTOR_100P));
// Tell the extension to update the icon using dictionary of ImageData
// objects, but setting only size 38.
@@ -276,8 +281,8 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia();
- EXPECT_FALSE(action_icon_skia->HasRepresentation(1.0f));
- EXPECT_TRUE(action_icon_skia->HasRepresentation(2.0f));
+ EXPECT_FALSE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_100P));
+ EXPECT_TRUE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_200P));
action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
EXPECT_GT(action_icon_current_id, action_icon_last_id);
@@ -285,12 +290,12 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
EXPECT_TRUE(gfx::BitmapsAreEqual(
*action_icon.ToSkBitmap(),
- action_icon_skia->GetRepresentation(2.0f).sk_bitmap()));
+ action_icon_skia->GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap()));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon_skia),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- 2.0f));
+ ui::SCALE_FACTOR_200P));
// Try setting icon with empty dictionary of ImageData objects.
GetBrowserActionsBar().Press(0);
diff --git a/chrome/browser/extensions/api/extension_action/extension_action_api.cc b/chrome/browser/extensions/api/extension_action/extension_action_api.cc
index 488e852..3d4c46d 100644
--- a/chrome/browser/extensions/api/extension_action/extension_action_api.cc
+++ b/chrome/browser/extensions/api/extension_action/extension_action_api.cc
@@ -100,7 +100,8 @@ bool StringToSkBitmap(const std::string& str, SkBitmap* bitmap) {
}
// Conversion function for reading/writing to storage.
-std::string RepresentationToString(const gfx::ImageSkia& image, float scale) {
+std::string RepresentationToString(const gfx::ImageSkia& image,
+ ui::ScaleFactor scale) {
SkBitmap bitmap = image.GetRepresentation(scale).sk_bitmap();
IPC::Message bitmap_pickle;
// Clear the header values so they don't vary in serialization.
@@ -143,8 +144,7 @@ void SetDefaultsFromValue(const base::DictionaryValue* dict,
if (icon_value->GetString(kIconSizes[i].size_string, &str_value) &&
StringToSkBitmap(str_value, &bitmap)) {
CHECK(!bitmap.isNull());
- float scale = ui::GetImageScale(kIconSizes[i].scale);
- icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
+ icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale));
}
}
action->SetIcon(kTabId, gfx::Image(icon));
@@ -172,11 +172,10 @@ scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) {
if (!icon.isNull()) {
base::DictionaryValue* icon_value = new base::DictionaryValue();
for (size_t i = 0; i < arraysize(kIconSizes); i++) {
- float scale = ui::GetImageScale(kIconSizes[i].scale);
- if (icon.HasRepresentation(scale)) {
+ if (icon.HasRepresentation(kIconSizes[i].scale)) {
icon_value->SetString(
kIconSizes[i].size_string,
- RepresentationToString(icon, scale));
+ RepresentationToString(icon, kIconSizes[i].scale));
}
}
dict->Set(kIconStorageKey, icon_value);
@@ -697,8 +696,7 @@ bool ExtensionActionSetIconFunction::RunExtensionAction() {
SkBitmap bitmap;
EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap));
CHECK(!bitmap.isNull());
- float scale = ui::GetImageScale(kIconSizes[i].scale);
- icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
+ icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale));
}
}
diff --git a/chrome/browser/extensions/api/notifications/notifications_api.cc b/chrome/browser/extensions/api/notifications/notifications_api.cc
index bd4054d..e78798e 100644
--- a/chrome/browser/extensions/api/notifications/notifications_api.cc
+++ b/chrome/browser/extensions/api/notifications/notifications_api.cc
@@ -102,7 +102,8 @@ bool NotificationBitmapToGfxImage(
}
// TODO(dewittj): Handle HiDPI images.
- gfx::ImageSkia skia(gfx::ImageSkiaRep(bitmap, 1.0f));
+ ui::ScaleFactor scale_factor(ui::SCALE_FACTOR_100P);
+ gfx::ImageSkia skia(gfx::ImageSkiaRep(bitmap, scale_factor));
*return_image = gfx::Image(skia);
return true;
}
diff --git a/chrome/browser/extensions/app_icon_loader_impl.cc b/chrome/browser/extensions/app_icon_loader_impl.cc
index 1172b2b..4eb0fc2 100644
--- a/chrome/browser/extensions/app_icon_loader_impl.cc
+++ b/chrome/browser/extensions/app_icon_loader_impl.cc
@@ -67,7 +67,7 @@ void AppIconLoaderImpl::FetchImage(const std::string& id) {
// Triggers image loading now instead of depending on paint message. This
// makes the temp blank image be shown for shorter time and improves user
// experience. See http://crbug.com/146114.
- image->image_skia().EnsureRepsForSupportedScales();
+ image->image_skia().EnsureRepsForSupportedScaleFactors();
}
void AppIconLoaderImpl::ClearImage(const std::string& id) {
diff --git a/chrome/browser/extensions/extension_action.cc b/chrome/browser/extensions/extension_action.cc
index 50ac185..ccce0ca 100644
--- a/chrome/browser/extensions/extension_action.cc
+++ b/chrome/browser/extensions/extension_action.cc
@@ -39,12 +39,13 @@ class GetAttentionImageSource : public gfx::ImageSkiaSource {
: icon_(icon) {}
// gfx::ImageSkiaSource overrides:
- virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale);
+ virtual gfx::ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor)
+ OVERRIDE {
+ gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale_factor);
color_utils::HSL shift = {-1, 0, 0.5};
return gfx::ImageSkiaRep(
SkBitmapOperations::CreateHSLShiftedBitmap(icon_rep.sk_bitmap(), shift),
- icon_rep.scale());
+ icon_rep.scale_factor());
}
private:
@@ -67,7 +68,7 @@ class AnimatedIconImageSource : public gfx::ImageSkiaSource {
private:
virtual ~AnimatedIconImageSource() {}
- virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ virtual gfx::ImageSkiaRep GetImageForScale(ui::ScaleFactor scale) OVERRIDE {
gfx::ImageSkiaRep original_rep = image_.GetRepresentation(scale);
if (!animation_.get())
return original_rep;
@@ -76,7 +77,8 @@ class AnimatedIconImageSource : public gfx::ImageSkiaSource {
// factor passed to this method. We want to use the former (since we are
// using bitmap for that scale).
return gfx::ImageSkiaRep(
- animation_->Apply(original_rep.sk_bitmap()), original_rep.scale());
+ animation_->Apply(original_rep.sk_bitmap()),
+ original_rep.scale_factor());
}
gfx::ImageSkia image_;
diff --git a/chrome/browser/extensions/extension_action_icon_factory_unittest.cc b/chrome/browser/extensions/extension_action_icon_factory_unittest.cc
index 649ac62..3eadffa 100644
--- a/chrome/browser/extensions/extension_action_icon_factory_unittest.cc
+++ b/chrome/browser/extensions/extension_action_icon_factory_unittest.cc
@@ -38,7 +38,7 @@ namespace {
bool ImageRepsAreEqual(const gfx::ImageSkiaRep& image_rep1,
const gfx::ImageSkiaRep& image_rep2) {
- return image_rep1.scale() == image_rep2.scale() &&
+ return image_rep1.scale_factor() == image_rep2.scale_factor() &&
gfx::BitmapsAreEqual(image_rep1.sk_bitmap(), image_rep2.sk_bitmap());
}
@@ -53,14 +53,15 @@ gfx::Image EnsureImageSize(const gfx::Image& original, int size) {
return gfx::Image::CreateFrom1xBitmap(resized);
}
-gfx::ImageSkiaRep CreateBlankRep(int size_dip, float scale) {
- SkBitmap bitmap;
- bitmap.setConfig(SkBitmap::kARGB_8888_Config,
- static_cast<int>(size_dip * scale),
- static_cast<int>(size_dip * scale));
- bitmap.allocPixels();
- bitmap.eraseColor(SkColorSetARGB(0, 0, 0, 0));
- return gfx::ImageSkiaRep(bitmap, scale);
+gfx::ImageSkiaRep CreateBlankRep(int size_dip, ui::ScaleFactor scale_factor) {
+ SkBitmap bitmap;
+ const float scale = ui::GetScaleFactorScale(scale_factor);
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config,
+ static_cast<int>(size_dip * scale),
+ static_cast<int>(size_dip * scale));
+ bitmap.allocPixels();
+ bitmap.eraseColor(SkColorSetARGB(0, 0, 0, 0));
+ return gfx::ImageSkiaRep(bitmap, scale_factor);
}
gfx::Image LoadIcon(const std::string& filename) {
@@ -202,8 +203,8 @@ TEST_F(ExtensionActionIconFactoryTest, NoIcons) {
gfx::Image icon = icon_factory.GetIcon(0);
EXPECT_TRUE(ImageRepsAreEqual(
- favicon.GetRepresentation(1.0f),
- icon.ToImageSkia()->GetRepresentation(1.0f)));
+ favicon.GetRepresentation(ui::SCALE_FACTOR_100P),
+ icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
}
// If the icon has been set using |SetIcon|, the factory should return that
@@ -233,15 +234,15 @@ TEST_F(ExtensionActionIconFactoryTest, AfterSetIcon) {
gfx::Image icon = icon_factory.GetIcon(0);
EXPECT_TRUE(ImageRepsAreEqual(
- set_icon.ToImageSkia()->GetRepresentation(1.0f),
- icon.ToImageSkia()->GetRepresentation(1.0f)));
+ set_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P),
+ icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
// It should still return favicon for another tabs.
icon = icon_factory.GetIcon(1);
EXPECT_TRUE(ImageRepsAreEqual(
- GetFavicon().GetRepresentation(1.0f),
- icon.ToImageSkia()->GetRepresentation(1.0f)));
+ GetFavicon().GetRepresentation(ui::SCALE_FACTOR_100P),
+ icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
}
// If there is a default icon, and the icon has not been set using |SetIcon|,
@@ -276,8 +277,8 @@ TEST_F(ExtensionActionIconFactoryTest, DefaultIcon) {
// The icon should be loaded asynchronously. Initially a transparent icon
// should be returned.
EXPECT_TRUE(ImageRepsAreEqual(
- CreateBlankRep(19, 1.0f),
- icon.ToImageSkia()->GetRepresentation(1.0f)));
+ CreateBlankRep(19, ui::SCALE_FACTOR_100P),
+ icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
WaitForIconUpdate();
@@ -285,15 +286,15 @@ TEST_F(ExtensionActionIconFactoryTest, DefaultIcon) {
// The default icon representation should be loaded at this point.
EXPECT_TRUE(ImageRepsAreEqual(
- default_icon.ToImageSkia()->GetRepresentation(1.0f),
- icon.ToImageSkia()->GetRepresentation(1.0f)));
+ default_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P),
+ icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
// The same icon should be returned for the other tabs.
icon = icon_factory.GetIcon(1);
EXPECT_TRUE(ImageRepsAreEqual(
- default_icon.ToImageSkia()->GetRepresentation(1.0f),
- icon.ToImageSkia()->GetRepresentation(1.0f)));
+ default_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P),
+ icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
}
diff --git a/chrome/browser/extensions/extension_icon_image.cc b/chrome/browser/extensions/extension_icon_image.cc
index 7b0b248..fbd1ee4 100644
--- a/chrome/browser/extensions/extension_icon_image.cc
+++ b/chrome/browser/extensions/extension_icon_image.cc
@@ -86,7 +86,8 @@ class IconImage::Source : public gfx::ImageSkiaSource {
private:
// gfx::ImageSkiaSource overrides:
- virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE;
+ virtual gfx::ImageSkiaRep GetImageForScale(
+ ui::ScaleFactor scale_factor) OVERRIDE;
// Used to load images, possibly asynchronously. NULLed out when the IconImage
// is destroyed.
@@ -111,17 +112,16 @@ void IconImage::Source::ResetHost() {
host_ = NULL;
}
-gfx::ImageSkiaRep IconImage::Source::GetImageForScale(float scale) {
+gfx::ImageSkiaRep IconImage::Source::GetImageForScale(
+ ui::ScaleFactor scale_factor) {
gfx::ImageSkiaRep representation;
- if (host_) {
- representation =
- host_->LoadImageForScaleFactor(ui::GetSupportedScaleFactor(scale));
- }
+ if (host_)
+ representation = host_->LoadImageForScaleFactor(scale_factor);
if (!representation.is_null())
return representation;
- return blank_image_.GetRepresentation(scale);
+ return blank_image_.GetRepresentation(scale_factor);
}
////////////////////////////////////////////////////////////////////////////////
@@ -163,7 +163,7 @@ gfx::ImageSkiaRep IconImage::LoadImageForScaleFactor(
if (!extension_)
return gfx::ImageSkiaRep();
- const float scale = ui::GetImageScale(scale_factor);
+ const float scale = ui::GetScaleFactorScale(scale_factor);
const int resource_size_in_pixel =
static_cast<int>(resource_size_in_dip_ * scale);
@@ -184,7 +184,7 @@ gfx::ImageSkiaRep IconImage::LoadImageForScaleFactor(
// If there is no resource found, return default icon.
if (resource.empty())
- return default_icon_.GetRepresentation(scale);
+ return default_icon_.GetRepresentation(scale_factor);
std::vector<ImageLoader::ImageRepresentation> info_list;
info_list.push_back(ImageLoader::ImageRepresentation(
@@ -198,12 +198,13 @@ gfx::ImageSkiaRep IconImage::LoadImageForScaleFactor(
loader->LoadImagesAsync(extension_, info_list,
base::Bind(&IconImage::OnImageLoaded,
weak_ptr_factory_.GetWeakPtr(),
- scale));
+ scale_factor));
return gfx::ImageSkiaRep();
}
-void IconImage::OnImageLoaded(float scale, const gfx::Image& image_in) {
+void IconImage::OnImageLoaded(ui::ScaleFactor scale_factor,
+ const gfx::Image& image_in) {
const gfx::ImageSkia* image =
image_in.IsEmpty() ? &default_icon_ : image_in.ToImageSkia();
@@ -211,12 +212,12 @@ void IconImage::OnImageLoaded(float scale, const gfx::Image& image_in) {
if (image->isNull())
return;
- gfx::ImageSkiaRep rep = image->GetRepresentation(scale);
+ gfx::ImageSkiaRep rep = image->GetRepresentation(scale_factor);
DCHECK(!rep.is_null());
- DCHECK_EQ(scale, rep.scale());
+ DCHECK_EQ(scale_factor, rep.scale_factor());
// Remove old representation if there is one.
- image_skia_.RemoveRepresentation(scale);
+ image_skia_.RemoveRepresentation(rep.scale_factor());
image_skia_.AddRepresentation(rep);
if (observer_)
diff --git a/chrome/browser/extensions/extension_icon_image.h b/chrome/browser/extensions/extension_icon_image.h
index 94cdae5..d1ddd57 100644
--- a/chrome/browser/extensions/extension_icon_image.h
+++ b/chrome/browser/extensions/extension_icon_image.h
@@ -13,7 +13,6 @@
#include "chrome/common/extensions/extension_icon_set.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
-#include "ui/base/layout.h"
#include "ui/gfx/image/image_skia.h"
class Profile;
@@ -82,7 +81,7 @@ class IconImage : public content::NotificationObserver {
// observer's |OnExtensionIconImageLoaded| will be called.
gfx::ImageSkiaRep LoadImageForScaleFactor(ui::ScaleFactor scale_factor);
- void OnImageLoaded(float scale_factor, const gfx::Image& image);
+ void OnImageLoaded(ui::ScaleFactor scale_factor, const gfx::Image& image);
// content::NotificationObserver overrides:
virtual void Observe(int type,
diff --git a/chrome/browser/extensions/extension_icon_image_unittest.cc b/chrome/browser/extensions/extension_icon_image_unittest.cc
index fd35ee9..0d9b9a7 100644
--- a/chrome/browser/extensions/extension_icon_image_unittest.cc
+++ b/chrome/browser/extensions/extension_icon_image_unittest.cc
@@ -31,7 +31,7 @@ namespace {
SkBitmap CreateBlankBitmapForScale(int size_dip, ui::ScaleFactor scale_factor) {
SkBitmap bitmap;
- const float scale = ui::GetImageScale(scale_factor);
+ const float scale = ui::GetScaleFactorScale(scale_factor);
bitmap.setConfig(SkBitmap::kARGB_8888_Config,
static_cast<int>(size_dip * scale),
static_cast<int>(size_dip * scale));
@@ -59,8 +59,9 @@ class MockImageSkiaSource : public gfx::ImageSkiaSource {
}
virtual ~MockImageSkiaSource() {}
- virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- return image_.GetRepresentation(scale);
+ virtual gfx::ImageSkiaRep GetImageForScale(
+ ui::ScaleFactor scale_factor) OVERRIDE {
+ return image_.GetRepresentation(scale_factor);
}
private:
@@ -209,10 +210,6 @@ class ExtensionIconImageTest : public testing::Test,
} // namespace
TEST_F(ExtensionIconImageTest, Basic) {
- std::vector<ui::ScaleFactor> supported_factors;
- supported_factors.push_back(ui::SCALE_FACTOR_100P);
- supported_factors.push_back(ui::SCALE_FACTOR_200P);
- ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
scoped_ptr<Profile> profile(new TestingProfile());
scoped_refptr<Extension> extension(CreateExtension(
"extension_icon_image", Manifest::INVALID_LOCATION));
@@ -243,7 +240,8 @@ TEST_F(ExtensionIconImageTest, Basic) {
ASSERT_EQ(0u, image_reps.size());
// Gets representation for a scale factor.
- gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
// Before the image representation is loaded, image should contain blank
// image representation.
@@ -255,14 +253,14 @@ TEST_F(ExtensionIconImageTest, Basic) {
EXPECT_EQ(1, ImageLoadedCount());
ASSERT_EQ(1u, image.image_skia().image_reps().size());
- representation = image.image_skia().GetRepresentation(1.0f);
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
// We should get the right representation now.
EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16));
EXPECT_EQ(16, representation.pixel_width());
// Gets representation for an additional scale factor.
- representation = image.image_skia().GetRepresentation(2.0f);
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
@@ -272,7 +270,7 @@ TEST_F(ExtensionIconImageTest, Basic) {
EXPECT_EQ(1, ImageLoadedCount());
ASSERT_EQ(2u, image.image_skia().image_reps().size());
- representation = image.image_skia().GetRepresentation(2.0f);
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
// Image should have been resized.
EXPECT_EQ(32, representation.pixel_width());
@@ -283,10 +281,6 @@ TEST_F(ExtensionIconImageTest, Basic) {
// There is no resource with either exact or bigger size, but there is a smaller
// resource.
TEST_F(ExtensionIconImageTest, FallbackToSmallerWhenNoBigger) {
- std::vector<ui::ScaleFactor> supported_factors;
- supported_factors.push_back(ui::SCALE_FACTOR_100P);
- supported_factors.push_back(ui::SCALE_FACTOR_200P);
- ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
scoped_ptr<Profile> profile(new TestingProfile());
scoped_refptr<Extension> extension(CreateExtension(
"extension_icon_image", Manifest::INVALID_LOCATION));
@@ -306,17 +300,18 @@ TEST_F(ExtensionIconImageTest, FallbackToSmallerWhenNoBigger) {
default_icon,
this);
- gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(2.0f);
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
WaitForImageLoad();
EXPECT_EQ(1, ImageLoadedCount());
ASSERT_EQ(1u, image.image_skia().image_reps().size());
- representation = image.image_skia().GetRepresentation(2.0f);
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
// We should have loaded the biggest smaller resource resized to the actual
// size.
- EXPECT_EQ(2.0f, representation.scale());
+ EXPECT_EQ(ui::SCALE_FACTOR_200P, representation.scale_factor());
EXPECT_EQ(64, representation.pixel_width());
EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(),
EnsureBitmapSize(bitmap_48, 64)));
@@ -345,16 +340,17 @@ TEST_F(ExtensionIconImageTest, FallbackToSmaller) {
default_icon,
this);
- gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
WaitForImageLoad();
EXPECT_EQ(1, ImageLoadedCount());
ASSERT_EQ(1u, image.image_skia().image_reps().size());
- representation = image.image_skia().GetRepresentation(1.0f);
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
// We should have loaded smaller (resized) resource.
- EXPECT_EQ(1.0f, representation.scale());
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor());
EXPECT_EQ(17, representation.pixel_width());
EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(),
EnsureBitmapSize(bitmap_16, 17)));
@@ -379,22 +375,23 @@ TEST_F(ExtensionIconImageTest, NoResources) {
default_icon,
this);
- gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
EnsureBitmapSize(
- default_icon.GetRepresentation(1.0f).sk_bitmap(),
+ default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(),
kRequestedSize)));
EXPECT_EQ(0, ImageLoadedCount());
// We should have a default icon representation.
ASSERT_EQ(1u, image.image_skia().image_reps().size());
- representation = image.image_skia().GetRepresentation(1.0f);
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
EnsureBitmapSize(
- default_icon.GetRepresentation(1.0f).sk_bitmap(),
+ default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(),
kRequestedSize)));
}
@@ -420,7 +417,8 @@ TEST_F(ExtensionIconImageTest, InvalidResource) {
default_icon,
this);
- gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
CreateBlankBitmapForScale(kInvalidIconSize, ui::SCALE_FACTOR_100P)));
@@ -430,11 +428,11 @@ TEST_F(ExtensionIconImageTest, InvalidResource) {
// We should have default icon representation now.
ASSERT_EQ(1u, image.image_skia().image_reps().size());
- representation = image.image_skia().GetRepresentation(1.0f);
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
EnsureBitmapSize(
- default_icon.GetRepresentation(1.0f).sk_bitmap(),
+ default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(),
kInvalidIconSize)));
}
@@ -460,16 +458,17 @@ TEST_F(ExtensionIconImageTest, LazyDefaultIcon) {
lazy_default_icon,
this);
- ASSERT_FALSE(lazy_default_icon.HasRepresentation(1.0f));
+ ASSERT_FALSE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
- gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
// The resouce set is empty, so we should get the result right away.
- EXPECT_TRUE(lazy_default_icon.HasRepresentation(1.0f));
+ EXPECT_TRUE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
EnsureBitmapSize(
- default_icon.GetRepresentation(1.0f).sk_bitmap(),
+ default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(),
kRequestedSize)));
// We should have a default icon representation.
@@ -499,22 +498,23 @@ TEST_F(ExtensionIconImageTest, LazyDefaultIcon_AsyncIconImage) {
lazy_default_icon,
this);
- ASSERT_FALSE(lazy_default_icon.HasRepresentation(1.0f));
+ ASSERT_FALSE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
- gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
WaitForImageLoad();
EXPECT_EQ(1, ImageLoadedCount());
// We should have default icon representation now.
ASSERT_EQ(1u, image.image_skia().image_reps().size());
- EXPECT_TRUE(lazy_default_icon.HasRepresentation(1.0f));
+ EXPECT_TRUE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
- representation = image.image_skia().GetRepresentation(1.0f);
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
EnsureBitmapSize(
- default_icon.GetRepresentation(1.0f).sk_bitmap(),
+ default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(),
kInvalidIconSize)));
}
@@ -545,7 +545,7 @@ TEST_F(ExtensionIconImageTest, IconImageDestruction) {
// Load an image representation.
gfx::ImageSkiaRep representation =
- image->image_skia().GetRepresentation(1.0f);
+ image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
WaitForImageLoad();
EXPECT_EQ(1, ImageLoadedCount());
@@ -557,14 +557,14 @@ TEST_F(ExtensionIconImageTest, IconImageDestruction) {
extension = NULL;
// Image skia should still be able to get previously loaded representation.
- representation = image_skia.GetRepresentation(1.0f);
+ representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_100P);
- EXPECT_EQ(1.0f, representation.scale());
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor());
EXPECT_EQ(16, representation.pixel_width());
EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16));
// When requesting another representation, we should get blank image.
- representation = image_skia.GetRepresentation(2.0f);
+ representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
diff --git a/chrome/browser/extensions/extension_icon_manager.cc b/chrome/browser/extensions/extension_icon_manager.cc
index 475f4cb..66f42db 100644
--- a/chrome/browser/extensions/extension_icon_manager.cc
+++ b/chrome/browser/extensions/extension_icon_manager.cc
@@ -32,7 +32,7 @@ static SkBitmap ApplyPadding(const SkBitmap& source,
scoped_ptr<gfx::Canvas> result(
new gfx::Canvas(gfx::Size(source.width() + padding.width(),
source.height() + padding.height()),
- 1.0f,
+ ui::SCALE_FACTOR_100P,
false));
result->DrawImageInt(
gfx::ImageSkia::CreateFrom1xBitmap(source),
diff --git a/chrome/browser/extensions/extension_install_prompt.cc b/chrome/browser/extensions/extension_install_prompt.cc
index f4b58ad..c45fefa 100644
--- a/chrome/browser/extensions/extension_install_prompt.cc
+++ b/chrome/browser/extensions/extension_install_prompt.cc
@@ -122,7 +122,9 @@ const int kIconSize = 69;
// Returns pixel size under maximal scale factor for the icon whose device
// independent size is |size_in_dip|
int GetSizeForMaxScaleFactor(int size_in_dip) {
- return static_cast<int>(size_in_dip * gfx::ImageSkia::GetMaxSupportedScale());
+ float max_scale_factor_scale =
+ ui::GetScaleFactorScale(ui::GetMaxScaleFactor());
+ return static_cast<int>(size_in_dip * max_scale_factor_scale);
}
// Returns bitmap for the default icon with size equal to the default icon's
@@ -131,8 +133,7 @@ SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
const gfx::ImageSkia& image = is_app ?
extensions::IconsInfo::GetDefaultAppIcon() :
extensions::IconsInfo::GetDefaultExtensionIcon();
- return image.GetRepresentation(
- gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap();
+ return image.GetRepresentation(ui::GetMaxScaleFactor()).sk_bitmap();
}
// If auto confirm is enabled then posts a task to proceed with or cancel the
diff --git a/chrome/browser/extensions/extension_uninstall_dialog.cc b/chrome/browser/extensions/extension_uninstall_dialog.cc
index fb6bc92..0eb8dcf 100644
--- a/chrome/browser/extensions/extension_uninstall_dialog.cc
+++ b/chrome/browser/extensions/extension_uninstall_dialog.cc
@@ -21,14 +21,14 @@
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
-#include "ui/gfx/image/image_skia.h"
namespace {
// Returns pixel size under maximal scale factor for the icon whose device
// independent size is |size_in_dip|
int GetSizeForMaxScaleFactor(int size_in_dip) {
- float max_scale_factor_scale = gfx::ImageSkia::GetMaxSupportedScale();
+ ui::ScaleFactor max_scale_factor = ui::GetMaxScaleFactor();
+ float max_scale_factor_scale = ui::GetScaleFactorScale(max_scale_factor);
return static_cast<int>(size_in_dip * max_scale_factor_scale);
}
@@ -39,8 +39,7 @@ SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
const gfx::ImageSkia& image = is_app ?
extensions::IconsInfo::GetDefaultAppIcon() :
extensions::IconsInfo::GetDefaultExtensionIcon();
- return image.GetRepresentation(
- gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap();
+ return image.GetRepresentation(ui::GetMaxScaleFactor()).sk_bitmap();
}
} // namespace
diff --git a/chrome/browser/extensions/extension_web_ui.cc b/chrome/browser/extensions/extension_web_ui.cc
index 631ba56..40a4deb 100644
--- a/chrome/browser/extensions/extension_web_ui.cc
+++ b/chrome/browser/extensions/extension_web_ui.cc
@@ -404,7 +404,7 @@ void ExtensionWebUI::GetFaviconForURL(
FaviconUtil::GetFaviconScaleFactors();
std::vector<extensions::ImageLoader::ImageRepresentation> info_list;
for (size_t i = 0; i < scale_factors.size(); ++i) {
- float scale = ui::GetImageScale(scale_factors[i]);
+ float scale = ui::GetScaleFactorScale(scale_factors[i]);
int pixel_size = static_cast<int>(gfx::kFaviconSize * scale);
extensions::ExtensionResource icon_resource =
extensions::IconsInfo::GetIconResource(extension,
diff --git a/chrome/browser/extensions/image_loader.cc b/chrome/browser/extensions/image_loader.cc
index 2c8f77c..2e2702e 100644
--- a/chrome/browser/extensions/image_loader.cc
+++ b/chrome/browser/extensions/image_loader.cc
@@ -334,8 +334,7 @@ void ImageLoader::ReplyBack(
const ImageRepresentation& image_rep = it->image_representation;
image_skia.AddRepresentation(gfx::ImageSkiaRep(
- bitmap,
- ui::GetImageScale(image_rep.scale_factor)));
+ bitmap, image_rep.scale_factor));
}
gfx::Image image;
diff --git a/chrome/browser/favicon/favicon_handler.cc b/chrome/browser/favicon/favicon_handler.cc
index 5e1459c..8eb1897 100644
--- a/chrome/browser/favicon/favicon_handler.cc
+++ b/chrome/browser/favicon/favicon_handler.cc
@@ -67,7 +67,7 @@ int GetMaximalIconSize(chrome::IconType icon_type) {
base_size = 0;
break;
}
- return gfx::ImageSkia::GetMaxSupportedScale() * base_size;
+ return ui::GetScaleFactorScale(ui::GetMaxScaleFactor()) * base_size;
}
bool DoUrlAndIconMatch(const FaviconURL& favicon_url,
@@ -148,7 +148,7 @@ bool HasExpiredOrIncompleteResult(
FaviconUtil::GetFaviconScaleFactors();
for (size_t i = 0; i < scale_factors.size(); ++i) {
int edge_size_in_pixel = floor(
- desired_size_in_dip * ui::GetImageScale(scale_factors[i]));
+ desired_size_in_dip * ui::GetScaleFactorScale(scale_factors[i]));
std::vector<gfx::Size>::iterator it = std::find(favicon_sizes.begin(),
favicon_sizes.end(), gfx::Size(edge_size_in_pixel, edge_size_in_pixel));
if (it == favicon_sizes.end())
diff --git a/chrome/browser/favicon/favicon_handler_unittest.cc b/chrome/browser/favicon/favicon_handler_unittest.cc
index 5671b73..d89d45f 100644
--- a/chrome/browser/favicon/favicon_handler_unittest.cc
+++ b/chrome/browser/favicon/favicon_handler_unittest.cc
@@ -410,8 +410,7 @@ class FaviconHandlerTest : public ChromeRenderViewHostTestHarness {
// results on all platforms.
std::vector<ui::ScaleFactor> scale_factors;
scale_factors.push_back(ui::SCALE_FACTOR_100P);
- scoped_set_supported_scale_factors_.reset(
- new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
+ ui::test::SetSupportedScaleFactors(scale_factors);
ChromeRenderViewHostTestHarness::SetUp();
}
@@ -425,9 +424,6 @@ class FaviconHandlerTest : public ChromeRenderViewHostTestHarness {
}
private:
- typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors>
- ScopedSetSupportedScaleFactors;
- ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_;
DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest);
};
diff --git a/chrome/browser/favicon/favicon_service.cc b/chrome/browser/favicon/favicon_service.cc
index fd0f9eb..555cdb1 100644
--- a/chrome/browser/favicon/favicon_service.cc
+++ b/chrome/browser/favicon/favicon_service.cc
@@ -238,7 +238,7 @@ void FaviconService::SetFavicons(const GURL& page_url,
return;
gfx::ImageSkia image_skia = image.AsImageSkia();
- image_skia.EnsureRepsForSupportedScales();
+ image_skia.EnsureRepsForSupportedScaleFactors();
const std::vector<gfx::ImageSkiaRep>& image_reps = image_skia.image_reps();
std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
for (size_t i = 0; i < image_reps.size(); ++i) {
@@ -343,7 +343,7 @@ void FaviconService::RunFaviconRawCallbackWithBitmapResults(
}
// If history bitmap is already desired pixel size, return early.
- float desired_scale = ui::GetImageScale(desired_scale_factor);
+ float desired_scale = ui::GetScaleFactorScale(desired_scale_factor);
int desired_edge_width_in_pixel = static_cast<int>(
desired_size_in_dip * desired_scale + 0.5f);
gfx::Size desired_size_in_pixel(desired_edge_width_in_pixel,
diff --git a/chrome/browser/favicon/favicon_util.cc b/chrome/browser/favicon/favicon_util.cc
index a34ffca..4f2db61 100644
--- a/chrome/browser/favicon/favicon_util.cc
+++ b/chrome/browser/favicon/favicon_util.cc
@@ -43,17 +43,18 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing(
best_candidate = png_data[i].bitmap_data;
}
}
- png_reps.push_back(gfx::ImagePNGRep(best_candidate, 1.0f));
+ png_reps.push_back(gfx::ImagePNGRep(best_candidate,
+ ui::SCALE_FACTOR_100P));
return png_reps;
}
// Cache the scale factor for each pixel size as |scale_factors| may contain
// any of GetFaviconScaleFactors() which may include scale factors not
- // supported by the platform. (ui::GetSupportedScaleFactor() cannot be used.)
+ // supported by the platform. (ui::GetScaleFactorFromScale() cannot be used.)
std::map<int, ui::ScaleFactor> desired_pixel_sizes;
for (size_t i = 0; i < scale_factors.size(); ++i) {
int pixel_size = floor(favicon_size *
- ui::GetImageScale(scale_factors[i]));
+ ui::GetScaleFactorScale(scale_factors[i]));
desired_pixel_sizes[pixel_size] = scale_factors[i];
}
@@ -70,9 +71,7 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing(
if (it == desired_pixel_sizes.end())
continue;
- png_reps.push_back(
- gfx::ImagePNGRep(png_data[i].bitmap_data,
- ui::GetImageScale(it->second)));
+ png_reps.push_back(gfx::ImagePNGRep(png_data[i].bitmap_data, it->second));
}
return png_reps;
@@ -138,7 +137,7 @@ SkBitmap ResizeBitmapByDownsamplingIfPossible(
// static
std::vector<ui::ScaleFactor> FaviconUtil::GetFaviconScaleFactors() {
- const float kScale1x = ui::GetImageScale(ui::SCALE_FACTOR_100P);
+ const float kScale1x = ui::GetScaleFactorScale(ui::SCALE_FACTOR_100P);
std::vector<ui::ScaleFactor> favicon_scale_factors =
ui::GetSupportedScaleFactors();
@@ -147,7 +146,7 @@ std::vector<ui::ScaleFactor> FaviconUtil::GetFaviconScaleFactors() {
// well.
size_t insert_index = favicon_scale_factors.size();
for (size_t i = 0; i < favicon_scale_factors.size(); ++i) {
- float scale = ui::GetImageScale(favicon_scale_factors[i]);
+ float scale = ui::GetScaleFactorScale(favicon_scale_factors[i]);
if (scale == kScale1x) {
return favicon_scale_factors;
} else if (scale > kScale1x) {
@@ -202,7 +201,7 @@ gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs(
std::vector<ui::ScaleFactor>::iterator it = std::find(
scale_factors_to_generate.begin(),
scale_factors_to_generate.end(),
- ui::GetSupportedScaleFactor(png_reps[i].scale));
+ png_reps[i].scale_factor);
CHECK(it != scale_factors_to_generate.end());
scale_factors_to_generate.erase(it);
}
@@ -230,7 +229,7 @@ gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs(
for (size_t i = 0; i < scale_factors_to_generate.size(); ++i) {
ui::ScaleFactor scale_factor = scale_factors_to_generate[i];
int desired_size_in_pixel =
- ceil(favicon_size * ui::GetImageScale(scale_factor));
+ ceil(favicon_size * ui::GetScaleFactorScale(scale_factor));
SkBitmap bitmap = ResizeBitmapByDownsamplingIfPossible(
bitmaps, desired_size_in_pixel);
resized_image_skia.AddRepresentation(
@@ -247,7 +246,7 @@ gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs(
if (gfx::PNGCodec::EncodeBGRASkBitmap(
resized_image_skia_reps[i].sk_bitmap(), false, &png_bytes->data())) {
png_reps.push_back(gfx::ImagePNGRep(png_bytes,
- resized_image_skia_reps[i].scale()));
+ resized_image_skia_reps[i].scale_factor()));
}
}
diff --git a/chrome/browser/history/select_favicon_frames.cc b/chrome/browser/history/select_favicon_frames.cc
index 43a1fa4..09bf8ff 100644
--- a/chrome/browser/history/select_favicon_frames.cc
+++ b/chrome/browser/history/select_favicon_frames.cc
@@ -58,7 +58,7 @@ size_t GetCandidateIndexWithBestScore(
ResizeMethod* resize_method) {
DCHECK_NE(desired_size_in_dip, 0);
- float scale = ui::GetImageScale(scale_factor);
+ float scale = ui::GetScaleFactorScale(scale_factor);
int desired_size_in_pixel =
static_cast<int>(desired_size_in_dip * scale + 0.5f);
@@ -179,7 +179,7 @@ SkBitmap GetResizedBitmap(const SkBitmap& source_bitmap,
int desired_size_in_dip,
ui::ScaleFactor scale_factor,
ResizeMethod resize_method) {
- float scale = ui::GetImageScale(scale_factor);
+ float scale = ui::GetScaleFactorScale(scale_factor);
int desired_size_in_pixel = static_cast<int>(
desired_size_in_dip * scale + 0.5f);
@@ -216,8 +216,7 @@ gfx::ImageSkia SelectFaviconFrames(
SkBitmap resized_bitmap = GetResizedBitmap(bitmaps[result.index],
desired_size, result.scale_factor, result.resize_method);
multi_image.AddRepresentation(
- gfx::ImageSkiaRep(resized_bitmap,
- ui::GetImageScale(result.scale_factor)));
+ gfx::ImageSkiaRep(resized_bitmap, result.scale_factor));
}
return multi_image;
}
diff --git a/chrome/browser/history/select_favicon_frames_unittest.cc b/chrome/browser/history/select_favicon_frames_unittest.cc
index 6936ece..f79e773 100644
--- a/chrome/browser/history/select_favicon_frames_unittest.cc
+++ b/chrome/browser/history/select_favicon_frames_unittest.cc
@@ -43,8 +43,7 @@ SkBitmap MakeBitmap(SkColor color, int w, int h) {
SkColor GetColor(const gfx::ImageSkia& image, ui::ScaleFactor factor,
int x = -1, int y = -1) {
- const SkBitmap& bitmap =
- image.GetRepresentation(ui::GetImageScale(factor)).sk_bitmap();
+ const SkBitmap& bitmap = image.GetRepresentation(factor).sk_bitmap();
if (x == -1)
x = bitmap.width() / 2;
if (y == -1)
@@ -72,7 +71,7 @@ TEST(SelectFaviconFramesTest, ZeroSizePicksLargest) {
gfx::ImageSkia image = SelectFaviconFrames(bitmaps,
SizesFromBitmaps(bitmaps), Scale1x(), 0, NULL);
EXPECT_EQ(1u, image.image_reps().size());
- ASSERT_TRUE(image.HasRepresentation(1.0f));
+ ASSERT_TRUE(image.HasRepresentation(ui::SCALE_FACTOR_100P));
EXPECT_EQ(48, image.width());
EXPECT_EQ(48, image.height());
@@ -88,7 +87,7 @@ TEST(SelectFaviconFramesTest, _16From16) {
gfx::ImageSkia image = SelectFaviconFrames(bitmaps,
SizesFromBitmaps(bitmaps), Scale1x(), 16, NULL);
EXPECT_EQ(1u, image.image_reps().size());
- ASSERT_TRUE(image.HasRepresentation(1.0f));
+ ASSERT_TRUE(image.HasRepresentation(ui::SCALE_FACTOR_100P));
EXPECT_EQ(16, image.width());
EXPECT_EQ(16, image.height());
EXPECT_EQ(SK_ColorGREEN, GetColor1x(image));
@@ -103,7 +102,7 @@ TEST(SelectFaviconFramesTest, _16From17) {
gfx::ImageSkia image = SelectFaviconFrames(bitmaps,
SizesFromBitmaps(bitmaps), Scale1x(), 16, NULL);
EXPECT_EQ(1u, image.image_reps().size());
- ASSERT_TRUE(image.HasRepresentation(1.0f));
+ ASSERT_TRUE(image.HasRepresentation(ui::SCALE_FACTOR_100P));
EXPECT_EQ(16, image.width());
EXPECT_EQ(16, image.height());
EXPECT_EQ(SK_ColorGREEN, GetColor1x(image));
@@ -119,7 +118,7 @@ TEST(SelectFaviconFramesTest, _16From15) {
gfx::ImageSkia image = SelectFaviconFrames(bitmaps,
SizesFromBitmaps(bitmaps), Scale1x(), 16, NULL);
EXPECT_EQ(1u, image.image_reps().size());
- ASSERT_TRUE(image.HasRepresentation(1.0f));
+ ASSERT_TRUE(image.HasRepresentation(ui::SCALE_FACTOR_100P));
EXPECT_EQ(16, image.width());
EXPECT_EQ(16, image.height());
EXPECT_EQ(SK_ColorGREEN, GetColor1x(image));
@@ -132,8 +131,8 @@ TEST(SelectFaviconFramesTest, _16From16_Scale2x_32_From_16) {
gfx::ImageSkia image = SelectFaviconFrames(bitmaps,
SizesFromBitmaps(bitmaps), Scale1x2x(), 16, NULL);
EXPECT_EQ(2u, image.image_reps().size());
- ASSERT_TRUE(image.HasRepresentation(1.0f));
- ASSERT_TRUE(image.HasRepresentation(2.0f));
+ ASSERT_TRUE(image.HasRepresentation(ui::SCALE_FACTOR_100P));
+ ASSERT_TRUE(image.HasRepresentation(ui::SCALE_FACTOR_200P));
EXPECT_EQ(16, image.width());
EXPECT_EQ(16, image.height());
EXPECT_EQ(SK_ColorGREEN, GetColor1x(image));
@@ -148,8 +147,8 @@ TEST(SelectFaviconFramesTest, _16From16_Scale2x_32_From_32) {
gfx::ImageSkia image = SelectFaviconFrames(bitmaps,
SizesFromBitmaps(bitmaps), Scale1x2x(), 16, NULL);
EXPECT_EQ(2u, image.image_reps().size());
- ASSERT_TRUE(image.HasRepresentation(1.0f));
- ASSERT_TRUE(image.HasRepresentation(2.0f));
+ ASSERT_TRUE(image.HasRepresentation(ui::SCALE_FACTOR_100P));
+ ASSERT_TRUE(image.HasRepresentation(ui::SCALE_FACTOR_200P));
EXPECT_EQ(16, image.width());
EXPECT_EQ(16, image.height());
EXPECT_EQ(SK_ColorGREEN, GetColor1x(image));
diff --git a/chrome/browser/profiles/profile_info_util.cc b/chrome/browser/profiles/profile_info_util.cc
index 7601f46..680334c 100644
--- a/chrome/browser/profiles/profile_info_util.cc
+++ b/chrome/browser/profiles/profile_info_util.cc
@@ -23,7 +23,7 @@ gfx::Image GetSizedAvatarIconWithBorder(const gfx::Image& image,
int length = std::min(width, height) - kAvatarIconBorder;
SkBitmap bmp = skia::ImageOperations::Resize(
*image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length);
- gfx::Canvas canvas(gfx::Size(width, height), 1.0f, false);
+ gfx::Canvas canvas(gfx::Size(width, height), ui::SCALE_FACTOR_100P, false);
// Draw the icon centered on the canvas.
int x = (width - length) / 2;
@@ -52,8 +52,8 @@ gfx::Image GetAvatarIconForWebUI(const gfx::Image& image,
std::min(kAvatarIconWidth, kAvatarIconHeight) - kAvatarIconBorder;
SkBitmap bmp = skia::ImageOperations::Resize(
*image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length);
- gfx::Canvas canvas(
- gfx::Size(kAvatarIconWidth, kAvatarIconHeight), 1.0f, false);
+ gfx::Canvas canvas(gfx::Size(kAvatarIconWidth, kAvatarIconHeight),
+ ui::SCALE_FACTOR_100P, false);
// Draw the icon centered on the canvas.
int x = (kAvatarIconWidth - length) / 2;
@@ -74,7 +74,8 @@ gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image,
std::min(dst_width, dst_height)) - kAvatarIconBorder;
SkBitmap bmp = skia::ImageOperations::Resize(
*image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length);
- gfx::Canvas canvas(gfx::Size(dst_width, dst_height), 1.0f, false);
+ gfx::Canvas canvas(gfx::Size(dst_width, dst_height), ui::SCALE_FACTOR_100P,
+ false);
// Draw the icon on the bottom center of the canvas.
int x1 = (dst_width - length) / 2;
@@ -101,4 +102,4 @@ gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image,
return gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep()));
}
-} // namespace profiles
+} // namespace
diff --git a/chrome/browser/speech/speech_recognition_bubble.cc b/chrome/browser/speech/speech_recognition_bubble.cc
index 2b28dd9..e93c4ec 100644
--- a/chrome/browser/speech/speech_recognition_bubble.cc
+++ b/chrome/browser/speech/speech_recognition_bubble.cc
@@ -95,7 +95,7 @@ SpeechRecognitionBubbleImages::SpeechRecognitionBubbleImages() {
// render properly and gets vertically squished in Linux due to a bug in
// Skia. Until that gets fixed we work around by taking a real copy of it
// below as the copied image has the correct rowBytes and renders fine.
- frame.EnsureRepsForSupportedScales();
+ frame.EnsureRepsForSupportedScaleFactors();
std::vector<gfx::ImageSkiaRep> image_reps = frame.image_reps();
gfx::ImageSkia frame_copy;
for (size_t i = 0; i < image_reps.size(); ++i) {
@@ -103,7 +103,7 @@ SpeechRecognitionBubbleImages::SpeechRecognitionBubbleImages() {
SkBitmap copy_dst;
copy_src.copyTo(&copy_dst, SkBitmap::kARGB_8888_Config);
frame_copy.AddRepresentation(gfx::ImageSkiaRep(
- copy_dst, image_reps[i].scale()));
+ copy_dst, image_reps[i].scale_factor()));
}
spinner_.push_back(frame_copy);
@@ -140,15 +140,16 @@ SpeechRecognitionBubbleBase::SpeechRecognitionBubbleBase(
animation_step_(0),
display_mode_(DISPLAY_MODE_RECORDING),
web_contents_(web_contents),
- scale_(1.0f) {
+ scale_factor_(ui::SCALE_FACTOR_NONE) {
gfx::NativeView view =
web_contents_ ? web_contents_->GetView()->GetNativeView() : NULL;
gfx::Screen* screen = gfx::Screen::GetScreenFor(view);
gfx::Display display = screen->GetDisplayNearestWindow(view);
- scale_ = display.device_scale_factor();
+ scale_factor_ = ui::GetScaleFactorFromScale(
+ display.device_scale_factor());
const gfx::ImageSkiaRep& rep =
- g_images.Get().mic_empty()->GetRepresentation(scale_);
+ g_images.Get().mic_empty()->GetRepresentation(scale_factor_);
mic_image_.reset(new SkBitmap());
mic_image_->setConfig(SkBitmap::kARGB_8888_Config,
rep.pixel_width(), rep.pixel_height());
@@ -234,12 +235,13 @@ void SpeechRecognitionBubbleBase::DrawVolumeOverlay(SkCanvas* canvas,
(((1.0f - volume) * (width * (kVolumeSteps + 1))) - width) / kVolumeSteps;
buffer_canvas.clipRect(SkRect::MakeLTRB(0, 0,
SkIntToScalar(width) - clip_right, SkIntToScalar(height)));
- buffer_canvas.drawBitmap(image.GetRepresentation(scale_).sk_bitmap(), 0, 0);
+ buffer_canvas.drawBitmap(
+ image.GetRepresentation(scale_factor_).sk_bitmap(), 0, 0);
buffer_canvas.restore();
SkPaint multiply_paint;
multiply_paint.setXfermodeMode(SkXfermode::kModulate_Mode);
buffer_canvas.drawBitmap(
- g_images.Get().mic_mask()->GetRepresentation(scale_).sk_bitmap(),
+ g_images.Get().mic_mask()->GetRepresentation(scale_factor_).sk_bitmap(),
-clip_right, 0, &multiply_paint);
canvas->drawBitmap(*buffer_image_.get(), 0, 0);
@@ -253,12 +255,12 @@ void SpeechRecognitionBubbleBase::SetInputVolume(float volume,
// Draw the empty volume image first and the current volume image on top,
// and then the noise volume image on top of both.
canvas.drawBitmap(
- g_images.Get().mic_empty()->GetRepresentation(scale_).sk_bitmap(),
+ g_images.Get().mic_empty()->GetRepresentation(scale_factor_).sk_bitmap(),
0, 0);
DrawVolumeOverlay(&canvas, *g_images.Get().mic_full(), volume);
DrawVolumeOverlay(&canvas, *g_images.Get().mic_noise(), noise_volume);
- gfx::ImageSkia image(gfx::ImageSkiaRep(*mic_image_.get(), scale_));
+ gfx::ImageSkia image(gfx::ImageSkiaRep(*mic_image_.get(), scale_factor_));
SetImage(image);
}
diff --git a/chrome/browser/speech/speech_recognition_bubble.h b/chrome/browser/speech/speech_recognition_bubble.h
index 08a741e..2bb911f 100644
--- a/chrome/browser/speech/speech_recognition_bubble.h
+++ b/chrome/browser/speech/speech_recognition_bubble.h
@@ -184,7 +184,7 @@ class SpeechRecognitionBubbleBase : public SpeechRecognitionBubble {
// The current image displayed in the bubble's icon widget.
gfx::ImageSkia icon_image_;
// The scale factor used for the web-contents.
- float scale_;
+ ui::ScaleFactor scale_factor_;
DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleBase);
};
diff --git a/chrome/browser/sync/test/integration/bookmarks_helper.cc b/chrome/browser/sync/test/integration/bookmarks_helper.cc
index 6340788..a59c28c 100644
--- a/chrome/browser/sync/test/integration/bookmarks_helper.cc
+++ b/chrome/browser/sync/test/integration/bookmarks_helper.cc
@@ -292,9 +292,9 @@ bool FaviconsMatch(BookmarkModel* model_a,
// Compare only the 1x bitmaps as only those are synced.
SkBitmap bitmap_a = image_a.AsImageSkia().GetRepresentation(
- 1.0f).sk_bitmap();
+ ui::SCALE_FACTOR_100P).sk_bitmap();
SkBitmap bitmap_b = image_b.AsImageSkia().GetRepresentation(
- 1.0f).sk_bitmap();
+ ui::SCALE_FACTOR_100P).sk_bitmap();
return FaviconBitmapsMatch(bitmap_a, bitmap_b);
}
@@ -714,16 +714,14 @@ gfx::Image CreateFavicon(SkColor color) {
FaviconUtil::GetFaviconScaleFactors();
gfx::ImageSkia favicon;
for (size_t i = 0; i < favicon_scale_factors.size(); ++i) {
- float scale = ui::GetImageScale(favicon_scale_factors[i]);
+ float scale = ui::GetScaleFactorScale(favicon_scale_factors[i]);
int pixel_width = dip_width * scale;
int pixel_height = dip_height * scale;
SkBitmap bmp;
bmp.setConfig(SkBitmap::kARGB_8888_Config, pixel_width, pixel_height);
bmp.allocPixels();
bmp.eraseColor(color);
- favicon.AddRepresentation(
- gfx::ImageSkiaRep(bmp,
- ui::GetImageScale(favicon_scale_factors[i])));
+ favicon.AddRepresentation(gfx::ImageSkiaRep(bmp, favicon_scale_factors[i]));
}
return gfx::Image(favicon);
}
diff --git a/chrome/browser/sync/test/integration/single_client_bookmarks_sync_test.cc b/chrome/browser/sync/test/integration/single_client_bookmarks_sync_test.cc
index 771b1a6..83ca050 100644
--- a/chrome/browser/sync/test/integration/single_client_bookmarks_sync_test.cc
+++ b/chrome/browser/sync/test/integration/single_client_bookmarks_sync_test.cc
@@ -163,7 +163,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
std::vector<ui::ScaleFactor> supported_scale_factors;
supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
- ui::SetSupportedScaleFactors(supported_scale_factors);
+ ui::test::SetSupportedScaleFactors(supported_scale_factors);
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(ModelMatchesVerifier(0));
diff --git a/chrome/browser/sync/test/integration/two_client_bookmarks_sync_test.cc b/chrome/browser/sync/test/integration/two_client_bookmarks_sync_test.cc
index 367f209..171f0f5 100644
--- a/chrome/browser/sync/test/integration/two_client_bookmarks_sync_test.cc
+++ b/chrome/browser/sync/test/integration/two_client_bookmarks_sync_test.cc
@@ -165,7 +165,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_SetFaviconHiDPI) {
std::vector<ui::ScaleFactor> supported_scale_factors;
supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
- ui::SetSupportedScaleFactors(supported_scale_factors);
+ ui::test::SetSupportedScaleFactors(supported_scale_factors);
const GURL page_url(kGenericURL);
const GURL icon_url1("http://www.google.com/favicon1.ico");
diff --git a/chrome/browser/task_manager/browser_process_resource_provider.cc b/chrome/browser/task_manager/browser_process_resource_provider.cc
index 6d898b7..21cec0b 100644
--- a/chrome/browser/task_manager/browser_process_resource_provider.cc
+++ b/chrome/browser/task_manager/browser_process_resource_provider.cc
@@ -40,7 +40,8 @@ BrowserProcessResource::BrowserProcessResource()
HICON icon = GetAppIcon();
if (icon) {
scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon));
- default_icon_ = new gfx::ImageSkia(gfx::ImageSkiaRep(*bitmap, 1.0f));
+ default_icon_ = new gfx::ImageSkia(
+ gfx::ImageSkiaRep(*bitmap, ui::SCALE_FACTOR_100P));
}
}
#elif defined(OS_POSIX) && !defined(OS_MACOSX)
diff --git a/chrome/browser/themes/browser_theme_pack.cc b/chrome/browser/themes/browser_theme_pack.cc
index 6f163af..988450e 100644
--- a/chrome/browser/themes/browser_theme_pack.cc
+++ b/chrome/browser/themes/browser_theme_pack.cc
@@ -245,7 +245,7 @@ bool InputScalesValid(const base::StringPiece& input,
// Do a memcpy to avoid misaligned memory access.
memcpy(scales.get(), input.data(), input.size());
for (size_t index = 0; index < scales_size; ++index) {
- if (scales[index] != ui::GetImageScale(expected[index]))
+ if (scales[index] != ui::GetScaleFactorScale(expected[index]))
return false;
}
return true;
@@ -256,7 +256,7 @@ std::string GetScaleFactorsAsString(
const std::vector<ui::ScaleFactor>& scale_factors) {
scoped_ptr<float[]> scales(new float[scale_factors.size()]);
for (size_t i = 0; i < scale_factors.size(); ++i)
- scales[i] = ui::GetImageScale(scale_factors[i]);
+ scales[i] = ui::GetScaleFactorScale(scale_factors[i]);
std::string out_string = std::string(
reinterpret_cast<const char*>(scales.get()),
scale_factors.size() * sizeof(float));
@@ -452,8 +452,8 @@ SkBitmap CreateLowQualityResizedBitmap(const SkBitmap& source_bitmap,
gfx::Size scaled_size = gfx::ToCeiledSize(
gfx::ScaleSize(gfx::Size(source_bitmap.width(),
source_bitmap.height()),
- ui::GetImageScale(desired_scale_factor) /
- ui::GetImageScale(source_scale_factor)));
+ ui::GetScaleFactorScale(desired_scale_factor) /
+ ui::GetScaleFactorScale(source_scale_factor)));
SkBitmap scaled_bitmap;
scaled_bitmap.setConfig(SkBitmap::kARGB_8888_Config,
scaled_size.width(),
@@ -477,15 +477,17 @@ class ThemeImageSource: public gfx::ImageSkiaSource {
}
virtual ~ThemeImageSource() {}
- virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- if (source_.HasRepresentation(scale))
- return source_.GetRepresentation(scale);
- const gfx::ImageSkiaRep& rep_100p = source_.GetRepresentation(1.0f);
+ virtual gfx::ImageSkiaRep GetImageForScale(
+ ui::ScaleFactor scale_factor) OVERRIDE {
+ if (source_.HasRepresentation(scale_factor))
+ return source_.GetRepresentation(scale_factor);
+ const gfx::ImageSkiaRep& rep_100p =
+ source_.GetRepresentation(ui::SCALE_FACTOR_100P);
SkBitmap scaled_bitmap = CreateLowQualityResizedBitmap(
rep_100p.sk_bitmap(),
ui::SCALE_FACTOR_100P,
- ui::GetSupportedScaleFactor(scale));
- return gfx::ImageSkiaRep(scaled_bitmap, scale);
+ scale_factor);
+ return gfx::ImageSkiaRep(scaled_bitmap, scale_factor);
}
private:
@@ -507,13 +509,13 @@ class ThemeImagePngSource : public gfx::ImageSkiaSource {
virtual ~ThemeImagePngSource() {}
private:
- virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale);
+ virtual gfx::ImageSkiaRep GetImageForScale(
+ ui::ScaleFactor scale_factor) OVERRIDE {
// Look up the bitmap for |scale factor| in the bitmap map. If found
// return it.
BitmapMap::const_iterator exact_bitmap_it = bitmap_map_.find(scale_factor);
if (exact_bitmap_it != bitmap_map_.end())
- return gfx::ImageSkiaRep(exact_bitmap_it->second, scale);
+ return gfx::ImageSkiaRep(exact_bitmap_it->second, scale_factor);
// Look up the raw PNG data for |scale_factor| in the png map. If found,
// decode it, store the result in the bitmap map and return it.
@@ -527,7 +529,7 @@ class ThemeImagePngSource : public gfx::ImageSkiaSource {
return gfx::ImageSkiaRep();
}
bitmap_map_[scale_factor] = bitmap;
- return gfx::ImageSkiaRep(bitmap, scale);
+ return gfx::ImageSkiaRep(bitmap, scale_factor);
}
// Find an available PNG for another scale factor. We want to use the
@@ -536,8 +538,8 @@ class ThemeImagePngSource : public gfx::ImageSkiaSource {
for (PngMap::const_iterator png_it = png_map_.begin();
png_it != png_map_.end(); ++png_it) {
if (available_png_it == png_map_.end() ||
- ui::GetImageScale(png_it->first) >
- ui::GetImageScale(available_png_it->first)) {
+ ui::GetScaleFactorScale(png_it->first) >
+ ui::GetScaleFactorScale(available_png_it->first)) {
available_png_it = png_it;
}
}
@@ -569,7 +571,7 @@ class ThemeImagePngSource : public gfx::ImageSkiaSource {
available_scale_factor,
scale_factor);
bitmap_map_[scale_factor] = scaled_bitmap;
- return gfx::ImageSkiaRep(scaled_bitmap, scale);
+ return gfx::ImageSkiaRep(scaled_bitmap, scale_factor);
}
PngMap png_map_;
@@ -1283,8 +1285,7 @@ bool BrowserThemePack::LoadRawBitmapsTo(
if (gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(),
&bitmap)) {
image_skia.AddRepresentation(
- gfx::ImageSkiaRep(bitmap,
- ui::GetImageScale(scale_factor)));
+ gfx::ImageSkiaRep(bitmap, scale_factor));
} else {
NOTREACHED() << "Unable to decode theme image resource "
<< it->first;
@@ -1472,9 +1473,7 @@ void BrowserThemePack::RepackImages(const ImageCache& images,
NOTREACHED() << "Image file for resource " << it->first
<< " could not be encoded.";
}
- int raw_id = GetRawIDByPersistentID(
- it->first,
- ui::GetSupportedScaleFactor(rep_it->scale()));
+ int raw_id = GetRawIDByPersistentID(it->first, rep_it->scale_factor());
(*reencoded_images)[raw_id] =
base::RefCountedBytes::TakeVector(&bitmap_data);
}
@@ -1534,7 +1533,7 @@ bool BrowserThemePack::GetScaleFactorFromManifestKey(
if (base::StringToInt(key, &percent)) {
float scale = static_cast<float>(percent) / 100.0f;
for (size_t i = 0; i < scale_factors_.size(); ++i) {
- if (fabs(ui::GetImageScale(scale_factors_[i]) - scale) < 0.001) {
+ if (fabs(ui::GetScaleFactorScale(scale_factors_[i]) - scale) < 0.001) {
*scale_factor = scale_factors_[i];
return true;
}
@@ -1571,8 +1570,8 @@ void BrowserThemePack::GenerateRawImageForAllSupportedScales(int prs_id) {
for (size_t i = 0; i < scale_factors_.size(); ++i) {
int raw_id = GetRawIDByPersistentID(prs_id, scale_factors_[i]);
if ((available_scale_factor == ui::SCALE_FACTOR_NONE ||
- (ui::GetImageScale(scale_factors_[i]) >
- ui::GetImageScale(available_scale_factor))) &&
+ (ui::GetScaleFactorScale(scale_factors_[i]) >
+ ui::GetScaleFactorScale(available_scale_factor))) &&
image_memory_.find(raw_id) != image_memory_.end()) {
available_scale_factor = scale_factors_[i];
}
diff --git a/chrome/browser/themes/browser_theme_pack_unittest.cc b/chrome/browser/themes/browser_theme_pack_unittest.cc
index 7d41e55..b2fd658 100644
--- a/chrome/browser/themes/browser_theme_pack_unittest.cc
+++ b/chrome/browser/themes/browser_theme_pack_unittest.cc
@@ -36,13 +36,8 @@ class BrowserThemePackTest : public ::testing::Test {
BrowserThemePackTest()
: message_loop(),
fake_ui_thread(BrowserThread::UI, &message_loop),
- fake_file_thread(BrowserThread::FILE, &message_loop) {
- std::vector<ui::ScaleFactor> scale_factors;
- scale_factors.push_back(ui::SCALE_FACTOR_100P);
- scale_factors.push_back(ui::SCALE_FACTOR_200P);
- scoped_set_supported_scale_factors_.reset(
- new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
- theme_pack_ = new BrowserThemePack();
+ fake_file_thread(BrowserThread::FILE, &message_loop),
+ theme_pack_(new BrowserThemePack) {
}
// Transformation for link underline colors.
@@ -275,7 +270,8 @@ class BrowserThemePackTest : public ::testing::Test {
const gfx::ImageSkia* image_skia = image.ToImageSkia();
ASSERT_TRUE(image_skia);
// Scale 100%.
- const gfx::ImageSkiaRep& rep1 = image_skia->GetRepresentation(1.0f);
+ const gfx::ImageSkiaRep& rep1 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_100P);
ASSERT_FALSE(rep1.is_null());
EXPECT_EQ(80, rep1.sk_bitmap().width());
EXPECT_EQ(80, rep1.sk_bitmap().height());
@@ -287,7 +283,8 @@ class BrowserThemePackTest : public ::testing::Test {
EXPECT_EQ(SkColorSetRGB( 0, 241, 237), rep1.sk_bitmap().getColor(32, 32));
rep1.sk_bitmap().unlockPixels();
// Scale 200%.
- const gfx::ImageSkiaRep& rep2 = image_skia->GetRepresentation(2.0f);
+ const gfx::ImageSkiaRep& rep2 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_200P);
ASSERT_FALSE(rep2.is_null());
EXPECT_EQ(160, rep2.sk_bitmap().width());
EXPECT_EQ(160, rep2.sk_bitmap().height());
@@ -315,7 +312,8 @@ class BrowserThemePackTest : public ::testing::Test {
image_skia = image.ToImageSkia();
ASSERT_TRUE(image_skia);
// Scale 100%.
- const gfx::ImageSkiaRep& rep3 = image_skia->GetRepresentation(1.0f);
+ const gfx::ImageSkiaRep& rep3 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_100P);
ASSERT_FALSE(rep3.is_null());
EXPECT_EQ(80, rep3.sk_bitmap().width());
EXPECT_EQ(80, rep3.sk_bitmap().height());
@@ -337,7 +335,8 @@ class BrowserThemePackTest : public ::testing::Test {
EXPECT_EQ(static_cast<size_t>(9), normal.size());
rep3.sk_bitmap().unlockPixels();
// Scale 200%.
- const gfx::ImageSkiaRep& rep4 = image_skia->GetRepresentation(2.0f);
+ const gfx::ImageSkiaRep& rep4 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_200P);
ASSERT_FALSE(rep4.is_null());
EXPECT_EQ(160, rep4.sk_bitmap().width());
EXPECT_EQ(160, rep4.sk_bitmap().height());
@@ -356,9 +355,6 @@ class BrowserThemePackTest : public ::testing::Test {
content::TestBrowserThread fake_ui_thread;
content::TestBrowserThread fake_file_thread;
- typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors>
- ScopedSetSupportedScaleFactors;
- ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_;
scoped_refptr<BrowserThemePack> theme_pack_;
};
@@ -588,6 +584,10 @@ TEST_F(BrowserThemePackTest, CanBuildAndReadPack) {
}
TEST_F(BrowserThemePackTest, HiDpiThemeTest) {
+ std::vector<ui::ScaleFactor> scale_factors;
+ scale_factors.push_back(ui::SCALE_FACTOR_100P);
+ scale_factors.push_back(ui::SCALE_FACTOR_200P);
+ ui::test::ScopedSetSupportedScaleFactors test_scale_factors(scale_factors);
base::ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
base::FilePath file = dir.path().AppendASCII("theme_data.pak");
diff --git a/chrome/browser/thumbnails/content_analysis_unittest.cc b/chrome/browser/thumbnails/content_analysis_unittest.cc
index a45708d..dc8f2c8 100644
--- a/chrome/browser/thumbnails/content_analysis_unittest.cc
+++ b/chrome/browser/thumbnails/content_analysis_unittest.cc
@@ -78,7 +78,7 @@ class ThumbnailContentAnalysisTest : public testing::Test {
};
TEST_F(ThumbnailContentAnalysisTest, ApplyGradientMagnitudeOnImpulse) {
- gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(800, 600), ui::SCALE_FACTOR_100P, true);
// The image consists of vertical non-overlapping stripes 100 pixels wide.
canvas.FillRect(gfx::Rect(0, 0, 800, 600), SkColorSetARGB(0, 10, 10, 10));
@@ -129,7 +129,7 @@ TEST_F(ThumbnailContentAnalysisTest, ApplyGradientMagnitudeOnImpulse) {
#define MAYBE_ApplyGradientMagnitudeOnFrame ApplyGradientMagnitudeOnFrame
#endif
TEST_F(ThumbnailContentAnalysisTest, MAYBE_ApplyGradientMagnitudeOnFrame) {
- gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(800, 600), ui::SCALE_FACTOR_100P, true);
// The image consists of a single white block in the centre.
gfx::Rect draw_rect(300, 200, 200, 200);
@@ -168,7 +168,7 @@ TEST_F(ThumbnailContentAnalysisTest, MAYBE_ApplyGradientMagnitudeOnFrame) {
}
TEST_F(ThumbnailContentAnalysisTest, ExtractImageProfileInformation) {
- gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(800, 600), ui::SCALE_FACTOR_100P, true);
// The image consists of a white frame drawn in the centre.
gfx::Rect draw_rect(100, 100, 200, 100);
@@ -240,7 +240,7 @@ TEST_F(ThumbnailContentAnalysisTest, ExtractImageProfileInformation) {
#endif
TEST_F(ThumbnailContentAnalysisTest,
MAYBE_ExtractImageProfileInformationWithClosing) {
- gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(800, 600), ui::SCALE_FACTOR_100P, true);
// The image consists of a two white frames drawn side by side, with a
// single-pixel vertical gap in between.
@@ -575,7 +575,7 @@ TEST_F(ThumbnailContentAnalysisTest, ConstrainedProfileSegmentation) {
TEST_F(ThumbnailContentAnalysisTest, ComputeDecimatedImage) {
gfx::Size image_size(1600, 1200);
- gfx::Canvas canvas(image_size, 1.0f, true);
+ gfx::Canvas canvas(image_size, ui::SCALE_FACTOR_100P, true);
// Make some content we will later want to keep.
canvas.FillRect(gfx::Rect(100, 200, 100, 100), SkColorSetARGB(0, 125, 0, 0));
@@ -625,7 +625,7 @@ TEST_F(ThumbnailContentAnalysisTest, ComputeDecimatedImage) {
TEST_F(ThumbnailContentAnalysisTest, CreateRetargetedThumbnailImage) {
gfx::Size image_size(1200, 1300);
- gfx::Canvas canvas(image_size, 1.0f, true);
+ gfx::Canvas canvas(image_size, ui::SCALE_FACTOR_100P, true);
// The following will create a 'fake image' consisting of color blocks placed
// on a neutral background. The entire layout is supposed to mimic a
diff --git a/chrome/browser/thumbnails/content_based_thumbnailing_algorithm_unittest.cc b/chrome/browser/thumbnails/content_based_thumbnailing_algorithm_unittest.cc
index 1e8eae7..07e033f 100644
--- a/chrome/browser/thumbnails/content_based_thumbnailing_algorithm_unittest.cc
+++ b/chrome/browser/thumbnails/content_based_thumbnailing_algorithm_unittest.cc
@@ -134,7 +134,7 @@ TEST_F(ContentBasedThumbnailingAlgorithmTest, CreateRetargetedThumbnail) {
// This tests the invocation of the main thumbnail-making apparatus.
// The actual content is not really of concern here, just check the plumbing.
const gfx::Size image_size(1200, 800);
- gfx::Canvas canvas(image_size, 1.0f, true);
+ gfx::Canvas canvas(image_size, ui::SCALE_FACTOR_100P, true);
// The image consists of vertical non-overlapping stripes 150 pixels wide.
canvas.FillRect(gfx::Rect(200, 200, 800, 400), SkColorSetRGB(255, 255, 255));
diff --git a/chrome/browser/thumbnails/render_widget_snapshot_taker.cc b/chrome/browser/thumbnails/render_widget_snapshot_taker.cc
index f9e2263..da2606c 100644
--- a/chrome/browser/thumbnails/render_widget_snapshot_taker.cc
+++ b/chrome/browser/thumbnails/render_widget_snapshot_taker.cc
@@ -45,7 +45,7 @@ void RenderWidgetSnapshotTaker::AskForSnapshot(
// this callback for later lookup when the rendering is done.
static int sequence_num = 0;
sequence_num++;
- float scale_factor = ui::GetImageScale(ui::GetScaleFactorForNativeView(
+ float scale_factor = ui::GetScaleFactorScale(ui::GetScaleFactorForNativeView(
renderer->GetView()->GetNativeView()));
gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
gfx::ScaleSize(desired_size, scale_factor));
diff --git a/chrome/browser/thumbnails/simple_thumbnail_crop.cc b/chrome/browser/thumbnails/simple_thumbnail_crop.cc
index b2128ef..c427b90 100644
--- a/chrome/browser/thumbnails/simple_thumbnail_crop.cc
+++ b/chrome/browser/thumbnails/simple_thumbnail_crop.cc
@@ -8,7 +8,6 @@
#include "content/public/browser/browser_thread.h"
#include "skia/ext/platform_canvas.h"
#include "ui/gfx/color_utils.h"
-#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/scrollbar_size.h"
#include "ui/gfx/size_conversions.h"
@@ -122,7 +121,7 @@ gfx::Size SimpleThumbnailCrop::GetCopySizeForThumbnail(
switch (scale_factor) {
case ui::SCALE_FACTOR_100P:
copy_size = gfx::ToFlooredSize(gfx::ScaleSize(
- copy_size, ui::GetImageScale(ui::SCALE_FACTOR_200P)));
+ copy_size, ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P)));
break;
case ui::SCALE_FACTOR_200P:
// Use the size as-is.
@@ -131,7 +130,7 @@ gfx::Size SimpleThumbnailCrop::GetCopySizeForThumbnail(
DLOG(WARNING) << "Unsupported scale factor. Use the same copy size as "
<< "ui::SCALE_FACTOR_100P";
copy_size = gfx::ToFlooredSize(gfx::ScaleSize(
- copy_size, gfx::ImageSkia::GetMaxSupportedScale()));
+ copy_size, ui::GetMaxScaleFactor()));
break;
}
return copy_size;
@@ -184,7 +183,8 @@ gfx::Size SimpleThumbnailCrop::ComputeTargetSizeAtMaximumScale(
const gfx::Size& given_size) {
// TODO(mazda|oshima): Update thumbnail when the max scale factor changes.
// crbug.com/159157.
- float max_scale_factor = gfx::ImageSkia::GetMaxSupportedScale();
+ float max_scale_factor =
+ ui::GetScaleFactorScale(ui::GetMaxScaleFactor());
return gfx::ToFlooredSize(gfx::ScaleSize(given_size, max_scale_factor));
}
diff --git a/chrome/browser/thumbnails/simple_thumbnail_crop_unittest.cc b/chrome/browser/thumbnails/simple_thumbnail_crop_unittest.cc
index c00abb2..b0324a4 100644
--- a/chrome/browser/thumbnails/simple_thumbnail_crop_unittest.cc
+++ b/chrome/browser/thumbnails/simple_thumbnail_crop_unittest.cc
@@ -30,7 +30,7 @@ TEST_F(SimpleThumbnailCropTest, CalculateBoringScore_Empty) {
TEST_F(SimpleThumbnailCropTest, CalculateBoringScore_SingleColor) {
const gfx::Size kSize(20, 10);
- gfx::Canvas canvas(kSize, 1.0f, true);
+ gfx::Canvas canvas(kSize, ui::SCALE_FACTOR_100P, true);
// Fill all pixels in black.
canvas.FillRect(gfx::Rect(kSize), SK_ColorBLACK);
@@ -43,7 +43,7 @@ TEST_F(SimpleThumbnailCropTest, CalculateBoringScore_SingleColor) {
TEST_F(SimpleThumbnailCropTest, CalculateBoringScore_TwoColors) {
const gfx::Size kSize(20, 10);
- gfx::Canvas canvas(kSize, 1.0f, true);
+ gfx::Canvas canvas(kSize, ui::SCALE_FACTOR_100P, true);
// Fill all pixels in black.
canvas.FillRect(gfx::Rect(kSize), SK_ColorBLACK);
// Fill the left half pixels in white.
@@ -60,7 +60,7 @@ TEST_F(SimpleThumbnailCropTest, CalculateBoringScore_TwoColors) {
TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_TallerThanWide) {
// The input bitmap is vertically long.
- gfx::Canvas canvas(gfx::Size(40, 90), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(40, 90), ui::SCALE_FACTOR_100P, true);
SkBitmap bitmap =
skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
@@ -77,7 +77,7 @@ TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_TallerThanWide) {
TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_WiderThanTall) {
// The input bitmap is horizontally long.
- gfx::Canvas canvas(gfx::Size(70, 40), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(70, 40), ui::SCALE_FACTOR_100P, true);
SkBitmap bitmap =
skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
@@ -94,7 +94,7 @@ TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_WiderThanTall) {
TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_TooWiderThanTall) {
// The input bitmap is horizontally very long.
- gfx::Canvas canvas(gfx::Size(90, 40), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(90, 40), ui::SCALE_FACTOR_100P, true);
SkBitmap bitmap =
skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
@@ -111,7 +111,7 @@ TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_TooWiderThanTall) {
TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_NotClipped) {
// The input bitmap is square.
- gfx::Canvas canvas(gfx::Size(40, 40), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(40, 40), ui::SCALE_FACTOR_100P, true);
SkBitmap bitmap =
skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
@@ -128,7 +128,7 @@ TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_NotClipped) {
TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_NonSquareOutput) {
// The input bitmap is square.
- gfx::Canvas canvas(gfx::Size(40, 40), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(40, 40), ui::SCALE_FACTOR_100P, true);
SkBitmap bitmap =
skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
diff --git a/chrome/browser/ui/app_list/search/common/url_icon_source.cc b/chrome/browser/ui/app_list/search/common/url_icon_source.cc
index acb2d28..443da12 100644
--- a/chrome/browser/ui/app_list/search/common/url_icon_source.cc
+++ b/chrome/browser/ui/app_list/search/common/url_icon_source.cc
@@ -47,15 +47,17 @@ void UrlIconSource::StartIconFetch() {
icon_fetcher_->Start();
}
-gfx::ImageSkiaRep UrlIconSource::GetImageForScale(float scale) {
+gfx::ImageSkiaRep UrlIconSource::GetImageForScale(
+ ui::ScaleFactor scale_factor) {
if (!icon_fetch_attempted_)
StartIconFetch();
if (!icon_.isNull())
- return icon_.GetRepresentation(scale);
+ return icon_.GetRepresentation(scale_factor);
return ui::ResourceBundle::GetSharedInstance()
- .GetImageSkiaNamed(default_icon_resource_id_)->GetRepresentation(scale);
+ .GetImageSkiaNamed(default_icon_resource_id_)->GetRepresentation(
+ scale_factor);
}
void UrlIconSource::OnURLFetchComplete(
diff --git a/chrome/browser/ui/app_list/search/common/url_icon_source.h b/chrome/browser/ui/app_list/search/common/url_icon_source.h
index 32465e8..de94f28 100644
--- a/chrome/browser/ui/app_list/search/common/url_icon_source.h
+++ b/chrome/browser/ui/app_list/search/common/url_icon_source.h
@@ -45,7 +45,8 @@ class UrlIconSource : public gfx::ImageSkiaSource,
void StartIconFetch();
// gfx::ImageSkiaSource overrides:
- virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE;
+ virtual gfx::ImageSkiaRep GetImageForScale(
+ ui::ScaleFactor scale_factor) OVERRIDE;
// net::URLFetcherDelegate overrides:
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
diff --git a/chrome/browser/ui/app_list/search/people/people_result.cc b/chrome/browser/ui/app_list/search/people/people_result.cc
index 72136b0..6d0990e 100644
--- a/chrome/browser/ui/app_list/search/people/people_result.cc
+++ b/chrome/browser/ui/app_list/search/people/people_result.cc
@@ -84,7 +84,7 @@ void PeopleResult::OnIconLoaded() {
// need to be re-created.
const std::vector<gfx::ImageSkiaRep>& image_reps = image_.image_reps();
for (size_t i = 0; i < image_reps.size(); ++i)
- image_.RemoveRepresentation(image_reps[i].scale());
+ image_.RemoveRepresentation(image_reps[i].scale_factor());
SetIcon(image_);
}
diff --git a/chrome/browser/ui/app_list/search/webstore/webstore_result.cc b/chrome/browser/ui/app_list/search/webstore/webstore_result.cc
index 56c4a2d..27310c2 100644
--- a/chrome/browser/ui/app_list/search/webstore/webstore_result.cc
+++ b/chrome/browser/ui/app_list/search/webstore/webstore_result.cc
@@ -147,7 +147,7 @@ void WebstoreResult::OnIconLoaded() {
// need to be re-created.
const std::vector<gfx::ImageSkiaRep>& image_reps = icon_.image_reps();
for (size_t i = 0; i < image_reps.size(); ++i)
- icon_.RemoveRepresentation(image_reps[i].scale());
+ icon_.RemoveRepresentation(image_reps[i].scale_factor());
icon_ = gfx::ImageSkia(new BadgedIconSource(icon_),
gfx::Size(kIconSize, kIconSize));
diff --git a/chrome/browser/ui/ash/launcher/launcher_item_controller.h b/chrome/browser/ui/ash/launcher/launcher_item_controller.h
index e035aa5..1ab1f66 100644
--- a/chrome/browser/ui/ash/launcher/launcher_item_controller.h
+++ b/chrome/browser/ui/ash/launcher/launcher_item_controller.h
@@ -10,7 +10,6 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_vector.h"
#include "base/strings/string16.h"
-#include "ui/events/event.h"
class ChromeLauncherController;
class ChromeLauncherAppMenuItem;
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
index 4510688..f6c08287 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -469,7 +469,7 @@ gfx::Image GetGeneratedCardImage(const base::string16& card_number,
const int kCardWidthPx = 300;
const int kCardHeightPx = 190;
const gfx::Size size(kCardWidthPx, kCardHeightPx);
- gfx::Canvas canvas(size, 1.0f, false);
+ gfx::Canvas canvas(size, ui::SCALE_FACTOR_100P, false);
gfx::Rect display_rect(size);
diff --git a/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm
index b27a21a..2df80ef 100644
--- a/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm
+++ b/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm
@@ -109,7 +109,7 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver {
scoped_ptr<gfx::Canvas> canvas(
new gfx::Canvas(
gfx::Size(image_size + kDropArrowLeftMarginPx + drop_image->width(),
- image_size), 1.0f, false));
+ image_size), ui::SCALE_FACTOR_100P, false));
canvas->DrawImageInt(*icon,
0, 0, icon->width(), icon->height(),
0, 0, image_size, image_size,
diff --git a/chrome/browser/ui/cocoa/panels/panel_stack_window_cocoa.mm b/chrome/browser/ui/cocoa/panels/panel_stack_window_cocoa.mm
index a4601eb..90ba6e0 100644
--- a/chrome/browser/ui/cocoa/panels/panel_stack_window_cocoa.mm
+++ b/chrome/browser/ui/cocoa/panels/panel_stack_window_cocoa.mm
@@ -293,7 +293,7 @@ void PanelStackWindowCocoa::Minimize() {
// Provide the custom miniwindow image since there is nothing painted for
// the background stack window.
gfx::Size stack_window_size = GetStackWindowBounds().size();
- gfx::Canvas canvas(stack_window_size, 1.0f, true);
+ gfx::Canvas canvas(stack_window_size, ui::SCALE_FACTOR_100P, true);
int y = 0;
Panels::const_iterator iter = panels_.begin();
for (; iter != panels_.end(); ++iter) {
diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
index 1a15f6f..95f2e54 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
@@ -164,7 +164,7 @@ NSImage* CreateImageWithSize(NSSize size,
base::scoped_nsobject<NSImage> result([[NSImage alloc] initWithSize:size]);
[NSGraphicsContext saveGraphicsState];
for (ui::ScaleFactor scale_factor : ui::GetSupportedScaleFactors()) {
- float scale = GetImageScale(scale_factor);
+ float scale = GetScaleFactorScale(scale_factor);
NSBitmapImageRep *bmpImageRep = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:size.width * scale
diff --git a/chrome/browser/ui/gtk/avatar_menu_item_gtk.cc b/chrome/browser/ui/gtk/avatar_menu_item_gtk.cc
index f5b8bc1..b708d03 100644
--- a/chrome/browser/ui/gtk/avatar_menu_item_gtk.cc
+++ b/chrome/browser/ui/gtk/avatar_menu_item_gtk.cc
@@ -201,7 +201,8 @@ void AvatarMenuItemGtk::Init(GtkThemeService* theme_service) {
// of the profile icon.
if (item_.active) {
const SkBitmap* avatar_image = item_.icon.ToSkBitmap();
- gfx::ImageSkiaRep avatar_image_rep = gfx::ImageSkiaRep(*avatar_image, 1.0f);
+ gfx::ImageSkiaRep avatar_image_rep =
+ gfx::ImageSkiaRep(*avatar_image, ui::SCALE_FACTOR_100P);
gfx::Canvas canvas(avatar_image_rep, /* is_opaque */ true);
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
diff --git a/chrome/browser/ui/gtk/gtk_theme_service.cc b/chrome/browser/ui/gtk/gtk_theme_service.cc
index a4d3562..97e0ec5 100644
--- a/chrome/browser/ui/gtk/gtk_theme_service.cc
+++ b/chrome/browser/ui/gtk/gtk_theme_service.cc
@@ -1040,7 +1040,7 @@ SkBitmap GtkThemeService::GenerateFrameImage(
SkColor base = it->second;
gfx::Canvas canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight),
- 1.0f, true);
+ ui::SCALE_FACTOR_100P, true);
int gradient_size;
GdkColor* gradient_top_color = NULL;
diff --git a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc
index 0575aea..c12d975c 100644
--- a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc
+++ b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc
@@ -171,7 +171,7 @@ void ExtensionInfoBarGtk::OnImageLoaded(const gfx::Image& image) {
static const int kDropArrowLeftMargin = 3;
scoped_ptr<gfx::Canvas> canvas(new gfx::Canvas(
gfx::Size(image_size + kDropArrowLeftMargin + drop_image->width(),
- image_size), 1.0f, false));
+ image_size), ui::SCALE_FACTOR_100P, false));
canvas->DrawImageInt(*icon, 0, 0, icon->width(), icon->height(), 0, 0,
image_size, image_size, false);
canvas->DrawImageInt(*drop_image, image_size + kDropArrowLeftMargin,
diff --git a/chrome/browser/ui/gtk/panels/panel_gtk.cc b/chrome/browser/ui/gtk/panels/panel_gtk.cc
index c45b6ea..54b0c3b 100644
--- a/chrome/browser/ui/gtk/panels/panel_gtk.cc
+++ b/chrome/browser/ui/gtk/panels/panel_gtk.cc
@@ -144,7 +144,7 @@ const AcceleratorMap& GetAcceleratorTable() {
}
gfx::Image CreateImageForColor(SkColor color) {
- gfx::Canvas canvas(gfx::Size(1, 1), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(1, 1), ui::SCALE_FACTOR_100P, true);
canvas.DrawColor(color);
return gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep()));
}
diff --git a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
index 4a6ce2d..5c66d9d 100644
--- a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
+++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
@@ -868,7 +868,7 @@ SkBitmap Gtk2UI::GenerateFrameImage(
SkColor base = it->second;
gfx::Canvas canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight),
- 1.0f, true);
+ ui::SCALE_FACTOR_100P, true);
int gradient_size;
GdkColor* gradient_top_color = NULL;
diff --git a/chrome/browser/ui/metro_pin_tab_helper_win.cc b/chrome/browser/ui/metro_pin_tab_helper_win.cc
index 58255d7..064bccf 100644
--- a/chrome/browser/ui/metro_pin_tab_helper_win.cc
+++ b/chrome/browser/ui/metro_pin_tab_helper_win.cc
@@ -85,7 +85,7 @@ bool CreateSiteSpecificLogo(const SkBitmap& bitmap,
SkColor dominant_color = color_utils::CalculateKMeanColorOfBitmap(bitmap);
SkPaint paint;
paint.setColor(dominant_color);
- gfx::Canvas canvas(gfx::Size(kLogoWidth, kLogoHeight), 1.0f,
+ gfx::Canvas canvas(gfx::Size(kLogoWidth, kLogoHeight), ui::SCALE_FACTOR_100P,
true);
canvas.DrawRect(gfx::Rect(0, 0, kLogoWidth, kLogoHeight), paint);
@@ -381,7 +381,7 @@ void MetroPinTabHelper::TogglePinnedToStartScreen() {
if (favicon_tab_helper->FaviconIsValid()) {
// Only the 1x bitmap data is needed.
favicon = favicon_tab_helper->GetFavicon().AsImageSkia().GetRepresentation(
- 1.0f).sk_bitmap();
+ ui::SCALE_FACTOR_100P).sk_bitmap();
}
favicon_chooser_.reset(new FaviconChooser(this, title, url_str, favicon));
diff --git a/chrome/browser/ui/toolbar/wrench_icon_painter_unittest.cc b/chrome/browser/ui/toolbar/wrench_icon_painter_unittest.cc
index f513aaa..43b30f9 100644
--- a/chrome/browser/ui/toolbar/wrench_icon_painter_unittest.cc
+++ b/chrome/browser/ui/toolbar/wrench_icon_painter_unittest.cc
@@ -37,7 +37,7 @@ class WrenchIconPainterTest : public testing::Test,
// leaks or crashes.
TEST_F(WrenchIconPainterTest, Paint) {
gfx::Rect rect(0, 0, 29, 29);
- gfx::Canvas canvas(rect.size(), 1.0f, true);
+ gfx::Canvas canvas(rect.size(), ui::SCALE_FACTOR_100P, true);
painter_.Paint(&canvas, theme_provider_, rect, WrenchIconPainter::BEZEL_NONE);
painter_.Paint(
diff --git a/chrome/browser/ui/views/dropdown_bar_view.cc b/chrome/browser/ui/views/dropdown_bar_view.cc
index 235bbef..eece8aa 100644
--- a/chrome/browser/ui/views/dropdown_bar_view.cc
+++ b/chrome/browser/ui/views/dropdown_bar_view.cc
@@ -112,7 +112,7 @@ void DropdownBarView::OnPaint(gfx::Canvas* canvas) {
if (animation_offset() > 0) {
gfx::Canvas animating_edges(
gfx::Size(bounds().width(), kAnimatingEdgeHeight),
- canvas->image_scale(),
+ canvas->scale_factor(),
false);
canvas->Translate(bounds().OffsetFromOrigin());
OnPaintBackground(&animating_edges);
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index e216446..58d24c7 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -209,7 +209,7 @@ void PaintDetachedBookmarkBar(gfx::Canvas* canvas,
// Calculate thickness of bottom border as per current scale factor to
// determine where to draw the 1-px thick border.
float thickness = views::NonClientFrameView::kClientEdgeThickness /
- canvas->image_scale();
+ ui::GetScaleFactorScale(canvas->scale_factor());
SkScalar y = SkIntToScalar(view->height()) - SkFloatToScalar(thickness);
canvas->sk_canvas()->drawLine(SkIntToScalar(0), y,
SkIntToScalar(view->width()), y, paint);
diff --git a/chrome/browser/ui/views/frame/opaque_browser_frame_view_layout_unittest.cc b/chrome/browser/ui/views/frame/opaque_browser_frame_view_layout_unittest.cc
index 5962fb0..2916c5f 100644
--- a/chrome/browser/ui/views/frame/opaque_browser_frame_view_layout_unittest.cc
+++ b/chrome/browser/ui/views/frame/opaque_browser_frame_view_layout_unittest.cc
@@ -84,7 +84,7 @@ class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate {
// The calculations depend on the size of the OTR resource, and chromeos
// uses a different sized image, so hard code the size of the current
// windows/linux one.
- gfx::ImageSkiaRep rep(gfx::Size(40, 29), 1.0f);
+ gfx::ImageSkiaRep rep(gfx::Size(40, 29), ui::SCALE_FACTOR_100P);
gfx::ImageSkia image(rep);
return image;
}
@@ -173,7 +173,7 @@ class OpaqueBrowserFrameViewLayoutTest : public views::ViewsTestBase {
views::ImageButton* InitWindowCaptionButton(ViewID view_id,
const gfx::Size& size) {
views::ImageButton* button = new views::ImageButton(NULL);
- gfx::ImageSkiaRep rep(size, 1.0f);
+ gfx::ImageSkiaRep rep(size, ui::SCALE_FACTOR_100P);
gfx::ImageSkia image(rep);
button->SetImage(views::CustomButton::STATE_NORMAL, &image);
button->set_id(view_id);
diff --git a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc
index 6734411..9e38e7a 100644
--- a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc
+++ b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc
@@ -65,7 +65,8 @@ ContentSettingImageView::ContentSettingImageView(
// sit atop.
const SkBitmap& bitmap(
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- kBackgroundImages[4])->GetRepresentation(1.0f).sk_bitmap());
+ kBackgroundImages[4])->GetRepresentation(
+ ui::SCALE_FACTOR_100P).sk_bitmap());
SkAutoLockPixels pixel_lock(bitmap);
SkColor background_image_color =
bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2);
diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
index f279f24..6a49136 100644
--- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
+++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
@@ -54,7 +54,8 @@ IconLabelBubbleView::IconLabelBubbleView(const int background_images[],
// sit atop.
const SkBitmap& bitmap(
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- background_images[4])->GetRepresentation(1.0f).sk_bitmap());
+ background_images[4])->GetRepresentation(
+ ui::SCALE_FACTOR_100P).sk_bitmap());
SkAutoLockPixels pixel_lock(bitmap);
SkColor background_image_color =
bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2);
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc
index e2c98ce..43bf0c7 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc
@@ -2514,7 +2514,7 @@ void OmniboxViewWin::DrawSlashForInsecureScheme(HDC hdc,
// it to fully transparent so any antialiasing will look nice when painted
// atop the edit.
gfx::Canvas canvas(gfx::Size(scheme_rect.Width(), scheme_rect.Height()),
- 1.0f, false);
+ ui::SCALE_FACTOR_100P, false);
SkCanvas* sk_canvas = canvas.sk_canvas();
sk_canvas->getDevice()->accessBitmap(true).eraseARGB(0, 0, 0, 0);
diff --git a/chrome/browser/ui/views/panels/panel_frame_view.cc b/chrome/browser/ui/views/panels/panel_frame_view.cc
index 7b9ed29..5359e72 100644
--- a/chrome/browser/ui/views/panels/panel_frame_view.cc
+++ b/chrome/browser/ui/views/panels/panel_frame_view.cc
@@ -64,7 +64,7 @@ const SkColor kMinimizeBorderDefaultColor = SkColorSetRGB(0xc9, 0xc9, 0xc9);
const SkColor kTitleTextDefaultColor = SkColorSetRGB(0xf9, 0xf9, 0xf9);
gfx::ImageSkia* CreateImageForColor(SkColor color) {
- gfx::Canvas canvas(gfx::Size(1, 1), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(1, 1), ui::SCALE_FACTOR_100P, true);
canvas.DrawColor(color);
return new gfx::ImageSkia(canvas.ExtractImageRep());
}
diff --git a/chrome/browser/ui/views/panels/taskbar_window_thumbnailer_win.cc b/chrome/browser/ui/views/panels/taskbar_window_thumbnailer_win.cc
index 29c2a5f..e6946bb 100644
--- a/chrome/browser/ui/views/panels/taskbar_window_thumbnailer_win.cc
+++ b/chrome/browser/ui/views/panels/taskbar_window_thumbnailer_win.cc
@@ -188,7 +188,7 @@ SkBitmap* TaskbarWindowThumbnailerWin::CaptureWindowImage() const {
if (!width || !height)
return NULL;
- gfx::Canvas canvas(gfx::Size(width, height), 1.0f, false);
+ gfx::Canvas canvas(gfx::Size(width, height), ui::SCALE_FACTOR_100P, false);
{
skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas());
HDC target_dc = scoped_platform_paint.GetPlatformSurface();
diff --git a/chrome/browser/ui/views/tab_icon_view.cc b/chrome/browser/ui/views/tab_icon_view.cc
index ab13cd6..433e36f 100644
--- a/chrome/browser/ui/views/tab_icon_view.cc
+++ b/chrome/browser/ui/views/tab_icon_view.cc
@@ -39,7 +39,8 @@ void TabIconView::InitializeIfNeeded() {
HICON app_icon = GetAppIcon();
scoped_ptr<SkBitmap> bitmap(
IconUtil::CreateSkBitmapFromHICON(app_icon, gfx::Size(16, 16)));
- g_default_favicon = new gfx::ImageSkia(gfx::ImageSkiaRep(*bitmap, 1.0f));
+ g_default_favicon = new gfx::ImageSkia(
+ gfx::ImageSkiaRep(*bitmap, ui::SCALE_FACTOR_100P));
DestroyIcon(app_icon);
#else
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
diff --git a/chrome/browser/ui/views/tabs/dragged_tab_view.cc b/chrome/browser/ui/views/tabs/dragged_tab_view.cc
index d7b8cf8..bb3b8a6 100644
--- a/chrome/browser/ui/views/tabs/dragged_tab_view.cc
+++ b/chrome/browser/ui/views/tabs/dragged_tab_view.cc
@@ -138,7 +138,7 @@ gfx::Size DraggedTabView::GetPreferredSize() {
void DraggedTabView::PaintDetachedView(gfx::Canvas* canvas) {
gfx::Size ps = GetPreferredSize();
// TODO(pkotwicz): DIP enable this class.
- gfx::Canvas scale_canvas(ps, 1.0f, false);
+ gfx::Canvas scale_canvas(ps, ui::SCALE_FACTOR_100P, false);
SkBitmap& bitmap_device = const_cast<SkBitmap&>(
skia::GetTopDevice(*scale_canvas.sk_canvas())->accessBitmap(true));
bitmap_device.eraseARGB(0, 0, 0, 0);
diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc
index 23590ae..2492f4e 100644
--- a/chrome/browser/ui/views/tabs/tab.cc
+++ b/chrome/browser/ui/views/tabs/tab.cc
@@ -1202,13 +1202,13 @@ void Tab::PaintInactiveTabBackgroundWithTitleChange(
gfx::Canvas* canvas,
gfx::MultiAnimation* animation) {
// Render the inactive tab background. We'll use this for clipping.
- gfx::Canvas background_canvas(size(), canvas->image_scale(), false);
+ gfx::Canvas background_canvas(size(), canvas->scale_factor(), false);
PaintInactiveTabBackground(&background_canvas);
gfx::ImageSkia background_image(background_canvas.ExtractImageRep());
// Draw a radial gradient to hover_canvas.
- gfx::Canvas hover_canvas(size(), canvas->image_scale(), false);
+ gfx::Canvas hover_canvas(size(), canvas->scale_factor(), false);
int radius = kMiniTitleChangeGradientRadius;
int x0 = width() + radius - kMiniTitleChangeInitialXOffset;
int x1 = radius;
@@ -1271,14 +1271,13 @@ void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas) {
!hover_controller_.ShouldDraw();
if (can_cache) {
- ui::ScaleFactor scale_factor =
- ui::GetSupportedScaleFactor(canvas->image_scale());
- gfx::ImageSkia cached_image(GetCachedImage(tab_id, size(), scale_factor));
+ gfx::ImageSkia cached_image(
+ GetCachedImage(tab_id, size(), canvas->scale_factor()));
if (cached_image.width() == 0) {
- gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false);
+ gfx::Canvas tmp_canvas(size(), canvas->scale_factor(), false);
PaintInactiveTabBackgroundUsingResourceId(&tmp_canvas, tab_id);
cached_image = gfx::ImageSkia(tmp_canvas.ExtractImageRep());
- SetCachedImage(tab_id, scale_factor, cached_image);
+ SetCachedImage(tab_id, canvas->scale_factor(), cached_image);
}
canvas->DrawImageInt(cached_image, 0, 0);
} else {
@@ -1311,7 +1310,7 @@ void Tab::PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas,
// We need a gfx::Canvas object to be able to extract the image from.
// We draw everything to this canvas and then output it to the canvas
// parameter in addition to using it to mask the hover glow if needed.
- gfx::Canvas background_canvas(size(), canvas->image_scale(), false);
+ gfx::Canvas background_canvas(size(), canvas->scale_factor(), false);
// Draw left edge. Don't draw over the toolbar, as we're not the foreground
// tab.
diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc
index 42cb522..17e1579 100644
--- a/chrome/browser/ui/views/tabs/tab_strip.cc
+++ b/chrome/browser/ui/views/tabs/tab_strip.cc
@@ -393,8 +393,7 @@ void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) {
#endif
void NewTabButton::OnPaint(gfx::Canvas* canvas) {
- gfx::ImageSkia image =
- GetImageForScale(ui::GetSupportedScaleFactor(canvas->image_scale()));
+ gfx::ImageSkia image = GetImageForScale(canvas->scale_factor());
canvas->DrawImageInt(image, 0, height() - image.height());
}
@@ -444,12 +443,12 @@ gfx::ImageSkia NewTabButton::GetBackgroundImage(
GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK);
int height = mask->height();
int width = mask->width();
- float scale = ui::GetImageScale(scale_factor);
+
// The canvas and mask has to use the same scale factor.
- if (!mask->HasRepresentation(scale))
+ if (!mask->HasRepresentation(scale_factor))
scale_factor = ui::SCALE_FACTOR_100P;
- gfx::Canvas canvas(gfx::Size(width, height), scale, false);
+ gfx::Canvas canvas(gfx::Size(width, height), scale_factor, false);
// For custom images the background starts at the top of the tab strip.
// Otherwise the background starts at the top of the frame.
@@ -495,9 +494,7 @@ gfx::ImageSkia NewTabButton::GetImageForState(
gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id);
gfx::Canvas canvas(
- gfx::Size(overlay->width(), overlay->height()),
- ui::GetImageScale(scale_factor),
- false);
+ gfx::Size(overlay->width(), overlay->height()), scale_factor, false);
canvas.DrawImageInt(GetBackgroundImage(state, scale_factor), 0, 0);
// Draw the button border with a slight alpha.
diff --git a/chrome/browser/ui/web_applications/web_app_ui.cc b/chrome/browser/ui/web_applications/web_app_ui.cc
index 2e7b6c4..4834b3f 100644
--- a/chrome/browser/ui/web_applications/web_app_ui.cc
+++ b/chrome/browser/ui/web_applications/web_app_ui.cc
@@ -364,7 +364,7 @@ void OnImageLoaded(ShellIntegration::ShortcutInfo shortcut_info,
// the icons, hackily put into a single ImageSkia. Separate them out into
// individual ImageSkias and insert them into the icon family.
const gfx::ImageSkia& multires_image_skia = image.AsImageSkia();
- // NOTE: We do not call ImageSkia::EnsureRepsForSupportedScales here.
+ // NOTE: We do not call ImageSkia::EnsureRepsForSupportedScaleFactors here.
// The image reps here are not really for different scale factors (ImageSkia
// is just being used as a handy container for multiple images).
std::vector<gfx::ImageSkiaRep> image_reps =
diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
index 4003e73..e7257aa 100644
--- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
+++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
@@ -548,7 +548,7 @@ void ChromeWebUIControllerFactory::GetFaviconForURL(
// Assume that |bitmap| is |gfx::kFaviconSize| x |gfx::kFaviconSize|
// DIP.
- float scale = ui::GetImageScale(scale_factors[i]);
+ float scale = ui::GetScaleFactorScale(scale_factors[i]);
int edge_pixel_size =
static_cast<int>(gfx::kFaviconSize * scale + 0.5f);
bitmap_result.pixel_size = gfx::Size(edge_pixel_size, edge_pixel_size);
diff --git a/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc b/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc
index b220e31..57af9b5 100644
--- a/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc
+++ b/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc
@@ -90,8 +90,7 @@ base::ListValue* NetworkMenuWebUI::ConvertMenuModel(ui::MenuModel* model) {
gfx::Image icon;
if (model->GetIconAt(i, &icon)) {
SkBitmap icon_bitmap = icon.ToImageSkia()->GetRepresentation(
- ui::GetImageScale(
- web_ui_->GetDeviceScaleFactor())).sk_bitmap();
+ web_ui_->GetDeviceScaleFactor()).sk_bitmap();
item->SetString("icon", webui::GetBitmapDataUrl(icon_bitmap));
}
if (id >= 0) {
@@ -193,7 +192,7 @@ void NetworkDropdown::SetNetworkIconAndText() {
RemoveObserver(this);
}
SkBitmap icon_bitmap = icon_image.GetRepresentation(
- ui::GetImageScale(web_ui_->GetDeviceScaleFactor())).sk_bitmap();
+ web_ui_->GetDeviceScaleFactor()).sk_bitmap();
std::string icon_str;
if (!icon_image.isNull())
icon_str = webui::GetBitmapDataUrl(icon_bitmap);
diff --git a/chrome/browser/ui/webui/fileicon_source.cc b/chrome/browser/ui/webui/fileicon_source.cc
index 1705c41..ee0cb11 100644
--- a/chrome/browser/ui/webui/fileicon_source.cc
+++ b/chrome/browser/ui/webui/fileicon_source.cc
@@ -103,8 +103,7 @@ void FileIconSource::FetchFileIcon(
if (icon) {
scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes);
gfx::PNGCodec::EncodeBGRASkBitmap(
- icon->ToImageSkia()->GetRepresentation(
- ui::GetImageScale(scale_factor)).sk_bitmap(),
+ icon->ToImageSkia()->GetRepresentation(scale_factor).sk_bitmap(),
false, &icon_data->data());
callback.Run(icon_data.get());
@@ -151,8 +150,8 @@ void FileIconSource::OnFileIconDataAvailable(const IconRequestDetails& details,
if (icon) {
scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes);
gfx::PNGCodec::EncodeBGRASkBitmap(
- icon->ToImageSkia()->GetRepresentation(
- ui::GetImageScale(details.scale_factor)).sk_bitmap(),
+ icon->ToImageSkia()->GetRepresentation(details.scale_factor)
+ .sk_bitmap(),
false,
&icon_data->data());
diff --git a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc
index dbe8373..db212ec 100644
--- a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc
+++ b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc
@@ -58,7 +58,8 @@ SkBitmap GetGAIAPictureForNTP(const gfx::Image& image) {
SkBitmap bmp = skia::ImageOperations::Resize(*image.ToSkBitmap(),
skia::ImageOperations::RESIZE_BEST, kLength, kLength);
- gfx::Canvas canvas(gfx::Size(kLength, kLength), 1.0f, false);
+ gfx::Canvas canvas(gfx::Size(kLength, kLength), ui::SCALE_FACTOR_100P,
+ false);
canvas.DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(bmp), 0, 0);
// Draw a gray border on the inside of the icon.
diff --git a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
index 218d24a..bc82a94 100644
--- a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
@@ -416,8 +416,7 @@ void SetCommonNetworkInfo(const ManagedState* state,
const gfx::ImageSkia& icon,
ui::ScaleFactor icon_scale_factor,
base::DictionaryValue* network_info) {
- gfx::ImageSkiaRep image_rep =
- icon.GetRepresentation(ui::GetImageScale(icon_scale_factor));
+ gfx::ImageSkiaRep image_rep = icon.GetRepresentation(icon_scale_factor);
std::string icon_url =
icon.isNull() ? "" : webui::GetBitmapDataUrl(image_rep.sk_bitmap());
network_info->SetString(kNetworkInfoKeyIconURL, icon_url);
@@ -1218,7 +1217,7 @@ std::string InternetOptionsHandler::GetIconDataUrl(int resource_id) const {
gfx::ImageSkia* icon =
ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
gfx::ImageSkiaRep image_rep = icon->GetRepresentation(
- ui::GetImageScale(web_ui()->GetDeviceScaleFactor()));
+ web_ui()->GetDeviceScaleFactor());
return webui::GetBitmapDataUrl(image_rep.sk_bitmap());
}
diff --git a/chrome/common/badge_util.cc b/chrome/common/badge_util.cc
index a762a6f..ccbaca1 100644
--- a/chrome/common/badge_util.cc
+++ b/chrome/common/badge_util.cc
@@ -124,7 +124,7 @@ SkBitmap DrawBadgeIconOverlay(const SkBitmap& icon,
// Render the badge bitmap and overlay into a canvas.
scoped_ptr<gfx::Canvas> canvas(new gfx::Canvas(
- gfx::Size(badge_width, icon.height()), 1.0f, false));
+ gfx::Size(badge_width, icon.height()), ui::SCALE_FACTOR_100P, false));
canvas->DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(icon), 0, 0);
// Draw the text overlay centered horizontally and vertically. Skia expects
diff --git a/chrome/common/icon_with_badge_image_source.cc b/chrome/common/icon_with_badge_image_source.cc
index 007292c..1665030 100644
--- a/chrome/common/icon_with_badge_image_source.cc
+++ b/chrome/common/icon_with_badge_image_source.cc
@@ -5,7 +5,6 @@
#include "chrome/common/icon_with_badge_image_source.h"
#include "chrome/common/badge_util.h"
-//#include "ui/base/layout.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/rect.h"
diff --git a/chrome/renderer/pepper/pepper_pdf_host.cc b/chrome/renderer/pepper/pepper_pdf_host.cc
index e187c52..9b78c93 100644
--- a/chrome/renderer/pepper/pepper_pdf_host.cc
+++ b/chrome/renderer/pepper/pepper_pdf_host.cc
@@ -296,15 +296,18 @@ int32_t PepperPDFHost::OnHostMsgGetResourceImage(
if (res_id == 0)
return PP_ERROR_FAILED;
+ ui::ScaleFactor scale_factor = ui::GetScaleFactorFromScale(scale);
+
gfx::ImageSkia* res_image_skia =
ResourceBundle::GetSharedInstance().GetImageSkiaNamed(res_id);
if (!res_image_skia)
return PP_ERROR_FAILED;
- gfx::ImageSkiaRep image_skia_rep = res_image_skia->GetRepresentation(scale);
+ gfx::ImageSkiaRep image_skia_rep = res_image_skia->GetRepresentation(
+ scale_factor);
- if (image_skia_rep.is_null() || image_skia_rep.scale() != scale)
+ if (image_skia_rep.is_null() || image_skia_rep.scale_factor() != scale_factor)
return PP_ERROR_FAILED;
PP_Size pp_size;
diff --git a/content/browser/aura/software_output_device_win.cc b/content/browser/aura/software_output_device_win.cc
index f8d6d9b..7937810 100644
--- a/content/browser/aura/software_output_device_win.cc
+++ b/content/browser/aura/software_output_device_win.cc
@@ -36,7 +36,7 @@ void SoftwareOutputDeviceWin::Resize(gfx::Size viewport_size) {
return;
viewport_size_ = viewport_size;
- contents_.reset(new gfx::Canvas(viewport_size, 1.0f, true));
+ contents_.reset(new gfx::Canvas(viewport_size, ui::SCALE_FACTOR_100P, true));
memset(&bitmap_info_, 0, sizeof(bitmap_info_));
gfx::CreateBitmapHeader(viewport_size_.width(), viewport_size_.height(),
&bitmap_info_.bmiHeader);
diff --git a/content/browser/renderer_host/backing_store_aura.cc b/content/browser/renderer_host/backing_store_aura.cc
index 105bf44..5f976c4 100644
--- a/content/browser/renderer_host/backing_store_aura.cc
+++ b/content/browser/renderer_host/backing_store_aura.cc
@@ -38,7 +38,7 @@ BackingStoreAura::BackingStoreAura(RenderWidgetHost* widget,
const gfx::Size& size)
: BackingStore(widget, size) {
device_scale_factor_ =
- ui::GetImageScale(GetScaleFactorForView(widget->GetView()));
+ ui::GetScaleFactorScale(GetScaleFactorForView(widget->GetView()));
gfx::Size pixel_size = ToPixelSize(size, device_scale_factor_);
bitmap_.setConfig(SkBitmap::kARGB_8888_Config,
pixel_size.width(), pixel_size.height());
@@ -52,7 +52,7 @@ BackingStoreAura::~BackingStoreAura() {
void BackingStoreAura::SkiaShowRect(const gfx::Point& point,
gfx::Canvas* canvas) {
gfx::ImageSkia image = gfx::ImageSkia(gfx::ImageSkiaRep(bitmap_,
- device_scale_factor_));
+ ui::GetScaleFactorFromScale(device_scale_factor_)));
canvas->DrawImageInt(image, point.x(), point.y());
}
diff --git a/content/browser/renderer_host/dip_util.cc b/content/browser/renderer_host/dip_util.cc
index f855abf..8ef2d6c 100644
--- a/content/browser/renderer_host/dip_util.cc
+++ b/content/browser/renderer_host/dip_util.cc
@@ -18,7 +18,7 @@ namespace content {
namespace {
float GetScaleForView(const RenderWidgetHostView* view) {
- return ui::GetImageScale(GetScaleFactorForView(view));
+ return ui::GetScaleFactorScale(GetScaleFactorForView(view));
}
} // namespace
diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc
index 772d0df..68204fb 100644
--- a/content/browser/renderer_host/render_view_host_impl.cc
+++ b/content/browser/renderer_host/render_view_host_impl.cc
@@ -1494,8 +1494,8 @@ void RenderViewHostImpl::OnStartDragging(
if (policy->CanReadFile(GetProcess()->GetID(), path))
filtered_data.filenames.push_back(*it);
}
- float scale = ui::GetImageScale(GetScaleFactorForView(GetView()));
- gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, scale));
+ ui::ScaleFactor scale_factor = GetScaleFactorForView(GetView());
+ gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, scale_factor));
view->StartDragging(filtered_data, drag_operations_mask, image,
bitmap_offset_in_dip, event_info);
}
diff --git a/content/browser/renderer_host/render_widget_host_unittest.cc b/content/browser/renderer_host/render_widget_host_unittest.cc
index eced781..21c368a 100644
--- a/content/browser/renderer_host/render_widget_host_unittest.cc
+++ b/content/browser/renderer_host/render_widget_host_unittest.cc
@@ -990,7 +990,7 @@ TEST_F(RenderWidgetHostTest, Background) {
host_->SetView(view.get());
// Create a checkerboard background to test with.
- gfx::Canvas canvas(gfx::Size(4, 4), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(4, 4), ui::SCALE_FACTOR_100P, true);
canvas.FillRect(gfx::Rect(0, 0, 2, 2), SK_ColorBLACK);
canvas.FillRect(gfx::Rect(2, 0, 2, 2), SK_ColorWHITE);
canvas.FillRect(gfx::Rect(0, 2, 2, 2), SK_ColorWHITE);
diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc
index 2e01e95..ae2806e 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.cc
+++ b/content/browser/renderer_host/render_widget_host_view_android.cc
@@ -567,7 +567,7 @@ void RenderWidgetHostViewAndroid::CopyFromCompositingSurface(
float device_scale_factor = display.device_scale_factor();
DCHECK_EQ(device_scale_factor,
- ui::GetImageScale(GetScaleFactorForView(this)));
+ ui::GetScaleFactorScale(GetScaleFactorForView(this)));
const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size);
gfx::Rect src_subrect_in_pixel =
diff --git a/content/browser/renderer_host/render_widget_host_view_browsertest.cc b/content/browser/renderer_host/render_widget_host_view_browsertest.cc
index 0db748f..0fe376e 100644
--- a/content/browser/renderer_host/render_widget_host_view_browsertest.cc
+++ b/content/browser/renderer_host/render_widget_host_view_browsertest.cc
@@ -57,7 +57,7 @@ namespace {
// Convenience macro: Short-circuit a pass for platforms where setting up
// high-DPI fails.
#define PASS_TEST_IF_SCALE_FACTOR_NOT_SUPPORTED(factor) \
- if (ui::GetImageScale( \
+ if (ui::GetScaleFactorScale( \
GetScaleFactorForView(GetRenderWidgetHostViewPort())) != factor) { \
LOG(WARNING) << "Blindly passing this test: failed to set up " \
"scale factor: " << factor; \
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
index e908cbe..6096798 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
@@ -163,7 +163,7 @@ static BOOL SupportsBackingPropertiesChangedNotification() {
}
static float ScaleFactor(NSView* view) {
- return ui::GetImageScale(ui::GetScaleFactorForNativeView(view));
+ return ui::GetScaleFactorScale(ui::GetScaleFactorForNativeView(view));
}
// Private methods:
diff --git a/content/browser/renderer_host/render_widget_host_view_win.cc b/content/browser/renderer_host/render_widget_host_view_win.cc
index 3d5fd98..82d0048 100644
--- a/content/browser/renderer_host/render_widget_host_view_win.cc
+++ b/content/browser/renderer_host/render_widget_host_view_win.cc
@@ -1410,7 +1410,7 @@ void RenderWidgetHostViewWin::DrawBackground(const RECT& dirty_rect,
CPaintDC* dc) {
if (!background_.empty()) {
gfx::Rect dirty_area(dirty_rect);
- gfx::Canvas canvas(dirty_area.size(), 1.0f, true);
+ gfx::Canvas canvas(dirty_area.size(), ui::SCALE_FACTOR_100P, true);
canvas.Translate(-dirty_area.OffsetFromOrigin());
gfx::Rect dc_rect(dc->m_ps.rcPaint);
diff --git a/content/browser/renderer_host/test_render_view_host.cc b/content/browser/renderer_host/test_render_view_host.cc
index d89f353..caf79cf 100644
--- a/content/browser/renderer_host/test_render_view_host.cc
+++ b/content/browser/renderer_host/test_render_view_host.cc
@@ -4,7 +4,6 @@
#include "content/browser/renderer_host/test_render_view_host.h"
-#include "base/memory/scoped_ptr.h"
#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
#include "content/browser/dom_storage/session_storage_namespace_impl.h"
#include "content/browser/renderer_host/test_backing_store.h"
@@ -395,10 +394,6 @@ void TestRenderViewHost::set_simulate_history_list_was_cleared(bool cleared) {
}
RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
- std::vector<ui::ScaleFactor> scale_factors;
- scale_factors.push_back(ui::SCALE_FACTOR_100P);
- scoped_set_supported_scale_factors_.reset(
- new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
}
RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
diff --git a/content/browser/renderer_host/test_render_view_host.h b/content/browser/renderer_host/test_render_view_host.h
index 5abed25..1eb7583 100644
--- a/content/browser/renderer_host/test_render_view_host.h
+++ b/content/browser/renderer_host/test_render_view_host.h
@@ -15,7 +15,6 @@
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/public/common/page_transition_types.h"
#include "content/public/test/test_renderer_host.h"
-#include "ui/base/layout.h"
#include "ui/gfx/vector2d_f.h"
// This file provides a testing framework for mocking out the RenderProcessHost
@@ -371,9 +370,6 @@ class RenderViewHostImplTestHarness : public RenderViewHostTestHarness {
TestWebContents* contents();
private:
- typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors>
- ScopedSetSupportedScaleFactors;
- ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_;
DISALLOW_COPY_AND_ASSIGN(RenderViewHostImplTestHarness);
};
diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc
index eba64fe..f3822f8 100644
--- a/content/browser/web_contents/web_contents_view_aura.cc
+++ b/content/browser/web_contents/web_contents_view_aura.cc
@@ -123,8 +123,7 @@ class OverscrollWindowDelegate : public ImageWindowDelegate {
if (entry && entry->screenshot().get()) {
std::vector<gfx::ImagePNGRep> image_reps;
image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(),
- ui::GetImageScale(
- ui::GetScaleFactorForNativeView(web_contents_window()))));
+ ui::GetScaleFactorForNativeView(web_contents_window())));
image = gfx::Image(image_reps);
}
SetImage(image);
@@ -516,8 +515,7 @@ class OverscrollNavigationOverlay :
if (entry && entry->screenshot().get()) {
std::vector<gfx::ImagePNGRep> image_reps;
image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(),
- ui::GetImageScale(
- ui::GetScaleFactorForNativeView(window_.get()))));
+ ui::GetScaleFactorForNativeView(window_.get())));
image = gfx::Image(image_reps);
}
layer_delegate_.SetImage(image);
diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.cc b/content/renderer/pepper/pepper_plugin_instance_impl.cc
index a993d25..c9d10af 100644
--- a/content/renderer/pepper/pepper_plugin_instance_impl.cc
+++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc
@@ -2672,9 +2672,11 @@ base::FilePath PepperPluginInstanceImpl::GetModulePath() {
PP_Resource PepperPluginInstanceImpl::CreateImage(gfx::ImageSkia* source_image,
float scale) {
- gfx::ImageSkiaRep image_skia_rep = source_image->GetRepresentation(scale);
+ ui::ScaleFactor scale_factor = ui::GetScaleFactorFromScale(scale);
+ gfx::ImageSkiaRep image_skia_rep = source_image->GetRepresentation(
+ scale_factor);
- if (image_skia_rep.is_null() || image_skia_rep.scale() != scale)
+ if (image_skia_rep.is_null() || image_skia_rep.scale_factor() != scale_factor)
return 0;
scoped_refptr<PPB_ImageData_Impl> image_data(new PPB_ImageData_Impl(
diff --git a/ui/app_list/views/app_list_item_view.cc b/ui/app_list/views/app_list_item_view.cc
index 083b89d..2717f51 100644
--- a/ui/app_list/views/app_list_item_view.cc
+++ b/ui/app_list/views/app_list_item_view.cc
@@ -184,7 +184,7 @@ void AppListItemView::CancelContextMenu() {
}
gfx::ImageSkia AppListItemView::GetDragImage() {
- gfx::Canvas canvas(size(), 1.0f, false /* is_opaque */);
+ gfx::Canvas canvas(size(), ui::SCALE_FACTOR_100P, false /* is_opaque */);
gfx::Rect bounds(size());
canvas.DrawColor(SK_ColorTRANSPARENT);
PaintChildren(&canvas);
diff --git a/ui/app_list/views/app_list_main_view.cc b/ui/app_list/views/app_list_main_view.cc
index f2fc46b..7dc19ff 100644
--- a/ui/app_list/views/app_list_main_view.cc
+++ b/ui/app_list/views/app_list_main_view.cc
@@ -43,13 +43,13 @@ class AppListMainView::IconLoader : public AppListItemModelObserver {
public:
IconLoader(AppListMainView* owner,
AppListItemModel* item,
- float scale)
+ ui::ScaleFactor scale_factor)
: owner_(owner),
item_(item) {
item_->AddObserver(this);
// Triggers icon loading for given |scale_factor|.
- item_->icon().GetRepresentation(scale);
+ item_->icon().GetRepresentation(scale_factor);
}
virtual ~IconLoader() {
@@ -147,7 +147,6 @@ void AppListMainView::PreloadIcons(PaginationModel* pagination_model,
if (parent)
scale_factor = ui::GetScaleFactorForNativeView(parent);
- float scale = ui::GetImageScale(scale_factor);
// |pagination_model| could have -1 as the initial selected page and
// assumes first page (i.e. index 0) will be used in this case.
const int selected_page = std::max(0, pagination_model->selected_page());
@@ -161,10 +160,10 @@ void AppListMainView::PreloadIcons(PaginationModel* pagination_model,
pending_icon_loaders_.clear();
for (int i = start_model_index; i < end_model_index; ++i) {
AppListItemModel* item = model_->apps()->GetItemAt(i);
- if (item->icon().HasRepresentation(scale))
+ if (item->icon().HasRepresentation(scale_factor))
continue;
- pending_icon_loaders_.push_back(new IconLoader(this, item, scale));
+ pending_icon_loaders_.push_back(new IconLoader(this, item, scale_factor));
}
}
diff --git a/ui/app_list/views/cached_label.cc b/ui/app_list/views/cached_label.cc
index a7d9e27..5488431 100644
--- a/ui/app_list/views/cached_label.cc
+++ b/ui/app_list/views/cached_label.cc
@@ -17,7 +17,7 @@ CachedLabel::CachedLabel()
void CachedLabel::PaintToBackingImage() {
if (image_.size() == size() && !needs_repaint_)
return;
- gfx::Canvas canvas(size(), 1.0f, false /* is_opaque */);
+ gfx::Canvas canvas(size(), ui::SCALE_FACTOR_100P, false /* is_opaque */);
canvas.FillRect(GetLocalBounds(), SkColorSetARGB(0, 0, 0, 0),
SkXfermode::kSrc_Mode);
Label::OnPaint(&canvas);
diff --git a/ui/base/clipboard/clipboard_gtk.cc b/ui/base/clipboard/clipboard_gtk.cc
index afcb304..86f4a3c 100644
--- a/ui/base/clipboard/clipboard_gtk.cc
+++ b/ui/base/clipboard/clipboard_gtk.cc
@@ -541,7 +541,8 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
gfx::Canvas canvas(gfx::Size(gdk_pixbuf_get_width(pixbuf.get()),
gdk_pixbuf_get_height(pixbuf.get())),
- 1.0f, false);
+ ui::SCALE_FACTOR_100P,
+ false);
{
skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas());
cairo_t* context = scoped_platform_paint.GetPlatformSurface();
diff --git a/ui/base/clipboard/clipboard_mac.mm b/ui/base/clipboard/clipboard_mac.mm
index 82ee1d0..85bd16d 100644
--- a/ui/base/clipboard/clipboard_mac.mm
+++ b/ui/base/clipboard/clipboard_mac.mm
@@ -358,7 +358,7 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
int width = [image size].width;
int height = [image size].height;
- gfx::Canvas canvas(gfx::Size(width, height), 1.0f, false);
+ gfx::Canvas canvas(gfx::Size(width, height), ui::SCALE_FACTOR_100P, false);
{
skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas());
CGContextRef gc = scoped_platform_paint.GetPlatformSurface();
diff --git a/ui/base/clipboard/clipboard_win.cc b/ui/base/clipboard/clipboard_win.cc
index fec5a90..6548448 100644
--- a/ui/base/clipboard/clipboard_win.cc
+++ b/ui/base/clipboard/clipboard_win.cc
@@ -562,7 +562,7 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
gfx::Canvas canvas(gfx::Size(bitmap->bmiHeader.biWidth,
bitmap->bmiHeader.biHeight),
- 1.0f,
+ ui::SCALE_FACTOR_100P,
false);
{
skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas());
diff --git a/ui/base/cursor/cursor_loader_x11.cc b/ui/base/cursor/cursor_loader_x11.cc
index 8cfcce6..aa84173 100644
--- a/ui/base/cursor/cursor_loader_x11.cc
+++ b/ui/base/cursor/cursor_loader_x11.cc
@@ -159,7 +159,7 @@ void CursorLoaderX11::LoadImageCursor(int id,
const gfx::ImageSkia* image =
ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(
- display().device_scale_factor());
+ GetScaleFactorFromScale(display().device_scale_factor()));
SkBitmap bitmap = image_rep.sk_bitmap();
gfx::Point hotpoint = hot;
ScaleAndRotateCursorBitmapAndHotpoint(
@@ -177,7 +177,7 @@ void CursorLoaderX11::LoadAnimatedCursor(int id,
const gfx::ImageSkia* image =
ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(
- display().device_scale_factor());
+ GetScaleFactorFromScale(display().device_scale_factor()));
SkBitmap bitmap = image_rep.sk_bitmap();
int frame_width = bitmap.height();
int frame_height = frame_width;
diff --git a/ui/base/cursor/cursors_aura.cc b/ui/base/cursor/cursors_aura.cc
index cdf4ab3..bb5947a 100644
--- a/ui/base/cursor/cursors_aura.cc
+++ b/ui/base/cursor/cursors_aura.cc
@@ -155,7 +155,7 @@ bool SearchTable(const CursorData* table,
int* resource_id,
gfx::Point* point) {
bool resource_2x_available =
- ResourceBundle::GetSharedInstance().GetMaxScaleFactor() ==
+ ResourceBundle::GetSharedInstance().max_scale_factor() ==
SCALE_FACTOR_200P;
for (size_t i = 0; i < table_length; ++i) {
if (table[i].id == id) {
diff --git a/ui/base/layout.cc b/ui/base/layout.cc
index 61517f3..40a0a9c 100644
--- a/ui/base/layout.cc
+++ b/ui/base/layout.cc
@@ -15,24 +15,30 @@
#include "ui/base/touch/touch_device.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/display.h"
-#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/screen.h"
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+#include "base/mac/mac_util.h"
+#endif
+
#if defined(OS_WIN)
#include "base/win/metro.h"
+#include "ui/gfx/win/dpi.h"
#include <Windows.h>
#endif // defined(OS_WIN)
+#if defined(OS_CHROMEOS)
+#include "ui/base/resource/resource_bundle.h"
+#endif
+
namespace ui {
namespace {
bool ScaleFactorComparator(const ScaleFactor& lhs, const ScaleFactor& rhs){
- return GetImageScale(lhs) < GetImageScale(rhs);
+ return GetScaleFactorScale(lhs) < GetScaleFactorScale(rhs);
}
-std::vector<ScaleFactor>* g_supported_scale_factors = NULL;
-
#if defined(OS_WIN)
// Helper function that determines whether we want to optimize the UI for touch.
bool UseTouchOptimizedUI() {
@@ -66,47 +72,90 @@ COMPILE_ASSERT(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales),
kScaleFactorScales_incorrect_size);
const size_t kScaleFactorScalesLength = arraysize(kScaleFactorScales);
-} // namespace
+namespace {
-DisplayLayout GetDisplayLayout() {
-#if defined(OS_WIN)
- if (UseTouchOptimizedUI())
- return LAYOUT_TOUCH;
-#endif
- return LAYOUT_DESKTOP;
+// Returns the scale factor closest to |scale| from the full list of factors.
+// Note that it does NOT rely on the list of supported scale factors.
+// Finding the closest match is inefficient and shouldn't be done frequently.
+ScaleFactor FindClosestScaleFactorUnsafe(float scale) {
+ float smallest_diff = std::numeric_limits<float>::max();
+ ScaleFactor closest_match = SCALE_FACTOR_100P;
+ for (int i = SCALE_FACTOR_100P; i < NUM_SCALE_FACTORS; ++i) {
+ const ScaleFactor scale_factor = static_cast<ScaleFactor>(i);
+ float diff = std::abs(kScaleFactorScales[scale_factor] - scale);
+ if (diff < smallest_diff) {
+ closest_match = scale_factor;
+ smallest_diff = diff;
+ }
+ }
+ return closest_match;
}
-void SetSupportedScaleFactors(
- const std::vector<ui::ScaleFactor>& scale_factors) {
- if (g_supported_scale_factors != NULL)
- delete g_supported_scale_factors;
+} // namespace
- g_supported_scale_factors = new std::vector<ScaleFactor>(scale_factors);
- std::sort(g_supported_scale_factors->begin(),
- g_supported_scale_factors->end(),
- ScaleFactorComparator);
+std::vector<ScaleFactor>& GetSupportedScaleFactorsInternal() {
+ static std::vector<ScaleFactor>* supported_scale_factors =
+ new std::vector<ScaleFactor>();
+ if (supported_scale_factors->empty()) {
+#if !defined(OS_IOS)
+ // On platforms other than iOS, 100P is always a supported scale factor.
+ supported_scale_factors->push_back(SCALE_FACTOR_100P);
+#endif
- // Set ImageSkia's supported scales.
- std::vector<float> scales;
- for (std::vector<ScaleFactor>::const_iterator it =
- g_supported_scale_factors->begin();
- it != g_supported_scale_factors->end(); ++it) {
- scales.push_back(GetImageScale(*it));
+#if defined(OS_ANDROID)
+ const gfx::Display display =
+ gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
+ const float display_density = display.device_scale_factor();
+ const ScaleFactor closest = FindClosestScaleFactorUnsafe(display_density);
+ if (closest != SCALE_FACTOR_100P)
+ supported_scale_factors->push_back(closest);
+#elif defined(OS_IOS)
+ gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
+ if (display.device_scale_factor() > 1.0) {
+ DCHECK_EQ(2.0, display.device_scale_factor());
+ supported_scale_factors->push_back(SCALE_FACTOR_200P);
+ } else {
+ supported_scale_factors->push_back(SCALE_FACTOR_100P);
+ }
+#elif defined(OS_MACOSX)
+ if (base::mac::IsOSLionOrLater())
+ supported_scale_factors->push_back(SCALE_FACTOR_200P);
+#elif defined(OS_WIN)
+ // Have high-DPI resources for 140% and 180% scaling on Windows based on
+ // default scaling for Metro mode. Round to nearest supported scale in
+ // all cases.
+ if (gfx::IsInHighDPIMode()) {
+ supported_scale_factors->push_back(SCALE_FACTOR_140P);
+ supported_scale_factors->push_back(SCALE_FACTOR_180P);
+ }
+#elif defined(OS_CHROMEOS)
+ // TODO(oshima): Include 200P only if the device support 200P
+ supported_scale_factors->push_back(SCALE_FACTOR_200P);
+#endif
+ std::sort(supported_scale_factors->begin(),
+ supported_scale_factors->end(),
+ ScaleFactorComparator);
}
- gfx::ImageSkia::SetSupportedScales(scales);
+ return *supported_scale_factors;
}
-const std::vector<ScaleFactor>& GetSupportedScaleFactors() {
- DCHECK(g_supported_scale_factors != NULL);
- return *g_supported_scale_factors;
+} // namespace
+
+DisplayLayout GetDisplayLayout() {
+#if defined(OS_WIN)
+ if (UseTouchOptimizedUI())
+ return LAYOUT_TOUCH;
+#endif
+ return LAYOUT_DESKTOP;
}
-ScaleFactor GetSupportedScaleFactor(float scale) {
- DCHECK(g_supported_scale_factors != NULL);
+ScaleFactor GetScaleFactorFromScale(float scale) {
ScaleFactor closest_match = SCALE_FACTOR_100P;
float smallest_diff = std::numeric_limits<float>::max();
- for (size_t i = 0; i < g_supported_scale_factors->size(); ++i) {
- ScaleFactor scale_factor = (*g_supported_scale_factors)[i];
+ const std::vector<ScaleFactor>& supported =
+ GetSupportedScaleFactorsInternal();
+ for (size_t i = 0; i < supported.size(); ++i) {
+ ScaleFactor scale_factor = supported[i];
float diff = std::abs(kScaleFactorScales[scale_factor] - scale);
if (diff < smallest_diff) {
closest_match = scale_factor;
@@ -117,55 +166,49 @@ ScaleFactor GetSupportedScaleFactor(float scale) {
return closest_match;
}
-float GetImageScale(ScaleFactor scale_factor) {
+float GetScaleFactorScale(ScaleFactor scale_factor) {
return kScaleFactorScales[scale_factor];
}
-bool IsScaleFactorSupported(ScaleFactor scale_factor) {
- DCHECK(g_supported_scale_factors != NULL);
- return std::find(g_supported_scale_factors->begin(),
- g_supported_scale_factors->end(),
- scale_factor) != g_supported_scale_factors->end();
+ScaleFactor GetMaxScaleFactor() {
+#if defined(OS_CHROMEOS)
+ return ResourceBundle::GetSharedInstance().max_scale_factor();
+#else
+ return GetSupportedScaleFactorsInternal().back();
+#endif
}
-// Returns the scale factor closest to |scale| from the full list of factors.
-// Note that it does NOT rely on the list of supported scale factors.
-// Finding the closest match is inefficient and shouldn't be done frequently.
-ScaleFactor FindClosestScaleFactorUnsafe(float scale) {
- float smallest_diff = std::numeric_limits<float>::max();
- ScaleFactor closest_match = SCALE_FACTOR_100P;
- for (int i = SCALE_FACTOR_100P; i < NUM_SCALE_FACTORS; ++i) {
- const ScaleFactor scale_factor = static_cast<ScaleFactor>(i);
- float diff = std::abs(kScaleFactorScales[scale_factor] - scale);
- if (diff < smallest_diff) {
- closest_match = scale_factor;
- smallest_diff = diff;
- }
- }
- return closest_match;
+std::vector<ScaleFactor> GetSupportedScaleFactors() {
+ return GetSupportedScaleFactorsInternal();
+}
+
+bool IsScaleFactorSupported(ScaleFactor scale_factor) {
+ const std::vector<ScaleFactor>& supported =
+ GetSupportedScaleFactorsInternal();
+ return std::find(supported.begin(), supported.end(), scale_factor) !=
+ supported.end();
}
namespace test {
+void SetSupportedScaleFactors(
+ const std::vector<ui::ScaleFactor>& scale_factors) {
+ std::vector<ui::ScaleFactor>& supported_scale_factors =
+ GetSupportedScaleFactorsInternal();
+ supported_scale_factors = scale_factors;
+ std::sort(supported_scale_factors.begin(),
+ supported_scale_factors.end(),
+ ScaleFactorComparator);
+}
+
ScopedSetSupportedScaleFactors::ScopedSetSupportedScaleFactors(
- const std::vector<ui::ScaleFactor>& new_scale_factors) {
- if (g_supported_scale_factors) {
- original_scale_factors_ =
- new std::vector<ScaleFactor>(*g_supported_scale_factors);
- } else {
- original_scale_factors_ = NULL;
- }
+ const std::vector<ui::ScaleFactor>& new_scale_factors)
+ : original_scale_factors_(GetSupportedScaleFactors()) {
SetSupportedScaleFactors(new_scale_factors);
}
ScopedSetSupportedScaleFactors::~ScopedSetSupportedScaleFactors() {
- if (original_scale_factors_) {
- SetSupportedScaleFactors(*original_scale_factors_);
- delete original_scale_factors_;
- } else {
- delete g_supported_scale_factors;
- g_supported_scale_factors = NULL;
- }
+ SetSupportedScaleFactors(original_scale_factors_);
}
} // namespace test
@@ -175,7 +218,7 @@ ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view) {
gfx::Screen* screen = gfx::Screen::GetScreenFor(view);
if (screen->IsDIPEnabled()) {
gfx::Display display = screen->GetDisplayNearestWindow(view);
- return GetSupportedScaleFactor(display.device_scale_factor());
+ return GetScaleFactorFromScale(display.device_scale_factor());
}
return ui::SCALE_FACTOR_100P;
}
diff --git a/ui/base/layout.h b/ui/base/layout.h
index 50b0e50..1292c38 100644
--- a/ui/base/layout.h
+++ b/ui/base/layout.h
@@ -46,37 +46,36 @@ enum ScaleFactor {
NUM_SCALE_FACTORS // This always appears last.
};
-// Changes the value of GetSupportedScaleFactors() to |scale_factors|.
-// Use ScopedSetSupportedScaleFactors for unit tests as not to affect the
-// state of other tests.
-UI_EXPORT void SetSupportedScaleFactors(
- const std::vector<ScaleFactor>& scale_factors);
-
-// Returns a vector with the scale factors which are supported by this
-// platform, in ascending order.
-UI_EXPORT const std::vector<ScaleFactor>& GetSupportedScaleFactors();
-
// Returns the float scale value for |scale_factor|.
-UI_EXPORT float GetImageScale(ScaleFactor scale_factor);
+UI_EXPORT float GetScaleFactorScale(ScaleFactor scale_factor);
// Returns the supported ScaleFactor which most closely matches |scale|.
// Converting from float to ScaleFactor is inefficient and should be done as
// little as possible.
// TODO(oshima): Make ScaleFactor a class and remove this.
-UI_EXPORT ScaleFactor GetSupportedScaleFactor(float image_scale);
+UI_EXPORT ScaleFactor GetScaleFactorFromScale(float scale);
// Returns the ScaleFactor used by |view|.
UI_EXPORT ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view);
+// Returns the maximum device scale factor supported by this platform.
+UI_EXPORT ScaleFactor GetMaxScaleFactor();
+
+// Returns a vector with the scale factors which are supported by this
+// platform, in ascending order.
+UI_EXPORT std::vector<ScaleFactor> GetSupportedScaleFactors();
+
// Returns true if |scale_factor| is supported by this platform.
UI_EXPORT bool IsScaleFactorSupported(ScaleFactor scale_factor);
-// Returns the scale factor closest to |scale| from the full list of factors.
-// Note that it does NOT rely on the list of supported scale factors.
-// Finding the closest match is inefficient and shouldn't be done frequently.
-UI_EXPORT ScaleFactor FindClosestScaleFactorUnsafe(float scale);
-
namespace test {
+
+// Changes the value of GetSupportedScaleFactors() to |scale_factors|.
+// Use ScopedSetSupportedScaleFactors for unit tests as not to affect the
+// state of other tests.
+UI_EXPORT void SetSupportedScaleFactors(
+ const std::vector<ScaleFactor>& scale_factors);
+
// Class which changes the value of GetSupportedScaleFactors() to
// |new_scale_factors| for the duration of its lifetime.
class UI_EXPORT ScopedSetSupportedScaleFactors {
@@ -86,7 +85,7 @@ class UI_EXPORT ScopedSetSupportedScaleFactors {
~ScopedSetSupportedScaleFactors();
private:
- std::vector<ui::ScaleFactor>* original_scale_factors_;
+ const std::vector<ui::ScaleFactor> original_scale_factors_;
DISALLOW_COPY_AND_ASSIGN(ScopedSetSupportedScaleFactors);
};
diff --git a/ui/base/layout_mac.mm b/ui/base/layout_mac.mm
index 6e50de1..f1a635d 100644
--- a/ui/base/layout_mac.mm
+++ b/ui/base/layout_mac.mm
@@ -32,7 +32,7 @@ float GetScaleFactorScaleForNativeView(gfx::NativeView view) {
namespace ui {
ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view) {
- return GetSupportedScaleFactor(GetScaleFactorScaleForNativeView(view));
+ return GetScaleFactorFromScale(GetScaleFactorScaleForNativeView(view));
}
} // namespace ui
diff --git a/ui/base/layout_unittest.cc b/ui/base/layout_unittest.cc
index 8ac2e2d..8a74182 100644
--- a/ui/base/layout_unittest.cc
+++ b/ui/base/layout_unittest.cc
@@ -14,13 +14,13 @@
namespace ui {
TEST(LayoutTest, GetScaleFactorScale) {
- EXPECT_FLOAT_EQ(1.0f, GetImageScale(SCALE_FACTOR_100P));
- EXPECT_FLOAT_EQ(1.25f, GetImageScale(SCALE_FACTOR_125P));
- EXPECT_FLOAT_EQ(1.33f, GetImageScale(SCALE_FACTOR_133P));
- EXPECT_FLOAT_EQ(1.4f, GetImageScale(SCALE_FACTOR_140P));
- EXPECT_FLOAT_EQ(1.5f, GetImageScale(SCALE_FACTOR_150P));
- EXPECT_FLOAT_EQ(1.8f, GetImageScale(SCALE_FACTOR_180P));
- EXPECT_FLOAT_EQ(2.0f, GetImageScale(SCALE_FACTOR_200P));
+ EXPECT_FLOAT_EQ(1.0f, GetScaleFactorScale(SCALE_FACTOR_100P));
+ EXPECT_FLOAT_EQ(1.25f, GetScaleFactorScale(SCALE_FACTOR_125P));
+ EXPECT_FLOAT_EQ(1.33f, GetScaleFactorScale(SCALE_FACTOR_133P));
+ EXPECT_FLOAT_EQ(1.4f, GetScaleFactorScale(SCALE_FACTOR_140P));
+ EXPECT_FLOAT_EQ(1.5f, GetScaleFactorScale(SCALE_FACTOR_150P));
+ EXPECT_FLOAT_EQ(1.8f, GetScaleFactorScale(SCALE_FACTOR_180P));
+ EXPECT_FLOAT_EQ(2.0f, GetScaleFactorScale(SCALE_FACTOR_200P));
}
TEST(LayoutTest, GetScaleFactorFromScalePartlySupported) {
@@ -28,14 +28,14 @@ TEST(LayoutTest, GetScaleFactorFromScalePartlySupported) {
supported_factors.push_back(SCALE_FACTOR_100P);
supported_factors.push_back(SCALE_FACTOR_180P);
test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
- EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(0.1f));
- EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(0.9f));
- EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(1.0f));
- EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(1.39f));
- EXPECT_EQ(SCALE_FACTOR_180P, GetSupportedScaleFactor(1.41f));
- EXPECT_EQ(SCALE_FACTOR_180P, GetSupportedScaleFactor(1.8f));
- EXPECT_EQ(SCALE_FACTOR_180P, GetSupportedScaleFactor(2.0f));
- EXPECT_EQ(SCALE_FACTOR_180P, GetSupportedScaleFactor(999.0f));
+ EXPECT_EQ(SCALE_FACTOR_100P, GetScaleFactorFromScale(0.1f));
+ EXPECT_EQ(SCALE_FACTOR_100P, GetScaleFactorFromScale(0.9f));
+ EXPECT_EQ(SCALE_FACTOR_100P, GetScaleFactorFromScale(1.0f));
+ EXPECT_EQ(SCALE_FACTOR_100P, GetScaleFactorFromScale(1.39f));
+ EXPECT_EQ(SCALE_FACTOR_180P, GetScaleFactorFromScale(1.41f));
+ EXPECT_EQ(SCALE_FACTOR_180P, GetScaleFactorFromScale(1.8f));
+ EXPECT_EQ(SCALE_FACTOR_180P, GetScaleFactorFromScale(2.0f));
+ EXPECT_EQ(SCALE_FACTOR_180P, GetScaleFactorFromScale(999.0f));
}
TEST(LayoutTest, GetScaleFactorFromScaleAllSupported) {
@@ -45,22 +45,59 @@ TEST(LayoutTest, GetScaleFactorFromScaleAllSupported) {
}
test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
- EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(0.1f));
- EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(0.9f));
- EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(1.0f));
- EXPECT_EQ(SCALE_FACTOR_125P, GetSupportedScaleFactor(1.19f));
- EXPECT_EQ(SCALE_FACTOR_125P, GetSupportedScaleFactor(1.21f));
- EXPECT_EQ(SCALE_FACTOR_133P, GetSupportedScaleFactor(1.291f));
- EXPECT_EQ(SCALE_FACTOR_133P, GetSupportedScaleFactor(1.3f));
- EXPECT_EQ(SCALE_FACTOR_140P, GetSupportedScaleFactor(1.4f));
- EXPECT_EQ(SCALE_FACTOR_150P, GetSupportedScaleFactor(1.59f));
- EXPECT_EQ(SCALE_FACTOR_150P, GetSupportedScaleFactor(1.61f));
- EXPECT_EQ(SCALE_FACTOR_180P, GetSupportedScaleFactor(1.7f));
- EXPECT_EQ(SCALE_FACTOR_180P, GetSupportedScaleFactor(1.89f));
- EXPECT_EQ(SCALE_FACTOR_200P, GetSupportedScaleFactor(1.91f));
- EXPECT_EQ(SCALE_FACTOR_200P, GetSupportedScaleFactor(2.0f));
- EXPECT_EQ(SCALE_FACTOR_200P, GetSupportedScaleFactor(2.1f));
- EXPECT_EQ(SCALE_FACTOR_200P, GetSupportedScaleFactor(999.0f));
+ EXPECT_EQ(SCALE_FACTOR_100P, GetScaleFactorFromScale(0.1f));
+ EXPECT_EQ(SCALE_FACTOR_100P, GetScaleFactorFromScale(0.9f));
+ EXPECT_EQ(SCALE_FACTOR_100P, GetScaleFactorFromScale(1.0f));
+ EXPECT_EQ(SCALE_FACTOR_125P, GetScaleFactorFromScale(1.19f));
+ EXPECT_EQ(SCALE_FACTOR_125P, GetScaleFactorFromScale(1.21f));
+ EXPECT_EQ(SCALE_FACTOR_133P, GetScaleFactorFromScale(1.291f));
+ EXPECT_EQ(SCALE_FACTOR_133P, GetScaleFactorFromScale(1.3f));
+ EXPECT_EQ(SCALE_FACTOR_140P, GetScaleFactorFromScale(1.4f));
+ EXPECT_EQ(SCALE_FACTOR_150P, GetScaleFactorFromScale(1.59f));
+ EXPECT_EQ(SCALE_FACTOR_150P, GetScaleFactorFromScale(1.61f));
+ EXPECT_EQ(SCALE_FACTOR_180P, GetScaleFactorFromScale(1.7f));
+ EXPECT_EQ(SCALE_FACTOR_180P, GetScaleFactorFromScale(1.89f));
+ EXPECT_EQ(SCALE_FACTOR_200P, GetScaleFactorFromScale(1.91f));
+ EXPECT_EQ(SCALE_FACTOR_200P, GetScaleFactorFromScale(2.0f));
+ EXPECT_EQ(SCALE_FACTOR_200P, GetScaleFactorFromScale(2.1f));
+ EXPECT_EQ(SCALE_FACTOR_200P, GetScaleFactorFromScale(999.0f));
+}
+
+TEST(LayoutTest, GetMaxScaleFactor) {
+#if defined(OS_CHROMEOS)
+ // On Chrome OS, the maximum scale factor is based on
+ // the available resource pack. In testing environment,
+ // we always have 200P.
+ EXPECT_EQ(SCALE_FACTOR_200P, GetMaxScaleFactor());
+#else
+ {
+ ScaleFactor scale_factors[] = { SCALE_FACTOR_100P };
+ std::vector<ScaleFactor> supported_factors(
+ scale_factors, scale_factors + arraysize(scale_factors));
+ test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
+ EXPECT_EQ(SCALE_FACTOR_100P, GetMaxScaleFactor());
+ }
+
+ {
+ ScaleFactor scale_factors[] = { SCALE_FACTOR_100P,
+ SCALE_FACTOR_140P };
+ std::vector<ScaleFactor> supported_factors(
+ scale_factors, scale_factors + arraysize(scale_factors));
+ test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
+ EXPECT_EQ(SCALE_FACTOR_140P, GetMaxScaleFactor());
+ }
+
+ {
+ ScaleFactor scale_factors[] = { SCALE_FACTOR_200P,
+ SCALE_FACTOR_180P,
+ SCALE_FACTOR_140P,
+ SCALE_FACTOR_100P };
+ std::vector<ScaleFactor> supported_factors(
+ scale_factors, scale_factors + arraysize(scale_factors));
+ test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
+ EXPECT_EQ(SCALE_FACTOR_200P, GetMaxScaleFactor());
+ }
+#endif
}
} // namespace ui
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index 8d2815d..31aed58 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -40,14 +40,6 @@
#include "ui/gfx/platform_font_pango.h"
#endif
-#if defined(OS_WIN)
-#include "ui/gfx/win/dpi.h"
-#endif
-
-#if defined(OS_MACOSX) && !defined(OS_IOS)
-#include "base/mac/mac_util.h"
-#endif
-
namespace ui {
namespace {
@@ -88,19 +80,18 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
virtual ~ResourceBundleImageSource() {}
// gfx::ImageSkiaSource overrides:
- virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ virtual gfx::ImageSkiaRep GetImageForScale(
+ ui::ScaleFactor scale_factor) OVERRIDE {
SkBitmap image;
bool fell_back_to_1x = false;
- ScaleFactor scale_factor = GetSupportedScaleFactor(scale);
bool found = rb_->LoadBitmap(resource_id_, &scale_factor,
&image, &fell_back_to_1x);
- // Force to a supported scale.
- scale = ui::GetImageScale(scale_factor);
if (!found)
return gfx::ImageSkiaRep();
if (fell_back_to_1x) {
// GRIT fell back to the 100% image, so rescale it to the correct size.
+ float scale = GetScaleFactorScale(scale_factor);
image = skia::ImageOperations::Resize(
image,
skia::ImageOperations::RESIZE_LANCZOS3,
@@ -121,7 +112,7 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
}
}
- return gfx::ImageSkiaRep(image, scale);
+ return gfx::ImageSkiaRep(image, scale_factor);
}
private:
@@ -134,7 +125,9 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
// static
std::string ResourceBundle::InitSharedInstanceWithLocale(
const std::string& pref_locale, Delegate* delegate) {
- InitSharedInstance(delegate);
+ DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
+ g_shared_instance_ = new ResourceBundle(delegate);
+
g_shared_instance_->LoadCommonResources();
std::string result = g_shared_instance_->LoadLocaleResources(pref_locale);
InitDefaultFont();
@@ -144,7 +137,9 @@ std::string ResourceBundle::InitSharedInstanceWithLocale(
// static
std::string ResourceBundle::InitSharedInstanceLocaleOnly(
const std::string& pref_locale, Delegate* delegate) {
- InitSharedInstance(delegate);
+ DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
+ g_shared_instance_ = new ResourceBundle(delegate);
+
std::string result = g_shared_instance_->LoadLocaleResources(pref_locale);
InitDefaultFont();
return result;
@@ -153,7 +148,9 @@ std::string ResourceBundle::InitSharedInstanceLocaleOnly(
// static
void ResourceBundle::InitSharedInstanceWithPakFile(
base::PlatformFile pak_file, bool should_load_common_resources) {
- InitSharedInstance(NULL);
+ DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
+ g_shared_instance_ = new ResourceBundle(NULL);
+
if (should_load_common_resources)
g_shared_instance_->LoadCommonResources();
@@ -169,7 +166,9 @@ void ResourceBundle::InitSharedInstanceWithPakFile(
// static
void ResourceBundle::InitSharedInstanceWithPakPath(const base::FilePath& path) {
- InitSharedInstance(NULL);
+ DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
+ g_shared_instance_ = new ResourceBundle(NULL);
+
g_shared_instance_->LoadTestResources(path, path);
InitDefaultFont();
@@ -342,20 +341,18 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
DCHECK(!data_packs_.empty()) <<
"Missing call to SetResourcesDataDLL?";
-#if defined(OS_CHROMEOS)
- ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor();
-#else
- ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P;
-#endif
-
- float scale = GetImageScale(scale_factor_to_load);
// TODO(oshima): Consider reading the image size from png IHDR chunk and
// skip decoding here and remove #ifdef below.
// ResourceBundle::GetSharedInstance() is destroyed after the
// BrowserMainLoop has finished running. |image_skia| is guaranteed to be
// destroyed before the resource bundle is destroyed.
+#if defined(OS_CHROMEOS)
+ ui::ScaleFactor scale_factor_to_load = ui::GetMaxScaleFactor();
+#else
+ ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P;
+#endif
gfx::ImageSkia image_skia(new ResourceBundleImageSource(this, resource_id),
- scale);
+ scale_factor_to_load);
if (image_skia.isNull()) {
LOG(WARNING) << "Unable to load image with id " << resource_id;
NOTREACHED(); // Want to assert in debug mode.
@@ -513,14 +510,6 @@ void ResourceBundle::ReloadFonts() {
LoadFontsIfNecessary();
}
-ScaleFactor ResourceBundle::GetMaxScaleFactor() const {
-#if defined(OS_CHROMEOS)
- return max_scale_factor_;
-#else
- return GetSupportedScaleFactors().back();
-#endif
-}
-
ResourceBundle::ResourceBundle(Delegate* delegate)
: delegate_(delegate),
images_and_fonts_lock_(new base::Lock),
@@ -533,49 +522,6 @@ ResourceBundle::~ResourceBundle() {
UnloadLocaleResources();
}
-// static
-void ResourceBundle::InitSharedInstance(Delegate* delegate) {
- DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
- g_shared_instance_ = new ResourceBundle(delegate);
- static std::vector<ScaleFactor> supported_scale_factors;
-#if !defined(OS_IOS)
- // On platforms other than iOS, 100P is always a supported scale factor.
- supported_scale_factors.push_back(SCALE_FACTOR_100P);
-#endif
-
-#if defined(OS_ANDROID)
- const gfx::Display display =
- gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
- const float display_density = display.device_scale_factor();
- const ScaleFactor closest = FindClosestScaleFactorUnsafe(display_density);
- if (closest != SCALE_FACTOR_100P)
- supported_scale_factors.push_back(closest);
-#elif defined(OS_IOS)
- gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
- if (display.device_scale_factor() > 1.0) {
- DCHECK_EQ(2.0, display.device_scale_factor());
- supported_scale_factors.push_back(SCALE_FACTOR_200P);
- } else {
- supported_scale_factors.push_back(SCALE_FACTOR_100P);
- }
-#elif defined(OS_MACOSX)
- if (base::mac::IsOSLionOrLater())
- supported_scale_factors.push_back(SCALE_FACTOR_200P);
-#elif defined(OS_WIN)
- // Have high-DPI resources for 140% and 180% scaling on Windows based on
- // default scaling for Metro mode. Round to nearest supported scale in
- // all cases.
- if (gfx::IsInHighDPIMode()) {
- supported_scale_factors.push_back(SCALE_FACTOR_140P);
- supported_scale_factors.push_back(SCALE_FACTOR_180P);
- }
-#elif defined(OS_CHROMEOS)
- // TODO(oshima): Include 200P only if the device support 200P
- supported_scale_factors.push_back(SCALE_FACTOR_200P);
-#endif
- ui::SetSupportedScaleFactors(supported_scale_factors);
-}
-
void ResourceBundle::FreeImages() {
images_.clear();
}
@@ -608,8 +554,8 @@ void ResourceBundle::AddDataPackFromPathInternal(const base::FilePath& path,
void ResourceBundle::AddDataPack(DataPack* data_pack) {
data_packs_.push_back(data_pack);
- if (GetImageScale(data_pack->GetScaleFactor()) >
- GetImageScale(max_scale_factor_))
+ if (GetScaleFactorScale(data_pack->GetScaleFactor()) >
+ GetScaleFactorScale(max_scale_factor_))
max_scale_factor_ = data_pack->GetScaleFactor();
}
diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h
index bea12c1..f9a34df 100644
--- a/ui/base/resource/resource_bundle.h
+++ b/ui/base/resource/resource_bundle.h
@@ -255,7 +255,9 @@ class UI_EXPORT ResourceBundle {
// Returns the maximum scale factor currently loaded.
// Returns SCALE_FACTOR_100P if no resource is loaded.
- ScaleFactor GetMaxScaleFactor() const;
+ ScaleFactor max_scale_factor() const {
+ return max_scale_factor_;
+ }
private:
FRIEND_TEST_ALL_PREFIXES(ResourceBundleTest, DelegateGetPathForLocalePack);
@@ -272,9 +274,6 @@ class UI_EXPORT ResourceBundle {
explicit ResourceBundle(Delegate* delegate);
~ResourceBundle();
- // Shared initialization.
- static void InitSharedInstance(Delegate* delegate);
-
// Free skia_images_.
void FreeImages();
diff --git a/ui/base/resource/resource_bundle_ios.mm b/ui/base/resource/resource_bundle_ios.mm
index d947c2f..c1daa91 100644
--- a/ui/base/resource/resource_bundle_ios.mm
+++ b/ui/base/resource/resource_bundle_ios.mm
@@ -109,7 +109,7 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
// Load the raw data from the resource pack at the current supported scale
// factor. This code assumes that only one of the possible scale factors is
// supported at runtime, based on the device resolution.
- ui::ScaleFactor scale_factor = GetMaxScaleFactor();
+ ui::ScaleFactor scale_factor = ui::GetMaxScaleFactor();
scoped_refptr<base::RefCountedStaticMemory> data(
LoadDataResourceBytesForScale(resource_id, scale_factor));
@@ -125,7 +125,7 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
bool is_fallback = PNGContainsFallbackMarker(data->front(), data->size());
// Create the image from the data.
- CGFloat target_scale = ui::GetImageScale(scale_factor);
+ CGFloat target_scale = ui::GetScaleFactorScale(scale_factor);
CGFloat source_scale = is_fallback ? 1.0 : target_scale;
base::scoped_nsobject<UIImage> ui_image(
[[UIImage alloc] initWithData:ns_data scale:source_scale]);
diff --git a/ui/base/resource/resource_bundle_unittest.cc b/ui/base/resource/resource_bundle_unittest.cc
index e50d6b4..6a7b2b7 100644
--- a/ui/base/resource/resource_bundle_unittest.cc
+++ b/ui/base/resource/resource_bundle_unittest.cc
@@ -433,10 +433,6 @@ TEST_F(ResourceBundleImageTest, GetRawDataResource) {
// Test requesting image reps at various scale factors from the image returned
// via ResourceBundle::GetImageNamed().
TEST_F(ResourceBundleImageTest, GetImageNamed) {
- std::vector<ScaleFactor> supported_factors;
- supported_factors.push_back(SCALE_FACTOR_100P);
- supported_factors.push_back(SCALE_FACTOR_200P);
- test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
base::FilePath data_1x_path = dir_path().AppendASCII("sample_1x.pak");
base::FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak");
@@ -449,44 +445,35 @@ TEST_F(ResourceBundleImageTest, GetImageNamed) {
resource_bundle->AddDataPackFromPath(data_1x_path, SCALE_FACTOR_100P);
resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P);
- EXPECT_EQ(SCALE_FACTOR_200P, resource_bundle->GetMaxScaleFactor());
+ EXPECT_EQ(SCALE_FACTOR_200P, resource_bundle->max_scale_factor());
gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
#if defined(OS_CHROMEOS)
// ChromeOS loads highest scale factor first.
- EXPECT_EQ(ui::SCALE_FACTOR_200P,
- GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
+ EXPECT_EQ(ui::SCALE_FACTOR_200P, image_skia->image_reps()[0].scale_factor());
#else
- EXPECT_EQ(ui::SCALE_FACTOR_100P,
- GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, image_skia->image_reps()[0].scale_factor());
#endif
// Resource ID 3 exists in both 1x and 2x paks. Image reps should be
// available for both scale factors in |image_skia|.
gfx::ImageSkiaRep image_rep =
- image_skia->GetRepresentation(GetImageScale(ui::SCALE_FACTOR_100P));
- EXPECT_EQ(ui::SCALE_FACTOR_100P, GetSupportedScaleFactor(image_rep.scale()));
- image_rep =
- image_skia->GetRepresentation(GetImageScale(ui::SCALE_FACTOR_200P));
- EXPECT_EQ(ui::SCALE_FACTOR_200P, GetSupportedScaleFactor(image_rep.scale()));
+ image_skia->GetRepresentation(ui::SCALE_FACTOR_100P);
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor());
+ image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_200P);
+ EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor());
// The 1.4x pack was not loaded. Requesting the 1.4x resource should return
// either the 1x or the 2x resource.
- image_rep = image_skia->GetRepresentation(
- ui::GetImageScale(ui::SCALE_FACTOR_140P));
- ui::ScaleFactor scale_factor = GetSupportedScaleFactor(image_rep.scale());
- EXPECT_TRUE(scale_factor == ui::SCALE_FACTOR_100P ||
- scale_factor == ui::SCALE_FACTOR_200P);
+ image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_140P);
+ EXPECT_TRUE(image_rep.scale_factor() == ui::SCALE_FACTOR_100P ||
+ image_rep.scale_factor() == ui::SCALE_FACTOR_200P);
}
// Test that GetImageNamed() behaves properly for images which GRIT has
// annotated as having fallen back to 1x.
TEST_F(ResourceBundleImageTest, GetImageNamedFallback1x) {
- std::vector<ScaleFactor> supported_factors;
- supported_factors.push_back(SCALE_FACTOR_100P);
- supported_factors.push_back(SCALE_FACTOR_200P);
- test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
base::FilePath data_path = dir_path().AppendASCII("sample.pak");
base::FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak");
@@ -508,8 +495,8 @@ TEST_F(ResourceBundleImageTest, GetImageNamedFallback1x) {
// The image rep for 2x should be available. It should be resized to the
// proper 2x size.
gfx::ImageSkiaRep image_rep =
- image_skia->GetRepresentation(GetImageScale(ui::SCALE_FACTOR_200P));
- EXPECT_EQ(ui::SCALE_FACTOR_200P, GetSupportedScaleFactor(image_rep.scale()));
+ image_skia->GetRepresentation(ui::SCALE_FACTOR_200P);
+ EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor());
EXPECT_EQ(20, image_rep.pixel_width());
EXPECT_EQ(20, image_rep.pixel_height());
}
@@ -519,12 +506,6 @@ TEST_F(ResourceBundleImageTest, GetImageNamedFallback1x) {
// requires rounding as a result of using a non-integer scale factor.
// Scale factors of 140 and 1805 are Windows specific.
TEST_F(ResourceBundleImageTest, GetImageNamedFallback1xRounding) {
- std::vector<ScaleFactor> supported_factors;
- supported_factors.push_back(SCALE_FACTOR_100P);
- supported_factors.push_back(SCALE_FACTOR_140P);
- supported_factors.push_back(SCALE_FACTOR_180P);
- test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
-
base::FilePath data_path = dir_path().AppendASCII("sample.pak");
base::FilePath data_140P_path = dir_path().AppendASCII("sample_140P.pak");
base::FilePath data_180P_path = dir_path().AppendASCII("sample_180P.pak");
@@ -546,11 +527,9 @@ TEST_F(ResourceBundleImageTest, GetImageNamedFallback1xRounding) {
// Non-integer dimensions should be rounded up.
gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
gfx::ImageSkiaRep image_rep =
- image_skia->GetRepresentation(
- GetImageScale(ui::SCALE_FACTOR_140P));
+ image_skia->GetRepresentation(ui::SCALE_FACTOR_140P);
EXPECT_EQ(12, image_rep.pixel_width());
- image_rep = image_skia->GetRepresentation(
- GetImageScale(ui::SCALE_FACTOR_180P));
+ image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_180P);
EXPECT_EQ(15, image_rep.pixel_width());
}
#endif
@@ -568,7 +547,7 @@ TEST_F(ResourceBundleImageTest, FallbackToNone) {
gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
EXPECT_EQ(1u, image_skia->image_reps().size());
EXPECT_EQ(ui::SCALE_FACTOR_100P,
- GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
+ image_skia->image_reps()[0].scale_factor());
}
} // namespace ui
diff --git a/ui/base/resource/resource_bundle_win.cc b/ui/base/resource/resource_bundle_win.cc
index cb99e20..0a2b185 100644
--- a/ui/base/resource/resource_bundle_win.cc
+++ b/ui/base/resource/resource_bundle_win.cc
@@ -44,7 +44,7 @@ void ResourceBundle::LoadCommonResources() {
// scaled up from 100% touch.
float scale = gfx::win::GetDeviceScaleFactor();
bool force_touch_resources = false;
- switch(ui::GetSupportedScaleFactor(scale)) {
+ switch(ui::GetScaleFactorFromScale(scale)) {
case ui::SCALE_FACTOR_180P:
AddDataPackFromPath(GetResourcesPakFilePath(
"chrome_touch_180_percent.pak"),
diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc
index a218392..58c2c69 100644
--- a/ui/base/x/x11_util.cc
+++ b/ui/base/x/x11_util.cc
@@ -1226,7 +1226,7 @@ bool CopyAreaToCanvas(XID drawable,
image->bytes_per_line);
bitmap.setPixels(image->data);
gfx::ImageSkia image_skia;
- gfx::ImageSkiaRep image_rep(bitmap, canvas->image_scale());
+ gfx::ImageSkiaRep image_rep(bitmap, canvas->scale_factor());
image_skia.AddRepresentation(image_rep);
canvas->DrawImageInt(image_skia, dest_offset.x(), dest_offset.y());
} else {
diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc
index a960609..1e7a029 100644
--- a/ui/compositor/layer.cc
+++ b/ui/compositor/layer.cc
@@ -639,7 +639,7 @@ void Layer::PaintContents(SkCanvas* sk_canvas,
gfx::RectF* opaque) {
TRACE_EVENT0("ui", "Layer::PaintContents");
scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling(
- sk_canvas, device_scale_factor_));
+ sk_canvas, ui::GetScaleFactorFromScale(device_scale_factor_)));
bool scale_content = scale_content_;
if (scale_content) {
diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc
index eb0834b..b59d2a0 100644
--- a/ui/gfx/canvas.cc
+++ b/ui/gfx/canvas.cc
@@ -23,10 +23,11 @@
namespace gfx {
-Canvas::Canvas(const Size& size, float image_scale, bool is_opaque)
- : image_scale_(image_scale),
+Canvas::Canvas(const Size& size, ui::ScaleFactor scale_factor, bool is_opaque)
+ : scale_factor_(scale_factor),
canvas_(NULL) {
- Size pixel_size = ToCeiledSize(ScaleSize(size, image_scale));
+ Size pixel_size = ToCeiledSize(
+ ScaleSize(size, ui::GetScaleFactorScale(scale_factor)));
owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(),
pixel_size.height(),
is_opaque));
@@ -38,24 +39,24 @@ Canvas::Canvas(const Size& size, float image_scale, bool is_opaque)
owned_canvas_->clear(SkColorSetARGB(0, 0, 0, 0));
#endif
- SkScalar scale_scalar = SkFloatToScalar(image_scale);
- canvas_->scale(scale_scalar, scale_scalar);
+ SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor));
+ canvas_->scale(scale, scale);
}
Canvas::Canvas(const ImageSkiaRep& image_rep, bool is_opaque)
- : image_scale_(image_rep.scale()),
+ : scale_factor_(image_rep.scale_factor()),
owned_canvas_(skia::AdoptRef(
skia::CreatePlatformCanvas(image_rep.pixel_width(),
image_rep.pixel_height(),
is_opaque))),
canvas_(owned_canvas_.get()) {
- SkScalar scale_scalar = SkFloatToScalar(image_scale_);
- canvas_->scale(scale_scalar, scale_scalar);
+ SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor_));
+ canvas_->scale(scale, scale);
DrawImageInt(ImageSkia(image_rep), 0, 0);
}
Canvas::Canvas()
- : image_scale_(1.0),
+ : scale_factor_(ui::SCALE_FACTOR_100P),
owned_canvas_(skia::AdoptRef(skia::CreatePlatformCanvas(0, 0, false))),
canvas_(owned_canvas_.get()) {
}
@@ -65,21 +66,22 @@ Canvas::~Canvas() {
// static
Canvas* Canvas::CreateCanvasWithoutScaling(SkCanvas* canvas,
- float image_scale) {
- return new Canvas(canvas, image_scale);
+ ui::ScaleFactor scale_factor) {
+ return new Canvas(canvas, scale_factor);
}
void Canvas::RecreateBackingCanvas(const Size& size,
- float image_scale,
+ ui::ScaleFactor scale_factor,
bool is_opaque) {
- image_scale_ = image_scale;
- Size pixel_size = ToFlooredSize(ScaleSize(size, image_scale));
+ scale_factor_ = scale_factor;
+ Size pixel_size = ToFlooredSize(
+ ScaleSize(size, ui::GetScaleFactorScale(scale_factor)));
owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(),
pixel_size.height(),
is_opaque));
canvas_ = owned_canvas_.get();
- SkScalar scale_scalar = SkFloatToScalar(image_scale);
- canvas_->scale(scale_scalar, scale_scalar);
+ SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor_));
+ canvas_->scale(scale, scale);
}
// static
@@ -134,7 +136,7 @@ ImageSkiaRep Canvas::ExtractImageRep() const {
SkBitmap result;
device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config);
- return ImageSkiaRep(result, image_scale_);
+ return ImageSkiaRep(result, scale_factor_);
}
void Canvas::DrawDashedRect(const Rect& rect, SkColor color) {
@@ -327,7 +329,7 @@ void Canvas::DrawImageInt(const ImageSkia& image,
if (image_rep.is_null())
return;
const SkBitmap& bitmap = image_rep.sk_bitmap();
- float bitmap_scale = image_rep.scale();
+ float bitmap_scale = image_rep.GetScale();
canvas_->save();
canvas_->scale(SkFloatToScalar(1.0f / bitmap_scale),
@@ -390,7 +392,7 @@ void Canvas::DrawImageInt(const ImageSkia& image,
if (src_w == dest_w && src_h == dest_h &&
user_scale_x == 1.0f && user_scale_y == 1.0f &&
- image_rep.scale() == 1.0f) {
+ image_rep.scale_factor() == ui::SCALE_FACTOR_100P) {
// Workaround for apparent bug in Skia that causes image to occasionally
// shift.
SkIRect src_rect = { src_x, src_y, src_x + src_w, src_y + src_h };
@@ -572,8 +574,8 @@ void Canvas::Transform(const gfx::Transform& transform) {
canvas_->concat(transform.matrix());
}
-Canvas::Canvas(SkCanvas* canvas, float image_scale)
- : image_scale_(image_scale),
+Canvas::Canvas(SkCanvas* canvas, ui::ScaleFactor scale_factor)
+ : scale_factor_(scale_factor),
owned_canvas_(),
canvas_(canvas) {
DCHECK(canvas);
@@ -599,7 +601,7 @@ const ImageSkiaRep& Canvas::GetImageRepToPaint(
const ImageSkia& image,
float user_additional_scale_x,
float user_additional_scale_y) const {
- const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_);
+ const ImageSkiaRep& image_rep = image.GetRepresentation(scale_factor_);
if (!image_rep.is_null()) {
SkMatrix m = canvas_->getTotalMatrix();
@@ -608,7 +610,7 @@ const ImageSkiaRep& Canvas::GetImageRepToPaint(
float scale_y = SkScalarToFloat(SkScalarAbs(m.getScaleY())) *
user_additional_scale_y;
- float bitmap_scale = image_rep.scale();
+ float bitmap_scale = image_rep.GetScale();
if (scale_x < bitmap_scale || scale_y < bitmap_scale)
const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap();
}
diff --git a/ui/gfx/canvas.h b/ui/gfx/canvas.h
index d6479cc..c8996a2 100644
--- a/ui/gfx/canvas.h
+++ b/ui/gfx/canvas.h
@@ -90,34 +90,34 @@ class UI_EXPORT Canvas {
NO_SUBPIXEL_RENDERING = 1 << 10,
};
- // Creates an empty canvas with image_scale of 1x.
+ // Creates an empty canvas with scale factor of 1x.
Canvas();
- // Creates canvas with provided DIP |size| and |image_scale|.
+ // Creates canvas with provided DIP |size| and |scale_factor|.
// If this canvas is not opaque, it's explicitly cleared to transparent before
// being returned.
- Canvas(const Size& size, float image_scale, bool is_opaque);
+ Canvas(const Size& size, ui::ScaleFactor scale_factor, bool is_opaque);
- // Constructs a canvas with the size and the image_scale of the provided
- // |image_rep|, and draws the |image_rep| into it.
+ // Constructs a canvas with the size and the scale factor of the
+ // provided |image_rep|, and draws the |image_rep| into it.
Canvas(const ImageSkiaRep& image_rep, bool is_opaque);
virtual ~Canvas();
- // Creates a Canvas backed by an |sk_canvas| with |image_scale_|.
- // |sk_canvas| is assumed to be already scaled based on |image_scale|
+ // Creates a Canvas backed by an |sk_canvas| with |scale_factor|.
+ // |sk_canvas| is assumed to be already scaled based on |scale_factor|
// so no additional scaling is applied.
static Canvas* CreateCanvasWithoutScaling(SkCanvas* sk_canvas,
- float image_scale);
+ ui::ScaleFactor scale_factor);
- // Recreates the backing platform canvas with DIP |size| and |image_scale_|.
+ // Recreates the backing platform canvas with DIP |size| and |scale_factor|.
// If the canvas is not opaque, it is explicitly cleared.
// This method is public so that canvas_skia_paint can recreate the platform
// canvas after having initialized the canvas.
- // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that
+ // TODO(pkotwicz): Push the scale factor into skia::PlatformCanvas such that
// this method can be private.
void RecreateBackingCanvas(const Size& size,
- float image_scale,
+ ui::ScaleFactor scale_factor,
bool is_opaque);
// Compute the size required to draw some text with the provided fonts.
@@ -451,16 +451,16 @@ class UI_EXPORT Canvas {
skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); }
SkCanvas* sk_canvas() const { return canvas_; }
- float image_scale() const { return image_scale_; }
+ ui::ScaleFactor scale_factor() const { return scale_factor_; }
private:
- Canvas(SkCanvas* canvas, float image_scale);
+ Canvas(SkCanvas* canvas, ui::ScaleFactor scale_factor);
// Test whether the provided rectangle intersects the current clip rect.
bool IntersectsClipRectInt(int x, int y, int w, int h);
bool IntersectsClipRect(const Rect& rect);
- // Returns the image rep which best matches the canvas |image_scale_|.
+ // Returns the image rep which best matches the canvas |scale_factor_|.
// Returns a null image rep if |image| contains no image reps.
// Builds mip map for returned image rep if necessary.
//
@@ -473,8 +473,8 @@ class UI_EXPORT Canvas {
// The device scale factor at which drawing on this canvas occurs.
// An additional scale can be applied via Canvas::Scale(). However,
- // Canvas::Scale() does not affect |image_scale_|.
- float image_scale_;
+ // Canvas::Scale() does not affect |scale_factor_|.
+ ui::ScaleFactor scale_factor_;
skia::RefPtr<skia::PlatformCanvas> owned_canvas_;
SkCanvas* canvas_;
diff --git a/ui/gfx/canvas_paint_gtk.cc b/ui/gfx/canvas_paint_gtk.cc
index 3faa064..4c185c0 100644
--- a/ui/gfx/canvas_paint_gtk.cc
+++ b/ui/gfx/canvas_paint_gtk.cc
@@ -53,7 +53,7 @@ CanvasSkiaPaint::~CanvasSkiaPaint() {
void CanvasSkiaPaint::Init(bool opaque) {
GdkRectangle bounds = rectangle();
RecreateBackingCanvas(gfx::Size(bounds.width, bounds.height),
- 1.0f, opaque);
+ ui::SCALE_FACTOR_100P, opaque);
skia::PlatformCanvas* canvas = platform_canvas();
@@ -66,4 +66,4 @@ void CanvasSkiaPaint::Init(bool opaque) {
} // namespace gfx
-
+
diff --git a/ui/gfx/canvas_paint_mac.mm b/ui/gfx/canvas_paint_mac.mm
index 8ba697d..c8796af 100644
--- a/ui/gfx/canvas_paint_mac.mm
+++ b/ui/gfx/canvas_paint_mac.mm
@@ -58,8 +58,9 @@ void CanvasSkiaPaint::Init(bool opaque) {
// Assume that the x scale and the y scale are the same.
CGFloat scale = scaled_unit_rect.size.width;
+ ui::ScaleFactor scale_factor = ui::GetScaleFactorFromScale(scale);
gfx::Size size(NSWidth(rectangle_), NSHeight(rectangle_));
- RecreateBackingCanvas(size, scale, opaque);
+ RecreateBackingCanvas(size, scale_factor, opaque);
skia::PlatformCanvas* canvas = platform_canvas();
canvas->clear(SkColorSetARGB(0, 0, 0, 0));
@@ -73,4 +74,4 @@ void CanvasSkiaPaint::Init(bool opaque) {
} // namespace skia
-
+
diff --git a/ui/gfx/canvas_paint_win.cc b/ui/gfx/canvas_paint_win.cc
index 7d20fbc..71c8367 100644
--- a/ui/gfx/canvas_paint_win.cc
+++ b/ui/gfx/canvas_paint_win.cc
@@ -56,7 +56,7 @@ void CanvasSkiaPaint::Init(bool opaque) {
const int height = ps_.rcPaint.bottom - ps_.rcPaint.top;
RecreateBackingCanvas(gfx::Size(width, height),
- gfx::win::GetDeviceScaleFactor(),
+ ui::GetScaleFactorFromScale(gfx::win::GetDeviceScaleFactor()),
opaque);
skia::PlatformCanvas* canvas = platform_canvas();
diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc
index b6830d5..ef8ee36 100644
--- a/ui/gfx/canvas_skia.cc
+++ b/ui/gfx/canvas_skia.cc
@@ -350,7 +350,7 @@ void Canvas::DrawStringRectWithHalo(const base::string16& text,
// Create a temporary buffer filled with the halo color. It must leave room
// for the 1-pixel border around the text.
Size size(display_rect.width() + 2, display_rect.height() + 2);
- Canvas text_canvas(size, image_scale(), true);
+ Canvas text_canvas(size, scale_factor(), true);
SkPaint bkgnd_paint;
bkgnd_paint.setColor(halo_color);
text_canvas.DrawRect(Rect(size), bkgnd_paint);
@@ -381,7 +381,7 @@ void Canvas::DrawStringRectWithHalo(const base::string16& text,
// Draw the halo bitmap with blur.
ImageSkia text_image = ImageSkia(ImageSkiaRep(text_bitmap,
- text_canvas.image_scale()));
+ text_canvas.scale_factor()));
DrawImageInt(text_image, display_rect.x() - 1, display_rect.y() - 1);
}
diff --git a/ui/gfx/color_analysis_unittest.cc b/ui/gfx/color_analysis_unittest.cc
index 7757eb9..c76681c 100644
--- a/ui/gfx/color_analysis_unittest.cc
+++ b/ui/gfx/color_analysis_unittest.cc
@@ -295,7 +295,7 @@ TEST_F(ColorAnalysisTest, ComputeColorCovarianceTrivial) {
}
TEST_F(ColorAnalysisTest, ComputeColorCovarianceWithCanvas) {
- gfx::Canvas canvas(gfx::Size(250, 200), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(250, 200), ui::SCALE_FACTOR_100P, true);
// The image consists of vertical stripes, with color bands set to 100
// in overlapping stripes 150 pixels wide.
canvas.FillRect(gfx::Rect(0, 0, 50, 200), SkColorSetRGB(100, 0, 0));
@@ -364,7 +364,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionSingleColor) {
TEST_F(ColorAnalysisTest, ApplyColorReductionBlackAndWhite) {
// Check with images with multiple colors. This is really different only when
// the result is scaled.
- gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(300, 200), ui::SCALE_FACTOR_100P, true);
// The image consists of vertical non-overlapping stripes 150 pixels wide.
canvas.FillRect(gfx::Rect(0, 0, 150, 200), SkColorSetRGB(0, 0, 0));
@@ -404,7 +404,7 @@ TEST_F(ColorAnalysisTest, ApplyColorReductionBlackAndWhite) {
TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) {
// Check with images with multiple colors. This is really different only when
// the result is scaled.
- gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(300, 200), ui::SCALE_FACTOR_100P, true);
// The image consists of vertical non-overlapping stripes 100 pixels wide.
canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(100, 0, 0));
@@ -452,7 +452,7 @@ TEST_F(ColorAnalysisTest, ComputePrincipalComponentImageNotComputable) {
}
TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) {
- gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true);
+ gfx::Canvas canvas(gfx::Size(300, 200), ui::SCALE_FACTOR_100P, true);
// The image consists of vertical non-overlapping stripes 100 pixels wide.
canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(10, 10, 10));
diff --git a/ui/gfx/image/canvas_image_source.cc b/ui/gfx/image/canvas_image_source.cc
index b336b31..747625a 100644
--- a/ui/gfx/image/canvas_image_source.cc
+++ b/ui/gfx/image/canvas_image_source.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "ui/gfx/canvas.h"
+#include "ui/base/layout.h"
namespace gfx {
@@ -17,8 +18,9 @@ CanvasImageSource::CanvasImageSource(const gfx::Size& size, bool is_opaque)
is_opaque_(is_opaque) {
}
-gfx::ImageSkiaRep CanvasImageSource::GetImageForScale(float scale) {
- gfx::Canvas canvas(size_, scale, is_opaque_);
+gfx::ImageSkiaRep CanvasImageSource::GetImageForScale(
+ ui::ScaleFactor scale_factor) {
+ gfx::Canvas canvas(size_, scale_factor, is_opaque_);
Draw(&canvas);
return canvas.ExtractImageRep();
}
diff --git a/ui/gfx/image/canvas_image_source.h b/ui/gfx/image/canvas_image_source.h
index 88e891d..8373387 100644
--- a/ui/gfx/image/canvas_image_source.h
+++ b/ui/gfx/image/canvas_image_source.h
@@ -30,7 +30,8 @@ class UI_EXPORT CanvasImageSource : public gfx::ImageSkiaSource {
const gfx::Size& size() const { return size_; };
// Overridden from gfx::ImageSkiaSource.
- virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE;
+ virtual gfx::ImageSkiaRep GetImageForScale(
+ ui::ScaleFactor scale_factor) OVERRIDE;
protected:
virtual ~CanvasImageSource() {}
diff --git a/ui/gfx/image/image.cc b/ui/gfx/image/image.cc
index 91b9e69..f089c83 100644
--- a/ui/gfx/image/image.cc
+++ b/ui/gfx/image/image.cc
@@ -43,7 +43,7 @@ const ImageSkia ImageSkiaFromGdkPixbuf(GdkPixbuf* pixbuf) {
CHECK(pixbuf);
gfx::Canvas canvas(gfx::Size(gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf)),
- 1.0f,
+ ui::SCALE_FACTOR_100P,
false);
skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas());
cairo_t* cr = scoped_platform_paint.GetPlatformSurface();
@@ -65,7 +65,7 @@ GdkPixbuf* GdkPixbufFromPNG(
const std::vector<gfx::ImagePNGRep>& image_png_reps) {
scoped_refptr<base::RefCountedMemory> png_bytes(NULL);
for (size_t i = 0; i < image_png_reps.size(); ++i) {
- if (image_png_reps[i].scale == 1.0f)
+ if (image_png_reps[i].scale_factor == ui::SCALE_FACTOR_100P)
png_bytes = image_png_reps[i].raw_data;
}
@@ -142,7 +142,7 @@ ImageSkia* GetErrorImageSkia() {
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
bitmap.allocPixels();
bitmap.eraseRGB(0xff, 0, 0);
- return new gfx::ImageSkia(gfx::ImageSkiaRep(bitmap, 1.0f));
+ return new gfx::ImageSkia(gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P));
}
ImageSkia* ImageSkiaFromPNG(
@@ -159,22 +159,23 @@ ImageSkia* ImageSkiaFromPNG(
if (!gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(),
&bitmap)) {
LOG(ERROR) << "Unable to decode PNG for "
- << image_png_reps[i].scale
+ << ui::GetScaleFactorScale(image_png_reps[i].scale_factor)
<< ".";
return GetErrorImageSkia();
}
image_skia->AddRepresentation(gfx::ImageSkiaRep(
- bitmap, image_png_reps[i].scale));
+ bitmap, image_png_reps[i].scale_factor));
}
return image_skia.release();
}
scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia(
const ImageSkia* image_skia) {
- ImageSkiaRep image_skia_rep = image_skia->GetRepresentation(1.0f);
+ ImageSkiaRep image_skia_rep = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_100P);
scoped_refptr<base::RefCountedBytes> png_bytes(new base::RefCountedBytes());
- if (image_skia_rep.scale() != 1.0f ||
+ if (image_skia_rep.scale_factor() != ui::SCALE_FACTOR_100P ||
!gfx::PNGCodec::EncodeBGRASkBitmap(image_skia_rep.sk_bitmap(), false,
&png_bytes->data())) {
return NULL;
@@ -273,7 +274,7 @@ class ImageRepPNG : public ImageRep {
if (!size_cache_) {
for (std::vector<ImagePNGRep>::const_iterator it = image_reps().begin();
it != image_reps().end(); ++it) {
- if (it->scale == 1.0f) {
+ if (it->scale_factor == ui::SCALE_FACTOR_100P) {
size_cache_.reset(new gfx::Size(it->Size()));
return *size_cache_;
}
@@ -603,7 +604,7 @@ Image Image::CreateFrom1xPNGBytes(const unsigned char* input,
scoped_refptr<base::RefCountedBytes> raw_data(new base::RefCountedBytes());
raw_data->data().assign(input, input + input_size);
std::vector<gfx::ImagePNGRep> image_reps;
- image_reps.push_back(ImagePNGRep(raw_data, 1.0f));
+ image_reps.push_back(ImagePNGRep(raw_data, ui::SCALE_FACTOR_100P));
return gfx::Image(image_reps);
}
@@ -771,7 +772,7 @@ scoped_refptr<base::RefCountedMemory> Image::As1xPNGBytes() const {
const std::vector<gfx::ImagePNGRep>& image_png_reps =
rep->AsImageRepPNG()->image_reps();
for (size_t i = 0; i < image_png_reps.size(); ++i) {
- if (image_png_reps[i].scale == 1.0f)
+ if (image_png_reps[i].scale_factor == ui::SCALE_FACTOR_100P)
return image_png_reps[i].raw_data;
}
return new base::RefCountedBytes();
@@ -826,7 +827,8 @@ scoped_refptr<base::RefCountedMemory> Image::As1xPNGBytes() const {
// final type eg (converting from ImageRepSkia to ImageRepPNG to get an
// ImageRepCocoa).
std::vector<ImagePNGRep> image_png_reps;
- image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(png_bytes,
+ ui::SCALE_FACTOR_100P));
rep = new internal::ImageRepPNG(image_png_reps);
AddRepresentation(rep);
return png_bytes;
diff --git a/ui/gfx/image/image_ios.mm b/ui/gfx/image/image_ios.mm
index f792e0d..01a3c87 100644
--- a/ui/gfx/image/image_ios.mm
+++ b/ui/gfx/image/image_ios.mm
@@ -48,7 +48,7 @@ UIImage* CreateErrorUIImage(float scale) {
// Converts from ImagePNGRep to UIImage.
UIImage* CreateUIImageFromImagePNGRep(const gfx::ImagePNGRep& image_png_rep) {
- float scale = image_png_rep.scale;
+ float scale = ui::GetScaleFactorScale(image_png_rep.scale_factor);
scoped_refptr<base::RefCountedMemory> png = image_png_rep.raw_data;
CHECK(png.get());
NSData* data = [NSData dataWithBytes:png->front() length:png->size()];
@@ -74,16 +74,17 @@ scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromUIImage(
UIImage* CreateUIImageFromPNG(
const std::vector<gfx::ImagePNGRep>& image_png_reps) {
- float ideal_scale = ImageSkia::GetMaxSupportedScale();
+ ui::ScaleFactor ideal_scale_factor = ui::GetMaxScaleFactor();
+ float ideal_scale = ui::GetScaleFactorScale(ideal_scale_factor);
if (image_png_reps.empty())
return CreateErrorUIImage(ideal_scale);
- // Find best match for |ideal_scale|.
+ // Find best match for |ideal_scale_factor|.
float smallest_diff = std::numeric_limits<float>::max();
size_t closest_index = 0u;
for (size_t i = 0; i < image_png_reps.size(); ++i) {
- float scale = image_png_reps[i].scale;
+ float scale = ui::GetScaleFactorScale(image_png_reps[i].scale_factor);
float diff = std::abs(ideal_scale - scale);
if (diff < smallest_diff) {
smallest_diff = diff;
@@ -101,8 +102,9 @@ scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia(
// TODO(rohitrao): Rewrite the callers of this function to save the UIImage
// representation in the gfx::Image. If we're generating it, we might as well
// hold on to it.
- const gfx::ImageSkiaRep& image_skia_rep = skia->GetRepresentation(1.0f);
- if (image_skia_rep.scale() != 1.0f)
+ const gfx::ImageSkiaRep& image_skia_rep = skia->GetRepresentation(
+ ui::SCALE_FACTOR_100P);
+ if (image_skia_rep.scale_factor() != ui::SCALE_FACTOR_100P)
return NULL;
UIImage* image = UIImageFromImageSkiaRep(image_skia_rep);
@@ -117,8 +119,8 @@ ImageSkia* ImageSkiaFromPNG(
for (size_t i = 0; i < image_png_reps.size(); ++i) {
base::scoped_nsobject<UIImage> uiimage(
CreateUIImageFromImagePNGRep(image_png_reps[i]));
- gfx::ImageSkiaRep image_skia_rep = ImageSkiaRepOfScaleFromUIImage(
- uiimage, image_png_reps[i].scale);
+ gfx::ImageSkiaRep image_skia_rep = ImageSkiaRepOfScaleFactorFromUIImage(
+ uiimage, image_png_reps[i].scale_factor);
if (!image_skia_rep.is_null())
image_skia->AddRepresentation(image_skia_rep);
}
diff --git a/ui/gfx/image/image_mac.mm b/ui/gfx/image/image_mac.mm
index 15a5610..d03b48e 100644
--- a/ui/gfx/image/image_mac.mm
+++ b/ui/gfx/image/image_mac.mm
@@ -65,7 +65,7 @@ NSImage* NSImageFromPNG(const std::vector<gfx::ImagePNGRep>& image_png_reps,
[[NSBitmapImageRep alloc] initWithData:ns_data]);
if (!ns_image_rep) {
LOG(ERROR) << "Unable to decode PNG at "
- << image_png_reps[i].scale
+ << ui::GetScaleFactorScale(image_png_reps[i].scale_factor)
<< ".";
return GetErrorNSImage();
}
@@ -88,7 +88,7 @@ NSImage* NSImageFromPNG(const std::vector<gfx::ImagePNGRep>& image_png_reps,
}
if (!image.get()) {
- float scale = image_png_reps[i].scale;
+ float scale = ui::GetScaleFactorScale(image_png_reps[i].scale_factor);
NSSize image_size = NSMakeSize([ns_image_rep pixelsWide] / scale,
[ns_image_rep pixelsHigh] / scale);
image.reset([[NSImage alloc] initWithSize:image_size]);
diff --git a/ui/gfx/image/image_mac_unittest.mm b/ui/gfx/image/image_mac_unittest.mm
index 2cbbd117..250deeb 100644
--- a/ui/gfx/image/image_mac_unittest.mm
+++ b/ui/gfx/image/image_mac_unittest.mm
@@ -16,26 +16,26 @@
namespace {
// Returns true if the structure of |ns_image| matches the structure
-// described by |width|, |height|, and |scales|.
+// described by |width|, |height|, and |scale_factors|.
// The structure matches if:
// - |ns_image| is not nil.
-// - |ns_image| has NSImageReps of |scales|.
+// - |ns_image| has NSImageReps of |scale_factors|.
// - Each of the NSImageReps has a pixel size of [|ns_image| size] *
-// scale.
+// scale_factor.
bool NSImageStructureMatches(
NSImage* ns_image,
int width,
int height,
- const std::vector<float>& scales) {
+ const std::vector<ui::ScaleFactor>& scale_factors) {
if (!ns_image ||
[ns_image size].width != width ||
[ns_image size].height != height ||
- [ns_image representations].count != scales.size()) {
+ [ns_image representations].count != scale_factors.size()) {
return false;
}
- for (size_t i = 0; i < scales.size(); ++i) {
- float scale = scales[i];
+ for (size_t i = 0; i < scale_factors.size(); ++i) {
+ float scale = ui::GetScaleFactorScale(scale_factors[i]);
bool found_match = false;
for (size_t j = 0; j < [ns_image representations].count; ++j) {
NSImageRep* ns_image_rep = [[ns_image representations] objectAtIndex:j];
@@ -74,14 +74,16 @@ void BitmapImageRep(int width, int height,
class ImageMacTest : public testing::Test {
public:
- ImageMacTest() {
- gfx::ImageSkia::SetSupportedScales(gfx::test::Get1xAnd2xScales());
+ ImageMacTest()
+ : supported_scale_factors_(gfx::test::Get1xAnd2xScaleFactors()) {
}
virtual ~ImageMacTest() {
}
private:
+ ui::test::ScopedSetSupportedScaleFactors supported_scale_factors_;
+
DISALLOW_COPY_AND_ASSIGN(ImageMacTest);
};
@@ -108,11 +110,11 @@ TEST_F(ImageMacTest, MultiResolutionNSImageToImageSkia) {
const gfx::ImageSkia* image_skia = image.ToImageSkia();
- std::vector<float> scales;
- scales.push_back(1.0f);
- scales.push_back(2.0f);
+ std::vector<ui::ScaleFactor> scale_factors;
+ scale_factors.push_back(ui::SCALE_FACTOR_100P);
+ scale_factors.push_back(ui::SCALE_FACTOR_200P);
EXPECT_TRUE(gt::ImageSkiaStructureMatches(*image_skia, kWidth1x, kHeight1x,
- scales));
+ scale_factors));
// ToImageSkia should create a second representation.
EXPECT_EQ(2u, image.RepresentationCount());
@@ -139,11 +141,11 @@ TEST_F(ImageMacTest, UnalignedMultiResolutionNSImageToImageSkia) {
const gfx::ImageSkia* image_skia = image.ToImageSkia();
- std::vector<float> scales;
- scales.push_back(1.0f);
- scales.push_back(2.0f);
+ std::vector<ui::ScaleFactor> scale_factors;
+ scale_factors.push_back(ui::SCALE_FACTOR_100P);
+ scale_factors.push_back(ui::SCALE_FACTOR_200P);
EXPECT_TRUE(gt::ImageSkiaStructureMatches(*image_skia, kWidth1x, kHeight1x,
- scales));
+ scale_factors));
// ToImageSkia should create a second representation.
EXPECT_EQ(2u, image.RepresentationCount());
@@ -157,9 +159,9 @@ TEST_F(ImageMacTest, MultiResolutionImageSkiaToNSImage) {
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(
- gt::CreateBitmap(kWidth1x, kHeight1x), 1.0f));
+ gt::CreateBitmap(kWidth1x, kHeight1x), ui::SCALE_FACTOR_100P));
image_skia.AddRepresentation(gfx::ImageSkiaRep(
- gt::CreateBitmap(kWidth2x, kHeight2x), 2.0f));
+ gt::CreateBitmap(kWidth2x, kHeight2x), ui::SCALE_FACTOR_200P));
gfx::Image image(image_skia);
@@ -168,10 +170,11 @@ TEST_F(ImageMacTest, MultiResolutionImageSkiaToNSImage) {
NSImage* ns_image = image.ToNSImage();
- std::vector<float> scales;
- scales.push_back(1.0f);
- scales.push_back(2.0f);
- EXPECT_TRUE(NSImageStructureMatches(ns_image, kWidth1x, kHeight1x, scales));
+ std::vector<ui::ScaleFactor> scale_factors;
+ scale_factors.push_back(ui::SCALE_FACTOR_100P);
+ scale_factors.push_back(ui::SCALE_FACTOR_200P);
+ EXPECT_TRUE(NSImageStructureMatches(ns_image, kWidth1x, kHeight1x,
+ scale_factors));
// Request for NSImage* should create a second representation.
EXPECT_EQ(2u, image.RepresentationCount());
@@ -184,16 +187,17 @@ TEST_F(ImageMacTest, MultiResolutionPNGToNSImage) {
scoped_refptr<base::RefCountedMemory> bytes1x = gt::CreatePNGBytes(kSize1x);
scoped_refptr<base::RefCountedMemory> bytes2x = gt::CreatePNGBytes(kSize2x);
std::vector<gfx::ImagePNGRep> image_png_reps;
- image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f));
- image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, 2.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, ui::SCALE_FACTOR_100P));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, ui::SCALE_FACTOR_200P));
gfx::Image image(image_png_reps);
NSImage* ns_image = image.ToNSImage();
- std::vector<float> scales;
- scales.push_back(1.0f);
- scales.push_back(2.0f);
- EXPECT_TRUE(NSImageStructureMatches(ns_image, kSize1x, kSize1x, scales));
+ std::vector<ui::ScaleFactor> scale_factors;
+ scale_factors.push_back(ui::SCALE_FACTOR_100P);
+ scale_factors.push_back(ui::SCALE_FACTOR_200P);
+ EXPECT_TRUE(NSImageStructureMatches(ns_image, kSize1x, kSize1x,
+ scale_factors));
// Converting from PNG to NSImage should not go through ImageSkia.
EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia));
@@ -201,9 +205,9 @@ TEST_F(ImageMacTest, MultiResolutionPNGToNSImage) {
// Convert to ImageSkia to check pixel contents of NSImageReps.
gfx::ImageSkia image_skia = gfx::ImageSkiaFromNSImage(ns_image);
EXPECT_TRUE(gt::IsEqual(bytes1x,
- image_skia.GetRepresentation(1.0f).sk_bitmap()));
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap()));
EXPECT_TRUE(gt::IsEqual(bytes2x,
- image_skia.GetRepresentation(2.0f).sk_bitmap()));
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap()));
}
} // namespace
diff --git a/ui/gfx/image/image_png_rep.cc b/ui/gfx/image/image_png_rep.cc
index 3970d2b..253a529 100644
--- a/ui/gfx/image/image_png_rep.cc
+++ b/ui/gfx/image/image_png_rep.cc
@@ -4,7 +4,6 @@
#include "ui/gfx/image/image_png_rep.h"
-#include "base/logging.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/size.h"
@@ -13,13 +12,13 @@ namespace gfx {
ImagePNGRep::ImagePNGRep()
: raw_data(NULL),
- scale(1.0) {
+ scale_factor(ui::SCALE_FACTOR_NONE) {
}
ImagePNGRep::ImagePNGRep(const scoped_refptr<base::RefCountedMemory>& data,
- float data_scale)
+ ui::ScaleFactor data_scale_factor)
: raw_data(data),
- scale(data_scale) {
+ scale_factor(data_scale_factor) {
}
ImagePNGRep::~ImagePNGRep() {
diff --git a/ui/gfx/image/image_png_rep.h b/ui/gfx/image/image_png_rep.h
index 98e37454..7e5ce5b 100644
--- a/ui/gfx/image/image_png_rep.h
+++ b/ui/gfx/image/image_png_rep.h
@@ -6,6 +6,7 @@
#define UI_GFX_IMAGE_IMAGE_PNG_REP_H_
#include "base/memory/ref_counted_memory.h"
+#include "ui/base/layout.h"
#include "ui/gfx/gfx_export.h"
namespace gfx {
@@ -14,10 +15,9 @@ class Size;
// An ImagePNGRep represents a bitmap's png encoded data and the scale factor it
// was intended for.
struct UI_EXPORT ImagePNGRep {
- public:
ImagePNGRep();
ImagePNGRep(const scoped_refptr<base::RefCountedMemory>& data,
- float data_scale);
+ ui::ScaleFactor data_scale_factor);
~ImagePNGRep();
// Width and height of the image, in pixels.
@@ -27,7 +27,7 @@ struct UI_EXPORT ImagePNGRep {
gfx::Size Size() const;
scoped_refptr<base::RefCountedMemory> raw_data;
- float scale;
+ ui::ScaleFactor scale_factor;
};
} // namespace gfx
diff --git a/ui/gfx/image/image_skia.cc b/ui/gfx/image/image_skia.cc
index a283117..1ae9874 100644
--- a/ui/gfx/image/image_skia.cc
+++ b/ui/gfx/image/image_skia.cc
@@ -26,7 +26,6 @@ gfx::ImageSkiaRep& NullImageRep() {
return null_image_rep;
}
-std::vector<float>* g_supported_scales = NULL;
} // namespace
namespace internal {
@@ -34,15 +33,15 @@ namespace {
class Matcher {
public:
- explicit Matcher(float scale) : scale_(scale) {
+ explicit Matcher(ui::ScaleFactor scale_factor) : scale_factor_(scale_factor) {
}
bool operator()(const ImageSkiaRep& rep) const {
- return rep.scale() == scale_;
+ return rep.scale_factor() == scale_factor_;
}
private:
- float scale_;
+ ui::ScaleFactor scale_factor_;
};
} // namespace
@@ -62,10 +61,11 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
read_only_(false) {
}
- ImageSkiaStorage(ImageSkiaSource* source, float scale)
+ ImageSkiaStorage(ImageSkiaSource* source, ui::ScaleFactor scale_factor)
: source_(source),
read_only_(false) {
- ImageSkia::ImageSkiaReps::iterator it = FindRepresentation(scale, true);
+ ImageSkia::ImageSkiaReps::iterator it =
+ FindRepresentation(scale_factor, true);
if (it == image_reps_.end() || it->is_null())
source_.reset();
else
@@ -103,15 +103,16 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
}
// Returns the iterator of the image rep whose density best matches
- // |scale|. If the image for the |scale| doesn't exist in the storage and
- // |storage| is set, it fetches new image by calling
- // |ImageSkiaSource::GetImageForScale|. If the source returns the image with
- // different scale (if the image doesn't exist in resource, for example), it
- // will fallback to closest image rep.
+ // |scale_factor|. If the image for the |scale_factor| doesn't exist
+ // in the storage and |storage| is set, it fetches new image by calling
+ // |ImageSkiaSource::GetImageForScale|. If the source returns the
+ // image with different scale factor (if the image doesn't exist in
+ // resource, for example), it will fallback to closest image rep.
std::vector<ImageSkiaRep>::iterator FindRepresentation(
- float scale, bool fetch_new_image) const {
+ ui::ScaleFactor scale_factor, bool fetch_new_image) const {
ImageSkiaStorage* non_const = const_cast<ImageSkiaStorage*>(this);
+ float scale = ui::GetScaleFactorScale(scale_factor);
ImageSkia::ImageSkiaReps::iterator closest_iter =
non_const->image_reps().end();
ImageSkia::ImageSkiaReps::iterator exact_iter =
@@ -120,7 +121,7 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
for (ImageSkia::ImageSkiaReps::iterator it =
non_const->image_reps().begin();
it < image_reps_.end(); ++it) {
- if (it->scale() == scale) {
+ if (it->GetScale() == scale) {
// found exact match
fetch_new_image = false;
if (it->is_null())
@@ -128,7 +129,7 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
exact_iter = it;
break;
}
- float diff = std::abs(it->scale() - scale);
+ float diff = std::abs(it->GetScale() - scale);
if (diff < smallest_diff && !it->is_null()) {
closest_iter = it;
smallest_diff = diff;
@@ -139,24 +140,25 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
DCHECK(CalledOnValidThread()) <<
"An ImageSkia with the source must be accessed by the same thread.";
- ImageSkiaRep image = source_->GetImageForScale(scale);
+ ImageSkiaRep image = source_->GetImageForScale(scale_factor);
// If the source returned the new image, store it.
if (!image.is_null() &&
std::find_if(image_reps_.begin(), image_reps_.end(),
- Matcher(image.scale())) == image_reps_.end()) {
+ Matcher(image.scale_factor())) == image_reps_.end()) {
non_const->image_reps().push_back(image);
}
- // If the result image's scale isn't same as the expected scale, create
- // null ImageSkiaRep with the |scale| so that the next lookup will
- // fallback to the closest scale.
- if (image.is_null() || image.scale() != scale) {
- non_const->image_reps().push_back(ImageSkiaRep(SkBitmap(), scale));
+ // If the result image's scale factor isn't same as the expected
+ // scale factor, create null ImageSkiaRep with the |scale_factor|
+ // so that the next lookup will fallback to the closest scale.
+ if (image.is_null() || image.scale_factor() != scale_factor) {
+ non_const->image_reps().push_back(
+ ImageSkiaRep(SkBitmap(), scale_factor));
}
// image_reps_ must have the exact much now, so find again.
- return FindRepresentation(scale, false);
+ return FindRepresentation(scale_factor, false);
}
return exact_iter != image_reps_.end() ? exact_iter : closest_iter;
}
@@ -168,7 +170,7 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
DetachFromThread();
}
- // Vector of bitmaps and their associated scale.
+ // Vector of bitmaps and their associated scale factor.
std::vector<gfx::ImageSkiaRep> image_reps_;
scoped_ptr<ImageSkiaSource> source_;
@@ -193,8 +195,8 @@ ImageSkia::ImageSkia(ImageSkiaSource* source, const gfx::Size& size)
DetachStorageFromThread();
}
-ImageSkia::ImageSkia(ImageSkiaSource* source, float scale)
- : storage_(new internal::ImageSkiaStorage(source, scale)) {
+ImageSkia::ImageSkia(ImageSkiaSource* source, ui::ScaleFactor scale_factor)
+ : storage_(new internal::ImageSkiaStorage(source, scale_factor)) {
DCHECK(source);
if (!storage_->has_source())
storage_ = NULL;
@@ -220,27 +222,8 @@ ImageSkia::~ImageSkia() {
}
// static
-void ImageSkia::SetSupportedScales(const std::vector<float>& supported_scales) {
- if (g_supported_scales != NULL)
- delete g_supported_scales;
- g_supported_scales = new std::vector<float>(supported_scales);
- std::sort(g_supported_scales->begin(), g_supported_scales->end());
-}
-
-// static
-const std::vector<float>& ImageSkia::GetSupportedScales() {
- DCHECK(g_supported_scales != NULL);
- return *g_supported_scales;
-}
-
-// static
-float ImageSkia::GetMaxSupportedScale() {
- return g_supported_scales->back();
-}
-
-// static
ImageSkia ImageSkia::CreateFrom1xBitmap(const SkBitmap& bitmap) {
- return ImageSkia(ImageSkiaRep(bitmap, 1.0f));
+ return ImageSkia(ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P));
}
scoped_ptr<ImageSkia> ImageSkia::DeepCopy() const {
@@ -271,9 +254,10 @@ void ImageSkia::AddRepresentation(const ImageSkiaRep& image_rep) {
// TODO(oshima): This method should be called |SetRepresentation|
// and replace the existing rep if there is already one with the
- // same scale so that we can guarantee that a ImageSkia instance contains only
- // one image rep per scale. This is not possible now as ImageLoader currently
- // stores need this feature, but this needs to be fixed.
+ // same scale factor so that we can guarantee that a ImageSkia
+ // instance contians only one image rep per scale factor. This is
+ // not possible now as ImageLoader currently stores need
+ // this feature, but this needs to be fixed.
if (isNull()) {
Init(image_rep);
} else {
@@ -282,34 +266,37 @@ void ImageSkia::AddRepresentation(const ImageSkiaRep& image_rep) {
}
}
-void ImageSkia::RemoveRepresentation(float scale) {
+void ImageSkia::RemoveRepresentation(ui::ScaleFactor scale_factor) {
if (isNull())
return;
CHECK(CanModify());
ImageSkiaReps& image_reps = storage_->image_reps();
ImageSkiaReps::iterator it =
- storage_->FindRepresentation(scale, false);
- if (it != image_reps.end() && it->scale() == scale)
+ storage_->FindRepresentation(scale_factor, false);
+ if (it != image_reps.end() && it->scale_factor() == scale_factor)
image_reps.erase(it);
}
-bool ImageSkia::HasRepresentation(float scale) const {
+bool ImageSkia::HasRepresentation(ui::ScaleFactor scale_factor) const {
if (isNull())
return false;
CHECK(CanRead());
- ImageSkiaReps::iterator it = storage_->FindRepresentation(scale, false);
- return (it != storage_->image_reps().end() && it->scale() == scale);
+ ImageSkiaReps::iterator it =
+ storage_->FindRepresentation(scale_factor, false);
+ return (it != storage_->image_reps().end() &&
+ it->scale_factor() == scale_factor);
}
-const ImageSkiaRep& ImageSkia::GetRepresentation(float scale) const {
+const ImageSkiaRep& ImageSkia::GetRepresentation(
+ ui::ScaleFactor scale_factor) const {
if (isNull())
return NullImageRep();
CHECK(CanRead());
- ImageSkiaReps::iterator it = storage_->FindRepresentation(scale, true);
+ ImageSkiaReps::iterator it = storage_->FindRepresentation(scale_factor, true);
if (it == storage_->image_reps().end())
return NullImageRep();
@@ -324,7 +311,7 @@ void ImageSkia::SetReadOnly() {
void ImageSkia::MakeThreadSafe() {
CHECK(storage_.get());
- EnsureRepsForSupportedScales();
+ EnsureRepsForSupportedScaleFactors();
// Delete source as we no longer needs it.
if (storage_.get())
storage_->DeleteSource();
@@ -367,15 +354,15 @@ std::vector<ImageSkiaRep> ImageSkia::image_reps() const {
return image_reps;
}
-void ImageSkia::EnsureRepsForSupportedScales() const {
- DCHECK(g_supported_scales != NULL);
+void ImageSkia::EnsureRepsForSupportedScaleFactors() const {
// Don't check ReadOnly because the source may generate images
// even for read only ImageSkia. Concurrent access will be protected
// by |DCHECK(CalledOnValidThread())| in FindRepresentation.
if (storage_.get() && storage_->has_source()) {
- for (std::vector<float>::const_iterator it = g_supported_scales->begin();
- it != g_supported_scales->end(); ++it)
- storage_->FindRepresentation(*it, true);
+ std::vector<ui::ScaleFactor> supported_scale_factors =
+ ui::GetSupportedScaleFactors();
+ for (size_t i = 0; i < supported_scale_factors.size(); ++i)
+ storage_->FindRepresentation(supported_scale_factors[i], true);
}
}
@@ -403,7 +390,8 @@ SkBitmap& ImageSkia::GetBitmap() const {
CHECK(CanRead());
#endif
- ImageSkiaReps::iterator it = storage_->FindRepresentation(1.0f, true);
+ ImageSkiaReps::iterator it =
+ storage_->FindRepresentation(ui::SCALE_FACTOR_100P, true);
if (it != storage_->image_reps().end())
return it->mutable_sk_bitmap();
return NullImageRep().mutable_sk_bitmap();
diff --git a/ui/gfx/image/image_skia.h b/ui/gfx/image/image_skia.h
index ec3e65a..4bc21f8 100644
--- a/ui/gfx/image/image_skia.h
+++ b/ui/gfx/image/image_skia.h
@@ -47,9 +47,9 @@ class UI_EXPORT ImageSkia {
ImageSkia(ImageSkiaSource* source, const gfx::Size& size);
// Creates an instance that uses the |source|. The constructor loads the image
- // at |scale| and uses its dimensions to calculate the size in DIP. ImageSkia
- // owns |source|.
- ImageSkia(ImageSkiaSource* source, float scale);
+ // at |scale_factor| and uses its dimensions to calculate the size in DIP.
+ // ImageSkia owns |source|.
+ ImageSkia(ImageSkiaSource* source, ui::ScaleFactor scale_factor);
explicit ImageSkia(const gfx::ImageSkiaRep& image_rep);
@@ -61,16 +61,6 @@ class UI_EXPORT ImageSkia {
~ImageSkia();
- // Changes the value of GetSupportedScales() to |scales|.
- static void SetSupportedScales(const std::vector<float>& scales);
-
- // Returns a vector with the scale factors which are supported by this
- // platform, in ascending order.
- static const std::vector<float>& GetSupportedScales();
-
- // Returns the maximum scale supported by this platform.
- static float GetMaxSupportedScale();
-
// Creates an image from the passed in bitmap.
// DIP width and height are based on scale factor of 1x.
// Adds ref to passed in bitmap.
@@ -84,7 +74,7 @@ class UI_EXPORT ImageSkia {
// Note that this does NOT generate ImageSkiaReps from its source.
// If you want to create a deep copy with ImageSkiaReps for supported
// scale factors, you need to explicitly call
- // |EnsureRepsForSupportedScales()| first.
+ // |EnsureRepsForSupportedScaleFactors()| first.
scoped_ptr<ImageSkia> DeepCopy() const;
// Returns true if this object is backed by the same ImageSkiaStorage as
@@ -94,16 +84,18 @@ class UI_EXPORT ImageSkia {
// Adds |image_rep| to the image reps contained by this object.
void AddRepresentation(const gfx::ImageSkiaRep& image_rep);
- // Removes the image rep of |scale| if present.
- void RemoveRepresentation(float scale);
+ // Removes the image rep of |scale_factor| if present.
+ void RemoveRepresentation(ui::ScaleFactor scale_factor);
// Returns true if the object owns an image rep whose density matches
- // |scale| exactly.
- bool HasRepresentation(float scale) const;
+ // |scale_factor| exactly.
+ bool HasRepresentation(ui::ScaleFactor scale_factor) const;
- // Returns the image rep whose density best matches |scale|.
+ // Returns the image rep whose density best matches
+ // |scale_factor|.
// Returns a null image rep if the object contains no image reps.
- const gfx::ImageSkiaRep& GetRepresentation(float scale) const;
+ const gfx::ImageSkiaRep& GetRepresentation(
+ ui::ScaleFactor scale_factor) const;
// Make the ImageSkia instance read-only. Note that this only prevent
// modification from client code, and the storage may still be
@@ -144,7 +136,7 @@ class UI_EXPORT ImageSkia {
// When the source is available, generates all ImageReps for
// supported scale factors. This method is defined as const as
// the state change in the storage is agnostic to the caller.
- void EnsureRepsForSupportedScales() const;
+ void EnsureRepsForSupportedScaleFactors() const;
private:
friend class test::TestOnThread;
diff --git a/ui/gfx/image/image_skia_operations.cc b/ui/gfx/image/image_skia_operations.cc
index 6953b59..6631560 100644
--- a/ui/gfx/image/image_skia_operations.cc
+++ b/ui/gfx/image/image_skia_operations.cc
@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "skia/ext/image_operations.h"
+#include "ui/base/layout.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/image/image_skia.h"
@@ -36,13 +37,14 @@ gfx::Rect DIPToPixelBounds(gfx::Rect dip_bounds, float scale) {
// Returns an image rep for the ImageSkiaSource to return to visually indicate
// an error.
-ImageSkiaRep GetErrorImageRep(float scale, const gfx::Size& pixel_size) {
+ImageSkiaRep GetErrorImageRep(ui::ScaleFactor scale_factor,
+ const gfx::Size& pixel_size) {
SkBitmap bitmap;
bitmap.setConfig(
SkBitmap::kARGB_8888_Config, pixel_size.width(), pixel_size.height());
bitmap.allocPixels();
bitmap.eraseColor(SK_ColorRED);
- return gfx::ImageSkiaRep(bitmap, scale);
+ return gfx::ImageSkiaRep(bitmap, scale_factor);
}
// A base image source class that creates an image from two source images.
@@ -60,25 +62,27 @@ class BinaryImageSource : public gfx::ImageSkiaSource {
}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- ImageSkiaRep first_rep = first_.GetRepresentation(scale);
- ImageSkiaRep second_rep = second_.GetRepresentation(scale);
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ ImageSkiaRep first_rep = first_.GetRepresentation(scale_factor);
+ ImageSkiaRep second_rep = second_.GetRepresentation(scale_factor);
if (first_rep.pixel_size() != second_rep.pixel_size()) {
- DCHECK_NE(first_rep.scale(), second_rep.scale());
- if (first_rep.scale() == second_rep.scale()) {
+ DCHECK_NE(first_rep.scale_factor(), second_rep.scale_factor());
+ if (first_rep.scale_factor() == second_rep.scale_factor()) {
LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_;
- return GetErrorImageRep(first_rep.scale(),first_rep.pixel_size());
+ return GetErrorImageRep(first_rep.scale_factor(),
+ first_rep.pixel_size());
}
- first_rep = first_.GetRepresentation(1.0f);
- second_rep = second_.GetRepresentation(1.0f);
+ first_rep = first_.GetRepresentation(ui::SCALE_FACTOR_100P);
+ second_rep = second_.GetRepresentation(ui::SCALE_FACTOR_100P);
DCHECK_EQ(first_rep.pixel_width(), second_rep.pixel_width());
DCHECK_EQ(first_rep.pixel_height(), second_rep.pixel_height());
if (first_rep.pixel_size() != second_rep.pixel_size()) {
LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_;
- return GetErrorImageRep(first_rep.scale(), first_rep.pixel_size());
+ return GetErrorImageRep(first_rep.scale_factor(),
+ first_rep.pixel_size());
}
} else {
- DCHECK_EQ(first_rep.scale(), second_rep.scale());
+ DCHECK_EQ(first_rep.scale_factor(), second_rep.scale_factor());
}
return CreateImageSkiaRep(first_rep, second_rep);
}
@@ -117,7 +121,7 @@ class BlendingImageSource : public BinaryImageSource {
const ImageSkiaRep& second_rep) const OVERRIDE {
SkBitmap blended = SkBitmapOperations::CreateBlendedBitmap(
first_rep.sk_bitmap(), second_rep.sk_bitmap(), alpha_);
- return ImageSkiaRep(blended, first_rep.scale());
+ return ImageSkiaRep(blended, first_rep.scale_factor());
}
private:
@@ -163,8 +167,8 @@ class TransparentImageSource : public gfx::ImageSkiaSource {
private:
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- ImageSkiaRep image_rep = image_.GetRepresentation(scale);
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor);
SkBitmap alpha;
alpha.setConfig(SkBitmap::kARGB_8888_Config,
image_rep.pixel_width(),
@@ -173,7 +177,7 @@ class TransparentImageSource : public gfx::ImageSkiaSource {
alpha.eraseColor(SkColorSetARGB(alpha_ * 255, 0, 0, 0));
return ImageSkiaRep(
SkBitmapOperations::CreateMaskedBitmap(image_rep.sk_bitmap(), alpha),
- image_rep.scale());
+ image_rep.scale_factor());
}
ImageSkia image_;
@@ -197,7 +201,7 @@ class MaskedImageSource : public BinaryImageSource {
const ImageSkiaRep& second_rep) const OVERRIDE {
return ImageSkiaRep(SkBitmapOperations::CreateMaskedBitmap(
first_rep.sk_bitmap(), second_rep.sk_bitmap()),
- first_rep.scale());
+ first_rep.scale_factor());
}
private:
@@ -220,15 +224,16 @@ class TiledImageSource : public gfx::ImageSkiaSource {
}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- ImageSkiaRep source_rep = source_.GetRepresentation(scale);
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ ImageSkiaRep source_rep = source_.GetRepresentation(scale_factor);
+ float scale = ui::GetScaleFactorScale(source_rep.scale_factor());
gfx::Rect bounds = DIPToPixelBounds(gfx::Rect(src_x_, src_y_, dst_w_,
- dst_h_), source_rep.scale());
+ dst_h_), scale);
return ImageSkiaRep(
SkBitmapOperations::CreateTiledBitmap(
source_rep.sk_bitmap(),
bounds.x(), bounds.y(), bounds.width(), bounds.height()),
- source_rep.scale());
+ source_rep.scale_factor());
}
private:
@@ -253,11 +258,11 @@ class HSLImageSource : public gfx::ImageSkiaSource {
}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- ImageSkiaRep image_rep = image_.GetRepresentation(scale);
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor);
return gfx::ImageSkiaRep(
SkBitmapOperations::CreateHSLShiftedBitmap(image_rep.sk_bitmap(),
- hsl_shift_), image_rep.scale());
+ hsl_shift_), image_rep.scale_factor());
}
private:
@@ -283,17 +288,17 @@ class ButtonImageSource: public gfx::ImageSkiaSource {
}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- ImageSkiaRep image_rep = image_.GetRepresentation(scale);
- ImageSkiaRep mask_rep = mask_.GetRepresentation(scale);
- if (image_rep.scale() != mask_rep.scale()) {
- image_rep = image_.GetRepresentation(1.0f);
- mask_rep = mask_.GetRepresentation(1.0f);
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor);
+ ImageSkiaRep mask_rep = mask_.GetRepresentation(scale_factor);
+ if (image_rep.scale_factor() != mask_rep.scale_factor()) {
+ image_rep = image_.GetRepresentation(ui::SCALE_FACTOR_100P);
+ mask_rep = mask_.GetRepresentation(ui::SCALE_FACTOR_100P);
}
return gfx::ImageSkiaRep(
SkBitmapOperations::CreateButtonBackground(color_,
image_rep.sk_bitmap(), mask_rep.sk_bitmap()),
- image_rep.scale());
+ image_rep.scale_factor());
}
private:
@@ -318,15 +323,16 @@ class ExtractSubsetImageSource: public gfx::ImageSkiaSource {
}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- ImageSkiaRep image_rep = image_.GetRepresentation(scale);
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor);
+ float scale_to_pixel = ui::GetScaleFactorScale(image_rep.scale_factor());
SkIRect subset_bounds_in_pixel = RectToSkIRect(
- DIPToPixelBounds(subset_bounds_, image_rep.scale()));
+ DIPToPixelBounds(subset_bounds_, scale_to_pixel));
SkBitmap dst;
bool success = image_rep.sk_bitmap().extractSubset(&dst,
subset_bounds_in_pixel);
DCHECK(success);
- return gfx::ImageSkiaRep(dst, image_rep.scale());
+ return gfx::ImageSkiaRep(dst, image_rep.scale_factor());
}
private:
@@ -350,19 +356,20 @@ class ResizeSource : public ImageSkiaSource {
virtual ~ResizeSource() {}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- const ImageSkiaRep& image_rep = source_.GetRepresentation(scale);
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
if (image_rep.GetWidth() == target_dip_size_.width() &&
image_rep.GetHeight() == target_dip_size_.height())
return image_rep;
+ const float scale = ui::GetScaleFactorScale(scale_factor);
const Size target_pixel_size = DIPToPixelSize(target_dip_size_, scale);
const SkBitmap resized = skia::ImageOperations::Resize(
image_rep.sk_bitmap(),
resize_method_,
target_pixel_size.width(),
target_pixel_size.height());
- return ImageSkiaRep(resized, scale);
+ return ImageSkiaRep(resized, scale_factor);
}
private:
@@ -385,9 +392,10 @@ class DropShadowSource : public ImageSkiaSource {
virtual ~DropShadowSource() {}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- const ImageSkiaRep& image_rep = source_.GetRepresentation(scale);
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
+ const float scale = image_rep.GetScale();
ShadowValues shadows_in_pixel;
for (size_t i = 0; i < shaodws_in_dip_.size(); ++i)
shadows_in_pixel.push_back(shaodws_in_dip_[i].Scale(scale));
@@ -395,7 +403,7 @@ class DropShadowSource : public ImageSkiaSource {
const SkBitmap shadow_bitmap = SkBitmapOperations::CreateDropShadow(
image_rep.sk_bitmap(),
shadows_in_pixel);
- return ImageSkiaRep(shadow_bitmap, image_rep.scale());
+ return ImageSkiaRep(shadow_bitmap, image_rep.scale_factor());
}
private:
@@ -417,11 +425,11 @@ class RotatedSource : public ImageSkiaSource {
virtual ~RotatedSource() {}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- const ImageSkiaRep& image_rep = source_.GetRepresentation(scale);
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
const SkBitmap rotated_bitmap =
SkBitmapOperations::Rotate(image_rep.sk_bitmap(), rotation_);
- return ImageSkiaRep(rotated_bitmap, image_rep.scale());
+ return ImageSkiaRep(rotated_bitmap, image_rep.scale_factor());
}
private:
diff --git a/ui/gfx/image/image_skia_rep.cc b/ui/gfx/image/image_skia_rep.cc
index f8f3acb..005b9a3 100644
--- a/ui/gfx/image/image_skia_rep.cc
+++ b/ui/gfx/image/image_skia_rep.cc
@@ -6,30 +6,41 @@
namespace gfx {
-ImageSkiaRep::ImageSkiaRep() : scale_(1.0f) {
+ImageSkiaRep::ImageSkiaRep()
+ : scale_factor_(ui::SCALE_FACTOR_NONE) {
}
ImageSkiaRep::~ImageSkiaRep() {
}
-ImageSkiaRep::ImageSkiaRep(const gfx::Size& size, float scale) : scale_(scale) {
+ImageSkiaRep::ImageSkiaRep(const gfx::Size& size,
+ ui::ScaleFactor scale_factor)
+ : scale_factor_(scale_factor) {
+ float scale = ui::GetScaleFactorScale(scale_factor);
bitmap_.setConfig(SkBitmap::kARGB_8888_Config,
static_cast<int>(size.width() * scale),
static_cast<int>(size.height() * scale));
bitmap_.allocPixels();
}
-ImageSkiaRep::ImageSkiaRep(const SkBitmap& src, float scale)
+ImageSkiaRep::ImageSkiaRep(const SkBitmap& src,
+ ui::ScaleFactor scale_factor)
: bitmap_(src),
- scale_(scale) {
+ scale_factor_(scale_factor) {
}
int ImageSkiaRep::GetWidth() const {
- return static_cast<int>(bitmap_.width() / scale_);
+ return static_cast<int>(bitmap_.width() /
+ ui::GetScaleFactorScale(scale_factor_));
}
int ImageSkiaRep::GetHeight() const {
- return static_cast<int>(bitmap_.height() / scale_);
+ return static_cast<int>(bitmap_.height() /
+ ui::GetScaleFactorScale(scale_factor_));
+}
+
+float ImageSkiaRep::GetScale() const {
+ return ui::GetScaleFactorScale(scale_factor_);
}
} // namespace gfx
diff --git a/ui/gfx/image/image_skia_rep.h b/ui/gfx/image/image_skia_rep.h
index 66179fb..6fca411 100644
--- a/ui/gfx/image/image_skia_rep.h
+++ b/ui/gfx/image/image_skia_rep.h
@@ -6,6 +6,7 @@
#define UI_GFX_IMAGE_IMAGE_SKIA_REP_H_
#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/base/layout.h"
#include "ui/gfx/gfx_export.h"
#include "ui/gfx/size.h"
@@ -20,11 +21,11 @@ class UI_EXPORT ImageSkiaRep {
// Creates a bitmap with kARGB_8888_Config config with given |size| in DIP.
// This allocates pixels in the bitmap.
- ImageSkiaRep(const gfx::Size& size, float scale);
+ ImageSkiaRep(const gfx::Size& size, ui::ScaleFactor scale_factor);
- // Creates a bitmap with given scale.
+ // Creates a bitmap with given scale factor.
// Adds ref to |src|.
- ImageSkiaRep(const SkBitmap& src, float scale);
+ ImageSkiaRep(const SkBitmap& src, ui::ScaleFactor scale_factor);
// Returns true if the backing bitmap is null.
bool is_null() const { return bitmap_.isNull(); }
@@ -41,7 +42,8 @@ class UI_EXPORT ImageSkiaRep {
}
// Retrieves the scale that the bitmap will be painted at.
- float scale() const { return scale_; }
+ float GetScale() const;
+ ui::ScaleFactor scale_factor() const { return scale_factor_; }
// Returns backing bitmap.
const SkBitmap& sk_bitmap() const { return bitmap_; }
@@ -51,7 +53,7 @@ class UI_EXPORT ImageSkiaRep {
SkBitmap& mutable_sk_bitmap() { return bitmap_; }
SkBitmap bitmap_;
- float scale_;
+ ui::ScaleFactor scale_factor_;
};
} // namespace gfx
diff --git a/ui/gfx/image/image_skia_source.h b/ui/gfx/image/image_skia_source.h
index 35be479..ed38e1c 100644
--- a/ui/gfx/image/image_skia_source.h
+++ b/ui/gfx/image/image_skia_source.h
@@ -5,8 +5,7 @@
#ifndef UI_GFX_IMAGE_IMAGE_SKIA_SOURCE_H_
#define UI_GFX_IMAGE_IMAGE_SKIA_SOURCE_H_
-#include <vector>
-
+#include "ui/base/layout.h"
#include "ui/gfx/gfx_export.h"
namespace gfx {
@@ -17,11 +16,11 @@ class UI_EXPORT ImageSkiaSource {
public:
virtual ~ImageSkiaSource() {}
- // Returns the ImageSkiaRep for the given |scale|. ImageSkia caches the
- // returned ImageSkiaRep and calls this method only if it doesn't have
- // ImageSkiaRep for given |scale|. There is no need for the implementation to
- // cache the image.
- virtual gfx::ImageSkiaRep GetImageForScale(float scale) = 0;
+ // Returns the ImageSkiaRep for the given |scale_factor|. ImageSkia
+ // caches the returned ImageSkiaRep and calls this method only if it
+ // doesn't have ImageSkaiRep for given |scale_factor|. There is
+ // no need for the implementation to cache the image.
+ virtual gfx::ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) = 0;
};
} // namespace gfx
diff --git a/ui/gfx/image/image_skia_unittest.cc b/ui/gfx/image/image_skia_unittest.cc
index 00478221..fd17453 100644
--- a/ui/gfx/image/image_skia_unittest.cc
+++ b/ui/gfx/image/image_skia_unittest.cc
@@ -8,6 +8,7 @@
#include "base/threading/simple_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/base/layout.h"
#include "ui/gfx/image/image_skia_rep.h"
#include "ui/gfx/image/image_skia_source.h"
#include "ui/gfx/size.h"
@@ -31,7 +32,7 @@ class FixedSource : public ImageSkiaSource {
virtual ~FixedSource() {
}
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
return image_;
}
@@ -48,8 +49,8 @@ class DynamicSource : public ImageSkiaSource {
virtual ~DynamicSource() {
}
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- return gfx::ImageSkiaRep(size_, scale);
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ return gfx::ImageSkiaRep(size_, scale_factor);
}
private:
@@ -66,7 +67,7 @@ class NullSource: public ImageSkiaSource {
virtual ~NullSource() {
}
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
return gfx::ImageSkiaRep();
}
@@ -114,55 +115,58 @@ class TestOnThread : public base::SimpleThread {
} // namespace test
TEST(ImageSkiaTest, FixedSource) {
- ImageSkiaRep image(Size(100, 200), 1.0f);
+ ImageSkiaRep image(Size(100, 200), ui::SCALE_FACTOR_100P);
ImageSkia image_skia(new FixedSource(image), Size(100, 200));
EXPECT_EQ(0U, image_skia.image_reps().size());
- const ImageSkiaRep& result_100p = image_skia.GetRepresentation(1.0f);
+ const ImageSkiaRep& result_100p =
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_100P);
EXPECT_EQ(100, result_100p.GetWidth());
EXPECT_EQ(200, result_100p.GetHeight());
- EXPECT_EQ(1.0f, result_100p.scale());
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, result_100p.scale_factor());
EXPECT_EQ(1U, image_skia.image_reps().size());
- const ImageSkiaRep& result_200p = image_skia.GetRepresentation(2.0f);
+ const ImageSkiaRep& result_200p =
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
EXPECT_EQ(100, result_200p.GetWidth());
EXPECT_EQ(200, result_200p.GetHeight());
EXPECT_EQ(100, result_200p.pixel_width());
EXPECT_EQ(200, result_200p.pixel_height());
- EXPECT_EQ(1.0f, result_200p.scale());
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, result_200p.scale_factor());
EXPECT_EQ(1U, image_skia.image_reps().size());
// Get the representation again and make sure it doesn't
// generate new image skia rep.
- image_skia.GetRepresentation(1.0f);
- image_skia.GetRepresentation(2.0f);
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_100P);
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
EXPECT_EQ(1U, image_skia.image_reps().size());
}
TEST(ImageSkiaTest, DynamicSource) {
ImageSkia image_skia(new DynamicSource(Size(100, 200)), Size(100, 200));
EXPECT_EQ(0U, image_skia.image_reps().size());
- const ImageSkiaRep& result_100p = image_skia.GetRepresentation(1.0f);
+ const ImageSkiaRep& result_100p =
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_100P);
EXPECT_EQ(100, result_100p.GetWidth());
EXPECT_EQ(200, result_100p.GetHeight());
- EXPECT_EQ(1.0f, result_100p.scale());
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, result_100p.scale_factor());
EXPECT_EQ(1U, image_skia.image_reps().size());
const ImageSkiaRep& result_200p =
- image_skia.GetRepresentation(2.0f);
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
EXPECT_EQ(100, result_200p.GetWidth());
EXPECT_EQ(200, result_200p.GetHeight());
EXPECT_EQ(200, result_200p.pixel_width());
EXPECT_EQ(400, result_200p.pixel_height());
- EXPECT_EQ(2.0f, result_200p.scale());
+ EXPECT_EQ(ui::SCALE_FACTOR_200P, result_200p.scale_factor());
EXPECT_EQ(2U, image_skia.image_reps().size());
// Get the representation again and make sure it doesn't
// generate new image skia rep.
- image_skia.GetRepresentation(1.0f);
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_100P);
EXPECT_EQ(2U, image_skia.image_reps().size());
- image_skia.GetRepresentation(2.0f);
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
EXPECT_EQ(2U, image_skia.image_reps().size());
}
@@ -178,16 +182,16 @@ TEST(ImageSkiaTest, ManyRepsPerScaleFactor) {
// Simulate a source which loads images on a delay. Upon
// GetImageForScaleFactor, it immediately returns null and starts loading
// image reps slowly.
- image.GetRepresentation(1.0f);
- image.GetRepresentation(2.0f);
+ image.GetRepresentation(ui::SCALE_FACTOR_100P);
+ image.GetRepresentation(ui::SCALE_FACTOR_200P);
// After a lengthy amount of simulated time, finally loaded image reps.
image.AddRepresentation(ImageSkiaRep(
- gfx::Size(kSmallIcon1x, kSmallIcon1x), 1.0f));
+ gfx::Size(kSmallIcon1x, kSmallIcon1x), ui::SCALE_FACTOR_100P));
image.AddRepresentation(ImageSkiaRep(
- gfx::Size(kSmallIcon2x, kSmallIcon2x), 2.0f));
+ gfx::Size(kSmallIcon2x, kSmallIcon2x), ui::SCALE_FACTOR_200P));
image.AddRepresentation(ImageSkiaRep(
- gfx::Size(kLargeIcon1x, kLargeIcon1x), 1.0f));
+ gfx::Size(kLargeIcon1x, kLargeIcon1x), ui::SCALE_FACTOR_100P));
std::vector<ImageSkiaRep> image_reps = image.image_reps();
EXPECT_EQ(3u, image_reps.size());
@@ -195,9 +199,9 @@ TEST(ImageSkiaTest, ManyRepsPerScaleFactor) {
int num_1x = 0;
int num_2x = 0;
for (size_t i = 0; i < image_reps.size(); ++i) {
- if (image_reps[i].scale() == 1.0f)
+ if (image_reps[i].scale_factor() == ui::SCALE_FACTOR_100P)
num_1x++;
- else if (image_reps[i].scale() == 2.0f)
+ else if (image_reps[i].scale_factor() == ui::SCALE_FACTOR_200P)
num_2x++;
}
EXPECT_EQ(2, num_1x);
@@ -214,9 +218,9 @@ TEST(ImageSkiaTest, GetBitmap) {
TEST(ImageSkiaTest, GetBitmapFromEmpty) {
// Create an image with 1 representation and remove it so the ImageSkiaStorage
// is left with no representations.
- ImageSkia empty_image(ImageSkiaRep(Size(100, 200), 1.0f));
+ ImageSkia empty_image(ImageSkiaRep(Size(100, 200), ui::SCALE_FACTOR_100P));
ImageSkia empty_image_copy(empty_image);
- empty_image.RemoveRepresentation(1.0f);
+ empty_image.RemoveRepresentation(ui::SCALE_FACTOR_100P);
// Check that ImageSkia::bitmap() still returns a valid SkBitmap pointer for
// the image and all its copies.
@@ -233,12 +237,12 @@ TEST(ImageSkiaTest, BackedBySameObjectAs) {
EXPECT_TRUE(image.BackedBySameObjectAs(unrelated));
image.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10),
- 1.0f));
+ ui::SCALE_FACTOR_100P));
ImageSkia copy = image;
copy.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10),
- 2.0f));
+ ui::SCALE_FACTOR_200P));
unrelated.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10),
- 1.0f));
+ ui::SCALE_FACTOR_100P));
EXPECT_TRUE(image.BackedBySameObjectAs(copy));
EXPECT_FALSE(image.BackedBySameObjectAs(unrelated));
EXPECT_FALSE(copy.BackedBySameObjectAs(unrelated));
@@ -255,7 +259,7 @@ TEST(ImageSkiaTest, EmptyOnThreadTest) {
}
TEST(ImageSkiaTest, StaticOnThreadTest) {
- ImageSkia image(ImageSkiaRep(Size(100, 200), 1.0f));
+ ImageSkia image(ImageSkiaRep(Size(100, 200), ui::SCALE_FACTOR_100P));
EXPECT_FALSE(image.IsThreadSafe());
test::TestOnThread image_on_thread(&image);
@@ -361,8 +365,8 @@ TEST(ImageSkiaTest, SourceOnThreadTest) {
image.MakeThreadSafe();
EXPECT_TRUE(image.IsThreadSafe());
// Check if image reps are generated for supported scale factors.
- EXPECT_EQ(ImageSkia::GetSupportedScales().size(),
- image.image_reps().size());
+ EXPECT_EQ(ui::GetSupportedScaleFactors().size(),
+ image.image_reps().size());
test::TestOnThread threadsafe_on_thread(&image);
threadsafe_on_thread.StartAndJoin();
EXPECT_TRUE(threadsafe_on_thread.can_read());
diff --git a/ui/gfx/image/image_skia_util_ios.h b/ui/gfx/image/image_skia_util_ios.h
index 6c5f30df..57c9698 100644
--- a/ui/gfx/image/image_skia_util_ios.h
+++ b/ui/gfx/image/image_skia_util_ios.h
@@ -5,6 +5,7 @@
#ifndef UI_GFX_IMAGE_IMAGE_SKIA_UTIL_IOS_H_
#define UI_GFX_IMAGE_IMAGE_SKIA_UTIL_IOS_H_
+#include "ui/base/layout.h"
#include "ui/gfx/gfx_export.h"
#ifdef __OBJC__
@@ -21,11 +22,13 @@ class ImageSkiaRep;
UI_EXPORT gfx::ImageSkia ImageSkiaFromUIImage(UIImage* image);
// Converts to an ImageSkiaRep of |scale_factor| from UIImage.
-// |scale| is passed explicitly in order to allow this method to be used
-// with a |scale| which is not supported by the platform.
-UI_EXPORT gfx::ImageSkiaRep ImageSkiaRepOfScaleFromUIImage(
+// |scale_factor| is passed explicitly in order to allow this method to be used
+// with a |scale_factor| which is not supported by the platform.
+// (ui::GetScaleFactorFromScale() is restricted to the platform's supported
+// scale factors.)
+UI_EXPORT gfx::ImageSkiaRep ImageSkiaRepOfScaleFactorFromUIImage(
UIImage* image,
- float scale);
+ ui::ScaleFactor scale_factor);
// Converts to UIImage from ImageSkia. The returned UIImage will be at the scale
// of the ImageSkiaRep in |image_skia| which most closely matches the device's
diff --git a/ui/gfx/image/image_skia_util_ios.mm b/ui/gfx/image/image_skia_util_ios.mm
index 77944ee..0ff8978 100644
--- a/ui/gfx/image/image_skia_util_ios.mm
+++ b/ui/gfx/image/image_skia_util_ios.mm
@@ -16,37 +16,39 @@ namespace gfx {
gfx::ImageSkia ImageSkiaFromUIImage(UIImage* image) {
gfx::ImageSkia image_skia;
- float max_scale = ImageSkia::GetSupportedScales().back();
- gfx::ImageSkiaRep image_skia_rep = ImageSkiaRepOfScaleFromUIImage(
- image, max_scale);
+ gfx::ImageSkiaRep image_skia_rep = ImageSkiaRepOfScaleFactorFromUIImage(
+ image, ui::GetMaxScaleFactor());
if (!image_skia_rep.is_null())
image_skia.AddRepresentation(image_skia_rep);
return image_skia;
}
-gfx::ImageSkiaRep ImageSkiaRepOfScaleFromUIImage(UIImage* image, float scale) {
+gfx::ImageSkiaRep ImageSkiaRepOfScaleFactorFromUIImage(
+ UIImage* image,
+ ui::ScaleFactor scale_factor) {
if (!image)
return gfx::ImageSkiaRep();
+ float scale = ui::GetScaleFactorScale(scale_factor);
CGSize size = image.size;
CGSize desired_size_for_scale =
CGSizeMake(size.width * scale, size.height * scale);
SkBitmap bitmap(gfx::CGImageToSkBitmap(image.CGImage,
desired_size_for_scale,
false));
- return gfx::ImageSkiaRep(bitmap, scale);
+ return gfx::ImageSkiaRep(bitmap, scale_factor);
}
UIImage* UIImageFromImageSkia(const gfx::ImageSkia& image_skia) {
- return UIImageFromImageSkiaRep(
- image_skia.GetRepresentation(ImageSkia::GetSupportedScales().back()));
+ return UIImageFromImageSkiaRep(image_skia.GetRepresentation(
+ ui::GetMaxScaleFactor()));
}
UIImage* UIImageFromImageSkiaRep(const gfx::ImageSkiaRep& image_skia_rep) {
if (image_skia_rep.is_null())
return nil;
- float scale = image_skia_rep.scale();
+ float scale = ui::GetScaleFactorScale(image_skia_rep.scale_factor());
base::ScopedCFTypeRef<CGColorSpaceRef> color_space(
CGColorSpaceCreateDeviceRGB());
return gfx::SkBitmapToUIImageWithColorSpace(image_skia_rep.sk_bitmap(), scale,
diff --git a/ui/gfx/image/image_skia_util_mac.mm b/ui/gfx/image/image_skia_util_mac.mm
index 64f95d6..f9d0475 100644
--- a/ui/gfx/image/image_skia_util_mac.mm
+++ b/ui/gfx/image/image_skia_util_mac.mm
@@ -57,11 +57,12 @@ gfx::ImageSkia ImageSkiaFromResizedNSImage(NSImage* image,
if (IsNSImageEmpty(image))
return gfx::ImageSkia();
- std::vector<float> supported_scales = ImageSkia::GetSupportedScales();
+ std::vector<ui::ScaleFactor> supported_scale_factors =
+ ui::GetSupportedScaleFactors();
gfx::ImageSkia image_skia;
- for (size_t i = 0; i < supported_scales.size(); ++i) {
- float scale = supported_scales[i];
+ for (size_t i = 0; i < supported_scale_factors.size(); ++i) {
+ float scale = ui::GetScaleFactorScale(supported_scale_factors[i]);
NSSize desired_size_for_scale = NSMakeSize(desired_size.width * scale,
desired_size.height * scale);
NSImageRep* ns_image_rep = GetNSImageRepWithPixelSize(image,
@@ -72,7 +73,8 @@ gfx::ImageSkia ImageSkiaFromResizedNSImage(NSImage* image,
if (bitmap.isNull())
continue;
- image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
+ image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap,
+ supported_scale_factors[i]));
}
return image_skia;
}
@@ -88,7 +90,7 @@ NSImage* NSImageFromImageSkia(const gfx::ImageSkia& image_skia) {
return nil;
base::scoped_nsobject<NSImage> image([[NSImage alloc] init]);
- image_skia.EnsureRepsForSupportedScales();
+ image_skia.EnsureRepsForSupportedScaleFactors();
std::vector<gfx::ImageSkiaRep> image_reps = image_skia.image_reps();
for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin();
it != image_reps.end(); ++it) {
@@ -106,7 +108,7 @@ NSImage* NSImageFromImageSkiaWithColorSpace(const gfx::ImageSkia& image_skia,
return nil;
base::scoped_nsobject<NSImage> image([[NSImage alloc] init]);
- image_skia.EnsureRepsForSupportedScales();
+ image_skia.EnsureRepsForSupportedScaleFactors();
std::vector<gfx::ImageSkiaRep> image_reps = image_skia.image_reps();
for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin();
it != image_reps.end(); ++it) {
diff --git a/ui/gfx/image/image_unittest.cc b/ui/gfx/image/image_unittest.cc
index 3595828..6d3c649 100644
--- a/ui/gfx/image/image_unittest.cc
+++ b/ui/gfx/image/image_unittest.cc
@@ -5,6 +5,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPaint.h"
+#include "ui/base/layout.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_png_rep.h"
#include "ui/gfx/image/image_skia.h"
@@ -30,15 +31,6 @@ const bool kUsesSkiaNatively = false;
#endif
class ImageTest : public testing::Test {
- public:
- ImageTest() {
- std::vector<float> scales;
- scales.push_back(1.0f);
-#if !defined(OS_IOS)
- scales.push_back(2.0f);
-#endif
- gfx::ImageSkia::SetSupportedScales(scales);
- }
};
namespace gt = gfx::test;
@@ -103,14 +95,14 @@ TEST_F(ImageTest, EmptyImageFromEmptyPlatformImage) {
// invalid data.
TEST_F(ImageTest, EmptyImageFromObviouslyInvalidPNGImage) {
std::vector<gfx::ImagePNGRep> image_png_reps1;
- image_png_reps1.push_back(gfx::ImagePNGRep(NULL, 1.0f));
+ image_png_reps1.push_back(gfx::ImagePNGRep(NULL, ui::SCALE_FACTOR_100P));
gfx::Image image1(image_png_reps1);
EXPECT_TRUE(image1.IsEmpty());
EXPECT_EQ(0U, image1.RepresentationCount());
std::vector<gfx::ImagePNGRep> image_png_reps2;
image_png_reps2.push_back(gfx::ImagePNGRep(
- new base::RefCountedBytes(), 1.0f));
+ new base::RefCountedBytes(), ui::SCALE_FACTOR_100P));
gfx::Image image2(image_png_reps2);
EXPECT_TRUE(image2.IsEmpty());
EXPECT_EQ(0U, image2.RepresentationCount());
@@ -174,7 +166,7 @@ TEST_F(ImageTest, ImageNo1xToPNG) {
const int kSize2x = 50;
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(gt::CreateBitmap(
- kSize2x, kSize2x), 2.0f));
+ kSize2x, kSize2x), ui::SCALE_FACTOR_200P));
gfx::Image image1(image_skia);
scoped_refptr<base::RefCountedMemory> png_bytes1 = image1.As1xPNGBytes();
EXPECT_TRUE(png_bytes1.get());
@@ -182,7 +174,7 @@ TEST_F(ImageTest, ImageNo1xToPNG) {
std::vector<gfx::ImagePNGRep> image_png_reps;
image_png_reps.push_back(gfx::ImagePNGRep(
- gt::CreatePNGBytes(kSize2x), 2.0f));
+ gt::CreatePNGBytes(kSize2x), ui::SCALE_FACTOR_200P));
gfx::Image image2(image_png_reps);
EXPECT_FALSE(image2.IsEmpty());
EXPECT_EQ(0, image2.Width());
@@ -200,9 +192,9 @@ TEST_F(ImageTest, CreateExtractPNGBytes) {
scoped_refptr<base::RefCountedMemory> bytes1x = gt::CreatePNGBytes(kSize1x);
std::vector<gfx::ImagePNGRep> image_png_reps;
- image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, ui::SCALE_FACTOR_100P));
image_png_reps.push_back(gfx::ImagePNGRep(
- gt::CreatePNGBytes(kSize2x), 2.0f));
+ gt::CreatePNGBytes(kSize2x), ui::SCALE_FACTOR_200P));
gfx::Image image(image_png_reps);
EXPECT_FALSE(image.IsEmpty());
@@ -220,9 +212,9 @@ TEST_F(ImageTest, MultiResolutionImageSkiaToPNG) {
SkBitmap bitmap_1x = gt::CreateBitmap(kSize1x, kSize1x);
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap_1x,
- 1.0f));
+ ui::SCALE_FACTOR_100P));
image_skia.AddRepresentation(gfx::ImageSkiaRep(gt::CreateBitmap(
- kSize2x, kSize2x), 2.0f));
+ kSize2x, kSize2x), ui::SCALE_FACTOR_200P));
gfx::Image image(image_skia);
EXPECT_TRUE(gt::IsEqual(image.As1xPNGBytes(), bitmap_1x));
@@ -237,20 +229,20 @@ TEST_F(ImageTest, MultiResolutionPNGToImageSkia) {
scoped_refptr<base::RefCountedMemory> bytes2x = gt::CreatePNGBytes(kSize2x);
std::vector<gfx::ImagePNGRep> image_png_reps;
- image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f));
- image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, 2.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, ui::SCALE_FACTOR_100P));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, ui::SCALE_FACTOR_200P));
gfx::Image image(image_png_reps);
- std::vector<float> scales;
- scales.push_back(1.0f);
- scales.push_back(2.0f);
+ std::vector<ui::ScaleFactor> scale_factors;
+ scale_factors.push_back(ui::SCALE_FACTOR_100P);
+ scale_factors.push_back(ui::SCALE_FACTOR_200P);
gfx::ImageSkia image_skia = image.AsImageSkia();
EXPECT_TRUE(gt::ImageSkiaStructureMatches(image_skia, kSize1x, kSize1x,
- scales));
+ scale_factors));
EXPECT_TRUE(gt::IsEqual(bytes1x,
- image_skia.GetRepresentation(1.0f).sk_bitmap()));
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap()));
EXPECT_TRUE(gt::IsEqual(bytes2x,
- image_skia.GetRepresentation(2.0f).sk_bitmap()));
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap()));
}
TEST_F(ImageTest, MultiResolutionPNGToPlatform) {
@@ -260,18 +252,18 @@ TEST_F(ImageTest, MultiResolutionPNGToPlatform) {
scoped_refptr<base::RefCountedMemory> bytes1x = gt::CreatePNGBytes(kSize1x);
scoped_refptr<base::RefCountedMemory> bytes2x = gt::CreatePNGBytes(kSize2x);
std::vector<gfx::ImagePNGRep> image_png_reps;
- image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f));
- image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, 2.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, ui::SCALE_FACTOR_100P));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, ui::SCALE_FACTOR_200P));
gfx::Image from_png(image_png_reps);
gfx::Image from_platform(gt::CopyPlatformType(from_png));
#if defined(OS_IOS)
// On iOS the platform type (UIImage) only supports one resolution.
- std::vector<float> scales = gfx::ImageSkia::GetSupportedScales();
- EXPECT_EQ(scales.size(), 1U);
- if (scales[0] == 1.0f)
+ std::vector<ui::ScaleFactor> scale_factors = ui::GetSupportedScaleFactors();
+ EXPECT_EQ(scale_factors.size(), 1U);
+ if (scale_factors[0] == ui::SCALE_FACTOR_100P)
EXPECT_TRUE(gt::IsEqual(bytes1x, from_platform.AsBitmap()));
- else if (scales[0] == 2.0f)
+ else if (scale_factors[0] == ui::SCALE_FACTOR_200P)
EXPECT_TRUE(gt::IsEqual(bytes2x, from_platform.AsBitmap()));
else
ADD_FAILURE() << "Unexpected platform scale factor.";
@@ -289,7 +281,7 @@ TEST_F(ImageTest, PlatformToPNGEncodeAndDecode) {
EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
std::vector<gfx::ImagePNGRep> image_png_reps;
- image_png_reps.push_back(gfx::ImagePNGRep(png_data, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(png_data, ui::SCALE_FACTOR_100P));
gfx::Image from_png(image_png_reps);
EXPECT_TRUE(from_png.HasRepresentation(gfx::Image::kImageRepPNG));
@@ -300,13 +292,15 @@ TEST_F(ImageTest, PlatformToPNGEncodeAndDecode) {
// sure these work with the Skia Encode/Decode.
TEST_F(ImageTest, PNGEncodeFromSkiaDecodeToPlatform) {
// Force the conversion sequence skia to png to platform_type.
+ ui::ScaleFactor ideal_scale_factor = ui::GetScaleFactorFromScale(1.0f);
+
gfx::Image from_bitmap = gfx::Image::CreateFrom1xBitmap(
gt::CreateBitmap(25, 25));
scoped_refptr<base::RefCountedMemory> png_bytes =
from_bitmap.As1xPNGBytes();
std::vector<gfx::ImagePNGRep> image_png_reps;
- image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, ideal_scale_factor));
gfx::Image from_png(image_png_reps);
gfx::Image from_platform(gt::CopyPlatformType(from_png));
@@ -321,7 +315,7 @@ TEST_F(ImageTest, PNGEncodeFromPlatformDecodeToSkia) {
scoped_refptr<base::RefCountedMemory> png_bytes =
from_platform.As1xPNGBytes();
std::vector<gfx::ImagePNGRep> image_png_reps;
- image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, ui::SCALE_FACTOR_100P));
gfx::Image from_png(image_png_reps);
EXPECT_TRUE(gt::IsEqual(from_platform.AsBitmap(), from_png.AsBitmap()));
@@ -333,7 +327,7 @@ TEST_F(ImageTest, PNGDecodeToSkiaFailure) {
invalid_bytes->data().push_back('0');
std::vector<gfx::ImagePNGRep> image_png_reps;
image_png_reps.push_back(gfx::ImagePNGRep(
- invalid_bytes, 1.0f));
+ invalid_bytes, ui::SCALE_FACTOR_100P));
gfx::Image image(image_png_reps);
gt::CheckImageIndicatesPNGDecodeFailure(image);
}
@@ -344,7 +338,7 @@ TEST_F(ImageTest, PNGDecodeToPlatformFailure) {
invalid_bytes->data().push_back('0');
std::vector<gfx::ImagePNGRep> image_png_reps;
image_png_reps.push_back(gfx::ImagePNGRep(
- invalid_bytes, 1.0f));
+ invalid_bytes, ui::SCALE_FACTOR_100P));
gfx::Image from_png(image_png_reps);
gfx::Image from_platform(gt::CopyPlatformType(from_png));
gt::CheckImageIndicatesPNGDecodeFailure(from_platform);
@@ -642,16 +636,16 @@ TEST_F(ImageTest, MultiResolutionImageSkia) {
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(
gt::CreateBitmap(kWidth1x, kHeight1x),
- 1.0f));
+ ui::SCALE_FACTOR_100P));
image_skia.AddRepresentation(gfx::ImageSkiaRep(
gt::CreateBitmap(kWidth2x, kHeight2x),
- 2.0f));
+ ui::SCALE_FACTOR_200P));
- std::vector<float> scales;
- scales.push_back(1.0f);
- scales.push_back(2.0f);
+ std::vector<ui::ScaleFactor> scale_factors;
+ scale_factors.push_back(ui::SCALE_FACTOR_100P);
+ scale_factors.push_back(ui::SCALE_FACTOR_200P);
EXPECT_TRUE(gt::ImageSkiaStructureMatches(image_skia, kWidth1x, kHeight1x,
- scales));
+ scale_factors));
// Check that the image has a single representation.
gfx::Image image(image_skia);
@@ -667,13 +661,13 @@ TEST_F(ImageTest, RemoveFromMultiResolutionImageSkia) {
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(
- gt::CreateBitmap(kWidth2x, kHeight2x), 2.0f));
+ gt::CreateBitmap(kWidth2x, kHeight2x), ui::SCALE_FACTOR_200P));
EXPECT_EQ(1u, image_skia.image_reps().size());
- image_skia.RemoveRepresentation(1.0f);
+ image_skia.RemoveRepresentation(ui::SCALE_FACTOR_100P);
EXPECT_EQ(1u, image_skia.image_reps().size());
- image_skia.RemoveRepresentation(2.0f);
+ image_skia.RemoveRepresentation(ui::SCALE_FACTOR_200P);
EXPECT_EQ(0u, image_skia.image_reps().size());
}
@@ -685,7 +679,7 @@ TEST_F(ImageTest, OwnershipTest) {
SkBitmap bitmap(gt::CreateBitmap(10, 10));
EXPECT_TRUE(!bitmap.isNull());
image = gfx::Image(gfx::ImageSkia(
- gfx::ImageSkiaRep(bitmap, 1.0f)));
+ gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)));
}
EXPECT_TRUE(!image.ToSkBitmap()->isNull());
}
diff --git a/ui/gfx/image/image_unittest_util.cc b/ui/gfx/image/image_unittest_util.cc
index 4baf30a..ef59eb6 100644
--- a/ui/gfx/image/image_unittest_util.cc
+++ b/ui/gfx/image/image_unittest_util.cc
@@ -48,11 +48,11 @@ bool ColorsClose(SkColor color1, SkColor color2) {
} // namespace
-std::vector<float> Get1xAnd2xScales() {
- std::vector<float> scales;
- scales.push_back(1.0f);
- scales.push_back(2.0f);
- return scales;
+std::vector<ui::ScaleFactor> Get1xAnd2xScaleFactors() {
+ std::vector<ui::ScaleFactor> scale_factors;
+ scale_factors.push_back(ui::SCALE_FACTOR_100P);
+ scale_factors.push_back(ui::SCALE_FACTOR_200P);
+ return scale_factors;
}
const SkBitmap CreateBitmap(int width, int height) {
@@ -89,9 +89,10 @@ bool IsEqual(const gfx::Image& img1, const gfx::Image& img2) {
return false;
for (size_t i = 0; i < img1_reps.size(); ++i) {
- float scale = img1_reps[i].scale();
- const gfx::ImageSkiaRep& image_rep2 = image_skia2.GetRepresentation(scale);
- if (image_rep2.scale() != scale ||
+ ui::ScaleFactor scale_factor = img1_reps[i].scale_factor();
+ const gfx::ImageSkiaRep& image_rep2 = image_skia2.GetRepresentation(
+ scale_factor);
+ if (image_rep2.scale_factor() != scale_factor ||
!IsEqual(img1_reps[i].sk_bitmap(), image_rep2.sk_bitmap())) {
return false;
}
@@ -149,22 +150,24 @@ bool ImageSkiaStructureMatches(
const gfx::ImageSkia& image_skia,
int width,
int height,
- const std::vector<float>& scales) {
+ const std::vector<ui::ScaleFactor>& scale_factors) {
if (image_skia.isNull() ||
image_skia.width() != width ||
image_skia.height() != height ||
- image_skia.image_reps().size() != scales.size()) {
+ image_skia.image_reps().size() != scale_factors.size()) {
return false;
}
- for (size_t i = 0; i < scales.size(); ++i) {
+ for (size_t i = 0; i < scale_factors.size(); ++i) {
gfx::ImageSkiaRep image_rep =
- image_skia.GetRepresentation(scales[i]);
- if (image_rep.is_null() || image_rep.scale() != scales[i])
+ image_skia.GetRepresentation(scale_factors[i]);
+ if (image_rep.is_null() ||
+ image_rep.scale_factor() != scale_factors[i])
return false;
- if (image_rep.pixel_width() != static_cast<int>(width * scales[i]) ||
- image_rep.pixel_height() != static_cast<int>(height * scales[i])) {
+ float scale = ui::GetScaleFactorScale(scale_factors[i]);
+ if (image_rep.pixel_width() != static_cast<int>(width * scale) ||
+ image_rep.pixel_height() != static_cast<int>(height * scale)) {
return false;
}
}
@@ -180,7 +183,8 @@ bool IsEmpty(const gfx::Image& image) {
PlatformImage CreatePlatformImage() {
const SkBitmap bitmap(CreateBitmap(25, 25));
#if defined(OS_IOS)
- float scale = ImageSkia::GetMaxSupportedScale();
+ ui::ScaleFactor scale_factor = ui::GetMaxScaleFactor();
+ float scale = ui::GetScaleFactorScale(scale_factor);
base::ScopedCFTypeRef<CGColorSpaceRef> color_space(
CGColorSpaceCreateDeviceRGB());
diff --git a/ui/gfx/image/image_unittest_util.h b/ui/gfx/image/image_unittest_util.h
index 4788e4e..a2293c8 100644
--- a/ui/gfx/image/image_unittest_util.h
+++ b/ui/gfx/image/image_unittest_util.h
@@ -8,6 +8,7 @@
#ifndef UI_GFX_IMAGE_IMAGE_UNITTEST_UTIL_H_
#define UI_GFX_IMAGE_IMAGE_UNITTEST_UTIL_H_
+#include "ui/base/layout.h"
#include "ui/gfx/image/image.h"
#include "third_party/skia/include/core/SkColor.h"
@@ -24,7 +25,7 @@ typedef GdkPixbuf* PlatformImage;
typedef gfx::ImageSkia PlatformImage;
#endif
-std::vector<float> Get1xAnd2xScales();
+std::vector<ui::ScaleFactor> Get1xAnd2xScaleFactors();
// Create a bitmap of |width|x|height|.
const SkBitmap CreateBitmap(int width, int height);
@@ -64,7 +65,7 @@ bool ImageSkiaStructureMatches(
const gfx::ImageSkia& image_skia,
int width,
int height,
- const std::vector<float>& scale_factors);
+ const std::vector<ui::ScaleFactor>& scale_factors);
bool IsEmpty(const gfx::Image& image);
diff --git a/ui/gfx/image/image_util.cc b/ui/gfx/image/image_util.cc
index 59d631d..e230a0b 100644
--- a/ui/gfx/image/image_util.cc
+++ b/ui/gfx/image/image_util.cc
@@ -26,8 +26,8 @@ Image ImageFrom1xJPEGEncodedData(const unsigned char* input,
bool JPEG1xEncodedDataFromImage(const Image& image, int quality,
std::vector<unsigned char>* dst) {
const gfx::ImageSkiaRep& image_skia_rep =
- image.AsImageSkia().GetRepresentation(1.0f);
- if (image_skia_rep.scale() != 1.0f)
+ image.AsImageSkia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ if (image_skia_rep.scale_factor() != ui::SCALE_FACTOR_100P)
return false;
const SkBitmap& bitmap = image_skia_rep.sk_bitmap();
diff --git a/ui/gfx/skia_util.cc b/ui/gfx/skia_util.cc
index 1d05d1a..50092ab 100644
--- a/ui/gfx/skia_util.cc
+++ b/ui/gfx/skia_util.cc
@@ -68,7 +68,7 @@ skia::RefPtr<SkShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep,
image_rep.sk_bitmap(), tile_mode, tile_mode));
SkScalar scale_x = local_matrix.getScaleX();
SkScalar scale_y = local_matrix.getScaleY();
- SkScalar bitmap_scale = SkFloatToScalar(image_rep.scale());
+ SkScalar bitmap_scale = SkFloatToScalar(image_rep.GetScale());
// Unscale matrix by |bitmap_scale| such that the bitmap is drawn at the
// correct density.
diff --git a/ui/gfx/win/dpi.cc b/ui/gfx/win/dpi.cc
index 2d2024f..98d23bd 100644
--- a/ui/gfx/win/dpi.cc
+++ b/ui/gfx/win/dpi.cc
@@ -40,7 +40,7 @@ float GetDeviceScaleFactorImpl() {
float scale = gfx::Display::HasForceDeviceScaleFactor() ?
gfx::Display::GetForcedDeviceScaleFactor() : gfx::GetDPIScale();
// Quantize to nearest supported scale factor.
- scale = ui::GetImageScale(ui::GetSupportedScaleFactor(scale));
+ scale = ui::GetScaleFactorScale(ui::GetScaleFactorFromScale(scale));
return scale;
}
return 1.0f;
diff --git a/ui/message_center/views/notification_view.cc b/ui/message_center/views/notification_view.cc
index 11b3474..b6e8bcc 100644
--- a/ui/message_center/views/notification_view.cc
+++ b/ui/message_center/views/notification_view.cc
@@ -108,8 +108,7 @@ bool HasAlpha(gfx::ImageSkia& image, views::Widget* widget) {
}
// Extract that bitmap's alpha and look for a non-opaque pixel there.
- SkBitmap bitmap =
- image.GetRepresentation(ui::GetImageScale(factor)).sk_bitmap();
+ SkBitmap bitmap = image.GetRepresentation(factor).sk_bitmap();
if (!bitmap.isNull()) {
SkBitmap alpha;
alpha.setConfig(SkBitmap::kA1_Config, bitmap.width(), bitmap.height(), 0);
diff --git a/ui/native_theme/native_theme_base.cc b/ui/native_theme/native_theme_base.cc
index 43bc222..2f94f54 100644
--- a/ui/native_theme/native_theme_base.cc
+++ b/ui/native_theme/native_theme_base.cc
@@ -1004,9 +1004,10 @@ void NativeThemeBase::DrawImageInt(
// TODO(pkotwicz): Do something better and don't infer device
// scale factor from canvas scale.
SkMatrix m = sk_canvas->getTotalMatrix();
- float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX()));
+ ui::ScaleFactor device_scale_factor = ui::GetScaleFactorFromScale(
+ SkScalarAbs(m.getScaleX()));
scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling(
- sk_canvas, device_scale));
+ sk_canvas, device_scale_factor));
canvas->DrawImageInt(image, src_x, src_y, src_w, src_h,
dest_x, dest_y, dest_w, dest_h, true);
}
@@ -1018,9 +1019,10 @@ void NativeThemeBase::DrawTiledImage(SkCanvas* sk_canvas,
// TODO(pkotwicz): Do something better and don't infer device
// scale factor from canvas scale.
SkMatrix m = sk_canvas->getTotalMatrix();
- float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX()));
+ ui::ScaleFactor device_scale_factor = ui::GetScaleFactorFromScale(
+ SkScalarAbs(m.getScaleX()));
scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling(
- sk_canvas, device_scale));
+ sk_canvas, device_scale_factor));
canvas->TileImageInt(image, src_x, src_y, tile_scale_x,
tile_scale_y, dest_x, dest_y, w, h);
}
diff --git a/ui/views/controls/button/image_button.h b/ui/views/controls/button/image_button.h
index 8dbe9d8..5ea0fa9 100644
--- a/ui/views/controls/button/image_button.h
+++ b/ui/views/controls/button/image_button.h
@@ -7,7 +7,6 @@
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
-#include "ui/base/layout.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/views/controls/button/custom_button.h"
diff --git a/ui/views/controls/glow_hover_controller.cc b/ui/views/controls/glow_hover_controller.cc
index 5ce23fa..f7fcd3f 100644
--- a/ui/views/controls/glow_hover_controller.cc
+++ b/ui/views/controls/glow_hover_controller.cc
@@ -83,7 +83,7 @@ void GlowHoverController::Draw(gfx::Canvas* canvas,
// Draw a radial gradient to hover_canvas.
gfx::Canvas hover_canvas(gfx::Size(mask_image.width(), mask_image.height()),
- canvas->image_scale(),
+ canvas->scale_factor(),
false);
// Draw a radial gradient to hover_canvas.
diff --git a/ui/views/controls/menu/menu_win.cc b/ui/views/controls/menu/menu_win.cc
index 2e5a4dc..ac08ec7 100644
--- a/ui/views/controls/menu/menu_win.cc
+++ b/ui/views/controls/menu/menu_win.cc
@@ -183,7 +183,8 @@ class MenuHostWindow : public gfx::WindowImpl {
// Draw the icon after the label, otherwise it would be covered
// by the label.
- gfx::ImageSkiaRep icon_image_rep = data->icon.GetRepresentation(1.0f);
+ gfx::ImageSkiaRep icon_image_rep =
+ data->icon.GetRepresentation(ui::SCALE_FACTOR_100P);
if (data->icon.width() != 0 && data->icon.height() != 0) {
gfx::Canvas canvas(icon_image_rep, false);
skia::DrawToNativeContext(
diff --git a/ui/views/controls/menu/native_menu_win.cc b/ui/views/controls/menu/native_menu_win.cc
index 9349c69..c48a98c 100644
--- a/ui/views/controls/menu/native_menu_win.cc
+++ b/ui/views/controls/menu/native_menu_win.cc
@@ -261,7 +261,7 @@ class NativeMenuWin::MenuHostWindow {
const gfx::ImageSkia* skia_icon = icon.ToImageSkia();
DCHECK(type != ui::MenuModel::TYPE_CHECK);
gfx::Canvas canvas(
- skia_icon->GetRepresentation(1.0f),
+ skia_icon->GetRepresentation(ui::SCALE_FACTOR_100P),
false);
skia::DrawToNativeContext(
canvas.sk_canvas(), dc,
@@ -287,7 +287,7 @@ class NativeMenuWin::MenuHostWindow {
(height - kItemTopMargin - kItemBottomMargin -
config.check_height) / 2;
gfx::Canvas canvas(gfx::Size(config.check_width, config.check_height),
- 1.0f,
+ ui::SCALE_FACTOR_100P,
false);
NativeTheme::ExtraParams extra;
extra.menu_check.is_radio = false;
diff --git a/ui/views/drag_utils.cc b/ui/views/drag_utils.cc
index b156276..61f4b76 100644
--- a/ui/views/drag_utils.cc
+++ b/ui/views/drag_utils.cc
@@ -22,8 +22,8 @@
#error
#endif
-float GetDeviceScaleForNativeView(views::Widget* widget) {
- float device_scale = 1.0f;
+ui::ScaleFactor GetDeviceScaleFactorForNativeView(views::Widget* widget) {
+ ui::ScaleFactor device_scale_factor = ui::SCALE_FACTOR_100P;
#if defined(USE_AURA)
// The following code should work on other platforms as well. But we do not
// yet care about device scale factor on other platforms. So to keep drag and
@@ -32,10 +32,11 @@ float GetDeviceScaleForNativeView(views::Widget* widget) {
gfx::NativeView view = widget->GetNativeView();
gfx::Display display = gfx::Screen::GetScreenFor(view)->
GetDisplayNearestWindow(view);
- device_scale = display.device_scale_factor();
+ device_scale_factor = ui::GetScaleFactorFromScale(
+ display.device_scale_factor());
}
#endif
- return device_scale;
+ return device_scale_factor;
}
namespace views {
@@ -65,8 +66,9 @@ void RunShellDrag(gfx::NativeView view,
gfx::Canvas* GetCanvasForDragImage(views::Widget* widget,
const gfx::Size& canvas_size) {
- float device_scale = GetDeviceScaleForNativeView(widget);
- return new gfx::Canvas(canvas_size, device_scale, false);
+ ui::ScaleFactor device_scale_factor =
+ GetDeviceScaleFactorForNativeView(widget);
+ return new gfx::Canvas(canvas_size, device_scale_factor, false);
}
} // namespace views
diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
index d7ba59c..485f450 100644
--- a/ui/views/win/hwnd_message_handler.cc
+++ b/ui/views/win/hwnd_message_handler.cc
@@ -1041,8 +1041,10 @@ void HWNDMessageHandler::ClientAreaSizeChanged() {
gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)),
std::max(0, static_cast<int>(r.bottom - r.top)));
delegate_->HandleClientSizeChanged(s);
- if (use_layered_buffer_)
- layered_window_contents_.reset(new gfx::Canvas(s, 1.0f, false));
+ if (use_layered_buffer_) {
+ layered_window_contents_.reset(
+ new gfx::Canvas(s, ui::SCALE_FACTOR_100P, false));
+ }
}
bool HWNDMessageHandler::GetClientAreaInsets(gfx::Insets* insets) const {
diff --git a/ui/webui/web_ui_util.cc b/ui/webui/web_ui_util.cc
index 1fda351..e171da8 100644
--- a/ui/webui/web_ui_util.cc
+++ b/ui/webui/web_ui_util.cc
@@ -96,7 +96,7 @@ bool ParseScaleFactor(const base::StringPiece& identifier,
return false;
}
- *scale_factor = ui::GetSupportedScaleFactor(static_cast<float>(scale));
+ *scale_factor = ui::GetScaleFactorFromScale(static_cast<float>(scale));
return true;
}