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/profiles/profile_info_util.h" | 5 #include "chrome/browser/profiles/profile_info_util.h" |
6 | 6 |
7 #include "skia/ext/image_operations.h" | 7 #include "skia/ext/image_operations.h" |
8 #include "ui/gfx/canvas.h" | 8 #include "ui/gfx/canvas.h" |
9 #include "ui/gfx/rect.h" | 9 #include "ui/gfx/rect.h" |
10 | 10 |
11 namespace profiles { | 11 namespace profiles { |
12 | 12 |
13 const int kAvatarIconWidth = 38; | 13 const int kAvatarIconWidth = 38; |
14 const int kAvatarIconHeight = 31; | 14 const int kAvatarIconHeight = 31; |
15 | 15 |
16 gfx::Image GetAvatarIconForMenu(const gfx::Image& image, | 16 gfx::Image GetAvatarIconForMenu(const gfx::Image& image, |
17 bool is_gaia_picture) { | 17 bool is_gaia_picture) { |
18 if (!is_gaia_picture) | 18 if (!is_gaia_picture) |
19 return image; | 19 return image; |
20 | 20 |
21 int length = std::min(kAvatarIconWidth, kAvatarIconHeight) - 2; | 21 int length = std::min(kAvatarIconWidth, kAvatarIconHeight) - 2; |
22 SkBitmap bmp = skia::ImageOperations::Resize( | 22 SkBitmap bmp = skia::ImageOperations::Resize( |
23 *image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length); | 23 *image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length); |
24 gfx::Canvas canvas(gfx::Size(kAvatarIconWidth, kAvatarIconHeight), false); | 24 gfx::Canvas canvas(gfx::Size(kAvatarIconWidth, kAvatarIconHeight), |
| 25 ui::SCALE_FACTOR_100P, false); |
25 | 26 |
26 // Draw the icon centered on the canvas. | 27 // Draw the icon centered on the canvas. |
27 int x = (kAvatarIconWidth - length) / 2; | 28 int x = (kAvatarIconWidth - length) / 2; |
28 int y = (kAvatarIconHeight - length) / 2; | 29 int y = (kAvatarIconHeight - length) / 2; |
29 canvas.DrawImageInt(bmp, x, y); | 30 canvas.DrawImageInt(bmp, x, y); |
30 | 31 |
31 // Draw a gray border on the inside of the icon. | 32 // Draw a gray border on the inside of the icon. |
32 SkColor color = SkColorSetARGB(83, 0, 0, 0); | 33 SkColor color = SkColorSetARGB(83, 0, 0, 0); |
33 canvas.DrawRect(gfx::Rect(x, y, length - 1, length - 1), color); | 34 canvas.DrawRect(gfx::Rect(x, y, length - 1, length - 1), color); |
34 | 35 |
35 return gfx::Image(canvas.ExtractBitmap()); | 36 return gfx::Image(canvas.ExtractImageRep()); |
36 } | 37 } |
37 | 38 |
38 gfx::Image GetAvatarIconForWebUI(const gfx::Image& image, | 39 gfx::Image GetAvatarIconForWebUI(const gfx::Image& image, |
39 bool is_gaia_picture) { | 40 bool is_gaia_picture) { |
40 if (!is_gaia_picture) | 41 if (!is_gaia_picture) |
41 return image; | 42 return image; |
42 | 43 |
43 int length = std::min(kAvatarIconWidth, kAvatarIconHeight) - 2; | 44 int length = std::min(kAvatarIconWidth, kAvatarIconHeight) - 2; |
44 SkBitmap bmp = skia::ImageOperations::Resize( | 45 SkBitmap bmp = skia::ImageOperations::Resize( |
45 *image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length); | 46 *image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length); |
46 gfx::Canvas canvas(gfx::Size(kAvatarIconWidth, kAvatarIconHeight), false); | 47 gfx::Canvas canvas(gfx::Size(kAvatarIconWidth, kAvatarIconHeight), |
| 48 ui::SCALE_FACTOR_100P, false); |
47 | 49 |
48 // Draw the icon centered on the canvas. | 50 // Draw the icon centered on the canvas. |
49 int x = (kAvatarIconWidth - length) / 2; | 51 int x = (kAvatarIconWidth - length) / 2; |
50 int y = (kAvatarIconHeight - length) / 2; | 52 int y = (kAvatarIconHeight - length) / 2; |
51 canvas.DrawImageInt(bmp, x, y); | 53 canvas.DrawImageInt(bmp, x, y); |
52 | 54 |
53 return gfx::Image(canvas.ExtractBitmap()); | 55 return gfx::Image(canvas.ExtractImageRep()); |
54 } | 56 } |
55 | 57 |
56 gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image, | 58 gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image, |
57 bool is_gaia_picture, | 59 bool is_gaia_picture, |
58 int dst_width, | 60 int dst_width, |
59 int dst_height) { | 61 int dst_height) { |
60 if (!is_gaia_picture) | 62 if (!is_gaia_picture) |
61 return image; | 63 return image; |
62 | 64 |
63 int length = std::min(std::min(kAvatarIconWidth, kAvatarIconHeight), | 65 int length = std::min(std::min(kAvatarIconWidth, kAvatarIconHeight), |
64 std::min(dst_width, dst_height)) - 2; | 66 std::min(dst_width, dst_height)) - 2; |
65 SkBitmap bmp = skia::ImageOperations::Resize( | 67 SkBitmap bmp = skia::ImageOperations::Resize( |
66 *image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length); | 68 *image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length); |
67 gfx::Canvas canvas(gfx::Size(dst_width, dst_height), false); | 69 gfx::Canvas canvas(gfx::Size(dst_width, dst_height), ui::SCALE_FACTOR_100P, |
| 70 false); |
68 | 71 |
69 // Draw the icon on the bottom center of the canvas. | 72 // Draw the icon on the bottom center of the canvas. |
70 int x1 = (dst_width - length) / 2; | 73 int x1 = (dst_width - length) / 2; |
71 int x2 = x1 + length; | 74 int x2 = x1 + length; |
72 int y1 = dst_height - length - 1; | 75 int y1 = dst_height - length - 1; |
73 int y2 = y1 + length; | 76 int y2 = y1 + length; |
74 canvas.DrawImageInt(bmp, x1, y1); | 77 canvas.DrawImageInt(bmp, x1, y1); |
75 | 78 |
76 // Give the icon an etched look by drawing a highlight on the bottom edge | 79 // Give the icon an etched look by drawing a highlight on the bottom edge |
77 // and a shadow on the remaining edges. | 80 // and a shadow on the remaining edges. |
78 SkColor highlight_color = SkColorSetARGB(128, 255, 255, 255); | 81 SkColor highlight_color = SkColorSetARGB(128, 255, 255, 255); |
79 SkColor shadow_color = SkColorSetARGB(83, 0, 0, 0); | 82 SkColor shadow_color = SkColorSetARGB(83, 0, 0, 0); |
80 // Bottom highlight. | 83 // Bottom highlight. |
81 canvas.DrawLine(gfx::Point(x1, y2 - 1), gfx::Point(x2, y2 - 1), | 84 canvas.DrawLine(gfx::Point(x1, y2 - 1), gfx::Point(x2, y2 - 1), |
82 highlight_color); | 85 highlight_color); |
83 // Top shadow. | 86 // Top shadow. |
84 canvas.DrawLine(gfx::Point(x1, y1), gfx::Point(x2, y1), shadow_color); | 87 canvas.DrawLine(gfx::Point(x1, y1), gfx::Point(x2, y1), shadow_color); |
85 // Left shadow. | 88 // Left shadow. |
86 canvas.DrawLine(gfx::Point(x1, y1 + 1), gfx::Point(x1, y2 - 1), shadow_color); | 89 canvas.DrawLine(gfx::Point(x1, y1 + 1), gfx::Point(x1, y2 - 1), shadow_color); |
87 // Right shadow. | 90 // Right shadow. |
88 canvas.DrawLine(gfx::Point(x2 - 1, y1 + 1), gfx::Point(x2 - 1, y2 - 1), | 91 canvas.DrawLine(gfx::Point(x2 - 1, y1 + 1), gfx::Point(x2 - 1, y2 - 1), |
89 shadow_color); | 92 shadow_color); |
90 | 93 |
91 return gfx::Image(canvas.ExtractBitmap()); | 94 return gfx::Image(canvas.ExtractImageRep()); |
92 } | 95 } |
93 | 96 |
94 } // namespace | 97 } // namespace |
OLD | NEW |