Index: src/core/SkNormalSource.cpp |
diff --git a/src/core/SkNormalSource.cpp b/src/core/SkNormalSource.cpp |
index a69367921263ccdd8d1f2f793d35bc3923c6deef..421f56459d0a4c0cf75cd17719ab119f215f44ff 100644 |
--- a/src/core/SkNormalSource.cpp |
+++ b/src/core/SkNormalSource.cpp |
@@ -51,6 +51,7 @@ private: |
virtual ~Provider() override; |
void fillScanLine(int x, int y, SkPoint3 output[], int count) const override; |
+ |
private: |
const NormalMapSourceImpl& fSource; |
SkShader::Context* fMapContext; |
@@ -197,8 +198,7 @@ sk_sp<GrFragmentProcessor> NormalMapSourceImpl::asFragmentProcessor( |
NormalMapSourceImpl::Provider::Provider(const NormalMapSourceImpl& source, |
SkShader::Context* mapContext) |
: fSource(source) |
- , fMapContext(mapContext) { |
-} |
+ , fMapContext(mapContext) {} |
NormalMapSourceImpl::Provider::~Provider() { |
fMapContext->~Context(); |
@@ -316,10 +316,200 @@ sk_sp<SkNormalSource> SkNormalSource::MakeFromNormalMap(sk_sp<SkShader> map, con |
return sk_make_sp<NormalMapSourceImpl>(std::move(map), invCTM); |
} |
+/////////////////////////////////////////////////////////////////////////////// |
+ |
+class SK_API NormalBevelSourceImpl : public SkNormalSource { |
+public: |
+ NormalBevelSourceImpl(BevelType type, SkScalar width, SkScalar height) |
+ : fType(type) |
+ , fWidth(width) |
+ , fHeight(height) {} |
+ |
+#if SK_SUPPORT_GPU |
+ sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*, |
+ const SkMatrix& viewM, |
+ const SkMatrix* localMatrix, |
+ SkFilterQuality, |
+ SkSourceGammaTreatment) const override; |
+#endif |
+ |
+ SkNormalSource::Provider* asProvider(const SkShader::ContextRec& rec, void* storage) const |
robertphillips
2016/07/11 19:13:21
orphan
dvonbeck
2016/07/13 14:23:37
Done.
|
+ override; |
+ size_t providerSize(const SkShader::ContextRec& rec) const override; |
+ |
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(NormalBevelSourceImpl) |
+ |
+protected: |
+ void flatten(SkWriteBuffer& buf) const override; |
+ |
+private: |
+ class Provider : public SkNormalSource::Provider { |
+ public: |
+ Provider(const NormalBevelSourceImpl& source); |
+ |
+ virtual ~Provider(); |
+ |
+ void fillScanLine(int x, int y, SkPoint3 output[], int count) const override; |
+ |
+ private: |
+ const NormalBevelSourceImpl& fSource; |
+ |
+ typedef SkNormalSource::Provider INHERITED; |
+ }; |
+ |
+ SkNormalSource::BevelType fType; |
+ SkScalar fWidth; |
+ SkScalar fHeight; |
+ |
robertphillips
2016/07/11 19:13:21
This is the base class. Does it need to be friende
dvonbeck
2016/07/13 14:23:37
No, it used to be when the structure was different
dvonbeck
2016/07/13 16:30:16
Nevermind, it is necessary for serialization to wo
|
+ friend class SkNormalSource; |
+ |
+ typedef SkNormalSource INHERITED; |
+}; |
+ |
+//////////////////////////////////////////////////////////////////////////// |
+ |
+#if SK_SUPPORT_GPU |
+ |
robertphillips
2016/07/11 19:13:21
??
dvonbeck
2016/07/13 14:23:38
Done.
|
+#if 0 // Keeping here for reference in case code gets refactored into another file |
+#include "GrCoordTransform.h" |
+#include "GrInvariantOutput.h" |
+#include "GrTextureParams.h" |
+#include "glsl/GrGLSLFragmentProcessor.h" |
+#include "glsl/GrGLSLFragmentShaderBuilder.h" |
+#include "SkGr.h" |
+#endif |
+ |
+class NormalBevelFP : public GrFragmentProcessor { |
+public: |
+ NormalBevelFP(SkNormalSource::BevelType type, SkScalar width, SkScalar height) |
+ : fType(type) |
+ , fWidth(width) |
+ , fHeight(height) { |
+ this->initClassID<NormalBevelFP>(); |
+ } |
+ |
+ class GLSLNormalBevelFP : public GrGLSLFragmentProcessor { |
+ public: |
+ GLSLNormalBevelFP() {} |
+ |
+ 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 { |
+ const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>(); |
+ |
+ fType = normalBevelFP.fType; |
+ fWidth = normalBevelFP.fWidth; |
+ fHeight = normalBevelFP.fHeight; |
+ } |
+ |
+ private: |
+ SkNormalSource::BevelType fType; |
+ SkScalar fWidth; |
+ SkScalar fHeight; |
+ }; |
+ |
+ void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { |
+ GLSLNormalBevelFP::GenKey(*this, caps, b); |
+ } |
+ |
+ const char* name() const override { return "NormalBevelFP"; } |
+ |
+ void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
+ inout->setToUnknown(GrInvariantOutput::ReadInput::kWillNot_ReadInput); |
+ } |
+ |
+private: |
+ GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLNormalBevelFP; } |
+ |
+ bool onIsEqual(const GrFragmentProcessor& proc) const override { |
+ const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>(); |
+ return fType == normalBevelFP.fType && |
+ fWidth == normalBevelFP.fWidth && |
+ fHeight == normalBevelFP.fHeight; |
+ } |
+ |
+ SkNormalSource::BevelType fType; |
+ SkScalar fWidth; |
+ SkScalar fHeight; |
+}; |
+ |
+sk_sp<GrFragmentProcessor> NormalBevelSourceImpl::asFragmentProcessor( |
+ GrContext *context, |
+ const SkMatrix &viewM, |
+ const SkMatrix *localMatrix, |
+ SkFilterQuality filterQuality, |
+ SkSourceGammaTreatment gammaTreatment) const { |
+ |
+ return sk_make_sp<NormalBevelFP>(fType, fWidth, fHeight); |
+} |
+ |
+#endif // SK_SUPPORT_GPU |
+ |
+//////////////////////////////////////////////////////////////////////////// |
+ |
+NormalBevelSourceImpl::Provider::Provider(const NormalBevelSourceImpl& source) |
+ : fSource(source) {} |
+ |
+NormalBevelSourceImpl::Provider::~Provider() {} |
+ |
+SkNormalSource::Provider* NormalBevelSourceImpl::asProvider(const SkShader::ContextRec &rec, |
+ void *storage) const { |
+ return new (storage) Provider(*this); |
+} |
+ |
+size_t NormalBevelSourceImpl::providerSize(const SkShader::ContextRec&) const { |
+ return sizeof(Provider); |
+} |
+ |
+void NormalBevelSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 output[], int count) |
robertphillips
2016/07/11 19:13:21
orphan
dvonbeck
2016/07/13 14:23:37
Done.
|
+ const { |
+ for (int i = 0; i < count; i++) { |
+ output[i] = {0, 0, 1.0}; |
+ } |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+ |
+sk_sp<SkFlattenable> NormalBevelSourceImpl::CreateProc(SkReadBuffer& buf) { |
+ |
+ auto type = static_cast<SkNormalSource::BevelType>(buf.readInt()); |
+ SkScalar width = buf.readScalar(); |
+ SkScalar height = buf.readScalar(); |
+ |
+ return sk_make_sp<NormalBevelSourceImpl>(type, width, height); |
+} |
+ |
+void NormalBevelSourceImpl::flatten(SkWriteBuffer& buf) const { |
+ this->INHERITED::flatten(buf); |
+ |
+ buf.writeInt(static_cast<int>(fType)); |
+ buf.writeScalar(fWidth); |
+ buf.writeScalar(fHeight); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////// |
+ |
+sk_sp<SkNormalSource> SkNormalSource::MakeBevel(BevelType type, SkScalar width, SkScalar height) { |
+ return sk_make_sp<NormalBevelSourceImpl>(type, width, height); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////// |
+ |
//////////////////////////////////////////////////////////////////////////// |
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource) |
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl) |
+ SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalBevelSourceImpl) |
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
//////////////////////////////////////////////////////////////////////////// |