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

Side by Side Diff: views/painter.cc

Issue 2811032: Revert 50784 - Canvas refactoring part 3.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 6 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 | « views/drag_utils_win.cc ('k') | views/view.cc » ('j') | 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) 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"
11 #include "gfx/insets.h" 10 #include "gfx/insets.h"
12 #include "third_party/skia/include/core/SkBitmap.h" 11 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "third_party/skia/include/effects/SkGradientShader.h" 12 #include "third_party/skia/include/effects/SkGradientShader.h"
14 13
15 namespace views { 14 namespace views {
16 15
17 namespace { 16 namespace {
18 17
19 class GradientPainter : public Painter { 18 class GradientPainter : public Painter {
20 public: 19 public:
(...skipping 16 matching lines...) Expand all
37 p[1].set(SkIntToScalar(0), SkIntToScalar(h)); 36 p[1].set(SkIntToScalar(0), SkIntToScalar(h));
38 37
39 SkShader* s = 38 SkShader* s =
40 SkGradientShader::CreateLinear(p, colors_, NULL, 2, 39 SkGradientShader::CreateLinear(p, colors_, NULL, 2,
41 SkShader::kClamp_TileMode, NULL); 40 SkShader::kClamp_TileMode, NULL);
42 paint.setStyle(SkPaint::kFill_Style); 41 paint.setStyle(SkPaint::kFill_Style);
43 paint.setShader(s); 42 paint.setShader(s);
44 // Need to unref shader, otherwise never deleted. 43 // Need to unref shader, otherwise never deleted.
45 s->unref(); 44 s->unref();
46 45
47 canvas->AsCanvasSkia()->drawRectCoords( 46 canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0),
48 SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(w), SkIntToScalar(h), 47 SkIntToScalar(w), SkIntToScalar(h), paint);
49 paint);
50 } 48 }
51 49
52 private: 50 private:
53 bool horizontal_; 51 bool horizontal_;
54 SkColor colors_[2]; 52 SkColor colors_[2];
55 53
56 DISALLOW_COPY_AND_ASSIGN(GradientPainter); 54 DISALLOW_COPY_AND_ASSIGN(GradientPainter);
57 }; 55 };
58 56
59 57
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 }; 139 };
142 140
143 } // namespace 141 } // namespace
144 142
145 // static 143 // static
146 void Painter::PaintPainterAt(int x, int y, int w, int h, 144 void Painter::PaintPainterAt(int x, int y, int w, int h,
147 gfx::Canvas* canvas, Painter* painter) { 145 gfx::Canvas* canvas, Painter* painter) {
148 DCHECK(canvas && painter); 146 DCHECK(canvas && painter);
149 if (w < 0 || h < 0) 147 if (w < 0 || h < 0)
150 return; 148 return;
151 canvas->AsCanvasSkia()->save(); 149 canvas->save();
152 canvas->TranslateInt(x, y); 150 canvas->TranslateInt(x, y);
153 painter->Paint(w, h, canvas); 151 painter->Paint(w, h, canvas);
154 canvas->AsCanvasSkia()->restore(); 152 canvas->restore();
155 } 153 }
156 154
157 // static 155 // static
158 Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) { 156 Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) {
159 return new GradientPainter(true, c1, c2); 157 return new GradientPainter(true, c1, c2);
160 } 158 }
161 159
162 // static 160 // static
163 Painter* Painter::CreateVerticalGradient(SkColor c1, SkColor c2) { 161 Painter* Painter::CreateVerticalGradient(SkColor c1, SkColor c2) {
164 return new GradientPainter(false, c1, c2); 162 return new GradientPainter(false, c1, c2);
(...skipping 24 matching lines...) Expand all
189 canvas->DrawBitmapInt(*images_[LEFT], 0, 0); 187 canvas->DrawBitmapInt(*images_[LEFT], 0, 0);
190 canvas->DrawBitmapInt(*images_[RIGHT], w - images_[RIGHT]->width(), 0); 188 canvas->DrawBitmapInt(*images_[RIGHT], w - images_[RIGHT]->width(), 0);
191 canvas->TileImageInt(*images_[CENTER], 189 canvas->TileImageInt(*images_[CENTER],
192 images_[LEFT]->width(), 190 images_[LEFT]->width(),
193 0, 191 0,
194 w - images_[LEFT]->width() - images_[RIGHT]->width(), 192 w - images_[LEFT]->width() - images_[RIGHT]->width(),
195 height_); 193 height_);
196 } 194 }
197 195
198 } // namespace views 196 } // namespace views
OLDNEW
« no previous file with comments | « views/drag_utils_win.cc ('k') | views/view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698