Index: gm/canvasstate.cpp |
diff --git a/gm/pathopsskpclip.cpp b/gm/canvasstate.cpp |
similarity index 18% |
copy from gm/pathopsskpclip.cpp |
copy to gm/canvasstate.cpp |
index b85b294fef113b03f97fdb4a67c78c2d32273149..ec873937bb32ef34ce00a91ebe5cc4b061f8f5df 100644 |
--- a/gm/pathopsskpclip.cpp |
+++ b/gm/canvasstate.cpp |
@@ -6,68 +6,116 @@ |
*/ |
#include "gm.h" |
-#include "SkBitmap.h" |
#include "SkCanvas.h" |
-#include "SkClipStack.h" |
-#include "SkDevice.h" |
+#include "SkPaint.h" |
#include "SkPath.h" |
-#include "SkPathOps.h" |
-#include "SkPicture.h" |
#include "SkRect.h" |
namespace skiagm { |
-class PathOpsSkpClipGM : public GM { |
+/* |
+ * This GM exercises the flags to SkCanvas::save(). The canvas' save() and |
+ * restore actions can be limited to only a portion of the canvas' state through |
+ * the use of flags when calling save. |
+ */ |
+class CanvasStateGM : public GM { |
+ SkSize fSize; |
+ enum { |
+ WIDTH = 150, |
+ HEIGHT = 150, |
+ }; |
+ |
+ SkPaint fFillPaint; |
+ SkPaint fStrokePaint; |
+ |
+ SkPath fPath; |
+ |
+ SkRect fOutlineRect; |
+ SkRect fFillRect; |
+ |
+ |
public: |
- PathOpsSkpClipGM() { |
+ CanvasStateGM() { |
+ fSize.set(SkIntToScalar(WIDTH), SkIntToScalar(HEIGHT)); |
+ |
+ fFillPaint.setColor(SK_ColorRED); |
+ fFillPaint.setStyle(SkPaint::kFill_Style); |
+ |
+ fStrokePaint.setColor(SK_ColorBLUE); |
+ fStrokePaint.setStyle(SkPaint::kStroke_Style); |
+ fStrokePaint.setStrokeWidth(1); |
+ |
+ fPath.moveTo(25, 25); |
+ fPath.lineTo(125, 25); |
+ fPath.lineTo(75, 125); |
+ fPath.close(); |
+ |
+ fOutlineRect = SkRect::MakeXYWH(1, 1, WIDTH-2, HEIGHT-2); |
+ fFillRect = SkRect::MakeXYWH(10, 10, WIDTH-20, HEIGHT-20); |
} |
protected: |
virtual SkString onShortName() SK_OVERRIDE { |
- return SkString("pathopsskpclip"); |
+ return SkString("canvas-state"); |
} |
virtual SkISize onISize() SK_OVERRIDE { |
robertphillips
2013/08/13 13:45:55
Should the width & height here be computed from WI
|
- return make_isize(1200, 900); |
+ return SkISize::Make(450, 600); |
} |
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
- SkPicture* pict = SkNEW(SkPicture); |
- SkCanvas* rec = pict->beginRecording(1200, 900); |
- SkPath p; |
- SkRect r = { |
- SkIntToScalar(100), |
- SkIntToScalar(200), |
- SkIntToScalar(400), |
- SkIntToScalar(700) |
- }; |
- p.addRoundRect(r, SkIntToScalar(50), SkIntToScalar(50)); |
- rec->clipPath(p, SkRegion::kIntersect_Op, true); |
- rec->translate(SkIntToScalar(250), SkIntToScalar(250)); |
- rec->clipPath(p, SkRegion::kIntersect_Op, true); |
- rec->drawColor(0xffff0000); |
- pict->endRecording(); |
- |
- canvas->setAllowSimplifyClip(true); |
+ // [0,0] -- red triangle |
+ // test that we don't drop the clip since we are not setting the clip bit |
robertphillips
2013/08/13 13:45:55
this-> on all these?
|
+ drawTestPattern(0, 0, canvas, SkCanvas::kMatrix_SaveFlag, true, false); |
+ |
+ // [1,0] -- red box |
+ // test that we drop the clip since we are setting the clip bit |
+ drawTestPattern(1, 0, canvas, SkCanvas::kClip_SaveFlag, true, false); |
+ |
+ // [0,1] -- red box in uppper left |
+ // test that we don't drop the matrix since we are not setting the matrix bit |
+ drawTestPattern(0, 1, canvas, SkCanvas::kClip_SaveFlag, false, true); |
+ |
+ // [1,1] -- red box |
+ // test that we drop the matrix since we are setting the matrix bit |
+ drawTestPattern(1, 1, canvas, SkCanvas::kMatrix_SaveFlag, false, true); |
+ |
+ // [0,2] -- red box in upper left |
+ // test that we drop the clip but not matrix |
+ drawTestPattern(0, 2, canvas, SkCanvas::kClip_SaveFlag, true, true); |
+ |
+ // [1,2] -- red triangle |
+ // test that we drop the matrix but not the clip |
+ drawTestPattern(1, 2, canvas, SkCanvas::kMatrix_SaveFlag, true, true); |
+ } |
+ |
+private: |
+ void drawTestPattern(int x, int y, SkCanvas* canvas, |
+ SkCanvas::SaveFlags flags, bool doClip, bool doScale) { |
canvas->save(); |
- canvas->drawPicture(*pict); |
+ canvas->translate(x*WIDTH, y*HEIGHT); |
+ |
+ // [0,0] -- red triangle |
+ // test that we don't drop the clip since we are not setting the clip bit |
+ canvas->drawRect(fOutlineRect, fStrokePaint); |
+ canvas->save(flags); |
+ if(doClip) { |
+ canvas->clipPath(fPath); |
+ } |
+ if (doScale) { |
+ canvas->scale(0.5, 0.5); |
+ } |
canvas->restore(); |
+ canvas->drawRect(fFillRect, fFillPaint); |
- canvas->setAllowSimplifyClip(false); |
- canvas->save(); |
- canvas->translate(SkIntToScalar(1200 / 2), 0); |
- canvas->drawPicture(*pict); |
canvas->restore(); |
- SkSafeUnref(pict); |
} |
-private: |
typedef GM INHERITED; |
}; |
////////////////////////////////////////////////////////////////////////////// |
-static GM* MyFactory(void*) { return new PathOpsSkpClipGM; } |
-static GMRegistry reg(MyFactory); |
+DEF_GM( return SkNEW(CanvasStateGM); ) |
-} |
+} // end namespace |