Index: gm/blurrect.cpp |
diff --git a/gm/blurrect.cpp b/gm/blurrect.cpp |
index 6b7354071b8b359a54ab8e15e3d5291ce823d3bf..4f158157484a007d720d9b2296ae96cf00f5ba02 100644 |
--- a/gm/blurrect.cpp |
+++ b/gm/blurrect.cpp |
@@ -169,31 +169,11 @@ private: |
typedef GM INHERITED; |
}; |
+DEF_SIMPLE_GM(blurrect_gallery, canvas, 1200, 1024) { |
+ const int fGMWidth = 1200; |
+ const int fPadding = 10; |
+ const int fMargin = 100; |
-class BlurRectDirectGM : public skiagm::GM { |
- SkString fName; |
- int fGMWidth, fGMHeight; |
- int fPadding, fMargin; |
-public: |
- BlurRectDirectGM(const char name[]) |
- : fName(name), |
- fGMWidth(1200), |
- fGMHeight(1024), |
- fPadding(10), |
- fMargin(100) |
- { |
- } |
- |
-protected: |
- virtual SkString onShortName() { |
- return fName; |
- } |
- |
- virtual SkISize onISize() { |
- return SkISize::Make(fGMWidth, fGMHeight); |
- } |
- |
- virtual void onDraw(SkCanvas* canvas) { |
const int widths[] = {25, 5, 5, 100, 150, 25}; |
const int heights[] = {100, 100, 5, 25, 150, 25}; |
const SkBlurStyle styles[] = {kNormal_SkBlurStyle, kInner_SkBlurStyle, kOuter_SkBlurStyle}; |
@@ -244,177 +224,8 @@ protected: |
} |
} |
} |
- } |
- |
-private: |
- typedef GM INHERITED; |
-}; |
- |
-class BlurRectCompareGM : public skiagm::GM { |
- SkString fName; |
- unsigned int fRectWidth, fRectHeight; |
- SkScalar fRadius; |
- SkBlurStyle fStyle; |
-public: |
- BlurRectCompareGM(const char name[], unsigned int rectWidth, |
- unsigned int rectHeight, float radius, |
- SkBlurStyle style) |
- : fName(name) |
- , fRectWidth(rectWidth) |
- , fRectHeight(rectHeight) |
- , fRadius(radius) |
- , fStyle(style) { |
- } |
- int width() const { |
- return fRectWidth; |
- } |
- int height() const { |
- return fRectHeight; |
- } |
- SkScalar radius() const { |
- return fRadius; |
- } |
- SkBlurStyle style() const { |
- return fStyle; |
- } |
- |
-protected: |
- virtual SkString onShortName() { |
- return fName; |
- } |
- |
- virtual SkISize onISize() { |
- return SkISize::Make(640, 480); |
- } |
- |
- virtual bool makeMask(SkMask *m, const SkRect&) = 0; |
- |
- virtual void onDraw(SkCanvas* canvas) { |
- SkRect r; |
- r.setWH(SkIntToScalar(fRectWidth), SkIntToScalar(fRectHeight)); |
- |
- SkISize canvas_size = canvas->getDeviceSize(); |
- int center_x = (canvas_size.fWidth - (int)(r.width()))/2; |
- int center_y = (canvas_size.fHeight - (int)(r.height()))/2; |
- |
- SkMask mask; |
- |
- if (!this->makeMask(&mask, r)) { |
- SkPaint paint; |
- r.offset( SkIntToScalar(center_x), SkIntToScalar(center_y) ); |
- canvas->drawRect(r,paint); |
- return; |
- } |
- SkAutoMaskFreeImage amfi(mask.fImage); |
- |
- SkBitmap bm; |
- bm.installMaskPixels(mask); |
- |
- center_x = (canvas_size.fWidth - mask.fBounds.width())/2; |
- center_y = (canvas_size.fHeight - mask.fBounds.height())/2; |
- |
- canvas->drawBitmap(bm, SkIntToScalar(center_x), SkIntToScalar(center_y), nullptr); |
- } |
- |
-private: |
- typedef GM INHERITED; |
-}; |
- |
-class BlurRectFastGM: public BlurRectCompareGM { |
-public: |
- BlurRectFastGM(const char name[], unsigned int rectWidth, |
- unsigned int rectHeight, float blurRadius, |
- SkBlurStyle style) : |
- INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
- } |
- |
-protected: |
- bool makeMask(SkMask *m, const SkRect& r) override { |
- return SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(this->radius()), |
- m, r, this->style()); |
- } |
-private: |
- typedef BlurRectCompareGM INHERITED; |
-}; |
- |
-class BlurRectSlowGM: public BlurRectCompareGM { |
-public: |
- BlurRectSlowGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
- float blurRadius, SkBlurStyle style) |
- : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
- } |
- |
-protected: |
- bool makeMask(SkMask *m, const SkRect& r) override { |
- SkMask src; |
- r.roundOut(&src.fBounds); |
- src.fBounds.offset(-src.fBounds.fLeft, -src.fBounds.fTop); // move to origin |
- src.fFormat = SkMask::kA8_Format; |
- src.fRowBytes = src.fBounds.width(); |
- src.fImage = SkMask::AllocImage(src.computeTotalImageSize()); |
- SkAutoMaskFreeImage amfi(src.fImage); |
- |
- memset(src.fImage, 0xff, src.computeTotalImageSize()); |
- |
- return SkBlurMask::BoxBlur(m, src, |
- SkBlurMask::ConvertRadiusToSigma(this->radius()), |
- this->style(), this->getQuality()); |
- } |
- |
- virtual SkBlurQuality getQuality() { |
- return kHigh_SkBlurQuality; |
- } |
-private: |
- typedef BlurRectCompareGM INHERITED; |
-}; |
- |
-class BlurRectSlowLowGM: public BlurRectSlowGM { |
-public: |
- BlurRectSlowLowGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
- float blurRadius, SkBlurStyle style) |
- : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
- } |
- |
-protected: |
- SkBlurQuality getQuality() override { |
- return kLow_SkBlurQuality; |
- } |
-private: |
- typedef BlurRectSlowGM INHERITED; |
-}; |
- |
-class BlurRectGroundTruthGM: public BlurRectCompareGM { |
-public: |
- BlurRectGroundTruthGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
- float blurRadius, SkBlurStyle style) |
- : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
- } |
- |
-protected: |
- bool makeMask(SkMask *m, const SkRect& r) override { |
- SkMask src; |
- r.roundOut(&src.fBounds); |
- src.fBounds.offset(-src.fBounds.fLeft, -src.fBounds.fTop); // move to origin |
- src.fFormat = SkMask::kA8_Format; |
- src.fRowBytes = src.fBounds.width(); |
- src.fImage = SkMask::AllocImage(src.computeTotalImageSize()); |
- SkAutoMaskFreeImage amfi(src.fImage); |
- |
- memset(src.fImage, 0xff, src.computeTotalImageSize()); |
- |
- return SkBlurMask::BlurGroundTruth(SkBlurMask::ConvertRadiusToSigma(this->radius()), |
- m, src, this->style()); |
- } |
- |
- virtual SkBlurQuality getQuality() { |
- return kHigh_SkBlurQuality; |
- } |
-private: |
- typedef BlurRectCompareGM INHERITED; |
-}; |
- |
+} |
////////////////////////////////////////////////////////////////////////////// |
DEF_GM(return new BlurRectGM("blurrects", 0xFF);) |
-DEF_GM(return new BlurRectDirectGM("blurrect_gallery");) |