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

Side by Side Diff: gm/dropshadowimagefilter.cpp

Issue 1530203002: Reland of move drawSprite from canvas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « bench/ImageBench.cpp ('k') | gm/imagefiltersbase.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkColorFilter.h" 9 #include "SkColorFilter.h"
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 SkCanvas c(bm); 60 SkCanvas c(bm);
61 draw_path(&c, r, nullptr); 61 draw_path(&c, r, nullptr);
62 62
63 paint.setImageFilter(imf); 63 paint.setImageFilter(imf);
64 canvas->save(); 64 canvas->save();
65 canvas->clipRect(r); 65 canvas->clipRect(r);
66 canvas->drawBitmap(bm, 0, 0, &paint); 66 canvas->drawBitmap(bm, 0, 0, &paint);
67 canvas->restore(); 67 canvas->restore();
68 } 68 }
69 69
70 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
71 SkPaint paint;
72
73 SkIRect bounds;
74 r.roundOut(&bounds);
75
76 SkBitmap bm;
77 bm.allocN32Pixels(bounds.width(), bounds.height());
78 bm.eraseColor(SK_ColorRED);
79 SkCanvas c(bm);
80
81 SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44);
82 paint.setColor(SK_ColorGREEN);
83 c.drawRect(SkRect::Make(cropRect), paint);
84
85 paint.setImageFilter(imf);
86 SkPoint loc = { r.fLeft, r.fTop };
87 canvas->getTotalMatrix().mapPoints(&loc, 1);
88 canvas->drawSprite(bm,
89 SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY),
90 &paint);
91 }
92
93 /////////////////////////////////////////////////////////////////////////////// 70 ///////////////////////////////////////////////////////////////////////////////
94 71
95 class DropShadowImageFilterGM : public skiagm::GM { 72 class DropShadowImageFilterGM : public skiagm::GM {
96 public: 73 public:
97 DropShadowImageFilterGM () {} 74 DropShadowImageFilterGM () {}
98 75
99 protected: 76 protected:
100 77
101 virtual SkString onShortName() { 78 virtual SkString onShortName() {
102 return SkString("dropshadowimagefilter"); 79 return SkString("dropshadowimagefilter");
103 } 80 }
104 81
105 virtual SkISize onISize() { return SkISize::Make(400, 656); } 82 virtual SkISize onISize() { return SkISize::Make(400, 656); }
106 83
107 void draw_frame(SkCanvas* canvas, const SkRect& r) { 84 void draw_frame(SkCanvas* canvas, const SkRect& r) {
108 SkPaint paint; 85 SkPaint paint;
109 paint.setStyle(SkPaint::kStroke_Style); 86 paint.setStyle(SkPaint::kStroke_Style);
110 paint.setColor(SK_ColorRED); 87 paint.setColor(SK_ColorRED);
111 canvas->drawRect(r, paint); 88 canvas->drawRect(r, paint);
112 } 89 }
113 90
114 virtual void onDraw(SkCanvas* canvas) { 91 virtual void onDraw(SkCanvas* canvas) {
115 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { 92 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = {
116 draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text 93 draw_bitmap, draw_path, draw_paint, draw_text
117 }; 94 };
118 95
119 SkAutoTUnref<SkColorFilter> cf( 96 SkAutoTUnref<SkColorFilter> cf(
120 SkColorFilter::CreateModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_ Mode)); 97 SkColorFilter::CreateModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_ Mode));
121 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get ())); 98 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get ()));
122 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), 99 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)),
123 SkImageFilter::CropRect::kHasAll_CropEd ge); 100 SkImageFilter::CropRect::kHasAll_CropEd ge);
124 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, - 100, 10, 10)), 101 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, - 100, 10, 10)),
125 SkImageFilter::CropRect::kHasAll_CropE dge); 102 SkImageFilter::CropRect::kHasAll_CropE dge);
126 103
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 140 }
164 } 141 }
165 142
166 private: 143 private:
167 typedef GM INHERITED; 144 typedef GM INHERITED;
168 }; 145 };
169 146
170 /////////////////////////////////////////////////////////////////////////////// 147 ///////////////////////////////////////////////////////////////////////////////
171 148
172 DEF_GM( return new DropShadowImageFilterGM; ) 149 DEF_GM( return new DropShadowImageFilterGM; )
OLDNEW
« no previous file with comments | « bench/ImageBench.cpp ('k') | gm/imagefiltersbase.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698