Fix SkColor4Shader
We weren't using the colorspace to initialize the cached byte color, even though onMakeColorSpace used the byte color as the starting point. Additionally, we were passing in the already-moved sk_sp, so the color space was always nullptr. With these changes, it's time to fix serialization, too. Change-Id: If6ca02684e3115b5be4febb9bd71760fe6251fd5 Reviewed-on: https://skia-review.googlesource.com/145368 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Mike Klein <mtklein@google.com> Auto-Submit: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
35eb7fa813
commit
97d0970c25
@ -105,29 +105,43 @@ static unsigned unit_to_byte(float unit) {
|
||||
return (unsigned)(unit * 255 + 0.5);
|
||||
}
|
||||
|
||||
static SkColor unit_to_skcolor(const SkColor4f& unit, SkColorSpace* cs) {
|
||||
return SkColorSetARGB(unit_to_byte(unit.fA), unit_to_byte(unit.fR),
|
||||
unit_to_byte(unit.fG), unit_to_byte(unit.fB));
|
||||
static SkColor to_skcolor(SkColor4f color, SkColorSpace* cs) {
|
||||
if (cs) {
|
||||
SkColorSpaceXformSteps steps =
|
||||
SkColorSpaceXformSteps::UnpremulToUnpremul(cs, sk_srgb_singleton());
|
||||
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(unit_to_skcolor(color.pin(), space.get()))
|
||||
, fCachedByteColor(to_skcolor(color, fColorSpace.get()))
|
||||
{}
|
||||
|
||||
sk_sp<SkFlattenable> SkColor4Shader::CreateProc(SkReadBuffer& buffer) {
|
||||
SkColor4f color;
|
||||
sk_sp<SkColorSpace> colorSpace;
|
||||
buffer.readColor4f(&color);
|
||||
if (buffer.readBool()) {
|
||||
// TODO how do we unflatten colorspaces
|
||||
sk_sp<SkData> data = buffer.readByteArrayAsData();
|
||||
colorSpace = data ? SkColorSpace::Deserialize(data->data(), data->size()) : nullptr;
|
||||
}
|
||||
return SkShader::MakeColorShader(color, nullptr);
|
||||
return SkShader::MakeColorShader(color, std::move(colorSpace));
|
||||
}
|
||||
|
||||
void SkColor4Shader::flatten(SkWriteBuffer& buffer) const {
|
||||
buffer.writeColor4f(fColor4);
|
||||
buffer.writeBool(false); // TODO how do we flatten colorspaces?
|
||||
sk_sp<SkData> colorSpaceData = fColorSpace ? fColorSpace->serialize() : nullptr;
|
||||
if (colorSpaceData) {
|
||||
buffer.writeBool(true);
|
||||
buffer.writeDataAsByteArray(colorSpaceData.get());
|
||||
} else {
|
||||
buffer.writeBool(false);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t SkColor4Shader::Color4Context::getFlags() const {
|
||||
|
Loading…
Reference in New Issue
Block a user