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/favicon/favicon_types.h" | 7 #include "chrome/browser/favicon/favicon_types.h" |
8 #include "chrome/browser/history/select_favicon_frames.h" | 8 #include "chrome/browser/history/select_favicon_frames.h" |
9 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
11 #include "skia/ext/image_operations.h" | 11 #include "skia/ext/image_operations.h" |
12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
13 #include "ui/gfx/codec/png_codec.h" | 13 #include "ui/gfx/codec/png_codec.h" |
14 #include "ui/gfx/favicon_size.h" | 14 #include "ui/gfx/favicon_size.h" |
15 #include "ui/gfx/image/image_png_rep.h" | 15 #include "ui/gfx/image/image_png_rep.h" |
16 #include "ui/gfx/image/image_skia.h" | 16 #include "ui/gfx/image/image_skia.h" |
17 #include "webkit/glue/image_decoder.h" | 17 #include "webkit/glue/image_decoder.h" |
18 | 18 |
| 19 #if defined(OS_MACOSX) |
| 20 #include "base/mac/mac_util.h" |
| 21 #endif |
| 22 |
19 namespace { | 23 namespace { |
20 | 24 |
21 // Creates image reps of DIP size |favicon_size| for the subset of | 25 // Creates image reps of DIP size |favicon_size| for the subset of |
22 // |scale_factors| for which the image reps can be created without resizing | 26 // |scale_factors| for which the image reps can be created without resizing |
23 // or decoding the bitmap data. | 27 // or decoding the bitmap data. |
24 std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( | 28 std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( |
25 const std::vector<chrome::FaviconBitmapResult>& png_data, | 29 const std::vector<chrome::FaviconBitmapResult>& png_data, |
26 const std::vector<ui::ScaleFactor>& scale_factors, | 30 const std::vector<ui::ScaleFactor>& scale_factors, |
27 int favicon_size) { | 31 int favicon_size) { |
28 std::vector<gfx::ImagePNGRep> png_reps; | 32 std::vector<gfx::ImagePNGRep> png_reps; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // TODO(ios): 100p should not be necessary on iOS retina devices. However | 102 // TODO(ios): 100p should not be necessary on iOS retina devices. However |
99 // the sync service only supports syncing 100p favicons. Until sync supports | 103 // the sync service only supports syncing 100p favicons. Until sync supports |
100 // other scales 100p is needed in the list of scale factors to retrieve and | 104 // other scales 100p is needed in the list of scale factors to retrieve and |
101 // store the favicons in both 100p for sync and 200p for display. cr/160503. | 105 // store the favicons in both 100p for sync and 200p for display. cr/160503. |
102 favicon_scale_factors.insert(favicon_scale_factors.begin() + insert_index, | 106 favicon_scale_factors.insert(favicon_scale_factors.begin() + insert_index, |
103 ui::SCALE_FACTOR_100P); | 107 ui::SCALE_FACTOR_100P); |
104 return favicon_scale_factors; | 108 return favicon_scale_factors; |
105 } | 109 } |
106 | 110 |
107 // static | 111 // static |
| 112 void FaviconUtil::SetFaviconColorSpace(gfx::Image* image) { |
| 113 #if defined(OS_MACOSX) |
| 114 image->SetSourceColorSpace(base::mac::GetSystemColorSpace()); |
| 115 #endif // OS_MACOSX |
| 116 } |
| 117 |
| 118 // static |
108 gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( | 119 gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( |
109 const std::vector<chrome::FaviconBitmapResult>& png_data, | 120 const std::vector<chrome::FaviconBitmapResult>& png_data, |
110 const std::vector<ui::ScaleFactor>& scale_factors, | 121 const std::vector<ui::ScaleFactor>& scale_factors, |
111 int favicon_size) { | 122 int favicon_size) { |
112 // Create image reps for as many scale factors as possible without resizing | 123 // Create image reps for as many scale factors as possible without resizing |
113 // the bitmap data or decoding it. FaviconHandler stores already resized | 124 // the bitmap data or decoding it. FaviconHandler stores already resized |
114 // favicons into history so no additional resizing should be needed in the | 125 // favicons into history so no additional resizing should be needed in the |
115 // common case. | 126 // common case. |
116 // Creating the gfx::Image from |png_data| without resizing or decoding if | 127 // Creating the gfx::Image from |png_data| without resizing or decoding if |
117 // possible is important because: | 128 // possible is important because: |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 int new_height = decoded.height(); | 218 int new_height = decoded.height(); |
208 gfx::CalculateFaviconTargetSize(&new_width, &new_height); | 219 gfx::CalculateFaviconTargetSize(&new_width, &new_height); |
209 decoded = skia::ImageOperations::Resize( | 220 decoded = skia::ImageOperations::Resize( |
210 decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height); | 221 decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height); |
211 } | 222 } |
212 | 223 |
213 // Encode our bitmap as a PNG. | 224 // Encode our bitmap as a PNG. |
214 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); | 225 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); |
215 return true; | 226 return true; |
216 } | 227 } |
OLD | NEW |