Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2016 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "SkNormalBevelSource.h" | |
| 9 | |
| 10 #include "SkError.h" | |
| 11 #include "SkErrorInternals.h" | |
| 12 #include "SkLightingShader.h" | |
| 13 #include "SkMatrix.h" | |
| 14 #include "SkNormalSource.h" | |
| 15 #include "SkPM4f.h" | |
| 16 #include "SkReadBuffer.h" | |
| 17 #include "SkWriteBuffer.h" | |
| 18 | |
| 19 #if SK_SUPPORT_GPU | |
| 20 #include "GrCoordTransform.h" | |
| 21 #include "GrInvariantOutput.h" | |
| 22 #include "GrTextureParams.h" | |
| 23 #include "glsl/GrGLSLFragmentProcessor.h" | |
| 24 #include "glsl/GrGLSLFragmentShaderBuilder.h" | |
| 25 #include "SkGr.h" | |
| 26 #endif | |
| 27 | |
| 28 #if SK_SUPPORT_GPU | |
|
egdaniel
2016/07/25 15:48:00
can we share the #if sk_support_gpu with the inclu
dvonbeck
2016/07/25 20:37:13
I felt like it was clearer this way when there wer
| |
| 29 | |
| 30 class NormalBevelFP : public GrFragmentProcessor { | |
| 31 public: | |
| 32 NormalBevelFP(SkNormalSource::BevelType type, SkScalar width, SkScalar heigh t) | |
| 33 : fType(type) | |
| 34 , fWidth(width) | |
| 35 , fHeight(height) { | |
| 36 this->initClassID<NormalBevelFP>(); | |
| 37 } | |
| 38 | |
| 39 class GLSLNormalBevelFP : public GrGLSLFragmentProcessor { | |
| 40 public: | |
| 41 GLSLNormalBevelFP() { | |
| 42 fPrevType = SkNormalSource::BevelType::kLinear; | |
| 43 fPrevWidth = SkFloatToScalar(0.0f); | |
| 44 fPrevHeight = SkFloatToScalar(0.0f); | |
| 45 } | |
| 46 | |
| 47 void emitCode(EmitArgs& args) override { | |
| 48 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | |
| 49 | |
| 50 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor ); | |
| 51 } | |
| 52 | |
| 53 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | |
| 54 GrProcessorKeyBuilder* b) { | |
| 55 b->add32(0x0); | |
| 56 } | |
| 57 | |
| 58 protected: | |
| 59 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override { | |
| 60 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>(); | |
| 61 | |
| 62 fPrevType = normalBevelFP.fType; | |
|
egdaniel
2016/07/25 15:48:00
can we put this in the form Rob suggested earlier,
dvonbeck
2016/07/25 20:37:13
Done.
| |
| 63 fPrevWidth = normalBevelFP.fWidth; | |
| 64 fPrevHeight = normalBevelFP.fHeight; | |
| 65 } | |
| 66 | |
| 67 private: | |
| 68 SkNormalSource::BevelType fPrevType; | |
|
egdaniel
2016/07/25 15:48:00
Do you need to store the type here? Seems like thi
dvonbeck
2016/07/25 20:37:13
Done.
| |
| 69 SkScalar fPrevWidth; | |
| 70 SkScalar fPrevHeight; | |
| 71 }; | |
| 72 | |
| 73 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { | |
| 74 GLSLNormalBevelFP::GenKey(*this, caps, b); | |
| 75 } | |
| 76 | |
| 77 const char* name() const override { return "NormalBevelFP"; } | |
| 78 | |
| 79 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | |
| 80 inout->setToUnknown(GrInvariantOutput::ReadInput::kWillNot_ReadInput); | |
| 81 } | |
| 82 | |
| 83 private: | |
| 84 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLNormalBevelFP; } | |
| 85 | |
| 86 bool onIsEqual(const GrFragmentProcessor& proc) const override { | |
| 87 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>(); | |
| 88 return fType == normalBevelFP.fType && | |
| 89 fWidth == normalBevelFP.fWidth && | |
| 90 fHeight == normalBevelFP.fHeight; | |
| 91 } | |
| 92 | |
| 93 SkNormalSource::BevelType fType; | |
| 94 SkScalar fWidth; | |
| 95 SkScalar fHeight; | |
| 96 }; | |
| 97 | |
| 98 sk_sp<GrFragmentProcessor> SkNormalBevelSourceImpl::asFragmentProcessor( | |
| 99 GrContext *context, | |
| 100 const SkMatrix &viewM, | |
| 101 const SkMatrix *localMatrix, | |
| 102 SkFilterQuality filterQuality, | |
| 103 SkSourceGammaTreatment gammaTreatment) const { | |
| 104 | |
| 105 return sk_make_sp<NormalBevelFP>(fType, fWidth, fHeight); | |
| 106 } | |
| 107 | |
| 108 #endif // SK_SUPPORT_GPU | |
| 109 | |
| 110 //////////////////////////////////////////////////////////////////////////// | |
| 111 | |
| 112 SkNormalBevelSourceImpl::Provider::Provider(const SkNormalBevelSourceImpl& sourc e) | |
| 113 : fSource(source) {} | |
| 114 | |
| 115 SkNormalBevelSourceImpl::Provider::~Provider() {} | |
| 116 | |
| 117 SkNormalSource::Provider* SkNormalBevelSourceImpl::asProvider(const SkShader::Co ntextRec &rec, | |
| 118 void *storage) const { | |
| 119 return new (storage) Provider(*this); | |
| 120 } | |
| 121 | |
| 122 size_t SkNormalBevelSourceImpl::providerSize(const SkShader::ContextRec&) const { | |
| 123 return sizeof(Provider); | |
| 124 } | |
| 125 | |
| 126 void SkNormalBevelSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 outp ut[], | |
| 127 int count) const { | |
| 128 for (int i = 0; i < count; i++) { | |
| 129 output[i] = {0, 0, 1.0}; | |
|
egdaniel
2016/07/25 15:48:00
1.0f?
dvonbeck
2016/07/25 20:37:13
Oops. Done.
| |
| 130 } | |
| 131 } | |
| 132 | |
| 133 //////////////////////////////////////////////////////////////////////////////// | |
| 134 | |
| 135 sk_sp<SkFlattenable> SkNormalBevelSourceImpl::CreateProc(SkReadBuffer& buf) { | |
| 136 | |
| 137 auto type = static_cast<SkNormalSource::BevelType>(buf.readInt()); | |
| 138 SkScalar width = buf.readScalar(); | |
| 139 SkScalar height = buf.readScalar(); | |
| 140 | |
| 141 return sk_make_sp<SkNormalBevelSourceImpl>(type, width, height); | |
| 142 } | |
| 143 | |
| 144 void SkNormalBevelSourceImpl::flatten(SkWriteBuffer& buf) const { | |
| 145 this->INHERITED::flatten(buf); | |
| 146 | |
| 147 buf.writeInt(static_cast<int>(fType)); | |
| 148 buf.writeScalar(fWidth); | |
| 149 buf.writeScalar(fHeight); | |
| 150 } | |
| 151 | |
| 152 //////////////////////////////////////////////////////////////////////////// | |
| 153 | |
| 154 sk_sp<SkNormalSource> SkNormalSource::MakeBevel(BevelType type, SkScalar width, SkScalar height) { | |
| 155 /* TODO make sure this checks are tolerant enough to account for loss of con version when GPUs | |
| 156 use 16-bit float types. We don't want to assume stuff is non-zero on the GPU and be wrong.*/ | |
| 157 SkASSERT(width > 0.0f && !SkScalarNearlyZero(width)); | |
| 158 if (SkScalarNearlyZero(height)) { | |
| 159 return SkNormalSource::MakeFlat(); | |
| 160 } | |
| 161 | |
| 162 return sk_make_sp<SkNormalBevelSourceImpl>(type, width, height); | |
| 163 } | |
| OLD | NEW |