SampleClipDrawMatch.cpp revision 9d524f22bfde5dc3dc8f48e1be39bdebd3bb0304
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" 11d3ebb48320cf1b7e969974673e4bd7743816985ebungeman#include "SkPath.h" 12d3ebb48320cf1b7e969974673e4bd7743816985ebungeman#include "SkRRect.h" 137defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips#include "SkTime.h" 147defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 157defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// This slide tests out the match up between BW clipping and rendering. It can 167defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// draw a large rect through some clip geometry and draw the same geometry 177defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// normally. Which one is drawn first can be toggled. The pair of objects is translated 187defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// fractionally (via an animator) to expose snapping bugs. The key bindings are: 197defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// 1-9: the different geometries 207defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// t: toggle which is drawn first the clip or the normal geometry 21c89f6fb29c38a7a52a40d585680cce590039d508robertphillips// f: flip-flops which corner the bottom AA clip rect occupies in the complex clip cases 227defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 237defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// The possible geometric combinations to test 247defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsenum Geometry { 257defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips kRect_Geometry, 267defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips kRRect_Geometry, 277defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips kCircle_Geometry, 287defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips kConvexPath_Geometry, 297defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips kConcavePath_Geometry, 307defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips kRectAndRect_Geometry, 317defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips kRectAndRRect_Geometry, 327defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips kRectAndConvex_Geometry, 337defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips kRectAndConcave_Geometry 347defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips}; 357defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 367defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips// The basic rect used is [kMin,kMin]..[kMax,kMax] 377defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsstatic const float kMin = 100.5f; 387defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsstatic const float kMid = 200.0f; 397defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsstatic const float kMax = 299.5f; 407defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 41c89f6fb29c38a7a52a40d585680cce590039d508robertphillips// The translation applied to the base AA rect in the combination cases 42c89f6fb29c38a7a52a40d585680cce590039d508robertphillips// (i.e., kRectAndRect through kRectAndConcave) 43c89f6fb29c38a7a52a40d585680cce590039d508robertphillipsstatic const float kXlate = 100.0f; 44c89f6fb29c38a7a52a40d585680cce590039d508robertphillips 457defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsSkRect create_rect(const SkPoint& offset) { 467defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips SkRect r = SkRect::MakeLTRB(kMin, kMin, kMax, kMax); 477defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips r.offset(offset); 487defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips return r; 497defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips} 507defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 517defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsSkRRect create_rrect(const SkPoint& offset) { 527defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips SkRRect rrect; 537defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips rrect.setRectXY(create_rect(offset), 10, 10); 547defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips return rrect; 557defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips} 567defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 577defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsSkRRect create_circle(const SkPoint& offset) { 587defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips SkRRect circle; 597defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips circle.setOval(create_rect(offset)); 607defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips return circle; 617defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips} 627defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 637defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsSkPath create_convex_path(const SkPoint& offset) { 647defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips SkPath convexPath; 657defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips convexPath.moveTo(kMin, kMin); 667defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips convexPath.lineTo(kMax, kMax); 677defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips convexPath.lineTo(kMin, kMax); 687defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips convexPath.close(); 697defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips convexPath.offset(offset.fX, offset.fY); 707defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips return convexPath; 717defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips} 727defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 737defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsSkPath create_concave_path(const SkPoint& offset) { 747defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips SkPath concavePath; 757defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips concavePath.moveTo(kMin, kMin); 767defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips concavePath.lineTo(kMid, 105.0f); 777defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips concavePath.lineTo(kMax, kMin); 787defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips concavePath.lineTo(295.0f, kMid); 797defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips concavePath.lineTo(kMax, kMax); 807defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips concavePath.lineTo(kMid, 295.0f); 817defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips concavePath.lineTo(kMin, kMax); 827defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips concavePath.lineTo(105.0f, kMid); 837defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips concavePath.close(); 847defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 857defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips concavePath.offset(offset.fX, offset.fY); 867defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips return concavePath; 877defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips} 887defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 897defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsstatic void draw_normal_geom(SkCanvas* canvas, const SkPoint& offset, int geom, bool useAA) { 907defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips SkPaint p; 917defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips p.setAntiAlias(useAA); 927defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips p.setColor(SK_ColorBLACK); 937defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 947defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips switch (geom) { 957defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips case kRect_Geometry: // fall thru 967defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips case kRectAndRect_Geometry: 977defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips canvas->drawRect(create_rect(offset), p); 987defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips break; 997defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips case kRRect_Geometry: // fall thru 1007defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips case kRectAndRRect_Geometry: 1017defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips canvas->drawRRect(create_rrect(offset), p); 1027defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips break; 1037defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips case kCircle_Geometry: 1047defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips canvas->drawRRect(create_circle(offset), p); 1057defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips break; 1067defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips case kConvexPath_Geometry: // fall thru 1077defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips case kRectAndConvex_Geometry: 1087defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips canvas->drawPath(create_convex_path(offset), p); 1097defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips break; 1107defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips case kConcavePath_Geometry: // fall thru 1117defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips case kRectAndConcave_Geometry: 1127defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips canvas->drawPath(create_concave_path(offset), p); 1137defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips break; 1149d524f22bfde5dc3dc8f48e1be39bdebd3bb0304halcanary } 1157defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips} 1167defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 1177defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsclass ClipDrawMatchView : public SampleView { 1187defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipspublic: 119c89f6fb29c38a7a52a40d585680cce590039d508robertphillips ClipDrawMatchView() : fTrans(2, 5), fGeom(kRect_Geometry), fClipFirst(true), fSign(1) { 1207defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips SkScalar values[2]; 1217defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 1227defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips fTrans.setRepeatCount(999); 1237defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips values[0] = values[1] = 0; 124ec4d4d784dbb250e572f8e04d18d0fd2ebeee851benjaminwagner fTrans.setKeyFrame(0, GetMSecs() + 1000, values); 1257defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips values[1] = 1; 126ec4d4d784dbb250e572f8e04d18d0fd2ebeee851benjaminwagner fTrans.setKeyFrame(1, GetMSecs() + 2000, values); 1277defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips values[0] = values[1] = 1; 128ec4d4d784dbb250e572f8e04d18d0fd2ebeee851benjaminwagner fTrans.setKeyFrame(2, GetMSecs() + 3000, values); 1297defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips values[1] = 0; 130ec4d4d784dbb250e572f8e04d18d0fd2ebeee851benjaminwagner fTrans.setKeyFrame(3, GetMSecs() + 4000, values); 1317defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips values[0] = 0; 132ec4d4d784dbb250e572f8e04d18d0fd2ebeee851benjaminwagner fTrans.setKeyFrame(4, GetMSecs() + 5000, values); 1337defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips } 1347defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 1357defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsprotected: 13636352bf5e38f45a70ee4f4fc132a38048d38206dmtklein bool onQuery(SkEvent* evt) override { 1377defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips if (SampleCode::TitleQ(*evt)) { 1387defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips SampleCode::TitleR(evt, "ClipDrawMatch"); 1397defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips return true; 1407defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips } 1417defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips SkUnichar uni; 1427defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips if (SampleCode::CharQ(*evt, &uni)) { 1437defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips switch (uni) { 14496fcdcc219d2a0d3579719b84b28bede76efba64halcanary case '1': fGeom = kRect_Geometry; this->inval(nullptr); return true; 14596fcdcc219d2a0d3579719b84b28bede76efba64halcanary case '2': fGeom = kRRect_Geometry; this->inval(nullptr); return true; 14696fcdcc219d2a0d3579719b84b28bede76efba64halcanary case '3': fGeom = kCircle_Geometry; this->inval(nullptr); return true; 14796fcdcc219d2a0d3579719b84b28bede76efba64halcanary case '4': fGeom = kConvexPath_Geometry; this->inval(nullptr); return true; 14896fcdcc219d2a0d3579719b84b28bede76efba64halcanary case '5': fGeom = kConcavePath_Geometry; this->inval(nullptr); return true; 14996fcdcc219d2a0d3579719b84b28bede76efba64halcanary case '6': fGeom = kRectAndRect_Geometry; this->inval(nullptr); return true; 15096fcdcc219d2a0d3579719b84b28bede76efba64halcanary case '7': fGeom = kRectAndRRect_Geometry; this->inval(nullptr); return true; 15196fcdcc219d2a0d3579719b84b28bede76efba64halcanary case '8': fGeom = kRectAndConvex_Geometry; this->inval(nullptr); return true; 15296fcdcc219d2a0d3579719b84b28bede76efba64halcanary case '9': fGeom = kRectAndConcave_Geometry; this->inval(nullptr); return true; 15396fcdcc219d2a0d3579719b84b28bede76efba64halcanary case 'f': fSign = -fSign; this->inval(nullptr); return true; 15496fcdcc219d2a0d3579719b84b28bede76efba64halcanary case 't': fClipFirst = !fClipFirst; this->inval(nullptr); return true; 1557defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips default: break; 1567defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips } 1577defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips } 1587defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips return this->INHERITED::onQuery(evt); 1597defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips } 1607defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 161c89f6fb29c38a7a52a40d585680cce590039d508robertphillips void drawClippedGeom(SkCanvas* canvas, const SkPoint& offset, bool useAA) { 162c89f6fb29c38a7a52a40d585680cce590039d508robertphillips 163c89f6fb29c38a7a52a40d585680cce590039d508robertphillips int count = canvas->save(); 164c89f6fb29c38a7a52a40d585680cce590039d508robertphillips 165c89f6fb29c38a7a52a40d585680cce590039d508robertphillips switch (fGeom) { 166c89f6fb29c38a7a52a40d585680cce590039d508robertphillips case kRect_Geometry: 167c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipRect(create_rect(offset), SkRegion::kReplace_Op, useAA); 168c89f6fb29c38a7a52a40d585680cce590039d508robertphillips break; 169c89f6fb29c38a7a52a40d585680cce590039d508robertphillips case kRRect_Geometry: 170c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipRRect(create_rrect(offset), SkRegion::kReplace_Op, useAA); 171c89f6fb29c38a7a52a40d585680cce590039d508robertphillips break; 172c89f6fb29c38a7a52a40d585680cce590039d508robertphillips case kCircle_Geometry: 173c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipRRect(create_circle(offset), SkRegion::kReplace_Op, useAA); 174c89f6fb29c38a7a52a40d585680cce590039d508robertphillips break; 175c89f6fb29c38a7a52a40d585680cce590039d508robertphillips case kConvexPath_Geometry: 176c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipPath(create_convex_path(offset), SkRegion::kReplace_Op, useAA); 177c89f6fb29c38a7a52a40d585680cce590039d508robertphillips break; 178c89f6fb29c38a7a52a40d585680cce590039d508robertphillips case kConcavePath_Geometry: 179c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipPath(create_concave_path(offset), SkRegion::kReplace_Op, useAA); 180c89f6fb29c38a7a52a40d585680cce590039d508robertphillips break; 181c89f6fb29c38a7a52a40d585680cce590039d508robertphillips case kRectAndRect_Geometry: { 182c89f6fb29c38a7a52a40d585680cce590039d508robertphillips SkRect r = create_rect(offset); 183c89f6fb29c38a7a52a40d585680cce590039d508robertphillips r.offset(fSign * kXlate, fSign * kXlate); 184c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips 185c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipRect(create_rect(offset), SkRegion::kIntersect_Op, useAA); 186c89f6fb29c38a7a52a40d585680cce590039d508robertphillips } break; 187c89f6fb29c38a7a52a40d585680cce590039d508robertphillips case kRectAndRRect_Geometry: { 188c89f6fb29c38a7a52a40d585680cce590039d508robertphillips SkRect r = create_rect(offset); 189c89f6fb29c38a7a52a40d585680cce590039d508robertphillips r.offset(fSign * kXlate, fSign * kXlate); 190c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips 191c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipRRect(create_rrect(offset), SkRegion::kIntersect_Op, useAA); 192c89f6fb29c38a7a52a40d585680cce590039d508robertphillips } break; 193c89f6fb29c38a7a52a40d585680cce590039d508robertphillips case kRectAndConvex_Geometry: { 194c89f6fb29c38a7a52a40d585680cce590039d508robertphillips SkRect r = create_rect(offset); 195c89f6fb29c38a7a52a40d585680cce590039d508robertphillips r.offset(fSign * kXlate, fSign * kXlate); 196c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips 197c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipPath(create_convex_path(offset), SkRegion::kIntersect_Op, useAA); 198c89f6fb29c38a7a52a40d585680cce590039d508robertphillips } break; 199c89f6fb29c38a7a52a40d585680cce590039d508robertphillips case kRectAndConcave_Geometry: { 200c89f6fb29c38a7a52a40d585680cce590039d508robertphillips SkRect r = create_rect(offset); 201c89f6fb29c38a7a52a40d585680cce590039d508robertphillips r.offset(fSign * kXlate, fSign * kXlate); 202c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips 203c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->clipPath(create_concave_path(offset), SkRegion::kIntersect_Op, useAA); 204c89f6fb29c38a7a52a40d585680cce590039d508robertphillips } break; 2059d524f22bfde5dc3dc8f48e1be39bdebd3bb0304halcanary } 206c89f6fb29c38a7a52a40d585680cce590039d508robertphillips 207c89f6fb29c38a7a52a40d585680cce590039d508robertphillips SkISize size = canvas->getDeviceSize(); 208c89f6fb29c38a7a52a40d585680cce590039d508robertphillips SkRect bigR = SkRect::MakeWH(SkIntToScalar(size.width()), SkIntToScalar(size.height())); 209c89f6fb29c38a7a52a40d585680cce590039d508robertphillips 210c89f6fb29c38a7a52a40d585680cce590039d508robertphillips SkPaint p; 211c89f6fb29c38a7a52a40d585680cce590039d508robertphillips p.setColor(SK_ColorRED); 212c89f6fb29c38a7a52a40d585680cce590039d508robertphillips 213c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->drawRect(bigR, p); 214c89f6fb29c38a7a52a40d585680cce590039d508robertphillips canvas->restoreToCount(count); 215c89f6fb29c38a7a52a40d585680cce590039d508robertphillips } 216c89f6fb29c38a7a52a40d585680cce590039d508robertphillips 2177defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips // Draw a big red rect through some clip geometry and also draw that same 2187defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips // geometry in black. The order in which they are drawn can be swapped. 2197defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips // This tests whether the clip and normally drawn geometry match up. 2207defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips void drawGeometry(SkCanvas* canvas, const SkPoint& offset, bool useAA) { 2217defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips if (fClipFirst) { 222c89f6fb29c38a7a52a40d585680cce590039d508robertphillips this->drawClippedGeom(canvas, offset, useAA); 2237defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips } 2247defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 2257defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips draw_normal_geom(canvas, offset, fGeom, useAA); 2267defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 2277defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips if (!fClipFirst) { 228c89f6fb29c38a7a52a40d585680cce590039d508robertphillips this->drawClippedGeom(canvas, offset, useAA); 2297defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips } 2307defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips } 2317defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 23236352bf5e38f45a70ee4f4fc132a38048d38206dmtklein void onDrawContent(SkCanvas* canvas) override { 2337defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips SkScalar trans[2]; 234ec4d4d784dbb250e572f8e04d18d0fd2ebeee851benjaminwagner fTrans.timeToValues(GetMSecs(), trans); 2357defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 2367defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips SkPoint offset; 2377defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips offset.set(trans[0], trans[1]); 2387defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 2397defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips int saveCount = canvas->save(); 2407defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips this->drawGeometry(canvas, offset, false); 2417defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips canvas->restoreToCount(saveCount); 2427defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 24396fcdcc219d2a0d3579719b84b28bede76efba64halcanary this->inval(nullptr); 2447defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips } 2457defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 246ec4d4d784dbb250e572f8e04d18d0fd2ebeee851benjaminwagner SkMSec GetMSecs() const { 247ec4d4d784dbb250e572f8e04d18d0fd2ebeee851benjaminwagner return static_cast<SkMSec>(SkTime::GetMSecs() - fStart); 248ec4d4d784dbb250e572f8e04d18d0fd2ebeee851benjaminwagner } 249ec4d4d784dbb250e572f8e04d18d0fd2ebeee851benjaminwagner 2507defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsprivate: 2517defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips SkInterpolator fTrans; 2527defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips Geometry fGeom; 2537defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips bool fClipFirst; 254c89f6fb29c38a7a52a40d585680cce590039d508robertphillips int fSign; 255ec4d4d784dbb250e572f8e04d18d0fd2ebeee851benjaminwagner const double fStart = SkTime::GetMSecs(); 2567defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 2577defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips typedef SampleView INHERITED; 2587defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips}; 2597defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 2607defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips////////////////////////////////////////////////////////////////////////////// 2617defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillips 2627defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsstatic SkView* MyFactory() { return new ClipDrawMatchView; } 2637defaa6c4a7577742d1b42bc869a84bd9a96e5a7robertphillipsstatic SkViewRegister reg(MyFactory); 264