17defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips/*
27defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips * Copyright 2015 Google Inc.
37defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips *
47defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips * Use of this source code is governed by a BSD-style license that can be
57defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips * found in the LICENSE file.
67defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips */
77defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
87defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips#include "SampleCode.h"
97defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips#include "SkCanvas.h"
107defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips#include "SkInterpolator.h"
117defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips#include "SkTime.h"
127defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
137defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// This slide tests out the match up between BW clipping and rendering. It can
147defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// draw a large rect through some clip geometry and draw the same geometry
157defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// normally. Which one is drawn first can be toggled. The pair of objects is translated
167defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// fractionally (via an animator) to expose snapping bugs. The key bindings are:
177defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips//      1-9: the different geometries
187defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips//      t:   toggle which is drawn first the clip or the normal geometry
19c89f6fb29c38a7a52a40d585680cce590039d508robertphillips//      f:   flip-flops which corner the bottom AA clip rect occupies in the complex clip cases
207defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
217defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// The possible geometric combinations to test
227defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsenum Geometry {
237defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    kRect_Geometry,
247defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    kRRect_Geometry,
257defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    kCircle_Geometry,
267defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    kConvexPath_Geometry,
277defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    kConcavePath_Geometry,
287defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    kRectAndRect_Geometry,
297defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    kRectAndRRect_Geometry,
307defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    kRectAndConvex_Geometry,
317defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    kRectAndConcave_Geometry
327defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips};
337defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
347defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// The basic rect used is [kMin,kMin]..[kMax,kMax]
357defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsstatic const float kMin = 100.5f;
367defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsstatic const float kMid = 200.0f;
377defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsstatic const float kMax = 299.5f;
387defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
39c89f6fb29c38a7a52a40d585680cce590039d508robertphillips// The translation applied to the base AA rect in the combination cases
40c89f6fb29c38a7a52a40d585680cce590039d508robertphillips// (i.e., kRectAndRect through kRectAndConcave)
41c89f6fb29c38a7a52a40d585680cce590039d508robertphillipsstatic const float kXlate = 100.0f;
42c89f6fb29c38a7a52a40d585680cce590039d508robertphillips
437defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsSkRect create_rect(const SkPoint& offset) {
447defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    SkRect r = SkRect::MakeLTRB(kMin, kMin, kMax, kMax);
457defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    r.offset(offset);
467defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    return r;
477defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips}
487defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
497defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsSkRRect create_rrect(const SkPoint& offset) {
507defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    SkRRect rrect;
517defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    rrect.setRectXY(create_rect(offset), 10, 10);
527defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    return rrect;
537defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips}
547defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
557defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsSkRRect create_circle(const SkPoint& offset) {
567defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    SkRRect circle;
577defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    circle.setOval(create_rect(offset));
587defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    return circle;
597defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips}
607defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
617defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsSkPath create_convex_path(const SkPoint& offset) {
627defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    SkPath convexPath;
637defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    convexPath.moveTo(kMin, kMin);
647defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    convexPath.lineTo(kMax, kMax);
657defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    convexPath.lineTo(kMin, kMax);
667defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    convexPath.close();
677defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    convexPath.offset(offset.fX, offset.fY);
687defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    return convexPath;
697defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips}
707defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
717defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsSkPath create_concave_path(const SkPoint& offset) {
727defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    SkPath concavePath;
737defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    concavePath.moveTo(kMin, kMin);
747defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    concavePath.lineTo(kMid, 105.0f);
757defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    concavePath.lineTo(kMax, kMin);
767defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    concavePath.lineTo(295.0f, kMid);
777defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    concavePath.lineTo(kMax, kMax);
787defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    concavePath.lineTo(kMid, 295.0f);
797defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    concavePath.lineTo(kMin, kMax);
807defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    concavePath.lineTo(105.0f, kMid);
817defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    concavePath.close();
827defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
837defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    concavePath.offset(offset.fX, offset.fY);
847defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    return concavePath;
857defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips}
867defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
877defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsstatic void draw_normal_geom(SkCanvas* canvas, const SkPoint& offset, int geom, bool useAA) {
887defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    SkPaint p;
897defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    p.setAntiAlias(useAA);
907defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    p.setColor(SK_ColorBLACK);
917defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
927defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    switch (geom) {
937defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    case kRect_Geometry:                // fall thru
947defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    case kRectAndRect_Geometry:
957defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        canvas->drawRect(create_rect(offset), p);
967defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        break;
977defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    case kRRect_Geometry:               // fall thru
987defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    case kRectAndRRect_Geometry:
997defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        canvas->drawRRect(create_rrect(offset), p);
1007defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        break;
1017defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    case kCircle_Geometry:
1027defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        canvas->drawRRect(create_circle(offset), p);
1037defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        break;
1047defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    case kConvexPath_Geometry:          // fall thru
1057defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    case kRectAndConvex_Geometry:
1067defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        canvas->drawPath(create_convex_path(offset), p);
1077defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        break;
1087defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    case kConcavePath_Geometry:         // fall thru
1097defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    case kRectAndConcave_Geometry:
1107defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        canvas->drawPath(create_concave_path(offset), p);
1117defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        break;
1127defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    }
1137defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips}
1147defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
1157defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsclass ClipDrawMatchView : public SampleView {
1167defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipspublic:
117c89f6fb29c38a7a52a40d585680cce590039d508robertphillips    ClipDrawMatchView() : fTrans(2, 5), fGeom(kRect_Geometry), fClipFirst(true), fSign(1) {
1187defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        SkScalar values[2];
1197defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
1207defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        fTrans.setRepeatCount(999);
1217defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        values[0] = values[1] = 0;
1227defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        fTrans.setKeyFrame(0, SkTime::GetMSecs() + 1000, values);
1237defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        values[1] = 1;
1247defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        fTrans.setKeyFrame(1, SkTime::GetMSecs() + 2000, values);
1257defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        values[0] = values[1] = 1;
1267defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        fTrans.setKeyFrame(2, SkTime::GetMSecs() + 3000, values);
1277defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        values[1] = 0;
1287defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        fTrans.setKeyFrame(3, SkTime::GetMSecs() + 4000, values);
1297defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        values[0] = 0;
1307defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        fTrans.setKeyFrame(4, SkTime::GetMSecs() + 5000, values);
1317defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    }
1327defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
1337defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsprotected:
13436352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    bool onQuery(SkEvent* evt) override {
1357defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        if (SampleCode::TitleQ(*evt)) {
1367defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips            SampleCode::TitleR(evt, "ClipDrawMatch");
1377defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips            return true;
1387defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        }
1397defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        SkUnichar uni;
1407defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        if (SampleCode::CharQ(*evt, &uni)) {
1417defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips            switch (uni) {
1427defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips                case '1': fGeom = kRect_Geometry; this->inval(NULL); return true;
1437defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips                case '2': fGeom = kRRect_Geometry; this->inval(NULL); return true;
1447defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips                case '3': fGeom = kCircle_Geometry; this->inval(NULL); return true;
1457defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips                case '4': fGeom = kConvexPath_Geometry; this->inval(NULL); return true;
1467defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips                case '5': fGeom = kConcavePath_Geometry; this->inval(NULL); return true;
1477defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips                case '6': fGeom = kRectAndRect_Geometry; this->inval(NULL); return true;
1487defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips                case '7': fGeom = kRectAndRRect_Geometry; this->inval(NULL); return true;
1497defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips                case '8': fGeom = kRectAndConvex_Geometry; this->inval(NULL); return true;
1507defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips                case '9': fGeom = kRectAndConcave_Geometry; this->inval(NULL); return true;
151c89f6fb29c38a7a52a40d585680cce590039d508robertphillips                case 'f': fSign = -fSign; this->inval(NULL); return true;
1527defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips                case 't': fClipFirst = !fClipFirst; this->inval(NULL); return true;
1537defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips                default: break;
1547defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips            }
1557defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        }
1567defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        return this->INHERITED::onQuery(evt);
1577defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    }
1587defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
159c89f6fb29c38a7a52a40d585680cce590039d508robertphillips    void drawClippedGeom(SkCanvas* canvas, const SkPoint& offset, bool useAA) {
160c89f6fb29c38a7a52a40d585680cce590039d508robertphillips
161c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        int count = canvas->save();
162c89f6fb29c38a7a52a40d585680cce590039d508robertphillips
163c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        switch (fGeom) {
164c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        case kRect_Geometry:
165c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipRect(create_rect(offset), SkRegion::kReplace_Op, useAA);
166c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            break;
167c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        case kRRect_Geometry:
168c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipRRect(create_rrect(offset), SkRegion::kReplace_Op, useAA);
169c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            break;
170c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        case kCircle_Geometry:
171c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipRRect(create_circle(offset), SkRegion::kReplace_Op, useAA);
172c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            break;
173c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        case kConvexPath_Geometry:
174c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipPath(create_convex_path(offset), SkRegion::kReplace_Op, useAA);
175c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            break;
176c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        case kConcavePath_Geometry:
177c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipPath(create_concave_path(offset), SkRegion::kReplace_Op, useAA);
178c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            break;
179c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        case kRectAndRect_Geometry: {
180c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            SkRect r = create_rect(offset);
181c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            r.offset(fSign * kXlate, fSign * kXlate);
182c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips
183c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipRect(create_rect(offset), SkRegion::kIntersect_Op, useAA);
184c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            } break;
185c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        case kRectAndRRect_Geometry: {
186c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            SkRect r = create_rect(offset);
187c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            r.offset(fSign * kXlate, fSign * kXlate);
188c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips
189c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipRRect(create_rrect(offset), SkRegion::kIntersect_Op, useAA);
190c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            } break;
191c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        case kRectAndConvex_Geometry: {
192c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            SkRect r = create_rect(offset);
193c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            r.offset(fSign * kXlate, fSign * kXlate);
194c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips
195c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipPath(create_convex_path(offset), SkRegion::kIntersect_Op, useAA);
196c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            } break;
197c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        case kRectAndConcave_Geometry: {
198c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            SkRect r = create_rect(offset);
199c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            r.offset(fSign * kXlate, fSign * kXlate);
200c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips
201c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            canvas->clipPath(create_concave_path(offset), SkRegion::kIntersect_Op, useAA);
202c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            } break;
203c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        }
204c89f6fb29c38a7a52a40d585680cce590039d508robertphillips
205c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        SkISize size = canvas->getDeviceSize();
206c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        SkRect bigR = SkRect::MakeWH(SkIntToScalar(size.width()), SkIntToScalar(size.height()));
207c89f6fb29c38a7a52a40d585680cce590039d508robertphillips
208c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        SkPaint p;
209c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        p.setColor(SK_ColorRED);
210c89f6fb29c38a7a52a40d585680cce590039d508robertphillips
211c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        canvas->drawRect(bigR, p);
212c89f6fb29c38a7a52a40d585680cce590039d508robertphillips        canvas->restoreToCount(count);
213c89f6fb29c38a7a52a40d585680cce590039d508robertphillips    }
214c89f6fb29c38a7a52a40d585680cce590039d508robertphillips
2157defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    // Draw a big red rect through some clip geometry and also draw that same
2167defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    // geometry in black. The order in which they are drawn can be swapped.
2177defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    // This tests whether the clip and normally drawn geometry match up.
2187defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    void drawGeometry(SkCanvas* canvas, const SkPoint& offset, bool useAA) {
2197defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        if (fClipFirst) {
220c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            this->drawClippedGeom(canvas, offset, useAA);
2217defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        }
2227defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
2237defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        draw_normal_geom(canvas, offset, fGeom, useAA);
2247defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
2257defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        if (!fClipFirst) {
226c89f6fb29c38a7a52a40d585680cce590039d508robertphillips            this->drawClippedGeom(canvas, offset, useAA);
2277defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        }
2287defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    }
2297defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
23036352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void onDrawContent(SkCanvas* canvas) override {
2317defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        SkScalar trans[2];
2327defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        fTrans.timeToValues(SkTime::GetMSecs(), trans);
2337defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
2347defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        SkPoint offset;
2357defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        offset.set(trans[0], trans[1]);
2367defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
2377defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        int saveCount = canvas->save();
2387defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        this->drawGeometry(canvas, offset, false);
2397defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        canvas->restoreToCount(saveCount);
2407defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
2417defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips        this->inval(NULL);
2427defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    }
2437defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
2447defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsprivate:
2457defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    SkInterpolator  fTrans;
2467defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    Geometry        fGeom;
2477defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    bool            fClipFirst;
248c89f6fb29c38a7a52a40d585680cce590039d508robertphillips    int             fSign;
2497defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
2507defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips    typedef SampleView INHERITED;
2517defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips};
2527defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
2537defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips//////////////////////////////////////////////////////////////////////////////
2547defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips
2557defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsstatic SkView* MyFactory() { return new ClipDrawMatchView; }
2567defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsstatic SkViewRegister reg(MyFactory);
257