OLD | NEW |
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 14 matching lines...) Expand all Loading... |
25 // or decoding the bitmap data. | 25 // or decoding the bitmap data. |
26 std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( | 26 std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( |
27 const std::vector<chrome::FaviconBitmapResult>& png_data, | 27 const std::vector<chrome::FaviconBitmapResult>& png_data, |
28 const std::vector<ui::ScaleFactor>& scale_factors, | 28 const std::vector<ui::ScaleFactor>& scale_factors, |
29 int favicon_size) { | 29 int favicon_size) { |
30 std::vector<gfx::ImagePNGRep> png_reps; | 30 std::vector<gfx::ImagePNGRep> png_reps; |
31 if (png_data.empty()) | 31 if (png_data.empty()) |
32 return png_reps; | 32 return png_reps; |
33 | 33 |
34 // A |favicon_size| of 0 indicates that the largest frame is desired. | 34 // A |favicon_size| of 0 indicates that the largest frame is desired. |
35 if (favicon_size == 0 && scale_factors.size() == 1) { | 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, |
46 scale_factors[0])); | 46 ui::SCALE_FACTOR_100P)); |
47 return png_reps; | 47 return png_reps; |
48 } | 48 } |
49 | 49 |
50 // Cache the scale factor for each pixel size as |scale_factors| may contain | 50 // Cache the scale factor for each pixel size as |scale_factors| may contain |
51 // any of GetFaviconScaleFactors() which may include scale factors not | 51 // any of GetFaviconScaleFactors() which may include scale factors not |
52 // supported by the platform. (ui::GetScaleFactorFromScale() cannot be used.) | 52 // supported by the platform. (ui::GetScaleFactorFromScale() cannot be used.) |
53 std::map<int, ui::ScaleFactor> desired_pixel_sizes; | 53 std::map<int, ui::ScaleFactor> desired_pixel_sizes; |
54 for (size_t i = 0; i < scale_factors.size(); ++i) { | 54 for (size_t i = 0; i < scale_factors.size(); ++i) { |
55 int pixel_size = floor(favicon_size * | 55 int pixel_size = floor(favicon_size * |
56 ui::GetScaleFactorScale(scale_factors[i])); | 56 ui::GetScaleFactorScale(scale_factors[i])); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // - Sync does a byte-to-byte comparison of gfx::Image::As1xPNGBytes() to | 127 // - Sync does a byte-to-byte comparison of gfx::Image::As1xPNGBytes() to |
128 // the data it put into the database in order to determine whether any | 128 // the data it put into the database in order to determine whether any |
129 // updates should be pushed to sync. | 129 // updates should be pushed to sync. |
130 // - The decoding occurs on the UI thread and the decoding can be a | 130 // - The decoding occurs on the UI thread and the decoding can be a |
131 // significant performance hit if a user has many bookmarks. | 131 // significant performance hit if a user has many bookmarks. |
132 // TODO(pkotwicz): Move the decoding off the UI thread. | 132 // TODO(pkotwicz): Move the decoding off the UI thread. |
133 std::vector<gfx::ImagePNGRep> png_reps = | 133 std::vector<gfx::ImagePNGRep> png_reps = |
134 SelectFaviconFramesFromPNGsWithoutResizing(png_data, scale_factors, | 134 SelectFaviconFramesFromPNGsWithoutResizing(png_data, scale_factors, |
135 favicon_size); | 135 favicon_size); |
136 | 136 |
| 137 // SelectFaviconFramesFromPNGsWithoutResizing() should have selected the |
| 138 // largest favicon if |favicon_size| == 0. |
| 139 if (favicon_size == 0) |
| 140 return gfx::Image(png_reps); |
| 141 |
137 std::vector<ui::ScaleFactor> scale_factors_to_generate = scale_factors; | 142 std::vector<ui::ScaleFactor> scale_factors_to_generate = scale_factors; |
138 for (size_t i = 0; i < png_reps.size(); ++i) { | 143 for (size_t i = 0; i < png_reps.size(); ++i) { |
139 std::vector<ui::ScaleFactor>::iterator it = std::find( | 144 std::vector<ui::ScaleFactor>::iterator it = std::find( |
140 scale_factors_to_generate.begin(), | 145 scale_factors_to_generate.begin(), |
141 scale_factors_to_generate.end(), | 146 scale_factors_to_generate.end(), |
142 png_reps[i].scale_factor); | 147 png_reps[i].scale_factor); |
143 CHECK(it != scale_factors_to_generate.end()); | 148 CHECK(it != scale_factors_to_generate.end()); |
144 scale_factors_to_generate.erase(it); | 149 scale_factors_to_generate.erase(it); |
145 } | 150 } |
146 | 151 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 int desired_size) { | 195 int desired_size) { |
191 std::vector<gfx::Size> sizes; | 196 std::vector<gfx::Size> sizes; |
192 for (size_t i = 0; i < bitmaps.size(); ++i) | 197 for (size_t i = 0; i < bitmaps.size(); ++i) |
193 sizes.push_back(gfx::Size(bitmaps[i].width(), bitmaps[i].height())); | 198 sizes.push_back(gfx::Size(bitmaps[i].width(), bitmaps[i].height())); |
194 std::vector<size_t> selected_bitmap_indices; | 199 std::vector<size_t> selected_bitmap_indices; |
195 SelectFaviconFrameIndices(sizes, scale_factors, desired_size, | 200 SelectFaviconFrameIndices(sizes, scale_factors, desired_size, |
196 &selected_bitmap_indices, NULL); | 201 &selected_bitmap_indices, NULL); |
197 DCHECK_EQ(1u, selected_bitmap_indices.size()); | 202 DCHECK_EQ(1u, selected_bitmap_indices.size()); |
198 return selected_bitmap_indices[0]; | 203 return selected_bitmap_indices[0]; |
199 } | 204 } |
OLD | NEW |