2013-08-21 19:27:48 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This test only works with the GPU backend.
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkBlendMode.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPoint3.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.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 "include/gpu/GrContext.h"
|
|
|
|
#include "include/private/GrRecordingContext.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/private/GrSharedEnums.h"
|
|
|
|
#include "include/private/GrTypesPriv.h"
|
|
|
|
#include "include/private/SkColorData.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkGeometry.h"
|
|
|
|
#include "src/core/SkPointPriv.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "src/gpu/GrCaps.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrContextPriv.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "src/gpu/GrGeometryProcessor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrMemoryPool.h"
|
|
|
|
#include "src/gpu/GrOpFlushState.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "src/gpu/GrPaint.h"
|
|
|
|
#include "src/gpu/GrProcessorAnalysis.h"
|
|
|
|
#include "src/gpu/GrProcessorSet.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "src/gpu/GrRenderTargetContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "src/gpu/GrUserStencilSettings.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/effects/GrBezierEffect.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "src/gpu/effects/GrPorterDuffXferProcessor.h"
|
2019-06-03 20:46:19 +00:00
|
|
|
#include "src/gpu/geometry/GrPathUtils.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "src/gpu/ops/GrDrawOp.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/ops/GrMeshDrawOp.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "src/gpu/ops/GrOp.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
class GrAppliedClip;
|
2013-08-21 19:27:48 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
2015-02-11 21:45:50 +00:00
|
|
|
|
2017-07-14 14:12:26 +00:00
|
|
|
class BezierTestOp : public GrMeshDrawOp {
|
|
|
|
public:
|
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
|
|
|
|
2019-06-24 00:07:38 +00:00
|
|
|
GrProcessorSet::Analysis finalize(
|
|
|
|
const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
|
|
|
|
GrClampType clampType) override {
|
2019-03-05 17:11:58 +00:00
|
|
|
return fProcessorSet.finalize(
|
|
|
|
fColor, GrProcessorAnalysisCoverage::kSingleChannel, clip,
|
2019-06-24 00:07:38 +00:00
|
|
|
&GrUserStencilSettings::kUnused, hasMixedSampledCoverage, caps, clampType, &fColor);
|
2017-07-14 14:12:26 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 01:35:29 +00:00
|
|
|
void visitProxies(const VisitProxyFunc& func) const override {
|
2017-09-13 17:10:52 +00:00
|
|
|
fProcessorSet.visitProxies(func);
|
|
|
|
}
|
|
|
|
|
2017-07-14 14:12:26 +00:00
|
|
|
protected:
|
2019-11-20 21:08:10 +00:00
|
|
|
BezierTestOp(GrClipEdgeType et, const SkRect& rect, const SkPMColor4f& color, int32_t classID)
|
2017-07-14 14:12:26 +00:00
|
|
|
: INHERITED(classID)
|
|
|
|
, fRect(rect)
|
|
|
|
, fColor(color)
|
2019-11-20 21:08:10 +00:00
|
|
|
, fEdgeType(et)
|
2017-07-14 14:12:26 +00:00
|
|
|
, fProcessorSet(SkBlendMode::kSrc) {
|
2019-10-01 19:14:44 +00:00
|
|
|
this->setBounds(rect, HasAABloat::kYes, IsHairline::kNo);
|
2017-07-14 14:12:26 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:13:22 +00:00
|
|
|
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
|
|
|
|
flushState->executeDrawsAndUploadsForMeshDrawOp(
|
|
|
|
this, chainBounds, std::move(fProcessorSet));
|
2017-07-14 14:12:26 +00:00
|
|
|
}
|
|
|
|
|
2019-11-20 21:08:10 +00:00
|
|
|
GrClipEdgeType edgeType() const { return fEdgeType; }
|
2017-07-14 14:12:26 +00:00
|
|
|
|
|
|
|
const SkRect& rect() const { return fRect; }
|
2018-10-31 18:04:39 +00:00
|
|
|
const SkPMColor4f& color() const { return fColor; }
|
2017-07-14 14:12:26 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SkRect fRect;
|
2018-10-31 18:04:39 +00:00
|
|
|
SkPMColor4f fColor;
|
2019-11-20 21:08:10 +00:00
|
|
|
GrClipEdgeType fEdgeType;
|
2017-07-14 14:12:26 +00:00
|
|
|
GrProcessorSet fProcessorSet;
|
|
|
|
|
|
|
|
typedef GrMeshDrawOp INHERITED;
|
|
|
|
};
|
|
|
|
|
2013-08-21 19:27:48 +00:00
|
|
|
/**
|
|
|
|
* This GM directly exercises effects that draw Bezier curves in the GPU backend.
|
|
|
|
*/
|
2017-07-14 14:12:26 +00:00
|
|
|
class BezierConicTestOp : public BezierTestOp {
|
2017-06-08 19:12:02 +00:00
|
|
|
public:
|
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
|
|
|
const char* name() const override { return "BezierConicTestOp"; }
|
|
|
|
|
2019-02-15 16:33:22 +00:00
|
|
|
static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
|
2019-11-20 21:08:10 +00:00
|
|
|
GrClipEdgeType et,
|
2018-06-12 14:11:12 +00:00
|
|
|
const SkRect& rect,
|
2018-10-31 18:04:39 +00:00
|
|
|
const SkPMColor4f& color,
|
2018-06-12 14:11:12 +00:00
|
|
|
const SkMatrix& klm) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrOpMemoryPool* pool = context->priv().opMemoryPool();
|
2018-06-19 17:09:54 +00:00
|
|
|
|
2019-11-20 21:08:10 +00:00
|
|
|
return pool->allocate<BezierConicTestOp>(et, rect, color, klm);
|
2017-06-08 19:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-06-12 14:11:12 +00:00
|
|
|
friend class ::GrOpMemoryPool; // for ctor
|
|
|
|
|
2019-11-20 21:08:10 +00:00
|
|
|
BezierConicTestOp(GrClipEdgeType et, const SkRect& rect,
|
2018-10-31 18:04:39 +00:00
|
|
|
const SkPMColor4f& color, const SkMatrix& klm)
|
2019-11-20 21:08:10 +00:00
|
|
|
: INHERITED(et, rect, color, ClassID()), fKLM(klm) {}
|
2017-07-14 14:12:26 +00:00
|
|
|
|
2017-06-08 19:12:02 +00:00
|
|
|
struct Vertex {
|
|
|
|
SkPoint fPosition;
|
|
|
|
float fKLM[4]; // The last value is ignored. The effect expects a vec4f.
|
|
|
|
};
|
|
|
|
|
2017-08-09 20:02:19 +00:00
|
|
|
void onPrepareDraws(Target* target) override {
|
2019-11-20 21:08:10 +00:00
|
|
|
GrGeometryProcessor* gp = GrConicEffect::Make(target->allocator(), this->color(),
|
|
|
|
SkMatrix::I(), this->edgeType(),
|
|
|
|
target->caps(), SkMatrix::I(), false);
|
|
|
|
if (!gp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkASSERT(gp->vertexStride() == sizeof(Vertex));
|
2018-08-07 14:02:38 +00:00
|
|
|
QuadHelper helper(target, sizeof(Vertex), 1);
|
|
|
|
Vertex* verts = reinterpret_cast<Vertex*>(helper.vertices());
|
2017-06-08 19:12:02 +00:00
|
|
|
if (!verts) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-14 14:12:26 +00:00
|
|
|
SkRect rect = this->rect();
|
2017-11-07 01:02:02 +00:00
|
|
|
SkPointPriv::SetRectTriStrip(&verts[0].fPosition, rect.fLeft, rect.fTop, rect.fRight,
|
|
|
|
rect.fBottom, sizeof(Vertex));
|
2017-06-08 19:12:02 +00:00
|
|
|
for (int v = 0; v < 4; ++v) {
|
2017-10-18 15:46:18 +00:00
|
|
|
SkPoint3 pt3 = {verts[v].fPosition.x(), verts[v].fPosition.y(), 1.f};
|
|
|
|
fKLM.mapHomogeneousPoints((SkPoint3* ) verts[v].fKLM, &pt3, 1);
|
2017-06-08 19:12:02 +00:00
|
|
|
}
|
2019-02-26 18:13:22 +00:00
|
|
|
|
2019-11-20 21:08:10 +00:00
|
|
|
helper.recordDraw(target, gp);
|
2017-06-08 19:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkMatrix fKLM;
|
|
|
|
|
|
|
|
static constexpr int kVertsPerCubic = 4;
|
|
|
|
static constexpr int kIndicesPerCubic = 6;
|
|
|
|
|
2017-07-14 14:12:26 +00:00
|
|
|
typedef BezierTestOp INHERITED;
|
2017-06-08 19:12:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-23 18:05:01 +00:00
|
|
|
/**
|
|
|
|
* This GM directly exercises effects that draw Bezier curves in the GPU backend.
|
|
|
|
*/
|
2019-02-07 22:23:36 +00:00
|
|
|
class BezierConicEffects : public GpuGM {
|
2013-08-23 18:05:01 +00:00
|
|
|
public:
|
|
|
|
BezierConicEffects() {
|
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
}
|
2013-08-21 19:27:48 +00:00
|
|
|
|
2013-08-23 18:05:01 +00:00
|
|
|
protected:
|
2019-11-21 18:16:21 +00:00
|
|
|
static const int kNumConics = 10;
|
|
|
|
static const int kCellWidth = 128;
|
|
|
|
static const int kCellHeight = 128;
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-08-23 18:05:01 +00:00
|
|
|
return SkString("bezier_conic_effects");
|
|
|
|
}
|
2013-08-21 19:27:48 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2019-11-21 18:16:21 +00:00
|
|
|
return SkISize::Make(kGrClipEdgeTypeCnt*kCellWidth, kNumConics*kCellHeight);
|
2013-08-23 18:05:01 +00:00
|
|
|
}
|
2013-08-21 19:27:48 +00:00
|
|
|
|
2019-02-07 22:23:36 +00:00
|
|
|
void onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
|
|
|
|
SkCanvas* canvas) override {
|
2019-11-21 18:16:21 +00:00
|
|
|
|
|
|
|
const SkScalar w = kCellWidth, h = kCellHeight;
|
|
|
|
const SkPMColor4f kOpaqueBlack = SkPMColor4f::FromBytes_RGBA(0xff000000);
|
|
|
|
|
|
|
|
const SkPoint baseControlPts[kNumConics][3] = {
|
|
|
|
{ { 0.31f * w, 0.01f * h}, { 0.48f * w, 0.74f * h }, { 0.19f * w, 0.33f * h } },
|
|
|
|
{ { 0.00f * w, 0.07f * h}, { 0.30f * w, 0.70f * h }, { 0.47f * w, 0.37f * h } },
|
|
|
|
{ { 0.15f * w, 0.23f * h}, { 0.49f * w, 0.87f * h }, { 0.85f * w, 0.66f * h } },
|
|
|
|
{ { 0.09f * w, 0.15f * h}, { 0.42f * w, 0.33f * h }, { 0.17f * w, 0.38f * h } },
|
|
|
|
{ { 0.98f * w, 0.54f * h}, { 0.83f * w, 0.91f * h }, { 0.62f * w, 0.40f * h } },
|
|
|
|
{ { 0.96f * w, 0.65f * h}, { 0.03f * w, 0.79f * h }, { 0.24f * w, 0.56f * h } },
|
|
|
|
{ { 0.57f * w, 0.12f * h}, { 0.33f * w, 0.67f * h }, { 0.59f * w, 0.33f * h } },
|
|
|
|
{ { 0.12f * w, 0.72f * h}, { 0.69f * w, 0.85f * h }, { 0.46f * w, 0.32f * h } },
|
|
|
|
{ { 0.27f * w, 0.49f * h}, { 0.41f * w, 0.02f * h }, { 0.11f * w, 0.42f * h } },
|
|
|
|
{ { 0.40f * w, 0.13f * h}, { 0.83f * w, 0.30f * h }, { 0.31f * w, 0.68f * h } },
|
2013-08-23 18:05:01 +00:00
|
|
|
};
|
2019-11-21 18:16:21 +00:00
|
|
|
const SkScalar weights[kNumConics] = { 0.62f, 0.01f, 0.95f, 1.48f, 0.37f,
|
|
|
|
0.66f, 0.15f, 0.14f, 0.61f, 1.4f };
|
|
|
|
|
|
|
|
SkPaint ctrlPtPaint;
|
|
|
|
ctrlPtPaint.setColor(SK_ColorRED);
|
|
|
|
|
|
|
|
SkPaint choppedPtPaint;
|
|
|
|
choppedPtPaint.setColor(~ctrlPtPaint.getColor() | 0xFF000000);
|
|
|
|
|
|
|
|
SkPaint polyPaint;
|
|
|
|
polyPaint.setColor(0xffA0A0A0);
|
|
|
|
polyPaint.setStrokeWidth(0);
|
|
|
|
polyPaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
SkPaint boundsPaint;
|
|
|
|
boundsPaint.setColor(0xff808080);
|
|
|
|
boundsPaint.setStrokeWidth(0);
|
|
|
|
boundsPaint.setStyle(SkPaint::kStroke_Style);
|
2013-08-21 19:27:48 +00:00
|
|
|
|
2019-11-21 18:16:21 +00:00
|
|
|
|
|
|
|
for (int row = 0; row < kNumConics; ++row) {
|
|
|
|
for(int col = 0; col < kGrClipEdgeTypeCnt; ++col) {
|
|
|
|
GrClipEdgeType et = (GrClipEdgeType) col;
|
2014-03-05 18:27:43 +00:00
|
|
|
|
2017-02-14 15:59:19 +00:00
|
|
|
SkScalar x = col * w;
|
|
|
|
SkScalar y = row * h;
|
2013-08-23 18:05:01 +00:00
|
|
|
SkPoint controlPts[] = {
|
2019-11-21 18:16:21 +00:00
|
|
|
{x + baseControlPts[row][0].fX, y + baseControlPts[row][0].fY},
|
|
|
|
{x + baseControlPts[row][1].fX, y + baseControlPts[row][1].fY},
|
|
|
|
{x + baseControlPts[row][2].fX, y + baseControlPts[row][2].fY}
|
2013-08-23 18:05:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
2017-05-15 17:35:35 +00:00
|
|
|
canvas->drawCircle(controlPts[i], 6.f, ctrlPtPaint);
|
2013-08-21 19:27:48 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 18:05:01 +00:00
|
|
|
canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, controlPts, polyPaint);
|
|
|
|
|
2019-11-21 18:16:21 +00:00
|
|
|
SkConic dst[4];
|
|
|
|
SkMatrix klm;
|
|
|
|
int cnt = ChopConic(controlPts, dst, weights[row]);
|
|
|
|
GrPathUtils::getConicKLM(controlPts, weights[row], &klm);
|
2013-08-23 18:05:01 +00:00
|
|
|
|
|
|
|
for (int c = 0; c < cnt; ++c) {
|
|
|
|
SkPoint* pts = dst[c].fPts;
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
2017-05-15 17:35:35 +00:00
|
|
|
canvas->drawCircle(pts[i], 3.f, choppedPtPaint);
|
2013-08-23 18:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkRect bounds;
|
2019-08-24 23:39:13 +00:00
|
|
|
bounds.setBounds(pts, 3);
|
2013-08-23 18:05:01 +00:00
|
|
|
|
|
|
|
canvas->drawRect(bounds, boundsPaint);
|
|
|
|
|
2019-11-20 21:08:10 +00:00
|
|
|
std::unique_ptr<GrDrawOp> op = BezierConicTestOp::Make(context, et, bounds,
|
2019-11-21 18:16:21 +00:00
|
|
|
kOpaqueBlack, klm);
|
2017-07-14 14:12:26 +00:00
|
|
|
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
2013-08-21 19:27:48 +00:00
|
|
|
}
|
2013-08-23 18:05:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-21 19:27:48 +00:00
|
|
|
|
2013-08-23 18:05:01 +00:00
|
|
|
private:
|
|
|
|
// Uses the max curvature function for quads to estimate
|
|
|
|
// where to chop the conic. If the max curvature is not
|
|
|
|
// found along the curve segment it will return 1 and
|
|
|
|
// dst[0] is the original conic. If it returns 2 the dst[0]
|
|
|
|
// and dst[1] are the two new conics.
|
2019-11-21 18:16:21 +00:00
|
|
|
static int SplitConic(const SkPoint src[3], SkConic dst[2], const SkScalar weight) {
|
2013-08-23 18:05:01 +00:00
|
|
|
SkScalar t = SkFindQuadMaxCurvature(src);
|
2018-07-24 07:08:31 +00:00
|
|
|
if (t == 0 || t == 1) {
|
2013-08-23 18:05:01 +00:00
|
|
|
if (dst) {
|
|
|
|
dst[0].set(src, weight);
|
2013-08-21 19:27:48 +00:00
|
|
|
}
|
2013-08-23 18:05:01 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
if (dst) {
|
|
|
|
SkConic conic;
|
|
|
|
conic.set(src, weight);
|
2016-09-26 18:03:54 +00:00
|
|
|
if (!conic.chopAt(t, dst)) {
|
|
|
|
dst[0].set(src, weight);
|
|
|
|
return 1;
|
|
|
|
}
|
2013-08-21 19:27:48 +00:00
|
|
|
}
|
2013-08-23 18:05:01 +00:00
|
|
|
return 2;
|
2013-08-21 19:27:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-21 18:16:21 +00:00
|
|
|
// Calls SplitConic on the entire conic and then once more on each subsection.
|
2013-08-23 18:05:01 +00:00
|
|
|
// Most cases will result in either 1 conic (chop point is not within t range)
|
|
|
|
// or 3 points (split once and then one subsection is split again).
|
2019-11-21 18:16:21 +00:00
|
|
|
static int ChopConic(const SkPoint src[3], SkConic dst[4], const SkScalar weight) {
|
2013-08-23 18:05:01 +00:00
|
|
|
SkConic dstTemp[2];
|
2019-11-21 18:16:21 +00:00
|
|
|
int conicCnt = SplitConic(src, dstTemp, weight);
|
2013-08-23 18:05:01 +00:00
|
|
|
if (2 == conicCnt) {
|
2019-11-21 18:16:21 +00:00
|
|
|
int conicCnt2 = SplitConic(dstTemp[0].fPts, dst, dstTemp[0].fW);
|
|
|
|
conicCnt = conicCnt2 + SplitConic(dstTemp[1].fPts, &dst[conicCnt2], dstTemp[1].fW);
|
2013-08-23 18:05:01 +00:00
|
|
|
} else {
|
|
|
|
dst[0] = dstTemp[0];
|
|
|
|
}
|
|
|
|
return conicCnt;
|
|
|
|
}
|
|
|
|
|
2013-08-21 19:27:48 +00:00
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2015-02-11 21:45:50 +00:00
|
|
|
|
2017-07-14 14:12:26 +00:00
|
|
|
class BezierQuadTestOp : public BezierTestOp {
|
2015-02-11 21:45:50 +00:00
|
|
|
public:
|
2016-12-01 14:36:50 +00:00
|
|
|
DEFINE_OP_CLASS_ID
|
2016-12-16 14:35:49 +00:00
|
|
|
const char* name() const override { return "BezierQuadTestOp"; }
|
2015-02-11 21:45:50 +00:00
|
|
|
|
2018-06-12 14:11:12 +00:00
|
|
|
static std::unique_ptr<GrDrawOp> Make(GrContext* context,
|
2019-11-20 21:08:10 +00:00
|
|
|
GrClipEdgeType et,
|
2018-06-12 14:11:12 +00:00
|
|
|
const SkRect& rect,
|
2018-10-31 18:04:39 +00:00
|
|
|
const SkPMColor4f& color,
|
2018-06-12 14:11:12 +00:00
|
|
|
const GrPathUtils::QuadUVMatrix& devToUV) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrOpMemoryPool* pool = context->priv().opMemoryPool();
|
2018-06-19 17:09:54 +00:00
|
|
|
|
2019-11-20 21:08:10 +00:00
|
|
|
return pool->allocate<BezierQuadTestOp>(et, rect, color, devToUV);
|
2015-02-11 21:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-06-12 14:11:12 +00:00
|
|
|
friend class ::GrOpMemoryPool; // for ctor
|
|
|
|
|
2019-11-20 21:08:10 +00:00
|
|
|
BezierQuadTestOp(GrClipEdgeType et, const SkRect& rect,
|
2018-10-31 18:04:39 +00:00
|
|
|
const SkPMColor4f& color, const GrPathUtils::QuadUVMatrix& devToUV)
|
2019-11-20 21:08:10 +00:00
|
|
|
: INHERITED(et, rect, color, ClassID()), fDevToUV(devToUV) {}
|
2015-02-11 21:45:50 +00:00
|
|
|
|
|
|
|
struct Vertex {
|
|
|
|
SkPoint fPosition;
|
|
|
|
float fKLM[4]; // The last value is ignored. The effect expects a vec4f.
|
|
|
|
};
|
|
|
|
|
2017-08-09 20:02:19 +00:00
|
|
|
void onPrepareDraws(Target* target) override {
|
2019-11-20 21:08:10 +00:00
|
|
|
GrGeometryProcessor* gp = GrQuadEffect::Make(target->allocator(), this->color(),
|
|
|
|
SkMatrix::I(), this->edgeType(),
|
|
|
|
target->caps(), SkMatrix::I(), false);
|
|
|
|
if (!gp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkASSERT(gp->vertexStride() == sizeof(Vertex));
|
2018-08-07 14:02:38 +00:00
|
|
|
QuadHelper helper(target, sizeof(Vertex), 1);
|
|
|
|
Vertex* verts = reinterpret_cast<Vertex*>(helper.vertices());
|
2015-05-05 14:49:49 +00:00
|
|
|
if (!verts) {
|
2015-03-05 22:33:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-07-14 14:12:26 +00:00
|
|
|
SkRect rect = this->rect();
|
2018-05-18 16:52:22 +00:00
|
|
|
SkPointPriv::SetRectTriStrip(&verts[0].fPosition, rect, sizeof(Vertex));
|
2018-12-26 21:48:25 +00:00
|
|
|
fDevToUV.apply(verts, 4, sizeof(Vertex), sizeof(SkPoint));
|
2019-11-20 21:08:10 +00:00
|
|
|
helper.recordDraw(target, gp);
|
2015-02-11 21:45:50 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 17:02:34 +00:00
|
|
|
GrPathUtils::QuadUVMatrix fDevToUV;
|
2015-02-11 21:45:50 +00:00
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kVertsPerCubic = 4;
|
|
|
|
static constexpr int kIndicesPerCubic = 6;
|
2015-02-11 21:45:50 +00:00
|
|
|
|
2017-07-14 14:12:26 +00:00
|
|
|
typedef BezierTestOp INHERITED;
|
2015-02-11 21:45:50 +00:00
|
|
|
};
|
|
|
|
|
2013-08-23 18:05:01 +00:00
|
|
|
/**
|
|
|
|
* This GM directly exercises effects that draw Bezier quad curves in the GPU backend.
|
|
|
|
*/
|
2019-02-07 22:23:36 +00:00
|
|
|
class BezierQuadEffects : public GpuGM {
|
2013-08-23 18:05:01 +00:00
|
|
|
public:
|
|
|
|
BezierQuadEffects() {
|
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2019-11-21 18:16:21 +00:00
|
|
|
static const int kNumQuads = 5;
|
|
|
|
static const int kCellWidth = 128;
|
|
|
|
static const int kCellHeight = 128;
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-08-23 18:05:01 +00:00
|
|
|
return SkString("bezier_quad_effects");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2019-11-21 18:16:21 +00:00
|
|
|
return SkISize::Make(kGrClipEdgeTypeCnt*kCellWidth, kNumQuads*kCellHeight);
|
2013-08-23 18:05:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 22:23:36 +00:00
|
|
|
void onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
|
|
|
|
SkCanvas* canvas) override {
|
2019-11-21 18:16:21 +00:00
|
|
|
|
|
|
|
const SkScalar w = kCellWidth, h = kCellHeight;
|
|
|
|
const SkPMColor4f kOpaqueBlack = SkPMColor4f::FromBytes_RGBA(0xff000000);
|
|
|
|
|
|
|
|
const SkPoint baseControlPts[kNumQuads][3] = {
|
|
|
|
{ { 0.31f * w, 0.01f * h}, { 0.48f * w, 0.74f * h }, { 0.19f * w, 0.33f * h } },
|
|
|
|
{ { 0.00f * w, 0.07f * h}, { 0.30f * w, 0.70f * h }, { 0.47f * w, 0.37f * h } },
|
|
|
|
{ { 0.15f * w, 0.23f * h}, { 0.49f * w, 0.87f * h }, { 0.85f * w, 0.66f * h } },
|
|
|
|
{ { 0.09f * w, 0.15f * h}, { 0.42f * w, 0.33f * h }, { 0.17f * w, 0.38f * h } },
|
|
|
|
{ { 0.98f * w, 0.54f * h}, { 0.83f * w, 0.91f * h }, { 0.62f * w, 0.40f * h } },
|
2013-08-23 18:05:01 +00:00
|
|
|
};
|
|
|
|
|
2019-11-21 18:16:21 +00:00
|
|
|
SkPaint ctrlPtPaint;
|
|
|
|
ctrlPtPaint.setColor(SK_ColorRED);
|
|
|
|
|
|
|
|
SkPaint choppedPtPaint;
|
|
|
|
choppedPtPaint.setColor(~ctrlPtPaint.getColor() | 0xFF000000);
|
|
|
|
|
|
|
|
SkPaint polyPaint;
|
|
|
|
polyPaint.setColor(0xffA0A0A0);
|
|
|
|
polyPaint.setStrokeWidth(0);
|
|
|
|
polyPaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
SkPaint boundsPaint;
|
|
|
|
boundsPaint.setColor(0xff808080);
|
|
|
|
boundsPaint.setStrokeWidth(0);
|
|
|
|
boundsPaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
for (int row = 0; row < kNumQuads; ++row) {
|
|
|
|
for(int col = 0; col < kGrClipEdgeTypeCnt; ++col) {
|
|
|
|
GrClipEdgeType et = (GrClipEdgeType) col;
|
2014-03-05 18:27:43 +00:00
|
|
|
|
2017-02-14 15:59:19 +00:00
|
|
|
SkScalar x = col * w;
|
|
|
|
SkScalar y = row * h;
|
2013-08-23 18:05:01 +00:00
|
|
|
SkPoint controlPts[] = {
|
2019-11-21 18:16:21 +00:00
|
|
|
{x + baseControlPts[row][0].fX, y + baseControlPts[row][0].fY},
|
|
|
|
{x + baseControlPts[row][1].fX, y + baseControlPts[row][1].fY},
|
|
|
|
{x + baseControlPts[row][2].fX, y + baseControlPts[row][2].fY}
|
2013-08-23 18:05:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
2017-05-15 17:35:35 +00:00
|
|
|
canvas->drawCircle(controlPts[i], 6.f, ctrlPtPaint);
|
2013-08-23 18:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, controlPts, polyPaint);
|
|
|
|
|
2019-11-21 18:16:21 +00:00
|
|
|
SkPoint chopped[5];
|
|
|
|
int cnt = SkChopQuadAtMaxCurvature(controlPts, chopped);
|
2013-08-23 18:05:01 +00:00
|
|
|
|
|
|
|
for (int c = 0; c < cnt; ++c) {
|
|
|
|
SkPoint* pts = chopped + 2 * c;
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
2017-05-15 17:35:35 +00:00
|
|
|
canvas->drawCircle(pts[i], 3.f, choppedPtPaint);
|
2013-08-23 18:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkRect bounds;
|
2019-08-24 23:39:13 +00:00
|
|
|
bounds.setBounds(pts, 3);
|
2013-08-23 18:05:01 +00:00
|
|
|
|
|
|
|
canvas->drawRect(bounds, boundsPaint);
|
|
|
|
|
2015-02-11 21:03:15 +00:00
|
|
|
GrPathUtils::QuadUVMatrix DevToUV(pts);
|
|
|
|
|
2019-11-21 18:16:21 +00:00
|
|
|
std::unique_ptr<GrDrawOp> op = BezierQuadTestOp::Make(context, et, bounds,
|
|
|
|
kOpaqueBlack, DevToUV);
|
2017-07-14 14:12:26 +00:00
|
|
|
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
2013-08-23 18:05:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
2013-08-21 19:27:48 +00:00
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new BezierConicEffects;)
|
|
|
|
DEF_GM(return new BezierQuadEffects;)
|
2013-08-21 19:27:48 +00:00
|
|
|
}
|