145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com/*
245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com * Copyright 2013 Google Inc.
345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com *
445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com * Use of this source code is governed by a BSD-style license that can be
545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com * found in the LICENSE file.
645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com */
745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com#include "gm.h"
945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com#include "SkBitmap.h"
1045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com#include "SkCanvas.h"
1145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com#include "SkClipStack.h"
1245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com#include "SkDevice.h"
1345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com#include "SkPath.h"
1445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com#include "SkPathOps.h"
1545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com#include "SkPicture.h"
16770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com#include "SkPictureRecorder.h"
1745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com#include "SkRect.h"
1845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
1945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.comnamespace skiagm {
2045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
2145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.comclass PathOpsSkpClipGM : public GM {
2245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.compublic:
2345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    PathOpsSkpClipGM() {
2445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    }
2545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
2645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.comprotected:
2745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    virtual SkString onShortName() SK_OVERRIDE {
2845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        return SkString("pathopsskpclip");
2945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    }
3045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
3145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    virtual SkISize onISize() SK_OVERRIDE {
32f539318f0d3dba743ec1886d5d9df0fb1be628a1tfarina        return SkISize::Make(1200, 900);
3345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    }
3445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
3545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
3684b18c7e3e042bf206e1ace3d1b6ea5bb929fe51robertphillips@google.com        SkPictureRecorder recorder;
375fb2ce38b3dcb8e60e9e112df23c9d42456d7069commit-bot@chromium.org        SkCanvas* rec = recorder.beginRecording(1200, 900, NULL, 0);
3845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        SkPath p;
3945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        SkRect r = {
4045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com            SkIntToScalar(100),
4145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com            SkIntToScalar(200),
4245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com            SkIntToScalar(400),
4345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com            SkIntToScalar(700)
4445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        };
4545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        p.addRoundRect(r, SkIntToScalar(50), SkIntToScalar(50));
4645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        rec->clipPath(p, SkRegion::kIntersect_Op, true);
4745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        rec->translate(SkIntToScalar(250), SkIntToScalar(250));
4845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        rec->clipPath(p, SkRegion::kIntersect_Op, true);
4945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        rec->drawColor(0xffff0000);
5084b18c7e3e042bf206e1ace3d1b6ea5bb929fe51robertphillips@google.com        SkAutoTUnref<SkPicture> pict(recorder.endRecording());
5145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
5245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        canvas->setAllowSimplifyClip(true);
5345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        canvas->save();
549b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips        canvas->drawPicture(pict);
5545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        canvas->restore();
5645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
5745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        canvas->setAllowSimplifyClip(false);
5845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        canvas->save();
5945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        canvas->translate(SkIntToScalar(1200 / 2), 0);
609b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips        canvas->drawPicture(pict);
6145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        canvas->restore();
6245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    }
6345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
6445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.comprivate:
6545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    typedef GM INHERITED;
6645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com};
6745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
6845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com//////////////////////////////////////////////////////////////////////////////
6945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
7045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.comstatic GM* MyFactory(void*) { return new PathOpsSkpClipGM; }
7145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.comstatic GMRegistry reg(MyFactory);
7245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
7345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com}
74