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

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

Issue 24175004: Remove dependency on ui::ScaleFactor from ui/gfx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix new usage of scale in FastShowPickler 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_service.h" 5 #include "chrome/browser/favicon/favicon_service.h"
6 6
7 #include "base/hash.h" 7 #include "base/hash.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "chrome/browser/favicon/favicon_util.h" 9 #include "chrome/browser/favicon/favicon_util.h"
10 #include "chrome/browser/history/history_backend.h" 10 #include "chrome/browser/history/history_backend.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 231 }
232 232
233 void FaviconService::SetFavicons(const GURL& page_url, 233 void FaviconService::SetFavicons(const GURL& page_url,
234 const GURL& icon_url, 234 const GURL& icon_url,
235 chrome::IconType icon_type, 235 chrome::IconType icon_type,
236 const gfx::Image& image) { 236 const gfx::Image& image) {
237 if (!history_service_) 237 if (!history_service_)
238 return; 238 return;
239 239
240 gfx::ImageSkia image_skia = image.AsImageSkia(); 240 gfx::ImageSkia image_skia = image.AsImageSkia();
241 image_skia.EnsureRepsForSupportedScaleFactors(); 241 image_skia.EnsureRepsForSupportedScales();
242 const std::vector<gfx::ImageSkiaRep>& image_reps = image_skia.image_reps(); 242 const std::vector<gfx::ImageSkiaRep>& image_reps = image_skia.image_reps();
243 std::vector<chrome::FaviconBitmapData> favicon_bitmap_data; 243 std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
244 for (size_t i = 0; i < image_reps.size(); ++i) { 244 for (size_t i = 0; i < image_reps.size(); ++i) {
245 scoped_refptr<base::RefCountedBytes> bitmap_data( 245 scoped_refptr<base::RefCountedBytes> bitmap_data(
246 new base::RefCountedBytes()); 246 new base::RefCountedBytes());
247 if (gfx::PNGCodec::EncodeBGRASkBitmap(image_reps[i].sk_bitmap(), 247 if (gfx::PNGCodec::EncodeBGRASkBitmap(image_reps[i].sk_bitmap(),
248 false, 248 false,
249 &bitmap_data->data())) { 249 &bitmap_data->data())) {
250 gfx::Size pixel_size(image_reps[i].pixel_width(), 250 gfx::Size pixel_size(image_reps[i].pixel_width(),
251 image_reps[i].pixel_height()); 251 image_reps[i].pixel_height());
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 336
337 // If the desired size is 0, SelectFaviconFrames() will return the largest 337 // If the desired size is 0, SelectFaviconFrames() will return the largest
338 // bitmap without doing any resizing. As |favicon_bitmap_results| has bitmap 338 // bitmap without doing any resizing. As |favicon_bitmap_results| has bitmap
339 // data for a single bitmap, return it and avoid an unnecessary decode. 339 // data for a single bitmap, return it and avoid an unnecessary decode.
340 if (desired_size_in_dip == 0) { 340 if (desired_size_in_dip == 0) {
341 callback.Run(bitmap_result); 341 callback.Run(bitmap_result);
342 return; 342 return;
343 } 343 }
344 344
345 // If history bitmap is already desired pixel size, return early. 345 // If history bitmap is already desired pixel size, return early.
346 float desired_scale = ui::GetScaleFactorScale(desired_scale_factor); 346 float desired_scale = ui::GetImageScale(desired_scale_factor);
347 int desired_edge_width_in_pixel = static_cast<int>( 347 int desired_edge_width_in_pixel = static_cast<int>(
348 desired_size_in_dip * desired_scale + 0.5f); 348 desired_size_in_dip * desired_scale + 0.5f);
349 gfx::Size desired_size_in_pixel(desired_edge_width_in_pixel, 349 gfx::Size desired_size_in_pixel(desired_edge_width_in_pixel,
350 desired_edge_width_in_pixel); 350 desired_edge_width_in_pixel);
351 if (bitmap_result.pixel_size == desired_size_in_pixel) { 351 if (bitmap_result.pixel_size == desired_size_in_pixel) {
352 callback.Run(bitmap_result); 352 callback.Run(bitmap_result);
353 return; 353 return;
354 } 354 }
355 355
356 // Convert raw bytes to SkBitmap, resize via SelectFaviconFrames(), then 356 // Convert raw bytes to SkBitmap, resize via SelectFaviconFrames(), then
357 // convert back. 357 // convert back.
358 std::vector<ui::ScaleFactor> desired_scale_factors; 358 std::vector<ui::ScaleFactor> desired_scale_factors;
359 desired_scale_factors.push_back(desired_scale_factor); 359 desired_scale_factors.push_back(desired_scale_factor);
360 gfx::Image resized_image = FaviconUtil::SelectFaviconFramesFromPNGs( 360 gfx::Image resized_image = FaviconUtil::SelectFaviconFramesFromPNGs(
361 favicon_bitmap_results, desired_scale_factors, desired_size_in_dip); 361 favicon_bitmap_results, desired_scale_factors, desired_size_in_dip);
362 362
363 std::vector<unsigned char> resized_bitmap_data; 363 std::vector<unsigned char> resized_bitmap_data;
364 if (!gfx::PNGCodec::EncodeBGRASkBitmap(resized_image.AsBitmap(), false, 364 if (!gfx::PNGCodec::EncodeBGRASkBitmap(resized_image.AsBitmap(), false,
365 &resized_bitmap_data)) { 365 &resized_bitmap_data)) {
366 callback.Run(chrome::FaviconBitmapResult()); 366 callback.Run(chrome::FaviconBitmapResult());
367 return; 367 return;
368 } 368 }
369 369
370 bitmap_result.bitmap_data = base::RefCountedBytes::TakeVector( 370 bitmap_result.bitmap_data = base::RefCountedBytes::TakeVector(
371 &resized_bitmap_data); 371 &resized_bitmap_data);
372 callback.Run(bitmap_result); 372 callback.Run(bitmap_result);
373 } 373 }
OLDNEW
« no previous file with comments | « chrome/browser/favicon/favicon_handler_unittest.cc ('k') | chrome/browser/favicon/favicon_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698