dvonbeck | bba4cfe | 2016-07-28 08:58:19 -0700 | [diff] [blame] | 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 "SkNormalSource.h" |
| 11 | #include "SkPoint3.h" |
| 12 | #include "SkReadBuffer.h" |
| 13 | #include "SkWriteBuffer.h" |
| 14 | |
| 15 | #if SK_SUPPORT_GPU |
| 16 | #include "GrInvariantOutput.h" |
| 17 | #include "glsl/GrGLSLFragmentProcessor.h" |
| 18 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 19 | |
| 20 | class NormalFlatFP : public GrFragmentProcessor { |
| 21 | public: |
| 22 | NormalFlatFP() { |
| 23 | this->initClassID<NormalFlatFP>(); |
| 24 | } |
| 25 | |
mtklein | 02aed95 | 2016-07-30 14:21:10 -0700 | [diff] [blame] | 26 | class GLSLNormalFlatFP : public GrGLSLFragmentProcessor { |
dvonbeck | bba4cfe | 2016-07-28 08:58:19 -0700 | [diff] [blame] | 27 | public: |
| 28 | GLSLNormalFlatFP() {} |
| 29 | |
mtklein | 02aed95 | 2016-07-30 14:21:10 -0700 | [diff] [blame] | 30 | void emitCode(EmitArgs& args) override { |
| 31 | GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
dvonbeck | bba4cfe | 2016-07-28 08:58:19 -0700 | [diff] [blame] | 32 | |
| 33 | fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor); |
| 34 | } |
| 35 | |
| 36 | static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
| 37 | GrProcessorKeyBuilder* b) { |
| 38 | b->add32(0x0); |
| 39 | } |
| 40 | |
| 41 | protected: |
mtklein | 02aed95 | 2016-07-30 14:21:10 -0700 | [diff] [blame] | 42 | void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {} |
dvonbeck | bba4cfe | 2016-07-28 08:58:19 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { |
| 46 | GLSLNormalFlatFP::GenKey(*this, caps, b); |
| 47 | } |
| 48 | |
| 49 | const char* name() const override { return "NormalFlatFP"; } |
| 50 | |
| 51 | void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 52 | inout->setToUnknown(GrInvariantOutput::ReadInput::kWillNot_ReadInput); |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLNormalFlatFP; } |
| 57 | |
| 58 | bool onIsEqual(const GrFragmentProcessor& proc) const override { |
| 59 | return true; |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | sk_sp<GrFragmentProcessor> SkNormalFlatSourceImpl::asFragmentProcessor( |
| 64 | const SkShader::AsFPArgs&) const { |
| 65 | |
| 66 | return sk_make_sp<NormalFlatFP>(); |
| 67 | } |
| 68 | |
| 69 | #endif // SK_SUPPORT_GPU |
| 70 | |
| 71 | //////////////////////////////////////////////////////////////////////////// |
| 72 | |
| 73 | SkNormalFlatSourceImpl::Provider::Provider() {} |
| 74 | |
| 75 | SkNormalFlatSourceImpl::Provider::~Provider() {} |
| 76 | |
| 77 | SkNormalSource::Provider* SkNormalFlatSourceImpl::asProvider(const SkShader::ContextRec &rec, |
| 78 | void *storage) const { |
| 79 | return new (storage) Provider(); |
| 80 | } |
| 81 | |
| 82 | size_t SkNormalFlatSourceImpl::providerSize(const SkShader::ContextRec&) const { |
| 83 | return sizeof(Provider); |
| 84 | } |
| 85 | |
| 86 | void SkNormalFlatSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 output[], |
| 87 | int count) const { |
| 88 | for (int i = 0; i < count; i++) { |
| 89 | output[i] = {0.0f, 0.0f, 1.0f}; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | //////////////////////////////////////////////////////////////////////////////// |
| 94 | |
| 95 | sk_sp<SkFlattenable> SkNormalFlatSourceImpl::CreateProc(SkReadBuffer& buf) { |
| 96 | return sk_make_sp<SkNormalFlatSourceImpl>(); |
| 97 | } |
| 98 | |
| 99 | void SkNormalFlatSourceImpl::flatten(SkWriteBuffer& buf) const { |
| 100 | this->INHERITED::flatten(buf); |
| 101 | } |
| 102 | |
| 103 | //////////////////////////////////////////////////////////////////////////// |
| 104 | |
| 105 | sk_sp<SkNormalSource> SkNormalSource::MakeFlat() { |
| 106 | return sk_make_sp<SkNormalFlatSourceImpl>(); |
| 107 | } |