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

Side by Side Diff: gm/dropshadowimagefilter.cpp

Issue 1529803004: Revert of remove 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
70 /////////////////////////////////////////////////////////////////////////////// 93 ///////////////////////////////////////////////////////////////////////////////
71 94
72 class DropShadowImageFilterGM : public skiagm::GM { 95 class DropShadowImageFilterGM : public skiagm::GM {
73 public: 96 public:
74 DropShadowImageFilterGM () {} 97 DropShadowImageFilterGM () {}
75 98
76 protected: 99 protected:
77 100
78 virtual SkString onShortName() { 101 virtual SkString onShortName() {
79 return SkString("dropshadowimagefilter"); 102 return SkString("dropshadowimagefilter");
80 } 103 }
81 104
82 virtual SkISize onISize() { return SkISize::Make(400, 656); } 105 virtual SkISize onISize() { return SkISize::Make(400, 656); }
83 106
84 void draw_frame(SkCanvas* canvas, const SkRect& r) { 107 void draw_frame(SkCanvas* canvas, const SkRect& r) {
85 SkPaint paint; 108 SkPaint paint;
86 paint.setStyle(SkPaint::kStroke_Style); 109 paint.setStyle(SkPaint::kStroke_Style);
87 paint.setColor(SK_ColorRED); 110 paint.setColor(SK_ColorRED);
88 canvas->drawRect(r, paint); 111 canvas->drawRect(r, paint);
89 } 112 }
90 113
91 virtual void onDraw(SkCanvas* canvas) { 114 virtual void onDraw(SkCanvas* canvas) {
92 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { 115 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = {
93 draw_bitmap, draw_path, draw_paint, draw_text 116 draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text
94 }; 117 };
95 118
96 SkAutoTUnref<SkColorFilter> cf( 119 SkAutoTUnref<SkColorFilter> cf(
97 SkColorFilter::CreateModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_ Mode)); 120 SkColorFilter::CreateModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_ Mode));
98 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get ())); 121 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get ()));
99 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), 122 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)),
100 SkImageFilter::CropRect::kHasAll_CropEd ge); 123 SkImageFilter::CropRect::kHasAll_CropEd ge);
101 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, - 100, 10, 10)), 124 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, - 100, 10, 10)),
102 SkImageFilter::CropRect::kHasAll_CropE dge); 125 SkImageFilter::CropRect::kHasAll_CropE dge);
103 126
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 163 }
141 } 164 }
142 165
143 private: 166 private:
144 typedef GM INHERITED; 167 typedef GM INHERITED;
145 }; 168 };
146 169
147 /////////////////////////////////////////////////////////////////////////////// 170 ///////////////////////////////////////////////////////////////////////////////
148 171
149 DEF_GM( return new DropShadowImageFilterGM; ) 172 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