Index: src/core/SkNormalMapSource.cpp |
diff --git a/src/core/SkNormalSource.cpp b/src/core/SkNormalMapSource.cpp |
similarity index 57% |
copy from src/core/SkNormalSource.cpp |
copy to src/core/SkNormalMapSource.cpp |
index 38cf0bf0afc4e2b63eb22e756bada722c88a3f87..2ecf1d310df0e46ad0b49b886d149129feb5f901 100644 |
--- a/src/core/SkNormalSource.cpp |
+++ b/src/core/SkNormalMapSource.cpp |
@@ -5,8 +5,8 @@ |
* found in the LICENSE file. |
*/ |
-#include "SkError.h" |
-#include "SkErrorInternals.h" |
+#include "SkNormalMapSource.h" |
+ |
#include "SkLightingShader.h" |
#include "SkMatrix.h" |
#include "SkNormalSource.h" |
@@ -14,63 +14,7 @@ |
#include "SkReadBuffer.h" |
#include "SkWriteBuffer.h" |
-// Genretating vtable |
-SkNormalSource::~SkNormalSource() {} |
- |
-/////////////////////////////////////////////////////////////////////////////// |
- |
-class NormalMapSourceImpl : public SkNormalSource { |
-public: |
- NormalMapSourceImpl(sk_sp<SkShader> mapShader, const SkMatrix& invCTM) |
- : fMapShader(std::move(mapShader)) |
- , fInvCTM(invCTM) {} |
- |
-#if SK_SUPPORT_GPU |
- sk_sp<GrFragmentProcessor> asFragmentProcessor(const SkShader::AsFPArgs&) const override; |
-#endif |
- |
- SkNormalSource::Provider* asProvider(const SkShader::ContextRec& rec, |
- void* storage) const override; |
- |
- size_t providerSize(const SkShader::ContextRec& rec) const override; |
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(NormalMapSourceImpl) |
- |
-protected: |
- void flatten(SkWriteBuffer& buf) const override; |
- |
- bool computeNormTotalInverse(const SkShader::ContextRec& rec, SkMatrix* normTotalInverse) const; |
- |
-private: |
- class Provider : public SkNormalSource::Provider { |
- public: |
- Provider(const NormalMapSourceImpl& source, SkShader::Context* mapContext, |
- SkPaint* overridePaint); |
- |
- virtual ~Provider() override; |
- |
- void fillScanLine(int x, int y, SkPoint3 output[], int count) const override; |
- |
- private: |
- const NormalMapSourceImpl& fSource; |
- SkShader::Context* fMapContext; |
- |
- SkPaint* fOverridePaint; |
- |
- typedef SkNormalSource::Provider INHERITED; |
- }; |
- |
- sk_sp<SkShader> fMapShader; |
- SkMatrix fInvCTM; // Inverse of the canvas total matrix, used for rotating normals. |
- |
- friend class SkNormalSource; |
- |
- typedef SkNormalSource INHERITED; |
-}; |
- |
-//////////////////////////////////////////////////////////////////////////// |
- |
#if SK_SUPPORT_GPU |
- |
#include "GrCoordTransform.h" |
#include "GrInvariantOutput.h" |
#include "GrTextureParams.h" |
@@ -173,7 +117,7 @@ private: |
SkMatrix fInvCTM; |
}; |
-sk_sp<GrFragmentProcessor> NormalMapSourceImpl::asFragmentProcessor( |
+sk_sp<GrFragmentProcessor> SkNormalMapSourceImpl::asFragmentProcessor( |
const SkShader::AsFPArgs& args) const { |
sk_sp<GrFragmentProcessor> mapFP = fMapShader->asFragmentProcessor(args); |
if (!mapFP) { |
@@ -187,19 +131,19 @@ sk_sp<GrFragmentProcessor> NormalMapSourceImpl::asFragmentProcessor( |
//////////////////////////////////////////////////////////////////////////// |
-NormalMapSourceImpl::Provider::Provider(const NormalMapSourceImpl& source, |
+SkNormalMapSourceImpl::Provider::Provider(const SkNormalMapSourceImpl& source, |
SkShader::Context* mapContext, |
SkPaint* overridePaint) |
: fSource(source) |
, fMapContext(mapContext) |
, fOverridePaint(overridePaint) {} |
-NormalMapSourceImpl::Provider::~Provider() { |
+SkNormalMapSourceImpl::Provider::~Provider() { |
fMapContext->~Context(); |
fOverridePaint->~SkPaint(); |
} |
-SkNormalSource::Provider* NormalMapSourceImpl::asProvider( |
+SkNormalSource::Provider* SkNormalMapSourceImpl::asProvider( |
const SkShader::ContextRec &rec, void *storage) const { |
SkMatrix normTotalInv; |
if (!this->computeNormTotalInverse(rec, &normTotalInv)) { |
@@ -222,11 +166,11 @@ SkNormalSource::Provider* NormalMapSourceImpl::asProvider( |
return new (storage) Provider(*this, context, overridePaint); |
} |
-size_t NormalMapSourceImpl::providerSize(const SkShader::ContextRec& rec) const { |
+size_t SkNormalMapSourceImpl::providerSize(const SkShader::ContextRec& rec) const { |
return sizeof(Provider) + sizeof(SkPaint) + fMapShader->contextSize(rec); |
} |
-bool NormalMapSourceImpl::computeNormTotalInverse(const SkShader::ContextRec& rec, |
+bool SkNormalMapSourceImpl::computeNormTotalInverse(const SkShader::ContextRec& rec, |
SkMatrix* normTotalInverse) const { |
SkMatrix total; |
total.setConcat(*rec.fMatrix, fMapShader->getLocalMatrix()); |
@@ -240,7 +184,7 @@ bool NormalMapSourceImpl::computeNormTotalInverse(const SkShader::ContextRec& re |
} |
#define BUFFER_MAX 16 |
-void NormalMapSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 output[], |
+void SkNormalMapSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 output[], |
int count) const { |
SkPMColor tmpNormalColors[BUFFER_MAX]; |
@@ -291,17 +235,17 @@ void NormalMapSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 output[] |
//////////////////////////////////////////////////////////////////////////////// |
-sk_sp<SkFlattenable> NormalMapSourceImpl::CreateProc(SkReadBuffer& buf) { |
+sk_sp<SkFlattenable> SkNormalMapSourceImpl::CreateProc(SkReadBuffer& buf) { |
sk_sp<SkShader> mapShader = buf.readFlattenable<SkShader>(); |
SkMatrix invCTM; |
buf.readMatrix(&invCTM); |
- return sk_make_sp<NormalMapSourceImpl>(std::move(mapShader), invCTM); |
+ return sk_make_sp<SkNormalMapSourceImpl>(std::move(mapShader), invCTM); |
} |
-void NormalMapSourceImpl::flatten(SkWriteBuffer& buf) const { |
+void SkNormalMapSourceImpl::flatten(SkWriteBuffer& buf) const { |
this->INHERITED::flatten(buf); |
buf.writeFlattenable(fMapShader.get()); |
@@ -317,146 +261,5 @@ sk_sp<SkNormalSource> SkNormalSource::MakeFromNormalMap(sk_sp<SkShader> map, con |
return nullptr; |
} |
- return sk_make_sp<NormalMapSourceImpl>(std::move(map), invCTM); |
+ return sk_make_sp<SkNormalMapSourceImpl>(std::move(map), invCTM); |
} |
- |
-/////////////////////////////////////////////////////////////////////////////// |
- |
-class SK_API NormalFlatSourceImpl : public SkNormalSource { |
-public: |
- NormalFlatSourceImpl(){} |
- |
-#if SK_SUPPORT_GPU |
- sk_sp<GrFragmentProcessor> asFragmentProcessor(const SkShader::AsFPArgs&) const override; |
-#endif |
- |
- SkNormalSource::Provider* asProvider(const SkShader::ContextRec& rec, |
- void* storage) const override; |
- size_t providerSize(const SkShader::ContextRec& rec) const override; |
- |
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(NormalFlatSourceImpl) |
- |
-protected: |
- void flatten(SkWriteBuffer& buf) const override; |
- |
-private: |
- class Provider : public SkNormalSource::Provider { |
- public: |
- Provider(); |
- |
- virtual ~Provider(); |
- |
- void fillScanLine(int x, int y, SkPoint3 output[], int count) const override; |
- |
- private: |
- typedef SkNormalSource::Provider INHERITED; |
- }; |
- |
- friend class SkNormalSource; |
- |
- typedef SkNormalSource INHERITED; |
-}; |
- |
-//////////////////////////////////////////////////////////////////////////// |
- |
-#if SK_SUPPORT_GPU |
- |
-class NormalFlatFP : public GrFragmentProcessor { |
-public: |
- NormalFlatFP() { |
- this->initClassID<NormalFlatFP>(); |
- } |
- |
- class GLSLNormalFlatFP : public GrGLSLFragmentProcessor { |
- public: |
- GLSLNormalFlatFP() {} |
- |
- void emitCode(EmitArgs& args) override { |
- GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
- |
- fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor); |
- } |
- |
- static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
- GrProcessorKeyBuilder* b) { |
- b->add32(0x0); |
- } |
- |
- protected: |
- void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {} |
- }; |
- |
- void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { |
- GLSLNormalFlatFP::GenKey(*this, caps, b); |
- } |
- |
- const char* name() const override { return "NormalFlatFP"; } |
- |
- void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
- inout->setToUnknown(GrInvariantOutput::ReadInput::kWillNot_ReadInput); |
- } |
- |
-private: |
- GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLNormalFlatFP; } |
- |
- bool onIsEqual(const GrFragmentProcessor& proc) const override { |
- return true; |
- } |
-}; |
- |
-sk_sp<GrFragmentProcessor> NormalFlatSourceImpl::asFragmentProcessor( |
- const SkShader::AsFPArgs&) const { |
- |
- return sk_make_sp<NormalFlatFP>(); |
-} |
- |
-#endif // SK_SUPPORT_GPU |
- |
-//////////////////////////////////////////////////////////////////////////// |
- |
-NormalFlatSourceImpl::Provider::Provider() {} |
- |
-NormalFlatSourceImpl::Provider::~Provider() {} |
- |
-SkNormalSource::Provider* NormalFlatSourceImpl::asProvider(const SkShader::ContextRec &rec, |
- void *storage) const { |
- return new (storage) Provider(); |
-} |
- |
-size_t NormalFlatSourceImpl::providerSize(const SkShader::ContextRec&) const { |
- return sizeof(Provider); |
-} |
- |
-void NormalFlatSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 output[], |
- int count) const { |
- for (int i = 0; i < count; i++) { |
- output[i] = {0.0f, 0.0f, 1.0f}; |
- } |
-} |
- |
-//////////////////////////////////////////////////////////////////////////////// |
- |
-sk_sp<SkFlattenable> NormalFlatSourceImpl::CreateProc(SkReadBuffer& buf) { |
- return sk_make_sp<NormalFlatSourceImpl>(); |
-} |
- |
-void NormalFlatSourceImpl::flatten(SkWriteBuffer& buf) const { |
- this->INHERITED::flatten(buf); |
-} |
- |
-//////////////////////////////////////////////////////////////////////////// |
- |
-sk_sp<SkNormalSource> SkNormalSource::MakeFlat() { |
- return sk_make_sp<NormalFlatSourceImpl>(); |
-} |
- |
-//////////////////////////////////////////////////////////////////////////// |
- |
-//////////////////////////////////////////////////////////////////////////// |
- |
-SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource) |
- SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl) |
- SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalFlatSourceImpl) |
-SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
- |
-//////////////////////////////////////////////////////////////////////////// |