2013-08-20 12:11:31 +00:00
|
|
|
/*
|
|
|
|
* 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.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
2013-08-20 12:11:31 +00:00
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRRect.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
// Test out various combinations of nested rects, ovals and rrects.
|
|
|
|
class NestedGM : public GM {
|
|
|
|
public:
|
2015-05-19 11:35:38 +00:00
|
|
|
NestedGM(bool doAA, bool flipped) : fDoAA(doAA), fFlipped(flipped) {
|
2015-06-15 13:51:08 +00:00
|
|
|
this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
|
2013-08-20 12:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-08-20 12:11:31 +00:00
|
|
|
SkString name("nested");
|
2015-05-19 11:35:38 +00:00
|
|
|
if (fFlipped) {
|
|
|
|
name.append("_flipY");
|
|
|
|
}
|
2013-08-20 12:11:31 +00:00
|
|
|
if (fDoAA) {
|
|
|
|
name.append("_aa");
|
|
|
|
} else {
|
|
|
|
name.append("_bw");
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(kImageWidth, kImageHeight);
|
2013-08-20 12:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum Shapes {
|
|
|
|
kRect_Shape = 0,
|
|
|
|
kRRect_Shape,
|
|
|
|
kOval_Shape,
|
|
|
|
kShapeCount
|
|
|
|
};
|
|
|
|
|
|
|
|
static void AddShape(SkPath* path, const SkRect& rect, Shapes shape, SkPath::Direction dir) {
|
|
|
|
switch (shape) {
|
|
|
|
case kRect_Shape:
|
|
|
|
path->addRect(rect, dir);
|
|
|
|
break;
|
|
|
|
case kRRect_Shape: {
|
|
|
|
SkRRect rr;
|
|
|
|
rr.setRectXY(rect, 5, 5);
|
|
|
|
path->addRRect(rr, dir);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kOval_Shape:
|
|
|
|
path->addOval(rect, dir);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-08-20 12:11:31 +00:00
|
|
|
|
|
|
|
SkPaint shapePaint;
|
|
|
|
shapePaint.setColor(SK_ColorBLACK);
|
|
|
|
shapePaint.setAntiAlias(fDoAA);
|
|
|
|
|
|
|
|
SkRect outerRect = SkRect::MakeWH(40, 40);
|
|
|
|
|
|
|
|
SkRect innerRects[] = {
|
|
|
|
{ 10, 10, 30, 30 }, // small
|
|
|
|
{ .5f, 18, 4.5f, 22 } // smaller and offset to left
|
|
|
|
};
|
|
|
|
|
|
|
|
// draw a background pattern to make transparency errors more apparent
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-08-20 12:11:31 +00:00
|
|
|
|
|
|
|
for (int y = 0; y < kImageHeight; y += 10) {
|
|
|
|
for (int x = 0; x < kImageWidth; x += 10) {
|
2013-08-21 07:01:29 +00:00
|
|
|
SkRect r = SkRect::MakeXYWH(SkIntToScalar(x),
|
|
|
|
SkIntToScalar(y),
|
2013-08-20 12:11:31 +00:00
|
|
|
10, 10);
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(rand.nextU() | 0xFF000000);
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 11:35:38 +00:00
|
|
|
SkScalar xOff = 2, yOff = 2;
|
2013-08-20 12:11:31 +00:00
|
|
|
for (int outerShape = 0; outerShape < kShapeCount; ++outerShape) {
|
|
|
|
for (int innerShape = 0; innerShape < kShapeCount; ++innerShape) {
|
|
|
|
for (size_t innerRect = 0; innerRect < SK_ARRAY_COUNT(innerRects); ++innerRect) {
|
|
|
|
SkPath path;
|
|
|
|
|
|
|
|
AddShape(&path, outerRect, (Shapes) outerShape, SkPath::kCW_Direction);
|
2013-08-21 07:01:29 +00:00
|
|
|
AddShape(&path, innerRects[innerRect], (Shapes) innerShape,
|
2013-08-20 12:11:31 +00:00
|
|
|
SkPath::kCCW_Direction);
|
|
|
|
|
2015-05-19 11:35:38 +00:00
|
|
|
canvas->save();
|
|
|
|
if (fFlipped) {
|
|
|
|
canvas->scale(1.0f, -1.0f);
|
|
|
|
canvas->translate(xOff, -yOff - 40.0f);
|
|
|
|
} else {
|
|
|
|
canvas->translate(xOff, yOff);
|
|
|
|
}
|
|
|
|
|
2013-08-20 12:11:31 +00:00
|
|
|
canvas->drawPath(path, shapePaint);
|
2015-05-19 11:35:38 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
xOff += 45;
|
2013-08-20 12:11:31 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-19 11:35:38 +00:00
|
|
|
|
|
|
|
xOff = 2;
|
|
|
|
yOff += 45;
|
2013-08-20 12:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kImageWidth = 269;
|
|
|
|
static constexpr int kImageHeight = 134;
|
2013-08-20 12:11:31 +00:00
|
|
|
|
|
|
|
bool fDoAA;
|
2015-05-19 11:35:38 +00:00
|
|
|
bool fFlipped;
|
2013-08-20 12:11:31 +00:00
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-05-19 11:35:38 +00:00
|
|
|
DEF_GM( return new NestedGM(/* doAA = */ true, /* flipped = */ false); )
|
|
|
|
DEF_GM( return new NestedGM(/* doAA = */ false, /* flipped = */ false); )
|
|
|
|
DEF_GM( return new NestedGM(/* doAA = */ true, /* flipped = */ true); )
|
|
|
|
DEF_GM( return new NestedGM(/* doAA = */ false, /* flipped = */ true); )
|
2013-08-20 12:11:31 +00:00
|
|
|
|
|
|
|
}
|