Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: ui/base/resource/resource_bundle_win.cc

Issue 211493009: Ensure that extension resources are loaded with the correct scaling applied on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix try server errors Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/resource/resource_bundle_win.h" 5 #include "ui/base/resource/resource_bundle_win.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "skia/ext/image_operations.h" 10 #include "skia/ext/image_operations.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { 59 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
60 // Flipped image is not used on Windows. 60 // Flipped image is not used on Windows.
61 DCHECK_EQ(rtl, RTL_DISABLED); 61 DCHECK_EQ(rtl, RTL_DISABLED);
62 62
63 // Windows only uses SkBitmap for gfx::Image, so this is the same as 63 // Windows only uses SkBitmap for gfx::Image, so this is the same as
64 // GetImageNamed. 64 // GetImageNamed.
65 return GetImageNamed(resource_id); 65 return GetImageNamed(resource_id);
66 } 66 }
67 67
68 // static 68 // static
69 float ResourceBundle::PlatformGetImageScale(ui::ScaleFactor scale_factor) {
70 if (!gfx::IsHighDPIEnabled())
71 return ui::GetImageScale(scale_factor);
72 return gfx::win::GetDeviceScaleFactor();
73 }
74
75 // static
69 SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image, 76 SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image,
70 float loaded_image_scale, 77 float loaded_image_scale,
71 float desired_bitmap_scale) { 78 float desired_bitmap_scale) {
72 if (!gfx::IsHighDPIEnabled()) 79 if (!gfx::IsHighDPIEnabled())
73 return image; 80 return image;
74 81
75 // On Windows we can have multiple device scales like 1/1.25/1.5/2, etc. 82 // On Windows we can have multiple device scales like 1/1.25/1.5/2, etc.
76 // We only have 1x and 2x data packs. We need to scale the bitmaps 83 // We only have 1x and 2x data packs. We need to scale the bitmaps
77 // accordingly. 84 // accordingly.
78 if (loaded_image_scale == desired_bitmap_scale) 85 if (loaded_image_scale == desired_bitmap_scale)
79 return image; 86 return image;
80 87
81 SkBitmap scaled_image; 88 SkBitmap scaled_image;
82 gfx::Size unscaled_size(image.width(), image.height()); 89 gfx::Size unscaled_size(image.width(), image.height());
83 gfx::Size scaled_size = ToCeiledSize( 90 gfx::Size scaled_size = ToCeiledSize(
84 gfx::ScaleSize(unscaled_size, 91 gfx::ScaleSize(unscaled_size,
85 desired_bitmap_scale / loaded_image_scale)); 92 desired_bitmap_scale / loaded_image_scale));
86 scaled_image = skia::ImageOperations::Resize( 93 scaled_image = skia::ImageOperations::Resize(
87 image, 94 image,
88 skia::ImageOperations::RESIZE_LANCZOS3, 95 skia::ImageOperations::RESIZE_LANCZOS3,
89 scaled_size.width(), 96 scaled_size.width(),
90 scaled_size.height()); 97 scaled_size.height());
91 DCHECK_EQ(scaled_image.width(), scaled_size.width()); 98 DCHECK_EQ(scaled_image.width(), scaled_size.width());
92 DCHECK_EQ(scaled_image.height(), scaled_size.height()); 99 DCHECK_EQ(scaled_image.height(), scaled_size.height());
93 return scaled_image; 100 return scaled_image;
94 } 101 }
95 102
96 float ResourceBundle::PlatformGetImageScale() {
97 if (!gfx::IsHighDPIEnabled())
98 return ui::GetImageScale(GetMaxScaleFactor());
99 return gfx::win::GetDeviceScaleFactor();
100 }
101
102 void SetResourcesDataDLL(HINSTANCE handle) { 103 void SetResourcesDataDLL(HINSTANCE handle) {
103 resources_data_dll = handle; 104 resources_data_dll = handle;
104 } 105 }
105 106
106 HICON LoadThemeIconFromResourcesDataDLL(int icon_id) { 107 HICON LoadThemeIconFromResourcesDataDLL(int icon_id) {
107 return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id)); 108 return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id));
108 } 109 }
109 110
110 } // namespace ui; 111 } // namespace ui;
OLDNEW
« ui/base/resource/resource_bundle.h ('K') | « ui/base/resource/resource_bundle.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698