2018-07-27 18:38:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 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/SkPoint.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"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContext.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/gpu/GrTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/private/GrRecordingContext.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/private/GrTypesPriv.h"
|
|
|
|
#include "include/private/SkColorData.h"
|
|
|
|
#include "src/gpu/GrBuffer.h"
|
|
|
|
#include "src/gpu/GrCaps.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrClip.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#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"
|
|
|
|
#include "src/gpu/GrGpuBuffer.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrMemoryPool.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/gpu/GrMesh.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#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/GrPipeline.h"
|
|
|
|
#include "src/gpu/GrPrimitiveProcessor.h"
|
|
|
|
#include "src/gpu/GrProcessor.h"
|
|
|
|
#include "src/gpu/GrProcessorSet.h"
|
2019-10-08 16:32:56 +00:00
|
|
|
#include "src/gpu/GrProgramInfo.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-05-01 21:28:53 +00:00
|
|
|
#include "src/gpu/GrResourceProvider.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-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/GrGLSLVarying.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;
|
2018-07-27 18:38:35 +00:00
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
namespace {
|
2018-07-27 18:38:35 +00:00
|
|
|
|
2018-09-14 20:16:55 +00:00
|
|
|
static constexpr GrGeometryProcessor::Attribute gVertex =
|
2019-06-19 18:19:47 +00:00
|
|
|
{"position", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
|
2018-07-27 18:38:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a GPU-backend specific test. It ensures that SkSL properly identifies clockwise-winding
|
|
|
|
* triangles (sk_Clockwise), in terms of to Skia device space, in all backends and with all render
|
|
|
|
* target origins. We draw clockwise triangles green and counter-clockwise red.
|
|
|
|
*/
|
2019-07-18 16:36:54 +00:00
|
|
|
class ClockwiseGM : public skiagm::GpuGM {
|
|
|
|
SkString onShortName() override { return SkString("clockwise"); }
|
|
|
|
SkISize onISize() override { return {300, 200}; }
|
2019-02-07 22:23:36 +00:00
|
|
|
void onDraw(GrContext*, GrRenderTargetContext*, SkCanvas*) override;
|
2018-07-27 18:38:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SkSL code.
|
|
|
|
|
|
|
|
class ClockwiseTestProcessor : public GrGeometryProcessor {
|
|
|
|
public:
|
2019-11-18 16:19:51 +00:00
|
|
|
static GrGeometryProcessor* Make(SkArenaAlloc* arena, bool readSkFragCoord) {
|
|
|
|
return arena->make<ClockwiseTestProcessor>(readSkFragCoord);
|
2018-07-27 18:38:35 +00:00
|
|
|
}
|
2019-11-15 19:57:05 +00:00
|
|
|
|
|
|
|
const char* name() const final { return "ClockwiseTestProcessor"; }
|
|
|
|
|
2018-07-27 18:38:35 +00:00
|
|
|
void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const final {
|
|
|
|
b->add32(fReadSkFragCoord);
|
|
|
|
}
|
2019-11-15 19:57:05 +00:00
|
|
|
|
2018-07-27 18:38:35 +00:00
|
|
|
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final;
|
|
|
|
|
2019-11-18 16:19:51 +00:00
|
|
|
bool readSkFragCoord() const { return fReadSkFragCoord; }
|
|
|
|
|
2018-07-27 18:38:35 +00:00
|
|
|
private:
|
2019-11-18 16:19:51 +00:00
|
|
|
friend class ::SkArenaAlloc; // for access to ctor
|
|
|
|
|
2019-11-15 19:57:05 +00:00
|
|
|
ClockwiseTestProcessor(bool readSkFragCoord)
|
|
|
|
: GrGeometryProcessor(kClockwiseTestProcessor_ClassID)
|
|
|
|
, fReadSkFragCoord(readSkFragCoord) {
|
|
|
|
this->setVertexAttributes(&gVertex, 1);
|
|
|
|
}
|
|
|
|
|
2018-07-27 18:38:35 +00:00
|
|
|
const bool fReadSkFragCoord;
|
|
|
|
|
2019-11-18 16:19:51 +00:00
|
|
|
typedef GrGeometryProcessor INHERITED;
|
2018-07-27 18:38:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GLSLClockwiseTestProcessor : public GrGLSLGeometryProcessor {
|
|
|
|
void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor&,
|
2019-11-27 13:57:17 +00:00
|
|
|
const CoordTransformRange&) override {}
|
2018-07-27 18:38:35 +00:00
|
|
|
|
|
|
|
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
|
|
|
|
const ClockwiseTestProcessor& proc = args.fGP.cast<ClockwiseTestProcessor>();
|
|
|
|
args.fVaryingHandler->emitAttributes(proc);
|
2019-06-19 18:19:47 +00:00
|
|
|
gpArgs->fPositionVar.set(kFloat2_GrSLType, "position");
|
2018-07-27 18:38:35 +00:00
|
|
|
args.fFragBuilder->codeAppendf(
|
|
|
|
"%s = sk_Clockwise ? half4(0,1,0,1) : half4(1,0,0,1);", args.fOutputColor);
|
2019-11-18 16:19:51 +00:00
|
|
|
if (!proc.readSkFragCoord()) {
|
2018-07-27 18:38:35 +00:00
|
|
|
args.fFragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);
|
|
|
|
} else {
|
|
|
|
// Verify layout(origin_upper_left) on gl_FragCoord does not affect gl_FrontFacing.
|
2019-02-05 22:17:40 +00:00
|
|
|
args.fFragBuilder->codeAppendf("%s = half4(min(half(sk_FragCoord.y), 1));",
|
2018-07-27 18:38:35 +00:00
|
|
|
args.fOutputCoverage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
GrGLSLPrimitiveProcessor* ClockwiseTestProcessor::createGLSLInstance(
|
|
|
|
const GrShaderCaps&) const {
|
|
|
|
return new GLSLClockwiseTestProcessor;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Draw Op.
|
|
|
|
|
|
|
|
class ClockwiseTestOp : public GrDrawOp {
|
|
|
|
public:
|
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
2019-02-15 16:33:22 +00:00
|
|
|
static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
|
|
|
|
bool readSkFragCoord, int y = 0) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrOpMemoryPool* pool = context->priv().opMemoryPool();
|
2018-07-27 18:38:35 +00:00
|
|
|
return pool->allocate<ClockwiseTestOp>(readSkFragCoord, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ClockwiseTestOp(bool readSkFragCoord, float y)
|
2019-11-18 16:19:51 +00:00
|
|
|
: GrDrawOp(ClassID())
|
|
|
|
, fReadSkFragCoord(readSkFragCoord)
|
|
|
|
, fY(y) {
|
2019-10-01 19:14:44 +00:00
|
|
|
this->setBounds(SkRect::MakeXYWH(0, fY, 100, 100), HasAABloat::kNo, IsHairline::kNo);
|
2018-07-27 18:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* name() const override { return "ClockwiseTestOp"; }
|
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
2019-06-24 00:07:38 +00:00
|
|
|
GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
|
|
|
|
bool hasMixedSampledCoverage, GrClampType) override {
|
2019-01-15 18:53:00 +00:00
|
|
|
return GrProcessorSet::EmptySetAnalysis();
|
2018-07-27 18:38:35 +00:00
|
|
|
}
|
2019-11-15 19:57:05 +00:00
|
|
|
|
|
|
|
void onPrePrepare(GrRecordingContext* context,
|
|
|
|
const GrSurfaceProxyView* dstView,
|
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-15 22:28:37 +00:00
|
|
|
SkArenaAlloc* arena = context->priv().recordTimeAllocator();
|
2019-11-15 19:57:05 +00:00
|
|
|
|
2019-11-21 21:02:34 +00:00
|
|
|
// This is equivalent to a GrOpFlushState::detachAppliedClip
|
|
|
|
GrAppliedClip appliedClip = clip ? std::move(*clip) : GrAppliedClip();
|
|
|
|
|
|
|
|
GrGeometryProcessor* geomProc = ClockwiseTestProcessor::Make(arena, fReadSkFragCoord);
|
|
|
|
|
|
|
|
// TODO: need to also give this to the recording context
|
|
|
|
fProgramInfo = sk_gpu_test::CreateProgramInfo(context->priv().caps(), arena, dstView,
|
|
|
|
std::move(appliedClip), dstProxyView,
|
|
|
|
geomProc, SkBlendMode::kPlus,
|
|
|
|
GrPrimitiveType::kTriangleStrip);
|
2019-11-15 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 17:23:23 +00:00
|
|
|
void onPrepare(GrOpFlushState* flushState) override {
|
2018-07-27 18:38:35 +00:00
|
|
|
SkPoint vertices[4] = {
|
|
|
|
{100, fY},
|
|
|
|
{0, fY+100},
|
|
|
|
{0, fY},
|
|
|
|
{100, fY+100},
|
|
|
|
};
|
2019-09-05 17:23:23 +00:00
|
|
|
fVertexBuffer = flushState->resourceProvider()->createBuffer(
|
|
|
|
sizeof(vertices), GrGpuBufferType::kVertex, kStatic_GrAccessPattern, vertices);
|
|
|
|
}
|
2019-11-15 19:57:05 +00:00
|
|
|
|
2019-09-05 17:23:23 +00:00
|
|
|
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
|
|
|
|
if (!fVertexBuffer) {
|
2018-07-27 20:15:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-11-15 19:57:05 +00:00
|
|
|
|
2019-11-21 21:02:34 +00:00
|
|
|
if (!fProgramInfo) {
|
|
|
|
GrGeometryProcessor* geomProc = ClockwiseTestProcessor::Make(flushState->allocator(),
|
|
|
|
fReadSkFragCoord);
|
|
|
|
|
|
|
|
fProgramInfo = sk_gpu_test::CreateProgramInfo(&flushState->caps(),
|
|
|
|
flushState->allocator(),
|
|
|
|
flushState->view(),
|
|
|
|
flushState->detachAppliedClip(),
|
|
|
|
flushState->dstProxyView(),
|
|
|
|
geomProc, SkBlendMode::kPlus,
|
|
|
|
GrPrimitiveType::kTriangleStrip);
|
|
|
|
}
|
|
|
|
|
2018-07-27 18:38:35 +00:00
|
|
|
GrMesh mesh(GrPrimitiveType::kTriangleStrip);
|
|
|
|
mesh.setNonIndexedNonInstanced(4);
|
2019-09-05 17:23:23 +00:00
|
|
|
mesh.setVertexData(std::move(fVertexBuffer));
|
2019-10-08 16:32:56 +00:00
|
|
|
|
2019-11-21 21:02:34 +00:00
|
|
|
flushState->opsRenderPass()->draw(*fProgramInfo, &mesh, 1,
|
|
|
|
SkRect::MakeXYWH(0, fY, 100, 100));
|
2018-07-27 18:38:35 +00:00
|
|
|
}
|
|
|
|
|
2019-11-18 16:19:51 +00:00
|
|
|
sk_sp<GrBuffer> fVertexBuffer;
|
|
|
|
const bool fReadSkFragCoord;
|
|
|
|
const float fY;
|
2019-11-15 19:57:05 +00:00
|
|
|
|
2019-11-18 16:19:51 +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:19:51 +00:00
|
|
|
GrProgramInfo* fProgramInfo = nullptr;
|
2018-07-27 18:38:35 +00:00
|
|
|
|
|
|
|
friend class ::GrOpMemoryPool; // for ctor
|
2019-11-18 16:19:51 +00:00
|
|
|
|
|
|
|
typedef GrDrawOp INHERITED;
|
2018-07-27 18:38:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Test.
|
|
|
|
|
2019-02-07 22:23:36 +00:00
|
|
|
void ClockwiseGM::onDraw(GrContext* ctx, GrRenderTargetContext* rtc, SkCanvas* canvas) {
|
2018-11-05 20:06:26 +00:00
|
|
|
rtc->clear(nullptr, { 0, 0, 0, 1 }, GrRenderTargetContext::CanClearFullscreen::kYes);
|
2018-07-27 18:38:35 +00:00
|
|
|
|
|
|
|
// Draw the test directly to the frame buffer.
|
|
|
|
rtc->priv().testingOnly_addDrawOp(ClockwiseTestOp::Make(ctx, false, 0));
|
|
|
|
rtc->priv().testingOnly_addDrawOp(ClockwiseTestOp::Make(ctx, true, 100));
|
|
|
|
|
|
|
|
// Draw the test to an off-screen, top-down render target.
|
2019-10-15 18:01:49 +00:00
|
|
|
GrColorType rtcColorType = rtc->colorInfo().colorType();
|
2020-01-08 16:52:34 +00:00
|
|
|
if (auto topLeftRTC = GrRenderTargetContext::Make(
|
|
|
|
ctx, rtcColorType, nullptr, SkBackingFit::kExact, {100, 200}, 1,
|
|
|
|
GrMipMapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin, SkBudgeted::kYes,
|
|
|
|
nullptr)) {
|
2018-11-05 20:06:26 +00:00
|
|
|
topLeftRTC->clear(nullptr, SK_PMColor4fTRANSPARENT,
|
|
|
|
GrRenderTargetContext::CanClearFullscreen::kYes);
|
2018-07-27 18:38:35 +00:00
|
|
|
topLeftRTC->priv().testingOnly_addDrawOp(ClockwiseTestOp::Make(ctx, false, 0));
|
|
|
|
topLeftRTC->priv().testingOnly_addDrawOp(ClockwiseTestOp::Make(ctx, true, 100));
|
2020-01-30 19:55:05 +00:00
|
|
|
rtc->drawTexture(GrNoClip(), topLeftRTC->readSurfaceView(), rtc->colorInfo().alphaType(),
|
|
|
|
GrSamplerState::Filter::kNearest, SkBlendMode::kSrcOver, SK_PMColor4fWHITE,
|
|
|
|
{0, 0, 100, 200}, {100, 0, 200, 200}, GrAA::kNo, GrQuadAAFlags::kNone,
|
2018-07-27 18:38:35 +00:00
|
|
|
SkCanvas::SrcRectConstraint::kStrict_SrcRectConstraint, SkMatrix::I(),
|
2018-11-19 15:42:10 +00:00
|
|
|
nullptr);
|
2018-07-27 18:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the test to an off-screen, bottom-up render target.
|
2020-01-08 16:52:34 +00:00
|
|
|
if (auto topLeftRTC = GrRenderTargetContext::Make(
|
|
|
|
ctx, rtcColorType, nullptr, SkBackingFit::kExact, {100, 200}, 1,
|
|
|
|
GrMipMapped::kNo, GrProtected::kNo, kBottomLeft_GrSurfaceOrigin, SkBudgeted::kYes,
|
|
|
|
nullptr)) {
|
2018-11-05 20:06:26 +00:00
|
|
|
topLeftRTC->clear(nullptr, SK_PMColor4fTRANSPARENT,
|
|
|
|
GrRenderTargetContext::CanClearFullscreen::kYes);
|
2018-07-27 18:38:35 +00:00
|
|
|
topLeftRTC->priv().testingOnly_addDrawOp(ClockwiseTestOp::Make(ctx, false, 0));
|
|
|
|
topLeftRTC->priv().testingOnly_addDrawOp(ClockwiseTestOp::Make(ctx, true, 100));
|
2020-01-30 19:55:05 +00:00
|
|
|
rtc->drawTexture(GrNoClip(), topLeftRTC->readSurfaceView(), rtc->colorInfo().alphaType(),
|
|
|
|
GrSamplerState::Filter::kNearest, SkBlendMode::kSrcOver, SK_PMColor4fWHITE,
|
|
|
|
{0, 0, 100, 200}, {200, 0, 300, 200}, GrAA::kNo, GrQuadAAFlags::kNone,
|
2018-07-27 18:38:35 +00:00
|
|
|
SkCanvas::SrcRectConstraint::kStrict_SrcRectConstraint, SkMatrix::I(),
|
2018-11-19 15:42:10 +00:00
|
|
|
nullptr);
|
2018-07-27 18:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM( return new ClockwiseGM(); )
|
|
|
|
|
|
|
|
}
|