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

Side by Side Diff: gm/drawbitmaprect.cpp

Issue 2286873002: drawBitmapRect() should not touch the CTM when mask filters are present (Closed)
Patch Set: GM cleanup Created 4 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
« no previous file with comments | « no previous file | src/core/SkBitmapDevice.cpp » ('j') | src/core/SkBitmapDevice.cpp » ('J')
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 "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 image->asLegacyBitmap(&tempBM, SkImage::kRO_LegacyBitmapMode); 87 image->asLegacyBitmap(&tempBM, SkImage::kRO_LegacyBitmapMode);
88 88
89 // Let backends know we won't change this, so they don't have to deep copy i t defensively. 89 // Let backends know we won't change this, so they don't have to deep copy i t defensively.
90 tempBM.setImmutable(); 90 tempBM.setImmutable();
91 *resultBM = tempBM; 91 *resultBM = tempBM;
92 92
93 return image; 93 return image;
94 } 94 }
95 95
96 static void canvasproc(SkCanvas* canvas, SkImage*, const SkBitmap& bm, const SkI Rect& srcR, 96 static void bitmapproc(SkCanvas* canvas, SkImage*, const SkBitmap& bm, const SkI Rect& srcR,
97 const SkRect& dstR) { 97 const SkRect& dstR, const SkPaint* paint) {
98 canvas->drawBitmapRect(bm, srcR, dstR, nullptr); 98 canvas->drawBitmapRect(bm, srcR, dstR, paint);
99 }
100
101 static void bitmapsubsetproc(SkCanvas* canvas, SkImage*, const SkBitmap& bm, con st SkIRect& srcR,
102 const SkRect& dstR, const SkPaint* paint) {
103 if (!bm.bounds().contains(srcR)) {
104 bitmapproc(canvas, nullptr, bm, srcR, dstR, paint);
105 return;
106 }
107
108 SkBitmap subset;
109 if (bm.extractSubset(&subset, srcR)) {
110 canvas->drawBitmapRect(subset, dstR, paint);
111 }
99 } 112 }
100 113
101 static void imageproc(SkCanvas* canvas, SkImage* image, const SkBitmap&, const S kIRect& srcR, 114 static void imageproc(SkCanvas* canvas, SkImage* image, const SkBitmap&, const S kIRect& srcR,
102 const SkRect& dstR) { 115 const SkRect& dstR, const SkPaint* paint) {
103 canvas->drawImageRect(image, srcR, dstR, nullptr); 116 canvas->drawImageRect(image, srcR, dstR, paint);
104 } 117 }
105 118
106 typedef void DrawRectRectProc(SkCanvas*, SkImage*, const SkBitmap&, const SkIRec t&, const SkRect&); 119 static void imagesubsetproc(SkCanvas* canvas, SkImage* image, const SkBitmap& bm ,
120 const SkIRect& srcR, const SkRect& dstR, const SkPai nt* paint) {
121 if (!image->bounds().contains(srcR)) {
122 imageproc(canvas, image, bm, srcR, dstR, paint);
123 return;
124 }
125
126 if (sk_sp<SkImage> subset = image->makeSubset(srcR)) {
127 canvas->drawImageRect(subset, dstR, paint);
128 }
129 }
130
131 typedef void DrawRectRectProc(SkCanvas*, SkImage*, const SkBitmap&, const SkIRec t&, const SkRect&,
132 const SkPaint*);
107 133
108 static const int gSize = 1024; 134 static const int gSize = 1024;
109 static const int gBmpSize = 2048; 135 static const int gBmpSize = 2048;
110 136
111 class DrawBitmapRectGM : public skiagm::GM { 137 class DrawBitmapRectGM : public skiagm::GM {
112 public: 138 public:
113 DrawBitmapRectGM(DrawRectRectProc proc, const char suffix[]) : fProc(proc) { 139 DrawBitmapRectGM(DrawRectRectProc proc, const char suffix[]) : fProc(proc) {
114 fName.set("drawbitmaprect"); 140 fName.set("drawbitmaprect");
115 if (suffix) { 141 if (suffix) {
116 fName.append(suffix); 142 fName.append(suffix);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 canvas->drawText(title.c_str(), title.size(), 0, 183 canvas->drawText(title.c_str(), title.size(), 0,
158 titleHeight, blackPaint); 184 titleHeight, blackPaint);
159 185
160 canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight); 186 canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight);
161 int rowCount = 0; 187 int rowCount = 0;
162 canvas->save(); 188 canvas->save();
163 for (int w = 1; w <= kMaxSrcRectSize; w *= 4) { 189 for (int w = 1; w <= kMaxSrcRectSize; w *= 4) {
164 for (int h = 1; h <= kMaxSrcRectSize; h *= 4) { 190 for (int h = 1; h <= kMaxSrcRectSize; h *= 4) {
165 191
166 SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSiz e - h) / 2, w, h); 192 SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSiz e - h) / 2, w, h);
167 fProc(canvas, fImage.get(), fLargeBitmap, srcRect, dstRect); 193 fProc(canvas, fImage.get(), fLargeBitmap, srcRect, dstRect, null ptr);
168 194
169 SkString label; 195 SkString label;
170 label.appendf("%d x %d", w, h); 196 label.appendf("%d x %d", w, h);
171 blackPaint.setAntiAlias(true); 197 blackPaint.setAntiAlias(true);
172 blackPaint.setStyle(SkPaint::kFill_Style); 198 blackPaint.setStyle(SkPaint::kFill_Style);
173 blackPaint.setTextSize(SK_Scalar1 * 10); 199 blackPaint.setTextSize(SK_Scalar1 * 10);
174 SkScalar baseline = dstRect.height() + 200 SkScalar baseline = dstRect.height() +
175 blackPaint.getTextSize() + SK_Scalar1 * 3; 201 blackPaint.getTextSize() + SK_Scalar1 * 3;
176 canvas->drawText(label.c_str(), label.size(), 202 canvas->drawText(label.c_str(), label.size(),
177 0, baseline, 203 0, baseline,
(...skipping 21 matching lines...) Expand all
199 SkPaint paint; 225 SkPaint paint;
200 SkBitmap bm; 226 SkBitmap bm;
201 227
202 bm = make_chessbm(5, 5); 228 bm = make_chessbm(5, 5);
203 paint.setFilterQuality(kLow_SkFilterQuality); 229 paint.setFilterQuality(kLow_SkFilterQuality);
204 230
205 srcRect.setXYWH(1, 1, 3, 3); 231 srcRect.setXYWH(1, 1, 3, 3);
206 paint.setMaskFilter(SkBlurMaskFilter::Make( 232 paint.setMaskFilter(SkBlurMaskFilter::Make(
207 kNormal_SkBlurStyle, 233 kNormal_SkBlurStyle,
208 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)), 234 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
209 SkBlurMaskFilter::kHighQuality_BlurFlag | 235 SkBlurMaskFilter::kHighQuality_BlurFlag));
210 SkBlurMaskFilter::kIgnoreTransform_BlurFlag)); 236
211 canvas->drawBitmapRect(bm, srcRect, dstRect, &paint); 237 sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
238 fProc(canvas, image.get(), bm, srcRect, dstRect, &paint);
212 } 239 }
213 } 240 }
214 241
215 private: 242 private:
216 typedef skiagm::GM INHERITED; 243 typedef skiagm::GM INHERITED;
217 }; 244 };
218 245
219 DEF_GM( return new DrawBitmapRectGM(canvasproc, nullptr); ) 246 DEF_GM( return new DrawBitmapRectGM(bitmapproc , nullptr); )
220 DEF_GM( return new DrawBitmapRectGM(imageproc, "-imagerect"); ) 247 DEF_GM( return new DrawBitmapRectGM(bitmapsubsetproc, "-subset"); )
248 DEF_GM( return new DrawBitmapRectGM(imageproc , "-imagerect"); )
249 DEF_GM( return new DrawBitmapRectGM(imagesubsetproc , "-imagerect-subset"); )
OLDNEW
« no previous file with comments | « no previous file | src/core/SkBitmapDevice.cpp » ('j') | src/core/SkBitmapDevice.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698