aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-03-24 16:00:35 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-24 16:00:55 +0000
commite7c85c45c4c0a97adc6711bb12ecacc36af4ba11 (patch)
tree56656a9d1ee3912b7c43c472632482b594a2f325 /gm
parentadf7b330bde6ddb03c888143f16cb3b04c074ebd (diff)
Revert "Create new inset algorithm for spot shadows"
This reverts commit e5f5bf5175e426ebb6aa234f4387831c898f20ad. Reason for revert: Breaking a bunch of bots. e.g: https://luci-milo.appspot.com/swarming/task/3519cae0a03c7b10/steps/dm/0/stdout Original change's description: > Create new inset algorithm for spot shadows > > BUG=skia: > > Change-Id: If7c67c2a5b9beea28f86d13362a5156b46394d0e > Reviewed-on: https://skia-review.googlesource.com/9875 > Commit-Queue: Ravi Mistry <rmistry@google.com> > Reviewed-by: Brian Salomon <bsalomon@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> > TBR=jvanverth@google.com,bsalomon@google.com,rmistry@google.com,robertphillips@google.com,msarett@google.com,reviews@skia.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Change-Id: I3d119ff631dbb1a41f873b9c8753d542ec91254e Reviewed-on: https://skia-review.googlesource.com/10112 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'gm')
-rw-r--r--gm/convex_all_line_paths.cpp436
-rw-r--r--gm/shadowutils.cpp3
2 files changed, 135 insertions, 304 deletions
diff --git a/gm/convex_all_line_paths.cpp b/gm/convex_all_line_paths.cpp
index a4bc6a66cb..62e8835831 100644
--- a/gm/convex_all_line_paths.cpp
+++ b/gm/convex_all_line_paths.cpp
@@ -6,7 +6,6 @@
*/
#include "gm.h"
-#include "SkInsetConvexPolygon.h"
#include "SkPathPriv.h"
static void create_ngon(int n, SkPoint* pts, SkScalar width, SkScalar height) {
@@ -23,135 +22,6 @@ static void create_ngon(int n, SkPoint* pts, SkScalar width, SkScalar height) {
}
}
-namespace ConvexLineOnlyData {
-// narrow rect
-const SkPoint gPoints0[] = {
- { -1.5f, -50.0f },
- { 1.5f, -50.0f },
- { 1.5f, 50.0f },
- { -1.5f, 50.0f }
-};
-// narrow rect on an angle
-const SkPoint gPoints1[] = {
- { -50.0f, -49.0f },
- { -49.0f, -50.0f },
- { 50.0f, 49.0f },
- { 49.0f, 50.0f }
-};
-// trap - narrow on top - wide on bottom
-const SkPoint gPoints2[] = {
- { -10.0f, -50.0f },
- { 10.0f, -50.0f },
- { 50.0f, 50.0f },
- { -50.0f, 50.0f }
-};
-// wide skewed rect
-const SkPoint gPoints3[] = {
- { -50.0f, -50.0f },
- { 0.0f, -50.0f },
- { 50.0f, 50.0f },
- { 0.0f, 50.0f }
-};
-// thin rect with colinear-ish lines
-const SkPoint gPoints4[] = {
- { -6.0f, -50.0f },
- { 4.0f, -50.0f },
- { 5.0f, -25.0f },
- { 6.0f, 0.0f },
- { 5.0f, 25.0f },
- { 4.0f, 50.0f },
- { -4.0f, 50.0f }
-};
-// degenerate
-const SkPoint gPoints5[] = {
- { -0.025f, -0.025f },
- { 0.025f, -0.025f },
- { 0.025f, 0.025f },
- { -0.025f, 0.025f }
-};
-// Triangle in which the first point should fuse with last
-const SkPoint gPoints6[] = {
- { -20.0f, -13.0f },
- { -20.0f, -13.05f },
- { 20.0f, -13.0f },
- { 20.0f, 27.0f }
-};
-// thin rect with colinear lines
-const SkPoint gPoints7[] = {
- { -10.0f, -50.0f },
- { 10.0f, -50.0f },
- { 10.0f, -25.0f },
- { 10.0f, 0.0f },
- { 10.0f, 25.0f },
- { 10.0f, 50.0f },
- { -10.0f, 50.0f }
-};
-// capped teardrop
-const SkPoint gPoints8[] = {
- { 50.00f, 50.00f },
- { 0.00f, 50.00f },
- { -15.45f, 47.55f },
- { -29.39f, 40.45f },
- { -40.45f, 29.39f },
- { -47.55f, 15.45f },
- { -50.00f, 0.00f },
- { -47.55f, -15.45f },
- { -40.45f, -29.39f },
- { -29.39f, -40.45f },
- { -15.45f, -47.55f },
- { 0.00f, -50.00f },
- { 50.00f, -50.00f }
-};
-// teardrop
-const SkPoint gPoints9[] = {
- { 4.39f, 40.45f },
- { -9.55f, 47.55f },
- { -25.00f, 50.00f },
- { -40.45f, 47.55f },
- { -54.39f, 40.45f },
- { -65.45f, 29.39f },
- { -72.55f, 15.45f },
- { -75.00f, 0.00f },
- { -72.55f, -15.45f },
- { -65.45f, -29.39f },
- { -54.39f, -40.45f },
- { -40.45f, -47.55f },
- { -25.0f, -50.0f },
- { -9.55f, -47.55f },
- { 4.39f, -40.45f },
- { 75.00f, 0.00f }
-};
-// clipped triangle
-const SkPoint gPoints10[] = {
- { -10.0f, -50.0f },
- { 10.0f, -50.0f },
- { 50.0f, 31.0f },
- { 40.0f, 50.0f },
- { -40.0f, 50.0f },
- { -50.0f, 31.0f },
-};
-
-const SkPoint* gPoints[] = {
- gPoints0, gPoints1, gPoints2, gPoints3, gPoints4, gPoints5, gPoints6,
- gPoints7, gPoints8, gPoints9, gPoints10,
-};
-
-const size_t gSizes[] = {
- SK_ARRAY_COUNT(gPoints0),
- SK_ARRAY_COUNT(gPoints1),
- SK_ARRAY_COUNT(gPoints2),
- SK_ARRAY_COUNT(gPoints3),
- SK_ARRAY_COUNT(gPoints4),
- SK_ARRAY_COUNT(gPoints5),
- SK_ARRAY_COUNT(gPoints6),
- SK_ARRAY_COUNT(gPoints7),
- SK_ARRAY_COUNT(gPoints8),
- SK_ARRAY_COUNT(gPoints9),
- SK_ARRAY_COUNT(gPoints10),
-};
-static_assert(SK_ARRAY_COUNT(gSizes) == SK_ARRAY_COUNT(gPoints), "array_mismatch");
-}
-
namespace skiagm {
// This GM is intended to exercise Ganesh's handling of convex line-only
@@ -172,19 +42,146 @@ protected:
SkISize onISize() override { return SkISize::Make(kGMWidth, kGMHeight); }
bool runAsBench() const override { return true; }
- static SkPath GetPath(int index, SkPath::Direction dir) {
+ static SkPath GetPath(int index, int offset, SkPath::Direction dir) {
+ // narrow rect
+ const SkPoint gPoints0[] = {
+ { -1.5f, -50.0f },
+ { 1.5f, -50.0f },
+ { 1.5f, 50.0f },
+ { -1.5f, 50.0f }
+ };
+ // narrow rect on an angle
+ const SkPoint gPoints1[] = {
+ { -50.0f, -49.0f },
+ { -49.0f, -50.0f },
+ { 50.0f, 49.0f },
+ { 49.0f, 50.0f }
+ };
+ // trap - narrow on top - wide on bottom
+ const SkPoint gPoints2[] = {
+ { -10.0f, -50.0f },
+ { 10.0f, -50.0f },
+ { 50.0f, 50.0f },
+ { -50.0f, 50.0f }
+ };
+ // wide skewed rect
+ const SkPoint gPoints3[] = {
+ { -50.0f, -50.0f },
+ { 0.0f, -50.0f },
+ { 50.0f, 50.0f },
+ { 0.0f, 50.0f }
+ };
+ // thin rect with colinear-ish lines
+ const SkPoint gPoints4[] = {
+ { -6.0f, -50.0f },
+ { 4.0f, -50.0f },
+ { 5.0f, -25.0f },
+ { 6.0f, 0.0f },
+ { 5.0f, 25.0f },
+ { 4.0f, 50.0f },
+ { -4.0f, 50.0f }
+ };
+ // degenerate
+ const SkPoint gPoints5[] = {
+ { -0.025f, -0.025f },
+ { 0.025f, -0.025f },
+ { 0.025f, 0.025f },
+ { -0.025f, 0.025f }
+ };
+ // Triangle in which the first point should fuse with last
+ const SkPoint gPoints6[] = {
+ { -20.0f, -13.0f },
+ { -20.0f, -13.05f },
+ { 20.0f, -13.0f },
+ { 20.0f, 27.0f }
+ };
+ // thin rect with colinear lines
+ const SkPoint gPoints7[] = {
+ { -10.0f, -50.0f },
+ { 10.0f, -50.0f },
+ { 10.0f, -25.0f },
+ { 10.0f, 0.0f },
+ { 10.0f, 25.0f },
+ { 10.0f, 50.0f },
+ { -10.0f, 50.0f }
+ };
+ // capped teardrop
+ const SkPoint gPoints8[] = {
+ { 50.00f, 50.00f },
+ { 0.00f, 50.00f },
+ { -15.45f, 47.55f },
+ { -29.39f, 40.45f },
+ { -40.45f, 29.39f },
+ { -47.55f, 15.45f },
+ { -50.00f, 0.00f },
+ { -47.55f, -15.45f },
+ { -40.45f, -29.39f },
+ { -29.39f, -40.45f },
+ { -15.45f, -47.55f },
+ { 0.00f, -50.00f },
+ { 50.00f, -50.00f }
+ };
+ // teardrop
+ const SkPoint gPoints9[] = {
+ { 4.39f, 40.45f },
+ { -9.55f, 47.55f },
+ { -25.00f, 50.00f },
+ { -40.45f, 47.55f },
+ { -54.39f, 40.45f },
+ { -65.45f, 29.39f },
+ { -72.55f, 15.45f },
+ { -75.00f, 0.00f },
+ { -72.55f, -15.45f },
+ { -65.45f, -29.39f },
+ { -54.39f, -40.45f },
+ { -40.45f, -47.55f },
+ { -25.0f, -50.0f },
+ { -9.55f, -47.55f },
+ { 4.39f, -40.45f },
+ { 75.00f, 0.00f }
+ };
+ // clipped triangle
+ const SkPoint gPoints10[] = {
+ { -10.0f, -50.0f },
+ { 10.0f, -50.0f },
+ { 50.0f, 31.0f },
+ { 40.0f, 50.0f },
+ { -40.0f, 50.0f },
+ { -50.0f, 31.0f },
+ };
+
+ const SkPoint* gPoints[] = {
+ gPoints0, gPoints1, gPoints2, gPoints3, gPoints4, gPoints5, gPoints6,
+ gPoints7, gPoints8, gPoints9, gPoints10,
+ };
+
+ const size_t gSizes[] = {
+ SK_ARRAY_COUNT(gPoints0),
+ SK_ARRAY_COUNT(gPoints1),
+ SK_ARRAY_COUNT(gPoints2),
+ SK_ARRAY_COUNT(gPoints3),
+ SK_ARRAY_COUNT(gPoints4),
+ SK_ARRAY_COUNT(gPoints5),
+ SK_ARRAY_COUNT(gPoints6),
+ SK_ARRAY_COUNT(gPoints7),
+ SK_ARRAY_COUNT(gPoints8),
+ SK_ARRAY_COUNT(gPoints9),
+ SK_ARRAY_COUNT(gPoints10),
+ };
+ static_assert(SK_ARRAY_COUNT(gSizes) == SK_ARRAY_COUNT(gPoints), "array_mismatch");
+
std::unique_ptr<SkPoint[]> data(nullptr);
const SkPoint* points;
int numPts;
- if (index < (int) SK_ARRAY_COUNT(ConvexLineOnlyData::gPoints)) {
+ if (index < (int) SK_ARRAY_COUNT(gPoints)) {
// manually specified
- points = ConvexLineOnlyData::gPoints[index];
- numPts = (int)ConvexLineOnlyData::gSizes[index];
+ points = gPoints[index];
+ numPts = (int) gSizes[index];
} else {
// procedurally generated
SkScalar width = kMaxPathHeight/2;
SkScalar height = kMaxPathHeight/2;
- switch (index-SK_ARRAY_COUNT(ConvexLineOnlyData::gPoints)) {
+ switch (index-SK_ARRAY_COUNT(gPoints)) {
case 0:
numPts = 3;
break;
@@ -262,7 +259,7 @@ protected:
SkPoint center;
{
- SkPath path = GetPath(index, SkPath::kCW_Direction);
+ SkPath path = GetPath(index, 0, SkPath::kCW_Direction);
if (offset->fX+path.getBounds().width() > kGMWidth) {
offset->fX = 0;
offset->fY += kMaxPathHeight;
@@ -289,7 +286,7 @@ protected:
paint.setAntiAlias(true);
for (size_t i = 0; i < SK_ARRAY_COUNT(scales); ++i) {
- SkPath path = GetPath(index, dirs[i%2]);
+ SkPath path = GetPath(index, (int) i, dirs[i%2]);
if (fDoStrokeAndFill) {
paint.setStyle(SkPaint::kStrokeAndFill_Style);
paint.setStrokeJoin(joins[i%3]);
@@ -350,173 +347,8 @@ private:
typedef GM INHERITED;
};
-// This GM is intended to exercise the insetting of convex polygons
-class ConvexPolygonInsetGM : public GM {
-public:
- ConvexPolygonInsetGM() {
- this->setBGColor(0xFFFFFFFF);
- }
-
-protected:
- SkString onShortName() override {
- return SkString("convex-polygon-inset");
- }
- SkISize onISize() override { return SkISize::Make(kGMWidth, kGMHeight); }
- bool runAsBench() const override { return true; }
-
- static void GetPath(int index, SkPath::Direction dir,
- std::unique_ptr<SkPoint[]>* data, int* numPts) {
- if (index < (int)SK_ARRAY_COUNT(ConvexLineOnlyData::gPoints)) {
- // manually specified
- *numPts = (int)ConvexLineOnlyData::gSizes[index];
- data->reset(new SkPoint[*numPts]);
- if (SkPath::kCW_Direction == dir) {
- for (int i = 0; i < *numPts; ++i) {
- (*data)[i] = ConvexLineOnlyData::gPoints[index][i];
- }
- } else {
- for (int i = 0; i < *numPts; ++i) {
- (*data)[i] = ConvexLineOnlyData::gPoints[index][*numPts - i - 1];
- }
- }
- } else {
- // procedurally generated
- SkScalar width = kMaxPathHeight / 2;
- SkScalar height = kMaxPathHeight / 2;
- switch (index - SK_ARRAY_COUNT(ConvexLineOnlyData::gPoints)) {
- case 0:
- *numPts = 3;
- break;
- case 1:
- *numPts = 4;
- break;
- case 2:
- *numPts = 5;
- break;
- case 3: // squashed pentagon
- *numPts = 5;
- width = kMaxPathHeight / 5;
- break;
- case 4:
- *numPts = 6;
- break;
- case 5:
- *numPts = 8;
- break;
- case 6: // squashed octogon
- *numPts = 8;
- width = kMaxPathHeight / 5;
- break;
- case 7:
- *numPts = 20;
- break;
- case 8:
- *numPts = 100;
- break;
- default:
- *numPts = 3;
- break;
- }
-
- data->reset(new SkPoint[*numPts]);
-
- create_ngon(*numPts, data->get(), width, height);
- if (SkPath::kCCW_Direction == dir) {
- // reverse it
- for (int i = 0; i < *numPts/2; ++i) {
- SkPoint tmp = (*data)[i];
- (*data)[i] = (*data)[*numPts - i - 1];
- (*data)[*numPts - i - 1] = tmp;
- }
- }
- }
- }
-
- // Draw a single path several times, shrinking it, flipping its direction
- // and changing its start vertex each time.
- void drawPath(SkCanvas* canvas, int index, SkPoint* offset) {
-
- SkPoint center;
- {
- std::unique_ptr<SkPoint[]> data(nullptr);
- int numPts;
- GetPath(index, SkPath::kCW_Direction, &data, &numPts);
- SkRect bounds;
- bounds.set(data.get(), numPts);
- if (offset->fX + bounds.width() > kGMWidth) {
- offset->fX = 0;
- offset->fY += kMaxPathHeight;
- }
- center = { offset->fX + SkScalarHalf(bounds.width()), offset->fY };
- offset->fX += bounds.width();
- }
-
- const SkPath::Direction dirs[2] = { SkPath::kCW_Direction, SkPath::kCCW_Direction };
- const float insets[] = { 5, 10, 15, 20, 25, 30, 35, 40 };
- const SkColor colors[] = { 0xFF901313, 0xFF8D6214, 0xFF698B14, 0xFF1C8914,
- 0xFF148755, 0xFF146C84, 0xFF142482, 0xFF4A1480 };
-
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(1);
-
- std::unique_ptr<SkPoint[]> data(nullptr);
- int numPts;
- GetPath(index, dirs[index % 2], &data, &numPts);
- {
- SkPath path;
- path.moveTo(data.get()[0]);
- for (int i = 1; i < numPts; ++i) {
- path.lineTo(data.get()[i]);
- }
- path.close();
- canvas->save();
- canvas->translate(center.fX, center.fY);
- canvas->drawPath(path, paint);
- canvas->restore();
- }
-
- SkTDArray<SkPoint> insetPoly;
- for (size_t i = 0; i < SK_ARRAY_COUNT(insets); ++i) {
- if (SkInsetConvexPolygon(data.get(), numPts, insets[i], &insetPoly)) {
- SkPath path;
- path.moveTo(insetPoly[0]);
- for (int i = 1; i < insetPoly.count(); ++i) {
- path.lineTo(insetPoly[i]);
- }
- path.close();
-
- paint.setColor(colors[i]);
- canvas->save();
- canvas->translate(center.fX, center.fY);
- canvas->drawPath(path, paint);
- canvas->restore();
- }
- }
- }
-
- void onDraw(SkCanvas* canvas) override {
- // the right edge of the last drawn path
- SkPoint offset = { 0, SkScalarHalf(kMaxPathHeight) };
-
- for (int i = 0; i < kNumPaths; ++i) {
- this->drawPath(canvas, i, &offset);
- }
- }
-
-private:
- static constexpr int kNumPaths = 20;
- static constexpr int kMaxPathHeight = 100;
- static constexpr int kGMWidth = 512;
- static constexpr int kGMHeight = 512;
-
- typedef GM INHERITED;
-};
-
//////////////////////////////////////////////////////////////////////////////
DEF_GM(return new ConvexLineOnlyPathsGM(false);)
DEF_GM(return new ConvexLineOnlyPathsGM(true);)
-DEF_GM(return new ConvexPolygonInsetGM();)
}
diff --git a/gm/shadowutils.cpp b/gm/shadowutils.cpp
index 53d9b78602..350a546f0a 100644
--- a/gm/shadowutils.cpp
+++ b/gm/shadowutils.cpp
@@ -19,7 +19,7 @@ void draw_shadow(SkCanvas* canvas, const SkPath& path, int height, SkColor color
color, flags, cache);
}
-static constexpr int kW = 800;
+static constexpr int kW = 700;
static constexpr int kH = 800;
DEF_SIMPLE_GM(shadow_utils, canvas, kW, kH) {
@@ -38,7 +38,6 @@ DEF_SIMPLE_GM(shadow_utils, canvas, kW, kH) {
paths.push_back().addRect(SkRect::MakeWH(50, 50));
paths.push_back().addCircle(25, 25, 25);
paths.push_back().cubicTo(100, 50, 20, 100, 0, 0);
- paths.push_back().addOval(SkRect::MakeWH(20, 60));
static constexpr SkScalar kPad = 15.f;
static constexpr SkPoint3 kLightPos = {250, 400, 500};