Skip to content

Commit

Permalink
Remove dependency on ui::ScaleFactor from ui/gfx
Browse files Browse the repository at this point in the history
As part of the work to removed dependencies on ui/base from ui/gfx I have
changed the public api to Canvas, ImageSkia, ImageSkiaRep and ImagePNGRep
to take float scale values instead of ui::ScaleFactor.

The notion of supported scale factors has been broken into 2 parts.
ui::SetSupportedScaleFactors remains and calls the
new ImageSkia::SetSupportedScales().

The initialization of the supported scale factors has been moved from layout.h
into ResourceBundle, and is done explicitly in tests that don't use
ResourceBundle.

BUG=103304
R=ben@chromium.org, oshima@chromium.org, sky@chromium.org

Review URL: https://codereview.chromium.org/24175004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224473 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
davemoore@chromium.org committed Sep 20, 2013
1 parent 62678a6 commit 86c71f7
Show file tree
Hide file tree
Showing 159 changed files with 1,010 additions and 1,040 deletions.
2 changes: 1 addition & 1 deletion apps/shell_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions ash/desktop_background/wallpaper_resizer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
5 changes: 1 addition & 4 deletions ash/display/mirror_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ash/drag_drop/drag_drop_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 2 additions & 6 deletions ash/drag_drop/drag_image_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 4 additions & 0 deletions ash/launcher/launcher_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "ash/ash_export.h"
#include "ash/launcher/launcher_types.h"

namespace aura {
class Window;
}

namespace ash {
class Launcher;

Expand Down
2 changes: 2 additions & 0 deletions ash/launcher/launcher_item_delegate_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "ash/launcher/launcher_item_delegate_manager.h"

#include "base/logging.h"

namespace ash {

LauncherItemDelegateManager::LauncherItemDelegateManager() {
Expand Down
3 changes: 1 addition & 2 deletions ash/shell/app_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions ash/shell/window_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 6 additions & 8 deletions ash/system/chromeos/network/network_icon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ash/wm/frame_painter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/android/provider/chrome_browser_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)),
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/extensions/wallpaper_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/extensions/wallpaper_private_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/login/helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/login/wallpaper_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -281,21 +276,21 @@ 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);
action_icon_last_id = action_icon_current_id;

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);
Expand Down
Loading

0 comments on commit 86c71f7

Please sign in to comment.