skia2/gm/circularclips.cpp
Mike Reed 4241f5e0a8 Revert "add guard to switch to SkPathTypes"
This reverts commit e1af44498b.

Reason for revert: breaking google3?

Original change's description:
> add guard to switch to SkPathTypes
> 
> Change-Id: I44d8b5ae8a5172d11a6d4cd9d994373dd3816d6f
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/241278
> Reviewed-by: Kevin Lubick <kjlubick@google.com>
> Reviewed-by: Florin Malita <fmalita@chromium.org>
> Commit-Queue: Mike Reed <reed@google.com>

TBR=robertphillips@google.com,kjlubick@google.com,fmalita@chromium.org,reed@google.com

Change-Id: If1fffb6310921ee6f213af000da793afcf62ab0b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/241560
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2019-09-14 19:13:44 +00:00

104 lines
2.7 KiB
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkClipOp.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "src/core/SkClipOpPriv.h"
class CircularClipsGM : public skiagm::GM {
SkScalar fX1, fX2, fY, fR;
SkPath fCircle1, fCircle2;
protected:
void onOnceBeforeDraw() override {
fX1 = 80;
fX2 = 120;
fY = 50;
fR = 40;
fCircle1.addCircle(fX1, fY, fR, SkPath::kCW_Direction);
fCircle2.addCircle(fX2, fY, fR, SkPath::kCW_Direction);
}
bool runAsBench() const override { return true; }
SkString onShortName() override {
return SkString("circular-clips");
}
SkISize onISize() override {
return SkISize::Make(800, 600);
}
void onDraw(SkCanvas* canvas) override {
const SkClipOp ops[] = {
kDifference_SkClipOp,
kIntersect_SkClipOp,
kUnion_SkClipOp,
kXOR_SkClipOp,
kReverseDifference_SkClipOp,
kReplace_SkClipOp,
};
SkRect rect = SkRect::MakeLTRB(fX1 - fR, fY - fR, fX2 + fR, fY + fR);
SkPaint fillPaint;
// Giant background circular clips (AA, non-inverted, replace/isect)
fillPaint.setColor(0x80808080);
canvas->save();
canvas->scale(10, 10);
canvas->translate(-((fX1 + fX2)/2 - fR), -(fY - 2*fR/3));
canvas->clipPath(fCircle1, true);
canvas->clipPath(fCircle2, true);
canvas->drawRect(rect, fillPaint);
canvas->restore();
fillPaint.setColor(0xFF000000);
for (size_t i = 0; i < 4; i++) {
fCircle1.toggleInverseFillType();
if (i % 2 == 0) {
fCircle2.toggleInverseFillType();
}
canvas->save();
for (size_t op = 0; op < SK_ARRAY_COUNT(ops); op++) {
canvas->save();
canvas->clipPath(fCircle1);
canvas->clipPath(fCircle2, ops[op]);
canvas->drawRect(rect, fillPaint);
canvas->restore();
canvas->translate(0, 2 * fY);
}
canvas->restore();
canvas->translate(fX1 + fX2, 0);
}
}
private:
typedef skiagm::GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM( return new CircularClipsGM; )