4241f5e0a8
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>
138 lines
4.3 KiB
C++
138 lines
4.3 KiB
C++
/*
|
|
* Copyright 2011 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
#include "include/core/SkColorPriv.h"
|
|
#include "include/core/SkFont.h"
|
|
#include "include/core/SkPaint.h"
|
|
#include "include/core/SkPath.h"
|
|
#include "include/utils/SkRandom.h"
|
|
#include "samplecode/Sample.h"
|
|
#include "src/core/SkClipOpPriv.h"
|
|
|
|
constexpr int W = 150;
|
|
constexpr int H = 200;
|
|
|
|
static void show_text(SkCanvas* canvas, bool doAA) {
|
|
SkRandom rand;
|
|
SkPaint paint;
|
|
SkFont font(nullptr, 20);
|
|
font.setEdging(doAA ? SkFont::Edging::kSubpixelAntiAlias : SkFont::Edging::kAlias);
|
|
|
|
for (int i = 0; i < 200; ++i) {
|
|
paint.setColor((SK_A32_MASK << SK_A32_SHIFT) | rand.nextU());
|
|
canvas->drawString("Hamburgefons", rand.nextSScalar1() * W, rand.nextSScalar1() * H + 20,
|
|
font, paint);
|
|
}
|
|
}
|
|
|
|
static void show_fill(SkCanvas* canvas, bool doAA) {
|
|
SkRandom rand;
|
|
SkPaint paint;
|
|
paint.setAntiAlias(doAA);
|
|
|
|
for (int i = 0; i < 50; ++i) {
|
|
SkRect r;
|
|
SkPath p;
|
|
|
|
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
|
|
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
|
|
paint.setColor(rand.nextU());
|
|
canvas->drawRect(r, paint);
|
|
|
|
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
|
|
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
|
|
paint.setColor(rand.nextU());
|
|
p.addOval(r);
|
|
canvas->drawPath(p, paint);
|
|
}
|
|
}
|
|
|
|
static SkScalar randRange(SkRandom& rand, SkScalar min, SkScalar max) {
|
|
SkASSERT(min <= max);
|
|
return min + rand.nextUScalar1() * (max - min);
|
|
}
|
|
|
|
static void show_stroke(SkCanvas* canvas, bool doAA, SkScalar strokeWidth, int n) {
|
|
SkRandom rand;
|
|
SkPaint paint;
|
|
paint.setAntiAlias(doAA);
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
paint.setStrokeWidth(strokeWidth);
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
SkRect r;
|
|
SkPath p;
|
|
|
|
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
|
|
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
|
|
paint.setColor(rand.nextU());
|
|
canvas->drawRect(r, paint);
|
|
|
|
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
|
|
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
|
|
paint.setColor(rand.nextU());
|
|
p.addOval(r);
|
|
canvas->drawPath(p, paint);
|
|
|
|
const SkScalar minx = -SkIntToScalar(W)/4;
|
|
const SkScalar maxx = 5*SkIntToScalar(W)/4;
|
|
const SkScalar miny = -SkIntToScalar(H)/4;
|
|
const SkScalar maxy = 5*SkIntToScalar(H)/4;
|
|
paint.setColor(rand.nextU());
|
|
canvas->drawLine(randRange(rand, minx, maxx), randRange(rand, miny, maxy),
|
|
randRange(rand, minx, maxx), randRange(rand, miny, maxy),
|
|
paint);
|
|
}
|
|
}
|
|
|
|
static void show_hair(SkCanvas* canvas, bool doAA) {
|
|
show_stroke(canvas, doAA, 0, 150);
|
|
}
|
|
|
|
static void show_thick(SkCanvas* canvas, bool doAA) {
|
|
show_stroke(canvas, doAA, SkIntToScalar(5), 50);
|
|
}
|
|
|
|
typedef void (*CanvasProc)(SkCanvas*, bool);
|
|
|
|
class ClipView : public Sample {
|
|
SkString name() override { return SkString("Clip"); }
|
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
|
canvas->drawColor(SK_ColorWHITE);
|
|
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
|
|
|
static const CanvasProc gProc[] = {
|
|
show_text, show_thick, show_hair, show_fill
|
|
};
|
|
|
|
SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) };
|
|
SkPath clipPath;
|
|
r.inset(SK_Scalar1 / 4, SK_Scalar1 / 4);
|
|
clipPath.addRoundRect(r, SkIntToScalar(20), SkIntToScalar(20));
|
|
|
|
// clipPath.toggleInverseFillType();
|
|
|
|
for (int aa = 0; aa <= 1; ++aa) {
|
|
canvas->save();
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gProc); ++i) {
|
|
canvas->save();
|
|
canvas->clipPath(clipPath, kIntersect_SkClipOp, SkToBool(aa));
|
|
// canvas->drawColor(SK_ColorWHITE);
|
|
gProc[i](canvas, SkToBool(aa));
|
|
canvas->restore();
|
|
canvas->translate(W * SK_Scalar1 * 8 / 7, 0);
|
|
}
|
|
canvas->restore();
|
|
canvas->translate(0, H * SK_Scalar1 * 8 / 7);
|
|
}
|
|
}
|
|
};
|
|
|
|
DEF_SAMPLE( return new ClipView(); )
|