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/chromeos/login/rounded_rect_painter.h" | 5 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/chromeos/login/helper.h" | 8 #include "chrome/browser/chromeos/login/helper.h" |
9 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 9 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
10 #include "third_party/skia/include/effects/SkGradientShader.h" | 10 #include "third_party/skia/include/effects/SkGradientShader.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 path.addRoundRect(rect, | 31 path.addRoundRect(rect, |
32 SkIntToScalar(corner_radius), SkIntToScalar(corner_radius)); | 32 SkIntToScalar(corner_radius), SkIntToScalar(corner_radius)); |
33 SkPaint paint; | 33 SkPaint paint; |
34 paint.setStyle(SkPaint::kFill_Style); | 34 paint.setStyle(SkPaint::kFill_Style); |
35 paint.setFlags(SkPaint::kAntiAlias_Flag); | 35 paint.setFlags(SkPaint::kAntiAlias_Flag); |
36 if (top_color != bottom_color) { | 36 if (top_color != bottom_color) { |
37 SkPoint p[2]; | 37 SkPoint p[2]; |
38 p[0].set(SkIntToScalar(rect.left()), SkIntToScalar(rect.top())); | 38 p[0].set(SkIntToScalar(rect.left()), SkIntToScalar(rect.top())); |
39 p[1].set(SkIntToScalar(rect.left()), SkIntToScalar(rect.bottom())); | 39 p[1].set(SkIntToScalar(rect.left()), SkIntToScalar(rect.bottom())); |
40 SkColor colors[2] = { top_color, bottom_color }; | 40 SkColor colors[2] = { top_color, bottom_color }; |
41 SkShader* s = SkGradientShader::CreateLinear(p, colors, NULL, 2, | 41 skia::RefPtr<SkShader> s = skia::AdoptRef( |
42 SkShader::kClamp_TileMode, NULL); | 42 SkGradientShader::CreateLinear( |
43 paint.setShader(s); | 43 p, colors, NULL, 2, SkShader::kClamp_TileMode, NULL)); |
44 // Need to unref shader, otherwise never deleted. | 44 paint.setShader(s.get()); |
45 s->unref(); | |
46 } else { | 45 } else { |
47 paint.setColor(top_color); | 46 paint.setColor(top_color); |
48 } | 47 } |
49 | 48 |
50 canvas->DrawPath(path, paint); | 49 canvas->DrawPath(path, paint); |
51 } | 50 } |
52 | 51 |
53 void DrawRoundedRectShadow(gfx::Canvas* canvas, | 52 void DrawRoundedRectShadow(gfx::Canvas* canvas, |
54 const SkRect& rect, | 53 const SkRect& rect, |
55 int corner_radius, | 54 int corner_radius, |
56 int shadow, | 55 int shadow, |
57 SkColor color) { | 56 SkColor color) { |
58 SkPaint paint; | 57 SkPaint paint; |
59 paint.setFlags(SkPaint::kAntiAlias_Flag); | 58 paint.setFlags(SkPaint::kAntiAlias_Flag); |
60 paint.setStyle(SkPaint::kFill_Style); | 59 paint.setStyle(SkPaint::kFill_Style); |
61 paint.setColor(color); | 60 paint.setColor(color); |
62 SkMaskFilter* filter = SkBlurMaskFilter::Create( | 61 skia::RefPtr<SkMaskFilter> filter = skia::AdoptRef( |
63 shadow / 2, SkBlurMaskFilter::kNormal_BlurStyle); | 62 SkBlurMaskFilter::Create( |
64 paint.setMaskFilter(filter)->unref(); | 63 shadow / 2, SkBlurMaskFilter::kNormal_BlurStyle)); |
| 64 paint.setMaskFilter(filter.get()); |
65 SkRect inset_rect(rect); | 65 SkRect inset_rect(rect); |
66 inset_rect.inset(SkIntToScalar(shadow / 2), SkIntToScalar(shadow / 2)); | 66 inset_rect.inset(SkIntToScalar(shadow / 2), SkIntToScalar(shadow / 2)); |
67 canvas->sk_canvas()->drawRoundRect( | 67 canvas->sk_canvas()->drawRoundRect( |
68 inset_rect, | 68 inset_rect, |
69 SkIntToScalar(corner_radius), SkIntToScalar(corner_radius), | 69 SkIntToScalar(corner_radius), SkIntToScalar(corner_radius), |
70 paint); | 70 paint); |
71 paint.setMaskFilter(NULL); | 71 paint.setMaskFilter(NULL); |
72 } | 72 } |
73 | 73 |
74 void DrawRectWithBorder(gfx::Canvas* canvas, | 74 void DrawRectWithBorder(gfx::Canvas* canvas, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 211 |
212 views::Background* CreateRoundedBackground(int corner_radius, | 212 views::Background* CreateRoundedBackground(int corner_radius, |
213 int stroke_width, | 213 int stroke_width, |
214 SkColor background_color, | 214 SkColor background_color, |
215 SkColor stroke_color) { | 215 SkColor stroke_color) { |
216 return new RoundedBackground( | 216 return new RoundedBackground( |
217 corner_radius, stroke_width, background_color, stroke_color); | 217 corner_radius, stroke_width, background_color, stroke_color); |
218 } | 218 } |
219 | 219 |
220 } // namespace chromeos | 220 } // namespace chromeos |
OLD | NEW |