Commit b82b38f7 authored by ananta@chromium.org's avatar ananta@chromium.org

Ensure that extension resources are loaded with the correct scaling applied on Windows.

We were loading the icons with the scaling factor based on the loaded resource pak, which works on
all platforms except on Windows with high dpi enabled with dpi settings other than 100% or 200%.

Fix is to pass in the correct scaling factor when loading these resources like icons etc which ensures that
they get resized correctly.

I made the PlatformGetImageScale function in the ResourceBundle class static and passed in the loaded scale factor
to it. This function returns the correct scale to be used as before. We call this function from the extensions resource
loading code.

There may be other places which need similar fixes. Will address those in upcoming CL's

BUG=351170, 354706
R=sky@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260254 0039d316-1c4b-4281-b951-d872f2087c98
parent 42e3031c
...@@ -57,7 +57,7 @@ namespace { ...@@ -57,7 +57,7 @@ namespace {
// Convenience macro: Short-circuit a pass for platforms where setting up // Convenience macro: Short-circuit a pass for platforms where setting up
// high-DPI fails. // high-DPI fails.
#define PASS_TEST_IF_SCALE_FACTOR_NOT_SUPPORTED(factor) \ #define PASS_TEST_IF_SCALE_FACTOR_NOT_SUPPORTED(factor) \
if (ui::GetImageScale( \ if (ui::GetScaleForScaleFactor( \
GetScaleFactorForView(GetRenderWidgetHostViewPort())) != factor) { \ GetScaleFactorForView(GetRenderWidgetHostViewPort())) != factor) { \
LOG(WARNING) << "Blindly passing this test: failed to set up " \ LOG(WARNING) << "Blindly passing this test: failed to set up " \
"scale factor: " << factor; \ "scale factor: " << factor; \
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#if defined(OS_WIN) #if defined(OS_WIN)
#include "base/win/metro.h" #include "base/win/metro.h"
#include "ui/gfx/win/dpi.h"
#include <Windows.h> #include <Windows.h>
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
...@@ -90,7 +91,7 @@ void SetSupportedScaleFactors( ...@@ -90,7 +91,7 @@ void SetSupportedScaleFactors(
for (std::vector<ScaleFactor>::const_iterator it = for (std::vector<ScaleFactor>::const_iterator it =
g_supported_scale_factors->begin(); g_supported_scale_factors->begin();
it != g_supported_scale_factors->end(); ++it) { it != g_supported_scale_factors->end(); ++it) {
scales.push_back(GetImageScale(*it)); scales.push_back(kScaleFactorScales[*it]);
} }
gfx::ImageSkia::SetSupportedScales(scales); gfx::ImageSkia::SetSupportedScales(scales);
} }
...@@ -117,7 +118,11 @@ ScaleFactor GetSupportedScaleFactor(float scale) { ...@@ -117,7 +118,11 @@ ScaleFactor GetSupportedScaleFactor(float scale) {
} }
float GetImageScale(ScaleFactor scale_factor) { float GetImageScale(ScaleFactor scale_factor) {
return kScaleFactorScales[scale_factor]; #if defined(OS_WIN)
if (gfx::IsHighDPIEnabled())
return gfx::win::GetDeviceScaleFactor();
#endif
return GetScaleForScaleFactor(scale_factor);
} }
bool IsScaleFactorSupported(ScaleFactor scale_factor) { bool IsScaleFactorSupported(ScaleFactor scale_factor) {
...@@ -144,6 +149,10 @@ ScaleFactor FindClosestScaleFactorUnsafe(float scale) { ...@@ -144,6 +149,10 @@ ScaleFactor FindClosestScaleFactorUnsafe(float scale) {
return closest_match; return closest_match;
} }
float GetScaleForScaleFactor(ScaleFactor scale_factor) {
return kScaleFactorScales[scale_factor];
}
namespace test { namespace test {
ScopedSetSupportedScaleFactors::ScopedSetSupportedScaleFactors( ScopedSetSupportedScaleFactors::ScopedSetSupportedScaleFactors(
......
...@@ -57,7 +57,8 @@ UI_BASE_EXPORT void SetSupportedScaleFactors( ...@@ -57,7 +57,8 @@ UI_BASE_EXPORT void SetSupportedScaleFactors(
// platform, in ascending order. // platform, in ascending order.
UI_BASE_EXPORT const std::vector<ScaleFactor>& GetSupportedScaleFactors(); UI_BASE_EXPORT const std::vector<ScaleFactor>& GetSupportedScaleFactors();
// Returns the float scale value for |scale_factor|. // Returns the actual image scale to be used for the scale factor passed in.
// On Windows high dpi, this returns the dpi scale for the display.
UI_BASE_EXPORT float GetImageScale(ScaleFactor scale_factor); UI_BASE_EXPORT float GetImageScale(ScaleFactor scale_factor);
// Returns the supported ScaleFactor which most closely matches |scale|. // Returns the supported ScaleFactor which most closely matches |scale|.
...@@ -77,6 +78,9 @@ UI_BASE_EXPORT bool IsScaleFactorSupported(ScaleFactor scale_factor); ...@@ -77,6 +78,9 @@ UI_BASE_EXPORT bool IsScaleFactorSupported(ScaleFactor scale_factor);
// Finding the closest match is inefficient and shouldn't be done frequently. // Finding the closest match is inefficient and shouldn't be done frequently.
UI_BASE_EXPORT ScaleFactor FindClosestScaleFactorUnsafe(float scale); UI_BASE_EXPORT ScaleFactor FindClosestScaleFactorUnsafe(float scale);
// Returns the image scale for the scale factor passed in.
UI_BASE_EXPORT float GetScaleForScaleFactor(ScaleFactor scale_factor);
namespace test { namespace test {
// Class which changes the value of GetSupportedScaleFactors() to // Class which changes the value of GetSupportedScaleFactors() to
// |new_scale_factors| for the duration of its lifetime. // |new_scale_factors| for the duration of its lifetime.
......
...@@ -109,8 +109,6 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { ...@@ -109,8 +109,6 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
if (!found) if (!found)
return gfx::ImageSkiaRep(); return gfx::ImageSkiaRep();
float loaded_image_scale = ui::GetImageScale(scale_factor);
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.
image = skia::ImageOperations::Resize( image = skia::ImageOperations::Resize(
...@@ -132,7 +130,9 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { ...@@ -132,7 +130,9 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
image = SkBitmapOperations::CreateBlendedBitmap(image, mask, 0.2); image = SkBitmapOperations::CreateBlendedBitmap(image, mask, 0.2);
} }
} else { } else {
image = PlatformScaleImage(image, loaded_image_scale, scale); image = PlatformScaleImage(image,
ui::GetScaleForScaleFactor(scale_factor),
scale);
} }
return gfx::ImageSkiaRep(image, scale); return gfx::ImageSkiaRep(image, scale);
} }
...@@ -353,7 +353,13 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) { ...@@ -353,7 +353,13 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
DCHECK(!data_packs_.empty()) << DCHECK(!data_packs_.empty()) <<
"Missing call to SetResourcesDataDLL?"; "Missing call to SetResourcesDataDLL?";
float scale = PlatformGetImageScale(); #if defined(OS_CHROMEOS) || defined(OS_WIN)
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 // 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.
...@@ -823,15 +829,6 @@ SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image, ...@@ -823,15 +829,6 @@ SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image,
float desired_scale) { float desired_scale) {
return image; return image;
} }
float ResourceBundle::PlatformGetImageScale() {
#if defined(OS_CHROMEOS)
ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor();
#else
ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P;
#endif
return GetImageScale(scale_factor_to_load);
}
#endif #endif
} // namespace ui } // namespace ui
...@@ -363,11 +363,6 @@ class UI_BASE_EXPORT ResourceBundle { ...@@ -363,11 +363,6 @@ class UI_BASE_EXPORT ResourceBundle {
float loaded_image_scale, float loaded_image_scale,
float desired_scale); float desired_scale);
// Returns the scale to be used for loading an image. In all platforms except
// windows this is based on the scale factors of the loaded resource packs.
// On Windows this returns the device scale factor if high dpi is enabled.
float PlatformGetImageScale();
// 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_;
......
...@@ -93,12 +93,6 @@ SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image, ...@@ -93,12 +93,6 @@ SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image,
return scaled_image; return scaled_image;
} }
float ResourceBundle::PlatformGetImageScale() {
if (!gfx::IsHighDPIEnabled())
return ui::GetImageScale(GetMaxScaleFactor());
return gfx::win::GetDeviceScaleFactor();
}
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