remove old shader routines from SkColor4Shader

They don't handle drawing to untagged destinations
correctly, drawing as if sRGB rather than as if src.

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I1d312c6fcd582e0ccd3f3aaf07526e18f67f7169
Reviewed-on: https://skia-review.googlesource.com/c/166480
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2018-10-30 13:36:24 -04:00 committed by Skia Commit-Bot
parent 7abb081a69
commit a4eb9360a4
2 changed files with 41 additions and 161 deletions

View File

@ -88,39 +88,9 @@ SkShader::GradientType SkColorShader::asAGradient(GradientInfo* info) const {
return kColor_GradientType;
}
#if SK_SUPPORT_GPU
#include "SkGr.h"
#include "effects/GrConstColorProcessor.h"
std::unique_ptr<GrFragmentProcessor> SkColorShader::asFragmentProcessor(
const GrFPArgs& args) const {
SkPMColor4f color = SkColorToPMColor4f(fColor, *args.fDstColorSpaceInfo);
return GrConstColorProcessor::Make(color, GrConstColorProcessor::InputMode::kModulateA);
}
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
static unsigned unit_to_byte(float unit) {
SkASSERT(unit >= 0 && unit <= 1);
return (unsigned)(unit * 255 + 0.5);
}
static SkColor to_skcolor(SkColor4f color, SkColorSpace* cs) {
SkColorSpaceXformSteps steps{cs , kUnpremul_SkAlphaType,
sk_srgb_singleton(), kUnpremul_SkAlphaType};
steps.apply(color.vec());
color = color.pin();
return SkColorSetARGB(unit_to_byte(color.fA), unit_to_byte(color.fR),
unit_to_byte(color.fG), unit_to_byte(color.fB));
}
SkColor4Shader::SkColor4Shader(const SkColor4f& color, sk_sp<SkColorSpace> space)
: fColorSpace(std::move(space))
, fColor4(color)
, fCachedByteColor(to_skcolor(color, fColorSpace.get()))
, fColor(color)
{}
sk_sp<SkFlattenable> SkColor4Shader::CreateProc(SkReadBuffer& buffer) {
@ -135,7 +105,7 @@ sk_sp<SkFlattenable> SkColor4Shader::CreateProc(SkReadBuffer& buffer) {
}
void SkColor4Shader::flatten(SkWriteBuffer& buffer) const {
buffer.writeColor4f(fColor4);
buffer.writeColor4f(fColor);
sk_sp<SkData> colorSpaceData = fColorSpace ? fColorSpace->serialize() : nullptr;
if (colorSpaceData) {
buffer.writeBool(true);
@ -145,88 +115,12 @@ void SkColor4Shader::flatten(SkWriteBuffer& buffer) const {
}
}
uint32_t SkColor4Shader::Color4Context::getFlags() const {
return fFlags;
}
#ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
SkShaderBase::Context* SkColor4Shader::onMakeContext(const ContextRec& rec,
SkArenaAlloc* alloc) const {
return alloc->make<Color4Context>(*this, rec);
}
#endif
SkColor4Shader::Color4Context::Color4Context(const SkColor4Shader& shader,
const ContextRec& rec)
: INHERITED(shader, rec)
{
SkColor color = shader.fCachedByteColor;
unsigned a = SkAlphaMul(SkColorGetA(color), SkAlpha255To256(rec.fPaint->getAlpha()));
unsigned r = SkColorGetR(color);
unsigned g = SkColorGetG(color);
unsigned b = SkColorGetB(color);
if (a != 255) {
r = SkMulDiv255Round(r, a);
g = SkMulDiv255Round(g, a);
b = SkMulDiv255Round(b, a);
}
fPMColor = SkPackARGB32(a, r, g, b);
SkColor4f c4 = shader.fColor4;
c4.fA *= rec.fPaint->getAlpha() * (1 / 255.0f);
fPMColor4f = c4.premul();
fFlags = kConstInY32_Flag;
if (255 == a) {
fFlags |= kOpaqueAlpha_Flag;
}
}
void SkColor4Shader::Color4Context::shadeSpan(int x, int y, SkPMColor span[], int count) {
sk_memset32(span, fPMColor, count);
}
void SkColor4Shader::Color4Context::shadeSpan4f(int x, int y, SkPMColor4f span[], int count) {
for (int i = 0; i < count; ++i) {
span[i] = fPMColor4f;
}
}
// TODO: do we need an updated version of this method for color4+colorspace?
SkShader::GradientType SkColor4Shader::asAGradient(GradientInfo* info) const {
if (info) {
if (info->fColors && info->fColorCount >= 1) {
info->fColors[0] = fCachedByteColor;
}
info->fColorCount = 1;
info->fTileMode = SkShader::kRepeat_TileMode;
}
return kColor_GradientType;
}
#if SK_SUPPORT_GPU
#include "GrColorSpaceInfo.h"
#include "GrColorSpaceXform.h"
#include "SkGr.h"
#include "effects/GrConstColorProcessor.h"
std::unique_ptr<GrFragmentProcessor> SkColor4Shader::asFragmentProcessor(
const GrFPArgs& args) const {
SkColorSpaceXformSteps steps{ fColorSpace.get(), kUnpremul_SkAlphaType,
args.fDstColorSpaceInfo->colorSpace(), kUnpremul_SkAlphaType };
SkColor4f color = fColor4;
steps.apply(color.vec());
return GrConstColorProcessor::Make(color.premul(),
GrConstColorProcessor::InputMode::kModulateA);
}
#endif
sk_sp<SkShader> SkColor4Shader::onMakeColorSpace(SkColorSpaceXformer* xformer) const {
return SkShader::MakeColorShader(xformer->apply(fCachedByteColor));
SkColor4f color = fColor;
SkColorSpaceXformSteps(fColorSpace.get(), kUnpremul_SkAlphaType,
xformer->dst().get(), kUnpremul_SkAlphaType).apply(color.vec());
return SkShader::MakeColorShader(color.toSkColor());
}
sk_sp<SkShader> SkShader::MakeColorShader(const SkColor4f& color, sk_sp<SkColorSpace> space) {
@ -236,8 +130,6 @@ sk_sp<SkShader> SkShader::MakeColorShader(const SkColor4f& color, sk_sp<SkColorS
return sk_make_sp<SkColor4Shader>(color, std::move(space));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
bool SkColorShader::onAppendStages(const StageRec& rec) const {
SkColor4f color = SkColor4f::FromColor(fColor);
SkColorSpaceXformSteps(sk_srgb_singleton(), kUnpremul_SkAlphaType,
@ -247,9 +139,34 @@ bool SkColorShader::onAppendStages(const StageRec& rec) const {
}
bool SkColor4Shader::onAppendStages(const StageRec& rec) const {
SkColor4f color = fColor4;
SkColor4f color = fColor;
SkColorSpaceXformSteps(fColorSpace.get(), kUnpremul_SkAlphaType,
rec.fDstCS, kUnpremul_SkAlphaType).apply(color.vec());
rec.fPipeline->append_constant_color(rec.fAlloc, color.premul().vec());
return true;
}
#if SK_SUPPORT_GPU
#include "GrColorSpaceInfo.h"
#include "GrColorSpaceXform.h"
#include "SkGr.h"
#include "effects/GrConstColorProcessor.h"
std::unique_ptr<GrFragmentProcessor> SkColorShader::asFragmentProcessor(
const GrFPArgs& args) const {
SkPMColor4f color = SkColorToPMColor4f(fColor, *args.fDstColorSpaceInfo);
return GrConstColorProcessor::Make(color, GrConstColorProcessor::InputMode::kModulateA);
}
std::unique_ptr<GrFragmentProcessor> SkColor4Shader::asFragmentProcessor(
const GrFPArgs& args) const {
SkColorSpaceXformSteps steps{ fColorSpace.get(), kUnpremul_SkAlphaType,
args.fDstColorSpaceInfo->colorSpace(), kUnpremul_SkAlphaType };
SkColor4f color = fColor;
steps.apply(color.vec());
return GrConstColorProcessor::Make(color.premul(),
GrConstColorProcessor::InputMode::kModulateA);
}
#endif

View File

@ -50,8 +50,9 @@ public:
std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
#endif
protected:
SkColorShader(SkReadBuffer&);
private:
SK_FLATTENABLE_HOOKS(SkColorShader)
void flatten(SkWriteBuffer&) const override;
#ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
Context* onMakeContext(const ContextRec&, SkArenaAlloc* storage) const override;
@ -68,67 +69,29 @@ protected:
return SkShader::MakeColorShader(xformer->apply(fColor));
}
private:
SK_FLATTENABLE_HOOKS(SkColorShader)
SkColor fColor;
typedef SkShaderBase INHERITED;
};
class SkColor4Shader : public SkShaderBase {
public:
SkColor4Shader(const SkColor4f&, sk_sp<SkColorSpace>);
bool isOpaque() const override {
return SkColorGetA(fCachedByteColor) == 255;
}
bool isOpaque() const override { return fColor.isOpaque(); }
bool isConstant() const override { return true; }
class Color4Context : public Context {
public:
Color4Context(const SkColor4Shader& shader, const ContextRec&);
uint32_t getFlags() const override;
void shadeSpan(int x, int y, SkPMColor span[], int count) override;
void shadeSpan4f(int x, int y, SkPMColor4f[], int count) override;
private:
SkPMColor4f fPMColor4f;
SkPMColor fPMColor;
uint32_t fFlags;
typedef Context INHERITED;
};
GradientType asAGradient(GradientInfo* info) const override;
#if SK_SUPPORT_GPU
std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
#endif
protected:
SkColor4Shader(SkReadBuffer&);
void flatten(SkWriteBuffer&) const override;
#ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
#endif
bool onAsLuminanceColor(SkColor* lum) const override {
*lum = fCachedByteColor;
return true;
}
bool onAppendStages(const StageRec&) const override;
sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override;
private:
SK_FLATTENABLE_HOOKS(SkColor4Shader)
sk_sp<SkColorSpace> fColorSpace;
const SkColor4f fColor4;
const SkColor fCachedByteColor;
void flatten(SkWriteBuffer&) const override;
bool onAppendStages(const StageRec&) const override;
sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override;
typedef SkShaderBase INHERITED;
sk_sp<SkColorSpace> fColorSpace;
const SkColor4f fColor;
};
#endif