ccpr: Update the sample to use proper coverage count buffers

Bug: skia:
Change-Id: I6ce3ec567e671fa2ab3f05403015b48251518227
Reviewed-on: https://skia-review.googlesource.com/115072
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
Chris Dalton 2018-03-19 14:16:44 -06:00 committed by Skia Commit-Bot
parent f36b8a30c5
commit 8d38a7f521
5 changed files with 66 additions and 21 deletions

View File

@ -49,7 +49,8 @@ public:
private:
class Click;
class Op;
class DrawCoverageCountOp;
class VisualizeCoverageCountFP;
void updateAndInval() { this->updateGpuData(); }
@ -68,15 +69,17 @@ private:
typedef SampleView INHERITED;
};
class CCPRGeometryView::Op : public GrDrawOp {
class CCPRGeometryView::DrawCoverageCountOp : public GrDrawOp {
DEFINE_OP_CLASS_ID
public:
Op(CCPRGeometryView* view) : INHERITED(ClassID()), fView(view) {
DrawCoverageCountOp(CCPRGeometryView* view) : INHERITED(ClassID()), fView(view) {
this->setBounds(SkRectPriv::MakeLargest(), GrOp::HasAABloat::kNo, GrOp::IsZeroArea::kNo);
}
const char* name() const override { return "[Testing/Sample code] CCPRGeometryView::Op"; }
const char* name() const override {
return "[Testing/Sample code] CCPRGeometryView::DrawCoverageCountOp";
}
private:
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
@ -94,6 +97,32 @@ private:
typedef GrDrawOp INHERITED;
};
class CCPRGeometryView::VisualizeCoverageCountFP : public GrFragmentProcessor {
public:
VisualizeCoverageCountFP() : GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags) {}
private:
const char* name() const override {
return "[Testing/Sample code] CCPRGeometryView::VisualizeCoverageCountFP";
}
std::unique_ptr<GrFragmentProcessor> clone() const override {
return skstd::make_unique<VisualizeCoverageCountFP>();
}
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
class Impl : public GrGLSLFragmentProcessor {
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* f = args.fFragBuilder;
f->codeAppendf("half count = %s.a;", args.fInputColor);
f->codeAppendf("%s = half4(clamp(-count, 0, 1), clamp(+count, 0, 1), 0, abs(count));",
args.fOutputColor);
}
};
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new Impl; }
};
static void draw_klm_line(int w, int h, SkCanvas* canvas, const SkScalar line[3], SkColor color) {
SkPoint p1, p2;
if (SkScalarAbs(line[1]) > SkScalarAbs(line[0])) {
@ -153,7 +182,29 @@ void CCPRGeometryView::onDrawContent(SkCanvas* canvas) {
SkString caption;
if (GrRenderTargetContext* rtc = canvas->internal_private_accessTopLayerRenderTargetContext()) {
rtc->priv().testingOnly_addDrawOp(skstd::make_unique<Op>(this));
// Render coverage count.
GrContext* ctx = canvas->getGrContext();
SkASSERT(ctx);
sk_sp<GrRenderTargetContext> ccbuff =
ctx->contextPriv().makeDeferredRenderTargetContext(SkBackingFit::kApprox,
this->width(), this->height(),
kAlpha_half_GrPixelConfig,
nullptr);
SkASSERT(ccbuff);
ccbuff->clear(nullptr, 0, GrRenderTargetContext::CanClearFullscreen::kYes);
ccbuff->priv().testingOnly_addDrawOp(skstd::make_unique<DrawCoverageCountOp>(this));
// Visualize coverage count in main canvas.
GrPaint paint;
paint.addColorFragmentProcessor(
GrSimpleTextureEffect::Make(sk_ref_sp(ccbuff->asTextureProxy()), SkMatrix::I()));
paint.addColorFragmentProcessor(
skstd::make_unique<VisualizeCoverageCountFP>());
paint.setPorterDuffXPFactory(SkBlendMode::kSrcOver);
rtc->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(),
SkRect::MakeIWH(this->width(), this->height()));
// Add label.
caption.appendf("RenderPass_%s", GrCCCoverageProcessor::RenderPassName(fRenderPass));
if (RenderPass::kCubics == fRenderPass) {
caption.appendf(" (%s)", SkCubicTypeName(fCubicType));
@ -238,7 +289,7 @@ void CCPRGeometryView::updateGpuData() {
}
}
void CCPRGeometryView::Op::onExecute(GrOpFlushState* state) {
void CCPRGeometryView::DrawCoverageCountOp::onExecute(GrOpFlushState* state) {
this->drawRenderPass(state, fView->fRenderPass);
RenderPass cornerPass = RenderPass((int)fView->fRenderPass + 1);
@ -247,7 +298,8 @@ void CCPRGeometryView::Op::onExecute(GrOpFlushState* state) {
}
}
void CCPRGeometryView::Op::drawRenderPass(GrOpFlushState* state, RenderPass renderPass) {
void CCPRGeometryView::DrawCoverageCountOp::drawRenderPass(GrOpFlushState* state,
RenderPass renderPass) {
GrResourceProvider* rp = state->resourceProvider();
GrContext* context = state->gpu()->getContext();
GrGLGpu* glGpu = kOpenGL_GrBackend == context->contextPriv().getBackend()
@ -255,7 +307,7 @@ void CCPRGeometryView::Op::drawRenderPass(GrOpFlushState* state, RenderPass rend
: nullptr;
GrCCCoverageProcessor proc(rp, renderPass, GrCCCoverageProcessor::WindMethod::kCrossProduct);
SkDEBUGCODE(proc.enableDebugVisualizations(kDebugBloat));
SkDEBUGCODE(proc.enableDebugBloat(kDebugBloat));
SkSTArray<1, GrMesh> mesh;
if (RenderPass::kCubics == renderPass) {

View File

@ -23,12 +23,6 @@ void GrCCCoverageProcessor::Shader::emitFragmentCode(const GrCCCoverageProcessor
this->onEmitFragmentCode(f, "coverage");
f->codeAppendf("%s.a = coverage;", skOutputColor);
f->codeAppendf("%s = half4(1);", skOutputCoverage);
#ifdef SK_DEBUG
if (proc.debugVisualizationsEnabled()) {
f->codeAppendf("%s = half4(-%s.a, %s.a, 0, abs(%s.a));",
skOutputColor, skOutputColor, skOutputColor, skOutputColor);
}
#endif
}
void GrCCCoverageProcessor::Shader::EmitEdgeDistanceEquation(GrGLSLVertexGeoBuilder* s,

View File

@ -104,11 +104,10 @@ public:
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
#ifdef SK_DEBUG
// Increases the 1/2 pixel AA bloat by a factor of debugBloat and outputs color instead of
// coverage (coverage=+1 -> green, coverage=0 -> black, coverage=-1 -> red).
void enableDebugVisualizations(float debugBloat) { fDebugBloat = debugBloat; }
bool debugVisualizationsEnabled() const { return fDebugBloat > 0; }
float debugBloat() const { SkASSERT(this->debugVisualizationsEnabled()); return fDebugBloat; }
// Increases the 1/2 pixel AA bloat by a factor of debugBloat.
void enableDebugBloat(float debugBloat) { fDebugBloat = debugBloat; }
bool debugBloatEnabled() const { return fDebugBloat > 0; }
float debugBloat() const { SkASSERT(this->debugBloatEnabled()); return fDebugBloat; }
#endif
// Appends a GrMesh that will draw the provided instances. The instanceBuffer must be an array

View File

@ -95,7 +95,7 @@ protected:
float bloat = kAABloatRadius;
#ifdef SK_DEBUG
if (proc.debugVisualizationsEnabled()) {
if (proc.debugBloatEnabled()) {
bloat *= proc.debugBloat();
}
#endif

View File

@ -62,7 +62,7 @@ protected:
float bloat = kAABloatRadius;
#ifdef SK_DEBUG
if (proc.debugVisualizationsEnabled()) {
if (proc.debugBloatEnabled()) {
bloat *= proc.debugBloat();
}
#endif