Index: components/favicon_base/favicon_util.cc |
diff --git a/components/favicon_base/favicon_util.cc b/components/favicon_base/favicon_util.cc |
index 0a3f0a21be78a74a4625eb2daa258857c59c34d7..8252a29e7f51c9943c3ef078322f8a21bf5bda17 100644 |
--- a/components/favicon_base/favicon_util.cc |
+++ b/components/favicon_base/favicon_util.cc |
@@ -4,6 +4,8 @@ |
#include "components/favicon_base/favicon_util.h" |
+#include <cmath> |
+ |
#include "components/favicon_base/favicon_types.h" |
#include "components/favicon_base/select_favicon_frames.h" |
#include "skia/ext/image_operations.h" |
@@ -27,7 +29,7 @@ namespace { |
// or decoding the bitmap data. |
std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( |
const std::vector<favicon_base::FaviconRawBitmapResult>& png_data, |
- const std::vector<ui::ScaleFactor>& scale_factors, |
+ const std::vector<float>& favicon_scales, |
int favicon_size) { |
std::vector<gfx::ImagePNGRep> png_reps; |
if (png_data.empty()) |
@@ -51,11 +53,10 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( |
// Cache the scale factor for each pixel size as |scale_factors| may contain |
// any of GetFaviconScaleFactors() which may include scale factors not |
// supported by the platform. (ui::GetSupportedScaleFactor() cannot be used.) |
- std::map<int, ui::ScaleFactor> desired_pixel_sizes; |
- for (size_t i = 0; i < scale_factors.size(); ++i) { |
- int pixel_size = |
- floor(favicon_size * ui::GetScaleForScaleFactor(scale_factors[i])); |
- desired_pixel_sizes[pixel_size] = scale_factors[i]; |
+ std::map<int, float> desired_pixel_sizes; |
+ for (size_t i = 0; i < favicon_scales.size(); ++i) { |
+ int pixel_size = std::floor(favicon_size * favicon_scales[i]); |
pkotwicz
2014/06/18 15:46:33
We should ceil instead.
oshima
2014/06/18 17:17:19
Done.
|
+ desired_pixel_sizes[pixel_size] = favicon_scales[i]; |
} |
for (size_t i = 0; i < png_data.size(); ++i) { |
@@ -66,13 +67,12 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( |
if (pixel_size.width() != pixel_size.height()) |
continue; |
- std::map<int, ui::ScaleFactor>::iterator it = |
+ std::map<int, float>::iterator it = |
desired_pixel_sizes.find(pixel_size.width()); |
if (it == desired_pixel_sizes.end()) |
continue; |
- png_reps.push_back(gfx::ImagePNGRep( |
- png_data[i].bitmap_data, ui::GetScaleForScaleFactor(it->second))); |
+ png_reps.push_back(gfx::ImagePNGRep(png_data[i].bitmap_data, it->second)); |
} |
return png_reps; |
@@ -136,31 +136,18 @@ SkBitmap ResizeBitmapByDownsamplingIfPossible( |
} // namespace |
-std::vector<ui::ScaleFactor> GetFaviconScaleFactors() { |
- const float kScale1x = 1.0f; |
- std::vector<ui::ScaleFactor> favicon_scale_factors = |
+std::vector<float> GetFaviconScales() { |
+ const std::vector<ui::ScaleFactor>& resource_scale_factors = |
ui::GetSupportedScaleFactors(); |
- // The scale factors returned from ui::GetSupportedScaleFactors() are sorted. |
- // Insert the 1x scale factor such that GetFaviconScaleFactors() is sorted as |
- // well. |
- size_t insert_index = favicon_scale_factors.size(); |
- for (size_t i = 0; i < favicon_scale_factors.size(); ++i) { |
- float scale = ui::GetScaleForScaleFactor(favicon_scale_factors[i]); |
- if (scale == kScale1x) { |
- return favicon_scale_factors; |
- } else if (scale > kScale1x) { |
- insert_index = i; |
- break; |
- } |
+ std::vector<float> favicon_scales(1, 1.0f); |
+ for (size_t i = 0; i < resource_scale_factors.size(); ++i) { |
+ if (resource_scale_factors[i] != ui::SCALE_FACTOR_100P) |
+ favicon_scales.push_back( |
+ ui::GetScaleForScaleFactor(resource_scale_factors[i])); |
} |
- // TODO(ios): 100p should not be necessary on iOS retina devices. However |
- // the sync service only supports syncing 100p favicons. Until sync supports |
- // other scales 100p is needed in the list of scale factors to retrieve and |
- // store the favicons in both 100p for sync and 200p for display. cr/160503. |
- favicon_scale_factors.insert(favicon_scale_factors.begin() + insert_index, |
- ui::SCALE_FACTOR_100P); |
pkotwicz
2014/06/18 15:46:33
The TODO for ios should stay
oshima
2014/06/18 17:17:19
Done.
|
- return favicon_scale_factors; |
+ |
+ return favicon_scales; |
} |
void SetFaviconColorSpace(gfx::Image* image) { |
@@ -171,7 +158,7 @@ void SetFaviconColorSpace(gfx::Image* image) { |
gfx::Image SelectFaviconFramesFromPNGs( |
const std::vector<favicon_base::FaviconRawBitmapResult>& png_data, |
- const std::vector<ui::ScaleFactor>& scale_factors, |
+ const std::vector<float>& favicon_scales, |
int favicon_size) { |
// Create image reps for as many scale factors as possible without resizing |
// the bitmap data or decoding it. FaviconHandler stores already resized |
@@ -187,25 +174,26 @@ gfx::Image SelectFaviconFramesFromPNGs( |
// TODO(pkotwicz): Move the decoding off the UI thread. |
std::vector<gfx::ImagePNGRep> png_reps = |
SelectFaviconFramesFromPNGsWithoutResizing( |
- png_data, scale_factors, favicon_size); |
+ png_data, favicon_scales, favicon_size); |
// SelectFaviconFramesFromPNGsWithoutResizing() should have selected the |
// largest favicon if |favicon_size| == 0. |
if (favicon_size == 0) |
return gfx::Image(png_reps); |
- std::vector<ui::ScaleFactor> scale_factors_to_generate = scale_factors; |
+ std::vector<float> favicon_scales_to_generate = favicon_scales; |
for (size_t i = 0; i < png_reps.size(); ++i) { |
pkotwicz
2014/06/18 15:46:33
You can use std::find() here now?
oshima
2014/06/18 17:17:19
let me do it in separate CL. I'd like to keep this
|
- for (int j = static_cast<int>(scale_factors_to_generate.size()) - 1; j >= 0; |
+ for (int j = static_cast<int>(favicon_scales_to_generate.size()) - 1; |
+ j >= 0; |
--j) { |
- if (png_reps[i].scale == |
- ui::GetScaleForScaleFactor(scale_factors_to_generate[j])) { |
- scale_factors_to_generate.erase(scale_factors_to_generate.begin() + j); |
+ if (png_reps[i].scale == favicon_scales_to_generate[j]) { |
+ favicon_scales_to_generate.erase(favicon_scales_to_generate.begin() + |
+ j); |
} |
} |
} |
- if (scale_factors_to_generate.empty()) |
+ if (favicon_scales_to_generate.empty()) |
return gfx::Image(png_reps); |
std::vector<SkBitmap> bitmaps; |
@@ -225,8 +213,8 @@ gfx::Image SelectFaviconFramesFromPNGs( |
return gfx::Image(); |
gfx::ImageSkia resized_image_skia; |
- for (size_t i = 0; i < scale_factors_to_generate.size(); ++i) { |
- float scale = ui::GetScaleForScaleFactor(scale_factors_to_generate[i]); |
+ for (size_t i = 0; i < favicon_scales_to_generate.size(); ++i) { |
+ float scale = favicon_scales_to_generate[i]; |
int desired_size_in_pixel = ceil(favicon_size * scale); |
SkBitmap bitmap = |
ResizeBitmapByDownsamplingIfPossible(bitmaps, desired_size_in_pixel); |