| 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 "ui/views/painter.h" | 5 #include "ui/views/painter.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "third_party/skia/include/effects/SkGradientShader.h" | 9 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // Overridden from Painter: | 41 // Overridden from Painter: |
| 42 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE { | 42 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE { |
| 43 SkPaint paint; | 43 SkPaint paint; |
| 44 SkPoint p[2]; | 44 SkPoint p[2]; |
| 45 p[0].iset(0, 0); | 45 p[0].iset(0, 0); |
| 46 if (horizontal_) | 46 if (horizontal_) |
| 47 p[1].iset(size.width(), 0); | 47 p[1].iset(size.width(), 0); |
| 48 else | 48 else |
| 49 p[1].iset(0, size.height()); | 49 p[1].iset(0, size.height()); |
| 50 | 50 |
| 51 SkShader* s = SkGradientShader::CreateLinear(p, colors_.get(), pos_.get(), | 51 skia::RefPtr<SkShader> s = skia::AdoptRef(SkGradientShader::CreateLinear( |
| 52 count_, SkShader::kClamp_TileMode, NULL); | 52 p, colors_.get(), pos_.get(), count_, SkShader::kClamp_TileMode, NULL)); |
| 53 paint.setStyle(SkPaint::kFill_Style); | 53 paint.setStyle(SkPaint::kFill_Style); |
| 54 paint.setShader(s); | 54 paint.setShader(s.get()); |
| 55 // Need to unref shader, otherwise never deleted. | 55 // Need to unref shader, otherwise never deleted. |
| 56 s->unref(); | |
| 57 | 56 |
| 58 canvas->sk_canvas()->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), | 57 canvas->sk_canvas()->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), |
| 59 SkIntToScalar(size.width()), | 58 SkIntToScalar(size.width()), |
| 60 SkIntToScalar(size.height()), paint); | 59 SkIntToScalar(size.height()), paint); |
| 61 } | 60 } |
| 62 | 61 |
| 63 private: | 62 private: |
| 64 // If |horizontal_| is true then the gradiant is painted horizontally. | 63 // If |horizontal_| is true then the gradiant is painted horizontally. |
| 65 bool horizontal_; | 64 bool horizontal_; |
| 66 // The gradient colors. | 65 // The gradient colors. |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 return; | 223 return; |
| 225 } | 224 } |
| 226 canvas->DrawImageInt(*images_[LEFT], 0, 0); | 225 canvas->DrawImageInt(*images_[LEFT], 0, 0); |
| 227 canvas->DrawImageInt(*images_[RIGHT], | 226 canvas->DrawImageInt(*images_[RIGHT], |
| 228 size.width() - images_[RIGHT]->width(), 0); | 227 size.width() - images_[RIGHT]->width(), 0); |
| 229 canvas->TileImageInt(*images_[CENTER], images_[LEFT]->width(), 0, | 228 canvas->TileImageInt(*images_[CENTER], images_[LEFT]->width(), 0, |
| 230 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), height_); | 229 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), height_); |
| 231 } | 230 } |
| 232 | 231 |
| 233 } // namespace views | 232 } // namespace views |
| OLD | NEW |