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 {
private:
bool ShouldWindowContentsBeTransparent() const;
gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state,
ui::ScaleFactor scale_factor) const;
float scale) const;
gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state,
ui::ScaleFactor scale_factor) const;
gfx::ImageSkia GetImageForScale(ui::ScaleFactor scale_factor) const;
float scale) const;
gfx::ImageSkia GetImageForScale(float scale) const;
// Tab strip that contains this button.
TabStrip* tab_strip_;
......@@ -307,8 +307,7 @@ void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) {
#endif
void NewTabButton::OnPaint(gfx::Canvas* canvas) {
gfx::ImageSkia image =
GetImageForScale(ui::GetSupportedScaleFactor(canvas->image_scale()));
gfx::ImageSkia image = GetImageForScale(canvas->image_scale());
canvas->DrawImageInt(image, 0, height() - image.height());
}
......@@ -326,7 +325,7 @@ bool NewTabButton::ShouldWindowContentsBeTransparent() const {
gfx::ImageSkia NewTabButton::GetBackgroundImage(
views::CustomButton::ButtonState state,
ui::ScaleFactor scale_factor) const {
float scale) const {
int background_id = 0;
if (ShouldWindowContentsBeTransparent()) {
background_id = IDR_THEME_TAB_BACKGROUND_V;
......@@ -355,10 +354,9 @@ 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))
scale_factor = ui::SCALE_FACTOR_100P;
scale = ui::GetScaleForScaleFactor(ui::SCALE_FACTOR_100P);
gfx::Canvas canvas(gfx::Size(width, height), scale, false);
......@@ -400,16 +398,16 @@ gfx::ImageSkia NewTabButton::GetBackgroundImage(
gfx::ImageSkia NewTabButton::GetImageForState(
views::CustomButton::ButtonState state,
ui::ScaleFactor scale_factor) const {
float scale) const {
const int overlay_id = state == views::CustomButton::STATE_PRESSED ?
IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON;
gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id);
gfx::Canvas canvas(
gfx::Size(overlay->width(), overlay->height()),
ui::GetImageScale(scale_factor),
scale,
false);
canvas.DrawImageInt(GetBackgroundImage(state, scale_factor), 0, 0);
canvas.DrawImageInt(GetBackgroundImage(state, scale), 0, 0);
// Draw the button border with a slight alpha.
const int kGlassFrameOverlayAlpha = 178;
......@@ -421,13 +419,12 @@ gfx::ImageSkia NewTabButton::GetImageForState(
return gfx::ImageSkia(canvas.ExtractImageRep());
}
gfx::ImageSkia NewTabButton::GetImageForScale(
ui::ScaleFactor scale_factor) const {
gfx::ImageSkia NewTabButton::GetImageForScale(float scale) const {
if (!hover_animation_->is_animating())
return GetImageForState(state(), scale_factor);
return GetImageForState(state(), scale);
return gfx::ImageSkiaOperations::CreateBlendedImage(
GetImageForState(views::CustomButton::STATE_NORMAL, scale_factor),
GetImageForState(views::CustomButton::STATE_HOVERED, scale_factor),
GetImageForState(views::CustomButton::STATE_NORMAL, scale),
GetImageForState(views::CustomButton::STATE_HOVERED, scale),
hover_animation_->GetCurrentValue());
}
......
......@@ -105,15 +105,14 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
ScaleFactor scale_factor = GetSupportedScaleFactor(scale);
bool found = rb_->LoadBitmap(resource_id_, &scale_factor,
&image, &fell_back_to_1x);
if (!found)
return gfx::ImageSkiaRep();
// 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"
// so that the ImageSkia do not automatically scale.
bool unscaled = scale_factor == ui::SCALE_FACTOR_NONE;
if (unscaled)
scale_factor = ui::SCALE_FACTOR_100P;
if (!found)
return gfx::ImageSkiaRep();
if (scale_factor == ui::SCALE_FACTOR_NONE)
return gfx::ImageSkiaRep(image, 0.0f);
if (fell_back_to_1x) {
// GRIT fell back to the 100% image, so rescale it to the correct size.
......@@ -122,19 +121,10 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
skia::ImageOperations::RESIZE_LANCZOS3,
gfx::ToCeiledInt(image.width() * 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 {
scale = GetScaleForScaleFactor(scale_factor);
}
return gfx::ImageSkiaRep(image, unscaled ? 0.0f : scale);
return gfx::ImageSkiaRep(image, scale);
}
private:
......@@ -359,15 +349,13 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
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.
gfx::ImageSkia image_skia(new ResourceBundleImageSource(this, resource_id),
scale);
GetScaleForScaleFactor(scale_factor_to_load));
if (image_skia.isNull()) {
LOG(WARNING) << "Unable to load image with id " << resource_id;
NOTREACHED(); // Want to assert in debug mode.
......@@ -813,13 +801,4 @@ bool ResourceBundle::DecodePNG(const unsigned char* buf,
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
......@@ -353,16 +353,6 @@ class UI_BASE_EXPORT ResourceBundle {
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
// be NULL.
Delegate* delegate_;
......
......@@ -65,34 +65,6 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
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) {
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