Index: src/core/SkNormalSource.cpp |
diff --git a/src/core/SkNormalSource.cpp b/src/core/SkNormalSource.cpp |
index 7dc8bc1aea7be24ea6ddfc4583fbdce37988d32b..6055f83f8b639bdbfdb74e2f8eebef3261e32a1c 100644 |
--- a/src/core/SkNormalSource.cpp |
+++ b/src/core/SkNormalSource.cpp |
@@ -472,6 +472,182 @@ sk_sp<SkNormalSource> SkNormalSource::MakeFlat() { |
//////////////////////////////////////////////////////////////////////////// |
+class SK_API NormalBevelSourceImpl : public SkNormalSource { |
+public: |
+ NormalBevelSourceImpl(BevelType type, SkScalar width, SkScalar height) |
robertphillips
2016/07/13 14:39:02
These seem over tabbed
dvonbeck
2016/07/13 16:09:17
Done.
|
+ : 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 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; |
+ |
+ typedef SkNormalSource INHERITED; |
+}; |
+ |
+//////////////////////////////////////////////////////////////////////////// |
+ |
+#if SK_SUPPORT_GPU |
+ |
+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: |
robertphillips
2016/07/13 14:39:02
Need to init your member variables to something he
dvonbeck
2016/07/13 16:09:16
Done. Why?
robertphillips
2016/07/13 16:16:55
Normally, in onSetData you have some code like:
i
|
+ 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: |
robertphillips
2016/07/13 14:39:02
Usually these would be named fPrevType, fPrevWidth
dvonbeck
2016/07/13 16:09:17
Done.
|
+ 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) |
robertphillips
2016/07/13 14:39:02
Over tabbed
dvonbeck
2016/07/13 16:09:16
Done.
|
+ : 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) const { |
robertphillips
2016/07/13 14:39:02
I think we're leaning to always having auto as the
dvonbeck
2016/07/13 16:09:16
I don't feel like it's appropriate here, being an
|
+ 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) |