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

Side by Side Diff: gm/imagefilterscropped.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 | « gm/imagefiltersbase.cpp ('k') | gm/spritebitmap.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 2011 Google Inc. 2 * Copyright 2011 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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 SkBitmap bm; 58 SkBitmap bm;
59 bm.allocN32Pixels(bounds.width(), bounds.height()); 59 bm.allocN32Pixels(bounds.width(), bounds.height());
60 bm.eraseColor(SK_ColorTRANSPARENT); 60 bm.eraseColor(SK_ColorTRANSPARENT);
61 SkCanvas c(bm); 61 SkCanvas c(bm);
62 draw_path(&c, r, nullptr); 62 draw_path(&c, r, nullptr);
63 63
64 paint.setImageFilter(imf); 64 paint.setImageFilter(imf);
65 canvas->drawBitmap(bm, 0, 0, &paint); 65 canvas->drawBitmap(bm, 0, 0, &paint);
66 } 66 }
67 67
68 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
69 SkPaint paint;
70
71 SkIRect bounds;
72 r.roundOut(&bounds);
73
74 SkBitmap bm;
75 bm.allocN32Pixels(bounds.width(), bounds.height());
76 bm.eraseColor(SK_ColorRED);
77 SkCanvas c(bm);
78
79 SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44);
80 paint.setColor(SK_ColorGREEN);
81 c.drawRect(SkRect::Make(cropRect), paint);
82
83 paint.setImageFilter(imf);
84 SkPoint loc = { r.fLeft, r.fTop };
85 canvas->getTotalMatrix().mapPoints(&loc, 1);
86 canvas->drawSprite(bm,
87 SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY),
88 &paint);
89 }
90
91 /////////////////////////////////////////////////////////////////////////////// 68 ///////////////////////////////////////////////////////////////////////////////
92 69
93 class ImageFiltersCroppedGM : public skiagm::GM { 70 class ImageFiltersCroppedGM : public skiagm::GM {
94 public: 71 public:
95 ImageFiltersCroppedGM () {} 72 ImageFiltersCroppedGM () {}
96 73
97 protected: 74 protected:
98 virtual SkString onShortName() override { 75 virtual SkString onShortName() override {
99 return SkString("imagefilterscropped"); 76 return SkString("imagefilterscropped");
100 } 77 }
(...skipping 27 matching lines...) Expand all
128 paint.setColor(SK_ColorRED); 105 paint.setColor(SK_ColorRED);
129 canvas->drawRect(r, paint); 106 canvas->drawRect(r, paint);
130 } 107 }
131 108
132 virtual void onOnceBeforeDraw() override{ 109 virtual void onOnceBeforeDraw() override{
133 make_checkerboard(); 110 make_checkerboard();
134 } 111 }
135 112
136 virtual void onDraw(SkCanvas* canvas) override { 113 virtual void onDraw(SkCanvas* canvas) override {
137 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { 114 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = {
138 draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text 115 draw_bitmap, draw_path, draw_paint, draw_text
139 }; 116 };
140 117
141 SkAutoTUnref<SkColorFilter> cf( 118 SkAutoTUnref<SkColorFilter> cf(
142 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mod e)); 119 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mod e));
143 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); 120 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge);
144 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, - 100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge); 121 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, - 100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge);
145 122
146 SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create( 123 SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create(
147 SkIntToScalar(-10), SkIntToScalar(-10))); 124 SkIntToScalar(-10), SkIntToScalar(-10)));
148 125
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 168 }
192 169
193 private: 170 private:
194 SkBitmap fCheckerboard; 171 SkBitmap fCheckerboard;
195 typedef GM INHERITED; 172 typedef GM INHERITED;
196 }; 173 };
197 174
198 /////////////////////////////////////////////////////////////////////////////// 175 ///////////////////////////////////////////////////////////////////////////////
199 176
200 DEF_GM( return new ImageFiltersCroppedGM; ) 177 DEF_GM( return new ImageFiltersCroppedGM; )
OLDNEW
« no previous file with comments | « gm/imagefiltersbase.cpp ('k') | gm/spritebitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698