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

Side by Side Diff: chrome/browser/favicon/favicon_util.cc

Issue 24175004: Remove dependency on ui::ScaleFactor from ui/gfx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename methods and vars to make image_scale more clear Created 7 years, 3 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 "chrome/browser/favicon/favicon_util.h" 5 #include "chrome/browser/favicon/favicon_util.h"
6 6
7 #include "chrome/browser/history/select_favicon_frames.h" 7 #include "chrome/browser/history/select_favicon_frames.h"
8 #include "chrome/common/favicon/favicon_types.h" 8 #include "chrome/common/favicon/favicon_types.h"
9 #include "skia/ext/image_operations.h" 9 #include "skia/ext/image_operations.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 24 matching lines...) Expand all
35 if (favicon_size == 0) { 35 if (favicon_size == 0) {
36 int maximum_area = 0; 36 int maximum_area = 0;
37 scoped_refptr<base::RefCountedMemory> best_candidate; 37 scoped_refptr<base::RefCountedMemory> best_candidate;
38 for (size_t i = 0; i < png_data.size(); ++i) { 38 for (size_t i = 0; i < png_data.size(); ++i) {
39 int area = png_data[i].pixel_size.GetArea(); 39 int area = png_data[i].pixel_size.GetArea();
40 if (area > maximum_area) { 40 if (area > maximum_area) {
41 maximum_area = area; 41 maximum_area = area;
42 best_candidate = png_data[i].bitmap_data; 42 best_candidate = png_data[i].bitmap_data;
43 } 43 }
44 } 44 }
45 png_reps.push_back(gfx::ImagePNGRep(best_candidate, 45 png_reps.push_back(gfx::ImagePNGRep(best_candidate, 1.0f));
46 ui::SCALE_FACTOR_100P));
47 return png_reps; 46 return png_reps;
48 } 47 }
49 48
50 // Cache the scale factor for each pixel size as |scale_factors| may contain 49 // Cache the scale factor for each pixel size as |scale_factors| may contain
51 // any of GetFaviconScaleFactors() which may include scale factors not 50 // any of GetFaviconScaleFactors() which may include scale factors not
52 // supported by the platform. (ui::GetScaleFactorFromScale() cannot be used.) 51 // supported by the platform. (ui::GetSupportedScaleFactor() cannot be used.)
53 std::map<int, ui::ScaleFactor> desired_pixel_sizes; 52 std::map<int, ui::ScaleFactor> desired_pixel_sizes;
54 for (size_t i = 0; i < scale_factors.size(); ++i) { 53 for (size_t i = 0; i < scale_factors.size(); ++i) {
55 int pixel_size = floor(favicon_size * 54 int pixel_size = floor(favicon_size *
56 ui::GetScaleFactorScale(scale_factors[i])); 55 ui::GetImageScale(scale_factors[i]));
57 desired_pixel_sizes[pixel_size] = scale_factors[i]; 56 desired_pixel_sizes[pixel_size] = scale_factors[i];
58 } 57 }
59 58
60 for (size_t i = 0; i < png_data.size(); ++i) { 59 for (size_t i = 0; i < png_data.size(); ++i) {
61 if (!png_data[i].is_valid()) 60 if (!png_data[i].is_valid())
62 continue; 61 continue;
63 62
64 const gfx::Size& pixel_size = png_data[i].pixel_size; 63 const gfx::Size& pixel_size = png_data[i].pixel_size;
65 if (pixel_size.width() != pixel_size.height()) 64 if (pixel_size.width() != pixel_size.height())
66 continue; 65 continue;
67 66
68 std::map<int, ui::ScaleFactor>::iterator it = desired_pixel_sizes.find( 67 std::map<int, ui::ScaleFactor>::iterator it = desired_pixel_sizes.find(
69 pixel_size.width()); 68 pixel_size.width());
70 if (it == desired_pixel_sizes.end()) 69 if (it == desired_pixel_sizes.end())
71 continue; 70 continue;
72 71
73 png_reps.push_back(gfx::ImagePNGRep(png_data[i].bitmap_data, it->second)); 72 png_reps.push_back(
73 gfx::ImagePNGRep(png_data[i].bitmap_data,
74 ui::GetImageScale(it->second)));
74 } 75 }
75 76
76 return png_reps; 77 return png_reps;
77 } 78 }
78 79
79 } // namespace 80 } // namespace
80 81
81 // static 82 // static
82 std::vector<ui::ScaleFactor> FaviconUtil::GetFaviconScaleFactors() { 83 std::vector<ui::ScaleFactor> FaviconUtil::GetFaviconScaleFactors() {
83 const float kScale1x = ui::GetScaleFactorScale(ui::SCALE_FACTOR_100P); 84 const float kScale1x = ui::GetImageScale(ui::SCALE_FACTOR_100P);
84 std::vector<ui::ScaleFactor> favicon_scale_factors = 85 std::vector<ui::ScaleFactor> favicon_scale_factors =
85 ui::GetSupportedScaleFactors(); 86 ui::GetSupportedScaleFactors();
86 87
87 // The scale factors returned from ui::GetSupportedScaleFactors() are sorted. 88 // The scale factors returned from ui::GetSupportedScaleFactors() are sorted.
88 // Insert the 1x scale factor such that GetFaviconScaleFactors() is sorted as 89 // Insert the 1x scale factor such that GetFaviconScaleFactors() is sorted as
89 // well. 90 // well.
90 size_t insert_index = favicon_scale_factors.size(); 91 size_t insert_index = favicon_scale_factors.size();
91 for (size_t i = 0; i < favicon_scale_factors.size(); ++i) { 92 for (size_t i = 0; i < favicon_scale_factors.size(); ++i) {
92 float scale = ui::GetScaleFactorScale(favicon_scale_factors[i]); 93 float scale = ui::GetImageScale(favicon_scale_factors[i]);
93 if (scale == kScale1x) { 94 if (scale == kScale1x) {
94 return favicon_scale_factors; 95 return favicon_scale_factors;
95 } else if (scale > kScale1x) { 96 } else if (scale > kScale1x) {
96 insert_index = i; 97 insert_index = i;
97 break; 98 break;
98 } 99 }
99 } 100 }
100 // TODO(ios): 100p should not be necessary on iOS retina devices. However 101 // TODO(ios): 100p should not be necessary on iOS retina devices. However
101 // the sync service only supports syncing 100p favicons. Until sync supports 102 // the sync service only supports syncing 100p favicons. Until sync supports
102 // other scales 100p is needed in the list of scale factors to retrieve and 103 // other scales 100p is needed in the list of scale factors to retrieve and
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // SelectFaviconFramesFromPNGsWithoutResizing() should have selected the 138 // SelectFaviconFramesFromPNGsWithoutResizing() should have selected the
138 // largest favicon if |favicon_size| == 0. 139 // largest favicon if |favicon_size| == 0.
139 if (favicon_size == 0) 140 if (favicon_size == 0)
140 return gfx::Image(png_reps); 141 return gfx::Image(png_reps);
141 142
142 std::vector<ui::ScaleFactor> scale_factors_to_generate = scale_factors; 143 std::vector<ui::ScaleFactor> scale_factors_to_generate = scale_factors;
143 for (size_t i = 0; i < png_reps.size(); ++i) { 144 for (size_t i = 0; i < png_reps.size(); ++i) {
144 std::vector<ui::ScaleFactor>::iterator it = std::find( 145 std::vector<ui::ScaleFactor>::iterator it = std::find(
145 scale_factors_to_generate.begin(), 146 scale_factors_to_generate.begin(),
146 scale_factors_to_generate.end(), 147 scale_factors_to_generate.end(),
147 png_reps[i].scale_factor); 148 ui::GetSupportedScaleFactor(png_reps[i].scale));
148 CHECK(it != scale_factors_to_generate.end()); 149 CHECK(it != scale_factors_to_generate.end());
149 scale_factors_to_generate.erase(it); 150 scale_factors_to_generate.erase(it);
150 } 151 }
151 152
152 if (scale_factors_to_generate.empty()) 153 if (scale_factors_to_generate.empty())
153 return gfx::Image(png_reps); 154 return gfx::Image(png_reps);
154 155
155 std::vector<SkBitmap> bitmaps; 156 std::vector<SkBitmap> bitmaps;
156 for (size_t i = 0; i < png_data.size(); ++i) { 157 for (size_t i = 0; i < png_data.size(); ++i) {
157 if (!png_data[i].is_valid()) 158 if (!png_data[i].is_valid())
(...skipping 16 matching lines...) Expand all
174 if (png_reps.empty()) 175 if (png_reps.empty())
175 return gfx::Image(resized_image_skia); 176 return gfx::Image(resized_image_skia);
176 177
177 std::vector<gfx::ImageSkiaRep> resized_image_skia_reps = 178 std::vector<gfx::ImageSkiaRep> resized_image_skia_reps =
178 resized_image_skia.image_reps(); 179 resized_image_skia.image_reps();
179 for (size_t i = 0; i < resized_image_skia_reps.size(); ++i) { 180 for (size_t i = 0; i < resized_image_skia_reps.size(); ++i) {
180 scoped_refptr<base::RefCountedBytes> png_bytes(new base::RefCountedBytes()); 181 scoped_refptr<base::RefCountedBytes> png_bytes(new base::RefCountedBytes());
181 if (gfx::PNGCodec::EncodeBGRASkBitmap( 182 if (gfx::PNGCodec::EncodeBGRASkBitmap(
182 resized_image_skia_reps[i].sk_bitmap(), false, &png_bytes->data())) { 183 resized_image_skia_reps[i].sk_bitmap(), false, &png_bytes->data())) {
183 png_reps.push_back(gfx::ImagePNGRep(png_bytes, 184 png_reps.push_back(gfx::ImagePNGRep(png_bytes,
184 resized_image_skia_reps[i].scale_factor())); 185 resized_image_skia_reps[i].scale()));
185 } 186 }
186 } 187 }
187 188
188 return gfx::Image(png_reps); 189 return gfx::Image(png_reps);
189 } 190 }
190 191
191 // static 192 // static
192 size_t FaviconUtil::SelectBestFaviconFromBitmaps( 193 size_t FaviconUtil::SelectBestFaviconFromBitmaps(
193 const std::vector<SkBitmap>& bitmaps, 194 const std::vector<SkBitmap>& bitmaps,
194 const std::vector<ui::ScaleFactor>& scale_factors, 195 const std::vector<ui::ScaleFactor>& scale_factors,
195 int desired_size) { 196 int desired_size) {
196 std::vector<gfx::Size> sizes; 197 std::vector<gfx::Size> sizes;
197 for (size_t i = 0; i < bitmaps.size(); ++i) 198 for (size_t i = 0; i < bitmaps.size(); ++i)
198 sizes.push_back(gfx::Size(bitmaps[i].width(), bitmaps[i].height())); 199 sizes.push_back(gfx::Size(bitmaps[i].width(), bitmaps[i].height()));
199 std::vector<size_t> selected_bitmap_indices; 200 std::vector<size_t> selected_bitmap_indices;
200 SelectFaviconFrameIndices(sizes, scale_factors, desired_size, 201 SelectFaviconFrameIndices(sizes, scale_factors, desired_size,
201 &selected_bitmap_indices, NULL); 202 &selected_bitmap_indices, NULL);
202 DCHECK_EQ(1u, selected_bitmap_indices.size()); 203 DCHECK_EQ(1u, selected_bitmap_indices.size());
203 return selected_bitmap_indices[0]; 204 return selected_bitmap_indices[0];
204 } 205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698