| OLD | NEW |
| 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 Loading... |
| 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, NULL); | 84 canvas->drawBitmapRect(bm, srcR, dstR); |
| 85 } | 85 } |
| 86 | 86 |
| 87 static void imageproc(SkCanvas* canvas, SkImage* image, const SkBitmap&, const S
kIRect& srcR, | 87 static void imageproc(SkCanvas* canvas, SkImage* image, const SkBitmap&, const S
kIRect* srcIR, |
| 88 const SkRect& dstR) { | 88 const SkRect& dstR) { |
| 89 canvas->drawImageRect(image, srcR, dstR, NULL); | 89 SkRect storage, *srcR = NULL; |
| 90 if (srcIR) { |
| 91 storage.set(*srcIR); |
| 92 srcR = &storage; |
| 93 } |
| 94 canvas->drawImageRect(image, srcR, dstR); |
| 90 } | 95 } |
| 91 | 96 |
| 92 static void imagescaleproc(SkCanvas* canvas, SkImage* image, const SkBitmap&, co
nst SkIRect& srcIR, | 97 static void imagescaleproc(SkCanvas* canvas, SkImage* image, const SkBitmap&, co
nst SkIRect* srcIR, |
| 93 const SkRect& dstR) { | 98 const SkRect& dstR) { |
| 94 const int newW = SkScalarRoundToInt(dstR.width()); | 99 const int newW = SkScalarRoundToInt(dstR.width()); |
| 95 const int newH = SkScalarRoundToInt(dstR.height()); | 100 const int newH = SkScalarRoundToInt(dstR.height()); |
| 96 SkAutoTUnref<SkImage> newImage(image->newImage(newW, newH, &srcIR)); | 101 SkAutoTUnref<SkImage> newImage(image->newImage(newW, newH, srcIR)); |
| 97 | 102 |
| 98 #ifdef SK_DEBUG | 103 #ifdef SK_DEBUG |
| 99 const SkIRect baseR = SkIRect::MakeWH(image->width(), image->height()); | 104 const SkIRect baseR = SkIRect::MakeWH(image->width(), image->height()); |
| 100 const bool containsSubset = baseR.contains(srcIR); | 105 const bool containsSubset = !srcIR || baseR.contains(*srcIR); |
| 101 #endif | 106 #endif |
| 102 | 107 |
| 103 if (newImage) { | 108 if (newImage) { |
| 104 SkASSERT(containsSubset); | 109 SkASSERT(containsSubset); |
| 105 canvas->drawImage(newImage, dstR.x(), dstR.y()); | 110 canvas->drawImage(newImage, dstR.x(), dstR.y()); |
| 106 } else { | 111 } else { |
| 107 // newImage() does not support subsets that are not contained by the ori
ginal | 112 // newImage() does not support subsets that are not contained by the ori
ginal |
| 108 // but drawImageRect does, so we just draw an X in its place to indicate
that we are | 113 // but drawImageRect does, so we just draw an X in its place to indicate
that we are |
| 109 // deliberately not drawing here. | 114 // deliberately not drawing here. |
| 110 SkASSERT(!containsSubset); | 115 SkASSERT(!containsSubset); |
| 111 SkPaint paint; | 116 SkPaint paint; |
| 112 paint.setStyle(SkPaint::kStroke_Style); | 117 paint.setStyle(SkPaint::kStroke_Style); |
| 113 paint.setStrokeWidth(4); | 118 paint.setStrokeWidth(4); |
| 114 canvas->drawLine(4, 4, newW - 4.0f, newH - 4.0f, paint); | 119 canvas->drawLine(4, 4, newW - 4.0f, newH - 4.0f, paint); |
| 115 canvas->drawLine(4, newH - 4.0f, newW - 4.0f, 4, paint); | 120 canvas->drawLine(4, newH - 4.0f, newW - 4.0f, 4, paint); |
| 116 } | 121 } |
| 117 } | 122 } |
| 118 | 123 |
| 119 typedef void DrawRectRectProc(SkCanvas*, SkImage*, const SkBitmap&, const SkIRec
t&, const SkRect&); | 124 typedef void DrawRectRectProc(SkCanvas*, SkImage*, const SkBitmap&, const SkIRec
t*, const SkRect&); |
| 120 | 125 |
| 121 static const int gSize = 1024; | 126 static const int gSize = 1024; |
| 122 static const int gBmpSize = 2048; | 127 static const int gBmpSize = 2048; |
| 123 | 128 |
| 124 class DrawBitmapRectGM : public skiagm::GM { | 129 class DrawBitmapRectGM : public skiagm::GM { |
| 125 public: | 130 public: |
| 126 DrawBitmapRectGM(DrawRectRectProc proc, const char suffix[]) : fProc(proc) { | 131 DrawBitmapRectGM(DrawRectRectProc proc, const char suffix[]) : fProc(proc) { |
| 127 fName.set("drawbitmaprect"); | 132 fName.set("drawbitmaprect"); |
| 128 if (suffix) { | 133 if (suffix) { |
| 129 fName.append(suffix); | 134 fName.append(suffix); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 canvas->drawText(title.c_str(), title.size(), 0, | 174 canvas->drawText(title.c_str(), title.size(), 0, |
| 170 titleHeight, blackPaint); | 175 titleHeight, blackPaint); |
| 171 | 176 |
| 172 canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight); | 177 canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight); |
| 173 int rowCount = 0; | 178 int rowCount = 0; |
| 174 canvas->save(); | 179 canvas->save(); |
| 175 for (int w = 1; w <= kMaxSrcRectSize; w *= 4) { | 180 for (int w = 1; w <= kMaxSrcRectSize; w *= 4) { |
| 176 for (int h = 1; h <= kMaxSrcRectSize; h *= 4) { | 181 for (int h = 1; h <= kMaxSrcRectSize; h *= 4) { |
| 177 | 182 |
| 178 SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSiz
e - h) / 2, w, h); | 183 SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSiz
e - h) / 2, w, h); |
| 179 fProc(canvas, fImage, fLargeBitmap, srcRect, dstRect); | 184 fProc(canvas, fImage, fLargeBitmap, &srcRect, dstRect); |
| 180 | 185 |
| 181 SkString label; | 186 SkString label; |
| 182 label.appendf("%d x %d", w, h); | 187 label.appendf("%d x %d", w, h); |
| 183 blackPaint.setAntiAlias(true); | 188 blackPaint.setAntiAlias(true); |
| 184 blackPaint.setStyle(SkPaint::kFill_Style); | 189 blackPaint.setStyle(SkPaint::kFill_Style); |
| 185 blackPaint.setTextSize(SK_Scalar1 * 10); | 190 blackPaint.setTextSize(SK_Scalar1 * 10); |
| 186 SkScalar baseline = dstRect.height() + | 191 SkScalar baseline = dstRect.height() + |
| 187 blackPaint.getTextSize() + SK_Scalar1 * 3; | 192 blackPaint.getTextSize() + SK_Scalar1 * 3; |
| 188 canvas->drawText(label.c_str(), label.size(), | 193 canvas->drawText(label.c_str(), label.size(), |
| 189 0, baseline, | 194 0, baseline, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 214 bm = make_chessbm(5, 5); | 219 bm = make_chessbm(5, 5); |
| 215 paint.setFilterQuality(kLow_SkFilterQuality); | 220 paint.setFilterQuality(kLow_SkFilterQuality); |
| 216 | 221 |
| 217 srcRect.setXYWH(1, 1, 3, 3); | 222 srcRect.setXYWH(1, 1, 3, 3); |
| 218 SkMaskFilter* mf = SkBlurMaskFilter::Create( | 223 SkMaskFilter* mf = SkBlurMaskFilter::Create( |
| 219 kNormal_SkBlurStyle, | 224 kNormal_SkBlurStyle, |
| 220 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)), | 225 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)), |
| 221 SkBlurMaskFilter::kHighQuality_BlurFlag | | 226 SkBlurMaskFilter::kHighQuality_BlurFlag | |
| 222 SkBlurMaskFilter::kIgnoreTransform_BlurFlag); | 227 SkBlurMaskFilter::kIgnoreTransform_BlurFlag); |
| 223 paint.setMaskFilter(mf)->unref(); | 228 paint.setMaskFilter(mf)->unref(); |
| 224 canvas->drawBitmapRect(bm, srcRect, dstRect, &paint); | 229 canvas->drawBitmapRect(bm, &srcRect, dstRect, &paint); |
| 225 } | 230 } |
| 226 } | 231 } |
| 227 | 232 |
| 228 private: | 233 private: |
| 229 typedef skiagm::GM INHERITED; | 234 typedef skiagm::GM INHERITED; |
| 230 }; | 235 }; |
| 231 | 236 |
| 232 DEF_GM( return new DrawBitmapRectGM(canvasproc, NULL); ) | 237 DEF_GM( return new DrawBitmapRectGM(canvasproc, NULL); ) |
| 233 DEF_GM( return new DrawBitmapRectGM(imageproc, "-imagerect"); ) | 238 DEF_GM( return new DrawBitmapRectGM(imageproc, "-imagerect"); ) |
| 234 DEF_GM( return new DrawBitmapRectGM(imagescaleproc, "-imagescale"); ) | 239 DEF_GM( return new DrawBitmapRectGM(imagescaleproc, "-imagescale"); ) |
| OLD | NEW |