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 "SkNormalFlatSource.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
merge sk_support_gpus
dvonbeck
2016/07/25 20:37:13
Done.
| |
| 29 | |
| 30 class NormalFlatFP : public GrFragmentProcessor { | |
| 31 public: | |
| 32 NormalFlatFP() { | |
| 33 this->initClassID<NormalFlatFP>(); | |
| 34 } | |
| 35 | |
| 36 class GLSLNormalFlatFP : public GrGLSLFragmentProcessor { | |
| 37 public: | |
| 38 GLSLNormalFlatFP() {} | |
| 39 | |
| 40 void emitCode(EmitArgs& args) override { | |
| 41 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | |
| 42 | |
| 43 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor ); | |
| 44 } | |
| 45 | |
| 46 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | |
| 47 GrProcessorKeyBuilder* b) { | |
| 48 b->add32(0x0); | |
| 49 } | |
| 50 | |
| 51 protected: | |
| 52 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {} | |
| 53 }; | |
| 54 | |
| 55 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { | |
| 56 GLSLNormalFlatFP::GenKey(*this, caps, b); | |
| 57 } | |
| 58 | |
| 59 const char* name() const override { return "NormalFlatFP"; } | |
| 60 | |
| 61 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | |
| 62 inout->setToUnknown(GrInvariantOutput::ReadInput::kWillNot_ReadInput); | |
| 63 } | |
| 64 | |
| 65 private: | |
| 66 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLNormalFlatFP; } | |
| 67 | |
| 68 bool onIsEqual(const GrFragmentProcessor& proc) const override { | |
| 69 return true; | |
| 70 } | |
| 71 }; | |
| 72 | |
| 73 sk_sp<GrFragmentProcessor> SkNormalFlatSourceImpl::asFragmentProcessor( | |
| 74 GrContext *context, | |
| 75 const SkMatrix &viewM, | |
| 76 const SkMatrix *localMatrix , | |
| 77 SkFilterQuality filterQuali ty, | |
| 78 SkSourceGammaTreatment gamm aTreatment) const { | |
| 79 | |
| 80 return sk_make_sp<NormalFlatFP>(); | |
| 81 } | |
| 82 | |
| 83 #endif // SK_SUPPORT_GPU | |
| 84 | |
| 85 //////////////////////////////////////////////////////////////////////////// | |
| 86 | |
| 87 SkNormalFlatSourceImpl::Provider::Provider() {} | |
| 88 | |
| 89 SkNormalFlatSourceImpl::Provider::~Provider() {} | |
| 90 | |
| 91 SkNormalSource::Provider* SkNormalFlatSourceImpl::asProvider(const SkShader::Con textRec &rec, | |
| 92 void *storage) const { | |
| 93 return new (storage) Provider(); | |
| 94 } | |
| 95 | |
| 96 size_t SkNormalFlatSourceImpl::providerSize(const SkShader::ContextRec&) const { | |
| 97 return sizeof(Provider); | |
| 98 } | |
| 99 | |
| 100 void SkNormalFlatSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 outpu t[], | |
| 101 int count) const { | |
| 102 for (int i = 0; i < count; i++) { | |
| 103 output[i] = {0.0f, 0.0f, 1.0f}; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 //////////////////////////////////////////////////////////////////////////////// | |
| 108 | |
| 109 sk_sp<SkFlattenable> SkNormalFlatSourceImpl::CreateProc(SkReadBuffer& buf) { | |
| 110 return sk_make_sp<SkNormalFlatSourceImpl>(); | |
| 111 } | |
| 112 | |
| 113 void SkNormalFlatSourceImpl::flatten(SkWriteBuffer& buf) const { | |
| 114 this->INHERITED::flatten(buf); | |
| 115 } | |
| 116 | |
| 117 //////////////////////////////////////////////////////////////////////////// | |
| 118 | |
| 119 sk_sp<SkNormalSource> SkNormalSource::MakeFlat() { | |
| 120 return sk_make_sp<SkNormalFlatSourceImpl>(); | |
| 121 } | |
| OLD | NEW |