Commit 0738c574 authored by ananta@chromium.org's avatar ananta@chromium.org

Initial sets of fixes for themes to work well with HiDPI Windows. More changes...

Initial sets of fixes for themes to work well with HiDPI Windows. More changes coming in a separate CL.

oshima, Please review everything.
sky : For owners review.

1. Removed the PlatformScaleImage function from the ResourceBundle class and the corresponding
   code to scale images. With automatic scaling support in ImageSkia this is no longer needed.

2. The other change is in the NewTabButton class to use floating point scales everywhere instead
   of converting from scale factor to scale using different functions which causes problems.

BUG=362979
R=oshima,sky

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271075 0039d316-1c4b-4281-b951-d872f2087c98
parent a75441ce
...@@ -227,10 +227,10 @@ class NewTabButton : public views::ImageButton { ...@@ -227,10 +227,10 @@ class NewTabButton : public views::ImageButton {
private: private:
bool ShouldWindowContentsBeTransparent() const; bool ShouldWindowContentsBeTransparent() const;
gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state, gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state,
ui::ScaleFactor scale_factor) const; float scale) const;
gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state, gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state,
ui::ScaleFactor scale_factor) const; float scale) const;
gfx::ImageSkia GetImageForScale(ui::ScaleFactor scale_factor) const; gfx::ImageSkia GetImageForScale(float scale) const;
// Tab strip that contains this button. // Tab strip that contains this button.
TabStrip* tab_strip_; TabStrip* tab_strip_;
...@@ -307,8 +307,7 @@ void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) { ...@@ -307,8 +307,7 @@ void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) {
#endif #endif
void NewTabButton::OnPaint(gfx::Canvas* canvas) { void NewTabButton::OnPaint(gfx::Canvas* canvas) {
gfx::ImageSkia image = gfx::ImageSkia image = GetImageForScale(canvas->image_scale());
GetImageForScale(ui::GetSupportedScaleFactor(canvas->image_scale()));
canvas->DrawImageInt(image, 0, height() - image.height()); canvas->DrawImageInt(image, 0, height() - image.height());
} }
...@@ -326,7 +325,7 @@ bool NewTabButton::ShouldWindowContentsBeTransparent() const { ...@@ -326,7 +325,7 @@ bool NewTabButton::ShouldWindowContentsBeTransparent() const {
gfx::ImageSkia NewTabButton::GetBackgroundImage( gfx::ImageSkia NewTabButton::GetBackgroundImage(
views::CustomButton::ButtonState state, views::CustomButton::ButtonState state,
ui::ScaleFactor scale_factor) const { float scale) const {
int background_id = 0; int background_id = 0;
if (ShouldWindowContentsBeTransparent()) { if (ShouldWindowContentsBeTransparent()) {
background_id = IDR_THEME_TAB_BACKGROUND_V; background_id = IDR_THEME_TAB_BACKGROUND_V;
...@@ -355,10 +354,9 @@ gfx::ImageSkia NewTabButton::GetBackgroundImage( ...@@ -355,10 +354,9 @@ gfx::ImageSkia NewTabButton::GetBackgroundImage(
GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK); GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK);
int height = mask->height(); int height = mask->height();
int width = mask->width(); int width = mask->width();
float scale = ui::GetImageScale(scale_factor);
// The canvas and mask has to use the same scale factor. // The canvas and mask has to use the same scale factor.
if (!mask->HasRepresentation(scale)) if (!mask->HasRepresentation(scale))
scale_factor = ui::SCALE_FACTOR_100P; scale = ui::GetScaleForScaleFactor(ui::SCALE_FACTOR_100P);
gfx::Canvas canvas(gfx::Size(width, height), scale, false); gfx::Canvas canvas(gfx::Size(width, height), scale, false);
...@@ -400,16 +398,16 @@ gfx::ImageSkia NewTabButton::GetBackgroundImage( ...@@ -400,16 +398,16 @@ gfx::ImageSkia NewTabButton::GetBackgroundImage(
gfx::ImageSkia NewTabButton::GetImageForState( gfx::ImageSkia NewTabButton::GetImageForState(
views::CustomButton::ButtonState state, views::CustomButton::ButtonState state,
ui::ScaleFactor scale_factor) const { float scale) const {
const int overlay_id = state == views::CustomButton::STATE_PRESSED ? const int overlay_id = state == views::CustomButton::STATE_PRESSED ?
IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON; IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON;
gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id); gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id);
gfx::Canvas canvas( gfx::Canvas canvas(
gfx::Size(overlay->width(), overlay->height()), gfx::Size(overlay->width(), overlay->height()),
ui::GetImageScale(scale_factor), scale,
false); false);
canvas.DrawImageInt(GetBackgroundImage(state, scale_factor), 0, 0); canvas.DrawImageInt(GetBackgroundImage(state, scale), 0, 0);
// Draw the button border with a slight alpha. // Draw the button border with a slight alpha.
const int kGlassFrameOverlayAlpha = 178; const int kGlassFrameOverlayAlpha = 178;
...@@ -421,13 +419,12 @@ gfx::ImageSkia NewTabButton::GetImageForState( ...@@ -421,13 +419,12 @@ gfx::ImageSkia NewTabButton::GetImageForState(
return gfx::ImageSkia(canvas.ExtractImageRep()); return gfx::ImageSkia(canvas.ExtractImageRep());
} }
gfx::ImageSkia NewTabButton::GetImageForScale( gfx::ImageSkia NewTabButton::GetImageForScale(float scale) const {
ui::ScaleFactor scale_factor) const {
if (!hover_animation_->is_animating()) if (!hover_animation_->is_animating())
return GetImageForState(state(), scale_factor); return GetImageForState(state(), scale);
return gfx::ImageSkiaOperations::CreateBlendedImage( return gfx::ImageSkiaOperations::CreateBlendedImage(
GetImageForState(views::CustomButton::STATE_NORMAL, scale_factor), GetImageForState(views::CustomButton::STATE_NORMAL, scale),
GetImageForState(views::CustomButton::STATE_HOVERED, scale_factor), GetImageForState(views::CustomButton::STATE_HOVERED, scale),
hover_animation_->GetCurrentValue()); hover_animation_->GetCurrentValue());
} }
......
...@@ -105,15 +105,14 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { ...@@ -105,15 +105,14 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
ScaleFactor scale_factor = GetSupportedScaleFactor(scale); ScaleFactor scale_factor = GetSupportedScaleFactor(scale);
bool found = rb_->LoadBitmap(resource_id_, &scale_factor, bool found = rb_->LoadBitmap(resource_id_, &scale_factor,
&image, &fell_back_to_1x); &image, &fell_back_to_1x);
if (!found)
return gfx::ImageSkiaRep();
// If the resource is in the package with SCALE_FACTOR_NONE, it // If the resource is in the package with SCALE_FACTOR_NONE, it
// can be used in any scale factor. The image is maked as "unscaled" // can be used in any scale factor. The image is maked as "unscaled"
// so that the ImageSkia do not automatically scale. // so that the ImageSkia do not automatically scale.
bool unscaled = scale_factor == ui::SCALE_FACTOR_NONE; if (scale_factor == ui::SCALE_FACTOR_NONE)
if (unscaled) return gfx::ImageSkiaRep(image, 0.0f);
scale_factor = ui::SCALE_FACTOR_100P;
if (!found)
return gfx::ImageSkiaRep();
if (fell_back_to_1x) { if (fell_back_to_1x) {
// GRIT fell back to the 100% image, so rescale it to the correct size. // GRIT fell back to the 100% image, so rescale it to the correct size.
...@@ -122,19 +121,10 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { ...@@ -122,19 +121,10 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
skia::ImageOperations::RESIZE_LANCZOS3, skia::ImageOperations::RESIZE_LANCZOS3,
gfx::ToCeiledInt(image.width() * scale), gfx::ToCeiledInt(image.width() * scale),
gfx::ToCeiledInt(image.height() * scale)); gfx::ToCeiledInt(image.height() * scale));
} else if (!unscaled) {
SkBitmap scaled_image =
PlatformScaleImage(image,
ui::GetScaleForScaleFactor(scale_factor),
scale);
if (scaled_image.isNull())
scale = GetScaleForScaleFactor(scale_factor);
else
image = scaled_image;
} else { } else {
scale = GetScaleForScaleFactor(scale_factor); scale = GetScaleForScaleFactor(scale_factor);
} }
return gfx::ImageSkiaRep(image, unscaled ? 0.0f : scale); return gfx::ImageSkiaRep(image, scale);
} }
private: private:
...@@ -359,15 +349,13 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) { ...@@ -359,15 +349,13 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P; ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P;
#endif #endif
float scale = GetImageScale(scale_factor_to_load);
// TODO(oshima): Consider reading the image size from png IHDR chunk and // TODO(oshima): Consider reading the image size from png IHDR chunk and
// skip decoding here and remove #ifdef below. // skip decoding here and remove #ifdef below.
// ResourceBundle::GetSharedInstance() is destroyed after the // ResourceBundle::GetSharedInstance() is destroyed after the
// BrowserMainLoop has finished running. |image_skia| is guaranteed to be // BrowserMainLoop has finished running. |image_skia| is guaranteed to be
// destroyed before the resource bundle is destroyed. // destroyed before the resource bundle is destroyed.
gfx::ImageSkia image_skia(new ResourceBundleImageSource(this, resource_id), gfx::ImageSkia image_skia(new ResourceBundleImageSource(this, resource_id),
scale); GetScaleForScaleFactor(scale_factor_to_load));
if (image_skia.isNull()) { if (image_skia.isNull()) {
LOG(WARNING) << "Unable to load image with id " << resource_id; LOG(WARNING) << "Unable to load image with id " << resource_id;
NOTREACHED(); // Want to assert in debug mode. NOTREACHED(); // Want to assert in debug mode.
...@@ -813,13 +801,4 @@ bool ResourceBundle::DecodePNG(const unsigned char* buf, ...@@ -813,13 +801,4 @@ bool ResourceBundle::DecodePNG(const unsigned char* buf,
return gfx::PNGCodec::Decode(buf, size, bitmap); return gfx::PNGCodec::Decode(buf, size, bitmap);
} }
#if !defined(OS_WIN)
// static
SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image,
float loaded_image_scale,
float desired_scale) {
return SkBitmap();
}
#endif
} // namespace ui } // namespace ui
...@@ -353,16 +353,6 @@ class UI_BASE_EXPORT ResourceBundle { ...@@ -353,16 +353,6 @@ class UI_BASE_EXPORT ResourceBundle {
const base::FilePath& GetOverriddenPakPath(); const base::FilePath& GetOverriddenPakPath();
// Platform specific image scaling is done here. Currently only implemented
// for Windows.
// |image| is the bitmap to be scaled.
// |loaded_image_scale| is the current scale of the bitmap.
// |desired_scale| is the desired scale of the bitmap.
// Returns the scaled bitmap or null bitmap if scaling is disabled.
static SkBitmap PlatformScaleImage(const SkBitmap& image,
float loaded_image_scale,
float desired_scale);
// This pointer is guaranteed to outlive the ResourceBundle instance and may // This pointer is guaranteed to outlive the ResourceBundle instance and may
// be NULL. // be NULL.
Delegate* delegate_; Delegate* delegate_;
......
...@@ -65,34 +65,6 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { ...@@ -65,34 +65,6 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
return GetImageNamed(resource_id); return GetImageNamed(resource_id);
} }
// static
SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image,
float loaded_image_scale,
float desired_bitmap_scale) {
if (!gfx::IsHighDPIEnabled())
return SkBitmap();
// On Windows we can have multiple device scales like 1/1.25/1.5/2, etc.
// We only have 1x and 2x data packs. We need to scale the bitmaps
// accordingly.
if (loaded_image_scale == desired_bitmap_scale)
return image;
SkBitmap scaled_image;
gfx::Size unscaled_size(image.width(), image.height());
gfx::Size scaled_size = ToCeiledSize(
gfx::ScaleSize(unscaled_size,
desired_bitmap_scale / loaded_image_scale));
scaled_image = skia::ImageOperations::Resize(
image,
skia::ImageOperations::RESIZE_LANCZOS3,
scaled_size.width(),
scaled_size.height());
DCHECK_EQ(scaled_image.width(), scaled_size.width());
DCHECK_EQ(scaled_image.height(), scaled_size.height());
return scaled_image;
}
void SetResourcesDataDLL(HINSTANCE handle) { void SetResourcesDataDLL(HINSTANCE handle) {
resources_data_dll = handle; resources_data_dll = handle;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment