diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-02-16 13:25:24 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-02-16 13:25:24 +0000 |
commit | e5b2af955b7d06815ddd405659ad62a2a8355ca3 (patch) | |
tree | 8c40834f5ae1be2503c049d583f06cbcb971d072 /gm | |
parent | 969588f0c9030d5a4942085a4b5a5ea7e8d2bc25 (diff) |
Store SkRRects in SkClipStack
BUG=skia:2181
R=robertphillips@google.com
Author: bsalomon@google.com
Review URL: https://codereview.chromium.org/163683002
git-svn-id: http://skia.googlecode.com/svn/trunk@13465 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm')
-rw-r--r-- | gm/complexclip2.cpp | 105 |
1 files changed, 69 insertions, 36 deletions
diff --git a/gm/complexclip2.cpp b/gm/complexclip2.cpp index 0e8e0bc116..2b94ffd661 100644 --- a/gm/complexclip2.cpp +++ b/gm/complexclip2.cpp @@ -15,8 +15,14 @@ namespace skiagm { class ComplexClip2GM : public GM { public: - ComplexClip2GM(bool doPaths, bool antiAlias) - : fDoPaths(doPaths) + enum Clip { + kRect_Clip, + kRRect_Clip, + kPath_Clip + }; + + ComplexClip2GM(Clip clip, bool antiAlias) + : fClip(clip) , fAntiAlias(antiAlias) { this->setBGColor(SkColorSetRGB(0xDD,0xA0,0xDD)); @@ -39,23 +45,28 @@ public: fHeight = yF - yA; fRects[0].set(xB, yB, xE, yE); - fPaths[0].addRoundRect(fRects[0], SkIntToScalar(5), SkIntToScalar(5)); + fRRects[0].setRectXY(fRects[0], 7, 7); + fPaths[0].addRoundRect(fRects[0], 5, 5); fRectColors[0] = SK_ColorRED; fRects[1].set(xA, yA, xD, yD); - fPaths[1].addRoundRect(fRects[1], SkIntToScalar(5), SkIntToScalar(5)); + fRRects[1].setRectXY(fRects[1], 7, 7); + fPaths[1].addRoundRect(fRects[1], 5, 5); fRectColors[1] = SK_ColorGREEN; fRects[2].set(xC, yA, xF, yD); - fPaths[2].addRoundRect(fRects[2], SkIntToScalar(5), SkIntToScalar(5)); + fRRects[2].setRectXY(fRects[2], 7, 7); + fPaths[2].addRoundRect(fRects[2], 5, 5); fRectColors[2] = SK_ColorBLUE; fRects[3].set(xA, yC, xD, yF); - fPaths[3].addRoundRect(fRects[3], SkIntToScalar(5), SkIntToScalar(5)); + fRRects[3].setRectXY(fRects[3], 7, 7); + fPaths[3].addRoundRect(fRects[3], 5, 5); fRectColors[3] = SK_ColorYELLOW; fRects[4].set(xC, yC, xF, yF); - fPaths[4].addRoundRect(fRects[4], SkIntToScalar(5), SkIntToScalar(5)); + fRRects[4].setRectXY(fRects[4], 7, 7); + fPaths[4].addRoundRect(fRects[4], 5, 5); fRectColors[4] = SK_ColorCYAN; fTotalWidth = kCols * fWidth + SK_Scalar1 * (kCols + 1) * kPadX; @@ -87,14 +98,27 @@ protected: static const int kPadX = 20; static const int kPadY = 20; + static const char* ClipStr(Clip clip) { + switch (clip) { + case kRect_Clip: + return "rect"; + case kRRect_Clip: + return "rrect"; + case kPath_Clip: + return "path"; + } + SkDEBUGFAIL("Unknown clip type."); + return ""; + } + virtual SkString onShortName() { - if (!fDoPaths && !fAntiAlias) { + if (kRect_Clip == fClip && !fAntiAlias) { return SkString("complexclip2"); } SkString str; str.printf("complexclip2_%s_%s", - fDoPaths ? "path" : "rect", + ClipStr(fClip), fAntiAlias ? "aa" : "bw"); return str; } @@ -123,22 +147,36 @@ protected: // antialiasing on the clipped draw for (int k = 0; k < 5; ++k) { rectPaint.setColor(fRectColors[k]); - if (fDoPaths) { - canvas->drawPath(fPaths[k], rectPaint); - } else { - canvas->drawRect(fRects[k], rectPaint); + switch (fClip) { + case kRect_Clip: + canvas->drawRect(fRects[k], rectPaint); + break; + case kRRect_Clip: + canvas->drawRRect(fRRects[k], rectPaint); + break; + case kPath_Clip: + canvas->drawPath(fPaths[k], rectPaint); + break; } } for (int k = 0; k < 5; ++k) { - if (fDoPaths) { - canvas->clipPath(fPaths[k], - fOps[j*kRows+i][k], - fAntiAlias); - } else { - canvas->clipRect(fRects[k], - fOps[j*kRows+i][k], - fAntiAlias); + switch (fClip) { + case kRect_Clip: + canvas->clipRect(fRects[k], + fOps[j*kRows+i][k], + fAntiAlias); + break; + case kRRect_Clip: + canvas->clipRRect(fRRects[k], + fOps[j*kRows+i][k], + fAntiAlias); + break; + case kPath_Clip: + canvas->clipPath(fPaths[k], + fOps[j*kRows+i][k], + fAntiAlias); + break; } } canvas->drawRect(SkRect::MakeWH(fWidth, fHeight), fillPaint); @@ -147,9 +185,10 @@ protected: } } private: - bool fDoPaths; + Clip fClip; bool fAntiAlias; SkRect fRects[5]; + SkRRect fRRects[5]; SkPath fPaths[5]; SkColor fRectColors[5]; SkRegion::Op fOps[kRows * kCols][5]; @@ -163,20 +202,14 @@ private: ////////////////////////////////////////////////////////////////////////////// -// bw rects -static GM* MyFactory(void*) { return new ComplexClip2GM(false, false); } -static GMRegistry reg(MyFactory); - -// bw paths -static GM* MyFactory2(void*) { return new ComplexClip2GM(true, false); } -static GMRegistry reg2(MyFactory2); - -// aa rects -static GM* MyFactory3(void*) { return new ComplexClip2GM(false, true); } -static GMRegistry reg3(MyFactory3); +// bw +DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRect_Clip, false); ) +DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRRect_Clip, false); ) +DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kPath_Clip, false); ) -// aa paths -static GM* MyFactory4(void*) { return new ComplexClip2GM(true, true); } -static GMRegistry reg4(MyFactory4); +// aa +DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRect_Clip, true); ) +DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRRect_Clip, true); ) +DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kPath_Clip, true); ) } |