2019-03-07 21:17:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 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/SkBlendMode.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColorSpace.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/gpu/GrTypes.h"
|
|
|
|
#include "include/private/GrTypesPriv.h"
|
|
|
|
#include "include/private/SkColorData.h"
|
|
|
|
#include "src/gpu/GrBuffer.h"
|
|
|
|
#include "src/gpu/GrCaps.h"
|
|
|
|
#include "src/gpu/GrColorSpaceXform.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrContextPriv.h"
|
2019-05-01 21:28:53 +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-08-26 15:08:51 +00:00
|
|
|
#include "src/gpu/GrOpsRenderPass.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/gpu/GrPaint.h"
|
|
|
|
#include "src/gpu/GrPipeline.h"
|
|
|
|
#include "src/gpu/GrPrimitiveProcessor.h"
|
|
|
|
#include "src/gpu/GrProcessor.h"
|
|
|
|
#include "src/gpu/GrProcessorSet.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContext.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
2019-08-14 21:00:30 +00:00
|
|
|
#include "src/gpu/GrSamplerState.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/gpu/GrShaderCaps.h"
|
|
|
|
#include "src/gpu/GrShaderVar.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrSurfaceProxy.h"
|
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/gpu/GrUserStencilSettings.h"
|
|
|
|
#include "src/gpu/effects/GrPorterDuffXferProcessor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
|
|
|
#include "src/gpu/glsl/GrGLSLGeometryProcessor.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/gpu/glsl/GrGLSLPrimitiveProcessor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
|
|
|
|
#include "src/gpu/glsl/GrGLSLVarying.h"
|
|
|
|
#include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/gpu/ops/GrDrawOp.h"
|
|
|
|
#include "src/gpu/ops/GrOp.h"
|
2019-11-21 21:02:34 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
class GrAppliedClip;
|
|
|
|
class GrGLSLProgramDataManager;
|
2019-03-07 21:17:03 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
enum class GradType : bool {
|
|
|
|
kHW,
|
|
|
|
kSW
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This test ensures that the shaderBuilder's sample offsets and sample mask are correlated with
|
|
|
|
* actual HW sample locations. It does so by drawing pseudo-random subpixel boxes, and only turning
|
|
|
|
* off the samples whose locations fall inside the boxes.
|
|
|
|
*/
|
|
|
|
class SampleLocationsGM : public GpuGM {
|
|
|
|
public:
|
|
|
|
SampleLocationsGM(GradType gradType, GrSurfaceOrigin origin)
|
|
|
|
: fGradType(gradType)
|
|
|
|
, fOrigin(origin) {}
|
|
|
|
|
|
|
|
private:
|
2019-07-18 16:36:54 +00:00
|
|
|
SkString onShortName() override {
|
|
|
|
return SkStringPrintf("samplelocations%s%s",
|
|
|
|
(GradType::kHW == fGradType) ? "_hwgrad" : "_swgrad",
|
|
|
|
(kTopLeft_GrSurfaceOrigin == fOrigin) ? "_topleft" : "_botleft");
|
|
|
|
}
|
|
|
|
|
2019-03-07 21:17:03 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(200, 200); }
|
2020-06-29 19:36:12 +00:00
|
|
|
DrawResult onDraw(GrRecordingContext*, GrRenderTargetContext*,
|
|
|
|
SkCanvas*, SkString* errorMsg) override;
|
2019-03-07 21:17:03 +00:00
|
|
|
|
|
|
|
const GradType fGradType;
|
|
|
|
const GrSurfaceOrigin fOrigin;
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SkSL code.
|
|
|
|
|
|
|
|
class SampleLocationsTestProcessor : public GrGeometryProcessor {
|
|
|
|
public:
|
2019-11-18 16:50:54 +00:00
|
|
|
static GrGeometryProcessor* Make(SkArenaAlloc* arena, GradType gradType) {
|
|
|
|
return arena->make<SampleLocationsTestProcessor>(gradType);
|
2019-03-07 21:17:03 +00:00
|
|
|
}
|
2019-11-18 16:50:54 +00:00
|
|
|
|
2019-03-07 21:17:03 +00:00
|
|
|
const char* name() const override { return "SampleLocationsTestProcessor"; }
|
2019-11-18 16:50:54 +00:00
|
|
|
|
2019-03-07 21:17:03 +00:00
|
|
|
void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const final {
|
|
|
|
b->add32((uint32_t)fGradType);
|
|
|
|
}
|
2019-11-18 16:50:54 +00:00
|
|
|
|
2019-03-07 21:17:03 +00:00
|
|
|
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final;
|
|
|
|
|
|
|
|
private:
|
2019-11-18 16:50:54 +00:00
|
|
|
friend class ::SkArenaAlloc; // for access to ctor
|
|
|
|
|
|
|
|
SampleLocationsTestProcessor(GradType gradType)
|
|
|
|
: GrGeometryProcessor(kSampleLocationsTestProcessor_ClassID)
|
|
|
|
, fGradType(gradType) {
|
|
|
|
this->setWillUseCustomFeature(CustomFeatures::kSampleLocations);
|
|
|
|
}
|
|
|
|
|
2019-03-07 21:17:03 +00:00
|
|
|
const GradType fGradType;
|
|
|
|
|
|
|
|
class Impl;
|
2019-11-18 16:50:54 +00:00
|
|
|
|
|
|
|
typedef GrGeometryProcessor INHERITED;
|
2019-03-07 21:17:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SampleLocationsTestProcessor::Impl : public GrGLSLGeometryProcessor {
|
|
|
|
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
|
|
|
|
const auto& proc = args.fGP.cast<SampleLocationsTestProcessor>();
|
|
|
|
auto* v = args.fVertBuilder;
|
|
|
|
auto* f = args.fFragBuilder;
|
|
|
|
|
|
|
|
GrGLSLVarying coord(kFloat2_GrSLType);
|
|
|
|
GrGLSLVarying grad(kFloat2_GrSLType);
|
|
|
|
args.fVaryingHandler->addVarying("coord", &coord);
|
|
|
|
if (GradType::kSW == proc.fGradType) {
|
|
|
|
args.fVaryingHandler->addVarying("grad", &grad);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pixel grid.
|
|
|
|
v->codeAppendf("int x = sk_InstanceID %% 200;");
|
|
|
|
v->codeAppendf("int y = sk_InstanceID / 200;");
|
|
|
|
|
|
|
|
// Create pseudo-random rectangles inside a 16x16 subpixel grid. This works out nicely
|
|
|
|
// because there are 17 positions on the grid (including both edges), and 17 is a great
|
|
|
|
// prime number for generating pseudo-random numbers.
|
|
|
|
v->codeAppendf("int ileft = (sk_InstanceID*929) %% 17;");
|
|
|
|
v->codeAppendf("int iright = ileft + 1 + ((sk_InstanceID*1637) %% (17 - ileft));");
|
|
|
|
v->codeAppendf("int itop = (sk_InstanceID*313) %% 17;");
|
|
|
|
v->codeAppendf("int ibot = itop + 1 + ((sk_InstanceID*1901) %% (17 - itop));");
|
|
|
|
|
|
|
|
// Outset (or inset) the rectangle, for the very likely scenario that samples fall on exact
|
|
|
|
// 16ths of a pixel. GL_SUBPIXEL_BITS is allowed to be as low as 4, so try not to let the
|
|
|
|
// outset value to get too small.
|
|
|
|
v->codeAppendf("float outset = 1/32.0;");
|
|
|
|
v->codeAppendf("outset = (0 == (x + y) %% 2) ? -outset : +outset;");
|
|
|
|
v->codeAppendf("float l = ileft/16.0 - outset;");
|
|
|
|
v->codeAppendf("float r = iright/16.0 + outset;");
|
|
|
|
v->codeAppendf("float t = itop/16.0 - outset;");
|
|
|
|
v->codeAppendf("float b = ibot/16.0 + outset;");
|
|
|
|
|
|
|
|
v->codeAppendf("float2 vertexpos;");
|
|
|
|
v->codeAppendf("vertexpos.x = float(x) + ((0 == (sk_VertexID %% 2)) ? l : r);");
|
|
|
|
v->codeAppendf("vertexpos.y = float(y) + ((0 == (sk_VertexID / 2)) ? t : b);");
|
|
|
|
gpArgs->fPositionVar.set(kFloat2_GrSLType, "vertexpos");
|
|
|
|
|
|
|
|
v->codeAppendf("%s.x = (0 == (sk_VertexID %% 2)) ? -1 : +1;", coord.vsOut());
|
|
|
|
v->codeAppendf("%s.y = (0 == (sk_VertexID / 2)) ? -1 : +1;", coord.vsOut());
|
|
|
|
if (GradType::kSW == proc.fGradType) {
|
|
|
|
v->codeAppendf("%s = 2/float2(r - l, b - t);", grad.vsOut());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fragment shader: Output RED.
|
|
|
|
f->codeAppendf("%s = half4(1,0,0,1);", args.fOutputColor);
|
|
|
|
f->codeAppendf("%s = half4(1);", args.fOutputCoverage);
|
|
|
|
|
|
|
|
// Now turn off all the samples inside our sub-rectangle. As long as the shaderBuilder's
|
|
|
|
// sample offsets and sample mask are correlated with actual HW sample locations, no red
|
|
|
|
// will bleed through.
|
|
|
|
f->codeAppendf("for (int i = 0; i < %i; ++i) {",
|
|
|
|
f->getProgramBuilder()->effectiveSampleCnt());
|
|
|
|
if (GradType::kHW == proc.fGradType) {
|
|
|
|
f->codeAppendf("float2x2 grad = float2x2(dFdx(%s), dFdy(%s));",
|
|
|
|
coord.fsIn(), coord.fsIn());
|
|
|
|
} else {
|
|
|
|
f->codeAppendf("float2x2 grad = float2x2(%s.x, 0, 0, %s.y);", grad.fsIn(), grad.fsIn());
|
|
|
|
}
|
|
|
|
f->codeAppendf( "float2 samplecoord = %s[i] * grad + %s;",
|
|
|
|
f->sampleOffsets(), coord.fsIn());
|
|
|
|
f->codeAppendf( "if (all(lessThanEqual(abs(samplecoord), float2(1)))) {");
|
|
|
|
f->maskOffMultisampleCoverage(
|
2019-03-27 19:08:50 +00:00
|
|
|
"~(1 << i)", GrGLSLFPFragmentBuilder::ScopeFlags::kInsideLoop);
|
2019-03-07 21:17:03 +00:00
|
|
|
f->codeAppendf( "}");
|
|
|
|
f->codeAppendf("}");
|
|
|
|
}
|
|
|
|
|
2020-07-01 19:14:39 +00:00
|
|
|
void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&) override {}
|
2019-03-07 21:17:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GrGLSLPrimitiveProcessor* SampleLocationsTestProcessor::createGLSLInstance(
|
|
|
|
const GrShaderCaps&) const {
|
|
|
|
return new Impl();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Draw Op.
|
|
|
|
|
2019-11-18 16:50:54 +00:00
|
|
|
static constexpr GrUserStencilSettings gStencilWrite(
|
|
|
|
GrUserStencilSettings::StaticInit<
|
|
|
|
0x0001,
|
|
|
|
GrUserStencilTest::kAlways,
|
|
|
|
0xffff,
|
|
|
|
GrUserStencilOp::kReplace,
|
|
|
|
GrUserStencilOp::kKeep,
|
|
|
|
0xffff>()
|
|
|
|
);
|
|
|
|
|
2019-03-07 21:17:03 +00:00
|
|
|
class SampleLocationsTestOp : public GrDrawOp {
|
|
|
|
public:
|
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
|
|
|
static std::unique_ptr<GrDrawOp> Make(
|
|
|
|
GrRecordingContext* ctx, const SkMatrix& viewMatrix, GradType gradType) {
|
|
|
|
GrOpMemoryPool* pool = ctx->priv().opMemoryPool();
|
|
|
|
return pool->allocate<SampleLocationsTestOp>(gradType);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SampleLocationsTestOp(GradType gradType) : GrDrawOp(ClassID()), fGradType(gradType) {
|
2019-10-01 19:14:44 +00:00
|
|
|
this->setBounds(SkRect::MakeIWH(200, 200), HasAABloat::kNo, IsHairline::kNo);
|
2019-03-07 21:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* name() const override { return "SampleLocationsTestOp"; }
|
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override {
|
|
|
|
return FixedFunctionFlags::kUsesHWAA | FixedFunctionFlags::kUsesStencil;
|
|
|
|
}
|
2019-06-24 00:07:38 +00:00
|
|
|
GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
|
|
|
|
bool hasMixedSampledCoverage, GrClampType) override {
|
2019-03-07 21:17:03 +00:00
|
|
|
return GrProcessorSet::EmptySetAnalysis();
|
|
|
|
}
|
2019-11-18 16:50:54 +00:00
|
|
|
|
2020-02-28 21:02:40 +00:00
|
|
|
|
|
|
|
GrProgramInfo* createProgramInfo(const GrCaps* caps,
|
|
|
|
SkArenaAlloc* arena,
|
2020-04-01 20:22:00 +00:00
|
|
|
const GrSurfaceProxyView* writeView,
|
2020-02-28 21:02:40 +00:00
|
|
|
GrAppliedClip&& appliedClip,
|
|
|
|
const GrXferProcessor::DstProxyView& dstProxyView) const {
|
|
|
|
GrGeometryProcessor* geomProc = SampleLocationsTestProcessor::Make(arena, fGradType);
|
|
|
|
|
|
|
|
GrPipeline::InputFlags flags = GrPipeline::InputFlags::kHWAntialias;
|
|
|
|
|
2020-04-01 20:22:00 +00:00
|
|
|
return sk_gpu_test::CreateProgramInfo(caps, arena, writeView,
|
2020-02-28 21:02:40 +00:00
|
|
|
std::move(appliedClip), dstProxyView,
|
|
|
|
geomProc, SkBlendMode::kSrcOver,
|
|
|
|
GrPrimitiveType::kTriangleStrip,
|
|
|
|
flags, &gStencilWrite);
|
|
|
|
}
|
|
|
|
|
|
|
|
GrProgramInfo* createProgramInfo(GrOpFlushState* flushState) const {
|
|
|
|
return this->createProgramInfo(&flushState->caps(),
|
|
|
|
flushState->allocator(),
|
2020-04-01 20:22:00 +00:00
|
|
|
flushState->writeView(),
|
2020-02-28 21:02:40 +00:00
|
|
|
flushState->detachAppliedClip(),
|
|
|
|
flushState->dstProxyView());
|
|
|
|
}
|
|
|
|
|
2019-11-18 16:50:54 +00:00
|
|
|
void onPrePrepare(GrRecordingContext* context,
|
2020-04-01 20:22:00 +00:00
|
|
|
const GrSurfaceProxyView* writeView,
|
2019-11-21 21:02:34 +00:00
|
|
|
GrAppliedClip* clip,
|
2019-11-21 15:44:53 +00:00
|
|
|
const GrXferProcessor::DstProxyView& dstProxyView) final {
|
2019-11-18 16:50:54 +00:00
|
|
|
// We're going to create the GrProgramInfo (and the GrPipeline and geometry processor
|
|
|
|
// it relies on) in the DDL-record-time arena.
|
|
|
|
SkArenaAlloc* arena = context->priv().recordTimeAllocator();
|
|
|
|
|
2019-11-21 21:02:34 +00:00
|
|
|
// This is equivalent to a GrOpFlushState::detachAppliedClip
|
Reland "Improve scissor state tracking in GrRTC"
This reverts commit 4926b07217f07e8f5ff1dba15d23bab960ffded3.
Reason for revert: fix wip
Original change's description:
> Revert "Improve scissor state tracking in GrRTC"
>
> This reverts commit 3b923a880bc0855772daffd95b5728795f515d5f.
>
> Reason for revert: GrAppliedHardClip isn't tracking scissor state properly
>
> Original change's description:
> > Improve scissor state tracking in GrRTC
> >
> > At a low level, this changes GrScissorState from a rect+bool to a rect+size.
> > The scissor test is considered enablebd if the rect does not fill the
> > device bounds rect specified by the size. This has a number of benefits:
> >
> > 1. We can always access the scissor rect and know that it will be
> > restricted to the render target dimensions.
> > 2. It helps consolidate code that previously had to test the scissor rect
> > and render target bounds separately.
> > 3. The clear operations can now match the proper backing store dimensions
> > of the render target.
> > 4. It makes it easier to reason about scissors applying to the logical
> > dimensions of the render target vs. its backing store dimensions.
> >
> > Originally, I was going to have the extra scissor guards for the logical
> > dimensions be added in a separate CL (with the cleanup for
> > attemptQuadOptimization). However, it became difficult to ensure correct
> > behavior respecting the vulkan render pass bounds without applying this
> > new logic at the same time.
> >
> > So now, with this CL, GrAppliedClips are sized to the backing store
> > dimensions of the render target. GrOpsTasks also clip bounds to the
> > backing store dimensions instead of the logical dimensions (which seems
> > more correct since that's where the auto-clipping happens). Then when
> > we convert a GrClip to a GrAppliedClip, the GrRTC automatically enforces
> > the logical dimensions scissor if we have stencil settings (to ensure
> > the padded pixels don't get corrupted). It also may remove the scissor
> > if the draw was just a color buffer update.
> >
> > Change-Id: I75671c9cc921f4696b1dd5231e02486090aa4282
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290654
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
>
> Change-Id: Ie98d084158e3a537604ab0fecee69bde3e744d1b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294340
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
# Not skipping CQ checks because this is a reland.
Change-Id: I2116e52146890ee4b7ea007f3c3d5c3e532e4bdd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294257
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-06-04 19:52:44 +00:00
|
|
|
GrAppliedClip appliedClip = clip ? std::move(*clip) : GrAppliedClip::Disabled();
|
2019-11-18 16:50:54 +00:00
|
|
|
|
2020-04-01 20:22:00 +00:00
|
|
|
fProgramInfo = this->createProgramInfo(context->priv().caps(), arena, writeView,
|
2020-02-28 21:02:40 +00:00
|
|
|
std::move(appliedClip), dstProxyView);
|
2019-11-18 16:50:54 +00:00
|
|
|
|
2020-02-28 21:02:40 +00:00
|
|
|
context->priv().recordProgramInfo(fProgramInfo);
|
2019-11-18 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onPrepare(GrOpFlushState*) final {}
|
|
|
|
|
|
|
|
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) final {
|
2019-11-21 21:02:34 +00:00
|
|
|
if (!fProgramInfo) {
|
2020-02-28 21:02:40 +00:00
|
|
|
fProgramInfo = this->createProgramInfo(flushState);
|
2019-11-21 21:02:34 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 16:05:11 +00:00
|
|
|
flushState->bindPipelineAndScissorClip(*fProgramInfo, SkRect::MakeIWH(200, 200));
|
|
|
|
flushState->bindBuffers(nullptr, nullptr, nullptr);
|
|
|
|
flushState->drawInstanced(200*200, 0, 4, 0);
|
2019-03-07 21:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const GradType fGradType;
|
|
|
|
|
2019-11-18 16:50:54 +00:00
|
|
|
// The program info (and both the GrPipeline and GrPrimitiveProcessor it relies on), when
|
2019-11-21 21:02:34 +00:00
|
|
|
// allocated, are allocated in either the ddl-record-time or flush-time arena. It is the
|
|
|
|
// arena's job to free up their memory so we just have a bare programInfo pointer here. We
|
|
|
|
// don't even store the GrPipeline and GrPrimitiveProcessor pointers here bc they are
|
|
|
|
// guaranteed to have the same lifetime as the program info.
|
2019-11-18 16:50:54 +00:00
|
|
|
GrProgramInfo* fProgramInfo = nullptr;
|
|
|
|
|
2019-03-07 21:17:03 +00:00
|
|
|
friend class ::GrOpMemoryPool; // for ctor
|
2019-11-18 16:50:54 +00:00
|
|
|
|
|
|
|
typedef GrDrawOp INHERITED;
|
2019-03-07 21:17:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Test.
|
|
|
|
|
2020-06-29 19:36:12 +00:00
|
|
|
DrawResult SampleLocationsGM::onDraw(GrRecordingContext* ctx, GrRenderTargetContext* rtc,
|
|
|
|
SkCanvas* canvas, SkString* errorMsg) {
|
2019-03-07 21:17:03 +00:00
|
|
|
if (!ctx->priv().caps()->sampleLocationsSupport()) {
|
|
|
|
*errorMsg = "Requires support for sample locations.";
|
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
2019-10-30 00:54:58 +00:00
|
|
|
if (!ctx->priv().caps()->shaderCaps()->sampleMaskSupport()) {
|
|
|
|
*errorMsg = "Requires support for sample mask.";
|
2019-03-07 21:17:03 +00:00
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
2020-04-07 18:31:59 +00:00
|
|
|
if (!ctx->priv().caps()->drawInstancedSupport()) {
|
|
|
|
*errorMsg = "Requires support for instanced rendering.";
|
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
2019-07-02 04:28:03 +00:00
|
|
|
if (rtc->numSamples() <= 1 && !ctx->priv().caps()->mixedSamplesSupport()) {
|
|
|
|
*errorMsg = "MSAA and mixed samples only.";
|
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:52:34 +00:00
|
|
|
auto offscreenRTC = GrRenderTargetContext::Make(
|
|
|
|
ctx, rtc->colorInfo().colorType(), nullptr, SkBackingFit::kExact, {200, 200},
|
2020-07-21 13:27:25 +00:00
|
|
|
rtc->numSamples(), GrMipmapped::kNo, GrProtected::kNo, fOrigin);
|
2019-07-02 04:28:03 +00:00
|
|
|
if (!offscreenRTC) {
|
|
|
|
*errorMsg = "Failed to create offscreen render target.";
|
|
|
|
return DrawResult::kFail;
|
|
|
|
}
|
|
|
|
if (offscreenRTC->numSamples() <= 1 &&
|
2019-12-16 19:38:36 +00:00
|
|
|
!offscreenRTC->asRenderTargetProxy()->canUseMixedSamples(*ctx->priv().caps())) {
|
2019-07-02 04:28:03 +00:00
|
|
|
*errorMsg = "MSAA and mixed samples only.";
|
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
2019-03-07 21:17:03 +00:00
|
|
|
|
|
|
|
static constexpr GrUserStencilSettings kStencilCover(
|
|
|
|
GrUserStencilSettings::StaticInit<
|
|
|
|
0x0000,
|
|
|
|
GrUserStencilTest::kNotEqual,
|
|
|
|
0xffff,
|
|
|
|
GrUserStencilOp::kZero,
|
|
|
|
GrUserStencilOp::kKeep,
|
|
|
|
0xffff>()
|
|
|
|
);
|
|
|
|
|
2020-05-26 20:57:38 +00:00
|
|
|
offscreenRTC->clear({0,1,0,1});
|
2019-07-02 04:28:03 +00:00
|
|
|
|
|
|
|
// Stencil.
|
|
|
|
offscreenRTC->priv().testingOnly_addDrawOp(
|
|
|
|
SampleLocationsTestOp::Make(ctx, canvas->getTotalMatrix(), fGradType));
|
|
|
|
|
|
|
|
// Cover.
|
|
|
|
GrPaint coverPaint;
|
|
|
|
coverPaint.setColor4f({1,0,0,1});
|
|
|
|
coverPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrcOver));
|
2020-05-29 13:54:07 +00:00
|
|
|
rtc->priv().stencilRect(nullptr, &kStencilCover, std::move(coverPaint), GrAA::kNo,
|
2019-07-02 04:28:03 +00:00
|
|
|
SkMatrix::I(), SkRect::MakeWH(200, 200));
|
|
|
|
|
|
|
|
// Copy offscreen texture to canvas.
|
2020-07-22 15:18:06 +00:00
|
|
|
rtc->drawTexture(nullptr,
|
|
|
|
offscreenRTC->readSurfaceView(),
|
2020-01-30 19:55:05 +00:00
|
|
|
offscreenRTC->colorInfo().alphaType(),
|
2020-07-22 15:18:06 +00:00
|
|
|
GrSamplerState::Filter::kNearest,
|
|
|
|
GrSamplerState::MipmapMode::kNone,
|
|
|
|
SkBlendMode::kSrc,
|
|
|
|
SK_PMColor4fWHITE,
|
|
|
|
{0, 0, 200, 200},
|
|
|
|
{0, 0, 200, 200},
|
|
|
|
GrAA::kNo,
|
|
|
|
GrQuadAAFlags::kNone,
|
|
|
|
SkCanvas::SrcRectConstraint::kStrict_SrcRectConstraint,
|
|
|
|
SkMatrix::I(),
|
2019-11-23 00:09:27 +00:00
|
|
|
nullptr);
|
2019-03-07 21:17:03 +00:00
|
|
|
|
|
|
|
return skiagm::DrawResult::kOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GM( return new SampleLocationsGM(GradType::kHW, kTopLeft_GrSurfaceOrigin); )
|
|
|
|
DEF_GM( return new SampleLocationsGM(GradType::kHW, kBottomLeft_GrSurfaceOrigin); )
|
|
|
|
DEF_GM( return new SampleLocationsGM(GradType::kSW, kTopLeft_GrSurfaceOrigin); )
|
|
|
|
DEF_GM( return new SampleLocationsGM(GradType::kSW, kBottomLeft_GrSurfaceOrigin); )
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|