2011-08-29 17:41:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-08-29 18:05:05 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkClipOp.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkRRect.h"
|
|
|
|
#include "include/core/SkRect.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/utils/SkRandom.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/core/SkClipOpPriv.h"
|
2011-08-29 17:41:02 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class ComplexClip2GM : public GM {
|
|
|
|
public:
|
2014-02-16 13:25:24 +00:00
|
|
|
enum Clip {
|
|
|
|
kRect_Clip,
|
|
|
|
kRRect_Clip,
|
|
|
|
kPath_Clip
|
|
|
|
};
|
|
|
|
|
|
|
|
ComplexClip2GM(Clip clip, bool antiAlias)
|
|
|
|
: fClip(clip)
|
2012-05-15 17:03:16 +00:00
|
|
|
, fAntiAlias(antiAlias) {
|
2015-02-25 17:04:04 +00:00
|
|
|
SkScalar xA = 0.65f;
|
|
|
|
SkScalar xF = 50.65f;
|
|
|
|
|
|
|
|
SkScalar yA = 0.65f;
|
|
|
|
SkScalar yF = 50.65f;
|
|
|
|
|
|
|
|
fWidth = xF - xA;
|
|
|
|
fHeight = yF - yA;
|
|
|
|
|
|
|
|
fTotalWidth = kCols * fWidth + SK_Scalar1 * (kCols + 1) * kPadX;
|
|
|
|
fTotalHeight = kRows * fHeight + SK_Scalar1 * (kRows + 1) * kPadY;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2011-10-31 14:18:20 +00:00
|
|
|
this->setBGColor(SkColorSetRGB(0xDD,0xA0,0xDD));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-05-15 17:03:16 +00:00
|
|
|
// offset the rects a bit so we get antialiasing even in the rect case
|
2013-11-25 19:44:07 +00:00
|
|
|
SkScalar xA = 0.65f;
|
|
|
|
SkScalar xB = 10.65f;
|
|
|
|
SkScalar xC = 20.65f;
|
|
|
|
SkScalar xD = 30.65f;
|
|
|
|
SkScalar xE = 40.65f;
|
|
|
|
SkScalar xF = 50.65f;
|
|
|
|
|
|
|
|
SkScalar yA = 0.65f;
|
|
|
|
SkScalar yB = 10.65f;
|
|
|
|
SkScalar yC = 20.65f;
|
|
|
|
SkScalar yD = 30.65f;
|
|
|
|
SkScalar yE = 40.65f;
|
|
|
|
SkScalar yF = 50.65f;
|
2011-08-29 17:41:02 +00:00
|
|
|
|
2019-08-24 23:39:13 +00:00
|
|
|
fRects[0].setLTRB(xB, yB, xE, yE);
|
2014-02-16 13:25:24 +00:00
|
|
|
fRRects[0].setRectXY(fRects[0], 7, 7);
|
2019-09-14 19:13:23 +00:00
|
|
|
fPaths[0].addRoundRect(fRects[0], 5, 5);
|
2011-08-29 17:41:02 +00:00
|
|
|
fRectColors[0] = SK_ColorRED;
|
|
|
|
|
2019-08-24 23:39:13 +00:00
|
|
|
fRects[1].setLTRB(xA, yA, xD, yD);
|
2014-02-16 13:25:24 +00:00
|
|
|
fRRects[1].setRectXY(fRects[1], 7, 7);
|
2019-09-14 19:13:23 +00:00
|
|
|
fPaths[1].addRoundRect(fRects[1], 5, 5);
|
2011-08-29 17:41:02 +00:00
|
|
|
fRectColors[1] = SK_ColorGREEN;
|
|
|
|
|
2019-08-24 23:39:13 +00:00
|
|
|
fRects[2].setLTRB(xC, yA, xF, yD);
|
2014-02-16 13:25:24 +00:00
|
|
|
fRRects[2].setRectXY(fRects[2], 7, 7);
|
2019-09-14 19:13:23 +00:00
|
|
|
fPaths[2].addRoundRect(fRects[2], 5, 5);
|
2011-08-29 17:41:02 +00:00
|
|
|
fRectColors[2] = SK_ColorBLUE;
|
|
|
|
|
2019-08-24 23:39:13 +00:00
|
|
|
fRects[3].setLTRB(xA, yC, xD, yF);
|
2014-02-16 13:25:24 +00:00
|
|
|
fRRects[3].setRectXY(fRects[3], 7, 7);
|
2019-09-14 19:13:23 +00:00
|
|
|
fPaths[3].addRoundRect(fRects[3], 5, 5);
|
2011-08-29 17:41:02 +00:00
|
|
|
fRectColors[3] = SK_ColorYELLOW;
|
|
|
|
|
2019-08-24 23:39:13 +00:00
|
|
|
fRects[4].setLTRB(xC, yC, xF, yF);
|
2014-02-16 13:25:24 +00:00
|
|
|
fRRects[4].setRectXY(fRects[4], 7, 7);
|
2019-09-14 19:13:23 +00:00
|
|
|
fPaths[4].addRoundRect(fRects[4], 5, 5);
|
2011-08-29 17:41:02 +00:00
|
|
|
fRectColors[4] = SK_ColorCYAN;
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
const SkClipOp ops[] = {
|
|
|
|
kDifference_SkClipOp,
|
|
|
|
kIntersect_SkClipOp,
|
|
|
|
kUnion_SkClipOp,
|
|
|
|
kXOR_SkClipOp,
|
|
|
|
kReverseDifference_SkClipOp,
|
|
|
|
kReplace_SkClipOp,
|
2011-08-29 17:41:02 +00:00
|
|
|
};
|
|
|
|
|
2014-12-15 20:54:51 +00:00
|
|
|
SkRandom r;
|
2011-08-29 17:41:02 +00:00
|
|
|
for (int i = 0; i < kRows; ++i) {
|
|
|
|
for (int j = 0; j < kCols; ++j) {
|
|
|
|
for (int k = 0; k < 5; ++k) {
|
|
|
|
fOps[j*kRows+i][k] = ops[r.nextU() % SK_ARRAY_COUNT(ops)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-29 18:05:05 +00:00
|
|
|
}
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kRows = 5;
|
|
|
|
static constexpr int kCols = 5;
|
|
|
|
static constexpr int kPadX = 20;
|
|
|
|
static constexpr int kPadY = 20;
|
2011-08-29 18:05:05 +00:00
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
static const char* ClipStr(Clip clip) {
|
|
|
|
switch (clip) {
|
|
|
|
case kRect_Clip:
|
|
|
|
return "rect";
|
|
|
|
case kRRect_Clip:
|
|
|
|
return "rrect";
|
|
|
|
case kPath_Clip:
|
|
|
|
return "path";
|
|
|
|
}
|
|
|
|
SkDEBUGFAIL("Unknown clip type.");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
SkString onShortName() override {
|
2014-02-16 13:25:24 +00:00
|
|
|
if (kRect_Clip == fClip && !fAntiAlias) {
|
2012-05-15 17:03:16 +00:00
|
|
|
return SkString("complexclip2");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString str;
|
2012-08-23 18:19:56 +00:00
|
|
|
str.printf("complexclip2_%s_%s",
|
2014-02-16 13:25:24 +00:00
|
|
|
ClipStr(fClip),
|
2012-05-15 17:03:16 +00:00
|
|
|
fAntiAlias ? "aa" : "bw");
|
|
|
|
return str;
|
2011-08-29 18:05:05 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(SkScalarRoundToInt(fTotalWidth),
|
|
|
|
SkScalarRoundToInt(fTotalHeight));
|
2011-08-29 19:02:39 +00:00
|
|
|
}
|
2011-08-29 18:05:05 +00:00
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2011-08-29 17:41:02 +00:00
|
|
|
SkPaint rectPaint;
|
|
|
|
rectPaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
rectPaint.setStrokeWidth(-1);
|
|
|
|
|
|
|
|
SkPaint fillPaint;
|
|
|
|
fillPaint.setColor(SkColorSetRGB(0xA0,0xDD,0xA0));
|
|
|
|
|
|
|
|
for (int i = 0; i < kRows; ++i) {
|
|
|
|
for (int j = 0; j < kCols; ++j) {
|
|
|
|
canvas->save();
|
2012-05-15 17:03:16 +00:00
|
|
|
|
2011-08-29 17:41:02 +00:00
|
|
|
canvas->translate(kPadX * SK_Scalar1 + (fWidth + kPadX * SK_Scalar1)*j,
|
|
|
|
kPadY * SK_Scalar1 + (fHeight + kPadY * SK_Scalar1)*i);
|
2012-05-15 17:03:16 +00:00
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
// draw the original shapes first so we can see the
|
2012-05-15 17:03:16 +00:00
|
|
|
// antialiasing on the clipped draw
|
2011-08-29 17:41:02 +00:00
|
|
|
for (int k = 0; k < 5; ++k) {
|
2012-05-15 17:03:16 +00:00
|
|
|
rectPaint.setColor(fRectColors[k]);
|
2014-02-16 13:25:24 +00:00
|
|
|
switch (fClip) {
|
|
|
|
case kRect_Clip:
|
|
|
|
canvas->drawRect(fRects[k], rectPaint);
|
|
|
|
break;
|
|
|
|
case kRRect_Clip:
|
|
|
|
canvas->drawRRect(fRRects[k], rectPaint);
|
|
|
|
break;
|
|
|
|
case kPath_Clip:
|
|
|
|
canvas->drawPath(fPaths[k], rectPaint);
|
|
|
|
break;
|
2012-05-15 17:03:16 +00:00
|
|
|
}
|
2011-08-29 17:41:02 +00:00
|
|
|
}
|
2012-05-15 17:03:16 +00:00
|
|
|
|
2011-08-29 17:41:02 +00:00
|
|
|
for (int k = 0; k < 5; ++k) {
|
2014-02-16 13:25:24 +00:00
|
|
|
switch (fClip) {
|
|
|
|
case kRect_Clip:
|
|
|
|
canvas->clipRect(fRects[k],
|
|
|
|
fOps[j*kRows+i][k],
|
|
|
|
fAntiAlias);
|
|
|
|
break;
|
|
|
|
case kRRect_Clip:
|
|
|
|
canvas->clipRRect(fRRects[k],
|
|
|
|
fOps[j*kRows+i][k],
|
|
|
|
fAntiAlias);
|
|
|
|
break;
|
|
|
|
case kPath_Clip:
|
|
|
|
canvas->clipPath(fPaths[k],
|
|
|
|
fOps[j*kRows+i][k],
|
|
|
|
fAntiAlias);
|
|
|
|
break;
|
2012-05-15 17:03:16 +00:00
|
|
|
}
|
2011-08-29 17:41:02 +00:00
|
|
|
}
|
2012-05-15 17:03:16 +00:00
|
|
|
canvas->drawRect(SkRect::MakeWH(fWidth, fHeight), fillPaint);
|
2011-08-29 17:41:02 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2014-02-16 13:25:24 +00:00
|
|
|
Clip fClip;
|
2012-05-15 17:03:16 +00:00
|
|
|
bool fAntiAlias;
|
2011-08-29 17:41:02 +00:00
|
|
|
SkRect fRects[5];
|
2014-02-16 13:25:24 +00:00
|
|
|
SkRRect fRRects[5];
|
2012-05-15 17:03:16 +00:00
|
|
|
SkPath fPaths[5];
|
2011-08-29 17:41:02 +00:00
|
|
|
SkColor fRectColors[5];
|
2016-12-09 14:00:50 +00:00
|
|
|
SkClipOp fOps[kRows * kCols][5];
|
2011-08-29 17:41:02 +00:00
|
|
|
SkScalar fWidth;
|
|
|
|
SkScalar fHeight;
|
|
|
|
SkScalar fTotalWidth;
|
|
|
|
SkScalar fTotalHeight;
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
// bw
|
|
|
|
DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRect_Clip, false); )
|
|
|
|
DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRRect_Clip, false); )
|
|
|
|
DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kPath_Clip, false); )
|
2012-05-15 17:03:16 +00:00
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
// aa
|
|
|
|
DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRect_Clip, true); )
|
|
|
|
DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRRect_Clip, true); )
|
|
|
|
DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kPath_Clip, true); )
|
2012-05-15 17:03:16 +00:00
|
|
|
|
2011-08-29 17:41:02 +00:00
|
|
|
}
|