7c12e28cf4
This reverts commit074414fed5
. Reason for revert: updated to guard against nullptr before calling quickContains(rrect). Original change's description: > Revert "GrClips provided as pointers to GrRTC" > > This reverts commit226b689471
. > > Reason for revert: Breaks Android roller > > Original change's description: > > GrClips provided as pointers to GrRTC > > > > A null clip represents no high-level clipping is necessary (the implicit > > clip to the render target's logical dimensions is fine). > > > > This also removes GrNoClip and GrFixedClip::Disabled() since they are > > replaced with just nullptr. > > > > By allowing nullptr to represent no intended clipping, it makes it easier > > to require GrClip and GrAppliedClip objects to know about the dimensions > > of the device. If we required a non-null clip object to represent no > > clipping, we'd have to have an instance for each device based on its > > size and that just became cumbersome. > > > > Bug: skia:10205 > > Change-Id: Ie30cc71820b92d99356d393a4c98c8677082e761 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290539 > > 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: I42c4828bcf016ee3d30d5c20b771be96e125817b > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10205 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292856 > Reviewed-by: Weston Tracey <westont@google.com> > Commit-Queue: Weston Tracey <westont@google.com> TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com,westont@google.com # Not skipping CQ checks because this is a reland. Bug: skia:10205 Change-Id: I5715a4de3b7c8847b73020dc4937d3816d879803 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292876 Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
98 lines
3.7 KiB
C++
98 lines
3.7 KiB
C++
/*
|
|
* 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 "gm/gm.h"
|
|
#include "include/effects/SkGradientShader.h"
|
|
#include "src/core/SkMatrixProvider.h"
|
|
#include "src/gpu/GrBitmapTextureMaker.h"
|
|
#include "src/gpu/GrContextPriv.h"
|
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
|
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
|
#include "src/gpu/ops/GrFillRectOp.h"
|
|
#include "tools/Resources.h"
|
|
|
|
class SampleMatrixConstantEffect : public GrFragmentProcessor {
|
|
public:
|
|
static constexpr GrProcessor::ClassID CLASS_ID = (GrProcessor::ClassID) 1;
|
|
|
|
SampleMatrixConstantEffect(std::unique_ptr<GrFragmentProcessor> child)
|
|
: INHERITED(CLASS_ID, kNone_OptimizationFlags) {
|
|
child->setSampleMatrix(SkSL::SampleMatrix(SkSL::SampleMatrix::Kind::kVariable));
|
|
this->registerChildProcessor(std::move(child));
|
|
}
|
|
|
|
const char* name() const override { return "SampleMatrixConstantEffect"; }
|
|
|
|
std::unique_ptr<GrFragmentProcessor> clone() const override {
|
|
SkASSERT(false);
|
|
return nullptr;
|
|
}
|
|
|
|
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {
|
|
}
|
|
|
|
bool onIsEqual(const GrFragmentProcessor& that) const override {
|
|
return this == &that;
|
|
}
|
|
|
|
private:
|
|
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
|
typedef GrFragmentProcessor INHERITED;
|
|
};
|
|
|
|
class GLSLSampleMatrixConstantEffect : public GrGLSLFragmentProcessor {
|
|
void emitCode(EmitArgs& args) override {
|
|
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
|
SkString sample = this->invokeChildWithMatrix(0, args, "float3x3(0.5)");
|
|
fragBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, sample.c_str());
|
|
}
|
|
};
|
|
|
|
GrGLSLFragmentProcessor* SampleMatrixConstantEffect::onCreateGLSLInstance() const {
|
|
return new GLSLSampleMatrixConstantEffect();
|
|
}
|
|
|
|
|
|
DEF_SIMPLE_GPU_GM(sample_matrix_constant, ctx, rtCtx, canvas, 512, 256) {
|
|
{
|
|
SkRect bounds = SkRect::MakeIWH(256, 256);
|
|
SkBitmap bmp;
|
|
GetResourceAsBitmap("images/mandrill_256.png", &bmp);
|
|
GrBitmapTextureMaker maker(ctx, bmp, GrImageTexGenPolicy::kDraw);
|
|
auto view = maker.view(GrMipMapped::kNo);
|
|
std::unique_ptr<GrFragmentProcessor> imgFP =
|
|
GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix());
|
|
auto fp = std::unique_ptr<GrFragmentProcessor>(
|
|
new SampleMatrixConstantEffect(std::move(imgFP)));
|
|
|
|
GrPaint paint;
|
|
paint.addCoverageFragmentProcessor(std::move(fp));
|
|
rtCtx->drawRect(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(), bounds);
|
|
}
|
|
|
|
{
|
|
GrPaint paint;
|
|
SkRect bounds = SkRect::MakeLTRB(256, 0, 512, 256);
|
|
static constexpr SkColor colors[] = { 0xff00ff00, 0xffff00ff };
|
|
static constexpr SkScalar pos[] = { 0.0f, 1.0f };
|
|
const SkPoint pts[] = {{ 256, 0 }, { 512, 0 }};
|
|
|
|
auto shader = SkGradientShader::MakeLinear(pts, colors, pos,
|
|
SK_ARRAY_COUNT(colors),
|
|
SkTileMode::kRepeat);
|
|
SkMatrix matrix;
|
|
SkSimpleMatrixProvider matrixProvider(matrix);
|
|
GrColorInfo colorInfo;
|
|
GrFPArgs args(ctx, matrixProvider, kHigh_SkFilterQuality, &colorInfo);
|
|
std::unique_ptr<GrFragmentProcessor> gradientFP = as_SB(shader)->asFragmentProcessor(args);
|
|
auto fp = std::unique_ptr<GrFragmentProcessor>(
|
|
new SampleMatrixConstantEffect(std::move(gradientFP)));
|
|
paint.addCoverageFragmentProcessor(std::move(fp));
|
|
rtCtx->drawRect(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(), bounds);
|
|
}
|
|
}
|