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.
|
|
|
|
|
|
|
|
#include "gm.h"
|
2018-04-16 20:23:00 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2013-08-21 19:27:48 +00:00
|
|
|
|
|
|
|
#include "GrContext.h"
|
2018-06-12 14:11:12 +00:00
|
|
|
#include "GrMemoryPool.h"
|
2017-07-14 14:12:26 +00:00
|
|
|
#include "GrOpFlushState.h"
|
2013-08-21 19:27:48 +00:00
|
|
|
#include "GrPathUtils.h"
|
2017-07-14 14:12:26 +00:00
|
|
|
#include "GrRenderTargetContextPriv.h"
|
2013-08-21 19:27:48 +00:00
|
|
|
#include "SkColorPriv.h"
|
2013-08-23 18:05:01 +00:00
|
|
|
#include "SkGeometry.h"
|
2017-10-18 15:46:18 +00:00
|
|
|
#include "SkPoint3.h"
|
2017-11-07 01:02:02 +00:00
|
|
|
#include "SkPointPriv.h"
|
2013-08-23 18:05:01 +00:00
|
|
|
#include "effects/GrBezierEffect.h"
|
2017-07-14 14:12:26 +00:00
|
|
|
#include "ops/GrMeshDrawOp.h"
|
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; }
|
|
|
|
|
2018-07-11 14:02:07 +00:00
|
|
|
RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override {
|
2017-07-14 14:12:26 +00:00
|
|
|
auto analysis = fProcessorSet.finalize(fColor, GrProcessorAnalysisCoverage::kSingleChannel,
|
2018-07-11 14:02:07 +00:00
|
|
|
clip, false, caps, &fColor);
|
2017-07-14 14:12:26 +00:00
|
|
|
return analysis.requiresDstTexture() ? RequiresDstTexture::kYes : RequiresDstTexture::kNo;
|
|
|
|
}
|
|
|
|
|
2018-10-12 18:37:19 +00:00
|
|
|
void visitProxies(const VisitProxyFunc& func, VisitorType) const override {
|
2017-09-13 17:10:52 +00:00
|
|
|
fProcessorSet.visitProxies(func);
|
|
|
|
}
|
|
|
|
|
2017-07-14 14:12:26 +00:00
|
|
|
protected:
|
2018-10-31 18:04:39 +00:00
|
|
|
BezierTestOp(sk_sp<const GrGeometryProcessor> gp, const SkRect& rect, const SkPMColor4f& color,
|
2018-08-07 14:02:38 +00:00
|
|
|
int32_t classID)
|
2017-07-14 14:12:26 +00:00
|
|
|
: INHERITED(classID)
|
|
|
|
, fRect(rect)
|
|
|
|
, fColor(color)
|
|
|
|
, fGeometryProcessor(std::move(gp))
|
|
|
|
, fProcessorSet(SkBlendMode::kSrc) {
|
|
|
|
this->setBounds(rect, HasAABloat::kYes, IsZeroArea::kNo);
|
|
|
|
}
|
|
|
|
|
2018-06-26 13:12:38 +00:00
|
|
|
Target::PipelineAndFixedDynamicState makePipeline(Target* target) {
|
2017-08-09 20:27:09 +00:00
|
|
|
return target->makePipeline(0, std::move(fProcessorSet), target->detachAppliedClip());
|
2017-07-14 14:12:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 14:02:38 +00:00
|
|
|
sk_sp<const GrGeometryProcessor> gp() const { return fGeometryProcessor; }
|
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;
|
2018-08-07 14:02:38 +00:00
|
|
|
sk_sp<const GrGeometryProcessor> fGeometryProcessor;
|
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.
|
|
|
|
*/
|
2013-08-23 18:05:01 +00:00
|
|
|
|
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"; }
|
|
|
|
|
2018-06-12 14:11:12 +00:00
|
|
|
static std::unique_ptr<GrDrawOp> Make(GrContext* context,
|
2018-08-07 14:02:38 +00:00
|
|
|
sk_sp<const GrGeometryProcessor> gp,
|
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) {
|
2018-06-19 17:09:54 +00:00
|
|
|
GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
|
|
|
|
|
|
|
|
return pool->allocate<BezierConicTestOp>(std::move(gp), 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
|
|
|
|
|
2018-10-30 19:30:35 +00:00
|
|
|
BezierConicTestOp(sk_sp<const GrGeometryProcessor> gp, const SkRect& rect,
|
2018-10-31 18:04:39 +00:00
|
|
|
const SkPMColor4f& color, const SkMatrix& klm)
|
2017-07-14 14:12:26 +00:00
|
|
|
: INHERITED(std::move(gp), rect, color, ClassID()), fKLM(klm) {}
|
|
|
|
|
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 {
|
Change how GPs configure attributes
Adds setVertexAttributes and setInstanceAttributes. These take a pointer
to the first attribute, and a count. The count is the total number of
possible attributes, though some may not be initialized. The base class
computes the number of initialized attributes, pre-computes the strides,
and only allows subsequent access to the initialized attributes.
The attributes need to be allocated contiguously. Some GPs place them in
an array, though most just place them as consecutive members, and pass
a pointer to the first one.
Indexed access would be possible, but now it makes more sense to iterate
over all attributes, so enable that, and use range-based for everywhere.
Completely remove the per-attribute offset helper (again - possible, but
not real helpful), and make the stride always available. In many ops,
just use the GP's computed stride, rather than re-computing it.
Bug: skia:
Change-Id: Ie4cccb7969a98ee5a10b373e714fbd702e875b3e
Reviewed-on: https://skia-review.googlesource.com/c/169241
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2018-11-12 20:34:00 +00:00
|
|
|
SkASSERT(this->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
|
|
|
}
|
2018-06-26 13:12:38 +00:00
|
|
|
auto pipe = this->makePipeline(target);
|
|
|
|
helper.recordDraw(target, this->gp(), pipe.fPipeline, pipe.fFixedDynamicState);
|
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.
|
|
|
|
*/
|
|
|
|
class BezierConicEffects : public GM {
|
|
|
|
public:
|
|
|
|
BezierConicEffects() {
|
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
}
|
2013-08-21 19:27:48 +00:00
|
|
|
|
2013-08-23 18:05:01 +00:00
|
|
|
protected:
|
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 {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(800, 800);
|
2013-08-23 18:05:01 +00:00
|
|
|
}
|
2013-08-21 19:27:48 +00:00
|
|
|
|
2013-08-23 18:05:01 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-10-27 18:47:55 +00:00
|
|
|
GrRenderTargetContext* renderTargetContext =
|
|
|
|
canvas->internal_private_accessTopLayerRenderTargetContext();
|
|
|
|
if (!renderTargetContext) {
|
2015-09-09 15:16:41 +00:00
|
|
|
skiagm::GM::DrawGpuOnlyMessage(canvas);
|
2013-08-23 18:05:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-28 21:32:04 +00:00
|
|
|
GrContext* context = canvas->getGrContext();
|
|
|
|
if (!context) {
|
2016-01-13 15:47:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-23 18:05:01 +00:00
|
|
|
struct Vertex {
|
|
|
|
SkPoint fPosition;
|
|
|
|
float fKLM[4]; // The last value is ignored. The effect expects a vec4f.
|
|
|
|
};
|
2013-08-21 19:27:48 +00:00
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int kNumConics = 10;
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-08-23 18:05:01 +00:00
|
|
|
|
|
|
|
// Mult by 3 for each edge effect type
|
|
|
|
int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumConics*3)));
|
|
|
|
int numRows = SkScalarCeilToInt(SkIntToScalar(kNumConics*3) / numCols);
|
2016-10-27 18:47:55 +00:00
|
|
|
SkScalar w = SkIntToScalar(renderTargetContext->width()) / numCols;
|
|
|
|
SkScalar h = SkIntToScalar(renderTargetContext->height()) / numRows;
|
2013-08-23 18:05:01 +00:00
|
|
|
int row = 0;
|
|
|
|
int col = 0;
|
2018-10-31 18:04:39 +00:00
|
|
|
SkPMColor4f color = SkPMColor4f::FromBytes_RGBA(0xff000000);
|
2013-08-23 18:05:01 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < kNumConics; ++i) {
|
|
|
|
SkPoint baseControlPts[] = {
|
|
|
|
{rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
|
|
|
|
{rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
|
|
|
|
{rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}
|
|
|
|
};
|
|
|
|
SkScalar weight = rand.nextRangeF(0.f, 2.f);
|
2017-11-10 16:58:19 +00:00
|
|
|
for(int edgeType = 0; edgeType < kGrClipEdgeTypeCnt; ++edgeType) {
|
2016-06-09 15:01:03 +00:00
|
|
|
sk_sp<GrGeometryProcessor> gp;
|
2017-11-09 19:51:17 +00:00
|
|
|
GrClipEdgeType et = (GrClipEdgeType)edgeType;
|
2018-05-11 14:14:21 +00:00
|
|
|
gp = GrConicEffect::Make(color, SkMatrix::I(), et, *context->contextPriv().caps(),
|
|
|
|
SkMatrix::I(), false);
|
2016-01-13 15:47:38 +00:00
|
|
|
if (!gp) {
|
|
|
|
continue;
|
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[] = {
|
|
|
|
{x + baseControlPts[0].fX, y + baseControlPts[0].fY},
|
|
|
|
{x + baseControlPts[1].fX, y + baseControlPts[1].fY},
|
|
|
|
{x + baseControlPts[2].fX, y + baseControlPts[2].fY}
|
|
|
|
};
|
|
|
|
SkConic dst[4];
|
2017-03-23 19:38:45 +00:00
|
|
|
SkMatrix klm;
|
2013-08-23 18:05:01 +00:00
|
|
|
int cnt = chop_conic(controlPts, dst, weight);
|
2017-03-23 19:38:45 +00:00
|
|
|
GrPathUtils::getConicKLM(controlPts, weight, &klm);
|
2013-08-23 18:05:01 +00:00
|
|
|
|
|
|
|
SkPaint ctrlPtPaint;
|
|
|
|
ctrlPtPaint.setColor(rand.nextU() | 0xFF000000);
|
|
|
|
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
|
|
|
SkPaint polyPaint;
|
|
|
|
polyPaint.setColor(0xffA0A0A0);
|
|
|
|
polyPaint.setStrokeWidth(0);
|
|
|
|
polyPaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, controlPts, polyPaint);
|
|
|
|
|
|
|
|
SkPaint choppedPtPaint;
|
|
|
|
choppedPtPaint.setColor(~ctrlPtPaint.getColor() | 0xFF000000);
|
|
|
|
|
|
|
|
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;
|
|
|
|
//SkPoint bPts[] = {{0.f, 0.f}, {800.f, 800.f}};
|
|
|
|
//bounds.set(bPts, 2);
|
|
|
|
bounds.set(pts, 3);
|
|
|
|
|
|
|
|
SkPaint boundsPaint;
|
|
|
|
boundsPaint.setColor(0xff808080);
|
|
|
|
boundsPaint.setStrokeWidth(0);
|
|
|
|
boundsPaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawRect(bounds, boundsPaint);
|
|
|
|
|
2018-06-12 14:11:12 +00:00
|
|
|
std::unique_ptr<GrDrawOp> op = BezierConicTestOp::Make(context, gp, bounds,
|
|
|
|
color, 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
|
|
|
++col;
|
|
|
|
if (numCols == col) {
|
|
|
|
col = 0;
|
|
|
|
++row;
|
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.
|
|
|
|
int split_conic(const SkPoint src[3], SkConic dst[2], const SkScalar weight) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-23 18:05:01 +00:00
|
|
|
// Calls split_conic on the entire conic and then once more on each subsection.
|
|
|
|
// 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).
|
|
|
|
int chop_conic(const SkPoint src[3], SkConic dst[4], const SkScalar weight) {
|
|
|
|
SkConic dstTemp[2];
|
|
|
|
int conicCnt = split_conic(src, dstTemp, weight);
|
|
|
|
if (2 == conicCnt) {
|
|
|
|
int conicCnt2 = split_conic(dstTemp[0].fPts, dst, dstTemp[0].fW);
|
|
|
|
conicCnt = conicCnt2 + split_conic(dstTemp[1].fPts, &dst[conicCnt2], dstTemp[1].fW);
|
|
|
|
} 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,
|
2018-08-07 14:02:38 +00:00
|
|
|
sk_sp<const GrGeometryProcessor> gp,
|
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) {
|
2018-06-19 17:09:54 +00:00
|
|
|
GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
|
|
|
|
|
|
|
|
return pool->allocate<BezierQuadTestOp>(std::move(gp), 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
|
|
|
|
|
2018-10-30 19:30:35 +00:00
|
|
|
BezierQuadTestOp(sk_sp<const GrGeometryProcessor> gp, const SkRect& rect,
|
2018-10-31 18:04:39 +00:00
|
|
|
const SkPMColor4f& color, const GrPathUtils::QuadUVMatrix& devToUV)
|
2017-07-14 14:12:26 +00:00
|
|
|
: INHERITED(std::move(gp), 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 {
|
Change how GPs configure attributes
Adds setVertexAttributes and setInstanceAttributes. These take a pointer
to the first attribute, and a count. The count is the total number of
possible attributes, though some may not be initialized. The base class
computes the number of initialized attributes, pre-computes the strides,
and only allows subsequent access to the initialized attributes.
The attributes need to be allocated contiguously. Some GPs place them in
an array, though most just place them as consecutive members, and pass
a pointer to the first one.
Indexed access would be possible, but now it makes more sense to iterate
over all attributes, so enable that, and use range-based for everywhere.
Completely remove the per-attribute offset helper (again - possible, but
not real helpful), and make the stride always available. In many ops,
just use the GP's computed stride, rather than re-computing it.
Bug: skia:
Change-Id: Ie4cccb7969a98ee5a10b373e714fbd702e875b3e
Reviewed-on: https://skia-review.googlesource.com/c/169241
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2018-11-12 20:34:00 +00:00
|
|
|
SkASSERT(this->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));
|
2018-06-26 13:12:38 +00:00
|
|
|
auto pipe = this->makePipeline(target);
|
|
|
|
helper.recordDraw(target, this->gp(), pipe.fPipeline, pipe.fFixedDynamicState);
|
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.
|
|
|
|
*/
|
|
|
|
class BezierQuadEffects : public GM {
|
|
|
|
public:
|
|
|
|
BezierQuadEffects() {
|
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
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 {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(800, 800);
|
2013-08-23 18:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-10-27 18:47:55 +00:00
|
|
|
GrRenderTargetContext* renderTargetContext =
|
|
|
|
canvas->internal_private_accessTopLayerRenderTargetContext();
|
|
|
|
if (!renderTargetContext) {
|
2015-09-09 15:16:41 +00:00
|
|
|
skiagm::GM::DrawGpuOnlyMessage(canvas);
|
2013-08-23 18:05:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-28 21:32:04 +00:00
|
|
|
GrContext* context = canvas->getGrContext();
|
|
|
|
if (!context) {
|
2016-01-13 15:47:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-23 18:05:01 +00:00
|
|
|
struct Vertex {
|
|
|
|
SkPoint fPosition;
|
|
|
|
float fUV[4]; // The last two values are ignored. The effect expects a vec4f.
|
|
|
|
};
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int kNumQuads = 5;
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-08-23 18:05:01 +00:00
|
|
|
|
|
|
|
int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumQuads*3)));
|
|
|
|
int numRows = SkScalarCeilToInt(SkIntToScalar(kNumQuads*3) / numCols);
|
2016-10-27 18:47:55 +00:00
|
|
|
SkScalar w = SkIntToScalar(renderTargetContext->width()) / numCols;
|
|
|
|
SkScalar h = SkIntToScalar(renderTargetContext->height()) / numRows;
|
2013-08-23 18:05:01 +00:00
|
|
|
int row = 0;
|
|
|
|
int col = 0;
|
2018-10-31 18:04:39 +00:00
|
|
|
SkPMColor4f color = SkPMColor4f::FromBytes_RGBA(0xff000000);
|
2013-08-23 18:05:01 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < kNumQuads; ++i) {
|
|
|
|
SkPoint baseControlPts[] = {
|
|
|
|
{rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
|
|
|
|
{rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)},
|
|
|
|
{rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}
|
|
|
|
};
|
2017-11-10 16:58:19 +00:00
|
|
|
for(int edgeType = 0; edgeType < kGrClipEdgeTypeCnt; ++edgeType) {
|
2016-06-09 15:01:03 +00:00
|
|
|
sk_sp<GrGeometryProcessor> gp;
|
2017-11-09 19:51:17 +00:00
|
|
|
GrClipEdgeType et = (GrClipEdgeType)edgeType;
|
2018-05-11 14:14:21 +00:00
|
|
|
gp = GrQuadEffect::Make(color, SkMatrix::I(), et, *context->contextPriv().caps(),
|
|
|
|
SkMatrix::I(), false);
|
2016-01-13 15:47:38 +00:00
|
|
|
if (!gp) {
|
|
|
|
continue;
|
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[] = {
|
|
|
|
{x + baseControlPts[0].fX, y + baseControlPts[0].fY},
|
|
|
|
{x + baseControlPts[1].fX, y + baseControlPts[1].fY},
|
|
|
|
{x + baseControlPts[2].fX, y + baseControlPts[2].fY}
|
|
|
|
};
|
|
|
|
SkPoint chopped[5];
|
|
|
|
int cnt = SkChopQuadAtMaxCurvature(controlPts, chopped);
|
|
|
|
|
|
|
|
SkPaint ctrlPtPaint;
|
|
|
|
ctrlPtPaint.setColor(rand.nextU() | 0xFF000000);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint polyPaint;
|
|
|
|
polyPaint.setColor(0xffA0A0A0);
|
|
|
|
polyPaint.setStrokeWidth(0);
|
|
|
|
polyPaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, controlPts, polyPaint);
|
|
|
|
|
|
|
|
SkPaint choppedPtPaint;
|
|
|
|
choppedPtPaint.setColor(~ctrlPtPaint.getColor() | 0xFF000000);
|
|
|
|
|
|
|
|
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;
|
|
|
|
bounds.set(pts, 3);
|
|
|
|
|
|
|
|
SkPaint boundsPaint;
|
|
|
|
boundsPaint.setColor(0xff808080);
|
|
|
|
boundsPaint.setStrokeWidth(0);
|
|
|
|
boundsPaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawRect(bounds, boundsPaint);
|
|
|
|
|
2016-06-23 21:07:00 +00:00
|
|
|
GrPaint grPaint;
|
2017-01-09 16:46:10 +00:00
|
|
|
grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
|
2015-02-11 19:34:58 +00:00
|
|
|
|
2015-02-11 21:03:15 +00:00
|
|
|
GrPathUtils::QuadUVMatrix DevToUV(pts);
|
|
|
|
|
2018-06-12 14:11:12 +00:00
|
|
|
std::unique_ptr<GrDrawOp> op = BezierQuadTestOp::Make(context, gp,
|
|
|
|
bounds, color, DevToUV);
|
2017-07-14 14:12:26 +00:00
|
|
|
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
2013-08-23 18:05:01 +00:00
|
|
|
}
|
|
|
|
++col;
|
|
|
|
if (numCols == col) {
|
|
|
|
col = 0;
|
|
|
|
++row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|