This source file includes following definitions.
- GetCurrentResourceDLL
- GetResourcesPakFilePath
- LoadCommonResources
- GetNativeImageNamed
- PlatformScaleImage
- SetResourcesDataDLL
- LoadThemeIconFromResourcesDataDLL
#include "ui/base/resource/resource_bundle_win.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "skia/ext/image_operations.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/resource/resource_data_dll_win.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_source.h"
#include "ui/gfx/win/dpi.h"
namespace ui {
namespace {
HINSTANCE resources_data_dll;
HINSTANCE GetCurrentResourceDLL() {
if (resources_data_dll)
return resources_data_dll;
return GetModuleHandle(NULL);
}
base::FilePath GetResourcesPakFilePath(const std::string& pak_name) {
base::FilePath path;
if (PathService::Get(base::DIR_MODULE, &path))
return path.AppendASCII(pak_name.c_str());
return base::FilePath(base::ASCIIToUTF16(pak_name));
}
}
void ResourceBundle::LoadCommonResources() {
data_packs_.push_back(new ResourceDataDLL(GetCurrentResourceDLL()));
if (IsScaleFactorSupported(SCALE_FACTOR_100P)) {
AddDataPackFromPath(
GetResourcesPakFilePath("chrome_100_percent.pak"),
SCALE_FACTOR_100P);
}
if (IsScaleFactorSupported(SCALE_FACTOR_200P)) {
DCHECK(gfx::IsHighDPIEnabled());
AddDataPackFromPath(
GetResourcesPakFilePath("chrome_200_percent.pak"),
SCALE_FACTOR_200P);
}
}
gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
DCHECK_EQ(rtl, RTL_DISABLED);
return GetImageNamed(resource_id);
}
SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image,
float loaded_image_scale,
float desired_bitmap_scale) {
if (!gfx::IsHighDPIEnabled())
return image;
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;
}
HICON LoadThemeIconFromResourcesDataDLL(int icon_id) {
return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id));
}
}