2015-04-28 14:42:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkPoint.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"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkPathPriv.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2015-04-28 14:42:04 +00:00
|
|
|
|
|
|
|
static void create_ngon(int n, SkPoint* pts, SkScalar width, SkScalar height) {
|
2019-04-02 14:59:28 +00:00
|
|
|
float angleStep = 360.0f / n, angle = 0.0f;
|
2015-04-28 14:42:04 +00:00
|
|
|
if ((n % 2) == 1) {
|
|
|
|
angle = angleStep/2.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < n; ++i) {
|
2019-04-02 14:59:28 +00:00
|
|
|
pts[i].fX = -SkScalarSin(SkDegreesToRadians(angle)) * width;
|
|
|
|
pts[i].fY = SkScalarCos(SkDegreesToRadians(angle)) * height;
|
2015-04-28 14:42:04 +00:00
|
|
|
angle += angleStep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Revert "Revert "Create new inset algorithm for spot shadows""
This reverts commit e7c85c45c4c0a97adc6711bb12ecacc36af4ba11.
Reason for revert: <INSERT REASONING HERE>
Original change's description:
> 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>
>
TBR=jvanverth@google.com,bsalomon@google.com,rmistry@google.com,msarett@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Change-Id: Ib3998300606d3a2e2fb3a14b2088cfad48363501
Reviewed-on: https://skia-review.googlesource.com/10113
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2017-03-24 16:07:20 +00:00
|
|
|
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 },
|
two pass convexity
This separates the existing convexity logic into
two passes. The first pass detects concavity by
counting the changes in direction.
The second pass computes the cross product to
see that all angles bend in the same direction, and
computes the dot product to see if the angle
doubles back on itself.
The second pass treats axis-aligned vectors
separately, and computes the dot and cross products
by comparing point values; it does not use arithmetic
to determine convexity, so it works with all finite
values.
A compile time switch enables returning concave
for co-linear diagonal points:
If successive points are not axis-aligned, and
those points are co-linear along a diagonal;
the path is treated as concave. This is conservative
but avoids paths that change convexity when the
are translated or scaled, since transforming the
path may cause the midpoint to shift to either
side of a line formed by the endpoints.
The compile time switch is set so that co-linear
diagonal points do not affect convexity. Note that
this permits shapes formerly considered concave, such
as stroked lines with round caps, to become convex;
this accounts for many of the GM differences.
A path may double back on itself and be convex;
for instance, a path containing a single line.
Path may have multiple initial moveTo verbs, or
trailing moveTo verbs, and still evaluate as convex.
A separate entry point, SkPathPriv::IsConvex()
allows passing an array of points instead of a path.
A legacy define has been checked into Chrome to
use the old code until layout tests have been
rebaselined.
R=reed@google.com,bsalomon@google.com
Bug:899689
Change-Id: I392bbe04836ffb19666ad92ab2a2404c56543019
Reviewed-on: https://skia-review.googlesource.com/c/173427
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Cary Clark <caryclark@skia.org>
2018-12-12 19:50:23 +00:00
|
|
|
{ 5.0f, -25.0f }, // remove if collinear diagonal points are not concave
|
Revert "Revert "Create new inset algorithm for spot shadows""
This reverts commit e7c85c45c4c0a97adc6711bb12ecacc36af4ba11.
Reason for revert: <INSERT REASONING HERE>
Original change's description:
> 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>
>
TBR=jvanverth@google.com,bsalomon@google.com,rmistry@google.com,msarett@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Change-Id: Ib3998300606d3a2e2fb3a14b2088cfad48363501
Reviewed-on: https://skia-review.googlesource.com/10113
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2017-03-24 16:07:20 +00:00
|
|
|
{ 6.0f, 0.0f },
|
two pass convexity
This separates the existing convexity logic into
two passes. The first pass detects concavity by
counting the changes in direction.
The second pass computes the cross product to
see that all angles bend in the same direction, and
computes the dot product to see if the angle
doubles back on itself.
The second pass treats axis-aligned vectors
separately, and computes the dot and cross products
by comparing point values; it does not use arithmetic
to determine convexity, so it works with all finite
values.
A compile time switch enables returning concave
for co-linear diagonal points:
If successive points are not axis-aligned, and
those points are co-linear along a diagonal;
the path is treated as concave. This is conservative
but avoids paths that change convexity when the
are translated or scaled, since transforming the
path may cause the midpoint to shift to either
side of a line formed by the endpoints.
The compile time switch is set so that co-linear
diagonal points do not affect convexity. Note that
this permits shapes formerly considered concave, such
as stroked lines with round caps, to become convex;
this accounts for many of the GM differences.
A path may double back on itself and be convex;
for instance, a path containing a single line.
Path may have multiple initial moveTo verbs, or
trailing moveTo verbs, and still evaluate as convex.
A separate entry point, SkPathPriv::IsConvex()
allows passing an array of points instead of a path.
A legacy define has been checked into Chrome to
use the old code until layout tests have been
rebaselined.
R=reed@google.com,bsalomon@google.com
Bug:899689
Change-Id: I392bbe04836ffb19666ad92ab2a2404c56543019
Reviewed-on: https://skia-review.googlesource.com/c/173427
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Cary Clark <caryclark@skia.org>
2018-12-12 19:50:23 +00:00
|
|
|
{ 5.0f, 25.0f }, // remove if collinear diagonal points are not concave
|
Revert "Revert "Create new inset algorithm for spot shadows""
This reverts commit e7c85c45c4c0a97adc6711bb12ecacc36af4ba11.
Reason for revert: <INSERT REASONING HERE>
Original change's description:
> 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>
>
TBR=jvanverth@google.com,bsalomon@google.com,rmistry@google.com,msarett@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Change-Id: Ib3998300606d3a2e2fb3a14b2088cfad48363501
Reviewed-on: https://skia-review.googlesource.com/10113
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2017-03-24 16:07:20 +00:00
|
|
|
{ 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");
|
|
|
|
}
|
|
|
|
|
2015-04-28 14:42:04 +00:00
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
// This GM is intended to exercise Ganesh's handling of convex line-only
|
|
|
|
// paths
|
|
|
|
class ConvexLineOnlyPathsGM : public GM {
|
|
|
|
public:
|
2016-08-26 12:30:19 +00:00
|
|
|
ConvexLineOnlyPathsGM(bool doStrokeAndFill) : fDoStrokeAndFill(doStrokeAndFill) {
|
2015-04-28 14:42:04 +00:00
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2016-08-26 12:30:19 +00:00
|
|
|
SkString onShortName() override {
|
|
|
|
if (fDoStrokeAndFill) {
|
|
|
|
return SkString("convex-lineonly-paths-stroke-and-fill");
|
|
|
|
}
|
|
|
|
return SkString("convex-lineonly-paths");
|
|
|
|
}
|
2015-04-28 14:42:04 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(kGMWidth, kGMHeight); }
|
|
|
|
bool runAsBench() const override { return true; }
|
|
|
|
|
2019-11-22 11:03:22 +00:00
|
|
|
static SkPath GetPath(int index, SkPath::Direction dir) {
|
2016-11-02 21:07:33 +00:00
|
|
|
std::unique_ptr<SkPoint[]> data(nullptr);
|
2015-04-28 14:42:04 +00:00
|
|
|
const SkPoint* points;
|
|
|
|
int numPts;
|
Revert "Revert "Create new inset algorithm for spot shadows""
This reverts commit e7c85c45c4c0a97adc6711bb12ecacc36af4ba11.
Reason for revert: <INSERT REASONING HERE>
Original change's description:
> 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>
>
TBR=jvanverth@google.com,bsalomon@google.com,rmistry@google.com,msarett@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Change-Id: Ib3998300606d3a2e2fb3a14b2088cfad48363501
Reviewed-on: https://skia-review.googlesource.com/10113
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2017-03-24 16:07:20 +00:00
|
|
|
if (index < (int) SK_ARRAY_COUNT(ConvexLineOnlyData::gPoints)) {
|
2015-04-28 14:42:04 +00:00
|
|
|
// manually specified
|
Revert "Revert "Create new inset algorithm for spot shadows""
This reverts commit e7c85c45c4c0a97adc6711bb12ecacc36af4ba11.
Reason for revert: <INSERT REASONING HERE>
Original change's description:
> 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>
>
TBR=jvanverth@google.com,bsalomon@google.com,rmistry@google.com,msarett@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Change-Id: Ib3998300606d3a2e2fb3a14b2088cfad48363501
Reviewed-on: https://skia-review.googlesource.com/10113
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2017-03-24 16:07:20 +00:00
|
|
|
points = ConvexLineOnlyData::gPoints[index];
|
|
|
|
numPts = (int)ConvexLineOnlyData::gSizes[index];
|
2015-04-28 14:42:04 +00:00
|
|
|
} else {
|
|
|
|
// procedurally generated
|
|
|
|
SkScalar width = kMaxPathHeight/2;
|
|
|
|
SkScalar height = kMaxPathHeight/2;
|
Revert "Revert "Create new inset algorithm for spot shadows""
This reverts commit e7c85c45c4c0a97adc6711bb12ecacc36af4ba11.
Reason for revert: <INSERT REASONING HERE>
Original change's description:
> 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>
>
TBR=jvanverth@google.com,bsalomon@google.com,rmistry@google.com,msarett@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Change-Id: Ib3998300606d3a2e2fb3a14b2088cfad48363501
Reviewed-on: https://skia-review.googlesource.com/10113
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2017-03-24 16:07:20 +00:00
|
|
|
switch (index-SK_ARRAY_COUNT(ConvexLineOnlyData::gPoints)) {
|
2015-04-28 14:42:04 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
data.reset(new SkPoint[numPts]);
|
2015-04-28 14:42:04 +00:00
|
|
|
|
|
|
|
create_ngon(numPts, data.get(), width, height);
|
|
|
|
points = data.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
|
2019-11-22 11:03:22 +00:00
|
|
|
if (SkPath::kCW_Direction == dir) {
|
2015-04-28 14:42:04 +00:00
|
|
|
path.moveTo(points[0]);
|
|
|
|
for (int i = 1; i < numPts; ++i) {
|
|
|
|
path.lineTo(points[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
path.moveTo(points[numPts-1]);
|
|
|
|
for (int i = numPts-2; i >= 0; --i) {
|
|
|
|
path.lineTo(points[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
path.close();
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
// Each path this method returns should be convex, only composed of
|
|
|
|
// lines, wound the right direction, and short enough to fit in one
|
|
|
|
// of the GMs rows.
|
|
|
|
SkASSERT(path.isConvex());
|
|
|
|
SkASSERT(SkPath::kLine_SegmentMask == path.getSegmentMasks());
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection actualDir;
|
|
|
|
SkASSERT(SkPathPriv::CheapComputeFirstDirection(path, &actualDir));
|
|
|
|
SkASSERT(SkPathPriv::AsFirstDirection(dir) == actualDir);
|
2015-04-28 14:42:04 +00:00
|
|
|
SkRect bounds = path.getBounds();
|
|
|
|
SkASSERT(SkScalarNearlyEqual(bounds.centerX(), 0.0f));
|
|
|
|
SkASSERT(bounds.height() <= kMaxPathHeight);
|
|
|
|
#endif
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw a single path several times, shrinking it, flipping its direction
|
|
|
|
// and changing its start vertex each time.
|
2015-05-08 14:08:13 +00:00
|
|
|
void drawPath(SkCanvas* canvas, int index, SkPoint* offset) {
|
2015-04-28 14:42:04 +00:00
|
|
|
|
|
|
|
SkPoint center;
|
|
|
|
{
|
2019-11-22 11:03:22 +00:00
|
|
|
SkPath path = GetPath(index, SkPath::kCW_Direction);
|
2015-05-08 14:08:13 +00:00
|
|
|
if (offset->fX+path.getBounds().width() > kGMWidth) {
|
|
|
|
offset->fX = 0;
|
|
|
|
offset->fY += kMaxPathHeight;
|
2016-08-26 12:30:19 +00:00
|
|
|
if (fDoStrokeAndFill) {
|
|
|
|
offset->fX += kStrokeWidth / 2.0f;
|
|
|
|
offset->fY += kStrokeWidth / 2.0f;
|
|
|
|
}
|
2015-04-28 14:42:04 +00:00
|
|
|
}
|
2015-05-08 14:08:13 +00:00
|
|
|
center = { offset->fX + SkScalarHalf(path.getBounds().width()), offset->fY};
|
|
|
|
offset->fX += path.getBounds().width();
|
2016-08-26 12:30:19 +00:00
|
|
|
if (fDoStrokeAndFill) {
|
|
|
|
offset->fX += kStrokeWidth;
|
|
|
|
}
|
2015-04-28 14:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE };
|
2019-11-22 11:03:22 +00:00
|
|
|
const SkPath::Direction dirs[2] = { SkPath::kCW_Direction, SkPath::kCCW_Direction };
|
2015-04-28 14:42:04 +00:00
|
|
|
const float scales[] = { 1.0f, 0.75f, 0.5f, 0.25f, 0.1f, 0.01f, 0.001f };
|
2016-09-01 18:24:54 +00:00
|
|
|
const SkPaint::Join joins[3] = { SkPaint::kRound_Join,
|
2016-08-26 12:30:19 +00:00
|
|
|
SkPaint::kBevel_Join,
|
|
|
|
SkPaint::kMiter_Join };
|
2015-04-28 14:42:04 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(scales); ++i) {
|
Revert "Revert "Create new inset algorithm for spot shadows""
This reverts commit e7c85c45c4c0a97adc6711bb12ecacc36af4ba11.
Reason for revert: <INSERT REASONING HERE>
Original change's description:
> 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>
>
TBR=jvanverth@google.com,bsalomon@google.com,rmistry@google.com,msarett@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Change-Id: Ib3998300606d3a2e2fb3a14b2088cfad48363501
Reviewed-on: https://skia-review.googlesource.com/10113
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2017-03-24 16:07:20 +00:00
|
|
|
SkPath path = GetPath(index, dirs[i%2]);
|
2016-08-26 12:30:19 +00:00
|
|
|
if (fDoStrokeAndFill) {
|
|
|
|
paint.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
paint.setStrokeJoin(joins[i%3]);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(kStrokeWidth));
|
|
|
|
}
|
2015-04-28 14:42:04 +00:00
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(center.fX, center.fY);
|
|
|
|
canvas->scale(scales[i], scales[i]);
|
|
|
|
paint.setColor(colors[i%2]);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2015-05-08 14:08:13 +00:00
|
|
|
// the right edge of the last drawn path
|
2016-03-29 16:03:52 +00:00
|
|
|
SkPoint offset = { 0, SkScalarHalf(kMaxPathHeight) };
|
2016-08-26 12:30:19 +00:00
|
|
|
if (fDoStrokeAndFill) {
|
|
|
|
offset.fX += kStrokeWidth / 2.0f;
|
|
|
|
offset.fY += kStrokeWidth / 2.0f;
|
|
|
|
}
|
2015-05-08 14:08:13 +00:00
|
|
|
|
2015-04-28 14:42:04 +00:00
|
|
|
for (int i = 0; i < kNumPaths; ++i) {
|
2015-05-08 14:08:13 +00:00
|
|
|
this->drawPath(canvas, i, &offset);
|
2015-04-28 14:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-08-31 16:04:18 +00:00
|
|
|
// Repro for crbug.com/472723 (Missing AA on portions of graphic with GPU rasterization)
|
2015-04-28 14:42:04 +00:00
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
2016-08-26 12:30:19 +00:00
|
|
|
if (fDoStrokeAndFill) {
|
|
|
|
p.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
p.setStrokeJoin(SkPaint::kMiter_Join);
|
|
|
|
p.setStrokeWidth(SkIntToScalar(kStrokeWidth));
|
|
|
|
}
|
2015-04-28 14:42:04 +00:00
|
|
|
|
|
|
|
SkPath p1;
|
|
|
|
p1.moveTo(60.8522949f, 364.671021f);
|
|
|
|
p1.lineTo(59.4380493f, 364.671021f);
|
|
|
|
p1.lineTo(385.414276f, 690.647217f);
|
|
|
|
p1.lineTo(386.121399f, 689.940125f);
|
2018-08-31 16:04:18 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->translate(356.0f, 50.0f);
|
2015-04-28 14:42:04 +00:00
|
|
|
canvas->drawPath(p1, p);
|
2018-08-31 16:04:18 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// Repro for crbug.com/869172 (SVG path incorrectly simplified when using GPU
|
|
|
|
// Rasterization). This will only draw anything in the stroke-and-fill version.
|
|
|
|
SkPath p2;
|
|
|
|
p2.moveTo(10.f, 0.f);
|
|
|
|
p2.lineTo(38.f, 0.f);
|
|
|
|
p2.lineTo(66.f, 0.f);
|
|
|
|
p2.lineTo(94.f, 0.f);
|
|
|
|
p2.lineTo(122.f, 0.f);
|
|
|
|
p2.lineTo(150.f, 0.f);
|
|
|
|
p2.lineTo(150.f, 0.f);
|
|
|
|
p2.lineTo(122.f, 0.f);
|
|
|
|
p2.lineTo(94.f, 0.f);
|
|
|
|
p2.lineTo(66.f, 0.f);
|
|
|
|
p2.lineTo(38.f, 0.f);
|
|
|
|
p2.lineTo(10.f, 0.f);
|
|
|
|
p2.close();
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(0.0f, 500.0f);
|
|
|
|
canvas->drawPath(p2, p);
|
|
|
|
canvas->restore();
|
2018-09-05 19:08:49 +00:00
|
|
|
|
|
|
|
// Repro for crbug.com/856137. This path previously caused GrAAConvexTessellator to turn
|
|
|
|
// inset rings into outsets when adjacent bisector angles converged outside the previous
|
|
|
|
// ring due to accumulated error.
|
|
|
|
SkPath p3;
|
|
|
|
p3.setFillType(SkPath::kEvenOdd_FillType);
|
|
|
|
p3.moveTo(1184.96f, 982.557f);
|
|
|
|
p3.lineTo(1183.71f, 982.865f);
|
|
|
|
p3.lineTo(1180.99f, 982.734f);
|
|
|
|
p3.lineTo(1178.5f, 981.541f);
|
|
|
|
p3.lineTo(1176.35f, 979.367f);
|
|
|
|
p3.lineTo(1178.94f, 938.854f);
|
|
|
|
p3.lineTo(1181.35f, 936.038f);
|
|
|
|
p3.lineTo(1183.96f, 934.117f);
|
|
|
|
p3.lineTo(1186.67f, 933.195f);
|
|
|
|
p3.lineTo(1189.36f, 933.342f);
|
|
|
|
p3.lineTo(1191.58f, 934.38f);
|
|
|
|
p3.close();
|
|
|
|
canvas->save();
|
|
|
|
SkMatrix m;
|
|
|
|
m.setAll(0.0893210843f, 0, 79.1197586f, 0, 0.0893210843f, 300, 0, 0, 1);
|
|
|
|
canvas->concat(m);
|
|
|
|
canvas->drawPath(p3, p);
|
|
|
|
canvas->restore();
|
2015-04-28 14:42:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kStrokeWidth = 10;
|
|
|
|
static constexpr int kNumPaths = 20;
|
|
|
|
static constexpr int kMaxPathHeight = 100;
|
|
|
|
static constexpr int kGMWidth = 512;
|
|
|
|
static constexpr int kGMHeight = 512;
|
2015-04-28 14:42:04 +00:00
|
|
|
|
2016-08-26 12:30:19 +00:00
|
|
|
bool fDoStrokeAndFill;
|
|
|
|
|
2015-04-28 14:42:04 +00:00
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-26 12:30:19 +00:00
|
|
|
DEF_GM(return new ConvexLineOnlyPathsGM(false);)
|
|
|
|
DEF_GM(return new ConvexLineOnlyPathsGM(true);)
|
2015-04-28 14:42:04 +00:00
|
|
|
}
|