#include <vector>
+#include "base/big_endian.h"
#include "base/command_line.h"
#include "base/file_util.h"
+#include "base/files/file.h"
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram.h"
#include "base/synchronization/lock.h"
#include "build/build_config.h"
#include "grit/app_locale_settings.h"
-#include "net/base/big_endian.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/safe_integer_conversions.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/size_conversions.h"
-#include "ui/gfx/skbitmap_operations.h"
#if defined(OS_CHROMEOS)
#include "ui/base/l10n/l10n_util.h"
ScaleFactor scale_factor = GetSupportedScaleFactor(scale);
bool found = rb_->LoadBitmap(resource_id_, &scale_factor,
&image, &fell_back_to_1x);
- // Force to a supported scale.
- scale = ui::GetImageScale(scale_factor);
if (!found)
return gfx::ImageSkiaRep();
skia::ImageOperations::RESIZE_LANCZOS3,
gfx::ToCeiledInt(image.width() * scale),
gfx::ToCeiledInt(image.height() * scale));
- // If --highlight-missing-scaled-resources is specified, log the resource
- // id and blend the created resource with red.
- if (ShouldHighlightMissingScaledResources()) {
- LOG(ERROR) << "Missing " << scale << "x scaled resource. id="
- << resource_id_;
-
- SkBitmap mask;
- mask.setConfig(SkBitmap::kARGB_8888_Config,
- image.width(), image.height());
- mask.allocPixels();
- mask.eraseColor(SK_ColorRED);
- image = SkBitmapOperations::CreateBlendedBitmap(image, mask, 0.2);
- }
+ } else {
+ image = PlatformScaleImage(image,
+ ui::GetScaleForScaleFactor(scale_factor),
+ scale);
}
-
return gfx::ImageSkiaRep(image, scale);
}
DCHECK(!data_packs_.empty()) <<
"Missing call to SetResourcesDataDLL?";
-#if defined(OS_CHROMEOS)
- ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor();
+#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;
+ 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
}
for (size_t i = 0; i < data_packs_.size(); i++) {
if ((data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_100P ||
+ data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_200P ||
data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE) &&
data_packs_[i]->GetStringPiece(resource_id, &data))
return data;
}
ScaleFactor ResourceBundle::GetMaxScaleFactor() const {
-#if defined(OS_CHROMEOS)
+#if defined(OS_CHROMEOS) || defined(OS_WIN)
return max_scale_factor_;
#else
return GetSupportedScaleFactors().back();
DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
g_shared_instance_ = new ResourceBundle(delegate);
static std::vector<ScaleFactor> supported_scale_factors;
-#if !defined(OS_IOS)
+#if !defined(OS_IOS) && !defined(OS_WIN)
// On platforms other than iOS, 100P is always a supported scale factor.
+ // For Windows we have a separate case in this function.
supported_scale_factors.push_back(SCALE_FACTOR_100P);
#endif
#if defined(OS_ANDROID)
supported_scale_factors.push_back(SCALE_FACTOR_200P);
#elif defined(OS_LINUX) && defined(ENABLE_HIDPI)
supported_scale_factors.push_back(SCALE_FACTOR_200P);
+#elif defined(OS_WIN)
+ bool default_to_100P = true;
+ if (gfx::IsHighDPIEnabled()) {
+ // On Windows if the dpi scale is greater than 1.25 on high dpi machines
+ // downscaling from 200 percent looks better than scaling up from 100
+ // percent.
+ if (gfx::GetDPIScale() > 1.25) {
+ supported_scale_factors.push_back(SCALE_FACTOR_200P);
+ default_to_100P = false;
+ }
+ }
+ if (default_to_100P)
+ supported_scale_factors.push_back(SCALE_FACTOR_100P);
#endif
ui::SetSupportedScaleFactors(supported_scale_factors);
#if defined(OS_WIN)
void ResourceBundle::AddDataPack(DataPack* data_pack) {
data_packs_.push_back(data_pack);
- if (GetImageScale(data_pack->GetScaleFactor()) >
- GetImageScale(max_scale_factor_))
+ if (GetScaleForScaleFactor(data_pack->GetScaleFactor()) >
+ GetScaleForScaleFactor(max_scale_factor_))
max_scale_factor_ = data_pack->GetScaleFactor();
}
}
// static
-bool ResourceBundle::ShouldHighlightMissingScaledResources() {
- return CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kHighlightMissingScaledResources);
-}
-
-// static
bool ResourceBundle::PNGContainsFallbackMarker(const unsigned char* buf,
- size_t size) {
+ size_t size) {
if (size < arraysize(kPngMagic) ||
memcmp(buf, kPngMagic, arraysize(kPngMagic)) != 0) {
// Data invalid or a JPEG.
if (size - pos < kPngChunkMetadataSize)
break;
uint32 length = 0;
- net::ReadBigEndian(reinterpret_cast<const char*>(buf + pos), &length);
+ base::ReadBigEndian(reinterpret_cast<const char*>(buf + pos), &length);
if (size - pos - kPngChunkMetadataSize < length)
break;
if (length == 0 && memcmp(buf + pos + sizeof(uint32), kPngScaleChunkType,
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 image;
+}
+#endif
+
} // namespace ui