aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/beziereffects.cpp
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-07-14 10:12:26 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-14 15:03:24 +0000
commit477d0efcf2d90c70a87c5a126349e76ac57d9649 (patch)
treefada7945b261b0a68ebad386c7fb6908439587dc /gm/beziereffects.cpp
parent148cf8813a2ac62242d23b5098a7707a7c37f9dc (diff)
Make ops in bezier_effects GMs be non-Legacy GrMeshDrawOps
Change-Id: I1d56536820a61af293a7bce290f35b724c3a8257 Reviewed-on: https://skia-review.googlesource.com/23480 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'gm/beziereffects.cpp')
-rw-r--r--gm/beziereffects.cpp149
1 files changed, 81 insertions, 68 deletions
diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp
index 7e492b0ca2..77f86c5ea4 100644
--- a/gm/beziereffects.cpp
+++ b/gm/beziereffects.cpp
@@ -11,56 +11,90 @@
#if SK_SUPPORT_GPU
-#include "GrRenderTargetContextPriv.h"
#include "GrContext.h"
+#include "GrOpFlushState.h"
#include "GrPathUtils.h"
+#include "GrRenderTargetContextPriv.h"
#include "GrTest.h"
#include "SkColorPriv.h"
#include "SkGeometry.h"
-
-#include "ops/GrTestMeshDrawOp.h"
-
#include "effects/GrBezierEffect.h"
+#include "ops/GrMeshDrawOp.h"
namespace skiagm {
-class BezierCubicTestOp : public GrTestMeshDrawOp {
+class BezierTestOp : public GrMeshDrawOp {
+public:
+ FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
+
+ RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override {
+ auto analysis = fProcessorSet.finalize(fColor, GrProcessorAnalysisCoverage::kSingleChannel,
+ clip, false, caps, &fColor);
+ return analysis.requiresDstTexture() ? RequiresDstTexture::kYes : RequiresDstTexture::kNo;
+ }
+
+protected:
+ BezierTestOp(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, GrColor color, int32_t classID)
+ : INHERITED(classID)
+ , fRect(rect)
+ , fColor(color)
+ , fGeometryProcessor(std::move(gp))
+ , fProcessorSet(SkBlendMode::kSrc) {
+ this->setBounds(rect, HasAABloat::kYes, IsZeroArea::kNo);
+ }
+
+ const GrPipeline* makePipeline(Target* target) const {
+ return target->makePipeline(0, &fProcessorSet);
+ }
+
+ const GrGeometryProcessor* gp() const { return fGeometryProcessor.get(); }
+
+ const SkRect& rect() const { return fRect; }
+ GrColor color() const { return fColor; }
+
+private:
+ bool onCombineIfPossible(GrOp* op, const GrCaps& caps) override { return false; }
+
+ SkRect fRect;
+ GrColor fColor;
+ sk_sp<GrGeometryProcessor> fGeometryProcessor;
+ GrProcessorSet fProcessorSet;
+
+ typedef GrMeshDrawOp INHERITED;
+};
+
+class BezierCubicTestOp : public BezierTestOp {
public:
DEFINE_OP_CLASS_ID
const char* name() const override { return "BezierCubicTestOp"; }
- static std::unique_ptr<GrLegacyMeshDrawOp> Make(sk_sp<GrGeometryProcessor> gp,
- const SkRect& rect, GrColor color) {
- return std::unique_ptr<GrLegacyMeshDrawOp>(new BezierCubicTestOp(gp, rect, color));
+ static std::unique_ptr<GrDrawOp> Make(sk_sp<GrGeometryProcessor> gp, const SkRect& rect,
+ GrColor color) {
+ return std::unique_ptr<GrDrawOp>(new BezierCubicTestOp(std::move(gp), rect, color));
}
private:
BezierCubicTestOp(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, GrColor color)
- : INHERITED(ClassID(), rect, color)
- , fRect(rect)
- , fGeometryProcessor(std::move(gp)) {
- }
+ : INHERITED(std::move(gp), rect, color, ClassID()) {}
void onPrepareDraws(Target* target) const override {
QuadHelper helper;
- size_t vertexStride = fGeometryProcessor->getVertexStride();
+ size_t vertexStride = this->gp()->getVertexStride();
SkASSERT(vertexStride == sizeof(SkPoint));
SkPoint* pts = reinterpret_cast<SkPoint*>(helper.init(target, vertexStride, 1));
if (!pts) {
return;
}
- pts[0].setRectFan(fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom, vertexStride);
- helper.recordDraw(target, fGeometryProcessor.get(), this->pipeline());
+ SkRect rect = this->rect();
+ pts[0].setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vertexStride);
+ helper.recordDraw(target, this->gp(), this->makePipeline(target));
}
- SkRect fRect;
- sk_sp<GrGeometryProcessor> fGeometryProcessor;
-
static constexpr int kVertsPerCubic = 4;
static constexpr int kIndicesPerCubic = 6;
- typedef GrTestMeshDrawOp INHERITED;
+ typedef BezierTestOp INHERITED;
};
/**
@@ -169,8 +203,6 @@ protected:
boundsPaint.setStyle(SkPaint::kStroke_Style);
canvas->drawRect(bounds, boundsPaint);
- GrPaint grPaint;
- grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
bool flipKL = (c == loopIndex && cnt != 3);
sk_sp<GrGeometryProcessor> gp = GrCubicEffect::Make(color, SkMatrix::I(), klm,
@@ -180,11 +212,9 @@ protected:
break;
}
- std::unique_ptr<GrLegacyMeshDrawOp> op =
+ std::unique_ptr<GrDrawOp> op =
BezierCubicTestOp::Make(std::move(gp), bounds, color);
-
- renderTargetContext->priv().testingOnly_addLegacyMeshDrawOp(
- std::move(grPaint), GrAAType::kNone, std::move(op));
+ renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
}
++col;
if (numCols == col) {
@@ -201,26 +231,23 @@ private:
//////////////////////////////////////////////////////////////////////////////
-class BezierConicTestOp : public GrTestMeshDrawOp {
+class BezierConicTestOp : public BezierTestOp {
public:
DEFINE_OP_CLASS_ID
const char* name() const override { return "BezierConicTestOp"; }
- static std::unique_ptr<GrLegacyMeshDrawOp> Make(sk_sp<GrGeometryProcessor> gp,
- const SkRect& rect, GrColor color,
- const SkMatrix& klm) {
- return std::unique_ptr<GrLegacyMeshDrawOp>(new BezierConicTestOp(gp, rect, color, klm));
+ static std::unique_ptr<GrDrawOp> Make(sk_sp<GrGeometryProcessor> gp, const SkRect& rect,
+ GrColor color, const SkMatrix& klm) {
+ return std::unique_ptr<GrMeshDrawOp>(
+ new BezierConicTestOp(std::move(gp), rect, color, klm));
}
private:
BezierConicTestOp(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, GrColor color,
const SkMatrix& klm)
- : INHERITED(ClassID(), rect, color)
- , fKLM(klm)
- , fRect(rect)
- , fGeometryProcessor(std::move(gp)) {
- }
+ : INHERITED(std::move(gp), rect, color, ClassID()), fKLM(klm) {}
+
struct Vertex {
SkPoint fPosition;
float fKLM[4]; // The last value is ignored. The effect expects a vec4f.
@@ -228,29 +255,28 @@ private:
void onPrepareDraws(Target* target) const override {
QuadHelper helper;
- size_t vertexStride = fGeometryProcessor->getVertexStride();
+ size_t vertexStride = this->gp()->getVertexStride();
SkASSERT(vertexStride == sizeof(Vertex));
Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, vertexStride, 1));
if (!verts) {
return;
}
- verts[0].fPosition.setRectFan(fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom,
+ SkRect rect = this->rect();
+ verts[0].fPosition.setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom,
sizeof(Vertex));
for (int v = 0; v < 4; ++v) {
SkScalar pt3[3] = {verts[v].fPosition.x(), verts[v].fPosition.y(), 1.f};
fKLM.mapHomogeneousPoints(verts[v].fKLM, pt3, 1);
}
- helper.recordDraw(target, fGeometryProcessor.get(), this->pipeline());
+ helper.recordDraw(target, this->gp(), this->makePipeline(target));
}
SkMatrix fKLM;
- SkRect fRect;
- sk_sp<GrGeometryProcessor> fGeometryProcessor;
static constexpr int kVertsPerCubic = 4;
static constexpr int kIndicesPerCubic = 6;
- typedef GrTestMeshDrawOp INHERITED;
+ typedef BezierTestOp INHERITED;
};
@@ -363,14 +389,8 @@ protected:
boundsPaint.setStyle(SkPaint::kStroke_Style);
canvas->drawRect(bounds, boundsPaint);
- GrPaint grPaint;
- grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
-
- std::unique_ptr<GrLegacyMeshDrawOp> op =
- BezierConicTestOp::Make(gp, bounds, color, klm);
-
- renderTargetContext->priv().testingOnly_addLegacyMeshDrawOp(
- std::move(grPaint), GrAAType::kNone, std::move(op));
+ std::unique_ptr<GrDrawOp> op = BezierConicTestOp::Make(gp, bounds, color, klm);
+ renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
}
++col;
if (numCols == col) {
@@ -427,24 +447,20 @@ private:
//////////////////////////////////////////////////////////////////////////////
-class BezierQuadTestOp : public GrTestMeshDrawOp {
+class BezierQuadTestOp : public BezierTestOp {
public:
DEFINE_OP_CLASS_ID
const char* name() const override { return "BezierQuadTestOp"; }
- static std::unique_ptr<GrLegacyMeshDrawOp> Make(sk_sp<GrGeometryProcessor> gp,
- const SkRect& rect, GrColor color,
- const GrPathUtils::QuadUVMatrix& devToUV) {
- return std::unique_ptr<GrLegacyMeshDrawOp>(new BezierQuadTestOp(gp, rect, color, devToUV));
+ static std::unique_ptr<GrDrawOp> Make(sk_sp<GrGeometryProcessor> gp, const SkRect& rect,
+ GrColor color, const GrPathUtils::QuadUVMatrix& devToUV) {
+ return std::unique_ptr<GrDrawOp>(new BezierQuadTestOp(std::move(gp), rect, color, devToUV));
}
private:
BezierQuadTestOp(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, GrColor color,
const GrPathUtils::QuadUVMatrix& devToUV)
- : INHERITED(ClassID(), rect, color)
- , fDevToUV(devToUV)
- , fRect(rect)
- , fGeometryProcessor(std::move(gp)) {}
+ : INHERITED(std::move(gp), rect, color, ClassID()), fDevToUV(devToUV) {}
struct Vertex {
SkPoint fPosition;
@@ -453,26 +469,25 @@ private:
void onPrepareDraws(Target* target) const override {
QuadHelper helper;
- size_t vertexStride = fGeometryProcessor->getVertexStride();
+ size_t vertexStride = this->gp()->getVertexStride();
SkASSERT(vertexStride == sizeof(Vertex));
Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, vertexStride, 1));
if (!verts) {
return;
}
- verts[0].fPosition.setRectFan(fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom,
+ SkRect rect = this->rect();
+ verts[0].fPosition.setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom,
sizeof(Vertex));
fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts);
- helper.recordDraw(target, fGeometryProcessor.get(), this->pipeline());
+ helper.recordDraw(target, this->gp(), this->makePipeline(target));
}
GrPathUtils::QuadUVMatrix fDevToUV;
- SkRect fRect;
- sk_sp<GrGeometryProcessor> fGeometryProcessor;
static constexpr int kVertsPerCubic = 4;
static constexpr int kIndicesPerCubic = 6;
- typedef GrTestMeshDrawOp INHERITED;
+ typedef BezierTestOp INHERITED;
};
/**
@@ -584,11 +599,9 @@ protected:
GrPathUtils::QuadUVMatrix DevToUV(pts);
- std::unique_ptr<GrLegacyMeshDrawOp> op =
+ std::unique_ptr<GrDrawOp> op =
BezierQuadTestOp::Make(gp, bounds, color, DevToUV);
-
- renderTargetContext->priv().testingOnly_addLegacyMeshDrawOp(
- std::move(grPaint), GrAAType::kNone, std::move(op));
+ renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
}
++col;
if (numCols == col) {