Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: ui/views/painter.cc

Issue 10953002: views: Delete some array pointers in GradientPainter using scoped_array. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "third_party/skia/include/effects/SkGradientShader.h" 9 #include "third_party/skia/include/effects/SkGradientShader.h"
9 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/image/image.h" 12 #include "ui/gfx/image/image.h"
12 #include "ui/gfx/image/image_skia.h" 13 #include "ui/gfx/image/image_skia.h"
13 #include "ui/gfx/insets.h" 14 #include "ui/gfx/insets.h"
14 #include "ui/gfx/point.h" 15 #include "ui/gfx/point.h"
15 #include "ui/gfx/rect.h" 16 #include "ui/gfx/rect.h"
16 17
17 namespace views { 18 namespace views {
18 19
19 namespace { 20 namespace {
20 21
21 class GradientPainter : public Painter { 22 class GradientPainter : public Painter {
22 public: 23 public:
23 GradientPainter(bool horizontal, 24 GradientPainter(bool horizontal,
24 SkColor* colors, 25 SkColor* colors,
25 SkScalar* pos, 26 SkScalar* pos,
26 size_t count) 27 size_t count)
27 : horizontal_(horizontal), 28 : horizontal_(horizontal),
28 count_(count) { 29 count_(count) {
29 pos_ = new SkScalar[count_]; 30 pos_.reset(new SkScalar[count_]);
30 colors_ = new SkColor[count_]; 31 colors_.reset(new SkColor[count_]);
31 32
32 for (size_t i = 0; i < count_; ++i) { 33 for (size_t i = 0; i < count_; ++i) {
33 pos_[i] = pos[i]; 34 pos_[i] = pos[i];
34 colors_[i] = colors[i]; 35 colors_[i] = colors[i];
35 } 36 }
36 } 37 }
37 38
38 virtual ~GradientPainter() { 39 virtual ~GradientPainter() {}
39 delete[] pos_;
40 delete[] colors_;
41 }
42 40
43 // Overridden from Painter: 41 // Overridden from Painter:
44 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE { 42 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE {
45 SkPaint paint; 43 SkPaint paint;
46 SkPoint p[2]; 44 SkPoint p[2];
47 p[0].iset(0, 0); 45 p[0].iset(0, 0);
48 if (horizontal_) 46 if (horizontal_)
49 p[1].iset(size.width(), 0); 47 p[1].iset(size.width(), 0);
50 else 48 else
51 p[1].iset(0, size.height()); 49 p[1].iset(0, size.height());
52 50
53 SkShader* s = SkGradientShader::CreateLinear(p, colors_, pos_, count_, 51 SkShader* s = SkGradientShader::CreateLinear(p, colors_.get(), pos_.get(),
54 SkShader::kClamp_TileMode, NULL); 52 count_, SkShader::kClamp_TileMode, NULL);
55 paint.setStyle(SkPaint::kFill_Style); 53 paint.setStyle(SkPaint::kFill_Style);
56 paint.setShader(s); 54 paint.setShader(s);
57 // Need to unref shader, otherwise never deleted. 55 // Need to unref shader, otherwise never deleted.
58 s->unref(); 56 s->unref();
59 57
60 canvas->sk_canvas()->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), 58 canvas->sk_canvas()->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0),
61 SkIntToScalar(size.width()), 59 SkIntToScalar(size.width()),
62 SkIntToScalar(size.height()), paint); 60 SkIntToScalar(size.height()), paint);
63 } 61 }
64 62
65 private: 63 private:
66 // If |horizontal_| is true then the gradiant is painted horizontally. 64 // If |horizontal_| is true then the gradiant is painted horizontally.
67 bool horizontal_; 65 bool horizontal_;
68 // The gradient colors. 66 // The gradient colors.
69 SkColor* colors_; 67 scoped_array<SkColor> colors_;
70 // The relative positions of the corresponding gradient colors. 68 // The relative positions of the corresponding gradient colors.
71 SkScalar* pos_; 69 scoped_array<SkScalar> pos_;
72 // The number of elements in |colors_| and |pos_|. 70 // The number of elements in |colors_| and |pos_|.
73 size_t count_; 71 size_t count_;
74 72
75 DISALLOW_COPY_AND_ASSIGN(GradientPainter); 73 DISALLOW_COPY_AND_ASSIGN(GradientPainter);
76 }; 74 };
77 75
78 76
79 class ImagePainter : public Painter { 77 class ImagePainter : public Painter {
80 public: 78 public:
81 ImagePainter(const gfx::ImageSkia& image, 79 ImagePainter(const gfx::ImageSkia& image,
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 return; 224 return;
227 } 225 }
228 canvas->DrawImageInt(*images_[LEFT], 0, 0); 226 canvas->DrawImageInt(*images_[LEFT], 0, 0);
229 canvas->DrawImageInt(*images_[RIGHT], 227 canvas->DrawImageInt(*images_[RIGHT],
230 size.width() - images_[RIGHT]->width(), 0); 228 size.width() - images_[RIGHT]->width(), 0);
231 canvas->TileImageInt(*images_[CENTER], images_[LEFT]->width(), 0, 229 canvas->TileImageInt(*images_[CENTER], images_[LEFT]->width(), 0,
232 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), height_); 230 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), height_);
233 } 231 }
234 232
235 } // namespace views 233 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698