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

Side by Side Diff: gm/drawbitmaprect.cpp

Issue 1240753003: Revert[2] of guard to remove DrawBitmapRectFlags (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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 | « gm/bitmaprect.cpp ('k') | gm/tallstretchedbitmaps.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 "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 canvas.drawRect(rect, paint); 72 canvas.drawRect(rect, paint);
73 rect.inset(wScalar / 8, hScalar / 8); 73 rect.inset(wScalar / 8, hScalar / 8);
74 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4); 74 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
75 } 75 }
76 // Let backends know we won't change this, so they don't have to deep copy i t defensively. 76 // Let backends know we won't change this, so they don't have to deep copy i t defensively.
77 bm->setImmutable(); 77 bm->setImmutable();
78 78
79 return image_from_bitmap(*bm); 79 return image_from_bitmap(*bm);
80 } 80 }
81 81
82 static void canvasproc(SkCanvas* canvas, SkImage*, const SkBitmap& bm, const SkI Rect* srcR, 82 static void canvasproc(SkCanvas* canvas, SkImage*, const SkBitmap& bm, const SkI Rect& srcR,
83 const SkRect& dstR) { 83 const SkRect& dstR) {
84 canvas->drawBitmapRect(bm, srcR, dstR); 84 canvas->drawBitmapRect(bm, srcR, dstR, NULL);
85 } 85 }
86 86
87 static void imageproc(SkCanvas* canvas, SkImage* image, const SkBitmap&, const S kIRect* srcIR, 87 static void imageproc(SkCanvas* canvas, SkImage* image, const SkBitmap&, const S kIRect& srcR,
88 const SkRect& dstR) { 88 const SkRect& dstR) {
89 SkRect storage, *srcR = NULL; 89 canvas->drawImageRect(image, srcR, dstR, NULL);
90 if (srcIR) {
91 storage.set(*srcIR);
92 srcR = &storage;
93 }
94 canvas->drawImageRect(image, srcR, dstR);
95 } 90 }
96 91
97 static void imagescaleproc(SkCanvas* canvas, SkImage* image, const SkBitmap&, co nst SkIRect* srcIR, 92 static void imagescaleproc(SkCanvas* canvas, SkImage* image, const SkBitmap&, co nst SkIRect& srcIR,
98 const SkRect& dstR) { 93 const SkRect& dstR) {
99 const int newW = SkScalarRoundToInt(dstR.width()); 94 const int newW = SkScalarRoundToInt(dstR.width());
100 const int newH = SkScalarRoundToInt(dstR.height()); 95 const int newH = SkScalarRoundToInt(dstR.height());
101 SkAutoTUnref<SkImage> newImage(image->newImage(newW, newH, srcIR)); 96 SkAutoTUnref<SkImage> newImage(image->newImage(newW, newH, &srcIR));
102 97
103 #ifdef SK_DEBUG 98 #ifdef SK_DEBUG
104 const SkIRect baseR = SkIRect::MakeWH(image->width(), image->height()); 99 const SkIRect baseR = SkIRect::MakeWH(image->width(), image->height());
105 const bool containsSubset = !srcIR || baseR.contains(*srcIR); 100 const bool containsSubset = baseR.contains(srcIR);
106 #endif 101 #endif
107 102
108 if (newImage) { 103 if (newImage) {
109 SkASSERT(containsSubset); 104 SkASSERT(containsSubset);
110 canvas->drawImage(newImage, dstR.x(), dstR.y()); 105 canvas->drawImage(newImage, dstR.x(), dstR.y());
111 } else { 106 } else {
112 // newImage() does not support subsets that are not contained by the ori ginal 107 // newImage() does not support subsets that are not contained by the ori ginal
113 // but drawImageRect does, so we just draw an X in its place to indicate that we are 108 // but drawImageRect does, so we just draw an X in its place to indicate that we are
114 // deliberately not drawing here. 109 // deliberately not drawing here.
115 SkASSERT(!containsSubset); 110 SkASSERT(!containsSubset);
116 SkPaint paint; 111 SkPaint paint;
117 paint.setStyle(SkPaint::kStroke_Style); 112 paint.setStyle(SkPaint::kStroke_Style);
118 paint.setStrokeWidth(4); 113 paint.setStrokeWidth(4);
119 canvas->drawLine(4, 4, newW - 4.0f, newH - 4.0f, paint); 114 canvas->drawLine(4, 4, newW - 4.0f, newH - 4.0f, paint);
120 canvas->drawLine(4, newH - 4.0f, newW - 4.0f, 4, paint); 115 canvas->drawLine(4, newH - 4.0f, newW - 4.0f, 4, paint);
121 } 116 }
122 } 117 }
123 118
124 typedef void DrawRectRectProc(SkCanvas*, SkImage*, const SkBitmap&, const SkIRec t*, const SkRect&); 119 typedef void DrawRectRectProc(SkCanvas*, SkImage*, const SkBitmap&, const SkIRec t&, const SkRect&);
125 120
126 static const int gSize = 1024; 121 static const int gSize = 1024;
127 static const int gBmpSize = 2048; 122 static const int gBmpSize = 2048;
128 123
129 class DrawBitmapRectGM : public skiagm::GM { 124 class DrawBitmapRectGM : public skiagm::GM {
130 public: 125 public:
131 DrawBitmapRectGM(DrawRectRectProc proc, const char suffix[]) : fProc(proc) { 126 DrawBitmapRectGM(DrawRectRectProc proc, const char suffix[]) : fProc(proc) {
132 fName.set("drawbitmaprect"); 127 fName.set("drawbitmaprect");
133 if (suffix) { 128 if (suffix) {
134 fName.append(suffix); 129 fName.append(suffix);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 canvas->drawText(title.c_str(), title.size(), 0, 169 canvas->drawText(title.c_str(), title.size(), 0,
175 titleHeight, blackPaint); 170 titleHeight, blackPaint);
176 171
177 canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight); 172 canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight);
178 int rowCount = 0; 173 int rowCount = 0;
179 canvas->save(); 174 canvas->save();
180 for (int w = 1; w <= kMaxSrcRectSize; w *= 4) { 175 for (int w = 1; w <= kMaxSrcRectSize; w *= 4) {
181 for (int h = 1; h <= kMaxSrcRectSize; h *= 4) { 176 for (int h = 1; h <= kMaxSrcRectSize; h *= 4) {
182 177
183 SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSiz e - h) / 2, w, h); 178 SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSiz e - h) / 2, w, h);
184 fProc(canvas, fImage, fLargeBitmap, &srcRect, dstRect); 179 fProc(canvas, fImage, fLargeBitmap, srcRect, dstRect);
185 180
186 SkString label; 181 SkString label;
187 label.appendf("%d x %d", w, h); 182 label.appendf("%d x %d", w, h);
188 blackPaint.setAntiAlias(true); 183 blackPaint.setAntiAlias(true);
189 blackPaint.setStyle(SkPaint::kFill_Style); 184 blackPaint.setStyle(SkPaint::kFill_Style);
190 blackPaint.setTextSize(SK_Scalar1 * 10); 185 blackPaint.setTextSize(SK_Scalar1 * 10);
191 SkScalar baseline = dstRect.height() + 186 SkScalar baseline = dstRect.height() +
192 blackPaint.getTextSize() + SK_Scalar1 * 3; 187 blackPaint.getTextSize() + SK_Scalar1 * 3;
193 canvas->drawText(label.c_str(), label.size(), 188 canvas->drawText(label.c_str(), label.size(),
194 0, baseline, 189 0, baseline,
(...skipping 24 matching lines...) Expand all
219 bm = make_chessbm(5, 5); 214 bm = make_chessbm(5, 5);
220 paint.setFilterQuality(kLow_SkFilterQuality); 215 paint.setFilterQuality(kLow_SkFilterQuality);
221 216
222 srcRect.setXYWH(1, 1, 3, 3); 217 srcRect.setXYWH(1, 1, 3, 3);
223 SkMaskFilter* mf = SkBlurMaskFilter::Create( 218 SkMaskFilter* mf = SkBlurMaskFilter::Create(
224 kNormal_SkBlurStyle, 219 kNormal_SkBlurStyle,
225 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)), 220 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
226 SkBlurMaskFilter::kHighQuality_BlurFlag | 221 SkBlurMaskFilter::kHighQuality_BlurFlag |
227 SkBlurMaskFilter::kIgnoreTransform_BlurFlag); 222 SkBlurMaskFilter::kIgnoreTransform_BlurFlag);
228 paint.setMaskFilter(mf)->unref(); 223 paint.setMaskFilter(mf)->unref();
229 canvas->drawBitmapRect(bm, &srcRect, dstRect, &paint); 224 canvas->drawBitmapRect(bm, srcRect, dstRect, &paint);
230 } 225 }
231 } 226 }
232 227
233 private: 228 private:
234 typedef skiagm::GM INHERITED; 229 typedef skiagm::GM INHERITED;
235 }; 230 };
236 231
237 DEF_GM( return new DrawBitmapRectGM(canvasproc, NULL); ) 232 DEF_GM( return new DrawBitmapRectGM(canvasproc, NULL); )
238 DEF_GM( return new DrawBitmapRectGM(imageproc, "-imagerect"); ) 233 DEF_GM( return new DrawBitmapRectGM(imageproc, "-imagerect"); )
239 DEF_GM( return new DrawBitmapRectGM(imagescaleproc, "-imagescale"); ) 234 DEF_GM( return new DrawBitmapRectGM(imagescaleproc, "-imagescale"); )
OLDNEW
« no previous file with comments | « gm/bitmaprect.cpp ('k') | gm/tallstretchedbitmaps.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698