restore .clang-format

Cq-Include-Trybots: skia.primary:Housekeeper-PerCommit-CheckGeneratedFiles
Change-Id: I93f928c35b2369c9e496d4e887e8500970bea2ec
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/202359
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2019-03-21 08:18:24 -05:00 committed by Skia Commit-Bot
parent a02dd32dee
commit d6ab77a2e2
50 changed files with 793 additions and 1079 deletions

View File

@ -14,23 +14,23 @@ Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: false
BinPackArguments: false
BinPackParameters: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
@ -57,7 +57,7 @@ ContinuationIndentWidth: 8
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ExperimentalAutoDetectBinPacking: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^<.*\.h>'
@ -98,30 +98,30 @@ SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
Standard: Auto
TabWidth: 4
UseTab: Never
---
Language: ObjC
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: false
BinPackArguments: false
BinPackParameters: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
@ -148,7 +148,7 @@ ContinuationIndentWidth: 8
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ExperimentalAutoDetectBinPacking: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^<.*\.h>'
@ -193,3 +193,4 @@ Standard: Auto
TabWidth: 4
UseTab: Never
...

View File

@ -20,13 +20,13 @@ public:
GrGLSLAARectEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrAARectEffect& _outer = args.fFp.cast<GrAARectEffect>();
const GrAARectEffect& _outer = args.fFp.cast<GrAARectEffect>();
(void)_outer;
auto edgeType = _outer.edgeType();
(void)edgeType;
auto rect = _outer.rect();
(void)rect;
prevRect = float4(-1.0);
prevRect = float4(-1.0);
fRectUniformVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "rectUniform");
fragBuilder->codeAppendf(
@ -59,9 +59,9 @@ public:
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrAARectEffect& _outer = _proc.cast<GrAARectEffect>();
auto edgeType = _outer.edgeType();
const GrFragmentProcessor& _proc) override {
const GrAARectEffect& _outer = _proc.cast<GrAARectEffect>();
auto edgeType = _outer.edgeType();
(void)edgeType;
auto rect = _outer.rect();
(void)rect;
@ -74,23 +74,21 @@ private:
prevRect = newRect;
}
}
SkRect prevRect = float4(0);
SkRect prevRect = float4(0);
UniformHandle fRectUniformVar;
};
GrGLSLFragmentProcessor* GrAARectEffect::onCreateGLSLInstance() const {
return new GrGLSLAARectEffect();
}
void GrAARectEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrAARectEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->add32((int32_t)fEdgeType);
}
bool GrAARectEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrAARectEffect& that = other.cast<GrAARectEffect>();
(void)that;
if (fEdgeType != that.fEdgeType)
return false;
if (fRect != that.fRect)
return false;
if (fEdgeType != that.fEdgeType) return false;
if (fRect != that.fRect) return false;
return true;
}
GrAARectEffect::GrAARectEffect(const GrAARectEffect& src)
@ -103,7 +101,7 @@ std::unique_ptr<GrFragmentProcessor> GrAARectEffect::clone() const {
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrAARectEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrAARectEffect::TestCreate(GrProcessorTestData* d) {
SkRect rect = SkRect::MakeLTRB(d->fRandom->nextSScalar1(),
SkRect rect = SkRect::MakeLTRB(d->fRandom->nextSScalar1(),
d->fRandom->nextSScalar1(),
d->fRandom->nextSScalar1(),
d->fRandom->nextSScalar1());

View File

@ -15,14 +15,14 @@
#include "GrCoordTransform.h"
class GrAARectEffect : public GrFragmentProcessor {
public:
const GrClipEdgeType& edgeType() const { return fEdgeType; }
const SkRect& rect() const { return fRect; }
const GrClipEdgeType& edgeType() const { return fEdgeType; }
const SkRect& rect() const { return fRect; }
static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType edgeType, SkRect rect) {
return std::unique_ptr<GrFragmentProcessor>(new GrAARectEffect(edgeType, rect));
}
GrAARectEffect(const GrAARectEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "AARectEffect"; }
const char* name() const override { return "AARectEffect"; }
private:
GrAARectEffect(GrClipEdgeType edgeType, SkRect rect)
@ -34,8 +34,8 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
GrClipEdgeType fEdgeType;
SkRect fRect;
GrClipEdgeType fEdgeType;
SkRect fRect;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -29,7 +29,7 @@ class GrGLSLAlphaThresholdFragmentProcessor : public GrGLSLFragmentProcessor {
public:
GrGLSLAlphaThresholdFragmentProcessor() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrAlphaThresholdFragmentProcessor& _outer =
args.fFp.cast<GrAlphaThresholdFragmentProcessor>();
(void)_outer;
@ -37,10 +37,10 @@ public:
(void)innerThreshold;
auto outerThreshold = _outer.outerThreshold();
(void)outerThreshold;
fInnerThresholdVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf_GrSLType, "innerThreshold");
fOuterThresholdVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf_GrSLType, "outerThreshold");
fInnerThresholdVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kHalf_GrSLType, "innerThreshold");
fOuterThresholdVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kHalf_GrSLType, "outerThreshold");
SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fragBuilder->codeAppendf(
"half4 color = %s;\nhalf4 mask_color = texture(%s, %s).%s;\nif (mask_color.w < "
@ -57,13 +57,12 @@ public:
args.fUniformHandler->getUniformCStr(fOuterThresholdVar),
args.fUniformHandler->getUniformCStr(fInnerThresholdVar),
args.fUniformHandler->getUniformCStr(fInnerThresholdVar),
args.fUniformHandler->getUniformCStr(fInnerThresholdVar),
args.fOutputColor);
args.fUniformHandler->getUniformCStr(fInnerThresholdVar), args.fOutputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrAlphaThresholdFragmentProcessor& _outer =
_proc.cast<GrAlphaThresholdFragmentProcessor>();
{
@ -77,17 +76,14 @@ private:
GrGLSLFragmentProcessor* GrAlphaThresholdFragmentProcessor::onCreateGLSLInstance() const {
return new GrGLSLAlphaThresholdFragmentProcessor();
}
void GrAlphaThresholdFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrAlphaThresholdFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrAlphaThresholdFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const {
const GrAlphaThresholdFragmentProcessor& that = other.cast<GrAlphaThresholdFragmentProcessor>();
(void)that;
if (fMask != that.fMask)
return false;
if (fInnerThreshold != that.fInnerThreshold)
return false;
if (fOuterThreshold != that.fOuterThreshold)
return false;
if (fMask != that.fMask) return false;
if (fInnerThreshold != that.fInnerThreshold) return false;
if (fOuterThreshold != that.fOuterThreshold) return false;
return true;
}
GrAlphaThresholdFragmentProcessor::GrAlphaThresholdFragmentProcessor(
@ -113,16 +109,16 @@ std::unique_ptr<GrFragmentProcessor> GrAlphaThresholdFragmentProcessor::TestCrea
GrProcessorTestData* testData) {
sk_sp<GrTextureProxy> maskProxy = testData->textureProxy(GrProcessorUnitTest::kAlphaTextureIdx);
// Make the inner and outer thresholds be in (0, 1) exclusive and be sorted correctly.
float innerThresh = testData->fRandom->nextUScalar1() * .99f + 0.005f;
float outerThresh = testData->fRandom->nextUScalar1() * .99f + 0.005f;
const int kMaxWidth = 1000;
const int kMaxHeight = 1000;
uint32_t width = testData->fRandom->nextULessThan(kMaxWidth);
uint32_t height = testData->fRandom->nextULessThan(kMaxHeight);
uint32_t x = testData->fRandom->nextULessThan(kMaxWidth - width);
uint32_t y = testData->fRandom->nextULessThan(kMaxHeight - height);
SkIRect bounds = SkIRect::MakeXYWH(x, y, width, height);
return GrAlphaThresholdFragmentProcessor::Make(
std::move(maskProxy), innerThresh, outerThresh, bounds);
float innerThresh = testData->fRandom->nextUScalar1() * .99f + 0.005f;
float outerThresh = testData->fRandom->nextUScalar1() * .99f + 0.005f;
const int kMaxWidth = 1000;
const int kMaxHeight = 1000;
uint32_t width = testData->fRandom->nextULessThan(kMaxWidth);
uint32_t height = testData->fRandom->nextULessThan(kMaxHeight);
uint32_t x = testData->fRandom->nextULessThan(kMaxWidth - width);
uint32_t y = testData->fRandom->nextULessThan(kMaxHeight - height);
SkIRect bounds = SkIRect::MakeXYWH(x, y, width, height);
return GrAlphaThresholdFragmentProcessor::Make(std::move(maskProxy), innerThresh, outerThresh,
bounds);
}
#endif

View File

@ -16,13 +16,13 @@
class GrAlphaThresholdFragmentProcessor : public GrFragmentProcessor {
public:
inline OptimizationFlags optFlags(float outerThreshold);
float innerThreshold() const { return fInnerThreshold; }
float outerThreshold() const { return fOuterThreshold; }
float innerThreshold() const { return fInnerThreshold; }
float outerThreshold() const { return fOuterThreshold; }
static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> mask,
float innerThreshold,
float outerThreshold,
const SkIRect& bounds) {
float innerThreshold,
float outerThreshold,
const SkIRect& bounds) {
return std::unique_ptr<GrFragmentProcessor>(new GrAlphaThresholdFragmentProcessor(
mask, innerThreshold, outerThreshold, bounds));
}
@ -31,10 +31,8 @@ public:
const char* name() const override { return "AlphaThresholdFragmentProcessor"; }
private:
GrAlphaThresholdFragmentProcessor(sk_sp<GrTextureProxy> mask,
float innerThreshold,
float outerThreshold,
const SkIRect& bounds)
GrAlphaThresholdFragmentProcessor(sk_sp<GrTextureProxy> mask, float innerThreshold,
float outerThreshold, const SkIRect& bounds)
: INHERITED(kGrAlphaThresholdFragmentProcessor_ClassID, kNone_OptimizationFlags)
, fMask(std::move(mask))
, fInnerThreshold(innerThreshold)
@ -50,10 +48,10 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
const TextureSampler& onTextureSampler(int) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
TextureSampler fMask;
float fInnerThreshold;
float fOuterThreshold;
GrCoordTransform fMaskCoordTransform;
TextureSampler fMask;
float fInnerThreshold;
float fOuterThreshold;
GrCoordTransform fMaskCoordTransform;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,7 +19,7 @@ class GrGLSLBlurredEdgeFragmentProcessor : public GrGLSLFragmentProcessor {
public:
GrGLSLBlurredEdgeFragmentProcessor() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrBlurredEdgeFragmentProcessor& _outer =
args.fFp.cast<GrBlurredEdgeFragmentProcessor>();
(void)_outer;
@ -30,27 +30,24 @@ public:
"exp((-factor * factor) * 4.0) - 0.017999999999999999;\n break;\n case "
"1:\n factor = smoothstep(1.0, 0.0, factor);\n break;\n}\n%s = "
"half4(factor);\n",
args.fInputColor,
(int)_outer.mode(),
args.fOutputColor);
args.fInputColor, (int)_outer.mode(), args.fOutputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {}
const GrFragmentProcessor& _proc) override {}
};
GrGLSLFragmentProcessor* GrBlurredEdgeFragmentProcessor::onCreateGLSLInstance() const {
return new GrGLSLBlurredEdgeFragmentProcessor();
}
void GrBlurredEdgeFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrBlurredEdgeFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->add32((int32_t)fMode);
}
bool GrBlurredEdgeFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const {
const GrBlurredEdgeFragmentProcessor& that = other.cast<GrBlurredEdgeFragmentProcessor>();
(void)that;
if (fMode != that.fMode)
return false;
if (fMode != that.fMode) return false;
return true;
}
GrBlurredEdgeFragmentProcessor::GrBlurredEdgeFragmentProcessor(

View File

@ -16,7 +16,7 @@
class GrBlurredEdgeFragmentProcessor : public GrFragmentProcessor {
public:
enum class Mode { kGaussian = 0, kSmoothStep = 1 };
const Mode& mode() const { return fMode; }
const Mode& mode() const { return fMode; }
static std::unique_ptr<GrFragmentProcessor> Make(Mode mode) {
return std::unique_ptr<GrFragmentProcessor>(new GrBlurredEdgeFragmentProcessor(mode));
}
@ -32,7 +32,7 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
Mode fMode;
Mode fMode;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -16,8 +16,8 @@
// kernel values.
static float make_unnormalized_half_kernel(float* halfKernel, int halfKernelSize, float sigma) {
const float invSigma = 1.f / sigma;
const float b = -0.5f * invSigma * invSigma;
float tot = 0.0f;
const float b = -0.5f * invSigma * invSigma;
float tot = 0.0f;
// Compute half kernel values at half pixel steps out from the center.
float t = 0.5f;
for (int i = 0; i < halfKernelSize; ++i) {
@ -31,13 +31,11 @@ static float make_unnormalized_half_kernel(float* halfKernel, int halfKernelSize
// Create a Gaussian half-kernel (right side) and a summed area table given a sigma and number
// of discrete steps. The half kernel is normalized to sum to 0.5.
static void make_half_kernel_and_summed_table(float* halfKernel,
float* summedHalfKernel,
int halfKernelSize,
float sigma) {
static void make_half_kernel_and_summed_table(float* halfKernel, float* summedHalfKernel,
int halfKernelSize, float sigma) {
// The half kernel should sum to 0.5 not 1.0.
const float tot = 2.f * make_unnormalized_half_kernel(halfKernel, halfKernelSize, sigma);
float sum = 0.f;
float sum = 0.f;
for (int i = 0; i < halfKernelSize; ++i) {
halfKernel[i] /= tot;
sum += halfKernel[i];
@ -47,12 +45,8 @@ static void make_half_kernel_and_summed_table(float* halfKernel,
// Applies the 1D half kernel vertically at points along the x axis to a circle centered at the
// origin with radius circleR.
void apply_kernel_in_y(float* results,
int numSteps,
float firstX,
float circleR,
int halfKernelSize,
const float* summedHalfKernelTable) {
void apply_kernel_in_y(float* results, int numSteps, float firstX, float circleR,
int halfKernelSize, const float* summedHalfKernelTable) {
float x = firstX;
for (int i = 0; i < numSteps; ++i, x += 1.f) {
if (x < -circleR || x > circleR) {
@ -71,7 +65,7 @@ void apply_kernel_in_y(float* results,
results[i] = 0.5f;
} else {
float yFrac = y - yInt;
results[i] = (1.f - yFrac) * summedHalfKernelTable[yInt] +
results[i] = (1.f - yFrac) * summedHalfKernelTable[yInt] +
yFrac * summedHalfKernelTable[yInt + 1];
}
}
@ -81,10 +75,7 @@ void apply_kernel_in_y(float* results,
// This relies on having a half kernel computed for the Gaussian and a table of applications of
// the half kernel in y to columns at (evalX - halfKernel, evalX - halfKernel + 1, ..., evalX +
// halfKernel) passed in as yKernelEvaluations.
static uint8_t eval_at(float evalX,
float circleR,
const float* halfKernel,
int halfKernelSize,
static uint8_t eval_at(float evalX, float circleR, const float* halfKernel, int halfKernelSize,
const float* yKernelEvaluations) {
float acc = 0;
@ -115,10 +106,8 @@ static uint8_t eval_at(float evalX,
// the size of the profile being computed. Then for each of the n profile entries we walk out k
// steps in each horizontal direction multiplying the corresponding y evaluation by the half
// kernel entry and sum these values to compute the profile entry.
static void create_circle_profile(uint8_t* weights,
float sigma,
float circleR,
int profileTextureWidth) {
static void create_circle_profile(uint8_t* weights, float sigma, float circleR,
int profileTextureWidth) {
const int numSteps = profileTextureWidth;
// The full kernel is 6 sigmas wide.
@ -130,9 +119,9 @@ static void create_circle_profile(uint8_t* weights,
int numYSteps = numSteps + 2 * halfKernelSize;
SkAutoTArray<float> bulkAlloc(halfKernelSize + halfKernelSize + numYSteps);
float* halfKernel = bulkAlloc.get();
float* summedKernel = bulkAlloc.get() + halfKernelSize;
float* yEvals = bulkAlloc.get() + 2 * halfKernelSize;
float* halfKernel = bulkAlloc.get();
float* summedKernel = bulkAlloc.get() + halfKernelSize;
float* yEvals = bulkAlloc.get() + 2 * halfKernelSize;
make_half_kernel_and_summed_table(halfKernel, summedKernel, halfKernelSize, sigma);
float firstX = -halfKernelSize + 0.5f;
@ -140,7 +129,7 @@ static void create_circle_profile(uint8_t* weights,
for (int i = 0; i < numSteps - 1; ++i) {
float evalX = i + 0.5f;
weights[i] = eval_at(evalX, circleR, halfKernel, halfKernelSize, yEvals + i);
weights[i] = eval_at(evalX, circleR, halfKernel, halfKernelSize, yEvals + i);
}
// Ensure the tail of the Gaussian goes to zero.
weights[numSteps - 1] = 0;
@ -149,14 +138,14 @@ static void create_circle_profile(uint8_t* weights,
static void create_half_plane_profile(uint8_t* profile, int profileWidth) {
SkASSERT(!(profileWidth & 0x1));
// The full kernel is 6 sigmas wide.
float sigma = profileWidth / 6.f;
int halfKernelSize = profileWidth / 2;
float sigma = profileWidth / 6.f;
int halfKernelSize = profileWidth / 2;
SkAutoTArray<float> halfKernel(halfKernelSize);
// The half kernel should sum to 0.5.
const float tot = 2.f * make_unnormalized_half_kernel(halfKernel.get(), halfKernelSize, sigma);
float sum = 0.f;
float sum = 0.f;
// Populate the profile from the right edge to the middle.
for (int i = 0; i < halfKernelSize; ++i) {
halfKernel[halfKernelSize - i - 1] /= tot;
@ -174,10 +163,8 @@ static void create_half_plane_profile(uint8_t* profile, int profileWidth) {
}
static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvider,
const SkRect& circle,
float sigma,
float* solidRadius,
float* textureRadius) {
const SkRect& circle, float sigma,
float* solidRadius, float* textureRadius) {
float circleR = circle.width() / 2.0f;
if (circleR < SK_ScalarNearlyZero) {
return nullptr;
@ -190,14 +177,14 @@ static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvid
// Guassian and the profile texture is a just a Gaussian evaluation. However, we haven't yet
// implemented this latter optimization.
sigmaToCircleRRatio = SkTMin(sigmaToCircleRRatio, 8.f);
SkFixed sigmaToCircleRRatioFixed;
SkFixed sigmaToCircleRRatioFixed;
static const SkScalar kHalfPlaneThreshold = 0.1f;
bool useHalfPlaneApprox = false;
bool useHalfPlaneApprox = false;
if (sigmaToCircleRRatio <= kHalfPlaneThreshold) {
useHalfPlaneApprox = true;
useHalfPlaneApprox = true;
sigmaToCircleRRatioFixed = 0;
*solidRadius = circleR - 3 * sigma;
*textureRadius = 6 * sigma;
*solidRadius = circleR - 3 * sigma;
*textureRadius = 6 * sigma;
} else {
// Convert to fixed point for the key.
sigmaToCircleRRatioFixed = SkScalarToFixed(sigmaToCircleRRatio);
@ -205,14 +192,14 @@ static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvid
// shave off more than we do.
sigmaToCircleRRatioFixed &= ~0xff;
sigmaToCircleRRatio = SkFixedToScalar(sigmaToCircleRRatioFixed);
sigma = circleR * sigmaToCircleRRatio;
*solidRadius = 0;
*textureRadius = circleR + 3 * sigma;
sigma = circleR * sigmaToCircleRRatio;
*solidRadius = 0;
*textureRadius = circleR + 3 * sigma;
}
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 1, "1-D Circular Blur");
GrUniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 1, "1-D Circular Blur");
builder[0] = sigmaToCircleRRatioFixed;
builder.finish();
@ -231,15 +218,15 @@ static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvid
} else {
// Rescale params to the size of the texture we're creating.
SkScalar scale = kProfileTextureWidth / *textureRadius;
create_circle_profile(
bm.getAddr8(0, 0), sigma * scale, circleR * scale, kProfileTextureWidth);
create_circle_profile(bm.getAddr8(0, 0), sigma * scale, circleR * scale,
kProfileTextureWidth);
}
bm.setImmutable();
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bm);
blurProfile = proxyProvider->createTextureProxy(
std::move(image), kNone_GrSurfaceFlags, 1, SkBudgeted::kYes, SkBackingFit::kExact);
blurProfile = proxyProvider->createTextureProxy(std::move(image), kNone_GrSurfaceFlags, 1,
SkBudgeted::kYes, SkBackingFit::kExact);
if (!blurProfile) {
return nullptr;
}
@ -252,11 +239,9 @@ static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvid
}
std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::Make(
GrProxyProvider* proxyProvider,
const SkRect& circle,
float sigma) {
float solidRadius;
float textureRadius;
GrProxyProvider* proxyProvider, const SkRect& circle, float sigma) {
float solidRadius;
float textureRadius;
sk_sp<GrTextureProxy> profile(
create_profile_texture(proxyProvider, circle, sigma, &solidRadius, &textureRadius));
if (!profile) {
@ -275,7 +260,7 @@ class GrGLSLCircleBlurFragmentProcessor : public GrGLSLFragmentProcessor {
public:
GrGLSLCircleBlurFragmentProcessor() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrCircleBlurFragmentProcessor& _outer =
args.fFp.cast<GrCircleBlurFragmentProcessor>();
(void)_outer;
@ -285,8 +270,8 @@ public:
(void)textureRadius;
auto solidRadius = _outer.solidRadius();
(void)solidRadius;
fCircleDataVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf4_GrSLType, "circleData");
fCircleDataVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType,
"circleData");
fragBuilder->codeAppendf(
"half2 vec = half2(half((sk_FragCoord.x - float(%s.x)) * float(%s.w)), "
"half((sk_FragCoord.y - float(%s.y)) * float(%s.w)));\nhalf dist = length(vec) + "
@ -296,8 +281,7 @@ public:
args.fUniformHandler->getUniformCStr(fCircleDataVar),
args.fUniformHandler->getUniformCStr(fCircleDataVar),
args.fUniformHandler->getUniformCStr(fCircleDataVar),
args.fUniformHandler->getUniformCStr(fCircleDataVar),
args.fOutputColor,
args.fUniformHandler->getUniformCStr(fCircleDataVar), args.fOutputColor,
args.fInputColor,
fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
@ -305,24 +289,21 @@ public:
private:
void onSetData(const GrGLSLProgramDataManager& data,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrCircleBlurFragmentProcessor& _outer = _proc.cast<GrCircleBlurFragmentProcessor>();
auto circleRect = _outer.circleRect();
auto circleRect = _outer.circleRect();
(void)circleRect;
auto textureRadius = _outer.textureRadius();
(void)textureRadius;
auto solidRadius = _outer.solidRadius();
(void)solidRadius;
GrSurfaceProxy& blurProfileSamplerProxy = *_outer.textureSampler(0).proxy();
GrTexture& blurProfileSampler = *blurProfileSamplerProxy.peekTexture();
GrTexture& blurProfileSampler = *blurProfileSamplerProxy.peekTexture();
(void)blurProfileSampler;
UniformHandle& circleData = fCircleDataVar;
(void)circleData;
data.set4f(circleData,
circleRect.centerX(),
circleRect.centerY(),
solidRadius,
data.set4f(circleData, circleRect.centerX(), circleRect.centerY(), solidRadius,
1.f / textureRadius);
}
UniformHandle fCircleDataVar;
@ -330,19 +311,15 @@ private:
GrGLSLFragmentProcessor* GrCircleBlurFragmentProcessor::onCreateGLSLInstance() const {
return new GrGLSLCircleBlurFragmentProcessor();
}
void GrCircleBlurFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrCircleBlurFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrCircleBlurFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const {
const GrCircleBlurFragmentProcessor& that = other.cast<GrCircleBlurFragmentProcessor>();
(void)that;
if (fCircleRect != that.fCircleRect)
return false;
if (fTextureRadius != that.fTextureRadius)
return false;
if (fSolidRadius != that.fSolidRadius)
return false;
if (fBlurProfileSampler != that.fBlurProfileSampler)
return false;
if (fCircleRect != that.fCircleRect) return false;
if (fTextureRadius != that.fTextureRadius) return false;
if (fSolidRadius != that.fSolidRadius) return false;
if (fBlurProfileSampler != that.fBlurProfileSampler) return false;
return true;
}
GrCircleBlurFragmentProcessor::GrCircleBlurFragmentProcessor(
@ -365,9 +342,9 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::TestCreate(
GrProcessorTestData* testData) {
SkScalar wh = testData->fRandom->nextRangeScalar(100.f, 1000.f);
SkScalar sigma = testData->fRandom->nextRangeF(1.f, 10.f);
SkRect circle = SkRect::MakeWH(wh, wh);
SkScalar wh = testData->fRandom->nextRangeScalar(100.f, 1000.f);
SkScalar sigma = testData->fRandom->nextRangeF(1.f, 10.f);
SkRect circle = SkRect::MakeWH(wh, wh);
return GrCircleBlurFragmentProcessor::Make(testData->proxyProvider(), circle, sigma);
}
#endif

View File

@ -16,20 +16,17 @@
class GrCircleBlurFragmentProcessor : public GrFragmentProcessor {
public:
const SkRect& circleRect() const { return fCircleRect; }
float textureRadius() const { return fTextureRadius; }
float solidRadius() const { return fSolidRadius; }
float textureRadius() const { return fTextureRadius; }
float solidRadius() const { return fSolidRadius; }
static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider*,
const SkRect& circle,
float sigma);
static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider*, const SkRect& circle,
float sigma);
GrCircleBlurFragmentProcessor(const GrCircleBlurFragmentProcessor& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "CircleBlurFragmentProcessor"; }
private:
GrCircleBlurFragmentProcessor(SkRect circleRect,
float textureRadius,
float solidRadius,
GrCircleBlurFragmentProcessor(SkRect circleRect, float textureRadius, float solidRadius,
sk_sp<GrTextureProxy> blurProfileSampler)
: INHERITED(kGrCircleBlurFragmentProcessor_ClassID,
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)
@ -44,10 +41,10 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
const TextureSampler& onTextureSampler(int) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
SkRect fCircleRect;
float fTextureRadius;
float fSolidRadius;
TextureSampler fBlurProfileSampler;
SkRect fCircleRect;
float fTextureRadius;
float fSolidRadius;
TextureSampler fBlurProfileSampler;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -20,7 +20,7 @@ public:
GrGLSLCircleEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrCircleEffect& _outer = args.fFp.cast<GrCircleEffect>();
const GrCircleEffect& _outer = args.fFp.cast<GrCircleEffect>();
(void)_outer;
auto edgeType = _outer.edgeType();
(void)edgeType;
@ -38,27 +38,22 @@ public:
"sk_FragCoord.xy) * float(%s.w))) * float(%s.z));\n}\n@if ((%d == 1 || %d == 3) || "
"%d == 4) {\n d = clamp(d, 0.0, 1.0);\n} else {\n d = d > 0.5 ? 1.0 : "
"0.0;\n}\n%s = %s * d;\n",
prevRadius,
(int)_outer.edgeType(),
(int)_outer.edgeType(),
prevRadius, (int)_outer.edgeType(), (int)_outer.edgeType(),
args.fUniformHandler->getUniformCStr(fCircleVar),
args.fUniformHandler->getUniformCStr(fCircleVar),
args.fUniformHandler->getUniformCStr(fCircleVar),
args.fUniformHandler->getUniformCStr(fCircleVar),
args.fUniformHandler->getUniformCStr(fCircleVar),
args.fUniformHandler->getUniformCStr(fCircleVar),
(int)_outer.edgeType(),
(int)_outer.edgeType(),
(int)_outer.edgeType(),
args.fOutputColor,
args.fUniformHandler->getUniformCStr(fCircleVar), (int)_outer.edgeType(),
(int)_outer.edgeType(), (int)_outer.edgeType(), args.fOutputColor,
args.fInputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrCircleEffect& _outer = _proc.cast<GrCircleEffect>();
auto edgeType = _outer.edgeType();
const GrFragmentProcessor& _proc) override {
const GrCircleEffect& _outer = _proc.cast<GrCircleEffect>();
auto edgeType = _outer.edgeType();
(void)edgeType;
auto center = _outer.center();
(void)center;
@ -77,32 +72,29 @@ private:
} else {
effectiveRadius += 0.5f;
}
pdman.set4f(
circle, center.fX, center.fY, effectiveRadius, SkScalarInvert(effectiveRadius));
pdman.set4f(circle, center.fX, center.fY, effectiveRadius,
SkScalarInvert(effectiveRadius));
prevCenter = center;
prevRadius = radius;
}
}
SkPoint prevCenter = half2(0);
float prevRadius = 0;
SkPoint prevCenter = half2(0);
float prevRadius = 0;
UniformHandle fCircleVar;
};
GrGLSLFragmentProcessor* GrCircleEffect::onCreateGLSLInstance() const {
return new GrGLSLCircleEffect();
}
void GrCircleEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrCircleEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->add32((int32_t)fEdgeType);
}
bool GrCircleEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrCircleEffect& that = other.cast<GrCircleEffect>();
(void)that;
if (fEdgeType != that.fEdgeType)
return false;
if (fCenter != that.fCenter)
return false;
if (fRadius != that.fRadius)
return false;
if (fEdgeType != that.fEdgeType) return false;
if (fCenter != that.fCenter) return false;
if (fRadius != that.fRadius) return false;
return true;
}
GrCircleEffect::GrCircleEffect(const GrCircleEffect& src)
@ -117,9 +109,9 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrCircleEffect::TestCreate(GrProcessorTestData* testData) {
SkPoint center;
center.fX = testData->fRandom->nextRangeScalar(0.f, 1000.f);
center.fY = testData->fRandom->nextRangeScalar(0.f, 1000.f);
SkScalar radius = testData->fRandom->nextRangeF(1.f, 1000.f);
center.fX = testData->fRandom->nextRangeScalar(0.f, 1000.f);
center.fY = testData->fRandom->nextRangeScalar(0.f, 1000.f);
SkScalar radius = testData->fRandom->nextRangeF(1.f, 1000.f);
GrClipEdgeType et;
do {
et = (GrClipEdgeType)testData->fRandom->nextULessThan(kGrClipEdgeTypeCnt);

View File

@ -16,12 +16,11 @@
class GrCircleEffect : public GrFragmentProcessor {
public:
const GrClipEdgeType& edgeType() const { return fEdgeType; }
const SkPoint& center() const { return fCenter; }
float radius() const { return fRadius; }
const SkPoint& center() const { return fCenter; }
float radius() const { return fRadius; }
static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType edgeType,
SkPoint center,
float radius) {
static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType edgeType, SkPoint center,
float radius) {
// A radius below half causes the implicit insetting done by this processor to become
// inverted. We could handle this case by making the processor code more complicated.
if (radius < .5f && GrProcessorEdgeTypeIsInverseFill(edgeType)) {
@ -31,7 +30,7 @@ public:
}
GrCircleEffect(const GrCircleEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "CircleEffect"; }
const char* name() const override { return "CircleEffect"; }
private:
GrCircleEffect(GrClipEdgeType edgeType, SkPoint center, float radius)
@ -44,9 +43,9 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
GrClipEdgeType fEdgeType;
SkPoint fCenter;
float fRadius;
GrClipEdgeType fEdgeType;
SkPoint fCenter;
float fRadius;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,8 +19,8 @@ class GrGLSLConfigConversionEffect : public GrGLSLFragmentProcessor {
public:
GrGLSLConfigConversionEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrConfigConversionEffect& _outer = args.fFp.cast<GrConfigConversionEffect>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrConfigConversionEffect& _outer = args.fFp.cast<GrConfigConversionEffect>();
(void)_outer;
auto pmConversion = _outer.pmConversion();
(void)pmConversion;
@ -31,34 +31,26 @@ public:
"%s.xyz = floor((%s.xyz * %s.w) * 255.0 + 0.5) / 255.0;\n break;\n case "
"1:\n %s.xyz = %s.w <= 0.0 ? half3(0.0) : floor((%s.xyz / %s.w) * 255.0 + "
"0.5) / 255.0;\n break;\n}\n",
args.fOutputColor,
args.fInputColor,
(int)_outer.pmConversion(),
args.fOutputColor,
args.fOutputColor,
args.fOutputColor,
args.fOutputColor,
args.fOutputColor,
args.fOutputColor,
args.fOutputColor);
args.fOutputColor, args.fInputColor, (int)_outer.pmConversion(), args.fOutputColor,
args.fOutputColor, args.fOutputColor, args.fOutputColor, args.fOutputColor,
args.fOutputColor, args.fOutputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {}
const GrFragmentProcessor& _proc) override {}
};
GrGLSLFragmentProcessor* GrConfigConversionEffect::onCreateGLSLInstance() const {
return new GrGLSLConfigConversionEffect();
}
void GrConfigConversionEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrConfigConversionEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->add32((int32_t)fPmConversion);
}
bool GrConfigConversionEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrConfigConversionEffect& that = other.cast<GrConfigConversionEffect>();
(void)that;
if (fPmConversion != that.fPmConversion)
return false;
if (fPmConversion != that.fPmConversion) return false;
return true;
}
GrConfigConversionEffect::GrConfigConversionEffect(const GrConfigConversionEffect& src)

View File

@ -22,15 +22,15 @@
class GrConfigConversionEffect : public GrFragmentProcessor {
public:
static bool TestForPreservingPMConversions(GrContext* context) {
static constexpr int kSize = 256;
static constexpr GrPixelConfig kConfig = kRGBA_8888_GrPixelConfig;
static constexpr SkColorType kColorType = kRGBA_8888_SkColorType;
const GrBackendFormat format =
static constexpr int kSize = 256;
static constexpr GrPixelConfig kConfig = kRGBA_8888_GrPixelConfig;
static constexpr SkColorType kColorType = kRGBA_8888_SkColorType;
const GrBackendFormat format =
context->priv().caps()->getBackendFormatFromColorType(kColorType);
SkAutoTMalloc<uint32_t> data(kSize * kSize * 3);
uint32_t* srcData = data.get();
uint32_t* firstRead = data.get() + kSize * kSize;
uint32_t* secondRead = data.get() + 2 * kSize * kSize;
uint32_t* srcData = data.get();
uint32_t* firstRead = data.get() + kSize * kSize;
uint32_t* secondRead = data.get() + 2 * kSize * kSize;
// Fill with every possible premultiplied A, color channel value. There will be 256-y
// duplicate values in row y. We set r, g, and b to the same value since they are handled
@ -38,10 +38,10 @@ public:
for (int y = 0; y < kSize; ++y) {
for (int x = 0; x < kSize; ++x) {
uint8_t* color = reinterpret_cast<uint8_t*>(&srcData[kSize * y + x]);
color[3] = y;
color[2] = SkTMin(x, y);
color[1] = SkTMin(x, y);
color[0] = SkTMin(x, y);
color[3] = y;
color[2] = SkTMin(x, y);
color[1] = SkTMin(x, y);
color[0] = SkTMin(x, y);
}
}
memset(firstRead, 0, kSize * kSize * sizeof(uint32_t));
@ -82,9 +82,9 @@ public:
// from readTex to tempTex followed by a PM->UPM draw to readTex and finally read the data.
// We then verify that two reads produced the same values.
GrPaint paint1;
GrPaint paint2;
GrPaint paint3;
GrPaint paint1;
GrPaint paint2;
GrPaint paint3;
std::unique_ptr<GrFragmentProcessor> pmToUPM(
new GrConfigConversionEffect(PMConversion::kToUnpremul));
std::unique_ptr<GrFragmentProcessor> upmToPM(
@ -94,8 +94,8 @@ public:
paint1.addColorFragmentProcessor(pmToUPM->clone());
paint1.setPorterDuffXPFactory(SkBlendMode::kSrc);
readRTC->fillRectToRect(
GrNoClip(), std::move(paint1), GrAA::kNo, SkMatrix::I(), kRect, kRect);
readRTC->fillRectToRect(GrNoClip(), std::move(paint1), GrAA::kNo, SkMatrix::I(), kRect,
kRect);
if (!readRTC->readPixels(ii, firstRead, 0, 0, 0)) {
return false;
}
@ -108,15 +108,15 @@ public:
paint2.addColorFragmentProcessor(std::move(upmToPM));
paint2.setPorterDuffXPFactory(SkBlendMode::kSrc);
tempRTC->fillRectToRect(
GrNoClip(), std::move(paint2), GrAA::kNo, SkMatrix::I(), kRect, kRect);
tempRTC->fillRectToRect(GrNoClip(), std::move(paint2), GrAA::kNo, SkMatrix::I(), kRect,
kRect);
paint3.addColorTextureProcessor(tempRTC->asTextureProxyRef(), SkMatrix::I());
paint3.addColorFragmentProcessor(std::move(pmToUPM));
paint3.setPorterDuffXPFactory(SkBlendMode::kSrc);
readRTC->fillRectToRect(
GrNoClip(), std::move(paint3), GrAA::kNo, SkMatrix::I(), kRect, kRect);
readRTC->fillRectToRect(GrNoClip(), std::move(paint3), GrAA::kNo, SkMatrix::I(), kRect,
kRect);
if (!readRTC->readPixels(ii, secondRead, 0, 0, 0)) {
return false;
@ -145,7 +145,7 @@ public:
}
GrConfigConversionEffect(const GrConfigConversionEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "ConfigConversionEffect"; }
const char* name() const override { return "ConfigConversionEffect"; }
private:
GrConfigConversionEffect(PMConversion pmConversion)
@ -155,7 +155,7 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
PMConversion fPmConversion;
PMConversion fPmConversion;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,8 +19,8 @@ class GrGLSLConstColorProcessor : public GrGLSLFragmentProcessor {
public:
GrGLSLConstColorProcessor() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrConstColorProcessor& _outer = args.fFp.cast<GrConstColorProcessor>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrConstColorProcessor& _outer = args.fFp.cast<GrConstColorProcessor>();
(void)_outer;
auto color = _outer.color();
(void)color;
@ -32,20 +32,16 @@ public:
"@switch (%d) {\n case 0:\n %s = %s;\n break;\n case 1:\n "
" %s = %s * %s;\n break;\n case 2:\n %s = %s.w * %s;\n "
"break;\n}\n",
(int)_outer.mode(),
args.fOutputColor,
args.fUniformHandler->getUniformCStr(fColorVar),
args.fOutputColor,
args.fInputColor,
args.fUniformHandler->getUniformCStr(fColorVar),
args.fOutputColor,
args.fInputColor,
(int)_outer.mode(), args.fOutputColor,
args.fUniformHandler->getUniformCStr(fColorVar), args.fOutputColor,
args.fInputColor, args.fUniformHandler->getUniformCStr(fColorVar),
args.fOutputColor, args.fInputColor,
args.fUniformHandler->getUniformCStr(fColorVar));
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrConstColorProcessor& _outer = _proc.cast<GrConstColorProcessor>();
{
const SkPMColor4f& colorValue = _outer.color();
@ -55,23 +51,21 @@ private:
}
}
}
SkPMColor4f fColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
UniformHandle fColorVar;
};
GrGLSLFragmentProcessor* GrConstColorProcessor::onCreateGLSLInstance() const {
return new GrGLSLConstColorProcessor();
}
void GrConstColorProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrConstColorProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->add32((int32_t)fMode);
}
bool GrConstColorProcessor::onIsEqual(const GrFragmentProcessor& other) const {
const GrConstColorProcessor& that = other.cast<GrConstColorProcessor>();
(void)that;
if (fColor != that.fColor)
return false;
if (fMode != that.fMode)
return false;
if (fColor != that.fColor) return false;
if (fMode != that.fMode) return false;
return true;
}
GrConstColorProcessor::GrConstColorProcessor(const GrConstColorProcessor& src)
@ -85,20 +79,22 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConstColorProcessor);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrConstColorProcessor::TestCreate(GrProcessorTestData* d) {
SkPMColor4f color;
int colorPicker = d->fRandom->nextULessThan(3);
int colorPicker = d->fRandom->nextULessThan(3);
switch (colorPicker) {
case 0: {
uint32_t a = d->fRandom->nextULessThan(0x100);
uint32_t r = d->fRandom->nextULessThan(a + 1);
uint32_t g = d->fRandom->nextULessThan(a + 1);
uint32_t b = d->fRandom->nextULessThan(a + 1);
color = SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(r, g, b, a));
color = SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(r, g, b, a));
break;
}
case 1: color = SK_PMColor4fTRANSPARENT; break;
case 1:
color = SK_PMColor4fTRANSPARENT;
break;
case 2:
uint32_t c = d->fRandom->nextULessThan(0x100);
color = SkPMColor4f::FromBytes_RGBA(c | (c << 8) | (c << 16) | (c << 24));
color = SkPMColor4f::FromBytes_RGBA(c | (c << 8) | (c << 16) | (c << 24));
break;
}
InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputModeCnt));

View File

@ -32,21 +32,24 @@ public:
SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override {
switch (fMode) {
case InputMode::kIgnore: return fColor;
case InputMode::kModulateA: return fColor * input.fA;
case InputMode::kModulateRGBA: return fColor * input;
case InputMode::kIgnore:
return fColor;
case InputMode::kModulateA:
return fColor * input.fA;
case InputMode::kModulateRGBA:
return fColor * input;
}
SK_ABORT("Unexpected mode");
return SK_PMColor4fTRANSPARENT;
}
const SkPMColor4f& color() const { return fColor; }
const InputMode& mode() const { return fMode; }
const SkPMColor4f& color() const { return fColor; }
const InputMode& mode() const { return fMode; }
static std::unique_ptr<GrFragmentProcessor> Make(SkPMColor4f color, InputMode mode) {
return std::unique_ptr<GrFragmentProcessor>(new GrConstColorProcessor(color, mode));
}
GrConstColorProcessor(const GrConstColorProcessor& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "ConstColorProcessor"; }
const char* name() const override { return "ConstColorProcessor"; }
private:
GrConstColorProcessor(SkPMColor4f color, InputMode mode)
@ -57,8 +60,8 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
SkPMColor4f fColor;
InputMode fMode;
SkPMColor4f fColor;
InputMode fMode;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -20,7 +20,7 @@ public:
GrGLSLEllipseEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrEllipseEffect& _outer = args.fFp.cast<GrEllipseEffect>();
const GrEllipseEffect& _outer = args.fFp.cast<GrEllipseEffect>();
(void)_outer;
auto edgeType = _outer.edgeType();
(void)edgeType;
@ -28,13 +28,13 @@ public:
(void)center;
auto radii = _outer.radii();
(void)radii;
prevRadii = float2(-1.0);
useScale = !sk_Caps.floatIs32Bits;
fEllipseVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "ellipse");
prevRadii = float2(-1.0);
useScale = !sk_Caps.floatIs32Bits;
fEllipseVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"ellipse");
if (useScale) {
fScaleVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat2_GrSLType, "scale");
fScaleVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat2_GrSLType,
"scale");
}
fragBuilder->codeAppendf(
"float2 prevCenter;\nfloat2 prevRadii = float2(%f, %f);\nbool useScale = "
@ -44,9 +44,7 @@ public:
"= implicit * inversesqrt(grad_dot);\n@if (useScale) {\n approx_dist *= "
"%s.x;\n}\nhalf alpha;\n@switch (%d) {\n case 0:\n alpha = approx_dist > "
"0.0 ? 0.0 : 1.0;\n break;\n case 1:\n alph",
prevRadii.fX,
prevRadii.fY,
(useScale ? "true" : "false"),
prevRadii.fX, prevRadii.fY, (useScale ? "true" : "false"),
args.fUniformHandler->getUniformCStr(fEllipseVar),
fScaleVar.isValid() ? args.fUniformHandler->getUniformCStr(fScaleVar) : "float2(0)",
args.fUniformHandler->getUniformCStr(fEllipseVar),
@ -57,15 +55,14 @@ public:
" alpha = approx_dist > 0.0 ? 1.0 : 0.0;\n break;\n case 3:\n "
"alpha = clamp(0.5 + half(approx_dist), 0.0, 1.0);\n break;\n default:\n "
" discard;\n}\n%s = %s * alpha;\n",
args.fOutputColor,
args.fInputColor);
args.fOutputColor, args.fInputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrEllipseEffect& _outer = _proc.cast<GrEllipseEffect>();
auto edgeType = _outer.edgeType();
const GrFragmentProcessor& _proc) override {
const GrEllipseEffect& _outer = _proc.cast<GrEllipseEffect>();
auto edgeType = _outer.edgeType();
(void)edgeType;
auto center = _outer.center();
(void)center;
@ -98,31 +95,28 @@ private:
}
pdman.set4f(ellipse, center.fX, center.fY, invRXSqd, invRYSqd);
prevCenter = center;
prevRadii = radii;
prevRadii = radii;
}
}
SkPoint prevCenter = float2(0);
SkPoint prevRadii = float2(0);
bool useScale = false;
SkPoint prevCenter = float2(0);
SkPoint prevRadii = float2(0);
bool useScale = false;
UniformHandle fEllipseVar;
UniformHandle fScaleVar;
};
GrGLSLFragmentProcessor* GrEllipseEffect::onCreateGLSLInstance() const {
return new GrGLSLEllipseEffect();
}
void GrEllipseEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrEllipseEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->add32((int32_t)fEdgeType);
}
bool GrEllipseEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrEllipseEffect& that = other.cast<GrEllipseEffect>();
(void)that;
if (fEdgeType != that.fEdgeType)
return false;
if (fCenter != that.fCenter)
return false;
if (fRadii != that.fRadii)
return false;
if (fEdgeType != that.fEdgeType) return false;
if (fCenter != that.fCenter) return false;
if (fRadii != that.fRadii) return false;
return true;
}
GrEllipseEffect::GrEllipseEffect(const GrEllipseEffect& src)
@ -137,15 +131,15 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrEllipseEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrEllipseEffect::TestCreate(GrProcessorTestData* testData) {
SkPoint center;
center.fX = testData->fRandom->nextRangeScalar(0.f, 1000.f);
center.fY = testData->fRandom->nextRangeScalar(0.f, 1000.f);
SkScalar rx = testData->fRandom->nextRangeF(0.f, 1000.f);
SkScalar ry = testData->fRandom->nextRangeF(0.f, 1000.f);
center.fX = testData->fRandom->nextRangeScalar(0.f, 1000.f);
center.fY = testData->fRandom->nextRangeScalar(0.f, 1000.f);
SkScalar rx = testData->fRandom->nextRangeF(0.f, 1000.f);
SkScalar ry = testData->fRandom->nextRangeF(0.f, 1000.f);
GrClipEdgeType et;
do {
et = (GrClipEdgeType)testData->fRandom->nextULessThan(kGrClipEdgeTypeCnt);
} while (GrClipEdgeType::kHairlineAA == et);
return GrEllipseEffect::Make(
et, center, SkPoint::Make(rx, ry), *testData->caps()->shaderCaps());
return GrEllipseEffect::Make(et, center, SkPoint::Make(rx, ry),
*testData->caps()->shaderCaps());
}
#endif

View File

@ -18,13 +18,11 @@
class GrEllipseEffect : public GrFragmentProcessor {
public:
const GrClipEdgeType& edgeType() const { return fEdgeType; }
const SkPoint& center() const { return fCenter; }
const SkPoint& radii() const { return fRadii; }
const SkPoint& center() const { return fCenter; }
const SkPoint& radii() const { return fRadii; }
static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType edgeType,
SkPoint center,
SkPoint radii,
const GrShaderCaps& caps) {
static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType edgeType, SkPoint center,
SkPoint radii, const GrShaderCaps& caps) {
// Small radii produce bad results on devices without full float.
if (!caps.floatIs32Bits() && (radii.fX < 0.5f || radii.fY < 0.5f)) {
return nullptr;
@ -33,7 +31,7 @@ public:
}
GrEllipseEffect(const GrEllipseEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "EllipseEffect"; }
const char* name() const override { return "EllipseEffect"; }
private:
GrEllipseEffect(GrClipEdgeType edgeType, SkPoint center, SkPoint radii)
@ -46,9 +44,9 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
GrClipEdgeType fEdgeType;
SkPoint fCenter;
SkPoint fRadii;
GrClipEdgeType fEdgeType;
SkPoint fCenter;
SkPoint fRadii;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,24 +19,23 @@ class GrGLSLLumaColorFilterEffect : public GrGLSLFragmentProcessor {
public:
GrGLSLLumaColorFilterEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrLumaColorFilterEffect& _outer = args.fFp.cast<GrLumaColorFilterEffect>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrLumaColorFilterEffect& _outer = args.fFp.cast<GrLumaColorFilterEffect>();
(void)_outer;
fragBuilder->codeAppendf(
"\nhalf luma = clamp(dot(half3(0.21260000000000001, 0.71519999999999995, 0.0722), "
"%s.xyz), 0.0, 1.0);\n%s = half4(0.0, 0.0, 0.0, luma);\n",
args.fInputColor,
args.fOutputColor);
args.fInputColor, args.fOutputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {}
const GrFragmentProcessor& _proc) override {}
};
GrGLSLFragmentProcessor* GrLumaColorFilterEffect::onCreateGLSLInstance() const {
return new GrGLSLLumaColorFilterEffect();
}
void GrLumaColorFilterEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrLumaColorFilterEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrLumaColorFilterEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrLumaColorFilterEffect& that = other.cast<GrLumaColorFilterEffect>();

View File

@ -27,7 +27,7 @@ public:
}
GrLumaColorFilterEffect(const GrLumaColorFilterEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "LumaColorFilterEffect"; }
const char* name() const override { return "LumaColorFilterEffect"; }
private:
GrLumaColorFilterEffect()

View File

@ -20,7 +20,7 @@ public:
GrGLSLMagnifierEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrMagnifierEffect& _outer = args.fFp.cast<GrMagnifierEffect>();
const GrMagnifierEffect& _outer = args.fFp.cast<GrMagnifierEffect>();
(void)_outer;
auto bounds = _outer.bounds();
(void)bounds;
@ -72,7 +72,7 @@ public:
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrMagnifierEffect& _outer = _proc.cast<GrMagnifierEffect>();
{
pdman.set1f(fXInvZoomVar, (_outer.xInvZoom()));
@ -81,7 +81,7 @@ private:
pdman.set1f(fYInvInsetVar, (_outer.yInvInset()));
}
GrSurfaceProxy& srcProxy = *_outer.textureSampler(0).proxy();
GrTexture& src = *srcProxy.peekTexture();
GrTexture& src = *srcProxy.peekTexture();
(void)src;
auto bounds = _outer.bounds();
(void)bounds;
@ -135,25 +135,18 @@ private:
GrGLSLFragmentProcessor* GrMagnifierEffect::onCreateGLSLInstance() const {
return new GrGLSLMagnifierEffect();
}
void GrMagnifierEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrMagnifierEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrMagnifierEffect& that = other.cast<GrMagnifierEffect>();
(void)that;
if (fSrc != that.fSrc)
return false;
if (fBounds != that.fBounds)
return false;
if (fSrcRect != that.fSrcRect)
return false;
if (fXInvZoom != that.fXInvZoom)
return false;
if (fYInvZoom != that.fYInvZoom)
return false;
if (fXInvInset != that.fXInvInset)
return false;
if (fYInvInset != that.fYInvInset)
return false;
if (fSrc != that.fSrc) return false;
if (fBounds != that.fBounds) return false;
if (fSrcRect != that.fSrcRect) return false;
if (fXInvZoom != that.fXInvZoom) return false;
if (fYInvZoom != that.fYInvZoom) return false;
if (fXInvInset != that.fXInvInset) return false;
if (fYInvInset != that.fYInvInset) return false;
return true;
}
GrMagnifierEffect::GrMagnifierEffect(const GrMagnifierEffect& src)
@ -178,16 +171,16 @@ const GrFragmentProcessor::TextureSampler& GrMagnifierEffect::onTextureSampler(i
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrMagnifierEffect::TestCreate(GrProcessorTestData* d) {
sk_sp<GrTextureProxy> proxy = d->textureProxy(0);
const int kMaxWidth = 200;
const int kMaxHeight = 200;
const SkScalar kMaxInset = 20.0f;
uint32_t width = d->fRandom->nextULessThan(kMaxWidth);
uint32_t height = d->fRandom->nextULessThan(kMaxHeight);
SkScalar inset = d->fRandom->nextRangeScalar(1.0f, kMaxInset);
sk_sp<GrTextureProxy> proxy = d->textureProxy(0);
const int kMaxWidth = 200;
const int kMaxHeight = 200;
const SkScalar kMaxInset = 20.0f;
uint32_t width = d->fRandom->nextULessThan(kMaxWidth);
uint32_t height = d->fRandom->nextULessThan(kMaxHeight);
SkScalar inset = d->fRandom->nextRangeScalar(1.0f, kMaxInset);
SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight));
SkRect srcRect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight));
SkRect srcRect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
auto effect = GrMagnifierEffect::Make(std::move(proxy),
bounds,

View File

@ -15,34 +15,25 @@
#include "GrCoordTransform.h"
class GrMagnifierEffect : public GrFragmentProcessor {
public:
const SkIRect& bounds() const { return fBounds; }
const SkRect& srcRect() const { return fSrcRect; }
float xInvZoom() const { return fXInvZoom; }
float yInvZoom() const { return fYInvZoom; }
float xInvInset() const { return fXInvInset; }
float yInvInset() const { return fYInvInset; }
static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> src,
SkIRect bounds,
SkRect srcRect,
float xInvZoom,
float yInvZoom,
float xInvInset,
float yInvInset) {
const SkIRect& bounds() const { return fBounds; }
const SkRect& srcRect() const { return fSrcRect; }
float xInvZoom() const { return fXInvZoom; }
float yInvZoom() const { return fYInvZoom; }
float xInvInset() const { return fXInvInset; }
float yInvInset() const { return fYInvInset; }
static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> src, SkIRect bounds,
SkRect srcRect, float xInvZoom, float yInvZoom,
float xInvInset, float yInvInset) {
return std::unique_ptr<GrFragmentProcessor>(new GrMagnifierEffect(
src, bounds, srcRect, xInvZoom, yInvZoom, xInvInset, yInvInset));
}
GrMagnifierEffect(const GrMagnifierEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "MagnifierEffect"; }
const char* name() const override { return "MagnifierEffect"; }
private:
GrMagnifierEffect(sk_sp<GrTextureProxy> src,
SkIRect bounds,
SkRect srcRect,
float xInvZoom,
float yInvZoom,
float xInvInset,
float yInvInset)
GrMagnifierEffect(sk_sp<GrTextureProxy> src, SkIRect bounds, SkRect srcRect, float xInvZoom,
float yInvZoom, float xInvInset, float yInvInset)
: INHERITED(kGrMagnifierEffect_ClassID, kNone_OptimizationFlags)
, fSrc(std::move(src))
, fBounds(bounds)
@ -60,14 +51,14 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
const TextureSampler& onTextureSampler(int) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
TextureSampler fSrc;
SkIRect fBounds;
SkRect fSrcRect;
float fXInvZoom;
float fYInvZoom;
float fXInvInset;
float fYInvInset;
GrCoordTransform fSrcCoordTransform;
TextureSampler fSrc;
SkIRect fBounds;
SkRect fSrcRect;
float fXInvZoom;
float fYInvZoom;
float fXInvInset;
float fYInvInset;
GrCoordTransform fSrcCoordTransform;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -20,7 +20,7 @@ public:
GrGLSLMixerEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrMixerEffect& _outer = args.fFp.cast<GrMixerEffect>();
const GrMixerEffect& _outer = args.fFp.cast<GrMixerEffect>();
(void)_outer;
auto weight = _outer.weight();
(void)weight;
@ -38,16 +38,14 @@ public:
fragBuilder->codeAppendf("half4 %s;", _child1.c_str());
}
fragBuilder->codeAppendf("\nhalf4 in1 = %s ? %s : %s;\n%s = mix(in0, in1, %s);\n",
_outer.fp1_index() >= 0 ? "true" : "false",
_child1.c_str(),
args.fInputColor,
args.fOutputColor,
_outer.fp1_index() >= 0 ? "true" : "false", _child1.c_str(),
args.fInputColor, args.fOutputColor,
args.fUniformHandler->getUniformCStr(fWeightVar));
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrMixerEffect& _outer = _proc.cast<GrMixerEffect>();
{ pdman.set1f(fWeightVar, (_outer.weight())); }
}
@ -56,13 +54,12 @@ private:
GrGLSLFragmentProcessor* GrMixerEffect::onCreateGLSLInstance() const {
return new GrGLSLMixerEffect();
}
void GrMixerEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrMixerEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrMixerEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrMixerEffect& that = other.cast<GrMixerEffect>();
(void)that;
if (fWeight != that.fWeight)
return false;
if (fWeight != that.fWeight) return false;
return true;
}
GrMixerEffect::GrMixerEffect(const GrMixerEffect& src)

View File

@ -45,28 +45,28 @@ public:
c1 = (this->numChildProcessors() > 1)
? ConstantOutputForConstantInput(this->childProcessor(1), input)
: input;
return {c0.fR + (c1.fR - c0.fR) * fWeight,
c0.fG + (c1.fG - c0.fG) * fWeight,
c0.fB + (c1.fB - c0.fB) * fWeight,
c0.fA + (c1.fA - c0.fA) * fWeight};
return {c0.fR + (c1.fR - c0.fR) * fWeight, c0.fG + (c1.fG - c0.fG) * fWeight,
c0.fB + (c1.fB - c0.fB) * fWeight, c0.fA + (c1.fA - c0.fA) * fWeight};
}
int fp0_index() const { return fFp0_index; }
int fp1_index() const { return fFp1_index; }
float weight() const { return fWeight; }
int fp0_index() const { return fFp0_index; }
int fp1_index() const { return fFp1_index; }
float weight() const { return fWeight; }
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp0,
std::unique_ptr<GrFragmentProcessor> fp1,
float weight) {
std::unique_ptr<GrFragmentProcessor>
fp1,
float weight) {
return std::unique_ptr<GrFragmentProcessor>(
new GrMixerEffect(std::move(fp0), std::move(fp1), weight));
}
GrMixerEffect(const GrMixerEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "MixerEffect"; }
const char* name() const override { return "MixerEffect"; }
private:
GrMixerEffect(std::unique_ptr<GrFragmentProcessor> fp0,
std::unique_ptr<GrFragmentProcessor> fp1,
float weight)
std::unique_ptr<GrFragmentProcessor>
fp1,
float weight)
: INHERITED(kGrMixerEffect_ClassID, (OptimizationFlags)OptFlags(fp0, fp1))
, fWeight(weight) {
SkASSERT(fp0);
@ -81,9 +81,9 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
int fFp0_index = -1;
int fFp1_index = -1;
float fWeight;
int fFp0_index = -1;
int fFp1_index = -1;
float fWeight;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,25 +19,22 @@ class GrGLSLPremulInputFragmentProcessor : public GrGLSLFragmentProcessor {
public:
GrGLSLPremulInputFragmentProcessor() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrPremulInputFragmentProcessor& _outer =
args.fFp.cast<GrPremulInputFragmentProcessor>();
(void)_outer;
fragBuilder->codeAppendf("%s = %s;\n%s.xyz *= %s.w;\n",
args.fOutputColor,
args.fInputColor,
args.fOutputColor,
args.fInputColor);
fragBuilder->codeAppendf("%s = %s;\n%s.xyz *= %s.w;\n", args.fOutputColor, args.fInputColor,
args.fOutputColor, args.fInputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {}
const GrFragmentProcessor& _proc) override {}
};
GrGLSLFragmentProcessor* GrPremulInputFragmentProcessor::onCreateGLSLInstance() const {
return new GrGLSLPremulInputFragmentProcessor();
}
void GrPremulInputFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrPremulInputFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrPremulInputFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const {
const GrPremulInputFragmentProcessor& that = other.cast<GrPremulInputFragmentProcessor>();

View File

@ -11,10 +11,10 @@
#include "GrRRectBlurEffect.h"
std::unique_ptr<GrFragmentProcessor> GrRRectBlurEffect::Make(GrRecordingContext* context,
float sigma,
float xformedSigma,
const SkRRect& srcRRect,
const SkRRect& devRRect) {
float sigma,
float xformedSigma,
const SkRRect& srcRRect,
const SkRRect& devRRect) {
SkASSERT(!SkRRectPriv::IsCircle(devRRect) &&
!devRRect.isRect()); // Should've been caught up-stream
@ -26,26 +26,15 @@ std::unique_ptr<GrFragmentProcessor> GrRRectBlurEffect::Make(GrRecordingContext*
// Make sure we can successfully ninepatch this rrect -- the blur sigma has to be
// sufficiently small relative to both the size of the corner radius and the
// width (and height) of the rrect.
SkRRect rrectToDraw;
SkISize size;
SkRRect rrectToDraw;
SkISize size;
SkScalar ignored[kSkBlurRRectMaxDivisions];
int ignoredSize;
int ignoredSize;
uint32_t ignored32;
bool ninePatchable = SkComputeBlurredRRectParams(srcRRect,
devRRect,
SkRect::MakeEmpty(),
sigma,
xformedSigma,
&rrectToDraw,
&size,
ignored,
ignored,
ignored,
ignored,
&ignoredSize,
&ignoredSize,
&ignored32);
bool ninePatchable = SkComputeBlurredRRectParams(
srcRRect, devRRect, SkRect::MakeEmpty(), sigma, xformedSigma, &rrectToDraw, &size,
ignored, ignored, ignored, ignored, &ignoredSize, &ignoredSize, &ignored32);
if (!ninePatchable) {
return nullptr;
}
@ -57,10 +46,8 @@ std::unique_ptr<GrFragmentProcessor> GrRRectBlurEffect::Make(GrRecordingContext*
}
return std::unique_ptr<GrFragmentProcessor>(
new GrRRectBlurEffect(xformedSigma,
devRRect.getBounds(),
SkRRectPriv::GetSimpleRadii(devRRect).fX,
std::move(mask)));
new GrRRectBlurEffect(xformedSigma, devRRect.getBounds(),
SkRRectPriv::GetSimpleRadii(devRRect).fX, std::move(mask)));
}
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
@ -73,7 +60,7 @@ public:
GrGLSLRRectBlurEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrRRectBlurEffect& _outer = args.fFp.cast<GrRRectBlurEffect>();
const GrRRectBlurEffect& _outer = args.fFp.cast<GrRRectBlurEffect>();
(void)_outer;
auto sigma = _outer.sigma();
(void)sigma;
@ -81,12 +68,12 @@ public:
(void)rect;
auto cornerRadius = _outer.cornerRadius();
(void)cornerRadius;
fCornerRadiusVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf_GrSLType, "cornerRadius");
fProxyRectVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "proxyRect");
fBlurRadiusVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf_GrSLType, "blurRadius");
fCornerRadiusVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
"cornerRadius");
fProxyRectVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"proxyRect");
fBlurRadiusVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
"blurRadius");
fragBuilder->codeAppendf(
"\nhalf2 translatedFragPos = half2(sk_FragCoord.xy - %s.xy);\nhalf threshold = %s "
"+ 2.0 * %s;\nhalf2 middle = half2((%s.zw - %s.xy) - float(2.0 * threshold));\nif "
@ -105,15 +92,14 @@ public:
"translatedFragPos.y -= middle.y - 1.0;\n}\nhalf2 proxyDims = half2(2.0 * "
"threshold + 1.0);\nhalf2 texCoord = translatedFragPos / proxyDims;\n%s = %s * "
"texture(%s, float2(texCoord)).%s;\n",
args.fOutputColor,
args.fInputColor,
args.fOutputColor, args.fInputColor,
fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrRRectBlurEffect& _outer = _proc.cast<GrRRectBlurEffect>();
{ pdman.set1f(fCornerRadiusVar, (_outer.cornerRadius())); }
auto sigma = _outer.sigma();
@ -123,7 +109,7 @@ private:
UniformHandle& cornerRadius = fCornerRadiusVar;
(void)cornerRadius;
GrSurfaceProxy& ninePatchSamplerProxy = *_outer.textureSampler(0).proxy();
GrTexture& ninePatchSampler = *ninePatchSamplerProxy.peekTexture();
GrTexture& ninePatchSampler = *ninePatchSamplerProxy.peekTexture();
(void)ninePatchSampler;
UniformHandle& proxyRect = fProxyRectVar;
(void)proxyRect;
@ -144,19 +130,15 @@ private:
GrGLSLFragmentProcessor* GrRRectBlurEffect::onCreateGLSLInstance() const {
return new GrGLSLRRectBlurEffect();
}
void GrRRectBlurEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrRRectBlurEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrRRectBlurEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrRRectBlurEffect& that = other.cast<GrRRectBlurEffect>();
(void)that;
if (fSigma != that.fSigma)
return false;
if (fRect != that.fRect)
return false;
if (fCornerRadius != that.fCornerRadius)
return false;
if (fNinePatchSampler != that.fNinePatchSampler)
return false;
if (fSigma != that.fSigma) return false;
if (fRect != that.fRect) return false;
if (fCornerRadius != that.fCornerRadius) return false;
if (fNinePatchSampler != that.fNinePatchSampler) return false;
return true;
}
GrRRectBlurEffect::GrRRectBlurEffect(const GrRRectBlurEffect& src)
@ -176,11 +158,11 @@ const GrFragmentProcessor::TextureSampler& GrRRectBlurEffect::onTextureSampler(i
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRRectBlurEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrRRectBlurEffect::TestCreate(GrProcessorTestData* d) {
SkScalar w = d->fRandom->nextRangeScalar(100.f, 1000.f);
SkScalar h = d->fRandom->nextRangeScalar(100.f, 1000.f);
SkScalar r = d->fRandom->nextRangeF(1.f, 9.f);
SkScalar w = d->fRandom->nextRangeScalar(100.f, 1000.f);
SkScalar h = d->fRandom->nextRangeScalar(100.f, 1000.f);
SkScalar r = d->fRandom->nextRangeF(1.f, 9.f);
SkScalar sigma = d->fRandom->nextRangeF(1.f, 10.f);
SkRRect rrect;
SkRRect rrect;
rrect.setRectXY(SkRect::MakeWH(w, h), r, r);
return GrRRectBlurEffect::Make(d->context(), sigma, sigma, rrect, rrect);
}

View File

@ -30,19 +30,17 @@
class GrRRectBlurEffect : public GrFragmentProcessor {
public:
static sk_sp<GrTextureProxy> find_or_create_rrect_blur_mask(GrRecordingContext* context,
const SkRRect& rrectToDraw,
const SkISize& size,
float xformedSigma) {
const SkRRect& rrectToDraw,
const SkISize& size,
float xformedSigma) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask");
GrUniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask");
builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f);
int index = 1;
for (auto c : {SkRRect::kUpperLeft_Corner,
SkRRect::kUpperRight_Corner,
SkRRect::kLowerRight_Corner,
SkRRect::kLowerLeft_Corner}) {
for (auto c : {SkRRect::kUpperLeft_Corner, SkRRect::kUpperRight_Corner,
SkRRect::kLowerRight_Corner, SkRRect::kLowerLeft_Corner}) {
SkASSERT(SkScalarIsInt(rrectToDraw.radii(c).fX) &&
SkScalarIsInt(rrectToDraw.radii(c).fY));
builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fX);
@ -60,26 +58,17 @@ public:
// TODO: this could be approx but the texture coords will need to be updated
sk_sp<GrRenderTargetContext> rtc(
context->priv().makeDeferredRenderTargetContextWithFallback(
format,
SkBackingFit::kExact,
size.fWidth,
size.fHeight,
kAlpha_8_GrPixelConfig,
nullptr));
format, SkBackingFit::kExact, size.fWidth, size.fHeight,
kAlpha_8_GrPixelConfig, nullptr));
if (!rtc) {
return nullptr;
}
GrPaint paint;
rtc->clear(nullptr,
SK_PMColor4fTRANSPARENT,
rtc->clear(nullptr, SK_PMColor4fTRANSPARENT,
GrRenderTargetContext::CanClearFullscreen::kYes);
rtc->drawRRect(GrNoClip(),
std::move(paint),
GrAA::kYes,
SkMatrix::I(),
rrectToDraw,
rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw,
GrStyle::SimpleFill());
sk_sp<GrTextureProxy> srcProxy(rtc->asTextureProxyRef());
@ -111,23 +100,21 @@ public:
return mask;
}
float sigma() const { return fSigma; }
float sigma() const { return fSigma; }
const SkRect& rect() const { return fRect; }
float cornerRadius() const { return fCornerRadius; }
float cornerRadius() const { return fCornerRadius; }
static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext* context,
float sigma,
float xformedSigma,
const SkRRect& srcRRect,
const SkRRect& devRRect);
float sigma,
float xformedSigma,
const SkRRect& srcRRect,
const SkRRect& devRRect);
GrRRectBlurEffect(const GrRRectBlurEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "RRectBlurEffect"; }
const char* name() const override { return "RRectBlurEffect"; }
private:
GrRRectBlurEffect(float sigma,
SkRect rect,
float cornerRadius,
GrRRectBlurEffect(float sigma, SkRect rect, float cornerRadius,
sk_sp<GrTextureProxy> ninePatchSampler)
: INHERITED(kGrRRectBlurEffect_ClassID,
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)
@ -142,10 +129,10 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
const TextureSampler& onTextureSampler(int) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
float fSigma;
SkRect fRect;
float fCornerRadius;
TextureSampler fNinePatchSampler;
float fSigma;
SkRect fRect;
float fCornerRadius;
TextureSampler fNinePatchSampler;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -20,7 +20,7 @@ public:
GrGLSLRectBlurEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrRectBlurEffect& _outer = args.fFp.cast<GrRectBlurEffect>();
const GrRectBlurEffect& _outer = args.fFp.cast<GrRectBlurEffect>();
(void)_outer;
auto rect = _outer.rect();
(void)rect;
@ -34,15 +34,15 @@ public:
fRectVar =
args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, "rect");
if (!highPrecision) {
fProxyRectHalfVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf4_GrSLType, "proxyRectHalf");
fProxyRectHalfVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kHalf4_GrSLType, "proxyRectHalf");
}
if (highPrecision) {
fProxyRectFloatVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "proxyRectFloat");
}
fProfileSizeVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf_GrSLType, "profileSize");
fProfileSizeVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
"profileSize");
fragBuilder->codeAppendf(
"/* key */ bool highPrecision = %s;\n@if (highPrecision) {\n float2 "
"translatedPos = sk_FragCoord.xy - %s.xy;\n float width = %s.z - %s.x;\n "
@ -51,8 +51,7 @@ public:
"1.0);\n float2 wh = smallDims - float2(center, center);\n half hcoord = "
"half((abs(translatedPos.x - 0.5 * width) - 0.5 * wh.x) / float(%s));\n half "
"hlookup = texture(%s, float2(float(hcoord), 0.5)).",
(highPrecision ? "true" : "false"),
args.fUniformHandler->getUniformCStr(fRectVar),
(highPrecision ? "true" : "false"), args.fUniformHandler->getUniformCStr(fRectVar),
args.fUniformHandler->getUniformCStr(fRectVar),
args.fUniformHandler->getUniformCStr(fRectVar),
args.fUniformHandler->getUniformCStr(fRectVar),
@ -74,9 +73,7 @@ public:
args.fUniformHandler->getUniformCStr(fProfileSizeVar),
fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(),
args.fOutputColor,
args.fInputColor,
args.fUniformHandler->getUniformCStr(fRectVar),
args.fOutputColor, args.fInputColor, args.fUniformHandler->getUniformCStr(fRectVar),
args.fUniformHandler->getUniformCStr(fRectVar),
args.fUniformHandler->getUniformCStr(fRectVar),
args.fUniformHandler->getUniformCStr(fRectVar),
@ -96,13 +93,12 @@ public:
args.fUniformHandler->getUniformCStr(fProfileSizeVar),
fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(),
args.fOutputColor,
args.fInputColor);
args.fOutputColor, args.fInputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrRectBlurEffect& _outer = _proc.cast<GrRectBlurEffect>();
{ pdman.set4fv(fRectVar, 1, reinterpret_cast<const float*>(&(_outer.rect()))); }
UniformHandle& rect = fRectVar;
@ -110,7 +106,7 @@ private:
auto sigma = _outer.sigma();
(void)sigma;
GrSurfaceProxy& blurProfileProxy = *_outer.textureSampler(0).proxy();
GrTexture& blurProfile = *blurProfileProxy.peekTexture();
GrTexture& blurProfile = *blurProfileProxy.peekTexture();
(void)blurProfile;
UniformHandle& proxyRectHalf = fProxyRectHalfVar;
(void)proxyRectHalf;
@ -121,7 +117,7 @@ private:
pdman.set1f(profileSize, SkScalarCeilToScalar(6 * sigma));
}
bool highPrecision = false;
bool highPrecision = false;
UniformHandle fProxyRectHalfVar;
UniformHandle fProxyRectFloatVar;
UniformHandle fProfileSizeVar;
@ -130,17 +126,14 @@ private:
GrGLSLFragmentProcessor* GrRectBlurEffect::onCreateGLSLInstance() const {
return new GrGLSLRectBlurEffect();
}
void GrRectBlurEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrRectBlurEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrRectBlurEffect& that = other.cast<GrRectBlurEffect>();
(void)that;
if (fRect != that.fRect)
return false;
if (fSigma != that.fSigma)
return false;
if (fBlurProfile != that.fBlurProfile)
return false;
if (fRect != that.fRect) return false;
if (fSigma != that.fSigma) return false;
if (fBlurProfile != that.fBlurProfile) return false;
return true;
}
GrRectBlurEffect::GrRectBlurEffect(const GrRectBlurEffect& src)
@ -159,12 +152,10 @@ const GrFragmentProcessor::TextureSampler& GrRectBlurEffect::onTextureSampler(in
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTestData* data) {
float sigma = data->fRandom->nextRangeF(3, 8);
float width = data->fRandom->nextRangeF(200, 300);
float sigma = data->fRandom->nextRangeF(3, 8);
float width = data->fRandom->nextRangeF(200, 300);
float height = data->fRandom->nextRangeF(200, 300);
return GrRectBlurEffect::Make(data->proxyProvider(),
*data->caps()->shaderCaps(),
SkRect::MakeWH(width, height),
sigma);
return GrRectBlurEffect::Make(data->proxyProvider(), *data->caps()->shaderCaps(),
SkRect::MakeWH(width, height), sigma);
}
#endif

View File

@ -21,12 +21,12 @@
class GrRectBlurEffect : public GrFragmentProcessor {
public:
static sk_sp<GrTextureProxy> CreateBlurProfileTexture(GrProxyProvider* proxyProvider,
float sigma) {
float sigma) {
unsigned int profileSize = SkScalarCeilToInt(6 * sigma);
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 1, "Rect Blur Mask");
GrUniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 1, "Rect Blur Mask");
builder[0] = profileSize;
builder.finish();
@ -48,11 +48,9 @@ public:
return nullptr;
}
blurProfile = proxyProvider->createTextureProxy(std::move(image),
kNone_GrSurfaceFlags,
1,
SkBudgeted::kYes,
SkBackingFit::kExact);
blurProfile =
proxyProvider->createTextureProxy(std::move(image), kNone_GrSurfaceFlags, 1,
SkBudgeted::kYes, SkBackingFit::kExact);
if (!blurProfile) {
return nullptr;
}
@ -64,12 +62,11 @@ public:
return blurProfile;
}
const SkRect& rect() const { return fRect; }
float sigma() const { return fSigma; }
float sigma() const { return fSigma; }
static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider* proxyProvider,
const GrShaderCaps& caps,
const SkRect& rect,
float sigma) {
static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider* proxyProvider,
const GrShaderCaps& caps, const SkRect& rect,
float sigma) {
if (!caps.floatIs32Bits()) {
// We promote the rect uniform from half to float when it has large values for
// precision. If we don't have full float then fail.
@ -93,20 +90,16 @@ public:
}
return std::unique_ptr<GrFragmentProcessor>(new GrRectBlurEffect(
rect,
sigma,
std::move(blurProfile),
rect, sigma, std::move(blurProfile),
GrSamplerState(GrSamplerState::WrapMode::kClamp, GrSamplerState::Filter::kBilerp)));
}
GrRectBlurEffect(const GrRectBlurEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "RectBlurEffect"; }
const char* name() const override { return "RectBlurEffect"; }
private:
GrRectBlurEffect(SkRect rect,
float sigma,
sk_sp<GrTextureProxy> blurProfile,
GrSamplerState samplerParams)
GrRectBlurEffect(SkRect rect, float sigma, sk_sp<GrTextureProxy> blurProfile,
GrSamplerState samplerParams)
: INHERITED(kGrRectBlurEffect_ClassID,
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)
, fRect(rect)
@ -119,9 +112,9 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
const TextureSampler& onTextureSampler(int) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
SkRect fRect;
float fSigma;
TextureSampler fBlurProfile;
SkRect fRect;
float fSigma;
TextureSampler fBlurProfile;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,16 +19,14 @@ class GrGLSLSimpleTextureEffect : public GrGLSLFragmentProcessor {
public:
GrGLSLSimpleTextureEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrSimpleTextureEffect& _outer = args.fFp.cast<GrSimpleTextureEffect>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrSimpleTextureEffect& _outer = args.fFp.cast<GrSimpleTextureEffect>();
(void)_outer;
auto matrix = _outer.matrix();
(void)matrix;
SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fragBuilder->codeAppendf(
"%s = %s * texture(%s, %s).%s;\n",
args.fOutputColor,
args.fInputColor,
"%s = %s * texture(%s, %s).%s;\n", args.fOutputColor, args.fInputColor,
fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
sk_TransformedCoords2D_0.c_str(),
fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
@ -36,20 +34,18 @@ public:
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {}
const GrFragmentProcessor& _proc) override {}
};
GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const {
return new GrGLSLSimpleTextureEffect();
}
void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>();
(void)that;
if (fImage != that.fImage)
return false;
if (fMatrix != that.fMatrix)
return false;
if (fImage != that.fImage) return false;
if (fMatrix != that.fMatrix) return false;
return true;
}
GrSimpleTextureEffect::GrSimpleTextureEffect(const GrSimpleTextureEffect& src)
@ -82,9 +78,9 @@ std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(
wrapModes[1] = GrSamplerState::WrapMode::kClamp;
}
GrSamplerState params(wrapModes,
testData->fRandom->nextBool() ? GrSamplerState::Filter::kBilerp
: GrSamplerState::Filter::kNearest);
GrSamplerState params(wrapModes, testData->fRandom->nextBool()
? GrSamplerState::Filter::kBilerp
: GrSamplerState::Filter::kNearest);
const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), matrix, params);

View File

@ -18,38 +18,35 @@ public:
const SkMatrix44& matrix() const { return fMatrix; }
static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
const SkMatrix& matrix) {
const SkMatrix& matrix) {
return std::unique_ptr<GrFragmentProcessor>(
new GrSimpleTextureEffect(std::move(proxy),
matrix,
new GrSimpleTextureEffect(std::move(proxy), matrix,
GrSamplerState(GrSamplerState::WrapMode::kClamp,
GrSamplerState::Filter::kNearest)));
}
/* clamp mode */
static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
const SkMatrix& matrix,
static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
const SkMatrix& matrix,
GrSamplerState::Filter filter) {
return std::unique_ptr<GrFragmentProcessor>(new GrSimpleTextureEffect(
std::move(proxy),
matrix,
std::move(proxy), matrix,
GrSamplerState(GrSamplerState::WrapMode::kClamp, filter)));
}
static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
const SkMatrix& matrix,
const SkMatrix& matrix,
const GrSamplerState& p) {
return std::unique_ptr<GrFragmentProcessor>(
new GrSimpleTextureEffect(std::move(proxy), matrix, p));
}
GrSimpleTextureEffect(const GrSimpleTextureEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "SimpleTextureEffect"; }
const char* name() const override { return "SimpleTextureEffect"; }
private:
GrSimpleTextureEffect(sk_sp<GrTextureProxy> image,
SkMatrix44 matrix,
GrSamplerState samplerParams)
GrSimpleTextureEffect(sk_sp<GrTextureProxy> image, SkMatrix44 matrix,
GrSamplerState samplerParams)
: INHERITED(kGrSimpleTextureEffect_ClassID,
(OptimizationFlags)ModulateForSamplerOptFlags(
image->config(),
@ -68,9 +65,9 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
const TextureSampler& onTextureSampler(int) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
TextureSampler fImage;
SkMatrix44 fMatrix;
GrCoordTransform fImageCoordTransform;
TextureSampler fImage;
SkMatrix44 fMatrix;
GrCoordTransform fImageCoordTransform;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,8 +19,8 @@ class GrGLSLClampedGradientEffect : public GrGLSLFragmentProcessor {
public:
GrGLSLClampedGradientEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrClampedGradientEffect& _outer = args.fFp.cast<GrClampedGradientEffect>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrClampedGradientEffect& _outer = args.fFp.cast<GrClampedGradientEffect>();
(void)_outer;
auto leftBorderColor = _outer.leftBorderColor();
(void)leftBorderColor;
@ -30,8 +30,8 @@ public:
(void)makePremul;
auto colorsAreOpaque = _outer.colorsAreOpaque();
(void)colorsAreOpaque;
fLeftBorderColorVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf4_GrSLType, "leftBorderColor");
fLeftBorderColorVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kHalf4_GrSLType, "leftBorderColor");
fRightBorderColorVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf4_GrSLType, "rightBorderColor");
SkString _child1("_child1");
@ -42,25 +42,21 @@ public:
_child1.c_str(),
(_outer.childProcessor(_outer.gradLayout_index()).preservesOpaqueInput() ? "true"
: "false"),
args.fOutputColor,
args.fOutputColor,
args.fUniformHandler->getUniformCStr(fLeftBorderColorVar),
args.fOutputColor,
args.fOutputColor, args.fOutputColor,
args.fUniformHandler->getUniformCStr(fLeftBorderColorVar), args.fOutputColor,
args.fUniformHandler->getUniformCStr(fRightBorderColorVar));
SkString _input0("t");
SkString _child0("_child0");
this->emitChild(_outer.colorizer_index(), _input0.c_str(), &_child0, args);
fragBuilder->codeAppendf("\n %s = %s;\n}\n@if (%s) {\n %s.xyz *= %s.w;\n}\n",
args.fOutputColor,
_child0.c_str(),
(_outer.makePremul() ? "true" : "false"),
args.fOutputColor,
args.fOutputColor, _child0.c_str(),
(_outer.makePremul() ? "true" : "false"), args.fOutputColor,
args.fOutputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrClampedGradientEffect& _outer = _proc.cast<GrClampedGradientEffect>();
{
const SkPMColor4f& leftBorderColorValue = _outer.leftBorderColor();
@ -75,29 +71,25 @@ private:
}
}
}
SkPMColor4f fLeftBorderColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fRightBorderColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fLeftBorderColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fRightBorderColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
UniformHandle fLeftBorderColorVar;
UniformHandle fRightBorderColorVar;
};
GrGLSLFragmentProcessor* GrClampedGradientEffect::onCreateGLSLInstance() const {
return new GrGLSLClampedGradientEffect();
}
void GrClampedGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrClampedGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->add32((int32_t)fMakePremul);
}
bool GrClampedGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrClampedGradientEffect& that = other.cast<GrClampedGradientEffect>();
(void)that;
if (fLeftBorderColor != that.fLeftBorderColor)
return false;
if (fRightBorderColor != that.fRightBorderColor)
return false;
if (fMakePremul != that.fMakePremul)
return false;
if (fColorsAreOpaque != that.fColorsAreOpaque)
return false;
if (fLeftBorderColor != that.fLeftBorderColor) return false;
if (fRightBorderColor != that.fRightBorderColor) return false;
if (fMakePremul != that.fMakePremul) return false;
if (fColorsAreOpaque != that.fColorsAreOpaque) return false;
return true;
}
GrClampedGradientEffect::GrClampedGradientEffect(const GrClampedGradientEffect& src)

View File

@ -15,38 +15,29 @@
#include "GrCoordTransform.h"
class GrClampedGradientEffect : public GrFragmentProcessor {
public:
int colorizer_index() const { return fColorizer_index; }
int gradLayout_index() const { return fGradLayout_index; }
int colorizer_index() const { return fColorizer_index; }
int gradLayout_index() const { return fGradLayout_index; }
const SkPMColor4f& leftBorderColor() const { return fLeftBorderColor; }
const SkPMColor4f& rightBorderColor() const { return fRightBorderColor; }
bool makePremul() const { return fMakePremul; }
bool colorsAreOpaque() const { return fColorsAreOpaque; }
bool makePremul() const { return fMakePremul; }
bool colorsAreOpaque() const { return fColorsAreOpaque; }
static std::unique_ptr<GrFragmentProcessor> Make(
std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
SkPMColor4f leftBorderColor,
SkPMColor4f rightBorderColor,
bool makePremul,
bool colorsAreOpaque) {
return std::unique_ptr<GrFragmentProcessor>(
new GrClampedGradientEffect(std::move(colorizer),
std::move(gradLayout),
leftBorderColor,
rightBorderColor,
makePremul,
colorsAreOpaque));
std::unique_ptr<GrFragmentProcessor> gradLayout, SkPMColor4f leftBorderColor,
SkPMColor4f rightBorderColor, bool makePremul, bool colorsAreOpaque) {
return std::unique_ptr<GrFragmentProcessor>(new GrClampedGradientEffect(
std::move(colorizer), std::move(gradLayout), leftBorderColor, rightBorderColor,
makePremul, colorsAreOpaque));
}
GrClampedGradientEffect(const GrClampedGradientEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "ClampedGradientEffect"; }
const char* name() const override { return "ClampedGradientEffect"; }
private:
GrClampedGradientEffect(std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
SkPMColor4f leftBorderColor,
SkPMColor4f rightBorderColor,
bool makePremul,
bool colorsAreOpaque)
SkPMColor4f leftBorderColor, SkPMColor4f rightBorderColor,
bool makePremul, bool colorsAreOpaque)
: INHERITED(kGrClampedGradientEffect_ClassID,
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag |
(colorsAreOpaque && gradLayout->preservesOpaqueInput()
@ -67,12 +58,12 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
int fColorizer_index = -1;
int fGradLayout_index = -1;
SkPMColor4f fLeftBorderColor;
SkPMColor4f fRightBorderColor;
bool fMakePremul;
bool fColorsAreOpaque;
int fColorizer_index = -1;
int fGradLayout_index = -1;
SkPMColor4f fLeftBorderColor;
SkPMColor4f fRightBorderColor;
bool fMakePremul;
bool fColorsAreOpaque;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,7 +19,7 @@ class GrGLSLDualIntervalGradientColorizer : public GrGLSLFragmentProcessor {
public:
GrGLSLDualIntervalGradientColorizer() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrDualIntervalGradientColorizer& _outer =
args.fFp.cast<GrDualIntervalGradientColorizer>();
(void)_outer;
@ -33,32 +33,30 @@ public:
(void)bias23;
auto threshold = _outer.threshold();
(void)threshold;
fScale01Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "scale01");
fBias01Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "bias01");
fScale23Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "scale23");
fBias23Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "bias23");
fThresholdVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf_GrSLType, "threshold");
fScale01Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"scale01");
fBias01Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias01");
fScale23Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"scale23");
fBias23Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias23");
fThresholdVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
"threshold");
fragBuilder->codeAppendf(
"half t = %s.x;\nfloat4 scale, bias;\nif (t < %s) {\n scale = %s;\n bias = "
"%s;\n} else {\n scale = %s;\n bias = %s;\n}\n%s = half4(float(t) * scale + "
"bias);\n",
args.fInputColor,
args.fUniformHandler->getUniformCStr(fThresholdVar),
args.fInputColor, args.fUniformHandler->getUniformCStr(fThresholdVar),
args.fUniformHandler->getUniformCStr(fScale01Var),
args.fUniformHandler->getUniformCStr(fBias01Var),
args.fUniformHandler->getUniformCStr(fScale23Var),
args.fUniformHandler->getUniformCStr(fBias23Var),
args.fOutputColor);
args.fUniformHandler->getUniformCStr(fBias23Var), args.fOutputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrDualIntervalGradientColorizer& _outer =
_proc.cast<GrDualIntervalGradientColorizer>();
{
@ -89,11 +87,11 @@ private:
}
}
}
SkPMColor4f fScale01Prev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fBias01Prev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fScale23Prev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fBias23Prev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
float fThresholdPrev = SK_FloatNaN;
SkPMColor4f fScale01Prev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fBias01Prev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fScale23Prev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fBias23Prev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
float fThresholdPrev = SK_FloatNaN;
UniformHandle fScale01Var;
UniformHandle fBias01Var;
UniformHandle fScale23Var;
@ -103,21 +101,16 @@ private:
GrGLSLFragmentProcessor* GrDualIntervalGradientColorizer::onCreateGLSLInstance() const {
return new GrGLSLDualIntervalGradientColorizer();
}
void GrDualIntervalGradientColorizer::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrDualIntervalGradientColorizer::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrDualIntervalGradientColorizer::onIsEqual(const GrFragmentProcessor& other) const {
const GrDualIntervalGradientColorizer& that = other.cast<GrDualIntervalGradientColorizer>();
(void)that;
if (fScale01 != that.fScale01)
return false;
if (fBias01 != that.fBias01)
return false;
if (fScale23 != that.fScale23)
return false;
if (fBias23 != that.fBias23)
return false;
if (fThreshold != that.fThreshold)
return false;
if (fScale01 != that.fScale01) return false;
if (fBias01 != that.fBias01) return false;
if (fScale23 != that.fScale23) return false;
if (fBias23 != that.fBias23) return false;
if (fThreshold != that.fThreshold) return false;
return true;
}
GrDualIntervalGradientColorizer::GrDualIntervalGradientColorizer(
@ -138,20 +131,18 @@ std::unique_ptr<GrFragmentProcessor> GrDualIntervalGradientColorizer::Make(const
const SkPMColor4f& c3,
float threshold) {
// Derive scale and biases from the 4 colors and threshold
auto vc0 = Sk4f::Load(c0.vec());
auto vc1 = Sk4f::Load(c1.vec());
auto vc0 = Sk4f::Load(c0.vec());
auto vc1 = Sk4f::Load(c1.vec());
auto scale01 = (vc1 - vc0) / threshold;
// bias01 = c0
auto vc2 = Sk4f::Load(c2.vec());
auto vc3 = Sk4f::Load(c3.vec());
auto vc2 = Sk4f::Load(c2.vec());
auto vc3 = Sk4f::Load(c3.vec());
auto scale23 = (vc3 - vc2) / (1 - threshold);
auto bias23 = vc2 - threshold * scale23;
auto bias23 = vc2 - threshold * scale23;
return std::unique_ptr<GrFragmentProcessor>(
new GrDualIntervalGradientColorizer({scale01[0], scale01[1], scale01[2], scale01[3]},
c0,
{scale23[0], scale23[1], scale23[2], scale23[3]},
{bias23[0], bias23[1], bias23[2], bias23[3]},
threshold));
return std::unique_ptr<GrFragmentProcessor>(new GrDualIntervalGradientColorizer(
{scale01[0], scale01[1], scale01[2], scale01[3]}, c0,
{scale23[0], scale23[1], scale23[2], scale23[3]},
{bias23[0], bias23[1], bias23[2], bias23[3]}, threshold));
}

View File

@ -19,23 +19,18 @@ public:
const SkPMColor4f& bias01() const { return fBias01; }
const SkPMColor4f& scale23() const { return fScale23; }
const SkPMColor4f& bias23() const { return fBias23; }
float threshold() const { return fThreshold; }
float threshold() const { return fThreshold; }
static std::unique_ptr<GrFragmentProcessor> Make(const SkPMColor4f& c0,
const SkPMColor4f& c1,
const SkPMColor4f& c2,
const SkPMColor4f& c3,
float threshold);
static std::unique_ptr<GrFragmentProcessor> Make(const SkPMColor4f& c0, const SkPMColor4f& c1,
const SkPMColor4f& c2, const SkPMColor4f& c3,
float threshold);
GrDualIntervalGradientColorizer(const GrDualIntervalGradientColorizer& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "DualIntervalGradientColorizer"; }
private:
GrDualIntervalGradientColorizer(SkPMColor4f scale01,
SkPMColor4f bias01,
SkPMColor4f scale23,
SkPMColor4f bias23,
float threshold)
GrDualIntervalGradientColorizer(SkPMColor4f scale01, SkPMColor4f bias01, SkPMColor4f scale23,
SkPMColor4f bias23, float threshold)
: INHERITED(kGrDualIntervalGradientColorizer_ClassID, kNone_OptimizationFlags)
, fScale01(scale01)
, fBias01(bias01)
@ -46,11 +41,11 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
SkPMColor4f fScale01;
SkPMColor4f fBias01;
SkPMColor4f fScale23;
SkPMColor4f fBias23;
float fThreshold;
SkPMColor4f fScale01;
SkPMColor4f fBias01;
SkPMColor4f fScale23;
SkPMColor4f fBias23;
float fThreshold;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,32 +19,30 @@ class GrGLSLLinearGradientLayout : public GrGLSLFragmentProcessor {
public:
GrGLSLLinearGradientLayout() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrLinearGradientLayout& _outer = args.fFp.cast<GrLinearGradientLayout>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrLinearGradientLayout& _outer = args.fFp.cast<GrLinearGradientLayout>();
(void)_outer;
auto gradientMatrix = _outer.gradientMatrix();
(void)gradientMatrix;
SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fragBuilder->codeAppendf(
"half t = half(%s.x) + 1.0000000000000001e-05;\n%s = half4(t, 1.0, 0.0, 0.0);\n",
sk_TransformedCoords2D_0.c_str(),
args.fOutputColor);
sk_TransformedCoords2D_0.c_str(), args.fOutputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {}
const GrFragmentProcessor& _proc) override {}
};
GrGLSLFragmentProcessor* GrLinearGradientLayout::onCreateGLSLInstance() const {
return new GrGLSLLinearGradientLayout();
}
void GrLinearGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrLinearGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrLinearGradientLayout::onIsEqual(const GrFragmentProcessor& other) const {
const GrLinearGradientLayout& that = other.cast<GrLinearGradientLayout>();
(void)that;
if (fGradientMatrix != that.fGradientMatrix)
return false;
if (fGradientMatrix != that.fGradientMatrix) return false;
return true;
}
GrLinearGradientLayout::GrLinearGradientLayout(const GrLinearGradientLayout& src)
@ -59,24 +57,19 @@ std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::clone() const {
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradientLayout);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::TestCreate(GrProcessorTestData* d) {
SkScalar scale = GrGradientShader::RandomParams::kGradientScale;
SkPoint points[] = {
SkScalar scale = GrGradientShader::RandomParams::kGradientScale;
SkPoint points[] = {
{d->fRandom->nextRangeScalar(0.0f, scale), d->fRandom->nextRangeScalar(0.0f, scale)},
{d->fRandom->nextRangeScalar(0.0f, scale), d->fRandom->nextRangeScalar(0.0f, scale)}};
GrGradientShader::RandomParams params(d->fRandom);
auto shader = params.fUseColors4f ? SkGradientShader::MakeLinear(points,
params.fColors4f,
params.fColorSpace,
params.fStops,
params.fColorCount,
params.fTileMode)
: SkGradientShader::MakeLinear(points,
params.fColors,
params.fStops,
params.fColorCount,
params.fTileMode);
GrTest::TestAsFPArgs asFPArgs(d);
auto shader = params.fUseColors4f
? SkGradientShader::MakeLinear(points, params.fColors4f,
params.fColorSpace, params.fStops,
params.fColorCount, params.fTileMode)
: SkGradientShader::MakeLinear(points, params.fColors, params.fStops,
params.fColorCount, params.fTileMode);
GrTest::TestAsFPArgs asFPArgs(d);
std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args());
GrAlwaysAssert(fp);
return fp;
@ -84,7 +77,7 @@ std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::TestCreate(GrProces
#endif
std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::Make(const SkLinearGradient& grad,
const GrFPArgs& args) {
const GrFPArgs& args) {
SkMatrix matrix;
if (!grad.totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix)->invert(&matrix)) {
return nullptr;

View File

@ -21,10 +21,10 @@ public:
const SkMatrix44& gradientMatrix() const { return fGradientMatrix; }
static std::unique_ptr<GrFragmentProcessor> Make(const SkLinearGradient& gradient,
const GrFPArgs& args);
const GrFPArgs& args);
GrLinearGradientLayout(const GrLinearGradientLayout& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "LinearGradientLayout"; }
const char* name() const override { return "LinearGradientLayout"; }
private:
GrLinearGradientLayout(SkMatrix44 gradientMatrix)
@ -38,8 +38,8 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
SkMatrix44 fGradientMatrix;
GrCoordTransform fCoordTransform0;
SkMatrix44 fGradientMatrix;
GrCoordTransform fCoordTransform0;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,31 +19,29 @@ class GrGLSLRadialGradientLayout : public GrGLSLFragmentProcessor {
public:
GrGLSLRadialGradientLayout() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrRadialGradientLayout& _outer = args.fFp.cast<GrRadialGradientLayout>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrRadialGradientLayout& _outer = args.fFp.cast<GrRadialGradientLayout>();
(void)_outer;
auto gradientMatrix = _outer.gradientMatrix();
(void)gradientMatrix;
SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fragBuilder->codeAppendf("half t = half(length(%s));\n%s = half4(t, 1.0, 0.0, 0.0);\n",
sk_TransformedCoords2D_0.c_str(),
args.fOutputColor);
sk_TransformedCoords2D_0.c_str(), args.fOutputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {}
const GrFragmentProcessor& _proc) override {}
};
GrGLSLFragmentProcessor* GrRadialGradientLayout::onCreateGLSLInstance() const {
return new GrGLSLRadialGradientLayout();
}
void GrRadialGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrRadialGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrRadialGradientLayout::onIsEqual(const GrFragmentProcessor& other) const {
const GrRadialGradientLayout& that = other.cast<GrRadialGradientLayout>();
(void)that;
if (fGradientMatrix != that.fGradientMatrix)
return false;
if (fGradientMatrix != that.fGradientMatrix) return false;
return true;
}
GrRadialGradientLayout::GrRadialGradientLayout(const GrRadialGradientLayout& src)
@ -58,28 +56,22 @@ std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::clone() const {
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRadialGradientLayout);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::TestCreate(GrProcessorTestData* d) {
SkScalar scale = GrGradientShader::RandomParams::kGradientScale;
SkScalar scale = GrGradientShader::RandomParams::kGradientScale;
sk_sp<SkShader> shader;
do {
GrGradientShader::RandomParams params(d->fRandom);
SkPoint center = {d->fRandom->nextRangeScalar(0.0f, scale),
SkPoint center = {d->fRandom->nextRangeScalar(0.0f, scale),
d->fRandom->nextRangeScalar(0.0f, scale)};
SkScalar radius = d->fRandom->nextRangeScalar(0.0f, scale);
shader = params.fUseColors4f ? SkGradientShader::MakeRadial(center,
radius,
params.fColors4f,
params.fColorSpace,
params.fStops,
params.fColorCount,
params.fTileMode)
: SkGradientShader::MakeRadial(center,
radius,
params.fColors,
params.fStops,
params.fColorCount,
params.fTileMode);
SkScalar radius = d->fRandom->nextRangeScalar(0.0f, scale);
shader = params.fUseColors4f
? SkGradientShader::MakeRadial(center, radius, params.fColors4f,
params.fColorSpace, params.fStops,
params.fColorCount, params.fTileMode)
: SkGradientShader::MakeRadial(center, radius, params.fColors,
params.fStops, params.fColorCount,
params.fTileMode);
} while (!shader);
GrTest::TestAsFPArgs asFPArgs(d);
GrTest::TestAsFPArgs asFPArgs(d);
std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args());
GrAlwaysAssert(fp);
return fp;
@ -87,7 +79,7 @@ std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::TestCreate(GrProces
#endif
std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::Make(const SkRadialGradient& grad,
const GrFPArgs& args) {
const GrFPArgs& args) {
SkMatrix matrix;
if (!grad.totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix)->invert(&matrix)) {
return nullptr;

View File

@ -21,10 +21,10 @@ public:
const SkMatrix44& gradientMatrix() const { return fGradientMatrix; }
static std::unique_ptr<GrFragmentProcessor> Make(const SkRadialGradient& gradient,
const GrFPArgs& args);
const GrFPArgs& args);
GrRadialGradientLayout(const GrRadialGradientLayout& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "RadialGradientLayout"; }
const char* name() const override { return "RadialGradientLayout"; }
private:
GrRadialGradientLayout(SkMatrix44 gradientMatrix)
@ -38,8 +38,8 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
SkMatrix44 fGradientMatrix;
GrCoordTransform fCoordTransform0;
SkMatrix44 fGradientMatrix;
GrCoordTransform fCoordTransform0;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,7 +19,7 @@ class GrGLSLSingleIntervalGradientColorizer : public GrGLSLFragmentProcessor {
public:
GrGLSLSingleIntervalGradientColorizer() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrSingleIntervalGradientColorizer& _outer =
args.fFp.cast<GrSingleIntervalGradientColorizer>();
(void)_outer;
@ -31,15 +31,14 @@ public:
args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "start");
fEndVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, "end");
fragBuilder->codeAppendf("half t = %s.x;\n%s = (1.0 - t) * %s + t * %s;\n",
args.fInputColor,
args.fOutputColor,
args.fInputColor, args.fOutputColor,
args.fUniformHandler->getUniformCStr(fStartVar),
args.fUniformHandler->getUniformCStr(fEndVar));
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrSingleIntervalGradientColorizer& _outer =
_proc.cast<GrSingleIntervalGradientColorizer>();
{
@ -55,23 +54,21 @@ private:
}
}
}
SkPMColor4f fStartPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fEndPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fStartPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fEndPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
UniformHandle fStartVar;
UniformHandle fEndVar;
};
GrGLSLFragmentProcessor* GrSingleIntervalGradientColorizer::onCreateGLSLInstance() const {
return new GrGLSLSingleIntervalGradientColorizer();
}
void GrSingleIntervalGradientColorizer::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrSingleIntervalGradientColorizer::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrSingleIntervalGradientColorizer::onIsEqual(const GrFragmentProcessor& other) const {
const GrSingleIntervalGradientColorizer& that = other.cast<GrSingleIntervalGradientColorizer>();
(void)that;
if (fStart != that.fStart)
return false;
if (fEnd != that.fEnd)
return false;
if (fStart != that.fStart) return false;
if (fEnd != that.fEnd) return false;
return true;
}
GrSingleIntervalGradientColorizer::GrSingleIntervalGradientColorizer(

View File

@ -15,8 +15,8 @@
#include "GrCoordTransform.h"
class GrSingleIntervalGradientColorizer : public GrFragmentProcessor {
public:
const SkPMColor4f& start() const { return fStart; }
const SkPMColor4f& end() const { return fEnd; }
const SkPMColor4f& start() const { return fStart; }
const SkPMColor4f& end() const { return fEnd; }
static std::unique_ptr<GrFragmentProcessor> Make(SkPMColor4f start, SkPMColor4f end) {
return std::unique_ptr<GrFragmentProcessor>(
new GrSingleIntervalGradientColorizer(start, end));
@ -34,8 +34,8 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
SkPMColor4f fStart;
SkPMColor4f fEnd;
SkPMColor4f fStart;
SkPMColor4f fEnd;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,8 +19,8 @@ class GrGLSLSweepGradientLayout : public GrGLSLFragmentProcessor {
public:
GrGLSLSweepGradientLayout() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrSweepGradientLayout& _outer = args.fFp.cast<GrSweepGradientLayout>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrSweepGradientLayout& _outer = args.fFp.cast<GrSweepGradientLayout>();
(void)_outer;
auto gradientMatrix = _outer.gradientMatrix();
(void)gradientMatrix;
@ -37,19 +37,15 @@ public:
"atan(-%s.y, length(%s) - %s.x));\n} else {\n angle = half(atan(-%s.y, "
"-%s.x));\n}\nhalf t = ((angle * 0.15915494309180001 + 0.5) + %s) * %s;\n%s = "
"half4(t, 1.0, 0.0, 0.0);\n",
sk_TransformedCoords2D_0.c_str(),
sk_TransformedCoords2D_0.c_str(),
sk_TransformedCoords2D_0.c_str(),
sk_TransformedCoords2D_0.c_str(),
sk_TransformedCoords2D_0.c_str(),
args.fUniformHandler->getUniformCStr(fBiasVar),
args.fUniformHandler->getUniformCStr(fScaleVar),
args.fOutputColor);
sk_TransformedCoords2D_0.c_str(), sk_TransformedCoords2D_0.c_str(),
sk_TransformedCoords2D_0.c_str(), sk_TransformedCoords2D_0.c_str(),
sk_TransformedCoords2D_0.c_str(), args.fUniformHandler->getUniformCStr(fBiasVar),
args.fUniformHandler->getUniformCStr(fScaleVar), args.fOutputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrSweepGradientLayout& _outer = _proc.cast<GrSweepGradientLayout>();
{
float biasValue = _outer.bias();
@ -64,25 +60,22 @@ private:
}
}
}
float fBiasPrev = SK_FloatNaN;
float fScalePrev = SK_FloatNaN;
float fBiasPrev = SK_FloatNaN;
float fScalePrev = SK_FloatNaN;
UniformHandle fBiasVar;
UniformHandle fScaleVar;
};
GrGLSLFragmentProcessor* GrSweepGradientLayout::onCreateGLSLInstance() const {
return new GrGLSLSweepGradientLayout();
}
void GrSweepGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrSweepGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrSweepGradientLayout::onIsEqual(const GrFragmentProcessor& other) const {
const GrSweepGradientLayout& that = other.cast<GrSweepGradientLayout>();
(void)that;
if (fGradientMatrix != that.fGradientMatrix)
return false;
if (fBias != that.fBias)
return false;
if (fScale != that.fScale)
return false;
if (fGradientMatrix != that.fGradientMatrix) return false;
if (fBias != that.fBias) return false;
if (fScale != that.fScale) return false;
return true;
}
GrSweepGradientLayout::GrSweepGradientLayout(const GrSweepGradientLayout& src)
@ -99,23 +92,18 @@ std::unique_ptr<GrFragmentProcessor> GrSweepGradientLayout::clone() const {
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSweepGradientLayout);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrSweepGradientLayout::TestCreate(GrProcessorTestData* d) {
SkScalar scale = GrGradientShader::RandomParams::kGradientScale;
SkPoint center = {d->fRandom->nextRangeScalar(0.0f, scale),
SkScalar scale = GrGradientShader::RandomParams::kGradientScale;
SkPoint center = {d->fRandom->nextRangeScalar(0.0f, scale),
d->fRandom->nextRangeScalar(0.0f, scale)};
GrGradientShader::RandomParams params(d->fRandom);
auto shader = params.fUseColors4f ? SkGradientShader::MakeSweep(center.fX,
center.fY,
params.fColors4f,
params.fColorSpace,
params.fStops,
params.fColorCount)
: SkGradientShader::MakeSweep(center.fX,
center.fY,
params.fColors,
params.fStops,
params.fColorCount);
GrTest::TestAsFPArgs asFPArgs(d);
auto shader = params.fUseColors4f
? SkGradientShader::MakeSweep(center.fX, center.fY, params.fColors4f,
params.fColorSpace, params.fStops,
params.fColorCount)
: SkGradientShader::MakeSweep(center.fX, center.fY, params.fColors,
params.fStops, params.fColorCount);
GrTest::TestAsFPArgs asFPArgs(d);
std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args());
GrAlwaysAssert(fp);
return fp;
@ -123,7 +111,7 @@ std::unique_ptr<GrFragmentProcessor> GrSweepGradientLayout::TestCreate(GrProcess
#endif
std::unique_ptr<GrFragmentProcessor> GrSweepGradientLayout::Make(const SkSweepGradient& grad,
const GrFPArgs& args) {
const GrFPArgs& args) {
SkMatrix matrix;
if (!grad.totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix)->invert(&matrix)) {
return nullptr;

View File

@ -19,14 +19,14 @@
class GrSweepGradientLayout : public GrFragmentProcessor {
public:
const SkMatrix44& gradientMatrix() const { return fGradientMatrix; }
float bias() const { return fBias; }
float scale() const { return fScale; }
float bias() const { return fBias; }
float scale() const { return fScale; }
static std::unique_ptr<GrFragmentProcessor> Make(const SkSweepGradient& gradient,
const GrFPArgs& args);
const GrFPArgs& args);
GrSweepGradientLayout(const GrSweepGradientLayout& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "SweepGradientLayout"; }
const char* name() const override { return "SweepGradientLayout"; }
private:
GrSweepGradientLayout(SkMatrix44 gradientMatrix, float bias, float scale)
@ -42,10 +42,10 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
SkMatrix44 fGradientMatrix;
float fBias;
float fScale;
GrCoordTransform fCoordTransform0;
SkMatrix44 fGradientMatrix;
float fBias;
float fScale;
GrCoordTransform fCoordTransform0;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,31 +19,29 @@ class GrGLSLTextureGradientColorizer : public GrGLSLFragmentProcessor {
public:
GrGLSLTextureGradientColorizer() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrTextureGradientColorizer& _outer = args.fFp.cast<GrTextureGradientColorizer>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrTextureGradientColorizer& _outer = args.fFp.cast<GrTextureGradientColorizer>();
(void)_outer;
fragBuilder->codeAppendf(
"half2 coord = half2(%s.x, 0.5);\n%s = texture(%s, float2(coord)).%s;\n",
args.fInputColor,
args.fOutputColor,
args.fInputColor, args.fOutputColor,
fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {}
const GrFragmentProcessor& _proc) override {}
};
GrGLSLFragmentProcessor* GrTextureGradientColorizer::onCreateGLSLInstance() const {
return new GrGLSLTextureGradientColorizer();
}
void GrTextureGradientColorizer::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrTextureGradientColorizer::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrTextureGradientColorizer::onIsEqual(const GrFragmentProcessor& other) const {
const GrTextureGradientColorizer& that = other.cast<GrTextureGradientColorizer>();
(void)that;
if (fGradient != that.fGradient)
return false;
if (fGradient != that.fGradient) return false;
return true;
}
GrTextureGradientColorizer::GrTextureGradientColorizer(const GrTextureGradientColorizer& src)

View File

@ -33,7 +33,7 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
const TextureSampler& onTextureSampler(int) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
TextureSampler fGradient;
TextureSampler fGradient;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,8 +19,8 @@ class GrGLSLTiledGradientEffect : public GrGLSLFragmentProcessor {
public:
GrGLSLTiledGradientEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>();
(void)_outer;
auto mirror = _outer.mirror();
(void)mirror;
@ -39,27 +39,24 @@ public:
_child1.c_str(),
(_outer.childProcessor(_outer.gradLayout_index()).preservesOpaqueInput() ? "true"
: "false"),
args.fOutputColor,
(_outer.mirror() ? "true" : "false"));
args.fOutputColor, (_outer.mirror() ? "true" : "false"));
SkString _input0("t");
SkString _child0("_child0");
this->emitChild(_outer.colorizer_index(), _input0.c_str(), &_child0, args);
fragBuilder->codeAppendf("\n %s = %s;\n}\n@if (%s) {\n %s.xyz *= %s.w;\n}\n",
args.fOutputColor,
_child0.c_str(),
(_outer.makePremul() ? "true" : "false"),
args.fOutputColor,
args.fOutputColor, _child0.c_str(),
(_outer.makePremul() ? "true" : "false"), args.fOutputColor,
args.fOutputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {}
const GrFragmentProcessor& _proc) override {}
};
GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const {
return new GrGLSLTiledGradientEffect();
}
void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->add32((int32_t)fMirror);
b->add32((int32_t)fMakePremul);
@ -67,12 +64,9 @@ void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>();
(void)that;
if (fMirror != that.fMirror)
return false;
if (fMakePremul != that.fMakePremul)
return false;
if (fColorsAreOpaque != that.fColorsAreOpaque)
return false;
if (fMirror != that.fMirror) return false;
if (fMakePremul != that.fMakePremul) return false;
if (fColorsAreOpaque != that.fColorsAreOpaque) return false;
return true;
}
GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src)

View File

@ -15,30 +15,26 @@
#include "GrCoordTransform.h"
class GrTiledGradientEffect : public GrFragmentProcessor {
public:
int colorizer_index() const { return fColorizer_index; }
int gradLayout_index() const { return fGradLayout_index; }
int colorizer_index() const { return fColorizer_index; }
int gradLayout_index() const { return fGradLayout_index; }
bool mirror() const { return fMirror; }
bool makePremul() const { return fMakePremul; }
bool colorsAreOpaque() const { return fColorsAreOpaque; }
static std::unique_ptr<GrFragmentProcessor> Make(
std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
bool mirror,
bool makePremul,
bool colorsAreOpaque) {
std::unique_ptr<GrFragmentProcessor> gradLayout, bool mirror, bool makePremul,
bool colorsAreOpaque) {
return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(
std::move(colorizer), std::move(gradLayout), mirror, makePremul, colorsAreOpaque));
}
GrTiledGradientEffect(const GrTiledGradientEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "TiledGradientEffect"; }
const char* name() const override { return "TiledGradientEffect"; }
private:
GrTiledGradientEffect(std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
bool mirror,
bool makePremul,
bool colorsAreOpaque)
std::unique_ptr<GrFragmentProcessor> gradLayout, bool mirror,
bool makePremul, bool colorsAreOpaque)
: INHERITED(kGrTiledGradientEffect_ClassID,
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag |
(colorsAreOpaque && gradLayout->preservesOpaqueInput()
@ -58,11 +54,11 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
int fColorizer_index = -1;
int fGradLayout_index = -1;
bool fMirror;
bool fMakePremul;
bool fColorsAreOpaque;
int fColorizer_index = -1;
int fGradLayout_index = -1;
bool fMirror;
bool fMakePremul;
bool fColorsAreOpaque;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,7 +19,7 @@ class GrGLSLTwoPointConicalGradientLayout : public GrGLSLFragmentProcessor {
public:
GrGLSLTwoPointConicalGradientLayout() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrTwoPointConicalGradientLayout& _outer =
args.fFp.cast<GrTwoPointConicalGradientLayout>();
(void)_outer;
@ -39,8 +39,8 @@ public:
(void)isNativelyFocal;
auto focalParams = _outer.focalParams();
(void)focalParams;
fFocalParamsVar = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf2_GrSLType, "focalParams");
fFocalParamsVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType,
"focalParams");
SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fragBuilder->codeAppendf(
"float2 p = %s;\nfloat t = -1.0;\nhalf v = 1.0;\n@switch (%d) {\n case 1:\n "
@ -50,8 +50,7 @@ public:
"0:\n {\n half r0 = %s.x;\n @if (%s) {\n "
" t = length(p) - float(r0);\n } else {\n t = "
"-length(p) - float(r0);\n ",
sk_TransformedCoords2D_0.c_str(),
(int)_outer.type(),
sk_TransformedCoords2D_0.c_str(), (int)_outer.type(),
args.fUniformHandler->getUniformCStr(fFocalParamsVar),
args.fUniformHandler->getUniformCStr(fFocalParamsVar),
(_outer.isRadiusIncreasing() ? "true" : "false"));
@ -86,13 +85,12 @@ public:
"float(fx);\n }\n }\n @if (%s) {\n "
" t = 1.0 - t;\n }\n }\n break;\n}\n%s = "
"half4(half(t), v, 0.0, 0.0);\n",
(_outer.isSwapped() ? "true" : "false"),
args.fOutputColor);
(_outer.isSwapped() ? "true" : "false"), args.fOutputColor);
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrTwoPointConicalGradientLayout& _outer =
_proc.cast<GrTwoPointConicalGradientLayout>();
{
@ -103,13 +101,13 @@ private:
}
}
}
SkPoint fFocalParamsPrev = SkPoint::Make(SK_FloatNaN, SK_FloatNaN);
SkPoint fFocalParamsPrev = SkPoint::Make(SK_FloatNaN, SK_FloatNaN);
UniformHandle fFocalParamsVar;
};
GrGLSLFragmentProcessor* GrTwoPointConicalGradientLayout::onCreateGLSLInstance() const {
return new GrGLSLTwoPointConicalGradientLayout();
}
void GrTwoPointConicalGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrTwoPointConicalGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->add32((int32_t)fType);
b->add32((int32_t)fIsRadiusIncreasing);
@ -121,22 +119,14 @@ void GrTwoPointConicalGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps&
bool GrTwoPointConicalGradientLayout::onIsEqual(const GrFragmentProcessor& other) const {
const GrTwoPointConicalGradientLayout& that = other.cast<GrTwoPointConicalGradientLayout>();
(void)that;
if (fGradientMatrix != that.fGradientMatrix)
return false;
if (fType != that.fType)
return false;
if (fIsRadiusIncreasing != that.fIsRadiusIncreasing)
return false;
if (fIsFocalOnCircle != that.fIsFocalOnCircle)
return false;
if (fIsWellBehaved != that.fIsWellBehaved)
return false;
if (fIsSwapped != that.fIsSwapped)
return false;
if (fIsNativelyFocal != that.fIsNativelyFocal)
return false;
if (fFocalParams != that.fFocalParams)
return false;
if (fGradientMatrix != that.fGradientMatrix) return false;
if (fType != that.fType) return false;
if (fIsRadiusIncreasing != that.fIsRadiusIncreasing) return false;
if (fIsFocalOnCircle != that.fIsFocalOnCircle) return false;
if (fIsWellBehaved != that.fIsWellBehaved) return false;
if (fIsSwapped != that.fIsSwapped) return false;
if (fIsNativelyFocal != that.fIsNativelyFocal) return false;
if (fFocalParams != that.fFocalParams) return false;
return true;
}
GrTwoPointConicalGradientLayout::GrTwoPointConicalGradientLayout(
@ -160,12 +150,12 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrTwoPointConicalGradientLayout);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrTwoPointConicalGradientLayout::TestCreate(
GrProcessorTestData* d) {
SkScalar scale = GrGradientShader::RandomParams::kGradientScale;
SkScalar scale = GrGradientShader::RandomParams::kGradientScale;
SkScalar offset = scale / 32.0f;
SkPoint center1 = {d->fRandom->nextRangeScalar(0.0f, scale),
SkPoint center1 = {d->fRandom->nextRangeScalar(0.0f, scale),
d->fRandom->nextRangeScalar(0.0f, scale)};
SkPoint center2 = {d->fRandom->nextRangeScalar(0.0f, scale),
SkPoint center2 = {d->fRandom->nextRangeScalar(0.0f, scale),
d->fRandom->nextRangeScalar(0.0f, scale)};
SkScalar radius1 = d->fRandom->nextRangeScalar(0.0f, scale);
SkScalar radius2 = d->fRandom->nextRangeScalar(0.0f, scale);
@ -220,24 +210,15 @@ std::unique_ptr<GrFragmentProcessor> GrTwoPointConicalGradientLayout::TestCreate
}
GrGradientShader::RandomParams params(d->fRandom);
auto shader = params.fUseColors4f ? SkGradientShader::MakeTwoPointConical(center1,
radius1,
center2,
radius2,
params.fColors4f,
params.fColorSpace,
params.fStops,
params.fColorCount,
params.fTileMode)
: SkGradientShader::MakeTwoPointConical(center1,
radius1,
center2,
radius2,
params.fColors,
params.fStops,
params.fColorCount,
params.fTileMode);
GrTest::TestAsFPArgs asFPArgs(d);
auto shader = params.fUseColors4f
? SkGradientShader::MakeTwoPointConical(
center1, radius1, center2, radius2, params.fColors4f,
params.fColorSpace, params.fStops, params.fColorCount,
params.fTileMode)
: SkGradientShader::MakeTwoPointConical(
center1, radius1, center2, radius2, params.fColors,
params.fStops, params.fColorCount, params.fTileMode);
GrTest::TestAsFPArgs asFPArgs(d);
std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args());
GrAlwaysAssert(fp);
@ -261,25 +242,24 @@ GrTwoPointConicalGradientLayout::Type convert_type(SkTwoPointConicalGradient::Ty
}
std::unique_ptr<GrFragmentProcessor> GrTwoPointConicalGradientLayout::Make(
const SkTwoPointConicalGradient& grad,
const GrFPArgs& args) {
const SkTwoPointConicalGradient& grad, const GrFPArgs& args) {
GrTwoPointConicalGradientLayout::Type grType = convert_type(grad.getType());
// The focalData struct is only valid if isFocal is true
const SkTwoPointConicalGradient::FocalData& focalData = grad.getFocalData();
bool isFocal = grType == Type::kFocal;
bool isFocal = grType == Type::kFocal;
// Calculate optimization switches from gradient specification
bool isFocalOnCircle = isFocal && focalData.isFocalOnCircle();
bool isWellBehaved = isFocal && focalData.isWellBehaved();
bool isSwapped = isFocal && focalData.isSwapped();
bool isWellBehaved = isFocal && focalData.isWellBehaved();
bool isSwapped = isFocal && focalData.isSwapped();
bool isNativelyFocal = isFocal && focalData.isNativelyFocal();
// Type-specific calculations: isRadiusIncreasing, focalParams, and the gradient matrix.
// However, all types start with the total inverse local matrix calculated from the shader
// and args
bool isRadiusIncreasing;
SkPoint focalParams; // really just a 2D tuple
bool isRadiusIncreasing;
SkPoint focalParams; // really just a 2D tuple
SkMatrix matrix;
// Initialize the base matrix
@ -294,7 +274,7 @@ std::unique_ptr<GrFragmentProcessor> GrTwoPointConicalGradientLayout::Make(
matrix.postConcat(grad.getGradientMatrix());
} else if (grType == Type::kRadial) {
SkScalar dr = grad.getDiffRadius();
SkScalar dr = grad.getDiffRadius();
isRadiusIncreasing = dr >= 0;
SkScalar r0 = grad.getStartRadius() / dr;
@ -317,13 +297,7 @@ std::unique_ptr<GrFragmentProcessor> GrTwoPointConicalGradientLayout::Make(
matrix.postConcat(grad.getGradientMatrix());
}
return std::unique_ptr<GrFragmentProcessor>(
new GrTwoPointConicalGradientLayout(matrix,
grType,
isRadiusIncreasing,
isFocalOnCircle,
isWellBehaved,
isSwapped,
isNativelyFocal,
focalParams));
return std::unique_ptr<GrFragmentProcessor>(new GrTwoPointConicalGradientLayout(
matrix, grType, isRadiusIncreasing, isFocalOnCircle, isWellBehaved, isSwapped,
isNativelyFocal, focalParams));
}

View File

@ -20,29 +20,24 @@ class GrTwoPointConicalGradientLayout : public GrFragmentProcessor {
public:
enum class Type { kFocal = 2, kRadial = 0, kStrip = 1 };
const SkMatrix44& gradientMatrix() const { return fGradientMatrix; }
const Type& type() const { return fType; }
bool isRadiusIncreasing() const { return fIsRadiusIncreasing; }
bool isFocalOnCircle() const { return fIsFocalOnCircle; }
bool isWellBehaved() const { return fIsWellBehaved; }
bool isSwapped() const { return fIsSwapped; }
bool isNativelyFocal() const { return fIsNativelyFocal; }
const SkPoint& focalParams() const { return fFocalParams; }
const Type& type() const { return fType; }
bool isRadiusIncreasing() const { return fIsRadiusIncreasing; }
bool isFocalOnCircle() const { return fIsFocalOnCircle; }
bool isWellBehaved() const { return fIsWellBehaved; }
bool isSwapped() const { return fIsSwapped; }
bool isNativelyFocal() const { return fIsNativelyFocal; }
const SkPoint& focalParams() const { return fFocalParams; }
static std::unique_ptr<GrFragmentProcessor> Make(const SkTwoPointConicalGradient& gradient,
const GrFPArgs& args);
const GrFPArgs& args);
GrTwoPointConicalGradientLayout(const GrTwoPointConicalGradientLayout& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "TwoPointConicalGradientLayout"; }
private:
GrTwoPointConicalGradientLayout(SkMatrix44 gradientMatrix,
Type type,
bool isRadiusIncreasing,
bool isFocalOnCircle,
bool isWellBehaved,
bool isSwapped,
bool isNativelyFocal,
SkPoint focalParams)
GrTwoPointConicalGradientLayout(SkMatrix44 gradientMatrix, Type type, bool isRadiusIncreasing,
bool isFocalOnCircle, bool isWellBehaved, bool isSwapped,
bool isNativelyFocal, SkPoint focalParams)
: INHERITED(kGrTwoPointConicalGradientLayout_ClassID,
(OptimizationFlags)kNone_OptimizationFlags)
, fGradientMatrix(gradientMatrix)
@ -60,15 +55,15 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
SkMatrix44 fGradientMatrix;
Type fType;
bool fIsRadiusIncreasing;
bool fIsFocalOnCircle;
bool fIsWellBehaved;
bool fIsSwapped;
bool fIsNativelyFocal;
SkPoint fFocalParams;
GrCoordTransform fCoordTransform0;
SkMatrix44 fGradientMatrix;
Type fType;
bool fIsRadiusIncreasing;
bool fIsFocalOnCircle;
bool fIsWellBehaved;
bool fIsSwapped;
bool fIsNativelyFocal;
SkPoint fFocalParams;
GrCoordTransform fCoordTransform0;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -19,7 +19,7 @@ class GrGLSLUnrolledBinaryGradientColorizer : public GrGLSLFragmentProcessor {
public:
GrGLSLUnrolledBinaryGradientColorizer() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrUnrolledBinaryGradientColorizer& _outer =
args.fFp.cast<GrUnrolledBinaryGradientColorizer>();
(void)_outer;
@ -61,70 +61,70 @@ public:
(void)thresholds1_7;
auto thresholds9_13 = _outer.thresholds9_13();
(void)thresholds9_13;
fScale0_1Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "scale0_1");
fScale0_1Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"scale0_1");
if (intervalCount > 1) {
fScale2_3Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "scale2_3");
fScale2_3Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale2_3");
}
if (intervalCount > 2) {
fScale4_5Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "scale4_5");
fScale4_5Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale4_5");
}
if (intervalCount > 3) {
fScale6_7Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "scale6_7");
fScale6_7Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale6_7");
}
if (intervalCount > 4) {
fScale8_9Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "scale8_9");
fScale8_9Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale8_9");
}
if (intervalCount > 5) {
fScale10_11Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "scale10_11");
fScale10_11Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale10_11");
}
if (intervalCount > 6) {
fScale12_13Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "scale12_13");
fScale12_13Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale12_13");
}
if (intervalCount > 7) {
fScale14_15Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "scale14_15");
fScale14_15Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kFloat4_GrSLType, "scale14_15");
}
fBias0_1Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "bias0_1");
fBias0_1Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias0_1");
if (intervalCount > 1) {
fBias2_3Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "bias2_3");
fBias2_3Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias2_3");
}
if (intervalCount > 2) {
fBias4_5Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "bias4_5");
fBias4_5Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias4_5");
}
if (intervalCount > 3) {
fBias6_7Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "bias6_7");
fBias6_7Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias6_7");
}
if (intervalCount > 4) {
fBias8_9Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "bias8_9");
fBias8_9Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"bias8_9");
}
if (intervalCount > 5) {
fBias10_11Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "bias10_11");
fBias10_11Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias10_11");
}
if (intervalCount > 6) {
fBias12_13Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "bias12_13");
fBias12_13Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias12_13");
}
if (intervalCount > 7) {
fBias14_15Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kFloat4_GrSLType, "bias14_15");
fBias14_15Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kFloat4_GrSLType, "bias14_15");
}
fThresholds1_7Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf4_GrSLType, "thresholds1_7");
fThresholds9_13Var = args.fUniformHandler->addUniform(
kFragment_GrShaderFlag, kHalf4_GrSLType, "thresholds9_13");
fThresholds1_7Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kHalf4_GrSLType, "thresholds1_7");
fThresholds9_13Var = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kHalf4_GrSLType, "thresholds9_13");
fragBuilder->codeAppendf(
"half t = %s.x;\nfloat4 scale, bias;\nif (%d <= 4 || t < %s.w) {\n if (%d <= 2 "
"|| t < %s.y) {\n if (%d <= 1 || t < %s.x) {\n scale = %s;\n "
@ -133,12 +133,9 @@ public:
"scale = %s;\n bias = %s;\n } else {\n scale = %s;\n "
" bias = %s;\n }\n }\n} else {\n if (%d <= 6 || t < %s.y) "
"{\n if (%d <= 5 || t <",
args.fInputColor,
_outer.intervalCount(),
args.fUniformHandler->getUniformCStr(fThresholds1_7Var),
_outer.intervalCount(),
args.fUniformHandler->getUniformCStr(fThresholds1_7Var),
_outer.intervalCount(),
args.fInputColor, _outer.intervalCount(),
args.fUniformHandler->getUniformCStr(fThresholds1_7Var), _outer.intervalCount(),
args.fUniformHandler->getUniformCStr(fThresholds1_7Var), _outer.intervalCount(),
args.fUniformHandler->getUniformCStr(fThresholds1_7Var),
args.fUniformHandler->getUniformCStr(fScale0_1Var),
args.fUniformHandler->getUniformCStr(fBias0_1Var),
@ -146,8 +143,7 @@ public:
: "float4(0)",
fBias2_3Var.isValid() ? args.fUniformHandler->getUniformCStr(fBias2_3Var)
: "float4(0)",
_outer.intervalCount(),
args.fUniformHandler->getUniformCStr(fThresholds1_7Var),
_outer.intervalCount(), args.fUniformHandler->getUniformCStr(fThresholds1_7Var),
fScale4_5Var.isValid() ? args.fUniformHandler->getUniformCStr(fScale4_5Var)
: "float4(0)",
fBias4_5Var.isValid() ? args.fUniformHandler->getUniformCStr(fBias4_5Var)
@ -156,8 +152,7 @@ public:
: "float4(0)",
fBias6_7Var.isValid() ? args.fUniformHandler->getUniformCStr(fBias6_7Var)
: "float4(0)",
_outer.intervalCount(),
args.fUniformHandler->getUniformCStr(fThresholds9_13Var),
_outer.intervalCount(), args.fUniformHandler->getUniformCStr(fThresholds9_13Var),
_outer.intervalCount());
fragBuilder->codeAppendf(
" %s.x) {\n scale = %s;\n bias = %s;\n } else {\n "
@ -174,8 +169,7 @@ public:
: "float4(0)",
fBias10_11Var.isValid() ? args.fUniformHandler->getUniformCStr(fBias10_11Var)
: "float4(0)",
_outer.intervalCount(),
args.fUniformHandler->getUniformCStr(fThresholds9_13Var),
_outer.intervalCount(), args.fUniformHandler->getUniformCStr(fThresholds9_13Var),
fScale12_13Var.isValid() ? args.fUniformHandler->getUniformCStr(fScale12_13Var)
: "float4(0)",
fBias12_13Var.isValid() ? args.fUniformHandler->getUniformCStr(fBias12_13Var)
@ -189,7 +183,7 @@ public:
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrFragmentProcessor& _proc) override {
const GrUnrolledBinaryGradientColorizer& _outer =
_proc.cast<GrUnrolledBinaryGradientColorizer>();
{
@ -237,11 +231,9 @@ private:
if (fBias14_15Var.isValid()) {
pdman.set4fv(fBias14_15Var, 1, (_outer.bias14_15()).vec());
}
pdman.set4fv(fThresholds1_7Var,
1,
pdman.set4fv(fThresholds1_7Var, 1,
reinterpret_cast<const float*>(&(_outer.thresholds1_7())));
pdman.set4fv(fThresholds9_13Var,
1,
pdman.set4fv(fThresholds9_13Var, 1,
reinterpret_cast<const float*>(&(_outer.thresholds9_13())));
}
}
@ -267,51 +259,32 @@ private:
GrGLSLFragmentProcessor* GrUnrolledBinaryGradientColorizer::onCreateGLSLInstance() const {
return new GrGLSLUnrolledBinaryGradientColorizer();
}
void GrUnrolledBinaryGradientColorizer::onGetGLSLProcessorKey(const GrShaderCaps& caps,
void GrUnrolledBinaryGradientColorizer::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->add32((int32_t)fIntervalCount);
}
bool GrUnrolledBinaryGradientColorizer::onIsEqual(const GrFragmentProcessor& other) const {
const GrUnrolledBinaryGradientColorizer& that = other.cast<GrUnrolledBinaryGradientColorizer>();
(void)that;
if (fIntervalCount != that.fIntervalCount)
return false;
if (fScale0_1 != that.fScale0_1)
return false;
if (fScale2_3 != that.fScale2_3)
return false;
if (fScale4_5 != that.fScale4_5)
return false;
if (fScale6_7 != that.fScale6_7)
return false;
if (fScale8_9 != that.fScale8_9)
return false;
if (fScale10_11 != that.fScale10_11)
return false;
if (fScale12_13 != that.fScale12_13)
return false;
if (fScale14_15 != that.fScale14_15)
return false;
if (fBias0_1 != that.fBias0_1)
return false;
if (fBias2_3 != that.fBias2_3)
return false;
if (fBias4_5 != that.fBias4_5)
return false;
if (fBias6_7 != that.fBias6_7)
return false;
if (fBias8_9 != that.fBias8_9)
return false;
if (fBias10_11 != that.fBias10_11)
return false;
if (fBias12_13 != that.fBias12_13)
return false;
if (fBias14_15 != that.fBias14_15)
return false;
if (fThresholds1_7 != that.fThresholds1_7)
return false;
if (fThresholds9_13 != that.fThresholds9_13)
return false;
if (fIntervalCount != that.fIntervalCount) return false;
if (fScale0_1 != that.fScale0_1) return false;
if (fScale2_3 != that.fScale2_3) return false;
if (fScale4_5 != that.fScale4_5) return false;
if (fScale6_7 != that.fScale6_7) return false;
if (fScale8_9 != that.fScale8_9) return false;
if (fScale10_11 != that.fScale10_11) return false;
if (fScale12_13 != that.fScale12_13) return false;
if (fScale14_15 != that.fScale14_15) return false;
if (fBias0_1 != that.fBias0_1) return false;
if (fBias2_3 != that.fBias2_3) return false;
if (fBias4_5 != that.fBias4_5) return false;
if (fBias6_7 != that.fBias6_7) return false;
if (fBias8_9 != that.fBias8_9) return false;
if (fBias10_11 != that.fBias10_11) return false;
if (fBias12_13 != that.fBias12_13) return false;
if (fBias14_15 != that.fBias14_15) return false;
if (fThresholds1_7 != that.fThresholds1_7) return false;
if (fThresholds9_13 != that.fThresholds9_13) return false;
return true;
}
GrUnrolledBinaryGradientColorizer::GrUnrolledBinaryGradientColorizer(
@ -340,11 +313,9 @@ std::unique_ptr<GrFragmentProcessor> GrUnrolledBinaryGradientColorizer::clone()
return std::unique_ptr<GrFragmentProcessor>(new GrUnrolledBinaryGradientColorizer(*this));
}
static const int kMaxIntervals = 8;
static const int kMaxIntervals = 8;
std::unique_ptr<GrFragmentProcessor> GrUnrolledBinaryGradientColorizer::Make(
const SkPMColor4f* colors,
const SkScalar* positions,
int count) {
const SkPMColor4f* colors, const SkScalar* positions, int count) {
// Depending on how the positions resolve into hard stops or regular stops, the number of
// intervals specified by the number of colors/positions can change. For instance, a plain
// 3 color gradient is two intervals, but a 4 color gradient with a hard stop is also
@ -360,7 +331,7 @@ std::unique_ptr<GrFragmentProcessor> GrUnrolledBinaryGradientColorizer::Make(
// after the dst color space is applied, it limits our ability to cache their values.
SkPMColor4f scales[kMaxIntervals];
SkPMColor4f biases[kMaxIntervals];
SkScalar thresholds[kMaxIntervals];
SkScalar thresholds[kMaxIntervals];
int intervalCount = 0;
@ -385,7 +356,7 @@ std::unique_ptr<GrFragmentProcessor> GrUnrolledBinaryGradientColorizer::Make(
auto c1 = Sk4f::Load(colors[i + 1].vec());
auto scale = (c1 - c0) / dt;
auto bias = c0 - t0 * scale;
auto bias = c0 - t0 * scale;
scale.store(scales + intervalCount);
bias.store(biases + intervalCount);
@ -395,29 +366,15 @@ std::unique_ptr<GrFragmentProcessor> GrUnrolledBinaryGradientColorizer::Make(
// For isEqual to make sense, set the unused values to something consistent
for (int i = intervalCount; i < kMaxIntervals; i++) {
scales[i] = SK_PMColor4fTRANSPARENT;
biases[i] = SK_PMColor4fTRANSPARENT;
scales[i] = SK_PMColor4fTRANSPARENT;
biases[i] = SK_PMColor4fTRANSPARENT;
thresholds[i] = 0.0;
}
return std::unique_ptr<GrFragmentProcessor>(new GrUnrolledBinaryGradientColorizer(
intervalCount,
scales[0],
scales[1],
scales[2],
scales[3],
scales[4],
scales[5],
scales[6],
scales[7],
biases[0],
biases[1],
biases[2],
biases[3],
biases[4],
biases[5],
biases[6],
biases[7],
intervalCount, scales[0], scales[1], scales[2], scales[3], scales[4], scales[5],
scales[6], scales[7], biases[0], biases[1], biases[2], biases[3], biases[4], biases[5],
biases[6], biases[7],
SkRect::MakeLTRB(thresholds[0], thresholds[1], thresholds[2], thresholds[3]),
SkRect::MakeLTRB(thresholds[4], thresholds[5], thresholds[6], 0.0)));
}

View File

@ -15,8 +15,8 @@
#include "GrCoordTransform.h"
class GrUnrolledBinaryGradientColorizer : public GrFragmentProcessor {
public:
static const int kMaxColorCount = 16;
int32_t intervalCount() const { return fIntervalCount; }
static const int kMaxColorCount = 16;
int32_t intervalCount() const { return fIntervalCount; }
const SkPMColor4f& scale0_1() const { return fScale0_1; }
const SkPMColor4f& scale2_3() const { return fScale2_3; }
const SkPMColor4f& scale4_5() const { return fScale4_5; }
@ -33,18 +33,18 @@ public:
const SkPMColor4f& bias10_11() const { return fBias10_11; }
const SkPMColor4f& bias12_13() const { return fBias12_13; }
const SkPMColor4f& bias14_15() const { return fBias14_15; }
const SkRect& thresholds1_7() const { return fThresholds1_7; }
const SkRect& thresholds9_13() const { return fThresholds9_13; }
const SkRect& thresholds1_7() const { return fThresholds1_7; }
const SkRect& thresholds9_13() const { return fThresholds9_13; }
static std::unique_ptr<GrFragmentProcessor> Make(const SkPMColor4f* colors,
const SkScalar* positions,
int count);
const SkScalar* positions,
int count);
GrUnrolledBinaryGradientColorizer(const GrUnrolledBinaryGradientColorizer& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "UnrolledBinaryGradientColorizer"; }
private:
GrUnrolledBinaryGradientColorizer(int32_t intervalCount,
GrUnrolledBinaryGradientColorizer(int32_t intervalCount,
SkPMColor4f scale0_1,
SkPMColor4f scale2_3,
SkPMColor4f scale4_5,
@ -61,8 +61,8 @@ private:
SkPMColor4f bias10_11,
SkPMColor4f bias12_13,
SkPMColor4f bias14_15,
SkRect thresholds1_7,
SkRect thresholds9_13)
SkRect thresholds1_7,
SkRect thresholds9_13)
: INHERITED(kGrUnrolledBinaryGradientColorizer_ClassID, kNone_OptimizationFlags)
, fIntervalCount(intervalCount)
, fScale0_1(scale0_1)
@ -87,25 +87,25 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
int32_t fIntervalCount;
SkPMColor4f fScale0_1;
SkPMColor4f fScale2_3;
SkPMColor4f fScale4_5;
SkPMColor4f fScale6_7;
SkPMColor4f fScale8_9;
SkPMColor4f fScale10_11;
SkPMColor4f fScale12_13;
SkPMColor4f fScale14_15;
SkPMColor4f fBias0_1;
SkPMColor4f fBias2_3;
SkPMColor4f fBias4_5;
SkPMColor4f fBias6_7;
SkPMColor4f fBias8_9;
SkPMColor4f fBias10_11;
SkPMColor4f fBias12_13;
SkPMColor4f fBias14_15;
SkRect fThresholds1_7;
SkRect fThresholds9_13;
int32_t fIntervalCount;
SkPMColor4f fScale0_1;
SkPMColor4f fScale2_3;
SkPMColor4f fScale4_5;
SkPMColor4f fScale6_7;
SkPMColor4f fScale8_9;
SkPMColor4f fScale10_11;
SkPMColor4f fScale12_13;
SkPMColor4f fScale14_15;
SkPMColor4f fBias0_1;
SkPMColor4f fBias2_3;
SkPMColor4f fBias4_5;
SkPMColor4f fBias6_7;
SkPMColor4f fBias8_9;
SkPMColor4f fBias10_11;
SkPMColor4f fBias12_13;
SkPMColor4f fBias14_15;
SkRect fThresholds1_7;
SkRect fThresholds9_13;
typedef GrFragmentProcessor INHERITED;
};
#endif