| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "views/painter.h" | 5 #include "views/painter.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "gfx/canvas.h" | 9 #include "gfx/canvas.h" |
| 10 #include "gfx/canvas_skia.h" |
| 10 #include "gfx/insets.h" | 11 #include "gfx/insets.h" |
| 11 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 12 #include "third_party/skia/include/effects/SkGradientShader.h" | 13 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 13 | 14 |
| 14 namespace views { | 15 namespace views { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 class GradientPainter : public Painter { | 19 class GradientPainter : public Painter { |
| 19 public: | 20 public: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 36 p[1].set(SkIntToScalar(0), SkIntToScalar(h)); | 37 p[1].set(SkIntToScalar(0), SkIntToScalar(h)); |
| 37 | 38 |
| 38 SkShader* s = | 39 SkShader* s = |
| 39 SkGradientShader::CreateLinear(p, colors_, NULL, 2, | 40 SkGradientShader::CreateLinear(p, colors_, NULL, 2, |
| 40 SkShader::kClamp_TileMode, NULL); | 41 SkShader::kClamp_TileMode, NULL); |
| 41 paint.setStyle(SkPaint::kFill_Style); | 42 paint.setStyle(SkPaint::kFill_Style); |
| 42 paint.setShader(s); | 43 paint.setShader(s); |
| 43 // Need to unref shader, otherwise never deleted. | 44 // Need to unref shader, otherwise never deleted. |
| 44 s->unref(); | 45 s->unref(); |
| 45 | 46 |
| 46 canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), | 47 canvas->AsCanvasSkia()->drawRectCoords( |
| 47 SkIntToScalar(w), SkIntToScalar(h), paint); | 48 SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(w), SkIntToScalar(h), |
| 49 paint); |
| 48 } | 50 } |
| 49 | 51 |
| 50 private: | 52 private: |
| 51 bool horizontal_; | 53 bool horizontal_; |
| 52 SkColor colors_[2]; | 54 SkColor colors_[2]; |
| 53 | 55 |
| 54 DISALLOW_COPY_AND_ASSIGN(GradientPainter); | 56 DISALLOW_COPY_AND_ASSIGN(GradientPainter); |
| 55 }; | 57 }; |
| 56 | 58 |
| 57 | 59 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 }; | 141 }; |
| 140 | 142 |
| 141 } // namespace | 143 } // namespace |
| 142 | 144 |
| 143 // static | 145 // static |
| 144 void Painter::PaintPainterAt(int x, int y, int w, int h, | 146 void Painter::PaintPainterAt(int x, int y, int w, int h, |
| 145 gfx::Canvas* canvas, Painter* painter) { | 147 gfx::Canvas* canvas, Painter* painter) { |
| 146 DCHECK(canvas && painter); | 148 DCHECK(canvas && painter); |
| 147 if (w < 0 || h < 0) | 149 if (w < 0 || h < 0) |
| 148 return; | 150 return; |
| 149 canvas->save(); | 151 canvas->AsCanvasSkia()->save(); |
| 150 canvas->TranslateInt(x, y); | 152 canvas->TranslateInt(x, y); |
| 151 painter->Paint(w, h, canvas); | 153 painter->Paint(w, h, canvas); |
| 152 canvas->restore(); | 154 canvas->AsCanvasSkia()->restore(); |
| 153 } | 155 } |
| 154 | 156 |
| 155 // static | 157 // static |
| 156 Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) { | 158 Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) { |
| 157 return new GradientPainter(true, c1, c2); | 159 return new GradientPainter(true, c1, c2); |
| 158 } | 160 } |
| 159 | 161 |
| 160 // static | 162 // static |
| 161 Painter* Painter::CreateVerticalGradient(SkColor c1, SkColor c2) { | 163 Painter* Painter::CreateVerticalGradient(SkColor c1, SkColor c2) { |
| 162 return new GradientPainter(false, c1, c2); | 164 return new GradientPainter(false, c1, c2); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 187 canvas->DrawBitmapInt(*images_[LEFT], 0, 0); | 189 canvas->DrawBitmapInt(*images_[LEFT], 0, 0); |
| 188 canvas->DrawBitmapInt(*images_[RIGHT], w - images_[RIGHT]->width(), 0); | 190 canvas->DrawBitmapInt(*images_[RIGHT], w - images_[RIGHT]->width(), 0); |
| 189 canvas->TileImageInt(*images_[CENTER], | 191 canvas->TileImageInt(*images_[CENTER], |
| 190 images_[LEFT]->width(), | 192 images_[LEFT]->width(), |
| 191 0, | 193 0, |
| 192 w - images_[LEFT]->width() - images_[RIGHT]->width(), | 194 w - images_[LEFT]->width() - images_[RIGHT]->width(), |
| 193 height_); | 195 height_); |
| 194 } | 196 } |
| 195 | 197 |
| 196 } // namespace views | 198 } // namespace views |
| OLD | NEW |