Test texture domain effect with local matrix.
Add a common way to make rect op for testing that uses a GP with a local matrix. Change-Id: I958d1230bd5067b2e4b60fcd374e2f7718681e43 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/255782 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
parent
506ff4f82f
commit
e21af50dc6
2
BUILD.gn
2
BUILD.gn
@ -1321,6 +1321,8 @@ if (skia_enable_tools) {
|
|||||||
"tools/gpu/MemoryCache.h",
|
"tools/gpu/MemoryCache.h",
|
||||||
"tools/gpu/ProxyUtils.cpp",
|
"tools/gpu/ProxyUtils.cpp",
|
||||||
"tools/gpu/TestContext.cpp",
|
"tools/gpu/TestContext.cpp",
|
||||||
|
"tools/gpu/TestOps.cpp",
|
||||||
|
"tools/gpu/TestOps.h",
|
||||||
"tools/gpu/YUVUtils.cpp",
|
"tools/gpu/YUVUtils.cpp",
|
||||||
"tools/gpu/YUVUtils.h",
|
"tools/gpu/YUVUtils.h",
|
||||||
"tools/gpu/mock/MockTestContext.cpp",
|
"tools/gpu/mock/MockTestContext.cpp",
|
||||||
|
@ -7,6 +7,9 @@ This file includes a list of high level updates for each milestone release.
|
|||||||
Milestone 80
|
Milestone 80
|
||||||
|
|
||||||
<Insert new notes here- top is most recent.>
|
<Insert new notes here- top is most recent.>
|
||||||
|
* Added SkMatrix::MakeTrans(SkVector) and SkRect::makeOffset(SkVector).
|
||||||
|
https://review.skia.org/255782
|
||||||
|
|
||||||
* Added SkImageInfo::MakeA8(SkISize) and added optional color space parameter to
|
* Added SkImageInfo::MakeA8(SkISize) and added optional color space parameter to
|
||||||
SkImageInfo::MakeN32Premul(SkISize).
|
SkImageInfo::MakeN32Premul(SkISize).
|
||||||
|
|
||||||
|
@ -15,128 +15,26 @@
|
|||||||
#include "include/core/SkPath.h"
|
#include "include/core/SkPath.h"
|
||||||
#include "include/core/SkPoint.h"
|
#include "include/core/SkPoint.h"
|
||||||
#include "include/core/SkRect.h"
|
#include "include/core/SkRect.h"
|
||||||
#include "include/core/SkRefCnt.h"
|
|
||||||
#include "include/core/SkScalar.h"
|
#include "include/core/SkScalar.h"
|
||||||
#include "include/core/SkSize.h"
|
#include "include/core/SkSize.h"
|
||||||
#include "include/core/SkString.h"
|
#include "include/core/SkString.h"
|
||||||
#include "include/core/SkTypes.h"
|
|
||||||
#include "include/gpu/GrContext.h"
|
#include "include/gpu/GrContext.h"
|
||||||
#include "include/private/GrRecordingContext.h"
|
|
||||||
#include "include/private/GrSharedEnums.h"
|
#include "include/private/GrSharedEnums.h"
|
||||||
#include "include/private/GrTypesPriv.h"
|
#include "include/private/GrTypesPriv.h"
|
||||||
#include "include/private/SkColorData.h"
|
|
||||||
#include "src/core/SkPointPriv.h"
|
|
||||||
#include "src/core/SkTLList.h"
|
#include "src/core/SkTLList.h"
|
||||||
#include "src/gpu/GrCaps.h"
|
|
||||||
#include "src/gpu/GrDefaultGeoProcFactory.h"
|
|
||||||
#include "src/gpu/GrFragmentProcessor.h"
|
#include "src/gpu/GrFragmentProcessor.h"
|
||||||
#include "src/gpu/GrGeometryProcessor.h"
|
|
||||||
#include "src/gpu/GrMemoryPool.h"
|
|
||||||
#include "src/gpu/GrOpFlushState.h"
|
|
||||||
#include "src/gpu/GrPaint.h"
|
#include "src/gpu/GrPaint.h"
|
||||||
#include "src/gpu/GrProcessorAnalysis.h"
|
|
||||||
#include "src/gpu/GrProcessorSet.h"
|
|
||||||
#include "src/gpu/GrRecordingContextPriv.h"
|
|
||||||
#include "src/gpu/GrRenderTargetContext.h"
|
#include "src/gpu/GrRenderTargetContext.h"
|
||||||
#include "src/gpu/GrRenderTargetContextPriv.h"
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
||||||
#include "src/gpu/GrUserStencilSettings.h"
|
|
||||||
#include "src/gpu/effects/GrConvexPolyEffect.h"
|
#include "src/gpu/effects/GrConvexPolyEffect.h"
|
||||||
#include "src/gpu/effects/GrPorterDuffXferProcessor.h"
|
#include "tools/gpu/TestOps.h"
|
||||||
#include "src/gpu/ops/GrDrawOp.h"
|
|
||||||
#include "src/gpu/ops/GrMeshDrawOp.h"
|
|
||||||
#include "src/gpu/ops/GrOp.h"
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
class GrAppliedClip;
|
class GrAppliedClip;
|
||||||
|
|
||||||
/** outset rendered rect to visualize anti-aliased poly edges */
|
|
||||||
static SkRect outset(const SkRect& unsorted) {
|
|
||||||
SkRect r = unsorted;
|
|
||||||
r.outset(5.f, 5.f);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** sorts a rect */
|
|
||||||
static SkRect sorted_rect(const SkRect& unsorted) {
|
|
||||||
SkRect r = unsorted;
|
|
||||||
r.sort();
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace skiagm {
|
namespace skiagm {
|
||||||
class PolyBoundsOp : public GrMeshDrawOp {
|
|
||||||
public:
|
|
||||||
DEFINE_OP_CLASS_ID
|
|
||||||
|
|
||||||
static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
|
|
||||||
GrPaint&& paint,
|
|
||||||
const SkRect& rect) {
|
|
||||||
GrOpMemoryPool* pool = context->priv().opMemoryPool();
|
|
||||||
|
|
||||||
return pool->allocate<PolyBoundsOp>(std::move(paint), rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* name() const override { return "PolyBoundsOp"; }
|
|
||||||
|
|
||||||
void visitProxies(const VisitProxyFunc& func) const override {
|
|
||||||
fProcessors.visitProxies(func);
|
|
||||||
}
|
|
||||||
|
|
||||||
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
|
||||||
|
|
||||||
GrProcessorSet::Analysis finalize(
|
|
||||||
const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
|
|
||||||
GrClampType clampType) override {
|
|
||||||
return fProcessors.finalize(
|
|
||||||
fColor, GrProcessorAnalysisCoverage::kNone, clip, &GrUserStencilSettings::kUnused,
|
|
||||||
hasMixedSampledCoverage, caps, clampType, &fColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class ::GrOpMemoryPool; // for ctor
|
|
||||||
|
|
||||||
PolyBoundsOp(GrPaint&& paint, const SkRect& rect)
|
|
||||||
: INHERITED(ClassID())
|
|
||||||
, fColor(paint.getColor4f())
|
|
||||||
, fProcessors(std::move(paint))
|
|
||||||
, fRect(outset(rect)) {
|
|
||||||
this->setBounds(sorted_rect(fRect), HasAABloat::kNo, IsHairline::kNo);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onPrepareDraws(Target* target) override {
|
|
||||||
using namespace GrDefaultGeoProcFactory;
|
|
||||||
|
|
||||||
Color color(fColor);
|
|
||||||
GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Make(target->allocator(),
|
|
||||||
target->caps().shaderCaps(),
|
|
||||||
color,
|
|
||||||
Coverage::kSolid_Type,
|
|
||||||
LocalCoords::kUnused_Type,
|
|
||||||
SkMatrix::I());
|
|
||||||
|
|
||||||
SkASSERT(gp->vertexStride() == sizeof(SkPoint));
|
|
||||||
QuadHelper helper(target, sizeof(SkPoint), 1);
|
|
||||||
SkPoint* verts = reinterpret_cast<SkPoint*>(helper.vertices());
|
|
||||||
if (!verts) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SkPointPriv::SetRectTriStrip(verts, fRect, sizeof(SkPoint));
|
|
||||||
helper.recordDraw(target, gp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
|
|
||||||
flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, std::move(fProcessors));
|
|
||||||
}
|
|
||||||
|
|
||||||
SkPMColor4f fColor;
|
|
||||||
GrProcessorSet fProcessors;
|
|
||||||
SkRect fRect;
|
|
||||||
|
|
||||||
typedef GrMeshDrawOp INHERITED;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This GM directly exercises a GrProcessor that draws convex polygons.
|
* This GM directly exercises a GrProcessor that draws convex polygons.
|
||||||
@ -213,7 +111,9 @@ protected:
|
|||||||
void onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
|
void onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
|
||||||
SkCanvas* canvas) override {
|
SkCanvas* canvas) override {
|
||||||
SkScalar y = 0;
|
SkScalar y = 0;
|
||||||
constexpr SkScalar kDX = 12.f;
|
static constexpr SkScalar kDX = 12.f;
|
||||||
|
static constexpr SkScalar kOutset = 5.f;
|
||||||
|
|
||||||
for (PathList::Iter iter(fPaths, PathList::Iter::kHead_IterStart);
|
for (PathList::Iter iter(fPaths, PathList::Iter::kHead_IterStart);
|
||||||
iter.get();
|
iter.get();
|
||||||
iter.next()) {
|
iter.next()) {
|
||||||
@ -236,8 +136,8 @@ protected:
|
|||||||
grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
|
grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
|
||||||
grPaint.addCoverageFragmentProcessor(std::move(fp));
|
grPaint.addCoverageFragmentProcessor(std::move(fp));
|
||||||
|
|
||||||
std::unique_ptr<GrDrawOp> op =
|
auto rect = p.getBounds().makeOutset(kOutset, kOutset);
|
||||||
PolyBoundsOp::Make(context, std::move(grPaint), p.getBounds());
|
auto op = sk_gpu_test::test_ops::MakeRect(context, std::move(grPaint), rect);
|
||||||
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
||||||
|
|
||||||
x += SkScalarCeilToScalar(path->getBounds().width() + kDX);
|
x += SkScalarCeilToScalar(path->getBounds().width() + kDX);
|
||||||
@ -263,8 +163,7 @@ protected:
|
|||||||
SkScalar x = 0;
|
SkScalar x = 0;
|
||||||
|
|
||||||
for (int et = 0; et < kGrClipEdgeTypeCnt; ++et) {
|
for (int et = 0; et < kGrClipEdgeTypeCnt; ++et) {
|
||||||
SkRect rect = *iter.get();
|
SkRect rect = iter.get()->makeOffset(x, y);
|
||||||
rect.offset(x, y);
|
|
||||||
GrClipEdgeType edgeType = (GrClipEdgeType) et;
|
GrClipEdgeType edgeType = (GrClipEdgeType) et;
|
||||||
std::unique_ptr<GrFragmentProcessor> fp(GrConvexPolyEffect::Make(edgeType, rect));
|
std::unique_ptr<GrFragmentProcessor> fp(GrConvexPolyEffect::Make(edgeType, rect));
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
@ -276,8 +175,9 @@ protected:
|
|||||||
grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
|
grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
|
||||||
grPaint.addCoverageFragmentProcessor(std::move(fp));
|
grPaint.addCoverageFragmentProcessor(std::move(fp));
|
||||||
|
|
||||||
std::unique_ptr<GrDrawOp> op = PolyBoundsOp::Make(context, std::move(grPaint),
|
auto drawRect = rect.makeOutset(kOutset, kOutset);
|
||||||
rect);
|
auto op = sk_gpu_test::test_ops::MakeRect(context, std::move(grPaint), drawRect);
|
||||||
|
|
||||||
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
||||||
|
|
||||||
x += SkScalarCeilToScalar(rect.width() + kDX);
|
x += SkScalarCeilToScalar(rect.width() + kDX);
|
||||||
|
@ -9,36 +9,24 @@
|
|||||||
|
|
||||||
#include "gm/gm.h"
|
#include "gm/gm.h"
|
||||||
#include "include/core/SkBitmap.h"
|
#include "include/core/SkBitmap.h"
|
||||||
#include "include/core/SkBlendMode.h"
|
|
||||||
#include "include/core/SkCanvas.h"
|
#include "include/core/SkCanvas.h"
|
||||||
#include "include/core/SkColor.h"
|
#include "include/core/SkColor.h"
|
||||||
#include "include/core/SkMatrix.h"
|
#include "include/core/SkMatrix.h"
|
||||||
#include "include/core/SkPaint.h"
|
#include "include/core/SkPaint.h"
|
||||||
#include "include/core/SkRect.h"
|
#include "include/core/SkRect.h"
|
||||||
#include "include/core/SkRefCnt.h"
|
|
||||||
#include "include/core/SkScalar.h"
|
|
||||||
#include "include/core/SkShader.h"
|
|
||||||
#include "include/core/SkSize.h"
|
#include "include/core/SkSize.h"
|
||||||
#include "include/core/SkString.h"
|
#include "include/core/SkString.h"
|
||||||
#include "include/core/SkTypes.h"
|
|
||||||
#include "include/effects/SkGradientShader.h"
|
#include "include/effects/SkGradientShader.h"
|
||||||
#include "include/gpu/GrContext.h"
|
|
||||||
#include "include/gpu/GrTypes.h"
|
|
||||||
#include "include/private/GrTypesPriv.h"
|
#include "include/private/GrTypesPriv.h"
|
||||||
#include "include/private/SkTArray.h"
|
#include "include/private/SkTArray.h"
|
||||||
#include "src/gpu/GrCaps.h"
|
|
||||||
#include "src/gpu/GrContextPriv.h"
|
#include "src/gpu/GrContextPriv.h"
|
||||||
#include "src/gpu/GrFragmentProcessor.h"
|
|
||||||
#include "src/gpu/GrPaint.h"
|
|
||||||
#include "src/gpu/GrProxyProvider.h"
|
#include "src/gpu/GrProxyProvider.h"
|
||||||
#include "src/gpu/GrRenderTargetContext.h"
|
#include "src/gpu/GrRenderTargetContext.h"
|
||||||
#include "src/gpu/GrRenderTargetContextPriv.h"
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
||||||
#include "src/gpu/GrSamplerState.h"
|
#include "src/gpu/GrSamplerState.h"
|
||||||
#include "src/gpu/GrTextureProxy.h"
|
#include "src/gpu/GrTextureProxy.h"
|
||||||
#include "src/gpu/effects/GrPorterDuffXferProcessor.h"
|
|
||||||
#include "src/gpu/effects/GrTextureDomain.h"
|
#include "src/gpu/effects/GrTextureDomain.h"
|
||||||
#include "src/gpu/ops/GrDrawOp.h"
|
#include "tools/gpu/TestOps.h"
|
||||||
#include "src/gpu/ops/GrFillRectOp.h"
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@ -49,8 +37,7 @@ namespace skiagm {
|
|||||||
*/
|
*/
|
||||||
class TextureDomainEffect : public GpuGM {
|
class TextureDomainEffect : public GpuGM {
|
||||||
public:
|
public:
|
||||||
TextureDomainEffect(GrSamplerState::Filter filter)
|
TextureDomainEffect(GrSamplerState::Filter filter) : fFilter(filter) {
|
||||||
: fFilter(filter) {
|
|
||||||
this->setBGColor(0xFFFFFFFF);
|
this->setBGColor(0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,9 +53,9 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkISize onISize() override {
|
SkISize onISize() override {
|
||||||
const SkScalar canvasWidth = kDrawPad +
|
const SkScalar canvasWidth =
|
||||||
(kTargetWidth + 2 * kDrawPad) * GrTextureDomain::kModeCount +
|
kDrawPad + 2 * ((kTargetWidth + 2 * kDrawPad) * GrTextureDomain::kModeCount +
|
||||||
kTestPad * GrTextureDomain::kModeCount;
|
kTestPad * GrTextureDomain::kModeCount);
|
||||||
return SkISize::Make(SkScalarCeilToInt(canvasWidth), 800);
|
return SkISize::Make(SkScalarCeilToInt(canvasWidth), 800);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,8 +111,7 @@ protected:
|
|||||||
fBitmap.width() / 2 + 2, fBitmap.height() / 2 + 2),
|
fBitmap.width() / 2 + 2, fBitmap.height() / 2 + 2),
|
||||||
};
|
};
|
||||||
|
|
||||||
SkRect renderRect = SkRect::Make(fBitmap.bounds());
|
SkRect localRect = SkRect::Make(fBitmap.bounds()).makeOutset(kDrawPad, kDrawPad);
|
||||||
renderRect.outset(kDrawPad, kDrawPad);
|
|
||||||
|
|
||||||
SkScalar y = kDrawPad + kTestPad;
|
SkScalar y = kDrawPad + kTestPad;
|
||||||
for (int tm = 0; tm < textureMatrices.count(); ++tm) {
|
for (int tm = 0; tm < textureMatrices.count(); ++tm) {
|
||||||
@ -138,26 +124,34 @@ protected:
|
|||||||
// Repeat mode doesn't produce correct results with bilerp filtering
|
// Repeat mode doesn't produce correct results with bilerp filtering
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
auto ct = SkColorTypeToGrColorType(fBitmap.colorType());
|
||||||
GrPaint grPaint;
|
SkRect domainRect = GrTextureDomain::MakeTexelDomain(texelDomains[d], mode);
|
||||||
grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
|
auto fp1 = GrTextureDomainEffect::Make(
|
||||||
auto fp = GrTextureDomainEffect::Make(
|
proxy, ct, textureMatrices[tm], domainRect, mode, fFilter);
|
||||||
proxy, SkColorTypeToGrColorType(fBitmap.colorType()),
|
if (!fp1) {
|
||||||
textureMatrices[tm],
|
|
||||||
GrTextureDomain::MakeTexelDomain(texelDomains[d], mode),
|
|
||||||
mode, fFilter);
|
|
||||||
|
|
||||||
if (!fp) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const SkMatrix viewMatrix = SkMatrix::MakeTrans(x, y);
|
auto fp2 = fp1->clone();
|
||||||
grPaint.addColorFragmentProcessor(std::move(fp));
|
SkASSERT(fp2);
|
||||||
renderTargetContext->priv().testingOnly_addDrawOp(
|
auto drawRect = localRect.makeOffset(x, y);
|
||||||
GrFillRectOp::MakeNonAARect(context, std::move(grPaint),
|
if (auto op = sk_gpu_test::test_ops::MakeRect(
|
||||||
viewMatrix, renderRect));
|
context, std::move(fp1), drawRect, localRect)) {
|
||||||
x += renderRect.width() + kTestPad;
|
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
||||||
|
}
|
||||||
|
x += localRect.width() + kTestPad;
|
||||||
|
// Draw again with a translated local rect and compensating translate matrix.
|
||||||
|
drawRect = localRect.makeOffset(x, y);
|
||||||
|
static constexpr SkVector kT = {-100, 300};
|
||||||
|
if (auto op = sk_gpu_test::test_ops::MakeRect(context,
|
||||||
|
std::move(fp2),
|
||||||
|
drawRect,
|
||||||
|
localRect.makeOffset(kT),
|
||||||
|
SkMatrix::MakeTrans(-kT))) {
|
||||||
|
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
||||||
|
}
|
||||||
|
x += localRect.width() + kTestPad;
|
||||||
}
|
}
|
||||||
y += renderRect.height() + kTestPad;
|
y += localRect.height() + kTestPad;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return DrawResult::kOk;
|
return DrawResult::kOk;
|
||||||
|
@ -89,6 +89,17 @@ public:
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sets SkMatrix to translate by (t.x(), t.y()). Returned matrix is:
|
||||||
|
|
||||||
|
| 1 0 t.x() |
|
||||||
|
| 0 1 t.y() |
|
||||||
|
| 0 0 1 |
|
||||||
|
|
||||||
|
@param t translation vector
|
||||||
|
@return SkMatrix with translation
|
||||||
|
*/
|
||||||
|
static SkMatrix SK_WARN_UNUSED_RESULT MakeTrans(SkVector t) { return MakeTrans(t.x(), t.y()); }
|
||||||
|
|
||||||
/** Sets SkMatrix to:
|
/** Sets SkMatrix to:
|
||||||
|
|
||||||
| scaleX skewX transX |
|
| scaleX skewX transX |
|
||||||
|
@ -175,13 +175,13 @@ struct SK_API SkPoint {
|
|||||||
|
|
||||||
@return fX
|
@return fX
|
||||||
*/
|
*/
|
||||||
SkScalar x() const { return fX; }
|
constexpr SkScalar x() const { return fX; }
|
||||||
|
|
||||||
/** Returns y-axis value of SkPoint or vector.
|
/** Returns y-axis value of SkPoint or vector.
|
||||||
|
|
||||||
@return fY
|
@return fY
|
||||||
*/
|
*/
|
||||||
SkScalar y() const { return fY; }
|
constexpr SkScalar y() const { return fY; }
|
||||||
|
|
||||||
/** Returns true if fX and fY are both zero.
|
/** Returns true if fX and fY are both zero.
|
||||||
|
|
||||||
|
@ -956,10 +956,17 @@ struct SK_API SkRect {
|
|||||||
@param dy added to fTop and fBottom
|
@param dy added to fTop and fBottom
|
||||||
@return SkRect offset on axes, with original width and height
|
@return SkRect offset on axes, with original width and height
|
||||||
*/
|
*/
|
||||||
SkRect makeOffset(SkScalar dx, SkScalar dy) const {
|
constexpr SkRect makeOffset(SkScalar dx, SkScalar dy) const {
|
||||||
return MakeLTRB(fLeft + dx, fTop + dy, fRight + dx, fBottom + dy);
|
return MakeLTRB(fLeft + dx, fTop + dy, fRight + dx, fBottom + dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns SkRect offset by v.
|
||||||
|
|
||||||
|
@param v added to rect
|
||||||
|
@return SkRect offset on axes, with original width and height
|
||||||
|
*/
|
||||||
|
constexpr SkRect makeOffset(SkVector v) const { return this->makeOffset(v.x(), v.y()); }
|
||||||
|
|
||||||
/** Returns SkRect, inset by (dx, dy).
|
/** Returns SkRect, inset by (dx, dy).
|
||||||
|
|
||||||
If dx is negative, SkRect returned is wider.
|
If dx is negative, SkRect returned is wider.
|
||||||
|
@ -159,6 +159,7 @@ public:
|
|||||||
kFwidthSquircleTestProcessor_ClassID,
|
kFwidthSquircleTestProcessor_ClassID,
|
||||||
kSwizzleFragmentProcessor_ClassID,
|
kSwizzleFragmentProcessor_ClassID,
|
||||||
kTestFP_ClassID,
|
kTestFP_ClassID,
|
||||||
|
kTestRectOp_ClassID,
|
||||||
kFlatNormalsFP_ClassID,
|
kFlatNormalsFP_ClassID,
|
||||||
kMappedNormalsFP_ClassID,
|
kMappedNormalsFP_ClassID,
|
||||||
kLightingFP_ClassID,
|
kLightingFP_ClassID,
|
||||||
|
194
tools/gpu/TestOps.cpp
Normal file
194
tools/gpu/TestOps.cpp
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 Google LLC
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
|
* found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tools/gpu/TestOps.h"
|
||||||
|
|
||||||
|
#include "src/core/SkPointPriv.h"
|
||||||
|
#include "src/gpu/GrCaps.h"
|
||||||
|
#include "src/gpu/GrGeometryProcessor.h"
|
||||||
|
#include "src/gpu/GrMemoryPool.h"
|
||||||
|
#include "src/gpu/GrOpFlushState.h"
|
||||||
|
#include "src/gpu/GrVertexWriter.h"
|
||||||
|
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
||||||
|
#include "src/gpu/glsl/GrGLSLGeometryProcessor.h"
|
||||||
|
#include "src/gpu/glsl/GrGLSLVarying.h"
|
||||||
|
#include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class GP : public GrGeometryProcessor {
|
||||||
|
public:
|
||||||
|
GP(const SkMatrix& localMatrix, bool wideColor)
|
||||||
|
: GrGeometryProcessor(kTestRectOp_ClassID), fLocalMatrix(localMatrix) {
|
||||||
|
fInColor = MakeColorAttribute("color", wideColor);
|
||||||
|
this->setVertexAttributes(&fInPosition, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* name() const override { return "TestRectOp::GP"; }
|
||||||
|
|
||||||
|
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps& caps) const override;
|
||||||
|
|
||||||
|
void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
|
||||||
|
|
||||||
|
bool wideColor() const { return fInColor.cpuType() != kUByte4_norm_GrVertexAttribType; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Attribute fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
|
||||||
|
Attribute fInLocalCoords = {"inLocalCoords", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
|
||||||
|
Attribute fInColor;
|
||||||
|
SkMatrix fLocalMatrix;
|
||||||
|
};
|
||||||
|
|
||||||
|
GrGLSLPrimitiveProcessor* GP::createGLSLInstance(const GrShaderCaps& caps) const {
|
||||||
|
class GLSLGP : public GrGLSLGeometryProcessor {
|
||||||
|
void setData(const GrGLSLProgramDataManager& pdman,
|
||||||
|
const GrPrimitiveProcessor& pp,
|
||||||
|
FPCoordTransformIter&& iter) override {
|
||||||
|
const auto& gp = pp.cast<GP>();
|
||||||
|
this->setTransformDataHelper(gp.fLocalMatrix, pdman, &iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
|
||||||
|
const auto& gp = args.fGP.cast<GP>();
|
||||||
|
args.fVaryingHandler->emitAttributes(gp);
|
||||||
|
GrGLSLVarying colorVarying(kHalf4_GrSLType);
|
||||||
|
args.fVaryingHandler->addVarying("color", &colorVarying,
|
||||||
|
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
|
||||||
|
args.fVertBuilder->codeAppendf("%s = %s;", colorVarying.vsOut(), gp.fInColor.name());
|
||||||
|
args.fFragBuilder->codeAppendf("%s = %s;", args.fOutputColor, colorVarying.fsIn());
|
||||||
|
args.fFragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);
|
||||||
|
this->writeOutputPosition(args.fVertBuilder, gpArgs, gp.fInPosition.name());
|
||||||
|
this->emitTransforms(args.fVertBuilder, args.fVaryingHandler, args.fUniformHandler,
|
||||||
|
gp.fInLocalCoords.asShaderVar(), gp.fLocalMatrix,
|
||||||
|
args.fFPCoordTransformHandler);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return new GLSLGP();
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestRectOp final : public GrMeshDrawOp {
|
||||||
|
public:
|
||||||
|
static std::unique_ptr<GrDrawOp> Make(GrRecordingContext*,
|
||||||
|
GrPaint&&,
|
||||||
|
const SkRect& drawRect,
|
||||||
|
const SkRect& localRect,
|
||||||
|
const SkMatrix& localM);
|
||||||
|
|
||||||
|
const char* name() const override { return "TestRectOp"; }
|
||||||
|
|
||||||
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
||||||
|
|
||||||
|
GrProcessorSet::Analysis finalize(const GrCaps&,
|
||||||
|
const GrAppliedClip*,
|
||||||
|
bool hasMixedSampledCoverage,
|
||||||
|
GrClampType) override;
|
||||||
|
|
||||||
|
void visitProxies(const VisitProxyFunc& func) const override {
|
||||||
|
fProcessorSet.visitProxies(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
DEFINE_OP_CLASS_ID
|
||||||
|
|
||||||
|
TestRectOp(const GrCaps*,
|
||||||
|
GrPaint&&,
|
||||||
|
const SkRect& drawRect,
|
||||||
|
const SkRect& localRect,
|
||||||
|
const SkMatrix& localMatrix);
|
||||||
|
void onPrepareDraws(Target*) override;
|
||||||
|
void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
|
||||||
|
|
||||||
|
SkRect fDrawRect;
|
||||||
|
SkRect fLocalRect;
|
||||||
|
SkPMColor4f fColor;
|
||||||
|
GP fGP;
|
||||||
|
GrProcessorSet fProcessorSet;
|
||||||
|
|
||||||
|
friend class ::GrOpMemoryPool;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<GrDrawOp> TestRectOp::Make(GrRecordingContext* context,
|
||||||
|
GrPaint&& paint,
|
||||||
|
const SkRect& drawRect,
|
||||||
|
const SkRect& localRect,
|
||||||
|
const SkMatrix& localM) {
|
||||||
|
auto* pool = context->priv().opMemoryPool();
|
||||||
|
const auto* caps = context->priv().caps();
|
||||||
|
return pool->allocate<TestRectOp>(caps, std::move(paint), drawRect, localRect, localM);
|
||||||
|
}
|
||||||
|
|
||||||
|
GrProcessorSet::Analysis TestRectOp::finalize(const GrCaps& caps,
|
||||||
|
const GrAppliedClip* clip,
|
||||||
|
bool hasMixedSampledCoverage,
|
||||||
|
GrClampType clampType) {
|
||||||
|
return fProcessorSet.finalize(GrProcessorAnalysisColor::Opaque::kYes,
|
||||||
|
GrProcessorAnalysisCoverage::kSingleChannel, clip,
|
||||||
|
&GrUserStencilSettings::kUnused, hasMixedSampledCoverage, caps,
|
||||||
|
clampType, &fColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool use_wide_color(const GrPaint& paint, const GrCaps* caps) {
|
||||||
|
return !paint.getColor4f().fitsInBytes() && caps->halfFloatVertexAttributeSupport();
|
||||||
|
}
|
||||||
|
TestRectOp::TestRectOp(const GrCaps* caps,
|
||||||
|
GrPaint&& paint,
|
||||||
|
const SkRect& drawRect,
|
||||||
|
const SkRect& localRect,
|
||||||
|
const SkMatrix& localMatrix)
|
||||||
|
: GrMeshDrawOp(ClassID())
|
||||||
|
, fDrawRect(drawRect)
|
||||||
|
, fLocalRect(localRect)
|
||||||
|
, fColor(paint.getColor4f())
|
||||||
|
, fGP(localMatrix, use_wide_color(paint, caps))
|
||||||
|
, fProcessorSet(std::move(paint)) {
|
||||||
|
this->setBounds(drawRect.makeSorted(), HasAABloat::kNo, IsHairline::kNo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestRectOp::onPrepareDraws(Target* target) {
|
||||||
|
QuadHelper helper(target, fGP.vertexStride(), 1);
|
||||||
|
GrVertexWriter writer{helper.vertices()};
|
||||||
|
auto pos = GrVertexWriter::TriStripFromRect(fDrawRect);
|
||||||
|
auto local = GrVertexWriter::TriStripFromRect(fLocalRect);
|
||||||
|
GrVertexColor color(fColor, fGP.wideColor());
|
||||||
|
writer.writeQuad(pos, local, color);
|
||||||
|
helper.recordDraw(target, &fGP);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestRectOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) {
|
||||||
|
flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, std::move(fProcessorSet));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
namespace sk_gpu_test::test_ops {
|
||||||
|
|
||||||
|
std::unique_ptr<GrDrawOp> MakeRect(GrRecordingContext* context,
|
||||||
|
GrPaint&& paint,
|
||||||
|
const SkRect& drawRect,
|
||||||
|
const SkRect& localRect,
|
||||||
|
const SkMatrix& localM) {
|
||||||
|
return TestRectOp::Make(context, std::move(paint), drawRect, localRect, localM);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<GrDrawOp> MakeRect(GrRecordingContext* context,
|
||||||
|
std::unique_ptr<GrFragmentProcessor> fp,
|
||||||
|
const SkRect& drawRect,
|
||||||
|
const SkRect& localRect,
|
||||||
|
const SkMatrix& localM) {
|
||||||
|
GrPaint paint;
|
||||||
|
paint.addColorFragmentProcessor(std::move(fp));
|
||||||
|
return TestRectOp::Make(context, std::move(paint), drawRect, localRect, localM);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<GrDrawOp> MakeRect(GrRecordingContext* context,
|
||||||
|
GrPaint&& paint,
|
||||||
|
const SkRect& rect) {
|
||||||
|
return TestRectOp::Make(context, std::move(paint), rect, rect, SkMatrix::I());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sk_gpu_test::test_ops
|
50
tools/gpu/TestOps.h
Normal file
50
tools/gpu/TestOps.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 Google LLC
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
|
* found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TestRectOp_DEFINED
|
||||||
|
#define TestRectOp_DEFINED
|
||||||
|
|
||||||
|
#include "include/core/SkRefCnt.h"
|
||||||
|
#include "include/private/GrRecordingContext.h"
|
||||||
|
#include "src/gpu/GrRecordingContextPriv.h"
|
||||||
|
#include "src/gpu/ops/GrMeshDrawOp.h"
|
||||||
|
|
||||||
|
class GrPaint;
|
||||||
|
|
||||||
|
namespace sk_gpu_test::test_ops {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fully specified device space rect op. The test Op draws a rectangle with local coords and a
|
||||||
|
* local matrix. It is important to test effects in the presence of GP local matrices. Our standard
|
||||||
|
* rect drawing code doesn't exercise this because it applies any local matrix to pre-transformed
|
||||||
|
* local coord vertex attributes.
|
||||||
|
*/
|
||||||
|
std::unique_ptr<GrDrawOp> MakeRect(GrRecordingContext*,
|
||||||
|
GrPaint&&,
|
||||||
|
const SkRect& drawRect,
|
||||||
|
const SkRect& localRect,
|
||||||
|
const SkMatrix& localM = SkMatrix::I());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simpler version of MakeRect that takes a single color FP instead of a full paint. Uses
|
||||||
|
* SkBlendMode::kSrcOver.
|
||||||
|
*/
|
||||||
|
std::unique_ptr<GrDrawOp> MakeRect(GrRecordingContext*,
|
||||||
|
std::unique_ptr<GrFragmentProcessor>,
|
||||||
|
const SkRect& drawRect,
|
||||||
|
const SkRect& localRect,
|
||||||
|
const SkMatrix& localM = SkMatrix::I());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simpler version of MakeRect that uses the same rect as the device space rect to draw as well as
|
||||||
|
* the local rect. The local matrix is identity.
|
||||||
|
*/
|
||||||
|
std::unique_ptr<GrDrawOp> MakeRect(GrRecordingContext*, GrPaint&&, const SkRect& rect);
|
||||||
|
|
||||||
|
} // namespace sk_gpu_test::test_ops
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user