Home | History | Annotate | Download | only in gm
      1 /*
      2  * Copyright 2013 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #include "gm.h"
      9 #include "SkBitmap.h"
     10 #include "SkCanvas.h"
     11 #include "SkClipStack.h"
     12 #include "SkDevice.h"
     13 #include "SkPath.h"
     14 #include "SkPathOps.h"
     15 #include "SkPicture.h"
     16 #include "SkRect.h"
     17 
     18 namespace skiagm {
     19 
     20 class PathOpsSkpClipGM : public GM {
     21 public:
     22     PathOpsSkpClipGM() {
     23     }
     24 
     25 protected:
     26     virtual SkString onShortName() SK_OVERRIDE {
     27         return SkString("pathopsskpclip");
     28     }
     29 
     30     virtual SkISize onISize() SK_OVERRIDE {
     31         return make_isize(1200, 900);
     32     }
     33 
     34     virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
     35         SkPicture* pict = SkNEW(SkPicture);
     36         SkCanvas* rec = pict->beginRecording(1200, 900);
     37         SkPath p;
     38         SkRect r = {
     39             SkIntToScalar(100),
     40             SkIntToScalar(200),
     41             SkIntToScalar(400),
     42             SkIntToScalar(700)
     43         };
     44         p.addRoundRect(r, SkIntToScalar(50), SkIntToScalar(50));
     45         rec->clipPath(p, SkRegion::kIntersect_Op, true);
     46         rec->translate(SkIntToScalar(250), SkIntToScalar(250));
     47         rec->clipPath(p, SkRegion::kIntersect_Op, true);
     48         rec->drawColor(0xffff0000);
     49         pict->endRecording();
     50 
     51         canvas->setAllowSimplifyClip(true);
     52         canvas->save();
     53         canvas->drawPicture(*pict);
     54         canvas->restore();
     55 
     56         canvas->setAllowSimplifyClip(false);
     57         canvas->save();
     58         canvas->translate(SkIntToScalar(1200 / 2), 0);
     59         canvas->drawPicture(*pict);
     60         canvas->restore();
     61         SkSafeUnref(pict);
     62     }
     63 
     64 private:
     65     typedef GM INHERITED;
     66 };
     67 
     68 //////////////////////////////////////////////////////////////////////////////
     69 
     70 static GM* MyFactory(void*) { return new PathOpsSkpClipGM; }
     71 static GMRegistry reg(MyFactory);
     72 
     73 }
     74