makeColorSpace() for SkColorFilterShader and SkLightingShader
Fixes 4 gms in gbr-8888 config. Bug: skia:6516 Change-Id: I9da839eb0211910989be35db0e13c0e1bbfa185d Reviewed-on: https://skia-review.googlesource.com/13964 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Matt Sarett <msarett@google.com>
This commit is contained in:
parent
28a7ad2ba7
commit
72266eeca0
@ -113,6 +113,8 @@ public:
|
|||||||
bool operator!= (const Light& b) { return !(this->operator==(b)); }
|
bool operator!= (const Light& b) { return !(this->operator==(b)); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class SkLights;
|
||||||
|
|
||||||
LightType fType;
|
LightType fType;
|
||||||
SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel.
|
SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel.
|
||||||
|
|
||||||
@ -191,6 +193,10 @@ private:
|
|||||||
SkLights() {
|
SkLights() {
|
||||||
fAmbientLightColor.set(0.0f, 0.0f, 0.0f);
|
fAmbientLightColor.set(0.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
friend class SkLightingShaderImpl;
|
||||||
|
sk_sp<SkLights> makeColorSpace(SkColorSpaceXformer* xformer) const;
|
||||||
|
|
||||||
SkTArray<Light> fLights;
|
SkTArray<Light> fLights;
|
||||||
SkColor3f fAmbientLightColor;
|
SkColor3f fAmbientLightColor;
|
||||||
typedef SkRefCnt INHERITED;
|
typedef SkRefCnt INHERITED;
|
||||||
|
@ -517,7 +517,9 @@ private:
|
|||||||
friend class SkLocalMatrixShader;
|
friend class SkLocalMatrixShader;
|
||||||
friend class SkBitmapProcLegacyShader; // for computeTotalInverse()
|
friend class SkBitmapProcLegacyShader; // for computeTotalInverse()
|
||||||
friend class SkComposeShader;
|
friend class SkComposeShader;
|
||||||
|
friend class SkColorFilterShader;
|
||||||
friend class SkColorSpaceXformer;
|
friend class SkColorSpaceXformer;
|
||||||
|
friend class SkLightingShaderImpl;
|
||||||
|
|
||||||
typedef SkFlattenable INHERITED;
|
typedef SkFlattenable INHERITED;
|
||||||
};
|
};
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "SkArenaAlloc.h"
|
#include "SkArenaAlloc.h"
|
||||||
#include "SkColorFilterShader.h"
|
#include "SkColorFilterShader.h"
|
||||||
|
#include "SkColorSpaceXformer.h"
|
||||||
#include "SkReadBuffer.h"
|
#include "SkReadBuffer.h"
|
||||||
#include "SkWriteBuffer.h"
|
#include "SkWriteBuffer.h"
|
||||||
#include "SkShader.h"
|
#include "SkShader.h"
|
||||||
@ -62,6 +63,9 @@ SkShader::Context* SkColorFilterShader::onMakeContext(const ContextRec& rec,
|
|||||||
return alloc->make<FilterShaderContext>(*this, shaderContext, rec);
|
return alloc->make<FilterShaderContext>(*this, shaderContext, rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sk_sp<SkShader> SkColorFilterShader::onMakeColorSpace(SkColorSpaceXformer* xformer) const {
|
||||||
|
return fShader->makeColorSpace(xformer)->makeWithColorFilter(xformer->apply(fFilter.get()));
|
||||||
|
}
|
||||||
|
|
||||||
SkColorFilterShader::FilterShaderContext::FilterShaderContext(
|
SkColorFilterShader::FilterShaderContext::FilterShaderContext(
|
||||||
const SkColorFilterShader& filterShader,
|
const SkColorFilterShader& filterShader,
|
||||||
|
@ -48,6 +48,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void flatten(SkWriteBuffer&) const override;
|
void flatten(SkWriteBuffer&) const override;
|
||||||
Context* onMakeContext(const ContextRec&, SkArenaAlloc* alloc) const override;
|
Context* onMakeContext(const ContextRec&, SkArenaAlloc* alloc) const override;
|
||||||
|
sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sk_sp<SkShader> fShader;
|
sk_sp<SkShader> fShader;
|
||||||
|
@ -83,6 +83,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void flatten(SkWriteBuffer&) const override;
|
void flatten(SkWriteBuffer&) const override;
|
||||||
Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
|
Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
|
||||||
|
sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sk_sp<SkShader> fDiffuseShader;
|
sk_sp<SkShader> fDiffuseShader;
|
||||||
@ -455,6 +456,13 @@ SkShader::Context* SkLightingShaderImpl::onMakeContext(
|
|||||||
return alloc->make<LightingShaderContext>(*this, rec, diffuseContext, normalProvider, nullptr);
|
return alloc->make<LightingShaderContext>(*this, rec, diffuseContext, normalProvider, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sk_sp<SkShader> SkLightingShaderImpl::onMakeColorSpace(SkColorSpaceXformer* xformer) const {
|
||||||
|
sk_sp<SkShader> xformedDiffuseShader =
|
||||||
|
fDiffuseShader ? fDiffuseShader->makeColorSpace(xformer) : nullptr;
|
||||||
|
return SkLightingShader::Make(std::move(xformedDiffuseShader), fNormalSource,
|
||||||
|
fLights->makeColorSpace(xformer));
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
sk_sp<SkShader> SkLightingShader::Make(sk_sp<SkShader> diffuseShader,
|
sk_sp<SkShader> SkLightingShader::Make(sk_sp<SkShader> diffuseShader,
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "SkColorSpaceXformer.h"
|
||||||
#include "SkLights.h"
|
#include "SkLights.h"
|
||||||
#include "SkReadBuffer.h"
|
#include "SkReadBuffer.h"
|
||||||
|
|
||||||
@ -59,6 +60,28 @@ sk_sp<SkLights> SkLights::MakeFromBuffer(SkReadBuffer& buf) {
|
|||||||
return builder.finish();
|
return builder.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SkColor3f xform_color(const SkColor3f& color, SkColorSpaceXformer* xformer) {
|
||||||
|
SkColor origColor = SkColorSetARGBInline(0xFF,
|
||||||
|
SkScalarRoundToInt(color.fX),
|
||||||
|
SkScalarRoundToInt(color.fY),
|
||||||
|
SkScalarRoundToInt(color.fZ));
|
||||||
|
SkColor xformedColor = xformer->apply(origColor);
|
||||||
|
return SkColor3f::Make(SkIntToScalar(SkGetPackedR32(xformedColor)),
|
||||||
|
SkIntToScalar(SkGetPackedG32(xformedColor)),
|
||||||
|
SkIntToScalar(SkGetPackedB32(xformedColor)));
|
||||||
|
}
|
||||||
|
|
||||||
|
sk_sp<SkLights> SkLights::makeColorSpace(SkColorSpaceXformer* xformer) const {
|
||||||
|
SkLights::Builder builder;
|
||||||
|
for (int i = 0; i < this->numLights(); i++) {
|
||||||
|
Light light(fLights[i].type(), xform_color(fLights[i].color(), xformer),
|
||||||
|
fLights[i].fDirOrPos, fLights[i].fIntensity, fLights[i].isRadial());
|
||||||
|
builder.add(light);
|
||||||
|
}
|
||||||
|
builder.setAmbientLightColor(xform_color(fAmbientLightColor, xformer));
|
||||||
|
return builder.finish();
|
||||||
|
}
|
||||||
|
|
||||||
void SkLights::flatten(SkWriteBuffer& buf) const {
|
void SkLights::flatten(SkWriteBuffer& buf) const {
|
||||||
buf.writeScalarArray(&this->ambientLightColor().fX, 3);
|
buf.writeScalarArray(&this->ambientLightColor().fX, 3);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user