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

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

Issue 10823385: [Coverity] Pass-by-ref instead of pass-by-val (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/select_favicon_frames.h" 5 #include "chrome/browser/favicon/select_favicon_frames.h"
6 6
7 #include "skia/ext/image_operations.h" 7 #include "skia/ext/image_operations.h"
8 #include "ui/gfx/image/image.h" 8 #include "ui/gfx/image/image.h"
9 #include "ui/gfx/image/image_skia.h" 9 #include "ui/gfx/image/image_skia.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 10 #include "third_party/skia/include/core/SkCanvas.h"
11 11
12 namespace { 12 namespace {
13 13
14 size_t BiggestCandidate(const std::vector<SkBitmap>& bitmaps) { 14 size_t BiggestCandidate(const std::vector<SkBitmap>& bitmaps) {
15 size_t max_index = 0; 15 size_t max_index = 0;
16 int max_area = bitmaps[0].width() * bitmaps[0].height(); 16 int max_area = bitmaps[0].width() * bitmaps[0].height();
17 for (size_t i = 1; i < bitmaps.size(); ++i) { 17 for (size_t i = 1; i < bitmaps.size(); ++i) {
18 int area = bitmaps[i].width() * bitmaps[i].height(); 18 int area = bitmaps[i].width() * bitmaps[i].height();
19 if (area > max_area) { 19 if (area > max_area) {
20 max_area = area; 20 max_area = area;
21 max_index = i; 21 max_index = i;
22 } 22 }
23 } 23 }
24 return max_index; 24 return max_index;
25 } 25 }
26 26
27 SkBitmap PadWithBorder(SkBitmap contents, int desired_size, int source_size) { 27 SkBitmap PadWithBorder(const SkBitmap& contents,
Nico 2012/09/19 10:29:16 SkBitmaps are refcounted and by design very cheap
sky 2012/09/19 14:25:05 We should still pass by ref if possible.
28 int desired_size,
29 int source_size) {
28 SkBitmap bitmap; 30 SkBitmap bitmap;
29 bitmap.setConfig( 31 bitmap.setConfig(
30 SkBitmap::kARGB_8888_Config, desired_size, desired_size); 32 SkBitmap::kARGB_8888_Config, desired_size, desired_size);
31 bitmap.allocPixels(); 33 bitmap.allocPixels();
32 bitmap.eraseARGB(0, 0, 0, 0); 34 bitmap.eraseARGB(0, 0, 0, 0);
33 35
34 { 36 {
35 SkCanvas canvas(bitmap); 37 SkCanvas canvas(bitmap);
36 int shift = (desired_size - source_size) / 2; 38 int shift = (desired_size - source_size) / 2;
37 SkRect dest(SkRect::MakeXYWH(shift, shift, source_size, source_size)); 39 SkRect dest(SkRect::MakeXYWH(shift, shift, source_size, source_size));
38 canvas.drawBitmapRect(contents, NULL, dest); 40 canvas.drawBitmapRect(contents, NULL, dest);
39 } 41 }
40 42
41 return bitmap; 43 return bitmap;
42 } 44 }
43 45
44 SkBitmap SampleNearestNeighbor(SkBitmap contents, int desired_size) { 46 SkBitmap SampleNearestNeighbor(const SkBitmap& contents, int desired_size) {
45 SkBitmap bitmap; 47 SkBitmap bitmap;
46 bitmap.setConfig( 48 bitmap.setConfig(
47 SkBitmap::kARGB_8888_Config, desired_size, desired_size); 49 SkBitmap::kARGB_8888_Config, desired_size, desired_size);
48 bitmap.allocPixels(); 50 bitmap.allocPixels();
49 if (!contents.isOpaque()) 51 if (!contents.isOpaque())
50 bitmap.eraseARGB(0, 0, 0, 0); 52 bitmap.eraseARGB(0, 0, 0, 0);
51 53
52 { 54 {
53 SkCanvas canvas(bitmap); 55 SkCanvas canvas(bitmap);
54 SkRect dest(SkRect::MakeWH(desired_size, desired_size)); 56 SkRect dest(SkRect::MakeWH(desired_size, desired_size));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 141 }
140 142
141 for (size_t i = 0; i < scale_factors.size(); ++i) { 143 for (size_t i = 0; i < scale_factors.size(); ++i) {
142 multi_image.AddRepresentation(gfx::ImageSkiaRep( 144 multi_image.AddRepresentation(gfx::ImageSkiaRep(
143 SelectCandidate(bitmaps, desired_size, scale_factors[i]), 145 SelectCandidate(bitmaps, desired_size, scale_factors[i]),
144 scale_factors[i])); 146 scale_factors[i]));
145 } 147 }
146 148
147 return multi_image; 149 return multi_image;
148 } 150 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698