summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-24 03:25:48 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-24 03:25:48 +0000
commit50b66263c3a926fd1de75248fb2100e72715696e (patch)
treea4ad06309d29bacf1c6de692a20f7d214f8ea7ab
parent2fa342b8ed9c8777f78b3ba8b344dab24a04ef97 (diff)
downloadchromium_src-50b66263c3a926fd1de75248fb2100e72715696e.zip
chromium_src-50b66263c3a926fd1de75248fb2100e72715696e.tar.gz
chromium_src-50b66263c3a926fd1de75248fb2100e72715696e.tar.bz2
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 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=224473 Review URL: https://codereview.chromium.org/24175004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224876 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.cc9
-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/render_widget_snapshot_taker_unittest.cc3
-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/fast_show_pickler.cc6
-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/app_list/test/fast_show_pickler_unittest.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
162 files changed, 1015 insertions, 1044 deletions
diff --git a/apps/shell_window.cc b/apps/shell_window.cc
index 44a3858..cd8ddd0 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(ui::SCALE_FACTOR_100P);
+ app_icon_image_->image_skia().GetRepresentation(1.0f);
}
void ShellWindow::CloseContents(WebContents* contents) {
diff --git a/ash/desktop_background/wallpaper_resizer_unittest.cc b/ash/desktop_background/wallpaper_resizer_unittest.cc
index 5761b67..8447307 100644
--- a/ash/desktop_background/wallpaper_resizer_unittest.cc
+++ b/ash/desktop_background/wallpaper_resizer_unittest.cc
@@ -104,16 +104,14 @@ 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),
- ui::SCALE_FACTOR_100P));
+ gfx::ImageSkia small_image(gfx::ImageSkiaRep(gfx::Size(10, 20), 1.0f));
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),
- ui::SCALE_FACTOR_100P));
+ gfx::ImageSkia large_image(gfx::ImageSkiaRep(gfx::Size(1000, 1000), 1.0f));
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 5ca7cec..3429df7 100644
--- a/ash/display/mirror_window_controller.cc
+++ b/ash/display/mirror_window_controller.cc
@@ -127,10 +127,8 @@ 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(device_scale_factor_);
+ image.GetRepresentation(display.device_scale_factor());
size_ = image_rep.pixel_size();
cursor_image_ = gfx::ImageSkia::CreateFrom1xBitmap(image_rep.sk_bitmap());
}
@@ -139,7 +137,6 @@ 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 ba46192..0cd770e 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), ui::SCALE_FACTOR_100P);
+ gfx::ImageSkiaRep image_rep(gfx::Size(10, 20), 1.0f);
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 5d0f2be..84eef1e 100644
--- a/ash/drag_drop/drag_image_view.cc
+++ b/ash/drag_drop/drag_image_view.cc
@@ -90,21 +90,17 @@ 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_factor);
+ gfx::ImageSkiaRep image_rep = GetImage().GetRepresentation(device_scale);
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_factor));
+ gfx::ImageSkia image_skia(gfx::ImageSkiaRep(scaled, device_scale));
canvas->DrawImageInt(image_skia, 0, 0);
}
}
diff --git a/ash/launcher/launcher_delegate.h b/ash/launcher/launcher_delegate.h
index 06e0445..41d0c29 100644
--- a/ash/launcher/launcher_delegate.h
+++ b/ash/launcher/launcher_delegate.h
@@ -8,6 +8,10 @@
#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 65fb0f0..1708fe6 100644
--- a/ash/launcher/launcher_item_delegate_manager.cc
+++ b/ash/launcher/launcher_item_delegate_manager.cc
@@ -4,6 +4,8 @@
#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 f0dae34..25306b3 100644
--- a/ash/shell/app_list.cc
+++ b/ash/shell/app_list.cc
@@ -204,8 +204,7 @@ 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, ui::SCALE_FACTOR_100P,
- false /* is_opaque */);
+ gfx::Canvas canvas(icon_size, 1.0f, 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 4dfcea4..f076483 100644
--- a/ash/shell/window_watcher.cc
+++ b/ash/shell/window_watcher.cc
@@ -118,8 +118,7 @@ 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,
- ui::SCALE_FACTOR_100P));
+ item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f));
model->Add(item);
}
diff --git a/ash/system/chromeos/network/network_icon.cc b/ash/system/chromeos/network/network_icon.cc
index 5e914e7..d3c4899 100644
--- a/ash/system/chromeos/network/network_icon.cc
+++ b/ash/system/chromeos/network/network_icon.cc
@@ -196,13 +196,12 @@ class EmptyImageSource: public gfx::ImageSkiaSource {
: size_(size) {
}
- virtual gfx::ImageSkiaRep GetImageForScale(
- ui::ScaleFactor scale_factor) OVERRIDE {
- gfx::Size pixel_size = gfx::ToFlooredSize(
- gfx::ScaleSize(size_, ui::GetScaleFactorScale(scale_factor)));
+ virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ gfx::Size pixel_size = gfx::ToFlooredSize(gfx::ScaleSize(size_, scale));
SkBitmap empty_bitmap = GetEmptyBitmap(pixel_size);
- return gfx::ImageSkiaRep(empty_bitmap, scale_factor);
+ return gfx::ImageSkiaRep(empty_bitmap, scale);
}
+
private:
const gfx::Size size_;
@@ -220,9 +219,8 @@ class NetworkIconImageSource : public gfx::ImageSkiaSource {
// TODO(pkotwicz): Figure out what to do when a new image resolution becomes
// available.
- virtual gfx::ImageSkiaRep GetImageForScale(
- ui::ScaleFactor scale_factor) OVERRIDE {
- gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale_factor);
+ virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale);
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 b27fc7b..0e53e33 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->scale_factor(), false);
+ gfx::Canvas temporary_canvas(bounds.size(), canvas->image_scale(), 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 f319c66..2f82c13 100644
--- a/chrome/browser/android/provider/chrome_browser_provider.cc
+++ b/chrome/browser/android/provider/chrome_browser_provider.cc
@@ -39,6 +39,7 @@
#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;
@@ -676,7 +677,7 @@ class BookmarkIconFetchTask : public FaviconServiceTask {
url,
chrome::FAVICON | chrome::TOUCH_ICON,
gfx::kFaviconSize),
- ui::GetMaxScaleFactor(),
+ ResourceBundle::GetSharedInstance().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 7bf7679..1f0f785 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.EnsureRepsForSupportedScaleFactors();
+ wallpaper.EnsureRepsForSupportedScales();
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 27c82cf..9448649 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_.EnsureRepsForSupportedScaleFactors();
+ wallpaper_.EnsureRepsForSupportedScales();
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.EnsureRepsForSupportedScaleFactors();
+ wallpaper.EnsureRepsForSupportedScales();
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 58e85a0..c75fb09 100644
--- a/chrome/browser/chromeos/login/helper.cc
+++ b/chrome/browser/chromeos/login/helper.cc
@@ -15,6 +15,7 @@
#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 {
@@ -36,8 +37,7 @@ int GetCurrentUserImageSize() {
float scale_factor = gfx::Display::GetForcedDeviceScaleFactor();
if (scale_factor > 1.0f)
return static_cast<int>(scale_factor * kBaseUserImageSize);
- return kBaseUserImageSize *
- ui::GetScaleFactorScale(ui::GetMaxScaleFactor());
+ return kBaseUserImageSize * gfx::ImageSkia::GetMaxSupportedScale();
}
namespace login {
diff --git a/chrome/browser/chromeos/login/wallpaper_manager.cc b/chrome/browser/chromeos/login/wallpaper_manager.cc
index 3692a2a..3920d71 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().EnsureRepsForSupportedScaleFactors();
+ wallpaper.image().EnsureRepsForSupportedScales();
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 f9785f8..0601780 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,
- ui::ScaleFactor scale_factor) {
- SkBitmap bitmap1 = i1.GetRepresentation(scale_factor).sk_bitmap();
- SkBitmap bitmap2 = i2.GetRepresentation(scale_factor).sk_bitmap();
+ float scale) {
+ SkBitmap bitmap1 = i1.GetRepresentation(scale).sk_bitmap();
+ SkBitmap bitmap2 = i2.GetRepresentation(scale).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::test::SetSupportedScaleFactors(supported_scale_factors);
+ ui::SetSupportedScaleFactors(supported_scale_factors);
#endif
// We should not be creating icons asynchronously, so we don't need an
@@ -171,13 +171,12 @@ 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(ui::SCALE_FACTOR_200P));
+ EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- ui::SCALE_FACTOR_100P));
+ 1.0f));
// Tell the extension to update the icon using path.
GetBrowserActionsBar().Press(0);
@@ -190,12 +189,12 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
action_icon_last_id = action_icon_current_id;
EXPECT_FALSE(
- action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
+ action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- ui::SCALE_FACTOR_100P));
+ 1.0f));
// Tell the extension to update the icon using dictionary of ImageData
// objects.
@@ -208,13 +207,12 @@ 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(ui::SCALE_FACTOR_200P));
+ EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- ui::SCALE_FACTOR_100P));
+ 1.0f));
// Tell the extension to update the icon using dictionary of paths.
GetBrowserActionsBar().Press(0);
@@ -226,13 +224,12 @@ 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(ui::SCALE_FACTOR_200P));
+ EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- ui::SCALE_FACTOR_100P));
+ 1.0f));
// Tell the extension to update the icon using dictionary of ImageData
// objects, but setting only size 19.
@@ -245,13 +242,12 @@ 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(ui::SCALE_FACTOR_200P));
+ EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- ui::SCALE_FACTOR_100P));
+ 1.0f));
// Tell the extension to update the icon using dictionary of paths, but
// setting only size 19.
@@ -264,13 +260,12 @@ 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(ui::SCALE_FACTOR_200P));
+ EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- ui::SCALE_FACTOR_100P));
+ 1.0f));
// Tell the extension to update the icon using dictionary of ImageData
// objects, but setting only size 38.
@@ -281,8 +276,8 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia();
- EXPECT_FALSE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_100P));
- EXPECT_TRUE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_200P));
+ EXPECT_FALSE(action_icon_skia->HasRepresentation(1.0f));
+ EXPECT_TRUE(action_icon_skia->HasRepresentation(2.0f));
action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
EXPECT_GT(action_icon_current_id, action_icon_last_id);
@@ -290,12 +285,12 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
EXPECT_TRUE(gfx::BitmapsAreEqual(
*action_icon.ToSkBitmap(),
- action_icon_skia->GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap()));
+ action_icon_skia->GetRepresentation(2.0f).sk_bitmap()));
EXPECT_TRUE(ImagesAreEqualAtScale(
AddBackgroundForViews(*action_icon_skia),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
- ui::SCALE_FACTOR_200P));
+ 2.0f));
// 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 3d4c46d..488e852 100644
--- a/chrome/browser/extensions/api/extension_action/extension_action_api.cc
+++ b/chrome/browser/extensions/api/extension_action/extension_action_api.cc
@@ -100,8 +100,7 @@ bool StringToSkBitmap(const std::string& str, SkBitmap* bitmap) {
}
// Conversion function for reading/writing to storage.
-std::string RepresentationToString(const gfx::ImageSkia& image,
- ui::ScaleFactor scale) {
+std::string RepresentationToString(const gfx::ImageSkia& image, float scale) {
SkBitmap bitmap = image.GetRepresentation(scale).sk_bitmap();
IPC::Message bitmap_pickle;
// Clear the header values so they don't vary in serialization.
@@ -144,7 +143,8 @@ void SetDefaultsFromValue(const base::DictionaryValue* dict,
if (icon_value->GetString(kIconSizes[i].size_string, &str_value) &&
StringToSkBitmap(str_value, &bitmap)) {
CHECK(!bitmap.isNull());
- icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale));
+ float scale = ui::GetImageScale(kIconSizes[i].scale);
+ icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
}
}
action->SetIcon(kTabId, gfx::Image(icon));
@@ -172,10 +172,11 @@ 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++) {
- if (icon.HasRepresentation(kIconSizes[i].scale)) {
+ float scale = ui::GetImageScale(kIconSizes[i].scale);
+ if (icon.HasRepresentation(scale)) {
icon_value->SetString(
kIconSizes[i].size_string,
- RepresentationToString(icon, kIconSizes[i].scale));
+ RepresentationToString(icon, scale));
}
}
dict->Set(kIconStorageKey, icon_value);
@@ -696,7 +697,8 @@ bool ExtensionActionSetIconFunction::RunExtensionAction() {
SkBitmap bitmap;
EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap));
CHECK(!bitmap.isNull());
- icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale));
+ float scale = ui::GetImageScale(kIconSizes[i].scale);
+ icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
}
}
diff --git a/chrome/browser/extensions/api/notifications/notifications_api.cc b/chrome/browser/extensions/api/notifications/notifications_api.cc
index e78798e..bd4054d 100644
--- a/chrome/browser/extensions/api/notifications/notifications_api.cc
+++ b/chrome/browser/extensions/api/notifications/notifications_api.cc
@@ -102,8 +102,7 @@ bool NotificationBitmapToGfxImage(
}
// TODO(dewittj): Handle HiDPI images.
- ui::ScaleFactor scale_factor(ui::SCALE_FACTOR_100P);
- gfx::ImageSkia skia(gfx::ImageSkiaRep(bitmap, scale_factor));
+ gfx::ImageSkia skia(gfx::ImageSkiaRep(bitmap, 1.0f));
*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 4eb0fc2..1172b2b 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().EnsureRepsForSupportedScaleFactors();
+ image->image_skia().EnsureRepsForSupportedScales();
}
void AppIconLoaderImpl::ClearImage(const std::string& id) {
diff --git a/chrome/browser/extensions/extension_action.cc b/chrome/browser/extensions/extension_action.cc
index ccce0ca..50ac185 100644
--- a/chrome/browser/extensions/extension_action.cc
+++ b/chrome/browser/extensions/extension_action.cc
@@ -39,13 +39,12 @@ class GetAttentionImageSource : public gfx::ImageSkiaSource {
: icon_(icon) {}
// gfx::ImageSkiaSource overrides:
- virtual gfx::ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor)
- OVERRIDE {
- gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale_factor);
+ virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale);
color_utils::HSL shift = {-1, 0, 0.5};
return gfx::ImageSkiaRep(
SkBitmapOperations::CreateHSLShiftedBitmap(icon_rep.sk_bitmap(), shift),
- icon_rep.scale_factor());
+ icon_rep.scale());
}
private:
@@ -68,7 +67,7 @@ class AnimatedIconImageSource : public gfx::ImageSkiaSource {
private:
virtual ~AnimatedIconImageSource() {}
- virtual gfx::ImageSkiaRep GetImageForScale(ui::ScaleFactor scale) OVERRIDE {
+ virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
gfx::ImageSkiaRep original_rep = image_.GetRepresentation(scale);
if (!animation_.get())
return original_rep;
@@ -77,8 +76,7 @@ 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_factor());
+ animation_->Apply(original_rep.sk_bitmap()), original_rep.scale());
}
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 3eadffa..649ac62 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_factor() == image_rep2.scale_factor() &&
+ return image_rep1.scale() == image_rep2.scale() &&
gfx::BitmapsAreEqual(image_rep1.sk_bitmap(), image_rep2.sk_bitmap());
}
@@ -53,15 +53,14 @@ gfx::Image EnsureImageSize(const gfx::Image& original, int size) {
return gfx::Image::CreateFrom1xBitmap(resized);
}
-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::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::Image LoadIcon(const std::string& filename) {
@@ -203,8 +202,8 @@ TEST_F(ExtensionActionIconFactoryTest, NoIcons) {
gfx::Image icon = icon_factory.GetIcon(0);
EXPECT_TRUE(ImageRepsAreEqual(
- favicon.GetRepresentation(ui::SCALE_FACTOR_100P),
- icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
+ favicon.GetRepresentation(1.0f),
+ icon.ToImageSkia()->GetRepresentation(1.0f)));
}
// If the icon has been set using |SetIcon|, the factory should return that
@@ -234,15 +233,15 @@ TEST_F(ExtensionActionIconFactoryTest, AfterSetIcon) {
gfx::Image icon = icon_factory.GetIcon(0);
EXPECT_TRUE(ImageRepsAreEqual(
- set_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P),
- icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
+ set_icon.ToImageSkia()->GetRepresentation(1.0f),
+ icon.ToImageSkia()->GetRepresentation(1.0f)));
// It should still return favicon for another tabs.
icon = icon_factory.GetIcon(1);
EXPECT_TRUE(ImageRepsAreEqual(
- GetFavicon().GetRepresentation(ui::SCALE_FACTOR_100P),
- icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
+ GetFavicon().GetRepresentation(1.0f),
+ icon.ToImageSkia()->GetRepresentation(1.0f)));
}
// If there is a default icon, and the icon has not been set using |SetIcon|,
@@ -277,8 +276,8 @@ TEST_F(ExtensionActionIconFactoryTest, DefaultIcon) {
// The icon should be loaded asynchronously. Initially a transparent icon
// should be returned.
EXPECT_TRUE(ImageRepsAreEqual(
- CreateBlankRep(19, ui::SCALE_FACTOR_100P),
- icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
+ CreateBlankRep(19, 1.0f),
+ icon.ToImageSkia()->GetRepresentation(1.0f)));
WaitForIconUpdate();
@@ -286,15 +285,15 @@ TEST_F(ExtensionActionIconFactoryTest, DefaultIcon) {
// The default icon representation should be loaded at this point.
EXPECT_TRUE(ImageRepsAreEqual(
- default_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P),
- icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
+ default_icon.ToImageSkia()->GetRepresentation(1.0f),
+ icon.ToImageSkia()->GetRepresentation(1.0f)));
// The same icon should be returned for the other tabs.
icon = icon_factory.GetIcon(1);
EXPECT_TRUE(ImageRepsAreEqual(
- default_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P),
- icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
+ default_icon.ToImageSkia()->GetRepresentation(1.0f),
+ icon.ToImageSkia()->GetRepresentation(1.0f)));
}
diff --git a/chrome/browser/extensions/extension_icon_image.cc b/chrome/browser/extensions/extension_icon_image.cc
index fbd1ee4..7b0b248 100644
--- a/chrome/browser/extensions/extension_icon_image.cc
+++ b/chrome/browser/extensions/extension_icon_image.cc
@@ -86,8 +86,7 @@ class IconImage::Source : public gfx::ImageSkiaSource {
private:
// gfx::ImageSkiaSource overrides:
- virtual gfx::ImageSkiaRep GetImageForScale(
- ui::ScaleFactor scale_factor) OVERRIDE;
+ virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE;
// Used to load images, possibly asynchronously. NULLed out when the IconImage
// is destroyed.
@@ -112,16 +111,17 @@ void IconImage::Source::ResetHost() {
host_ = NULL;
}
-gfx::ImageSkiaRep IconImage::Source::GetImageForScale(
- ui::ScaleFactor scale_factor) {
+gfx::ImageSkiaRep IconImage::Source::GetImageForScale(float scale) {
gfx::ImageSkiaRep representation;
- if (host_)
- representation = host_->LoadImageForScaleFactor(scale_factor);
+ if (host_) {
+ representation =
+ host_->LoadImageForScaleFactor(ui::GetSupportedScaleFactor(scale));
+ }
if (!representation.is_null())
return representation;
- return blank_image_.GetRepresentation(scale_factor);
+ return blank_image_.GetRepresentation(scale);
}
////////////////////////////////////////////////////////////////////////////////
@@ -163,7 +163,7 @@ gfx::ImageSkiaRep IconImage::LoadImageForScaleFactor(
if (!extension_)
return gfx::ImageSkiaRep();
- const float scale = ui::GetScaleFactorScale(scale_factor);
+ const float scale = ui::GetImageScale(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_factor);
+ return default_icon_.GetRepresentation(scale);
std::vector<ImageLoader::ImageRepresentation> info_list;
info_list.push_back(ImageLoader::ImageRepresentation(
@@ -198,13 +198,12 @@ gfx::ImageSkiaRep IconImage::LoadImageForScaleFactor(
loader->LoadImagesAsync(extension_, info_list,
base::Bind(&IconImage::OnImageLoaded,
weak_ptr_factory_.GetWeakPtr(),
- scale_factor));
+ scale));
return gfx::ImageSkiaRep();
}
-void IconImage::OnImageLoaded(ui::ScaleFactor scale_factor,
- const gfx::Image& image_in) {
+void IconImage::OnImageLoaded(float scale, const gfx::Image& image_in) {
const gfx::ImageSkia* image =
image_in.IsEmpty() ? &default_icon_ : image_in.ToImageSkia();
@@ -212,12 +211,12 @@ void IconImage::OnImageLoaded(ui::ScaleFactor scale_factor,
if (image->isNull())
return;
- gfx::ImageSkiaRep rep = image->GetRepresentation(scale_factor);
+ gfx::ImageSkiaRep rep = image->GetRepresentation(scale);
DCHECK(!rep.is_null());
- DCHECK_EQ(scale_factor, rep.scale_factor());
+ DCHECK_EQ(scale, rep.scale());
// Remove old representation if there is one.
- image_skia_.RemoveRepresentation(rep.scale_factor());
+ image_skia_.RemoveRepresentation(scale);
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 d1ddd57..94cdae5 100644
--- a/chrome/browser/extensions/extension_icon_image.h
+++ b/chrome/browser/extensions/extension_icon_image.h
@@ -13,6 +13,7 @@
#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;
@@ -81,7 +82,7 @@ class IconImage : public content::NotificationObserver {
// observer's |OnExtensionIconImageLoaded| will be called.
gfx::ImageSkiaRep LoadImageForScaleFactor(ui::ScaleFactor scale_factor);
- void OnImageLoaded(ui::ScaleFactor scale_factor, const gfx::Image& image);
+ void OnImageLoaded(float 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 0d9b9a7..fd35ee9 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::GetScaleFactorScale(scale_factor);
+ const float scale = ui::GetImageScale(scale_factor);
bitmap.setConfig(SkBitmap::kARGB_8888_Config,
static_cast<int>(size_dip * scale),
static_cast<int>(size_dip * scale));
@@ -59,9 +59,8 @@ class MockImageSkiaSource : public gfx::ImageSkiaSource {
}
virtual ~MockImageSkiaSource() {}
- virtual gfx::ImageSkiaRep GetImageForScale(
- ui::ScaleFactor scale_factor) OVERRIDE {
- return image_.GetRepresentation(scale_factor);
+ virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ return image_.GetRepresentation(scale);
}
private:
@@ -210,6 +209,10 @@ 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));
@@ -240,8 +243,7 @@ TEST_F(ExtensionIconImageTest, Basic) {
ASSERT_EQ(0u, image_reps.size());
// Gets representation for a scale factor.
- gfx::ImageSkiaRep representation =
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
// Before the image representation is loaded, image should contain blank
// image representation.
@@ -253,14 +255,14 @@ TEST_F(ExtensionIconImageTest, Basic) {
EXPECT_EQ(1, ImageLoadedCount());
ASSERT_EQ(1u, image.image_skia().image_reps().size());
- representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ representation = image.image_skia().GetRepresentation(1.0f);
// 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(ui::SCALE_FACTOR_200P);
+ representation = image.image_skia().GetRepresentation(2.0f);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
@@ -270,7 +272,7 @@ TEST_F(ExtensionIconImageTest, Basic) {
EXPECT_EQ(1, ImageLoadedCount());
ASSERT_EQ(2u, image.image_skia().image_reps().size());
- representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
+ representation = image.image_skia().GetRepresentation(2.0f);
// Image should have been resized.
EXPECT_EQ(32, representation.pixel_width());
@@ -281,6 +283,10 @@ 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));
@@ -300,18 +306,17 @@ TEST_F(ExtensionIconImageTest, FallbackToSmallerWhenNoBigger) {
default_icon,
this);
- gfx::ImageSkiaRep representation =
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
+ gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(2.0f);
WaitForImageLoad();
EXPECT_EQ(1, ImageLoadedCount());
ASSERT_EQ(1u, image.image_skia().image_reps().size());
- representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
+ representation = image.image_skia().GetRepresentation(2.0f);
// We should have loaded the biggest smaller resource resized to the actual
// size.
- EXPECT_EQ(ui::SCALE_FACTOR_200P, representation.scale_factor());
+ EXPECT_EQ(2.0f, representation.scale());
EXPECT_EQ(64, representation.pixel_width());
EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(),
EnsureBitmapSize(bitmap_48, 64)));
@@ -340,17 +345,16 @@ TEST_F(ExtensionIconImageTest, FallbackToSmaller) {
default_icon,
this);
- gfx::ImageSkiaRep representation =
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
WaitForImageLoad();
EXPECT_EQ(1, ImageLoadedCount());
ASSERT_EQ(1u, image.image_skia().image_reps().size());
- representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ representation = image.image_skia().GetRepresentation(1.0f);
// We should have loaded smaller (resized) resource.
- EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor());
+ EXPECT_EQ(1.0f, representation.scale());
EXPECT_EQ(17, representation.pixel_width());
EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(),
EnsureBitmapSize(bitmap_16, 17)));
@@ -375,23 +379,22 @@ TEST_F(ExtensionIconImageTest, NoResources) {
default_icon,
this);
- gfx::ImageSkiaRep representation =
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
EnsureBitmapSize(
- default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(),
+ default_icon.GetRepresentation(1.0f).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(ui::SCALE_FACTOR_100P);
+ representation = image.image_skia().GetRepresentation(1.0f);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
EnsureBitmapSize(
- default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(),
+ default_icon.GetRepresentation(1.0f).sk_bitmap(),
kRequestedSize)));
}
@@ -417,8 +420,7 @@ TEST_F(ExtensionIconImageTest, InvalidResource) {
default_icon,
this);
- gfx::ImageSkiaRep representation =
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
CreateBlankBitmapForScale(kInvalidIconSize, ui::SCALE_FACTOR_100P)));
@@ -428,11 +430,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(ui::SCALE_FACTOR_100P);
+ representation = image.image_skia().GetRepresentation(1.0f);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
EnsureBitmapSize(
- default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(),
+ default_icon.GetRepresentation(1.0f).sk_bitmap(),
kInvalidIconSize)));
}
@@ -458,17 +460,16 @@ TEST_F(ExtensionIconImageTest, LazyDefaultIcon) {
lazy_default_icon,
this);
- ASSERT_FALSE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
+ ASSERT_FALSE(lazy_default_icon.HasRepresentation(1.0f));
- gfx::ImageSkiaRep representation =
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
// The resouce set is empty, so we should get the result right away.
- EXPECT_TRUE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
+ EXPECT_TRUE(lazy_default_icon.HasRepresentation(1.0f));
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
EnsureBitmapSize(
- default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(),
+ default_icon.GetRepresentation(1.0f).sk_bitmap(),
kRequestedSize)));
// We should have a default icon representation.
@@ -498,23 +499,22 @@ TEST_F(ExtensionIconImageTest, LazyDefaultIcon_AsyncIconImage) {
lazy_default_icon,
this);
- ASSERT_FALSE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
+ ASSERT_FALSE(lazy_default_icon.HasRepresentation(1.0f));
- gfx::ImageSkiaRep representation =
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
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(ui::SCALE_FACTOR_100P));
+ EXPECT_TRUE(lazy_default_icon.HasRepresentation(1.0f));
- representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ representation = image.image_skia().GetRepresentation(1.0f);
EXPECT_TRUE(gfx::BitmapsAreEqual(
representation.sk_bitmap(),
EnsureBitmapSize(
- default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(),
+ default_icon.GetRepresentation(1.0f).sk_bitmap(),
kInvalidIconSize)));
}
@@ -545,7 +545,7 @@ TEST_F(ExtensionIconImageTest, IconImageDestruction) {
// Load an image representation.
gfx::ImageSkiaRep representation =
- image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ image->image_skia().GetRepresentation(1.0f);
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(ui::SCALE_FACTOR_100P);
+ representation = image_skia.GetRepresentation(1.0f);
- EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor());
+ EXPECT_EQ(1.0f, representation.scale());
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(ui::SCALE_FACTOR_200P);
+ representation = image_skia.GetRepresentation(2.0f);
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 66f42db..475f4cb 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()),
- ui::SCALE_FACTOR_100P,
+ 1.0f,
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 309c28f..e4a08aa 100644
--- a/chrome/browser/extensions/extension_install_prompt.cc
+++ b/chrome/browser/extensions/extension_install_prompt.cc
@@ -122,9 +122,7 @@ 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) {
- float max_scale_factor_scale =
- ui::GetScaleFactorScale(ui::GetMaxScaleFactor());
- return static_cast<int>(size_in_dip * max_scale_factor_scale);
+ return static_cast<int>(size_in_dip * gfx::ImageSkia::GetMaxSupportedScale());
}
// Returns bitmap for the default icon with size equal to the default icon's
@@ -133,7 +131,8 @@ SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
const gfx::ImageSkia& image = is_app ?
extensions::IconsInfo::GetDefaultAppIcon() :
extensions::IconsInfo::GetDefaultExtensionIcon();
- return image.GetRepresentation(ui::GetMaxScaleFactor()).sk_bitmap();
+ return image.GetRepresentation(
+ gfx::ImageSkia::GetMaxSupportedScale()).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 0eb8dcf..fb6bc92 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) {
- ui::ScaleFactor max_scale_factor = ui::GetMaxScaleFactor();
- float max_scale_factor_scale = ui::GetScaleFactorScale(max_scale_factor);
+ float max_scale_factor_scale = gfx::ImageSkia::GetMaxSupportedScale();
return static_cast<int>(size_in_dip * max_scale_factor_scale);
}
@@ -39,7 +39,8 @@ SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
const gfx::ImageSkia& image = is_app ?
extensions::IconsInfo::GetDefaultAppIcon() :
extensions::IconsInfo::GetDefaultExtensionIcon();
- return image.GetRepresentation(ui::GetMaxScaleFactor()).sk_bitmap();
+ return image.GetRepresentation(
+ gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap();
}
} // namespace
diff --git a/chrome/browser/extensions/extension_web_ui.cc b/chrome/browser/extensions/extension_web_ui.cc
index 40a4deb..631ba56 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::GetScaleFactorScale(scale_factors[i]);
+ float scale = ui::GetImageScale(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 2e2702e..2c8f77c 100644
--- a/chrome/browser/extensions/image_loader.cc
+++ b/chrome/browser/extensions/image_loader.cc
@@ -334,7 +334,8 @@ void ImageLoader::ReplyBack(
const ImageRepresentation& image_rep = it->image_representation;
image_skia.AddRepresentation(gfx::ImageSkiaRep(
- bitmap, image_rep.scale_factor));
+ bitmap,
+ ui::GetImageScale(image_rep.scale_factor)));
}
gfx::Image image;
diff --git a/chrome/browser/favicon/favicon_handler.cc b/chrome/browser/favicon/favicon_handler.cc
index 8eb1897..5e1459c 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 ui::GetScaleFactorScale(ui::GetMaxScaleFactor()) * base_size;
+ return gfx::ImageSkia::GetMaxSupportedScale() * 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::GetScaleFactorScale(scale_factors[i]));
+ desired_size_in_dip * ui::GetImageScale(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 d89d45f..5671b73 100644
--- a/chrome/browser/favicon/favicon_handler_unittest.cc
+++ b/chrome/browser/favicon/favicon_handler_unittest.cc
@@ -410,7 +410,8 @@ class FaviconHandlerTest : public ChromeRenderViewHostTestHarness {
// results on all platforms.
std::vector<ui::ScaleFactor> scale_factors;
scale_factors.push_back(ui::SCALE_FACTOR_100P);
- ui::test::SetSupportedScaleFactors(scale_factors);
+ scoped_set_supported_scale_factors_.reset(
+ new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
ChromeRenderViewHostTestHarness::SetUp();
}
@@ -424,6 +425,9 @@ 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 555cdb1..fd0f9eb 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.EnsureRepsForSupportedScaleFactors();
+ image_skia.EnsureRepsForSupportedScales();
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::GetScaleFactorScale(desired_scale_factor);
+ float desired_scale = ui::GetImageScale(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 4f2db61..a34ffca 100644
--- a/chrome/browser/favicon/favicon_util.cc
+++ b/chrome/browser/favicon/favicon_util.cc
@@ -43,18 +43,17 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing(
best_candidate = png_data[i].bitmap_data;
}
}
- png_reps.push_back(gfx::ImagePNGRep(best_candidate,
- ui::SCALE_FACTOR_100P));
+ png_reps.push_back(gfx::ImagePNGRep(best_candidate, 1.0f));
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::GetScaleFactorFromScale() cannot be used.)
+ // supported by the platform. (ui::GetSupportedScaleFactor() 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::GetScaleFactorScale(scale_factors[i]));
+ ui::GetImageScale(scale_factors[i]));
desired_pixel_sizes[pixel_size] = scale_factors[i];
}
@@ -71,7 +70,9 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing(
if (it == desired_pixel_sizes.end())
continue;
- png_reps.push_back(gfx::ImagePNGRep(png_data[i].bitmap_data, it->second));
+ png_reps.push_back(
+ gfx::ImagePNGRep(png_data[i].bitmap_data,
+ ui::GetImageScale(it->second)));
}
return png_reps;
@@ -137,7 +138,7 @@ SkBitmap ResizeBitmapByDownsamplingIfPossible(
// static
std::vector<ui::ScaleFactor> FaviconUtil::GetFaviconScaleFactors() {
- const float kScale1x = ui::GetScaleFactorScale(ui::SCALE_FACTOR_100P);
+ const float kScale1x = ui::GetImageScale(ui::SCALE_FACTOR_100P);
std::vector<ui::ScaleFactor> favicon_scale_factors =
ui::GetSupportedScaleFactors();
@@ -146,7 +147,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::GetScaleFactorScale(favicon_scale_factors[i]);
+ float scale = ui::GetImageScale(favicon_scale_factors[i]);
if (scale == kScale1x) {
return favicon_scale_factors;
} else if (scale > kScale1x) {
@@ -201,7 +202,7 @@ gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs(
std::vector<ui::ScaleFactor>::iterator it = std::find(
scale_factors_to_generate.begin(),
scale_factors_to_generate.end(),
- png_reps[i].scale_factor);
+ ui::GetSupportedScaleFactor(png_reps[i].scale));
CHECK(it != scale_factors_to_generate.end());
scale_factors_to_generate.erase(it);
}
@@ -229,7 +230,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::GetScaleFactorScale(scale_factor));
+ ceil(favicon_size * ui::GetImageScale(scale_factor));
SkBitmap bitmap = ResizeBitmapByDownsamplingIfPossible(
bitmaps, desired_size_in_pixel);
resized_image_skia.AddRepresentation(
@@ -246,7 +247,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_factor()));
+ resized_image_skia_reps[i].scale()));
}
}
diff --git a/chrome/browser/history/select_favicon_frames.cc b/chrome/browser/history/select_favicon_frames.cc
index 09bf8ff..43a1fa4 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::GetScaleFactorScale(scale_factor);
+ float scale = ui::GetImageScale(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::GetScaleFactorScale(scale_factor);
+ float scale = ui::GetImageScale(scale_factor);
int desired_size_in_pixel = static_cast<int>(
desired_size_in_dip * scale + 0.5f);
@@ -216,7 +216,8 @@ 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, result.scale_factor));
+ gfx::ImageSkiaRep(resized_bitmap,
+ ui::GetImageScale(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 f79e773..6936ece 100644
--- a/chrome/browser/history/select_favicon_frames_unittest.cc
+++ b/chrome/browser/history/select_favicon_frames_unittest.cc
@@ -43,7 +43,8 @@ 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(factor).sk_bitmap();
+ const SkBitmap& bitmap =
+ image.GetRepresentation(ui::GetImageScale(factor)).sk_bitmap();
if (x == -1)
x = bitmap.width() / 2;
if (y == -1)
@@ -71,7 +72,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(ui::SCALE_FACTOR_100P));
+ ASSERT_TRUE(image.HasRepresentation(1.0f));
EXPECT_EQ(48, image.width());
EXPECT_EQ(48, image.height());
@@ -87,7 +88,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(ui::SCALE_FACTOR_100P));
+ ASSERT_TRUE(image.HasRepresentation(1.0f));
EXPECT_EQ(16, image.width());
EXPECT_EQ(16, image.height());
EXPECT_EQ(SK_ColorGREEN, GetColor1x(image));
@@ -102,7 +103,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(ui::SCALE_FACTOR_100P));
+ ASSERT_TRUE(image.HasRepresentation(1.0f));
EXPECT_EQ(16, image.width());
EXPECT_EQ(16, image.height());
EXPECT_EQ(SK_ColorGREEN, GetColor1x(image));
@@ -118,7 +119,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(ui::SCALE_FACTOR_100P));
+ ASSERT_TRUE(image.HasRepresentation(1.0f));
EXPECT_EQ(16, image.width());
EXPECT_EQ(16, image.height());
EXPECT_EQ(SK_ColorGREEN, GetColor1x(image));
@@ -131,8 +132,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(ui::SCALE_FACTOR_100P));
- ASSERT_TRUE(image.HasRepresentation(ui::SCALE_FACTOR_200P));
+ ASSERT_TRUE(image.HasRepresentation(1.0f));
+ ASSERT_TRUE(image.HasRepresentation(2.0f));
EXPECT_EQ(16, image.width());
EXPECT_EQ(16, image.height());
EXPECT_EQ(SK_ColorGREEN, GetColor1x(image));
@@ -147,8 +148,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(ui::SCALE_FACTOR_100P));
- ASSERT_TRUE(image.HasRepresentation(ui::SCALE_FACTOR_200P));
+ ASSERT_TRUE(image.HasRepresentation(1.0f));
+ ASSERT_TRUE(image.HasRepresentation(2.0f));
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 ba01fc3..1f56b3d 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), ui::SCALE_FACTOR_100P, false);
+ gfx::Canvas canvas(gfx::Size(width, height), 1.0f, 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),
- ui::SCALE_FACTOR_100P, false);
+ gfx::Canvas canvas(
+ gfx::Size(kAvatarIconWidth, kAvatarIconHeight), 1.0f, false);
// Draw the icon centered on the canvas.
int x = (kAvatarIconWidth - length) / 2;
@@ -74,8 +74,7 @@ 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), ui::SCALE_FACTOR_100P,
- false);
+ gfx::Canvas canvas(gfx::Size(dst_width, dst_height), 1.0f, false);
// Draw the icon on the bottom center of the canvas.
int x1 = (dst_width - length) / 2;
diff --git a/chrome/browser/speech/speech_recognition_bubble.cc b/chrome/browser/speech/speech_recognition_bubble.cc
index e93c4ec..2b28dd9 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.EnsureRepsForSupportedScaleFactors();
+ frame.EnsureRepsForSupportedScales();
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_factor()));
+ copy_dst, image_reps[i].scale()));
}
spinner_.push_back(frame_copy);
@@ -140,16 +140,15 @@ SpeechRecognitionBubbleBase::SpeechRecognitionBubbleBase(
animation_step_(0),
display_mode_(DISPLAY_MODE_RECORDING),
web_contents_(web_contents),
- scale_factor_(ui::SCALE_FACTOR_NONE) {
+ scale_(1.0f) {
gfx::NativeView view =
web_contents_ ? web_contents_->GetView()->GetNativeView() : NULL;
gfx::Screen* screen = gfx::Screen::GetScreenFor(view);
gfx::Display display = screen->GetDisplayNearestWindow(view);
- scale_factor_ = ui::GetScaleFactorFromScale(
- display.device_scale_factor());
+ scale_ = display.device_scale_factor();
const gfx::ImageSkiaRep& rep =
- g_images.Get().mic_empty()->GetRepresentation(scale_factor_);
+ g_images.Get().mic_empty()->GetRepresentation(scale_);
mic_image_.reset(new SkBitmap());
mic_image_->setConfig(SkBitmap::kARGB_8888_Config,
rep.pixel_width(), rep.pixel_height());
@@ -235,13 +234,12 @@ 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_factor_).sk_bitmap(), 0, 0);
+ buffer_canvas.drawBitmap(image.GetRepresentation(scale_).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_factor_).sk_bitmap(),
+ g_images.Get().mic_mask()->GetRepresentation(scale_).sk_bitmap(),
-clip_right, 0, &multiply_paint);
canvas->drawBitmap(*buffer_image_.get(), 0, 0);
@@ -255,12 +253,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_factor_).sk_bitmap(),
+ g_images.Get().mic_empty()->GetRepresentation(scale_).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_factor_));
+ gfx::ImageSkia image(gfx::ImageSkiaRep(*mic_image_.get(), scale_));
SetImage(image);
}
diff --git a/chrome/browser/speech/speech_recognition_bubble.h b/chrome/browser/speech/speech_recognition_bubble.h
index 2bb911f..08a741e 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.
- ui::ScaleFactor scale_factor_;
+ float scale_;
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 a59c28c..6340788 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(
- ui::SCALE_FACTOR_100P).sk_bitmap();
+ 1.0f).sk_bitmap();
SkBitmap bitmap_b = image_b.AsImageSkia().GetRepresentation(
- ui::SCALE_FACTOR_100P).sk_bitmap();
+ 1.0f).sk_bitmap();
return FaviconBitmapsMatch(bitmap_a, bitmap_b);
}
@@ -714,14 +714,16 @@ gfx::Image CreateFavicon(SkColor color) {
FaviconUtil::GetFaviconScaleFactors();
gfx::ImageSkia favicon;
for (size_t i = 0; i < favicon_scale_factors.size(); ++i) {
- float scale = ui::GetScaleFactorScale(favicon_scale_factors[i]);
+ float scale = ui::GetImageScale(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, favicon_scale_factors[i]));
+ favicon.AddRepresentation(
+ gfx::ImageSkiaRep(bmp,
+ ui::GetImageScale(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 83ca050..771b1a6 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::test::SetSupportedScaleFactors(supported_scale_factors);
+ ui::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 171f0f5..367f209 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::test::SetSupportedScaleFactors(supported_scale_factors);
+ ui::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 21cec0b..6d898b7 100644
--- a/chrome/browser/task_manager/browser_process_resource_provider.cc
+++ b/chrome/browser/task_manager/browser_process_resource_provider.cc
@@ -40,8 +40,7 @@ BrowserProcessResource::BrowserProcessResource()
HICON icon = GetAppIcon();
if (icon) {
scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon));
- default_icon_ = new gfx::ImageSkia(
- gfx::ImageSkiaRep(*bitmap, ui::SCALE_FACTOR_100P));
+ default_icon_ = new gfx::ImageSkia(gfx::ImageSkiaRep(*bitmap, 1.0f));
}
}
#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 988450e..6f163af 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::GetScaleFactorScale(expected[index]))
+ if (scales[index] != ui::GetImageScale(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::GetScaleFactorScale(scale_factors[i]);
+ scales[i] = ui::GetImageScale(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::GetScaleFactorScale(desired_scale_factor) /
- ui::GetScaleFactorScale(source_scale_factor)));
+ ui::GetImageScale(desired_scale_factor) /
+ ui::GetImageScale(source_scale_factor)));
SkBitmap scaled_bitmap;
scaled_bitmap.setConfig(SkBitmap::kARGB_8888_Config,
scaled_size.width(),
@@ -477,17 +477,15 @@ class ThemeImageSource: public gfx::ImageSkiaSource {
}
virtual ~ThemeImageSource() {}
- 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);
+ virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ if (source_.HasRepresentation(scale))
+ return source_.GetRepresentation(scale);
+ const gfx::ImageSkiaRep& rep_100p = source_.GetRepresentation(1.0f);
SkBitmap scaled_bitmap = CreateLowQualityResizedBitmap(
rep_100p.sk_bitmap(),
ui::SCALE_FACTOR_100P,
- scale_factor);
- return gfx::ImageSkiaRep(scaled_bitmap, scale_factor);
+ ui::GetSupportedScaleFactor(scale));
+ return gfx::ImageSkiaRep(scaled_bitmap, scale);
}
private:
@@ -509,13 +507,13 @@ class ThemeImagePngSource : public gfx::ImageSkiaSource {
virtual ~ThemeImagePngSource() {}
private:
- virtual gfx::ImageSkiaRep GetImageForScale(
- ui::ScaleFactor scale_factor) OVERRIDE {
+ virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale);
// 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_factor);
+ return gfx::ImageSkiaRep(exact_bitmap_it->second, scale);
// 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.
@@ -529,7 +527,7 @@ class ThemeImagePngSource : public gfx::ImageSkiaSource {
return gfx::ImageSkiaRep();
}
bitmap_map_[scale_factor] = bitmap;
- return gfx::ImageSkiaRep(bitmap, scale_factor);
+ return gfx::ImageSkiaRep(bitmap, scale);
}
// Find an available PNG for another scale factor. We want to use the
@@ -538,8 +536,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::GetScaleFactorScale(png_it->first) >
- ui::GetScaleFactorScale(available_png_it->first)) {
+ ui::GetImageScale(png_it->first) >
+ ui::GetImageScale(available_png_it->first)) {
available_png_it = png_it;
}
}
@@ -571,7 +569,7 @@ class ThemeImagePngSource : public gfx::ImageSkiaSource {
available_scale_factor,
scale_factor);
bitmap_map_[scale_factor] = scaled_bitmap;
- return gfx::ImageSkiaRep(scaled_bitmap, scale_factor);
+ return gfx::ImageSkiaRep(scaled_bitmap, scale);
}
PngMap png_map_;
@@ -1285,7 +1283,8 @@ bool BrowserThemePack::LoadRawBitmapsTo(
if (gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(),
&bitmap)) {
image_skia.AddRepresentation(
- gfx::ImageSkiaRep(bitmap, scale_factor));
+ gfx::ImageSkiaRep(bitmap,
+ ui::GetImageScale(scale_factor)));
} else {
NOTREACHED() << "Unable to decode theme image resource "
<< it->first;
@@ -1473,7 +1472,9 @@ void BrowserThemePack::RepackImages(const ImageCache& images,
NOTREACHED() << "Image file for resource " << it->first
<< " could not be encoded.";
}
- int raw_id = GetRawIDByPersistentID(it->first, rep_it->scale_factor());
+ int raw_id = GetRawIDByPersistentID(
+ it->first,
+ ui::GetSupportedScaleFactor(rep_it->scale()));
(*reencoded_images)[raw_id] =
base::RefCountedBytes::TakeVector(&bitmap_data);
}
@@ -1533,7 +1534,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::GetScaleFactorScale(scale_factors_[i]) - scale) < 0.001) {
+ if (fabs(ui::GetImageScale(scale_factors_[i]) - scale) < 0.001) {
*scale_factor = scale_factors_[i];
return true;
}
@@ -1570,8 +1571,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::GetScaleFactorScale(scale_factors_[i]) >
- ui::GetScaleFactorScale(available_scale_factor))) &&
+ (ui::GetImageScale(scale_factors_[i]) >
+ ui::GetImageScale(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 b2fd658..7d41e55 100644
--- a/chrome/browser/themes/browser_theme_pack_unittest.cc
+++ b/chrome/browser/themes/browser_theme_pack_unittest.cc
@@ -36,8 +36,13 @@ class BrowserThemePackTest : public ::testing::Test {
BrowserThemePackTest()
: message_loop(),
fake_ui_thread(BrowserThread::UI, &message_loop),
- fake_file_thread(BrowserThread::FILE, &message_loop),
- theme_pack_(new BrowserThemePack) {
+ 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();
}
// Transformation for link underline colors.
@@ -270,8 +275,7 @@ 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(
- ui::SCALE_FACTOR_100P);
+ const gfx::ImageSkiaRep& rep1 = image_skia->GetRepresentation(1.0f);
ASSERT_FALSE(rep1.is_null());
EXPECT_EQ(80, rep1.sk_bitmap().width());
EXPECT_EQ(80, rep1.sk_bitmap().height());
@@ -283,8 +287,7 @@ 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(
- ui::SCALE_FACTOR_200P);
+ const gfx::ImageSkiaRep& rep2 = image_skia->GetRepresentation(2.0f);
ASSERT_FALSE(rep2.is_null());
EXPECT_EQ(160, rep2.sk_bitmap().width());
EXPECT_EQ(160, rep2.sk_bitmap().height());
@@ -312,8 +315,7 @@ class BrowserThemePackTest : public ::testing::Test {
image_skia = image.ToImageSkia();
ASSERT_TRUE(image_skia);
// Scale 100%.
- const gfx::ImageSkiaRep& rep3 = image_skia->GetRepresentation(
- ui::SCALE_FACTOR_100P);
+ const gfx::ImageSkiaRep& rep3 = image_skia->GetRepresentation(1.0f);
ASSERT_FALSE(rep3.is_null());
EXPECT_EQ(80, rep3.sk_bitmap().width());
EXPECT_EQ(80, rep3.sk_bitmap().height());
@@ -335,8 +337,7 @@ 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(
- ui::SCALE_FACTOR_200P);
+ const gfx::ImageSkiaRep& rep4 = image_skia->GetRepresentation(2.0f);
ASSERT_FALSE(rep4.is_null());
EXPECT_EQ(160, rep4.sk_bitmap().width());
EXPECT_EQ(160, rep4.sk_bitmap().height());
@@ -355,6 +356,9 @@ 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_;
};
@@ -584,10 +588,6 @@ 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 dc8f2c8..a45708d 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, 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, ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(image_size, 1.0f, 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, ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(image_size, 1.0f, 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 07e033f..1e8eae7 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, ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(image_size, 1.0f, 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 da2606c..f9e2263 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::GetScaleFactorScale(ui::GetScaleFactorForNativeView(
+ float scale_factor = ui::GetImageScale(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/render_widget_snapshot_taker_unittest.cc b/chrome/browser/thumbnails/render_widget_snapshot_taker_unittest.cc
index 5a33ed1..d44a69b 100644
--- a/chrome/browser/thumbnails/render_widget_snapshot_taker_unittest.cc
+++ b/chrome/browser/thumbnails/render_widget_snapshot_taker_unittest.cc
@@ -75,7 +75,8 @@ TEST_F(RenderWidgetSnapshotTakerTest,
size);
EXPECT_EQ(1U, snapshot_taker.callback_map_.size());
const int sequence_num = 1;
- const gfx::Size size2(200, 200);
+ // Ensure this is bigger than the max scale factor X the size.
+ const gfx::Size size2(300, 300);
snapshot_taker.WidgetDidReceivePaintAtSizeAck(
content::RenderViewHostTestHarness::rvh(),
sequence_num,
diff --git a/chrome/browser/thumbnails/simple_thumbnail_crop.cc b/chrome/browser/thumbnails/simple_thumbnail_crop.cc
index c427b90..b2128ef 100644
--- a/chrome/browser/thumbnails/simple_thumbnail_crop.cc
+++ b/chrome/browser/thumbnails/simple_thumbnail_crop.cc
@@ -8,6 +8,7 @@
#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"
@@ -121,7 +122,7 @@ gfx::Size SimpleThumbnailCrop::GetCopySizeForThumbnail(
switch (scale_factor) {
case ui::SCALE_FACTOR_100P:
copy_size = gfx::ToFlooredSize(gfx::ScaleSize(
- copy_size, ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P)));
+ copy_size, ui::GetImageScale(ui::SCALE_FACTOR_200P)));
break;
case ui::SCALE_FACTOR_200P:
// Use the size as-is.
@@ -130,7 +131,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, ui::GetMaxScaleFactor()));
+ copy_size, gfx::ImageSkia::GetMaxSupportedScale()));
break;
}
return copy_size;
@@ -183,8 +184,7 @@ 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 =
- ui::GetScaleFactorScale(ui::GetMaxScaleFactor());
+ float max_scale_factor = gfx::ImageSkia::GetMaxSupportedScale();
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 b0324a4..c00abb2 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, ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(kSize, 1.0f, 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, ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(kSize, 1.0f, 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(40, 90), 1.0f, 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(70, 40), 1.0f, 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(90, 40), 1.0f, 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(40, 40), 1.0f, 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(40, 40), 1.0f, true);
SkBitmap bitmap =
skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
diff --git a/chrome/browser/ui/app_list/fast_show_pickler.cc b/chrome/browser/ui/app_list/fast_show_pickler.cc
index 2ef48ef..d282aab 100644
--- a/chrome/browser/ui/app_list/fast_show_pickler.cc
+++ b/chrome/browser/ui/app_list/fast_show_pickler.cc
@@ -88,7 +88,7 @@ bool PickleImage(Pickle* pickle, const gfx::ImageSkia& image) {
pickle->WriteInt(static_cast<int>(reps.size()));
for (std::vector<gfx::ImageSkiaRep>::const_iterator it = reps.begin();
it != reps.end(); ++it) {
- pickle->WriteInt(static_cast<int>(it->scale_factor()));
+ pickle->WriteInt(static_cast<int>(ui::GetSupportedScaleFactor(it->scale())));
pickle->WriteInt(it->pixel_width());
pickle->WriteInt(it->pixel_height());
ImageFormat format = NONE;
@@ -147,8 +147,8 @@ bool UnpickleImage(PickleIterator* it, gfx::ImageSkia* out) {
SkAutoLockPixels lock(bitmap);
memcpy(bitmap.getPixels(), pixels, bitmap.getSize());
}
- result.AddRepresentation(
- gfx::ImageSkiaRep(bitmap, static_cast<ui::ScaleFactor>(scale_factor)));
+ float scale = ui::GetImageScale(static_cast<ui::ScaleFactor>(scale_factor));
+ result.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
}
*out = result;
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 443da12..acb2d28 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,17 +47,15 @@ void UrlIconSource::StartIconFetch() {
icon_fetcher_->Start();
}
-gfx::ImageSkiaRep UrlIconSource::GetImageForScale(
- ui::ScaleFactor scale_factor) {
+gfx::ImageSkiaRep UrlIconSource::GetImageForScale(float scale) {
if (!icon_fetch_attempted_)
StartIconFetch();
if (!icon_.isNull())
- return icon_.GetRepresentation(scale_factor);
+ return icon_.GetRepresentation(scale);
return ui::ResourceBundle::GetSharedInstance()
- .GetImageSkiaNamed(default_icon_resource_id_)->GetRepresentation(
- scale_factor);
+ .GetImageSkiaNamed(default_icon_resource_id_)->GetRepresentation(scale);
}
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 de94f28..32465e8 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,8 +45,7 @@ class UrlIconSource : public gfx::ImageSkiaSource,
void StartIconFetch();
// gfx::ImageSkiaSource overrides:
- virtual gfx::ImageSkiaRep GetImageForScale(
- ui::ScaleFactor scale_factor) OVERRIDE;
+ virtual gfx::ImageSkiaRep GetImageForScale(float scale) 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 e4394c0..01e54cf 100644
--- a/chrome/browser/ui/app_list/search/people/people_result.cc
+++ b/chrome/browser/ui/app_list/search/people/people_result.cc
@@ -95,7 +95,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_factor());
+ image_.RemoveRepresentation(image_reps[i].scale());
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 27310c2..56c4a2d 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_factor());
+ icon_.RemoveRepresentation(image_reps[i].scale());
icon_ = gfx::ImageSkia(new BadgedIconSource(icon_),
gfx::Size(kIconSize, kIconSize));
diff --git a/chrome/browser/ui/app_list/test/fast_show_pickler_unittest.cc b/chrome/browser/ui/app_list/test/fast_show_pickler_unittest.cc
index 56a8f48..6f2d8da 100644
--- a/chrome/browser/ui/app_list/test/fast_show_pickler_unittest.cc
+++ b/chrome/browser/ui/app_list/test/fast_show_pickler_unittest.cc
@@ -39,7 +39,7 @@ class AppListModelPicklerUnitTest : public testing::Test {
for (size_t i = 0; i < reps1.size(); ++i) {
ASSERT_TRUE(
gfx::BitmapsAreEqual(reps1[i].sk_bitmap(), reps2[i].sk_bitmap()));
- ASSERT_EQ(reps1[i].scale_factor(), reps2[i].scale_factor());
+ ASSERT_EQ(reps1[i].scale(), reps2[i].scale());
}
}
diff --git a/chrome/browser/ui/ash/launcher/launcher_item_controller.h b/chrome/browser/ui/ash/launcher/launcher_item_controller.h
index 1ab1f66..e035aa5 100644
--- a/chrome/browser/ui/ash/launcher/launcher_item_controller.h
+++ b/chrome/browser/ui/ash/launcher/launcher_item_controller.h
@@ -10,6 +10,7 @@
#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 6872a86..34193e7 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -472,7 +472,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, ui::SCALE_FACTOR_100P, false);
+ gfx::Canvas canvas(size, 1.0f, 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 2df80ef..b27a21a 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), ui::SCALE_FACTOR_100P, false));
+ image_size), 1.0f, 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 90ba6e0..a4601eb 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, ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(stack_window_size, 1.0f, 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 95f2e54..1a15f6f 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 = GetScaleFactorScale(scale_factor);
+ float scale = GetImageScale(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 b708d03..f5b8bc1 100644
--- a/chrome/browser/ui/gtk/avatar_menu_item_gtk.cc
+++ b/chrome/browser/ui/gtk/avatar_menu_item_gtk.cc
@@ -201,8 +201,7 @@ 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, ui::SCALE_FACTOR_100P);
+ gfx::ImageSkiaRep avatar_image_rep = gfx::ImageSkiaRep(*avatar_image, 1.0f);
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 97e0ec5..a4d3562 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),
- ui::SCALE_FACTOR_100P, true);
+ 1.0f, 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 c12d975c..0575aea 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), ui::SCALE_FACTOR_100P, false));
+ image_size), 1.0f, 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 54b0c3b..c45b6ea 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(1, 1), 1.0f, 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 5c66d9d..4a6ce2d 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),
- ui::SCALE_FACTOR_100P, true);
+ 1.0f, 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 064bccf..58255d7 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), ui::SCALE_FACTOR_100P,
+ gfx::Canvas canvas(gfx::Size(kLogoWidth, kLogoHeight), 1.0f,
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(
- ui::SCALE_FACTOR_100P).sk_bitmap();
+ 1.0f).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 43b30f9..f513aaa 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(), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(rect.size(), 1.0f, 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 eece8aa..235bbef 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->scale_factor(),
+ canvas->image_scale(),
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 58d24c7..e216446 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 /
- ui::GetScaleFactorScale(canvas->scale_factor());
+ canvas->image_scale();
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 2916c5f..5962fb0 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), ui::SCALE_FACTOR_100P);
+ gfx::ImageSkiaRep rep(gfx::Size(40, 29), 1.0f);
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, ui::SCALE_FACTOR_100P);
+ gfx::ImageSkiaRep rep(size, 1.0f);
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 9e38e7a..6734411 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,8 +65,7 @@ ContentSettingImageView::ContentSettingImageView(
// sit atop.
const SkBitmap& bitmap(
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- kBackgroundImages[4])->GetRepresentation(
- ui::SCALE_FACTOR_100P).sk_bitmap());
+ kBackgroundImages[4])->GetRepresentation(1.0f).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 6a49136..f279f24 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,8 +54,7 @@ IconLabelBubbleView::IconLabelBubbleView(const int background_images[],
// sit atop.
const SkBitmap& bitmap(
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- background_images[4])->GetRepresentation(
- ui::SCALE_FACTOR_100P).sk_bitmap());
+ background_images[4])->GetRepresentation(1.0f).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 43bf0c7..e2c98ce 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()),
- ui::SCALE_FACTOR_100P, false);
+ 1.0f, 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 5359e72..7b9ed29 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(1, 1), 1.0f, 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 e6946bb..29c2a5f 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), ui::SCALE_FACTOR_100P, false);
+ gfx::Canvas canvas(gfx::Size(width, height), 1.0f, 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 433e36f..ab13cd6 100644
--- a/chrome/browser/ui/views/tab_icon_view.cc
+++ b/chrome/browser/ui/views/tab_icon_view.cc
@@ -39,8 +39,7 @@ 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, ui::SCALE_FACTOR_100P));
+ g_default_favicon = new gfx::ImageSkia(gfx::ImageSkiaRep(*bitmap, 1.0f));
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 bb3b8a6..d7b8cf8 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, ui::SCALE_FACTOR_100P, false);
+ gfx::Canvas scale_canvas(ps, 1.0f, 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 2492f4e..23590ae 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->scale_factor(), false);
+ gfx::Canvas background_canvas(size(), canvas->image_scale(), false);
PaintInactiveTabBackground(&background_canvas);
gfx::ImageSkia background_image(background_canvas.ExtractImageRep());
// Draw a radial gradient to hover_canvas.
- gfx::Canvas hover_canvas(size(), canvas->scale_factor(), false);
+ gfx::Canvas hover_canvas(size(), canvas->image_scale(), false);
int radius = kMiniTitleChangeGradientRadius;
int x0 = width() + radius - kMiniTitleChangeInitialXOffset;
int x1 = radius;
@@ -1271,13 +1271,14 @@ void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas) {
!hover_controller_.ShouldDraw();
if (can_cache) {
- gfx::ImageSkia cached_image(
- GetCachedImage(tab_id, size(), canvas->scale_factor()));
+ ui::ScaleFactor scale_factor =
+ ui::GetSupportedScaleFactor(canvas->image_scale());
+ gfx::ImageSkia cached_image(GetCachedImage(tab_id, size(), scale_factor));
if (cached_image.width() == 0) {
- gfx::Canvas tmp_canvas(size(), canvas->scale_factor(), false);
+ gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false);
PaintInactiveTabBackgroundUsingResourceId(&tmp_canvas, tab_id);
cached_image = gfx::ImageSkia(tmp_canvas.ExtractImageRep());
- SetCachedImage(tab_id, canvas->scale_factor(), cached_image);
+ SetCachedImage(tab_id, scale_factor, cached_image);
}
canvas->DrawImageInt(cached_image, 0, 0);
} else {
@@ -1310,7 +1311,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->scale_factor(), false);
+ gfx::Canvas background_canvas(size(), canvas->image_scale(), 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 f59e661..5e40997 100644
--- a/chrome/browser/ui/views/tabs/tab_strip.cc
+++ b/chrome/browser/ui/views/tabs/tab_strip.cc
@@ -394,7 +394,8 @@ void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) {
#endif
void NewTabButton::OnPaint(gfx::Canvas* canvas) {
- gfx::ImageSkia image = GetImageForScale(canvas->scale_factor());
+ gfx::ImageSkia image =
+ GetImageForScale(ui::GetSupportedScaleFactor(canvas->image_scale()));
canvas->DrawImageInt(image, 0, height() - image.height());
}
@@ -444,12 +445,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_factor))
+ if (!mask->HasRepresentation(scale))
scale_factor = ui::SCALE_FACTOR_100P;
- gfx::Canvas canvas(gfx::Size(width, height), scale_factor, false);
+ gfx::Canvas canvas(gfx::Size(width, height), scale, 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,7 +496,9 @@ gfx::ImageSkia NewTabButton::GetImageForState(
gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id);
gfx::Canvas canvas(
- gfx::Size(overlay->width(), overlay->height()), scale_factor, false);
+ gfx::Size(overlay->width(), overlay->height()),
+ ui::GetImageScale(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 4834b3f..2e7b6c4 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::EnsureRepsForSupportedScaleFactors here.
+ // NOTE: We do not call ImageSkia::EnsureRepsForSupportedScales 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 e7257aa..4003e73 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::GetScaleFactorScale(scale_factors[i]);
+ float scale = ui::GetImageScale(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 57af9b5..b220e31 100644
--- a/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc
+++ b/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc
@@ -90,7 +90,8 @@ base::ListValue* NetworkMenuWebUI::ConvertMenuModel(ui::MenuModel* model) {
gfx::Image icon;
if (model->GetIconAt(i, &icon)) {
SkBitmap icon_bitmap = icon.ToImageSkia()->GetRepresentation(
- web_ui_->GetDeviceScaleFactor()).sk_bitmap();
+ ui::GetImageScale(
+ web_ui_->GetDeviceScaleFactor())).sk_bitmap();
item->SetString("icon", webui::GetBitmapDataUrl(icon_bitmap));
}
if (id >= 0) {
@@ -192,7 +193,7 @@ void NetworkDropdown::SetNetworkIconAndText() {
RemoveObserver(this);
}
SkBitmap icon_bitmap = icon_image.GetRepresentation(
- web_ui_->GetDeviceScaleFactor()).sk_bitmap();
+ ui::GetImageScale(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 ee0cb11..1705c41 100644
--- a/chrome/browser/ui/webui/fileicon_source.cc
+++ b/chrome/browser/ui/webui/fileicon_source.cc
@@ -103,7 +103,8 @@ void FileIconSource::FetchFileIcon(
if (icon) {
scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes);
gfx::PNGCodec::EncodeBGRASkBitmap(
- icon->ToImageSkia()->GetRepresentation(scale_factor).sk_bitmap(),
+ icon->ToImageSkia()->GetRepresentation(
+ ui::GetImageScale(scale_factor)).sk_bitmap(),
false, &icon_data->data());
callback.Run(icon_data.get());
@@ -150,8 +151,8 @@ void FileIconSource::OnFileIconDataAvailable(const IconRequestDetails& details,
if (icon) {
scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes);
gfx::PNGCodec::EncodeBGRASkBitmap(
- icon->ToImageSkia()->GetRepresentation(details.scale_factor)
- .sk_bitmap(),
+ icon->ToImageSkia()->GetRepresentation(
+ ui::GetImageScale(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 db212ec..dbe8373 100644
--- a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc
+++ b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc
@@ -58,8 +58,7 @@ 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), ui::SCALE_FACTOR_100P,
- false);
+ gfx::Canvas canvas(gfx::Size(kLength, kLength), 1.0f, 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 bc82a94..218d24a 100644
--- a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
@@ -416,7 +416,8 @@ void SetCommonNetworkInfo(const ManagedState* state,
const gfx::ImageSkia& icon,
ui::ScaleFactor icon_scale_factor,
base::DictionaryValue* network_info) {
- gfx::ImageSkiaRep image_rep = icon.GetRepresentation(icon_scale_factor);
+ gfx::ImageSkiaRep image_rep =
+ icon.GetRepresentation(ui::GetImageScale(icon_scale_factor));
std::string icon_url =
icon.isNull() ? "" : webui::GetBitmapDataUrl(image_rep.sk_bitmap());
network_info->SetString(kNetworkInfoKeyIconURL, icon_url);
@@ -1217,7 +1218,7 @@ std::string InternetOptionsHandler::GetIconDataUrl(int resource_id) const {
gfx::ImageSkia* icon =
ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
gfx::ImageSkiaRep image_rep = icon->GetRepresentation(
- web_ui()->GetDeviceScaleFactor());
+ ui::GetImageScale(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 ccbaca1..a762a6f 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()), ui::SCALE_FACTOR_100P, false));
+ gfx::Size(badge_width, icon.height()), 1.0f, 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 1665030..007292c 100644
--- a/chrome/common/icon_with_badge_image_source.cc
+++ b/chrome/common/icon_with_badge_image_source.cc
@@ -5,6 +5,7 @@
#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 9b78c93..e187c52 100644
--- a/chrome/renderer/pepper/pepper_pdf_host.cc
+++ b/chrome/renderer/pepper/pepper_pdf_host.cc
@@ -296,18 +296,15 @@ 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_factor);
+ gfx::ImageSkiaRep image_skia_rep = res_image_skia->GetRepresentation(scale);
- if (image_skia_rep.is_null() || image_skia_rep.scale_factor() != scale_factor)
+ if (image_skia_rep.is_null() || image_skia_rep.scale() != scale)
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 7937810..f8d6d9b 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, ui::SCALE_FACTOR_100P, true));
+ contents_.reset(new gfx::Canvas(viewport_size, 1.0f, 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 5f976c4..105bf44 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::GetScaleFactorScale(GetScaleFactorForView(widget->GetView()));
+ ui::GetImageScale(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_,
- ui::GetScaleFactorFromScale(device_scale_factor_)));
+ 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 8ef2d6c..f855abf 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::GetScaleFactorScale(GetScaleFactorForView(view));
+ return ui::GetImageScale(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 68204fb..772d0df 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);
}
- ui::ScaleFactor scale_factor = GetScaleFactorForView(GetView());
- gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, scale_factor));
+ float scale = ui::GetImageScale(GetScaleFactorForView(GetView()));
+ gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, scale));
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 21c368a..eced781 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(4, 4), 1.0f, 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 3b94566..5ebd7d4 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.cc
+++ b/content/browser/renderer_host/render_widget_host_view_android.cc
@@ -571,7 +571,7 @@ void RenderWidgetHostViewAndroid::CopyFromCompositingSurface(
float device_scale_factor = display.device_scale_factor();
DCHECK_EQ(device_scale_factor,
- ui::GetScaleFactorScale(GetScaleFactorForView(this)));
+ ui::GetImageScale(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 0fe376e..0db748f 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::GetScaleFactorScale( \
+ if (ui::GetImageScale( \
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 6096798..e908cbe 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::GetScaleFactorScale(ui::GetScaleFactorForNativeView(view));
+ return ui::GetImageScale(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 82d0048..3d5fd98 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(), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(dirty_area.size(), 1.0f, 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 caf79cf..d89f353 100644
--- a/content/browser/renderer_host/test_render_view_host.cc
+++ b/content/browser/renderer_host/test_render_view_host.cc
@@ -4,6 +4,7 @@
#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"
@@ -394,6 +395,10 @@ 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 1eb7583..5abed25 100644
--- a/content/browser/renderer_host/test_render_view_host.h
+++ b/content/browser/renderer_host/test_render_view_host.h
@@ -15,6 +15,7 @@
#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
@@ -370,6 +371,9 @@ 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 f3822f8..eba64fe 100644
--- a/content/browser/web_contents/web_contents_view_aura.cc
+++ b/content/browser/web_contents/web_contents_view_aura.cc
@@ -123,7 +123,8 @@ class OverscrollWindowDelegate : public ImageWindowDelegate {
if (entry && entry->screenshot().get()) {
std::vector<gfx::ImagePNGRep> image_reps;
image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(),
- ui::GetScaleFactorForNativeView(web_contents_window())));
+ ui::GetImageScale(
+ ui::GetScaleFactorForNativeView(web_contents_window()))));
image = gfx::Image(image_reps);
}
SetImage(image);
@@ -515,7 +516,8 @@ class OverscrollNavigationOverlay :
if (entry && entry->screenshot().get()) {
std::vector<gfx::ImagePNGRep> image_reps;
image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(),
- ui::GetScaleFactorForNativeView(window_.get())));
+ ui::GetImageScale(
+ 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 f8b2cff..64b063c 100644
--- a/content/renderer/pepper/pepper_plugin_instance_impl.cc
+++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc
@@ -2672,11 +2672,9 @@ base::FilePath PepperPluginInstanceImpl::GetModulePath() {
PP_Resource PepperPluginInstanceImpl::CreateImage(gfx::ImageSkia* source_image,
float scale) {
- ui::ScaleFactor scale_factor = ui::GetScaleFactorFromScale(scale);
- gfx::ImageSkiaRep image_skia_rep = source_image->GetRepresentation(
- scale_factor);
+ gfx::ImageSkiaRep image_skia_rep = source_image->GetRepresentation(scale);
- if (image_skia_rep.is_null() || image_skia_rep.scale_factor() != scale_factor)
+ if (image_skia_rep.is_null() || image_skia_rep.scale() != scale)
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 2717f51..083b89d 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(), ui::SCALE_FACTOR_100P, false /* is_opaque */);
+ gfx::Canvas canvas(size(), 1.0f, 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 7dc19ff..f2fc46b 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,
- ui::ScaleFactor scale_factor)
+ float scale)
: owner_(owner),
item_(item) {
item_->AddObserver(this);
// Triggers icon loading for given |scale_factor|.
- item_->icon().GetRepresentation(scale_factor);
+ item_->icon().GetRepresentation(scale);
}
virtual ~IconLoader() {
@@ -147,6 +147,7 @@ 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());
@@ -160,10 +161,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_factor))
+ if (item->icon().HasRepresentation(scale))
continue;
- pending_icon_loaders_.push_back(new IconLoader(this, item, scale_factor));
+ pending_icon_loaders_.push_back(new IconLoader(this, item, scale));
}
}
diff --git a/ui/app_list/views/cached_label.cc b/ui/app_list/views/cached_label.cc
index 5488431..a7d9e27 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(), ui::SCALE_FACTOR_100P, false /* is_opaque */);
+ gfx::Canvas canvas(size(), 1.0f, 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 86f4a3c..afcb304 100644
--- a/ui/base/clipboard/clipboard_gtk.cc
+++ b/ui/base/clipboard/clipboard_gtk.cc
@@ -541,8 +541,7 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
gfx::Canvas canvas(gfx::Size(gdk_pixbuf_get_width(pixbuf.get()),
gdk_pixbuf_get_height(pixbuf.get())),
- ui::SCALE_FACTOR_100P,
- false);
+ 1.0f, 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 85bd16d..82ee1d0 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), ui::SCALE_FACTOR_100P, false);
+ gfx::Canvas canvas(gfx::Size(width, height), 1.0f, 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 6548448..fec5a90 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),
- ui::SCALE_FACTOR_100P,
+ 1.0f,
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 aa84173..8cfcce6 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(
- GetScaleFactorFromScale(display().device_scale_factor()));
+ 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(
- GetScaleFactorFromScale(display().device_scale_factor()));
+ 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 bb5947a..cdf4ab3 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().max_scale_factor() ==
+ ResourceBundle::GetSharedInstance().GetMaxScaleFactor() ==
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 40a0a9c..61517f3 100644
--- a/ui/base/layout.cc
+++ b/ui/base/layout.cc
@@ -15,30 +15,24 @@
#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 GetScaleFactorScale(lhs) < GetScaleFactorScale(rhs);
+ return GetImageScale(lhs) < GetImageScale(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() {
@@ -72,73 +66,6 @@ COMPILE_ASSERT(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales),
kScaleFactorScales_incorrect_size);
const size_t kScaleFactorScalesLength = arraysize(kScaleFactorScales);
-namespace {
-
-// 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;
-}
-
-} // namespace
-
-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
-
-#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);
- }
- return *supported_scale_factors;
-}
-
} // namespace
DisplayLayout GetDisplayLayout() {
@@ -149,13 +76,37 @@ DisplayLayout GetDisplayLayout() {
return LAYOUT_DESKTOP;
}
-ScaleFactor GetScaleFactorFromScale(float scale) {
+void SetSupportedScaleFactors(
+ const std::vector<ui::ScaleFactor>& scale_factors) {
+ if (g_supported_scale_factors != NULL)
+ delete g_supported_scale_factors;
+
+ g_supported_scale_factors = new std::vector<ScaleFactor>(scale_factors);
+ std::sort(g_supported_scale_factors->begin(),
+ g_supported_scale_factors->end(),
+ ScaleFactorComparator);
+
+ // 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));
+ }
+ gfx::ImageSkia::SetSupportedScales(scales);
+}
+
+const std::vector<ScaleFactor>& GetSupportedScaleFactors() {
+ DCHECK(g_supported_scale_factors != NULL);
+ return *g_supported_scale_factors;
+}
+
+ScaleFactor GetSupportedScaleFactor(float scale) {
+ DCHECK(g_supported_scale_factors != NULL);
ScaleFactor closest_match = SCALE_FACTOR_100P;
float smallest_diff = std::numeric_limits<float>::max();
- const std::vector<ScaleFactor>& supported =
- GetSupportedScaleFactorsInternal();
- for (size_t i = 0; i < supported.size(); ++i) {
- ScaleFactor scale_factor = supported[i];
+ for (size_t i = 0; i < g_supported_scale_factors->size(); ++i) {
+ ScaleFactor scale_factor = (*g_supported_scale_factors)[i];
float diff = std::abs(kScaleFactorScales[scale_factor] - scale);
if (diff < smallest_diff) {
closest_match = scale_factor;
@@ -166,49 +117,55 @@ ScaleFactor GetScaleFactorFromScale(float scale) {
return closest_match;
}
-float GetScaleFactorScale(ScaleFactor scale_factor) {
+float GetImageScale(ScaleFactor scale_factor) {
return kScaleFactorScales[scale_factor];
}
-ScaleFactor GetMaxScaleFactor() {
-#if defined(OS_CHROMEOS)
- return ResourceBundle::GetSharedInstance().max_scale_factor();
-#else
- return GetSupportedScaleFactorsInternal().back();
-#endif
-}
-
-std::vector<ScaleFactor> GetSupportedScaleFactors() {
- return GetSupportedScaleFactorsInternal();
+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();
}
-bool IsScaleFactorSupported(ScaleFactor scale_factor) {
- const std::vector<ScaleFactor>& supported =
- GetSupportedScaleFactorsInternal();
- return std::find(supported.begin(), supported.end(), scale_factor) !=
- supported.end();
+// 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;
}
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)
- : original_scale_factors_(GetSupportedScaleFactors()) {
+ 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;
+ }
SetSupportedScaleFactors(new_scale_factors);
}
ScopedSetSupportedScaleFactors::~ScopedSetSupportedScaleFactors() {
- SetSupportedScaleFactors(original_scale_factors_);
+ if (original_scale_factors_) {
+ SetSupportedScaleFactors(*original_scale_factors_);
+ delete original_scale_factors_;
+ } else {
+ delete g_supported_scale_factors;
+ g_supported_scale_factors = NULL;
+ }
}
} // namespace test
@@ -218,7 +175,7 @@ ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view) {
gfx::Screen* screen = gfx::Screen::GetScreenFor(view);
if (screen->IsDIPEnabled()) {
gfx::Display display = screen->GetDisplayNearestWindow(view);
- return GetScaleFactorFromScale(display.device_scale_factor());
+ return GetSupportedScaleFactor(display.device_scale_factor());
}
return ui::SCALE_FACTOR_100P;
}
diff --git a/ui/base/layout.h b/ui/base/layout.h
index 1292c38..50b0e50 100644
--- a/ui/base/layout.h
+++ b/ui/base/layout.h
@@ -46,36 +46,37 @@ 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 GetScaleFactorScale(ScaleFactor scale_factor);
+UI_EXPORT float GetImageScale(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 GetScaleFactorFromScale(float scale);
+UI_EXPORT ScaleFactor GetSupportedScaleFactor(float image_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);
-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);
+// 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 {
// Class which changes the value of GetSupportedScaleFactors() to
// |new_scale_factors| for the duration of its lifetime.
class UI_EXPORT ScopedSetSupportedScaleFactors {
@@ -85,7 +86,7 @@ class UI_EXPORT ScopedSetSupportedScaleFactors {
~ScopedSetSupportedScaleFactors();
private:
- const std::vector<ui::ScaleFactor> original_scale_factors_;
+ 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 f1a635d..6e50de1 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 GetScaleFactorFromScale(GetScaleFactorScaleForNativeView(view));
+ return GetSupportedScaleFactor(GetScaleFactorScaleForNativeView(view));
}
} // namespace ui
diff --git a/ui/base/layout_unittest.cc b/ui/base/layout_unittest.cc
index 8a74182..8ac2e2d 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, 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));
+ 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));
}
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, 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));
+ 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));
}
TEST(LayoutTest, GetScaleFactorFromScaleAllSupported) {
@@ -45,59 +45,22 @@ TEST(LayoutTest, GetScaleFactorFromScaleAllSupported) {
}
test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
- 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
+ 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));
}
} // namespace ui
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index 31aed58..8d2815d 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -40,6 +40,14 @@
#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 {
@@ -80,18 +88,19 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
virtual ~ResourceBundleImageSource() {}
// gfx::ImageSkiaSource overrides:
- virtual gfx::ImageSkiaRep GetImageForScale(
- ui::ScaleFactor scale_factor) OVERRIDE {
+ virtual gfx::ImageSkiaRep GetImageForScale(float scale) 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,
@@ -112,7 +121,7 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
}
}
- return gfx::ImageSkiaRep(image, scale_factor);
+ return gfx::ImageSkiaRep(image, scale);
}
private:
@@ -125,9 +134,7 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
// static
std::string ResourceBundle::InitSharedInstanceWithLocale(
const std::string& pref_locale, Delegate* delegate) {
- DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
- g_shared_instance_ = new ResourceBundle(delegate);
-
+ InitSharedInstance(delegate);
g_shared_instance_->LoadCommonResources();
std::string result = g_shared_instance_->LoadLocaleResources(pref_locale);
InitDefaultFont();
@@ -137,9 +144,7 @@ std::string ResourceBundle::InitSharedInstanceWithLocale(
// static
std::string ResourceBundle::InitSharedInstanceLocaleOnly(
const std::string& pref_locale, Delegate* delegate) {
- DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
- g_shared_instance_ = new ResourceBundle(delegate);
-
+ InitSharedInstance(delegate);
std::string result = g_shared_instance_->LoadLocaleResources(pref_locale);
InitDefaultFont();
return result;
@@ -148,9 +153,7 @@ std::string ResourceBundle::InitSharedInstanceLocaleOnly(
// static
void ResourceBundle::InitSharedInstanceWithPakFile(
base::PlatformFile pak_file, bool should_load_common_resources) {
- DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
- g_shared_instance_ = new ResourceBundle(NULL);
-
+ InitSharedInstance(NULL);
if (should_load_common_resources)
g_shared_instance_->LoadCommonResources();
@@ -166,9 +169,7 @@ void ResourceBundle::InitSharedInstanceWithPakFile(
// static
void ResourceBundle::InitSharedInstanceWithPakPath(const base::FilePath& path) {
- DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
- g_shared_instance_ = new ResourceBundle(NULL);
-
+ InitSharedInstance(NULL);
g_shared_instance_->LoadTestResources(path, path);
InitDefaultFont();
@@ -341,18 +342,20 @@ 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_factor_to_load);
+ scale);
if (image_skia.isNull()) {
LOG(WARNING) << "Unable to load image with id " << resource_id;
NOTREACHED(); // Want to assert in debug mode.
@@ -510,6 +513,14 @@ 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),
@@ -522,6 +533,49 @@ 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();
}
@@ -554,8 +608,8 @@ void ResourceBundle::AddDataPackFromPathInternal(const base::FilePath& path,
void ResourceBundle::AddDataPack(DataPack* data_pack) {
data_packs_.push_back(data_pack);
- if (GetScaleFactorScale(data_pack->GetScaleFactor()) >
- GetScaleFactorScale(max_scale_factor_))
+ if (GetImageScale(data_pack->GetScaleFactor()) >
+ GetImageScale(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 f9a34df..bea12c1 100644
--- a/ui/base/resource/resource_bundle.h
+++ b/ui/base/resource/resource_bundle.h
@@ -255,9 +255,7 @@ class UI_EXPORT ResourceBundle {
// Returns the maximum scale factor currently loaded.
// Returns SCALE_FACTOR_100P if no resource is loaded.
- ScaleFactor max_scale_factor() const {
- return max_scale_factor_;
- }
+ ScaleFactor GetMaxScaleFactor() const;
private:
FRIEND_TEST_ALL_PREFIXES(ResourceBundleTest, DelegateGetPathForLocalePack);
@@ -274,6 +272,9 @@ 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 c1daa91..d947c2f 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 = ui::GetMaxScaleFactor();
+ ui::ScaleFactor scale_factor = 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::GetScaleFactorScale(scale_factor);
+ CGFloat target_scale = ui::GetImageScale(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 6a7b2b7..e50d6b4 100644
--- a/ui/base/resource/resource_bundle_unittest.cc
+++ b/ui/base/resource/resource_bundle_unittest.cc
@@ -433,6 +433,10 @@ 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");
@@ -445,35 +449,44 @@ 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->max_scale_factor());
+ EXPECT_EQ(SCALE_FACTOR_200P, resource_bundle->GetMaxScaleFactor());
gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
#if defined(OS_CHROMEOS)
// ChromeOS loads highest scale factor first.
- EXPECT_EQ(ui::SCALE_FACTOR_200P, image_skia->image_reps()[0].scale_factor());
+ EXPECT_EQ(ui::SCALE_FACTOR_200P,
+ GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
#else
- EXPECT_EQ(ui::SCALE_FACTOR_100P, image_skia->image_reps()[0].scale_factor());
+ EXPECT_EQ(ui::SCALE_FACTOR_100P,
+ GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
#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(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());
+ 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()));
// 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::SCALE_FACTOR_140P);
- EXPECT_TRUE(image_rep.scale_factor() == ui::SCALE_FACTOR_100P ||
- image_rep.scale_factor() == ui::SCALE_FACTOR_200P);
+ 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);
}
// 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");
@@ -495,8 +508,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(ui::SCALE_FACTOR_200P);
- EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor());
+ image_skia->GetRepresentation(GetImageScale(ui::SCALE_FACTOR_200P));
+ EXPECT_EQ(ui::SCALE_FACTOR_200P, GetSupportedScaleFactor(image_rep.scale()));
EXPECT_EQ(20, image_rep.pixel_width());
EXPECT_EQ(20, image_rep.pixel_height());
}
@@ -506,6 +519,12 @@ 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");
@@ -527,9 +546,11 @@ 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(ui::SCALE_FACTOR_140P);
+ image_skia->GetRepresentation(
+ GetImageScale(ui::SCALE_FACTOR_140P));
EXPECT_EQ(12, image_rep.pixel_width());
- image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_180P);
+ image_rep = image_skia->GetRepresentation(
+ GetImageScale(ui::SCALE_FACTOR_180P));
EXPECT_EQ(15, image_rep.pixel_width());
}
#endif
@@ -547,7 +568,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,
- image_skia->image_reps()[0].scale_factor());
+ GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
}
} // namespace ui
diff --git a/ui/base/resource/resource_bundle_win.cc b/ui/base/resource/resource_bundle_win.cc
index 0a2b185..cb99e20 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::GetScaleFactorFromScale(scale)) {
+ switch(ui::GetSupportedScaleFactor(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 58c2c69..a218392 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->scale_factor());
+ gfx::ImageSkiaRep image_rep(bitmap, canvas->image_scale());
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 1e7a029..a960609 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, ui::GetScaleFactorFromScale(device_scale_factor_)));
+ sk_canvas, device_scale_factor_));
bool scale_content = scale_content_;
if (scale_content) {
diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc
index b59d2a0..eb0834b 100644
--- a/ui/gfx/canvas.cc
+++ b/ui/gfx/canvas.cc
@@ -23,11 +23,10 @@
namespace gfx {
-Canvas::Canvas(const Size& size, ui::ScaleFactor scale_factor, bool is_opaque)
- : scale_factor_(scale_factor),
+Canvas::Canvas(const Size& size, float image_scale, bool is_opaque)
+ : image_scale_(image_scale),
canvas_(NULL) {
- Size pixel_size = ToCeiledSize(
- ScaleSize(size, ui::GetScaleFactorScale(scale_factor)));
+ Size pixel_size = ToCeiledSize(ScaleSize(size, image_scale));
owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(),
pixel_size.height(),
is_opaque));
@@ -39,24 +38,24 @@ Canvas::Canvas(const Size& size, ui::ScaleFactor scale_factor, bool is_opaque)
owned_canvas_->clear(SkColorSetARGB(0, 0, 0, 0));
#endif
- SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor));
- canvas_->scale(scale, scale);
+ SkScalar scale_scalar = SkFloatToScalar(image_scale);
+ canvas_->scale(scale_scalar, scale_scalar);
}
Canvas::Canvas(const ImageSkiaRep& image_rep, bool is_opaque)
- : scale_factor_(image_rep.scale_factor()),
+ : image_scale_(image_rep.scale()),
owned_canvas_(skia::AdoptRef(
skia::CreatePlatformCanvas(image_rep.pixel_width(),
image_rep.pixel_height(),
is_opaque))),
canvas_(owned_canvas_.get()) {
- SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor_));
- canvas_->scale(scale, scale);
+ SkScalar scale_scalar = SkFloatToScalar(image_scale_);
+ canvas_->scale(scale_scalar, scale_scalar);
DrawImageInt(ImageSkia(image_rep), 0, 0);
}
Canvas::Canvas()
- : scale_factor_(ui::SCALE_FACTOR_100P),
+ : image_scale_(1.0),
owned_canvas_(skia::AdoptRef(skia::CreatePlatformCanvas(0, 0, false))),
canvas_(owned_canvas_.get()) {
}
@@ -66,22 +65,21 @@ Canvas::~Canvas() {
// static
Canvas* Canvas::CreateCanvasWithoutScaling(SkCanvas* canvas,
- ui::ScaleFactor scale_factor) {
- return new Canvas(canvas, scale_factor);
+ float image_scale) {
+ return new Canvas(canvas, image_scale);
}
void Canvas::RecreateBackingCanvas(const Size& size,
- ui::ScaleFactor scale_factor,
+ float image_scale,
bool is_opaque) {
- scale_factor_ = scale_factor;
- Size pixel_size = ToFlooredSize(
- ScaleSize(size, ui::GetScaleFactorScale(scale_factor)));
+ image_scale_ = image_scale;
+ Size pixel_size = ToFlooredSize(ScaleSize(size, image_scale));
owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(),
pixel_size.height(),
is_opaque));
canvas_ = owned_canvas_.get();
- SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor_));
- canvas_->scale(scale, scale);
+ SkScalar scale_scalar = SkFloatToScalar(image_scale);
+ canvas_->scale(scale_scalar, scale_scalar);
}
// static
@@ -136,7 +134,7 @@ ImageSkiaRep Canvas::ExtractImageRep() const {
SkBitmap result;
device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config);
- return ImageSkiaRep(result, scale_factor_);
+ return ImageSkiaRep(result, image_scale_);
}
void Canvas::DrawDashedRect(const Rect& rect, SkColor color) {
@@ -329,7 +327,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.GetScale();
+ float bitmap_scale = image_rep.scale();
canvas_->save();
canvas_->scale(SkFloatToScalar(1.0f / bitmap_scale),
@@ -392,7 +390,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_factor() == ui::SCALE_FACTOR_100P) {
+ image_rep.scale() == 1.0f) {
// 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 };
@@ -574,8 +572,8 @@ void Canvas::Transform(const gfx::Transform& transform) {
canvas_->concat(transform.matrix());
}
-Canvas::Canvas(SkCanvas* canvas, ui::ScaleFactor scale_factor)
- : scale_factor_(scale_factor),
+Canvas::Canvas(SkCanvas* canvas, float image_scale)
+ : image_scale_(image_scale),
owned_canvas_(),
canvas_(canvas) {
DCHECK(canvas);
@@ -601,7 +599,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(scale_factor_);
+ const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_);
if (!image_rep.is_null()) {
SkMatrix m = canvas_->getTotalMatrix();
@@ -610,7 +608,7 @@ const ImageSkiaRep& Canvas::GetImageRepToPaint(
float scale_y = SkScalarToFloat(SkScalarAbs(m.getScaleY())) *
user_additional_scale_y;
- float bitmap_scale = image_rep.GetScale();
+ float bitmap_scale = image_rep.scale();
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 c8996a2..d6479cc 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 scale factor of 1x.
+ // Creates an empty canvas with image_scale of 1x.
Canvas();
- // Creates canvas with provided DIP |size| and |scale_factor|.
+ // Creates canvas with provided DIP |size| and |image_scale|.
// If this canvas is not opaque, it's explicitly cleared to transparent before
// being returned.
- Canvas(const Size& size, ui::ScaleFactor scale_factor, bool is_opaque);
+ Canvas(const Size& size, float image_scale, bool is_opaque);
- // Constructs a canvas with the size and the scale factor of the
- // provided |image_rep|, and draws the |image_rep| into it.
+ // Constructs a canvas with the size and the image_scale 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 |scale_factor|.
- // |sk_canvas| is assumed to be already scaled based on |scale_factor|
+ // Creates a Canvas backed by an |sk_canvas| with |image_scale_|.
+ // |sk_canvas| is assumed to be already scaled based on |image_scale|
// so no additional scaling is applied.
static Canvas* CreateCanvasWithoutScaling(SkCanvas* sk_canvas,
- ui::ScaleFactor scale_factor);
+ float image_scale);
- // Recreates the backing platform canvas with DIP |size| and |scale_factor|.
+ // Recreates the backing platform canvas with DIP |size| and |image_scale_|.
// 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 scale factor into skia::PlatformCanvas such that
+ // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that
// this method can be private.
void RecreateBackingCanvas(const Size& size,
- ui::ScaleFactor scale_factor,
+ float image_scale,
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_; }
- ui::ScaleFactor scale_factor() const { return scale_factor_; }
+ float image_scale() const { return image_scale_; }
private:
- Canvas(SkCanvas* canvas, ui::ScaleFactor scale_factor);
+ Canvas(SkCanvas* canvas, float image_scale);
// 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 |scale_factor_|.
+ // Returns the image rep which best matches the canvas |image_scale_|.
// 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 |scale_factor_|.
- ui::ScaleFactor scale_factor_;
+ // Canvas::Scale() does not affect |image_scale_|.
+ float image_scale_;
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 4c185c0..3faa064 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),
- ui::SCALE_FACTOR_100P, opaque);
+ 1.0f, 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 c8796af..8ba697d 100644
--- a/ui/gfx/canvas_paint_mac.mm
+++ b/ui/gfx/canvas_paint_mac.mm
@@ -58,9 +58,8 @@ 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_factor, opaque);
+ RecreateBackingCanvas(size, scale, opaque);
skia::PlatformCanvas* canvas = platform_canvas();
canvas->clear(SkColorSetARGB(0, 0, 0, 0));
@@ -74,4 +73,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 71c8367..7d20fbc 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),
- ui::GetScaleFactorFromScale(gfx::win::GetDeviceScaleFactor()),
+ gfx::win::GetDeviceScaleFactor(),
opaque);
skia::PlatformCanvas* canvas = platform_canvas();
diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc
index ef8ee36..b6830d5 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, scale_factor(), true);
+ Canvas text_canvas(size, image_scale(), 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.scale_factor()));
+ text_canvas.image_scale()));
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 c76681c..7757eb9 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(250, 200), 1.0f, 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, 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), ui::SCALE_FACTOR_100P, true);
+ gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, 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 747625a..b336b31 100644
--- a/ui/gfx/image/canvas_image_source.cc
+++ b/ui/gfx/image/canvas_image_source.cc
@@ -6,7 +6,6 @@
#include "base/logging.h"
#include "ui/gfx/canvas.h"
-#include "ui/base/layout.h"
namespace gfx {
@@ -18,9 +17,8 @@ CanvasImageSource::CanvasImageSource(const gfx::Size& size, bool is_opaque)
is_opaque_(is_opaque) {
}
-gfx::ImageSkiaRep CanvasImageSource::GetImageForScale(
- ui::ScaleFactor scale_factor) {
- gfx::Canvas canvas(size_, scale_factor, is_opaque_);
+gfx::ImageSkiaRep CanvasImageSource::GetImageForScale(float scale) {
+ gfx::Canvas canvas(size_, scale, 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 8373387..88e891d 100644
--- a/ui/gfx/image/canvas_image_source.h
+++ b/ui/gfx/image/canvas_image_source.h
@@ -30,8 +30,7 @@ class UI_EXPORT CanvasImageSource : public gfx::ImageSkiaSource {
const gfx::Size& size() const { return size_; };
// Overridden from gfx::ImageSkiaSource.
- virtual gfx::ImageSkiaRep GetImageForScale(
- ui::ScaleFactor scale_factor) OVERRIDE;
+ virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE;
protected:
virtual ~CanvasImageSource() {}
diff --git a/ui/gfx/image/image.cc b/ui/gfx/image/image.cc
index f089c83..91b9e69 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)),
- ui::SCALE_FACTOR_100P,
+ 1.0f,
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_factor == ui::SCALE_FACTOR_100P)
+ if (image_png_reps[i].scale == 1.0f)
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, ui::SCALE_FACTOR_100P));
+ return new gfx::ImageSkia(gfx::ImageSkiaRep(bitmap, 1.0f));
}
ImageSkia* ImageSkiaFromPNG(
@@ -159,23 +159,22 @@ ImageSkia* ImageSkiaFromPNG(
if (!gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(),
&bitmap)) {
LOG(ERROR) << "Unable to decode PNG for "
- << ui::GetScaleFactorScale(image_png_reps[i].scale_factor)
+ << image_png_reps[i].scale
<< ".";
return GetErrorImageSkia();
}
image_skia->AddRepresentation(gfx::ImageSkiaRep(
- bitmap, image_png_reps[i].scale_factor));
+ bitmap, image_png_reps[i].scale));
}
return image_skia.release();
}
scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia(
const ImageSkia* image_skia) {
- ImageSkiaRep image_skia_rep = image_skia->GetRepresentation(
- ui::SCALE_FACTOR_100P);
+ ImageSkiaRep image_skia_rep = image_skia->GetRepresentation(1.0f);
scoped_refptr<base::RefCountedBytes> png_bytes(new base::RefCountedBytes());
- if (image_skia_rep.scale_factor() != ui::SCALE_FACTOR_100P ||
+ if (image_skia_rep.scale() != 1.0f ||
!gfx::PNGCodec::EncodeBGRASkBitmap(image_skia_rep.sk_bitmap(), false,
&png_bytes->data())) {
return NULL;
@@ -274,7 +273,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_factor == ui::SCALE_FACTOR_100P) {
+ if (it->scale == 1.0f) {
size_cache_.reset(new gfx::Size(it->Size()));
return *size_cache_;
}
@@ -604,7 +603,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, ui::SCALE_FACTOR_100P));
+ image_reps.push_back(ImagePNGRep(raw_data, 1.0f));
return gfx::Image(image_reps);
}
@@ -772,7 +771,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_factor == ui::SCALE_FACTOR_100P)
+ if (image_png_reps[i].scale == 1.0f)
return image_png_reps[i].raw_data;
}
return new base::RefCountedBytes();
@@ -827,8 +826,7 @@ 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,
- ui::SCALE_FACTOR_100P));
+ image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, 1.0f));
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 01a3c87..f792e0d 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 = ui::GetScaleFactorScale(image_png_rep.scale_factor);
+ float scale = image_png_rep.scale;
scoped_refptr<base::RefCountedMemory> png = image_png_rep.raw_data;
CHECK(png.get());
NSData* data = [NSData dataWithBytes:png->front() length:png->size()];
@@ -74,17 +74,16 @@ scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromUIImage(
UIImage* CreateUIImageFromPNG(
const std::vector<gfx::ImagePNGRep>& image_png_reps) {
- ui::ScaleFactor ideal_scale_factor = ui::GetMaxScaleFactor();
- float ideal_scale = ui::GetScaleFactorScale(ideal_scale_factor);
+ float ideal_scale = ImageSkia::GetMaxSupportedScale();
if (image_png_reps.empty())
return CreateErrorUIImage(ideal_scale);
- // Find best match for |ideal_scale_factor|.
+ // Find best match for |ideal_scale|.
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 = ui::GetScaleFactorScale(image_png_reps[i].scale_factor);
+ float scale = image_png_reps[i].scale;
float diff = std::abs(ideal_scale - scale);
if (diff < smallest_diff) {
smallest_diff = diff;
@@ -102,9 +101,8 @@ 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(
- ui::SCALE_FACTOR_100P);
- if (image_skia_rep.scale_factor() != ui::SCALE_FACTOR_100P)
+ const gfx::ImageSkiaRep& image_skia_rep = skia->GetRepresentation(1.0f);
+ if (image_skia_rep.scale() != 1.0f)
return NULL;
UIImage* image = UIImageFromImageSkiaRep(image_skia_rep);
@@ -119,8 +117,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 = ImageSkiaRepOfScaleFactorFromUIImage(
- uiimage, image_png_reps[i].scale_factor);
+ gfx::ImageSkiaRep image_skia_rep = ImageSkiaRepOfScaleFromUIImage(
+ uiimage, image_png_reps[i].scale);
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 d03b48e..15a5610 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 "
- << ui::GetScaleFactorScale(image_png_reps[i].scale_factor)
+ << image_png_reps[i].scale
<< ".";
return GetErrorNSImage();
}
@@ -88,7 +88,7 @@ NSImage* NSImageFromPNG(const std::vector<gfx::ImagePNGRep>& image_png_reps,
}
if (!image.get()) {
- float scale = ui::GetScaleFactorScale(image_png_reps[i].scale_factor);
+ float scale = image_png_reps[i].scale;
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 250deeb..2cbbd117 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 |scale_factors|.
+// described by |width|, |height|, and |scales|.
// The structure matches if:
// - |ns_image| is not nil.
-// - |ns_image| has NSImageReps of |scale_factors|.
+// - |ns_image| has NSImageReps of |scales|.
// - Each of the NSImageReps has a pixel size of [|ns_image| size] *
-// scale_factor.
+// scale.
bool NSImageStructureMatches(
NSImage* ns_image,
int width,
int height,
- const std::vector<ui::ScaleFactor>& scale_factors) {
+ const std::vector<float>& scales) {
if (!ns_image ||
[ns_image size].width != width ||
[ns_image size].height != height ||
- [ns_image representations].count != scale_factors.size()) {
+ [ns_image representations].count != scales.size()) {
return false;
}
- for (size_t i = 0; i < scale_factors.size(); ++i) {
- float scale = ui::GetScaleFactorScale(scale_factors[i]);
+ for (size_t i = 0; i < scales.size(); ++i) {
+ float scale = scales[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,16 +74,14 @@ void BitmapImageRep(int width, int height,
class ImageMacTest : public testing::Test {
public:
- ImageMacTest()
- : supported_scale_factors_(gfx::test::Get1xAnd2xScaleFactors()) {
+ ImageMacTest() {
+ gfx::ImageSkia::SetSupportedScales(gfx::test::Get1xAnd2xScales());
}
virtual ~ImageMacTest() {
}
private:
- ui::test::ScopedSetSupportedScaleFactors supported_scale_factors_;
-
DISALLOW_COPY_AND_ASSIGN(ImageMacTest);
};
@@ -110,11 +108,11 @@ TEST_F(ImageMacTest, MultiResolutionNSImageToImageSkia) {
const gfx::ImageSkia* image_skia = image.ToImageSkia();
- std::vector<ui::ScaleFactor> scale_factors;
- scale_factors.push_back(ui::SCALE_FACTOR_100P);
- scale_factors.push_back(ui::SCALE_FACTOR_200P);
+ std::vector<float> scales;
+ scales.push_back(1.0f);
+ scales.push_back(2.0f);
EXPECT_TRUE(gt::ImageSkiaStructureMatches(*image_skia, kWidth1x, kHeight1x,
- scale_factors));
+ scales));
// ToImageSkia should create a second representation.
EXPECT_EQ(2u, image.RepresentationCount());
@@ -141,11 +139,11 @@ TEST_F(ImageMacTest, UnalignedMultiResolutionNSImageToImageSkia) {
const gfx::ImageSkia* image_skia = image.ToImageSkia();
- std::vector<ui::ScaleFactor> scale_factors;
- scale_factors.push_back(ui::SCALE_FACTOR_100P);
- scale_factors.push_back(ui::SCALE_FACTOR_200P);
+ std::vector<float> scales;
+ scales.push_back(1.0f);
+ scales.push_back(2.0f);
EXPECT_TRUE(gt::ImageSkiaStructureMatches(*image_skia, kWidth1x, kHeight1x,
- scale_factors));
+ scales));
// ToImageSkia should create a second representation.
EXPECT_EQ(2u, image.RepresentationCount());
@@ -159,9 +157,9 @@ TEST_F(ImageMacTest, MultiResolutionImageSkiaToNSImage) {
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(
- gt::CreateBitmap(kWidth1x, kHeight1x), ui::SCALE_FACTOR_100P));
+ gt::CreateBitmap(kWidth1x, kHeight1x), 1.0f));
image_skia.AddRepresentation(gfx::ImageSkiaRep(
- gt::CreateBitmap(kWidth2x, kHeight2x), ui::SCALE_FACTOR_200P));
+ gt::CreateBitmap(kWidth2x, kHeight2x), 2.0f));
gfx::Image image(image_skia);
@@ -170,11 +168,10 @@ TEST_F(ImageMacTest, MultiResolutionImageSkiaToNSImage) {
NSImage* ns_image = image.ToNSImage();
- 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));
+ std::vector<float> scales;
+ scales.push_back(1.0f);
+ scales.push_back(2.0f);
+ EXPECT_TRUE(NSImageStructureMatches(ns_image, kWidth1x, kHeight1x, scales));
// Request for NSImage* should create a second representation.
EXPECT_EQ(2u, image.RepresentationCount());
@@ -187,17 +184,16 @@ 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, ui::SCALE_FACTOR_100P));
- image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, ui::SCALE_FACTOR_200P));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, 2.0f));
gfx::Image image(image_png_reps);
NSImage* ns_image = image.ToNSImage();
- 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));
+ std::vector<float> scales;
+ scales.push_back(1.0f);
+ scales.push_back(2.0f);
+ EXPECT_TRUE(NSImageStructureMatches(ns_image, kSize1x, kSize1x, scales));
// Converting from PNG to NSImage should not go through ImageSkia.
EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia));
@@ -205,9 +201,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(ui::SCALE_FACTOR_100P).sk_bitmap()));
+ image_skia.GetRepresentation(1.0f).sk_bitmap()));
EXPECT_TRUE(gt::IsEqual(bytes2x,
- image_skia.GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap()));
+ image_skia.GetRepresentation(2.0f).sk_bitmap()));
}
} // namespace
diff --git a/ui/gfx/image/image_png_rep.cc b/ui/gfx/image/image_png_rep.cc
index 253a529..3970d2b 100644
--- a/ui/gfx/image/image_png_rep.cc
+++ b/ui/gfx/image/image_png_rep.cc
@@ -4,6 +4,7 @@
#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"
@@ -12,13 +13,13 @@ namespace gfx {
ImagePNGRep::ImagePNGRep()
: raw_data(NULL),
- scale_factor(ui::SCALE_FACTOR_NONE) {
+ scale(1.0) {
}
ImagePNGRep::ImagePNGRep(const scoped_refptr<base::RefCountedMemory>& data,
- ui::ScaleFactor data_scale_factor)
+ float data_scale)
: raw_data(data),
- scale_factor(data_scale_factor) {
+ scale(data_scale) {
}
ImagePNGRep::~ImagePNGRep() {
diff --git a/ui/gfx/image/image_png_rep.h b/ui/gfx/image/image_png_rep.h
index 7e5ce5b..98e37454 100644
--- a/ui/gfx/image/image_png_rep.h
+++ b/ui/gfx/image/image_png_rep.h
@@ -6,7 +6,6 @@
#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 {
@@ -15,9 +14,10 @@ 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,
- ui::ScaleFactor data_scale_factor);
+ float data_scale);
~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;
- ui::ScaleFactor scale_factor;
+ float scale;
};
} // namespace gfx
diff --git a/ui/gfx/image/image_skia.cc b/ui/gfx/image/image_skia.cc
index 1ae9874..a283117 100644
--- a/ui/gfx/image/image_skia.cc
+++ b/ui/gfx/image/image_skia.cc
@@ -26,6 +26,7 @@ gfx::ImageSkiaRep& NullImageRep() {
return null_image_rep;
}
+std::vector<float>* g_supported_scales = NULL;
} // namespace
namespace internal {
@@ -33,15 +34,15 @@ namespace {
class Matcher {
public:
- explicit Matcher(ui::ScaleFactor scale_factor) : scale_factor_(scale_factor) {
+ explicit Matcher(float scale) : scale_(scale) {
}
bool operator()(const ImageSkiaRep& rep) const {
- return rep.scale_factor() == scale_factor_;
+ return rep.scale() == scale_;
}
private:
- ui::ScaleFactor scale_factor_;
+ float scale_;
};
} // namespace
@@ -61,11 +62,10 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
read_only_(false) {
}
- ImageSkiaStorage(ImageSkiaSource* source, ui::ScaleFactor scale_factor)
+ ImageSkiaStorage(ImageSkiaSource* source, float scale)
: source_(source),
read_only_(false) {
- ImageSkia::ImageSkiaReps::iterator it =
- FindRepresentation(scale_factor, true);
+ ImageSkia::ImageSkiaReps::iterator it = FindRepresentation(scale, true);
if (it == image_reps_.end() || it->is_null())
source_.reset();
else
@@ -103,16 +103,15 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
}
// Returns the iterator of the image rep whose density best matches
- // |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.
+ // |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.
std::vector<ImageSkiaRep>::iterator FindRepresentation(
- ui::ScaleFactor scale_factor, bool fetch_new_image) const {
+ float scale, 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 =
@@ -121,7 +120,7 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
for (ImageSkia::ImageSkiaReps::iterator it =
non_const->image_reps().begin();
it < image_reps_.end(); ++it) {
- if (it->GetScale() == scale) {
+ if (it->scale() == scale) {
// found exact match
fetch_new_image = false;
if (it->is_null())
@@ -129,7 +128,7 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
exact_iter = it;
break;
}
- float diff = std::abs(it->GetScale() - scale);
+ float diff = std::abs(it->scale() - scale);
if (diff < smallest_diff && !it->is_null()) {
closest_iter = it;
smallest_diff = diff;
@@ -140,25 +139,24 @@ 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_factor);
+ ImageSkiaRep image = source_->GetImageForScale(scale);
// 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_factor())) == image_reps_.end()) {
+ Matcher(image.scale())) == image_reps_.end()) {
non_const->image_reps().push_back(image);
}
- // 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));
+ // 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));
}
// image_reps_ must have the exact much now, so find again.
- return FindRepresentation(scale_factor, false);
+ return FindRepresentation(scale, false);
}
return exact_iter != image_reps_.end() ? exact_iter : closest_iter;
}
@@ -170,7 +168,7 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
DetachFromThread();
}
- // Vector of bitmaps and their associated scale factor.
+ // Vector of bitmaps and their associated scale.
std::vector<gfx::ImageSkiaRep> image_reps_;
scoped_ptr<ImageSkiaSource> source_;
@@ -195,8 +193,8 @@ ImageSkia::ImageSkia(ImageSkiaSource* source, const gfx::Size& size)
DetachStorageFromThread();
}
-ImageSkia::ImageSkia(ImageSkiaSource* source, ui::ScaleFactor scale_factor)
- : storage_(new internal::ImageSkiaStorage(source, scale_factor)) {
+ImageSkia::ImageSkia(ImageSkiaSource* source, float scale)
+ : storage_(new internal::ImageSkiaStorage(source, scale)) {
DCHECK(source);
if (!storage_->has_source())
storage_ = NULL;
@@ -222,8 +220,27 @@ 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, ui::SCALE_FACTOR_100P));
+ return ImageSkia(ImageSkiaRep(bitmap, 1.0f));
}
scoped_ptr<ImageSkia> ImageSkia::DeepCopy() const {
@@ -254,10 +271,9 @@ 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 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.
+ // 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.
if (isNull()) {
Init(image_rep);
} else {
@@ -266,37 +282,34 @@ void ImageSkia::AddRepresentation(const ImageSkiaRep& image_rep) {
}
}
-void ImageSkia::RemoveRepresentation(ui::ScaleFactor scale_factor) {
+void ImageSkia::RemoveRepresentation(float scale) {
if (isNull())
return;
CHECK(CanModify());
ImageSkiaReps& image_reps = storage_->image_reps();
ImageSkiaReps::iterator it =
- storage_->FindRepresentation(scale_factor, false);
- if (it != image_reps.end() && it->scale_factor() == scale_factor)
+ storage_->FindRepresentation(scale, false);
+ if (it != image_reps.end() && it->scale() == scale)
image_reps.erase(it);
}
-bool ImageSkia::HasRepresentation(ui::ScaleFactor scale_factor) const {
+bool ImageSkia::HasRepresentation(float scale) const {
if (isNull())
return false;
CHECK(CanRead());
- ImageSkiaReps::iterator it =
- storage_->FindRepresentation(scale_factor, false);
- return (it != storage_->image_reps().end() &&
- it->scale_factor() == scale_factor);
+ ImageSkiaReps::iterator it = storage_->FindRepresentation(scale, false);
+ return (it != storage_->image_reps().end() && it->scale() == scale);
}
-const ImageSkiaRep& ImageSkia::GetRepresentation(
- ui::ScaleFactor scale_factor) const {
+const ImageSkiaRep& ImageSkia::GetRepresentation(float scale) const {
if (isNull())
return NullImageRep();
CHECK(CanRead());
- ImageSkiaReps::iterator it = storage_->FindRepresentation(scale_factor, true);
+ ImageSkiaReps::iterator it = storage_->FindRepresentation(scale, true);
if (it == storage_->image_reps().end())
return NullImageRep();
@@ -311,7 +324,7 @@ void ImageSkia::SetReadOnly() {
void ImageSkia::MakeThreadSafe() {
CHECK(storage_.get());
- EnsureRepsForSupportedScaleFactors();
+ EnsureRepsForSupportedScales();
// Delete source as we no longer needs it.
if (storage_.get())
storage_->DeleteSource();
@@ -354,15 +367,15 @@ std::vector<ImageSkiaRep> ImageSkia::image_reps() const {
return image_reps;
}
-void ImageSkia::EnsureRepsForSupportedScaleFactors() const {
+void ImageSkia::EnsureRepsForSupportedScales() const {
+ DCHECK(g_supported_scales != NULL);
// 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()) {
- 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);
+ for (std::vector<float>::const_iterator it = g_supported_scales->begin();
+ it != g_supported_scales->end(); ++it)
+ storage_->FindRepresentation(*it, true);
}
}
@@ -390,8 +403,7 @@ SkBitmap& ImageSkia::GetBitmap() const {
CHECK(CanRead());
#endif
- ImageSkiaReps::iterator it =
- storage_->FindRepresentation(ui::SCALE_FACTOR_100P, true);
+ ImageSkiaReps::iterator it = storage_->FindRepresentation(1.0f, 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 4bc21f8..ec3e65a 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_factor| and uses its dimensions to calculate the size in DIP.
- // ImageSkia owns |source|.
- ImageSkia(ImageSkiaSource* source, ui::ScaleFactor scale_factor);
+ // at |scale| and uses its dimensions to calculate the size in DIP. ImageSkia
+ // owns |source|.
+ ImageSkia(ImageSkiaSource* source, float scale);
explicit ImageSkia(const gfx::ImageSkiaRep& image_rep);
@@ -61,6 +61,16 @@ 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.
@@ -74,7 +84,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
- // |EnsureRepsForSupportedScaleFactors()| first.
+ // |EnsureRepsForSupportedScales()| first.
scoped_ptr<ImageSkia> DeepCopy() const;
// Returns true if this object is backed by the same ImageSkiaStorage as
@@ -84,18 +94,16 @@ 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_factor| if present.
- void RemoveRepresentation(ui::ScaleFactor scale_factor);
+ // Removes the image rep of |scale| if present.
+ void RemoveRepresentation(float scale);
// Returns true if the object owns an image rep whose density matches
- // |scale_factor| exactly.
- bool HasRepresentation(ui::ScaleFactor scale_factor) const;
+ // |scale| exactly.
+ bool HasRepresentation(float scale) const;
- // Returns the image rep whose density best matches
- // |scale_factor|.
+ // Returns the image rep whose density best matches |scale|.
// Returns a null image rep if the object contains no image reps.
- const gfx::ImageSkiaRep& GetRepresentation(
- ui::ScaleFactor scale_factor) const;
+ const gfx::ImageSkiaRep& GetRepresentation(float scale) const;
// Make the ImageSkia instance read-only. Note that this only prevent
// modification from client code, and the storage may still be
@@ -136,7 +144,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 EnsureRepsForSupportedScaleFactors() const;
+ void EnsureRepsForSupportedScales() 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 6631560..6953b59 100644
--- a/ui/gfx/image/image_skia_operations.cc
+++ b/ui/gfx/image/image_skia_operations.cc
@@ -7,7 +7,6 @@
#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"
@@ -37,14 +36,13 @@ 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(ui::ScaleFactor scale_factor,
- const gfx::Size& pixel_size) {
+ImageSkiaRep GetErrorImageRep(float scale, 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_factor);
+ return gfx::ImageSkiaRep(bitmap, scale);
}
// A base image source class that creates an image from two source images.
@@ -62,27 +60,25 @@ class BinaryImageSource : public gfx::ImageSkiaSource {
}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
- ImageSkiaRep first_rep = first_.GetRepresentation(scale_factor);
- ImageSkiaRep second_rep = second_.GetRepresentation(scale_factor);
+ virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ ImageSkiaRep first_rep = first_.GetRepresentation(scale);
+ ImageSkiaRep second_rep = second_.GetRepresentation(scale);
if (first_rep.pixel_size() != second_rep.pixel_size()) {
- DCHECK_NE(first_rep.scale_factor(), second_rep.scale_factor());
- if (first_rep.scale_factor() == second_rep.scale_factor()) {
+ DCHECK_NE(first_rep.scale(), second_rep.scale());
+ if (first_rep.scale() == second_rep.scale()) {
LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_;
- return GetErrorImageRep(first_rep.scale_factor(),
- first_rep.pixel_size());
+ return GetErrorImageRep(first_rep.scale(),first_rep.pixel_size());
}
- first_rep = first_.GetRepresentation(ui::SCALE_FACTOR_100P);
- second_rep = second_.GetRepresentation(ui::SCALE_FACTOR_100P);
+ first_rep = first_.GetRepresentation(1.0f);
+ second_rep = second_.GetRepresentation(1.0f);
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_factor(),
- first_rep.pixel_size());
+ return GetErrorImageRep(first_rep.scale(), first_rep.pixel_size());
}
} else {
- DCHECK_EQ(first_rep.scale_factor(), second_rep.scale_factor());
+ DCHECK_EQ(first_rep.scale(), second_rep.scale());
}
return CreateImageSkiaRep(first_rep, second_rep);
}
@@ -121,7 +117,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_factor());
+ return ImageSkiaRep(blended, first_rep.scale());
}
private:
@@ -167,8 +163,8 @@ class TransparentImageSource : public gfx::ImageSkiaSource {
private:
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
- ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor);
+ virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ ImageSkiaRep image_rep = image_.GetRepresentation(scale);
SkBitmap alpha;
alpha.setConfig(SkBitmap::kARGB_8888_Config,
image_rep.pixel_width(),
@@ -177,7 +173,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_factor());
+ image_rep.scale());
}
ImageSkia image_;
@@ -201,7 +197,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_factor());
+ first_rep.scale());
}
private:
@@ -224,16 +220,15 @@ class TiledImageSource : public gfx::ImageSkiaSource {
}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
- ImageSkiaRep source_rep = source_.GetRepresentation(scale_factor);
- float scale = ui::GetScaleFactorScale(source_rep.scale_factor());
+ virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ ImageSkiaRep source_rep = source_.GetRepresentation(scale);
gfx::Rect bounds = DIPToPixelBounds(gfx::Rect(src_x_, src_y_, dst_w_,
- dst_h_), scale);
+ dst_h_), source_rep.scale());
return ImageSkiaRep(
SkBitmapOperations::CreateTiledBitmap(
source_rep.sk_bitmap(),
bounds.x(), bounds.y(), bounds.width(), bounds.height()),
- source_rep.scale_factor());
+ source_rep.scale());
}
private:
@@ -258,11 +253,11 @@ class HSLImageSource : public gfx::ImageSkiaSource {
}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
- ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor);
+ virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ ImageSkiaRep image_rep = image_.GetRepresentation(scale);
return gfx::ImageSkiaRep(
SkBitmapOperations::CreateHSLShiftedBitmap(image_rep.sk_bitmap(),
- hsl_shift_), image_rep.scale_factor());
+ hsl_shift_), image_rep.scale());
}
private:
@@ -288,17 +283,17 @@ class ButtonImageSource: public gfx::ImageSkiaSource {
}
// gfx::ImageSkiaSource overrides:
- 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);
+ 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);
}
return gfx::ImageSkiaRep(
SkBitmapOperations::CreateButtonBackground(color_,
image_rep.sk_bitmap(), mask_rep.sk_bitmap()),
- image_rep.scale_factor());
+ image_rep.scale());
}
private:
@@ -323,16 +318,15 @@ class ExtractSubsetImageSource: public gfx::ImageSkiaSource {
}
// gfx::ImageSkiaSource overrides:
- 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());
+ virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ ImageSkiaRep image_rep = image_.GetRepresentation(scale);
SkIRect subset_bounds_in_pixel = RectToSkIRect(
- DIPToPixelBounds(subset_bounds_, scale_to_pixel));
+ DIPToPixelBounds(subset_bounds_, image_rep.scale()));
SkBitmap dst;
bool success = image_rep.sk_bitmap().extractSubset(&dst,
subset_bounds_in_pixel);
DCHECK(success);
- return gfx::ImageSkiaRep(dst, image_rep.scale_factor());
+ return gfx::ImageSkiaRep(dst, image_rep.scale());
}
private:
@@ -356,20 +350,19 @@ class ResizeSource : public ImageSkiaSource {
virtual ~ResizeSource() {}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
- const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
+ virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ const ImageSkiaRep& image_rep = source_.GetRepresentation(scale);
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_factor);
+ return ImageSkiaRep(resized, scale);
}
private:
@@ -392,10 +385,9 @@ class DropShadowSource : public ImageSkiaSource {
virtual ~DropShadowSource() {}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
- const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
+ virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ const ImageSkiaRep& image_rep = source_.GetRepresentation(scale);
- 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));
@@ -403,7 +395,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_factor());
+ return ImageSkiaRep(shadow_bitmap, image_rep.scale());
}
private:
@@ -425,11 +417,11 @@ class RotatedSource : public ImageSkiaSource {
virtual ~RotatedSource() {}
// gfx::ImageSkiaSource overrides:
- virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
- const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
+ virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ const ImageSkiaRep& image_rep = source_.GetRepresentation(scale);
const SkBitmap rotated_bitmap =
SkBitmapOperations::Rotate(image_rep.sk_bitmap(), rotation_);
- return ImageSkiaRep(rotated_bitmap, image_rep.scale_factor());
+ return ImageSkiaRep(rotated_bitmap, image_rep.scale());
}
private:
diff --git a/ui/gfx/image/image_skia_rep.cc b/ui/gfx/image/image_skia_rep.cc
index 005b9a3..f8f3acb 100644
--- a/ui/gfx/image/image_skia_rep.cc
+++ b/ui/gfx/image/image_skia_rep.cc
@@ -6,41 +6,30 @@
namespace gfx {
-ImageSkiaRep::ImageSkiaRep()
- : scale_factor_(ui::SCALE_FACTOR_NONE) {
+ImageSkiaRep::ImageSkiaRep() : scale_(1.0f) {
}
ImageSkiaRep::~ImageSkiaRep() {
}
-ImageSkiaRep::ImageSkiaRep(const gfx::Size& size,
- ui::ScaleFactor scale_factor)
- : scale_factor_(scale_factor) {
- float scale = ui::GetScaleFactorScale(scale_factor);
+ImageSkiaRep::ImageSkiaRep(const gfx::Size& size, float scale) : scale_(scale) {
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,
- ui::ScaleFactor scale_factor)
+ImageSkiaRep::ImageSkiaRep(const SkBitmap& src, float scale)
: bitmap_(src),
- scale_factor_(scale_factor) {
+ scale_(scale) {
}
int ImageSkiaRep::GetWidth() const {
- return static_cast<int>(bitmap_.width() /
- ui::GetScaleFactorScale(scale_factor_));
+ return static_cast<int>(bitmap_.width() / scale_);
}
int ImageSkiaRep::GetHeight() const {
- return static_cast<int>(bitmap_.height() /
- ui::GetScaleFactorScale(scale_factor_));
-}
-
-float ImageSkiaRep::GetScale() const {
- return ui::GetScaleFactorScale(scale_factor_);
+ return static_cast<int>(bitmap_.height() / scale_);
}
} // namespace gfx
diff --git a/ui/gfx/image/image_skia_rep.h b/ui/gfx/image/image_skia_rep.h
index 6fca411..66179fb 100644
--- a/ui/gfx/image/image_skia_rep.h
+++ b/ui/gfx/image/image_skia_rep.h
@@ -6,7 +6,6 @@
#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"
@@ -21,11 +20,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, ui::ScaleFactor scale_factor);
+ ImageSkiaRep(const gfx::Size& size, float scale);
- // Creates a bitmap with given scale factor.
+ // Creates a bitmap with given scale.
// Adds ref to |src|.
- ImageSkiaRep(const SkBitmap& src, ui::ScaleFactor scale_factor);
+ ImageSkiaRep(const SkBitmap& src, float scale);
// Returns true if the backing bitmap is null.
bool is_null() const { return bitmap_.isNull(); }
@@ -42,8 +41,7 @@ class UI_EXPORT ImageSkiaRep {
}
// Retrieves the scale that the bitmap will be painted at.
- float GetScale() const;
- ui::ScaleFactor scale_factor() const { return scale_factor_; }
+ float scale() const { return scale_; }
// Returns backing bitmap.
const SkBitmap& sk_bitmap() const { return bitmap_; }
@@ -53,7 +51,7 @@ class UI_EXPORT ImageSkiaRep {
SkBitmap& mutable_sk_bitmap() { return bitmap_; }
SkBitmap bitmap_;
- ui::ScaleFactor scale_factor_;
+ float scale_;
};
} // namespace gfx
diff --git a/ui/gfx/image/image_skia_source.h b/ui/gfx/image/image_skia_source.h
index ed38e1c..35be479 100644
--- a/ui/gfx/image/image_skia_source.h
+++ b/ui/gfx/image/image_skia_source.h
@@ -5,7 +5,8 @@
#ifndef UI_GFX_IMAGE_IMAGE_SKIA_SOURCE_H_
#define UI_GFX_IMAGE_IMAGE_SKIA_SOURCE_H_
-#include "ui/base/layout.h"
+#include <vector>
+
#include "ui/gfx/gfx_export.h"
namespace gfx {
@@ -16,11 +17,11 @@ class UI_EXPORT ImageSkiaSource {
public:
virtual ~ImageSkiaSource() {}
- // 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;
+ // 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;
};
} // namespace gfx
diff --git a/ui/gfx/image/image_skia_unittest.cc b/ui/gfx/image/image_skia_unittest.cc
index fd17453..00478221 100644
--- a/ui/gfx/image/image_skia_unittest.cc
+++ b/ui/gfx/image/image_skia_unittest.cc
@@ -8,7 +8,6 @@
#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"
@@ -32,7 +31,7 @@ class FixedSource : public ImageSkiaSource {
virtual ~FixedSource() {
}
- virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
return image_;
}
@@ -49,8 +48,8 @@ class DynamicSource : public ImageSkiaSource {
virtual ~DynamicSource() {
}
- virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
- return gfx::ImageSkiaRep(size_, scale_factor);
+ virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
+ return gfx::ImageSkiaRep(size_, scale);
}
private:
@@ -67,7 +66,7 @@ class NullSource: public ImageSkiaSource {
virtual ~NullSource() {
}
- virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
return gfx::ImageSkiaRep();
}
@@ -115,58 +114,55 @@ class TestOnThread : public base::SimpleThread {
} // namespace test
TEST(ImageSkiaTest, FixedSource) {
- ImageSkiaRep image(Size(100, 200), ui::SCALE_FACTOR_100P);
+ ImageSkiaRep image(Size(100, 200), 1.0f);
ImageSkia image_skia(new FixedSource(image), Size(100, 200));
EXPECT_EQ(0U, image_skia.image_reps().size());
- const ImageSkiaRep& result_100p =
- image_skia.GetRepresentation(ui::SCALE_FACTOR_100P);
+ const ImageSkiaRep& result_100p = image_skia.GetRepresentation(1.0f);
EXPECT_EQ(100, result_100p.GetWidth());
EXPECT_EQ(200, result_100p.GetHeight());
- EXPECT_EQ(ui::SCALE_FACTOR_100P, result_100p.scale_factor());
+ EXPECT_EQ(1.0f, result_100p.scale());
EXPECT_EQ(1U, image_skia.image_reps().size());
- const ImageSkiaRep& result_200p =
- image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
+ const ImageSkiaRep& result_200p = image_skia.GetRepresentation(2.0f);
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(ui::SCALE_FACTOR_100P, result_200p.scale_factor());
+ EXPECT_EQ(1.0f, result_200p.scale());
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(ui::SCALE_FACTOR_100P);
- image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
+ image_skia.GetRepresentation(1.0f);
+ image_skia.GetRepresentation(2.0f);
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(ui::SCALE_FACTOR_100P);
+ const ImageSkiaRep& result_100p = image_skia.GetRepresentation(1.0f);
EXPECT_EQ(100, result_100p.GetWidth());
EXPECT_EQ(200, result_100p.GetHeight());
- EXPECT_EQ(ui::SCALE_FACTOR_100P, result_100p.scale_factor());
+ EXPECT_EQ(1.0f, result_100p.scale());
EXPECT_EQ(1U, image_skia.image_reps().size());
const ImageSkiaRep& result_200p =
- image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
+ image_skia.GetRepresentation(2.0f);
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(ui::SCALE_FACTOR_200P, result_200p.scale_factor());
+ EXPECT_EQ(2.0f, result_200p.scale());
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(ui::SCALE_FACTOR_100P);
+ image_skia.GetRepresentation(1.0f);
EXPECT_EQ(2U, image_skia.image_reps().size());
- image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
+ image_skia.GetRepresentation(2.0f);
EXPECT_EQ(2U, image_skia.image_reps().size());
}
@@ -182,16 +178,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(ui::SCALE_FACTOR_100P);
- image.GetRepresentation(ui::SCALE_FACTOR_200P);
+ image.GetRepresentation(1.0f);
+ image.GetRepresentation(2.0f);
// After a lengthy amount of simulated time, finally loaded image reps.
image.AddRepresentation(ImageSkiaRep(
- gfx::Size(kSmallIcon1x, kSmallIcon1x), ui::SCALE_FACTOR_100P));
+ gfx::Size(kSmallIcon1x, kSmallIcon1x), 1.0f));
image.AddRepresentation(ImageSkiaRep(
- gfx::Size(kSmallIcon2x, kSmallIcon2x), ui::SCALE_FACTOR_200P));
+ gfx::Size(kSmallIcon2x, kSmallIcon2x), 2.0f));
image.AddRepresentation(ImageSkiaRep(
- gfx::Size(kLargeIcon1x, kLargeIcon1x), ui::SCALE_FACTOR_100P));
+ gfx::Size(kLargeIcon1x, kLargeIcon1x), 1.0f));
std::vector<ImageSkiaRep> image_reps = image.image_reps();
EXPECT_EQ(3u, image_reps.size());
@@ -199,9 +195,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_factor() == ui::SCALE_FACTOR_100P)
+ if (image_reps[i].scale() == 1.0f)
num_1x++;
- else if (image_reps[i].scale_factor() == ui::SCALE_FACTOR_200P)
+ else if (image_reps[i].scale() == 2.0f)
num_2x++;
}
EXPECT_EQ(2, num_1x);
@@ -218,9 +214,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), ui::SCALE_FACTOR_100P));
+ ImageSkia empty_image(ImageSkiaRep(Size(100, 200), 1.0f));
ImageSkia empty_image_copy(empty_image);
- empty_image.RemoveRepresentation(ui::SCALE_FACTOR_100P);
+ empty_image.RemoveRepresentation(1.0f);
// Check that ImageSkia::bitmap() still returns a valid SkBitmap pointer for
// the image and all its copies.
@@ -237,12 +233,12 @@ TEST(ImageSkiaTest, BackedBySameObjectAs) {
EXPECT_TRUE(image.BackedBySameObjectAs(unrelated));
image.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10),
- ui::SCALE_FACTOR_100P));
+ 1.0f));
ImageSkia copy = image;
copy.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10),
- ui::SCALE_FACTOR_200P));
+ 2.0f));
unrelated.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10),
- ui::SCALE_FACTOR_100P));
+ 1.0f));
EXPECT_TRUE(image.BackedBySameObjectAs(copy));
EXPECT_FALSE(image.BackedBySameObjectAs(unrelated));
EXPECT_FALSE(copy.BackedBySameObjectAs(unrelated));
@@ -259,7 +255,7 @@ TEST(ImageSkiaTest, EmptyOnThreadTest) {
}
TEST(ImageSkiaTest, StaticOnThreadTest) {
- ImageSkia image(ImageSkiaRep(Size(100, 200), ui::SCALE_FACTOR_100P));
+ ImageSkia image(ImageSkiaRep(Size(100, 200), 1.0f));
EXPECT_FALSE(image.IsThreadSafe());
test::TestOnThread image_on_thread(&image);
@@ -365,8 +361,8 @@ TEST(ImageSkiaTest, SourceOnThreadTest) {
image.MakeThreadSafe();
EXPECT_TRUE(image.IsThreadSafe());
// Check if image reps are generated for supported scale factors.
- EXPECT_EQ(ui::GetSupportedScaleFactors().size(),
- image.image_reps().size());
+ EXPECT_EQ(ImageSkia::GetSupportedScales().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 57c9698..6c5f30df 100644
--- a/ui/gfx/image/image_skia_util_ios.h
+++ b/ui/gfx/image/image_skia_util_ios.h
@@ -5,7 +5,6 @@
#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__
@@ -22,13 +21,11 @@ class ImageSkiaRep;
UI_EXPORT gfx::ImageSkia ImageSkiaFromUIImage(UIImage* image);
// Converts to an ImageSkiaRep of |scale_factor| from UIImage.
-// |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(
+// |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(
UIImage* image,
- ui::ScaleFactor scale_factor);
+ float scale);
// 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 0ff8978..77944ee 100644
--- a/ui/gfx/image/image_skia_util_ios.mm
+++ b/ui/gfx/image/image_skia_util_ios.mm
@@ -16,39 +16,37 @@ namespace gfx {
gfx::ImageSkia ImageSkiaFromUIImage(UIImage* image) {
gfx::ImageSkia image_skia;
- gfx::ImageSkiaRep image_skia_rep = ImageSkiaRepOfScaleFactorFromUIImage(
- image, ui::GetMaxScaleFactor());
+ float max_scale = ImageSkia::GetSupportedScales().back();
+ gfx::ImageSkiaRep image_skia_rep = ImageSkiaRepOfScaleFromUIImage(
+ image, max_scale);
if (!image_skia_rep.is_null())
image_skia.AddRepresentation(image_skia_rep);
return image_skia;
}
-gfx::ImageSkiaRep ImageSkiaRepOfScaleFactorFromUIImage(
- UIImage* image,
- ui::ScaleFactor scale_factor) {
+gfx::ImageSkiaRep ImageSkiaRepOfScaleFromUIImage(UIImage* image, float scale) {
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_factor);
+ return gfx::ImageSkiaRep(bitmap, scale);
}
UIImage* UIImageFromImageSkia(const gfx::ImageSkia& image_skia) {
- return UIImageFromImageSkiaRep(image_skia.GetRepresentation(
- ui::GetMaxScaleFactor()));
+ return UIImageFromImageSkiaRep(
+ image_skia.GetRepresentation(ImageSkia::GetSupportedScales().back()));
}
UIImage* UIImageFromImageSkiaRep(const gfx::ImageSkiaRep& image_skia_rep) {
if (image_skia_rep.is_null())
return nil;
- float scale = ui::GetScaleFactorScale(image_skia_rep.scale_factor());
+ float scale = image_skia_rep.scale();
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 f9d0475..64f95d6 100644
--- a/ui/gfx/image/image_skia_util_mac.mm
+++ b/ui/gfx/image/image_skia_util_mac.mm
@@ -57,12 +57,11 @@ gfx::ImageSkia ImageSkiaFromResizedNSImage(NSImage* image,
if (IsNSImageEmpty(image))
return gfx::ImageSkia();
- std::vector<ui::ScaleFactor> supported_scale_factors =
- ui::GetSupportedScaleFactors();
+ std::vector<float> supported_scales = ImageSkia::GetSupportedScales();
gfx::ImageSkia image_skia;
- for (size_t i = 0; i < supported_scale_factors.size(); ++i) {
- float scale = ui::GetScaleFactorScale(supported_scale_factors[i]);
+ for (size_t i = 0; i < supported_scales.size(); ++i) {
+ float scale = supported_scales[i];
NSSize desired_size_for_scale = NSMakeSize(desired_size.width * scale,
desired_size.height * scale);
NSImageRep* ns_image_rep = GetNSImageRepWithPixelSize(image,
@@ -73,8 +72,7 @@ gfx::ImageSkia ImageSkiaFromResizedNSImage(NSImage* image,
if (bitmap.isNull())
continue;
- image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap,
- supported_scale_factors[i]));
+ image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
}
return image_skia;
}
@@ -90,7 +88,7 @@ NSImage* NSImageFromImageSkia(const gfx::ImageSkia& image_skia) {
return nil;
base::scoped_nsobject<NSImage> image([[NSImage alloc] init]);
- image_skia.EnsureRepsForSupportedScaleFactors();
+ image_skia.EnsureRepsForSupportedScales();
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) {
@@ -108,7 +106,7 @@ NSImage* NSImageFromImageSkiaWithColorSpace(const gfx::ImageSkia& image_skia,
return nil;
base::scoped_nsobject<NSImage> image([[NSImage alloc] init]);
- image_skia.EnsureRepsForSupportedScaleFactors();
+ image_skia.EnsureRepsForSupportedScales();
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 6d3c649..3595828 100644
--- a/ui/gfx/image/image_unittest.cc
+++ b/ui/gfx/image/image_unittest.cc
@@ -5,7 +5,6 @@
#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"
@@ -31,6 +30,15 @@ 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;
@@ -95,14 +103,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, ui::SCALE_FACTOR_100P));
+ image_png_reps1.push_back(gfx::ImagePNGRep(NULL, 1.0f));
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(), ui::SCALE_FACTOR_100P));
+ new base::RefCountedBytes(), 1.0f));
gfx::Image image2(image_png_reps2);
EXPECT_TRUE(image2.IsEmpty());
EXPECT_EQ(0U, image2.RepresentationCount());
@@ -166,7 +174,7 @@ TEST_F(ImageTest, ImageNo1xToPNG) {
const int kSize2x = 50;
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(gt::CreateBitmap(
- kSize2x, kSize2x), ui::SCALE_FACTOR_200P));
+ kSize2x, kSize2x), 2.0f));
gfx::Image image1(image_skia);
scoped_refptr<base::RefCountedMemory> png_bytes1 = image1.As1xPNGBytes();
EXPECT_TRUE(png_bytes1.get());
@@ -174,7 +182,7 @@ TEST_F(ImageTest, ImageNo1xToPNG) {
std::vector<gfx::ImagePNGRep> image_png_reps;
image_png_reps.push_back(gfx::ImagePNGRep(
- gt::CreatePNGBytes(kSize2x), ui::SCALE_FACTOR_200P));
+ gt::CreatePNGBytes(kSize2x), 2.0f));
gfx::Image image2(image_png_reps);
EXPECT_FALSE(image2.IsEmpty());
EXPECT_EQ(0, image2.Width());
@@ -192,9 +200,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, ui::SCALE_FACTOR_100P));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f));
image_png_reps.push_back(gfx::ImagePNGRep(
- gt::CreatePNGBytes(kSize2x), ui::SCALE_FACTOR_200P));
+ gt::CreatePNGBytes(kSize2x), 2.0f));
gfx::Image image(image_png_reps);
EXPECT_FALSE(image.IsEmpty());
@@ -212,9 +220,9 @@ TEST_F(ImageTest, MultiResolutionImageSkiaToPNG) {
SkBitmap bitmap_1x = gt::CreateBitmap(kSize1x, kSize1x);
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap_1x,
- ui::SCALE_FACTOR_100P));
+ 1.0f));
image_skia.AddRepresentation(gfx::ImageSkiaRep(gt::CreateBitmap(
- kSize2x, kSize2x), ui::SCALE_FACTOR_200P));
+ kSize2x, kSize2x), 2.0f));
gfx::Image image(image_skia);
EXPECT_TRUE(gt::IsEqual(image.As1xPNGBytes(), bitmap_1x));
@@ -229,20 +237,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, ui::SCALE_FACTOR_100P));
- image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, ui::SCALE_FACTOR_200P));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, 2.0f));
gfx::Image image(image_png_reps);
- std::vector<ui::ScaleFactor> scale_factors;
- scale_factors.push_back(ui::SCALE_FACTOR_100P);
- scale_factors.push_back(ui::SCALE_FACTOR_200P);
+ std::vector<float> scales;
+ scales.push_back(1.0f);
+ scales.push_back(2.0f);
gfx::ImageSkia image_skia = image.AsImageSkia();
EXPECT_TRUE(gt::ImageSkiaStructureMatches(image_skia, kSize1x, kSize1x,
- scale_factors));
+ scales));
EXPECT_TRUE(gt::IsEqual(bytes1x,
- image_skia.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap()));
+ image_skia.GetRepresentation(1.0f).sk_bitmap()));
EXPECT_TRUE(gt::IsEqual(bytes2x,
- image_skia.GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap()));
+ image_skia.GetRepresentation(2.0f).sk_bitmap()));
}
TEST_F(ImageTest, MultiResolutionPNGToPlatform) {
@@ -252,18 +260,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, ui::SCALE_FACTOR_100P));
- image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, ui::SCALE_FACTOR_200P));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, 2.0f));
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<ui::ScaleFactor> scale_factors = ui::GetSupportedScaleFactors();
- EXPECT_EQ(scale_factors.size(), 1U);
- if (scale_factors[0] == ui::SCALE_FACTOR_100P)
+ std::vector<float> scales = gfx::ImageSkia::GetSupportedScales();
+ EXPECT_EQ(scales.size(), 1U);
+ if (scales[0] == 1.0f)
EXPECT_TRUE(gt::IsEqual(bytes1x, from_platform.AsBitmap()));
- else if (scale_factors[0] == ui::SCALE_FACTOR_200P)
+ else if (scales[0] == 2.0f)
EXPECT_TRUE(gt::IsEqual(bytes2x, from_platform.AsBitmap()));
else
ADD_FAILURE() << "Unexpected platform scale factor.";
@@ -281,7 +289,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, ui::SCALE_FACTOR_100P));
+ image_png_reps.push_back(gfx::ImagePNGRep(png_data, 1.0f));
gfx::Image from_png(image_png_reps);
EXPECT_TRUE(from_png.HasRepresentation(gfx::Image::kImageRepPNG));
@@ -292,15 +300,13 @@ 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, ideal_scale_factor));
+ image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, 1.0f));
gfx::Image from_png(image_png_reps);
gfx::Image from_platform(gt::CopyPlatformType(from_png));
@@ -315,7 +321,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, ui::SCALE_FACTOR_100P));
+ image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, 1.0f));
gfx::Image from_png(image_png_reps);
EXPECT_TRUE(gt::IsEqual(from_platform.AsBitmap(), from_png.AsBitmap()));
@@ -327,7 +333,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, ui::SCALE_FACTOR_100P));
+ invalid_bytes, 1.0f));
gfx::Image image(image_png_reps);
gt::CheckImageIndicatesPNGDecodeFailure(image);
}
@@ -338,7 +344,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, ui::SCALE_FACTOR_100P));
+ invalid_bytes, 1.0f));
gfx::Image from_png(image_png_reps);
gfx::Image from_platform(gt::CopyPlatformType(from_png));
gt::CheckImageIndicatesPNGDecodeFailure(from_platform);
@@ -636,16 +642,16 @@ TEST_F(ImageTest, MultiResolutionImageSkia) {
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(
gt::CreateBitmap(kWidth1x, kHeight1x),
- ui::SCALE_FACTOR_100P));
+ 1.0f));
image_skia.AddRepresentation(gfx::ImageSkiaRep(
gt::CreateBitmap(kWidth2x, kHeight2x),
- ui::SCALE_FACTOR_200P));
+ 2.0f));
- std::vector<ui::ScaleFactor> scale_factors;
- scale_factors.push_back(ui::SCALE_FACTOR_100P);
- scale_factors.push_back(ui::SCALE_FACTOR_200P);
+ std::vector<float> scales;
+ scales.push_back(1.0f);
+ scales.push_back(2.0f);
EXPECT_TRUE(gt::ImageSkiaStructureMatches(image_skia, kWidth1x, kHeight1x,
- scale_factors));
+ scales));
// Check that the image has a single representation.
gfx::Image image(image_skia);
@@ -661,13 +667,13 @@ TEST_F(ImageTest, RemoveFromMultiResolutionImageSkia) {
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(
- gt::CreateBitmap(kWidth2x, kHeight2x), ui::SCALE_FACTOR_200P));
+ gt::CreateBitmap(kWidth2x, kHeight2x), 2.0f));
EXPECT_EQ(1u, image_skia.image_reps().size());
- image_skia.RemoveRepresentation(ui::SCALE_FACTOR_100P);
+ image_skia.RemoveRepresentation(1.0f);
EXPECT_EQ(1u, image_skia.image_reps().size());
- image_skia.RemoveRepresentation(ui::SCALE_FACTOR_200P);
+ image_skia.RemoveRepresentation(2.0f);
EXPECT_EQ(0u, image_skia.image_reps().size());
}
@@ -679,7 +685,7 @@ TEST_F(ImageTest, OwnershipTest) {
SkBitmap bitmap(gt::CreateBitmap(10, 10));
EXPECT_TRUE(!bitmap.isNull());
image = gfx::Image(gfx::ImageSkia(
- gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)));
+ gfx::ImageSkiaRep(bitmap, 1.0f)));
}
EXPECT_TRUE(!image.ToSkBitmap()->isNull());
}
diff --git a/ui/gfx/image/image_unittest_util.cc b/ui/gfx/image/image_unittest_util.cc
index ef59eb6..4baf30a 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<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;
+std::vector<float> Get1xAnd2xScales() {
+ std::vector<float> scales;
+ scales.push_back(1.0f);
+ scales.push_back(2.0f);
+ return scales;
}
const SkBitmap CreateBitmap(int width, int height) {
@@ -89,10 +89,9 @@ bool IsEqual(const gfx::Image& img1, const gfx::Image& img2) {
return false;
for (size_t i = 0; i < img1_reps.size(); ++i) {
- 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 ||
+ float scale = img1_reps[i].scale();
+ const gfx::ImageSkiaRep& image_rep2 = image_skia2.GetRepresentation(scale);
+ if (image_rep2.scale() != scale ||
!IsEqual(img1_reps[i].sk_bitmap(), image_rep2.sk_bitmap())) {
return false;
}
@@ -150,24 +149,22 @@ bool ImageSkiaStructureMatches(
const gfx::ImageSkia& image_skia,
int width,
int height,
- const std::vector<ui::ScaleFactor>& scale_factors) {
+ const std::vector<float>& scales) {
if (image_skia.isNull() ||
image_skia.width() != width ||
image_skia.height() != height ||
- image_skia.image_reps().size() != scale_factors.size()) {
+ image_skia.image_reps().size() != scales.size()) {
return false;
}
- for (size_t i = 0; i < scale_factors.size(); ++i) {
+ for (size_t i = 0; i < scales.size(); ++i) {
gfx::ImageSkiaRep image_rep =
- image_skia.GetRepresentation(scale_factors[i]);
- if (image_rep.is_null() ||
- image_rep.scale_factor() != scale_factors[i])
+ image_skia.GetRepresentation(scales[i]);
+ if (image_rep.is_null() || image_rep.scale() != scales[i])
return false;
- 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)) {
+ if (image_rep.pixel_width() != static_cast<int>(width * scales[i]) ||
+ image_rep.pixel_height() != static_cast<int>(height * scales[i])) {
return false;
}
}
@@ -183,8 +180,7 @@ bool IsEmpty(const gfx::Image& image) {
PlatformImage CreatePlatformImage() {
const SkBitmap bitmap(CreateBitmap(25, 25));
#if defined(OS_IOS)
- ui::ScaleFactor scale_factor = ui::GetMaxScaleFactor();
- float scale = ui::GetScaleFactorScale(scale_factor);
+ float scale = ImageSkia::GetMaxSupportedScale();
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 a2293c8..4788e4e 100644
--- a/ui/gfx/image/image_unittest_util.h
+++ b/ui/gfx/image/image_unittest_util.h
@@ -8,7 +8,6 @@
#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"
@@ -25,7 +24,7 @@ typedef GdkPixbuf* PlatformImage;
typedef gfx::ImageSkia PlatformImage;
#endif
-std::vector<ui::ScaleFactor> Get1xAnd2xScaleFactors();
+std::vector<float> Get1xAnd2xScales();
// Create a bitmap of |width|x|height|.
const SkBitmap CreateBitmap(int width, int height);
@@ -65,7 +64,7 @@ bool ImageSkiaStructureMatches(
const gfx::ImageSkia& image_skia,
int width,
int height,
- const std::vector<ui::ScaleFactor>& scale_factors);
+ const std::vector<float>& 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 e230a0b..59d631d 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(ui::SCALE_FACTOR_100P);
- if (image_skia_rep.scale_factor() != ui::SCALE_FACTOR_100P)
+ image.AsImageSkia().GetRepresentation(1.0f);
+ if (image_skia_rep.scale() != 1.0f)
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 50092ab..1d05d1a 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.GetScale());
+ SkScalar bitmap_scale = SkFloatToScalar(image_rep.scale());
// 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 98d23bd..2d2024f 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::GetScaleFactorScale(ui::GetScaleFactorFromScale(scale));
+ scale = ui::GetImageScale(ui::GetSupportedScaleFactor(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 b6e8bcc..11b3474 100644
--- a/ui/message_center/views/notification_view.cc
+++ b/ui/message_center/views/notification_view.cc
@@ -108,7 +108,8 @@ 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(factor).sk_bitmap();
+ SkBitmap bitmap =
+ image.GetRepresentation(ui::GetImageScale(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 2f94f54..43bc222 100644
--- a/ui/native_theme/native_theme_base.cc
+++ b/ui/native_theme/native_theme_base.cc
@@ -1004,10 +1004,9 @@ void NativeThemeBase::DrawImageInt(
// TODO(pkotwicz): Do something better and don't infer device
// scale factor from canvas scale.
SkMatrix m = sk_canvas->getTotalMatrix();
- ui::ScaleFactor device_scale_factor = ui::GetScaleFactorFromScale(
- SkScalarAbs(m.getScaleX()));
+ float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX()));
scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling(
- sk_canvas, device_scale_factor));
+ sk_canvas, device_scale));
canvas->DrawImageInt(image, src_x, src_y, src_w, src_h,
dest_x, dest_y, dest_w, dest_h, true);
}
@@ -1019,10 +1018,9 @@ 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();
- ui::ScaleFactor device_scale_factor = ui::GetScaleFactorFromScale(
- SkScalarAbs(m.getScaleX()));
+ float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX()));
scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling(
- sk_canvas, device_scale_factor));
+ sk_canvas, device_scale));
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 5ea0fa9..8dbe9d8 100644
--- a/ui/views/controls/button/image_button.h
+++ b/ui/views/controls/button/image_button.h
@@ -7,6 +7,7 @@
#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 f7fcd3f..5ce23fa 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->scale_factor(),
+ canvas->image_scale(),
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 ac08ec7..2e5a4dc 100644
--- a/ui/views/controls/menu/menu_win.cc
+++ b/ui/views/controls/menu/menu_win.cc
@@ -183,8 +183,7 @@ 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(ui::SCALE_FACTOR_100P);
+ gfx::ImageSkiaRep icon_image_rep = data->icon.GetRepresentation(1.0f);
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 c48a98c..9349c69 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(ui::SCALE_FACTOR_100P),
+ skia_icon->GetRepresentation(1.0f),
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),
- ui::SCALE_FACTOR_100P,
+ 1.0f,
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 61f4b76..b156276 100644
--- a/ui/views/drag_utils.cc
+++ b/ui/views/drag_utils.cc
@@ -22,8 +22,8 @@
#error
#endif
-ui::ScaleFactor GetDeviceScaleFactorForNativeView(views::Widget* widget) {
- ui::ScaleFactor device_scale_factor = ui::SCALE_FACTOR_100P;
+float GetDeviceScaleForNativeView(views::Widget* widget) {
+ float device_scale = 1.0f;
#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,11 +32,10 @@ ui::ScaleFactor GetDeviceScaleFactorForNativeView(views::Widget* widget) {
gfx::NativeView view = widget->GetNativeView();
gfx::Display display = gfx::Screen::GetScreenFor(view)->
GetDisplayNearestWindow(view);
- device_scale_factor = ui::GetScaleFactorFromScale(
- display.device_scale_factor());
+ device_scale = display.device_scale_factor();
}
#endif
- return device_scale_factor;
+ return device_scale;
}
namespace views {
@@ -66,9 +65,8 @@ void RunShellDrag(gfx::NativeView view,
gfx::Canvas* GetCanvasForDragImage(views::Widget* widget,
const gfx::Size& canvas_size) {
- ui::ScaleFactor device_scale_factor =
- GetDeviceScaleFactorForNativeView(widget);
- return new gfx::Canvas(canvas_size, device_scale_factor, false);
+ float device_scale = GetDeviceScaleForNativeView(widget);
+ return new gfx::Canvas(canvas_size, device_scale, false);
}
} // namespace views
diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
index c09dceb..f2582e7 100644
--- a/ui/views/win/hwnd_message_handler.cc
+++ b/ui/views/win/hwnd_message_handler.cc
@@ -1045,10 +1045,8 @@ 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, ui::SCALE_FACTOR_100P, false));
- }
+ if (use_layered_buffer_)
+ layered_window_contents_.reset(new gfx::Canvas(s, 1.0f, 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 e171da8..1fda351 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::GetScaleFactorFromScale(static_cast<float>(scale));
+ *scale_factor = ui::GetSupportedScaleFactor(static_cast<float>(scale));
return true;
}