Switch gradients from GrColor4f to SkPMColor4f

This is the most misleading use-case, because these values are either
premul or unpremul depending on the gradient's flags. It turns out that
we only need to "lie" and alias in one spot, though, so I think this is
better than adding an entirely new kUnknown_SkAlphaType specialization
of SkRGBA4f.

Bug: skia:
Change-Id: I4b7e280355219d439f50a7fe54230ea17715abc3
Reviewed-on: https://skia-review.googlesource.com/c/162745
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2018-10-16 15:19:44 -04:00 committed by Skia Commit-Bot
parent e3a5b1960d
commit 021ed51dc6
15 changed files with 194 additions and 195 deletions

View File

@ -59,20 +59,20 @@ private:
const GrFragmentProcessor& _proc) override {
const GrClampedGradientEffect& _outer = _proc.cast<GrClampedGradientEffect>();
{
const GrColor4f& leftBorderColorValue = _outer.leftBorderColor();
const SkPMColor4f& leftBorderColorValue = _outer.leftBorderColor();
if (fLeftBorderColorPrev != leftBorderColorValue) {
fLeftBorderColorPrev = leftBorderColorValue;
pdman.set4fv(fLeftBorderColorVar, 1, leftBorderColorValue.fRGBA);
pdman.set4fv(fLeftBorderColorVar, 1, leftBorderColorValue.vec());
}
const GrColor4f& rightBorderColorValue = _outer.rightBorderColor();
const SkPMColor4f& rightBorderColorValue = _outer.rightBorderColor();
if (fRightBorderColorPrev != rightBorderColorValue) {
fRightBorderColorPrev = rightBorderColorValue;
pdman.set4fv(fRightBorderColorVar, 1, rightBorderColorValue.fRGBA);
pdman.set4fv(fRightBorderColorVar, 1, rightBorderColorValue.vec());
}
}
}
GrColor4f fLeftBorderColorPrev = GrColor4f::kIllegalConstructor;
GrColor4f fRightBorderColorPrev = GrColor4f::kIllegalConstructor;
SkPMColor4f fLeftBorderColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fRightBorderColorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
UniformHandle fLeftBorderColorVar;
UniformHandle fRightBorderColorVar;
};

View File

@ -17,8 +17,8 @@
in fragmentProcessor colorizer;
in fragmentProcessor gradLayout;
layout(ctype=GrColor4f, tracked) in uniform half4 leftBorderColor; // t < 0.0
layout(ctype=GrColor4f, tracked) in uniform half4 rightBorderColor; // t > 1.0
layout(ctype=SkPMColor4f, tracked) in uniform half4 leftBorderColor; // t < 0.0
layout(ctype=SkPMColor4f, tracked) in uniform half4 rightBorderColor; // t > 1.0
layout(key) in bool makePremul;
// Trust the creator that this matches the color spec of the gradient

View File

@ -15,14 +15,14 @@
#include "GrCoordTransform.h"
class GrClampedGradientEffect : public GrFragmentProcessor {
public:
const GrColor4f& leftBorderColor() const { return fLeftBorderColor; }
const GrColor4f& rightBorderColor() const { return fRightBorderColor; }
const SkPMColor4f& leftBorderColor() const { return fLeftBorderColor; }
const SkPMColor4f& rightBorderColor() const { return fRightBorderColor; }
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, GrColor4f leftBorderColor,
GrColor4f rightBorderColor, bool makePremul, bool 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));
@ -34,8 +34,8 @@ public:
private:
GrClampedGradientEffect(std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
GrColor4f leftBorderColor, GrColor4f rightBorderColor, bool makePremul,
bool colorsAreOpaque)
SkPMColor4f leftBorderColor, SkPMColor4f rightBorderColor,
bool makePremul, bool colorsAreOpaque)
: INHERITED(kGrClampedGradientEffect_ClassID,
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag |
(colorsAreOpaque && gradLayout->preservesOpaqueInput()
@ -52,8 +52,8 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
GrColor4f fLeftBorderColor;
GrColor4f fRightBorderColor;
SkPMColor4f fLeftBorderColor;
SkPMColor4f fRightBorderColor;
bool fMakePremul;
bool fColorsAreOpaque;
typedef GrFragmentProcessor INHERITED;

View File

@ -60,25 +60,25 @@ private:
const GrDualIntervalGradientColorizer& _outer =
_proc.cast<GrDualIntervalGradientColorizer>();
{
const GrColor4f& scale01Value = _outer.scale01();
const SkPMColor4f& scale01Value = _outer.scale01();
if (fScale01Prev != scale01Value) {
fScale01Prev = scale01Value;
pdman.set4fv(fScale01Var, 1, scale01Value.fRGBA);
pdman.set4fv(fScale01Var, 1, scale01Value.vec());
}
const GrColor4f& bias01Value = _outer.bias01();
const SkPMColor4f& bias01Value = _outer.bias01();
if (fBias01Prev != bias01Value) {
fBias01Prev = bias01Value;
pdman.set4fv(fBias01Var, 1, bias01Value.fRGBA);
pdman.set4fv(fBias01Var, 1, bias01Value.vec());
}
const GrColor4f& scale23Value = _outer.scale23();
const SkPMColor4f& scale23Value = _outer.scale23();
if (fScale23Prev != scale23Value) {
fScale23Prev = scale23Value;
pdman.set4fv(fScale23Var, 1, scale23Value.fRGBA);
pdman.set4fv(fScale23Var, 1, scale23Value.vec());
}
const GrColor4f& bias23Value = _outer.bias23();
const SkPMColor4f& bias23Value = _outer.bias23();
if (fBias23Prev != bias23Value) {
fBias23Prev = bias23Value;
pdman.set4fv(fBias23Var, 1, bias23Value.fRGBA);
pdman.set4fv(fBias23Var, 1, bias23Value.vec());
}
float thresholdValue = _outer.threshold();
if (fThresholdPrev != thresholdValue) {
@ -87,10 +87,10 @@ private:
}
}
}
GrColor4f fScale01Prev = GrColor4f::kIllegalConstructor;
GrColor4f fBias01Prev = GrColor4f::kIllegalConstructor;
GrColor4f fScale23Prev = GrColor4f::kIllegalConstructor;
GrColor4f fBias23Prev = GrColor4f::kIllegalConstructor;
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;
@ -125,24 +125,24 @@ std::unique_ptr<GrFragmentProcessor> GrDualIntervalGradientColorizer::clone() co
return std::unique_ptr<GrFragmentProcessor>(new GrDualIntervalGradientColorizer(*this));
}
std::unique_ptr<GrFragmentProcessor> GrDualIntervalGradientColorizer::Make(const GrColor4f& c0,
const GrColor4f& c1,
const GrColor4f& c2,
const GrColor4f& c3,
std::unique_ptr<GrFragmentProcessor> GrDualIntervalGradientColorizer::Make(const SkPMColor4f& c0,
const SkPMColor4f& c1,
const SkPMColor4f& c2,
const SkPMColor4f& c3,
float threshold) {
// Derive scale and biases from the 4 colors and threshold
auto vc0 = Sk4f::Load(c0.fRGBA);
auto vc1 = Sk4f::Load(c1.fRGBA);
auto vc0 = Sk4f::Load(c0.vec());
auto vc1 = Sk4f::Load(c1.vec());
auto scale01 = (vc1 - vc0) / threshold;
// bias01 = c0
auto vc2 = Sk4f::Load(c2.fRGBA);
auto vc3 = Sk4f::Load(c3.fRGBA);
auto vc2 = Sk4f::Load(c2.vec());
auto vc3 = Sk4f::Load(c3.vec());
auto scale23 = (vc3 - vc2) / (1 - threshold);
auto bias23 = vc2 - threshold * scale23;
return std::unique_ptr<GrFragmentProcessor>(new GrDualIntervalGradientColorizer(
GrColor4f(scale01[0], scale01[1], scale01[2], scale01[3]), c0,
GrColor4f(scale23[0], scale23[1], scale23[2], scale23[3]),
GrColor4f(bias23[0], bias23[1], bias23[2], bias23[3]), threshold));
{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

@ -8,12 +8,12 @@
// Models two intervals (so 4 colors), that are connected at a specific threshold point.
// Bias and scale for 0 to threshold
layout(ctype=GrColor4f, tracked) in uniform float4 scale01;
layout(ctype=GrColor4f, tracked) in uniform float4 bias01;
layout(ctype=SkPMColor4f, tracked) in uniform float4 scale01;
layout(ctype=SkPMColor4f, tracked) in uniform float4 bias01;
// Bias and scale for threshold to 1
layout(ctype=GrColor4f, tracked) in uniform float4 scale23;
layout(ctype=GrColor4f, tracked) in uniform float4 bias23;
layout(ctype=SkPMColor4f, tracked) in uniform float4 scale23;
layout(ctype=SkPMColor4f, tracked) in uniform float4 bias23;
layout(tracked) in uniform half threshold;
@ -35,28 +35,28 @@ void main() {
//////////////////////////////////////////////////////////////////////////////
@make {
static std::unique_ptr<GrFragmentProcessor> Make(const GrColor4f& c0, const GrColor4f& c1,
const GrColor4f& c2, const GrColor4f& c3,
static std::unique_ptr<GrFragmentProcessor> Make(const SkPMColor4f& c0, const SkPMColor4f& c1,
const SkPMColor4f& c2, const SkPMColor4f& c3,
float threshold);
}
@cppEnd {
std::unique_ptr<GrFragmentProcessor> GrDualIntervalGradientColorizer::Make(
const GrColor4f& c0, const GrColor4f& c1, const GrColor4f& c2, const GrColor4f& c3, float threshold) {
const SkPMColor4f& c0, const SkPMColor4f& c1, const SkPMColor4f& c2, const SkPMColor4f& c3, float threshold) {
// Derive scale and biases from the 4 colors and threshold
auto vc0 = Sk4f::Load(c0.fRGBA);
auto vc1 = Sk4f::Load(c1.fRGBA);
auto vc0 = Sk4f::Load(c0.vec());
auto vc1 = Sk4f::Load(c1.vec());
auto scale01 = (vc1 - vc0) / threshold;
// bias01 = c0
auto vc2 = Sk4f::Load(c2.fRGBA);
auto vc3 = Sk4f::Load(c3.fRGBA);
auto vc2 = Sk4f::Load(c2.vec());
auto vc3 = Sk4f::Load(c3.vec());
auto scale23 = (vc3 - vc2) / (1 - threshold);
auto bias23 = vc2 - threshold * scale23;
return std::unique_ptr<GrFragmentProcessor>(new GrDualIntervalGradientColorizer(
GrColor4f(scale01[0], scale01[1], scale01[2], scale01[3]), c0,
GrColor4f(scale23[0], scale23[1], scale23[2], scale23[3]),
GrColor4f(bias23[0], bias23[1], bias23[2], bias23[3]), threshold));
{ 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

@ -15,22 +15,22 @@
#include "GrCoordTransform.h"
class GrDualIntervalGradientColorizer : public GrFragmentProcessor {
public:
const GrColor4f& scale01() const { return fScale01; }
const GrColor4f& bias01() const { return fBias01; }
const GrColor4f& scale23() const { return fScale23; }
const GrColor4f& bias23() const { return fBias23; }
const SkPMColor4f& scale01() const { return fScale01; }
const SkPMColor4f& bias01() const { return fBias01; }
const SkPMColor4f& scale23() const { return fScale23; }
const SkPMColor4f& bias23() const { return fBias23; }
float threshold() const { return fThreshold; }
static std::unique_ptr<GrFragmentProcessor> Make(const GrColor4f& c0, const GrColor4f& c1,
const GrColor4f& c2, const GrColor4f& c3,
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(GrColor4f scale01, GrColor4f bias01, GrColor4f scale23,
GrColor4f bias23, float threshold)
GrDualIntervalGradientColorizer(SkPMColor4f scale01, SkPMColor4f bias01, SkPMColor4f scale23,
SkPMColor4f bias23, float threshold)
: INHERITED(kGrDualIntervalGradientColorizer_ClassID, kNone_OptimizationFlags)
, fScale01(scale01)
, fBias01(bias01)
@ -41,10 +41,10 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
GrColor4f fScale01;
GrColor4f fBias01;
GrColor4f fScale23;
GrColor4f fBias23;
SkPMColor4f fScale01;
SkPMColor4f fBias01;
SkPMColor4f fScale23;
SkPMColor4f fBias23;
float fThreshold;
typedef GrFragmentProcessor INHERITED;
};

View File

@ -125,7 +125,7 @@ void GrGradientBitmapCache::add(const void* buffer, size_t len, const SkBitmap&
///////////////////////////////////////////////////////////////////////////////
void GrGradientBitmapCache::fillGradient(const GrColor4f* colors, const SkScalar* positions,
void GrGradientBitmapCache::fillGradient(const SkPMColor4f* colors, const SkScalar* positions,
int count, SkColorType colorType, SkBitmap* bitmap) {
SkHalf* pixelsF16 = reinterpret_cast<SkHalf*>(bitmap->getPixels());
uint32_t* pixels32 = reinterpret_cast<uint32_t*>(bitmap->getPixels());
@ -155,8 +155,8 @@ void GrGradientBitmapCache::fillGradient(const GrColor4f* colors, const SkScalar
SkIntToScalar(fResolution - 1));
if (nextIndex > prevIndex) {
Sk4f c0 = Sk4f::Load(colors[i - 1].fRGBA),
c1 = Sk4f::Load(colors[i ].fRGBA);
Sk4f c0 = Sk4f::Load(colors[i - 1].vec()),
c1 = Sk4f::Load(colors[i ].vec());
Sk4f step = Sk4f(1.0f / static_cast<float>(nextIndex - prevIndex));
Sk4f delta = (c1 - c0) * step;
@ -171,11 +171,11 @@ void GrGradientBitmapCache::fillGradient(const GrColor4f* colors, const SkScalar
SkASSERT(prevIndex == fResolution - 1);
}
void GrGradientBitmapCache::getGradient(const GrColor4f* colors, const SkScalar* positions,
void GrGradientBitmapCache::getGradient(const SkPMColor4f* colors, const SkScalar* positions,
int count, SkColorType colorType, SkAlphaType alphaType, SkBitmap* bitmap) {
// build our key: [numColors + colors[] + positions[] + alphaType + colorType ]
static_assert(sizeof(GrColor4f) % sizeof(int32_t) == 0, "");
const int colorsAsIntCount = count * sizeof(GrColor4f) / sizeof(int32_t);
static_assert(sizeof(SkPMColor4f) % sizeof(int32_t) == 0, "");
const int colorsAsIntCount = count * sizeof(SkPMColor4f) / sizeof(int32_t);
int keyCount = 1 + colorsAsIntCount + 1 + 1;
if (count > 2) {
keyCount += count - 1;
@ -185,7 +185,7 @@ void GrGradientBitmapCache::getGradient(const GrColor4f* colors, const SkScalar*
int32_t* buffer = storage.get();
*buffer++ = count;
memcpy(buffer, colors, count * sizeof(GrColor4f));
memcpy(buffer, colors, count * sizeof(SkPMColor4f));
buffer += colorsAsIntCount;
if (count > 2) {
for (int i = 1; i < count; i++) {

View File

@ -12,7 +12,7 @@
#include "SkBitmap.h"
#include "SkMutex.h"
#include "SkNoncopyable.h"
#include "GrColor.h"
#include "SkPM4f.h"
class GrGradientBitmapCache : SkNoncopyable {
public:
@ -21,7 +21,7 @@ public:
// Assumes colors are compatible with the specified alphaType (e.g. if it's premul then colors
// are already premultiplied). Thread safe.
void getGradient(const GrColor4f* colors, const SkScalar* positions, int count,
void getGradient(const SkPMColor4f* colors, const SkScalar* positions, int count,
SkColorType colorType, SkAlphaType alphaType, SkBitmap* bitmap);
private:
@ -41,7 +41,7 @@ private:
bool find(const void* buffer, size_t len, SkBitmap*) const;
void add(const void* buffer, size_t len, const SkBitmap&);
void fillGradient(const GrColor4f* colors, const SkScalar* positions, int count,
void fillGradient(const SkPMColor4f* colors, const SkScalar* positions, int count,
SkColorType colorType, SkBitmap* bitmap);
#ifdef SK_DEBUG

View File

@ -36,7 +36,7 @@ static const int kGradientTextureSize = 256;
// NOTE: signature takes raw pointers to the color/pos arrays and a count to make it easy for
// MakeColorizer to transparently take care of hard stops at the end points of the gradient.
static std::unique_ptr<GrFragmentProcessor> make_textured_colorizer(const GrColor4f* colors,
static std::unique_ptr<GrFragmentProcessor> make_textured_colorizer(const SkPMColor4f* colors,
const SkScalar* positions, int count, bool premul, const GrFPArgs& args) {
static GrGradientBitmapCache gCache(kMaxNumCachedGradientBitmaps, kGradientTextureSize);
@ -66,7 +66,7 @@ static std::unique_ptr<GrFragmentProcessor> make_textured_colorizer(const GrColo
// Analyze the shader's color stops and positions and chooses an appropriate colorizer to represent
// the gradient.
static std::unique_ptr<GrFragmentProcessor> make_colorizer(const GrColor4f* colors,
static std::unique_ptr<GrFragmentProcessor> make_colorizer(const SkPMColor4f* colors,
const SkScalar* positions, int count, bool premul, const GrFPArgs& args) {
// If there are hard stops at the beginning or end, the first and/or last color should be
// ignored by the colorizer since it should only be used in a clamped border color. By detecting
@ -156,19 +156,18 @@ static std::unique_ptr<GrFragmentProcessor> make_gradient(const SkGradientShader
return nullptr;
}
// Convert all colors into destination space and into GrColor4fs, and handle
// Convert all colors into destination space and into SkPMColor4fs, and handle
// premul issues depending on the interpolation mode
bool inputPremul = shader.getGradFlags() & SkGradientShader::kInterpolateColorsInPremul_Flag;
bool allOpaque = true;
SkAutoSTMalloc<4, GrColor4f> colors(shader.fColorCount);
SkAutoSTMalloc<4, SkPMColor4f> colors(shader.fColorCount);
SkColor4fXformer xformedColors(shader.fOrigColors4f, shader.fColorCount,
shader.fColorSpace.get(), args.fDstColorSpaceInfo->colorSpace());
for (int i = 0; i < shader.fColorCount; i++) {
colors[i] = GrColor4f::FromRGBA4f(xformedColors.fColors[i]);
if (inputPremul) {
colors[i] = colors[i].premul();
}
if (allOpaque && !SkScalarNearlyEqual(colors[i].fRGBA[3], 1.0)) {
const SkColor4f& upmColor = xformedColors.fColors[i];
colors[i] = inputPremul ? upmColor.premul()
: SkPMColor4f{ upmColor.fR, upmColor.fG, upmColor.fB, upmColor.fA };
if (allOpaque && !SkScalarNearlyEqual(colors[i].fA, 1.0)) {
allOpaque = false;
}
}
@ -226,7 +225,7 @@ static std::unique_ptr<GrFragmentProcessor> make_gradient(const SkGradientShader
// Even if the gradient colors are opaque, the decal borders are transparent so
// disable that optimization
master = GrClampedGradientEffect::Make(std::move(colorizer), std::move(layout),
GrColor4f::TransparentBlack(), GrColor4f::TransparentBlack(),
SK_PMColor4fTRANSPARENT, SK_PMColor4fTRANSPARENT,
makePremul, /* colorsAreOpaque */ false);
break;
}

View File

@ -43,20 +43,20 @@ private:
const GrSingleIntervalGradientColorizer& _outer =
_proc.cast<GrSingleIntervalGradientColorizer>();
{
const GrColor4f& startValue = _outer.start();
const SkPMColor4f& startValue = _outer.start();
if (fStartPrev != startValue) {
fStartPrev = startValue;
pdman.set4fv(fStartVar, 1, startValue.fRGBA);
pdman.set4fv(fStartVar, 1, startValue.vec());
}
const GrColor4f& endValue = _outer.end();
const SkPMColor4f& endValue = _outer.end();
if (fEndPrev != endValue) {
fEndPrev = endValue;
pdman.set4fv(fEndVar, 1, endValue.fRGBA);
pdman.set4fv(fEndVar, 1, endValue.vec());
}
}
}
GrColor4f fStartPrev = GrColor4f::kIllegalConstructor;
GrColor4f fEndPrev = GrColor4f::kIllegalConstructor;
SkPMColor4f fStartPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
SkPMColor4f fEndPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
UniformHandle fStartVar;
UniformHandle fEndVar;
};

View File

@ -9,8 +9,8 @@
// two end points based on t. But it serves as a good test for connecting all of the plumbing into a
// functional gradient shader.
layout(ctype=GrColor4f, tracked) in uniform half4 start;
layout(ctype=GrColor4f, tracked) in uniform half4 end;
layout(ctype=SkPMColor4f, tracked) in uniform half4 start;
layout(ctype=SkPMColor4f, tracked) in uniform half4 end;
void main() {
half t = sk_InColor.x;

View File

@ -15,9 +15,9 @@
#include "GrCoordTransform.h"
class GrSingleIntervalGradientColorizer : public GrFragmentProcessor {
public:
const GrColor4f& start() const { return fStart; }
const GrColor4f& end() const { return fEnd; }
static std::unique_ptr<GrFragmentProcessor> Make(GrColor4f start, GrColor4f end) {
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));
}
@ -26,7 +26,7 @@ public:
const char* name() const override { return "SingleIntervalGradientColorizer"; }
private:
GrSingleIntervalGradientColorizer(GrColor4f start, GrColor4f end)
GrSingleIntervalGradientColorizer(SkPMColor4f start, SkPMColor4f end)
: INHERITED(kGrSingleIntervalGradientColorizer_ClassID, kNone_OptimizationFlags)
, fStart(start)
, fEnd(end) {}
@ -34,8 +34,8 @@ private:
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
GrColor4f fStart;
GrColor4f fEnd;
SkPMColor4f fStart;
SkPMColor4f fEnd;
typedef GrFragmentProcessor INHERITED;
};
#endif

View File

@ -187,49 +187,49 @@ private:
const GrUnrolledBinaryGradientColorizer& _outer =
_proc.cast<GrUnrolledBinaryGradientColorizer>();
{
pdman.set4fv(fScale0_1Var, 1, (_outer.scale0_1()).fRGBA);
pdman.set4fv(fScale0_1Var, 1, (_outer.scale0_1()).vec());
if (fScale2_3Var.isValid()) {
pdman.set4fv(fScale2_3Var, 1, (_outer.scale2_3()).fRGBA);
pdman.set4fv(fScale2_3Var, 1, (_outer.scale2_3()).vec());
}
if (fScale4_5Var.isValid()) {
pdman.set4fv(fScale4_5Var, 1, (_outer.scale4_5()).fRGBA);
pdman.set4fv(fScale4_5Var, 1, (_outer.scale4_5()).vec());
}
if (fScale6_7Var.isValid()) {
pdman.set4fv(fScale6_7Var, 1, (_outer.scale6_7()).fRGBA);
pdman.set4fv(fScale6_7Var, 1, (_outer.scale6_7()).vec());
}
if (fScale8_9Var.isValid()) {
pdman.set4fv(fScale8_9Var, 1, (_outer.scale8_9()).fRGBA);
pdman.set4fv(fScale8_9Var, 1, (_outer.scale8_9()).vec());
}
if (fScale10_11Var.isValid()) {
pdman.set4fv(fScale10_11Var, 1, (_outer.scale10_11()).fRGBA);
pdman.set4fv(fScale10_11Var, 1, (_outer.scale10_11()).vec());
}
if (fScale12_13Var.isValid()) {
pdman.set4fv(fScale12_13Var, 1, (_outer.scale12_13()).fRGBA);
pdman.set4fv(fScale12_13Var, 1, (_outer.scale12_13()).vec());
}
if (fScale14_15Var.isValid()) {
pdman.set4fv(fScale14_15Var, 1, (_outer.scale14_15()).fRGBA);
pdman.set4fv(fScale14_15Var, 1, (_outer.scale14_15()).vec());
}
pdman.set4fv(fBias0_1Var, 1, (_outer.bias0_1()).fRGBA);
pdman.set4fv(fBias0_1Var, 1, (_outer.bias0_1()).vec());
if (fBias2_3Var.isValid()) {
pdman.set4fv(fBias2_3Var, 1, (_outer.bias2_3()).fRGBA);
pdman.set4fv(fBias2_3Var, 1, (_outer.bias2_3()).vec());
}
if (fBias4_5Var.isValid()) {
pdman.set4fv(fBias4_5Var, 1, (_outer.bias4_5()).fRGBA);
pdman.set4fv(fBias4_5Var, 1, (_outer.bias4_5()).vec());
}
if (fBias6_7Var.isValid()) {
pdman.set4fv(fBias6_7Var, 1, (_outer.bias6_7()).fRGBA);
pdman.set4fv(fBias6_7Var, 1, (_outer.bias6_7()).vec());
}
if (fBias8_9Var.isValid()) {
pdman.set4fv(fBias8_9Var, 1, (_outer.bias8_9()).fRGBA);
pdman.set4fv(fBias8_9Var, 1, (_outer.bias8_9()).vec());
}
if (fBias10_11Var.isValid()) {
pdman.set4fv(fBias10_11Var, 1, (_outer.bias10_11()).fRGBA);
pdman.set4fv(fBias10_11Var, 1, (_outer.bias10_11()).vec());
}
if (fBias12_13Var.isValid()) {
pdman.set4fv(fBias12_13Var, 1, (_outer.bias12_13()).fRGBA);
pdman.set4fv(fBias12_13Var, 1, (_outer.bias12_13()).vec());
}
if (fBias14_15Var.isValid()) {
pdman.set4fv(fBias14_15Var, 1, (_outer.bias14_15()).fRGBA);
pdman.set4fv(fBias14_15Var, 1, (_outer.bias14_15()).vec());
}
pdman.set4fv(fThresholds1_7Var, 1,
reinterpret_cast<const float*>(&(_outer.thresholds1_7())));
@ -315,7 +315,7 @@ std::unique_ptr<GrFragmentProcessor> GrUnrolledBinaryGradientColorizer::clone()
static const int kMaxIntervals = 8;
std::unique_ptr<GrFragmentProcessor> GrUnrolledBinaryGradientColorizer::Make(
const GrColor4f* 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
@ -329,8 +329,8 @@ std::unique_ptr<GrFragmentProcessor> GrUnrolledBinaryGradientColorizer::Make(
// The raster implementation also uses scales and biases, but since they must be calculated
// after the dst color space is applied, it limits our ability to cache their values.
GrColor4f scales[kMaxIntervals];
GrColor4f biases[kMaxIntervals];
SkPMColor4f scales[kMaxIntervals];
SkPMColor4f biases[kMaxIntervals];
SkScalar thresholds[kMaxIntervals];
int intervalCount = 0;
@ -352,8 +352,8 @@ std::unique_ptr<GrFragmentProcessor> GrUnrolledBinaryGradientColorizer::Make(
continue;
}
auto c0 = Sk4f::Load(colors[i].fRGBA);
auto c1 = Sk4f::Load(colors[i + 1].fRGBA);
auto c0 = Sk4f::Load(colors[i].vec());
auto c1 = Sk4f::Load(colors[i + 1].vec());
auto scale = (c1 - c0) / dt;
auto bias = c0 - t0 * scale;
@ -366,8 +366,8 @@ 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] = GrColor4f::TransparentBlack();
biases[i] = GrColor4f::TransparentBlack();
scales[i] = SK_PMColor4fTRANSPARENT;
biases[i] = SK_PMColor4fTRANSPARENT;
thresholds[i] = 0.0;
}

View File

@ -14,23 +14,23 @@ layout(key) in int intervalCount;
// With the current hardstop detection threshold of 0.00024, the maximum scale and bias values
// will be on the order of 4k (since they divide by dt). That is well outside the precision
// capabilities of half floats, which can lead to inaccurate gradient calculations
layout(ctype=GrColor4f) in uniform float4 scale0_1;
layout(ctype=GrColor4f, when=intervalCount > 1) in uniform float4 scale2_3;
layout(ctype=GrColor4f, when=intervalCount > 2) in uniform float4 scale4_5;
layout(ctype=GrColor4f, when=intervalCount > 3) in uniform float4 scale6_7;
layout(ctype=GrColor4f, when=intervalCount > 4) in uniform float4 scale8_9;
layout(ctype=GrColor4f, when=intervalCount > 5) in uniform float4 scale10_11;
layout(ctype=GrColor4f, when=intervalCount > 6) in uniform float4 scale12_13;
layout(ctype=GrColor4f, when=intervalCount > 7) in uniform float4 scale14_15;
layout(ctype=SkPMColor4f) in uniform float4 scale0_1;
layout(ctype=SkPMColor4f, when=intervalCount > 1) in uniform float4 scale2_3;
layout(ctype=SkPMColor4f, when=intervalCount > 2) in uniform float4 scale4_5;
layout(ctype=SkPMColor4f, when=intervalCount > 3) in uniform float4 scale6_7;
layout(ctype=SkPMColor4f, when=intervalCount > 4) in uniform float4 scale8_9;
layout(ctype=SkPMColor4f, when=intervalCount > 5) in uniform float4 scale10_11;
layout(ctype=SkPMColor4f, when=intervalCount > 6) in uniform float4 scale12_13;
layout(ctype=SkPMColor4f, when=intervalCount > 7) in uniform float4 scale14_15;
layout(ctype=GrColor4f) in uniform float4 bias0_1;
layout(ctype=GrColor4f, when=intervalCount > 1) in uniform float4 bias2_3;
layout(ctype=GrColor4f, when=intervalCount > 2) in uniform float4 bias4_5;
layout(ctype=GrColor4f, when=intervalCount > 3) in uniform float4 bias6_7;
layout(ctype=GrColor4f, when=intervalCount > 4) in uniform float4 bias8_9;
layout(ctype=GrColor4f, when=intervalCount > 5) in uniform float4 bias10_11;
layout(ctype=GrColor4f, when=intervalCount > 6) in uniform float4 bias12_13;
layout(ctype=GrColor4f, when=intervalCount > 7) in uniform float4 bias14_15;
layout(ctype=SkPMColor4f) in uniform float4 bias0_1;
layout(ctype=SkPMColor4f, when=intervalCount > 1) in uniform float4 bias2_3;
layout(ctype=SkPMColor4f, when=intervalCount > 2) in uniform float4 bias4_5;
layout(ctype=SkPMColor4f, when=intervalCount > 3) in uniform float4 bias6_7;
layout(ctype=SkPMColor4f, when=intervalCount > 4) in uniform float4 bias8_9;
layout(ctype=SkPMColor4f, when=intervalCount > 5) in uniform float4 bias10_11;
layout(ctype=SkPMColor4f, when=intervalCount > 6) in uniform float4 bias12_13;
layout(ctype=SkPMColor4f, when=intervalCount > 7) in uniform float4 bias14_15;
// The 7 threshold positions that define the boundaries of the 8 intervals (excluding t = 0, and t =
// 1) are packed into two half4's instead of having up to 7 separate scalar uniforms. For low
@ -114,7 +114,7 @@ void main() {
}
@make {
static std::unique_ptr<GrFragmentProcessor> Make(const GrColor4f* colors,
static std::unique_ptr<GrFragmentProcessor> Make(const SkPMColor4f* colors,
const SkScalar* positions,
int count);
}
@ -122,7 +122,7 @@ void main() {
@cppEnd {
static const int kMaxIntervals = 8;
std::unique_ptr<GrFragmentProcessor> GrUnrolledBinaryGradientColorizer::Make(
const GrColor4f* 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
@ -136,8 +136,8 @@ void main() {
// The raster implementation also uses scales and biases, but since they must be calculated
// after the dst color space is applied, it limits our ability to cache their values.
GrColor4f scales[kMaxIntervals];
GrColor4f biases[kMaxIntervals];
SkPMColor4f scales[kMaxIntervals];
SkPMColor4f biases[kMaxIntervals];
SkScalar thresholds[kMaxIntervals];
int intervalCount = 0;
@ -159,8 +159,8 @@ void main() {
continue;
}
auto c0 = Sk4f::Load(colors[i].fRGBA);
auto c1 = Sk4f::Load(colors[i + 1].fRGBA);
auto c0 = Sk4f::Load(colors[i].vec());
auto c1 = Sk4f::Load(colors[i + 1].vec());
auto scale = (c1 - c0) / dt;
auto bias = c0 - t0 * scale;
@ -173,8 +173,8 @@ void main() {
// For isEqual to make sense, set the unused values to something consistent
for (int i = intervalCount; i < kMaxIntervals; i++) {
scales[i] = GrColor4f::TransparentBlack();
biases[i] = GrColor4f::TransparentBlack();
scales[i] = SK_PMColor4fTRANSPARENT;
biases[i] = SK_PMColor4fTRANSPARENT;
thresholds[i] = 0.0;
}

View File

@ -17,26 +17,26 @@ class GrUnrolledBinaryGradientColorizer : public GrFragmentProcessor {
public:
static const int kMaxColorCount = 16;
int32_t intervalCount() const { return fIntervalCount; }
const GrColor4f& scale0_1() const { return fScale0_1; }
const GrColor4f& scale2_3() const { return fScale2_3; }
const GrColor4f& scale4_5() const { return fScale4_5; }
const GrColor4f& scale6_7() const { return fScale6_7; }
const GrColor4f& scale8_9() const { return fScale8_9; }
const GrColor4f& scale10_11() const { return fScale10_11; }
const GrColor4f& scale12_13() const { return fScale12_13; }
const GrColor4f& scale14_15() const { return fScale14_15; }
const GrColor4f& bias0_1() const { return fBias0_1; }
const GrColor4f& bias2_3() const { return fBias2_3; }
const GrColor4f& bias4_5() const { return fBias4_5; }
const GrColor4f& bias6_7() const { return fBias6_7; }
const GrColor4f& bias8_9() const { return fBias8_9; }
const GrColor4f& bias10_11() const { return fBias10_11; }
const GrColor4f& bias12_13() const { return fBias12_13; }
const GrColor4f& bias14_15() const { return fBias14_15; }
const SkPMColor4f& scale0_1() const { return fScale0_1; }
const SkPMColor4f& scale2_3() const { return fScale2_3; }
const SkPMColor4f& scale4_5() const { return fScale4_5; }
const SkPMColor4f& scale6_7() const { return fScale6_7; }
const SkPMColor4f& scale8_9() const { return fScale8_9; }
const SkPMColor4f& scale10_11() const { return fScale10_11; }
const SkPMColor4f& scale12_13() const { return fScale12_13; }
const SkPMColor4f& scale14_15() const { return fScale14_15; }
const SkPMColor4f& bias0_1() const { return fBias0_1; }
const SkPMColor4f& bias2_3() const { return fBias2_3; }
const SkPMColor4f& bias4_5() const { return fBias4_5; }
const SkPMColor4f& bias6_7() const { return fBias6_7; }
const SkPMColor4f& bias8_9() const { return fBias8_9; }
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; }
static std::unique_ptr<GrFragmentProcessor> Make(const GrColor4f* colors,
static std::unique_ptr<GrFragmentProcessor> Make(const SkPMColor4f* colors,
const SkScalar* positions,
int count);
GrUnrolledBinaryGradientColorizer(const GrUnrolledBinaryGradientColorizer& src);
@ -45,22 +45,22 @@ public:
private:
GrUnrolledBinaryGradientColorizer(int32_t intervalCount,
GrColor4f scale0_1,
GrColor4f scale2_3,
GrColor4f scale4_5,
GrColor4f scale6_7,
GrColor4f scale8_9,
GrColor4f scale10_11,
GrColor4f scale12_13,
GrColor4f scale14_15,
GrColor4f bias0_1,
GrColor4f bias2_3,
GrColor4f bias4_5,
GrColor4f bias6_7,
GrColor4f bias8_9,
GrColor4f bias10_11,
GrColor4f bias12_13,
GrColor4f bias14_15,
SkPMColor4f scale0_1,
SkPMColor4f scale2_3,
SkPMColor4f scale4_5,
SkPMColor4f scale6_7,
SkPMColor4f scale8_9,
SkPMColor4f scale10_11,
SkPMColor4f scale12_13,
SkPMColor4f scale14_15,
SkPMColor4f bias0_1,
SkPMColor4f bias2_3,
SkPMColor4f bias4_5,
SkPMColor4f bias6_7,
SkPMColor4f bias8_9,
SkPMColor4f bias10_11,
SkPMColor4f bias12_13,
SkPMColor4f bias14_15,
SkRect thresholds1_7,
SkRect thresholds9_13)
: INHERITED(kGrUnrolledBinaryGradientColorizer_ClassID, kNone_OptimizationFlags)
@ -88,22 +88,22 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
int32_t fIntervalCount;
GrColor4f fScale0_1;
GrColor4f fScale2_3;
GrColor4f fScale4_5;
GrColor4f fScale6_7;
GrColor4f fScale8_9;
GrColor4f fScale10_11;
GrColor4f fScale12_13;
GrColor4f fScale14_15;
GrColor4f fBias0_1;
GrColor4f fBias2_3;
GrColor4f fBias4_5;
GrColor4f fBias6_7;
GrColor4f fBias8_9;
GrColor4f fBias10_11;
GrColor4f fBias12_13;
GrColor4f fBias14_15;
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;