| 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 = SkGradientShader::CreateLinear( |
| 42 SkShader::kClamp_TileMode, NULL); | 42 p, colors, NULL, 2, SkShader::kClamp_TileMode, NULL); |
| 43 paint.setShader(s); | 43 paint.setShader(s.get()); |
| 44 // Need to unref shader, otherwise never deleted. | |
| 45 s->unref(); | |
| 46 } else { | 44 } else { |
| 47 paint.setColor(top_color); | 45 paint.setColor(top_color); |
| 48 } | 46 } |
| 49 | 47 |
| 50 canvas->DrawPath(path, paint); | 48 canvas->DrawPath(path, paint); |
| 51 } | 49 } |
| 52 | 50 |
| 53 void DrawRoundedRectShadow(gfx::Canvas* canvas, | 51 void DrawRoundedRectShadow(gfx::Canvas* canvas, |
| 54 const SkRect& rect, | 52 const SkRect& rect, |
| 55 int corner_radius, | 53 int corner_radius, |
| 56 int shadow, | 54 int shadow, |
| 57 SkColor color) { | 55 SkColor color) { |
| 58 SkPaint paint; | 56 SkPaint paint; |
| 59 paint.setFlags(SkPaint::kAntiAlias_Flag); | 57 paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 60 paint.setStyle(SkPaint::kFill_Style); | 58 paint.setStyle(SkPaint::kFill_Style); |
| 61 paint.setColor(color); | 59 paint.setColor(color); |
| 62 SkMaskFilter* filter = SkBlurMaskFilter::Create( | 60 skia::RefPtr<SkMaskFilter> filter = SkBlurMaskFilter::Create( |
| 63 shadow / 2, SkBlurMaskFilter::kNormal_BlurStyle); | 61 shadow / 2, SkBlurMaskFilter::kNormal_BlurStyle); |
| 64 paint.setMaskFilter(filter)->unref(); | 62 paint.setMaskFilter(filter.get()); |
| 65 SkRect inset_rect(rect); | 63 SkRect inset_rect(rect); |
| 66 inset_rect.inset(SkIntToScalar(shadow / 2), SkIntToScalar(shadow / 2)); | 64 inset_rect.inset(SkIntToScalar(shadow / 2), SkIntToScalar(shadow / 2)); |
| 67 canvas->sk_canvas()->drawRoundRect( | 65 canvas->sk_canvas()->drawRoundRect( |
| 68 inset_rect, | 66 inset_rect, |
| 69 SkIntToScalar(corner_radius), SkIntToScalar(corner_radius), | 67 SkIntToScalar(corner_radius), SkIntToScalar(corner_radius), |
| 70 paint); | 68 paint); |
| 71 paint.setMaskFilter(NULL); | 69 paint.setMaskFilter(NULL); |
| 72 } | 70 } |
| 73 | 71 |
| 74 void DrawRectWithBorder(gfx::Canvas* canvas, | 72 void DrawRectWithBorder(gfx::Canvas* canvas, |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 209 |
| 212 views::Background* CreateRoundedBackground(int corner_radius, | 210 views::Background* CreateRoundedBackground(int corner_radius, |
| 213 int stroke_width, | 211 int stroke_width, |
| 214 SkColor background_color, | 212 SkColor background_color, |
| 215 SkColor stroke_color) { | 213 SkColor stroke_color) { |
| 216 return new RoundedBackground( | 214 return new RoundedBackground( |
| 217 corner_radius, stroke_width, background_color, stroke_color); | 215 corner_radius, stroke_width, background_color, stroke_color); |
| 218 } | 216 } |
| 219 | 217 |
| 220 } // namespace chromeos | 218 } // namespace chromeos |
| OLD | NEW |