egdaniel | 16a04b8 | 2015-01-14 10:49:18 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | #ifndef SkArithmeticMode_gpu_DEFINED |
| 9 | #define SkArithmeticMode_gpu_DEFINED |
| 10 | |
egdaniel | 04ea634 | 2015-01-15 07:05:02 -0800 | [diff] [blame] | 11 | #include "SkTypes.h" |
| 12 | |
egdaniel | 16a04b8 | 2015-01-14 10:49:18 -0800 | [diff] [blame] | 13 | #if SK_SUPPORT_GPU |
| 14 | |
| 15 | #include "GrCoordTransform.h" |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 16 | #include "GrDrawTargetCaps.h" |
egdaniel | 16a04b8 | 2015-01-14 10:49:18 -0800 | [diff] [blame] | 17 | #include "GrFragmentProcessor.h" |
| 18 | #include "GrTextureAccess.h" |
egdaniel | f351aa3 | 2015-01-14 12:53:01 -0800 | [diff] [blame] | 19 | #include "GrTypes.h" |
| 20 | #include "GrXferProcessor.h" |
egdaniel | 16a04b8 | 2015-01-14 10:49:18 -0800 | [diff] [blame] | 21 | |
| 22 | class GrInvariantOutput; |
egdaniel | f351aa3 | 2015-01-14 12:53:01 -0800 | [diff] [blame] | 23 | class GrProcOptInfo; |
egdaniel | 16a04b8 | 2015-01-14 10:49:18 -0800 | [diff] [blame] | 24 | class GrTexture; |
| 25 | |
| 26 | /////////////////////////////////////////////////////////////////////////////// |
| 27 | // Fragment Processor |
| 28 | /////////////////////////////////////////////////////////////////////////////// |
| 29 | |
| 30 | class GrGLArtithmeticFP; |
| 31 | |
| 32 | class GrArithmeticFP : public GrFragmentProcessor { |
| 33 | public: |
| 34 | static GrFragmentProcessor* Create(float k1, float k2, float k3, float k4, bool enforcePMColor, |
| 35 | GrTexture* background) { |
| 36 | return SkNEW_ARGS(GrArithmeticFP, (k1, k2, k3, k4, enforcePMColor, background)); |
| 37 | } |
| 38 | |
| 39 | ~GrArithmeticFP() SK_OVERRIDE {}; |
| 40 | |
| 41 | const char* name() const SK_OVERRIDE { return "Arithmetic"; } |
| 42 | |
| 43 | void getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
| 44 | |
| 45 | GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; |
| 46 | |
egdaniel | 16a04b8 | 2015-01-14 10:49:18 -0800 | [diff] [blame] | 47 | float k1() const { return fK1; } |
| 48 | float k2() const { return fK2; } |
| 49 | float k3() const { return fK3; } |
| 50 | float k4() const { return fK4; } |
| 51 | bool enforcePMColor() const { return fEnforcePMColor; } |
| 52 | |
| 53 | private: |
| 54 | bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; |
| 55 | |
| 56 | void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; |
| 57 | |
| 58 | GrArithmeticFP(float k1, float k2, float k3, float k4, bool enforcePMColor, |
| 59 | GrTexture* background); |
| 60 | |
| 61 | float fK1, fK2, fK3, fK4; |
| 62 | bool fEnforcePMColor; |
| 63 | GrCoordTransform fBackgroundTransform; |
| 64 | GrTextureAccess fBackgroundAccess; |
| 65 | |
| 66 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 67 | typedef GrFragmentProcessor INHERITED; |
| 68 | }; |
| 69 | |
egdaniel | f351aa3 | 2015-01-14 12:53:01 -0800 | [diff] [blame] | 70 | /////////////////////////////////////////////////////////////////////////////// |
| 71 | // Xfer Processor |
| 72 | /////////////////////////////////////////////////////////////////////////////// |
| 73 | |
| 74 | class GrArithmeticXP : public GrXferProcessor { |
| 75 | public: |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 76 | static GrXferProcessor* Create(float k1, float k2, float k3, float k4, bool enforcePMColor, |
| 77 | const GrDeviceCoordTexture* dstCopy, |
| 78 | bool willReadDstColor) { |
| 79 | return SkNEW_ARGS(GrArithmeticXP, (k1, k2, k3, k4, enforcePMColor, dstCopy, |
| 80 | willReadDstColor)); |
egdaniel | f351aa3 | 2015-01-14 12:53:01 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | ~GrArithmeticXP() SK_OVERRIDE {}; |
| 84 | |
| 85 | const char* name() const SK_OVERRIDE { return "Arithmetic"; } |
| 86 | |
egdaniel | f351aa3 | 2015-01-14 12:53:01 -0800 | [diff] [blame] | 87 | GrGLXferProcessor* createGLInstance() const SK_OVERRIDE; |
| 88 | |
| 89 | bool hasSecondaryOutput() const SK_OVERRIDE { return false; } |
| 90 | |
| 91 | GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI, |
| 92 | const GrProcOptInfo& coveragePOI, |
| 93 | bool doesStencilWrite, |
| 94 | GrColor* overrideColor, |
| 95 | const GrDrawTargetCaps& caps) SK_OVERRIDE; |
| 96 | |
| 97 | void getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const SK_OVERRIDE { |
| 98 | blendInfo->fSrcBlend = kOne_GrBlendCoeff; |
| 99 | blendInfo->fDstBlend = kZero_GrBlendCoeff; |
| 100 | blendInfo->fBlendConstant = 0; |
| 101 | } |
| 102 | |
| 103 | float k1() const { return fK1; } |
| 104 | float k2() const { return fK2; } |
| 105 | float k3() const { return fK3; } |
| 106 | float k4() const { return fK4; } |
| 107 | bool enforcePMColor() const { return fEnforcePMColor; } |
| 108 | |
| 109 | private: |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 110 | GrArithmeticXP(float k1, float k2, float k3, float k4, bool enforcePMColor, |
| 111 | const GrDeviceCoordTexture* dstCopy, bool willReadDstColor); |
| 112 | |
| 113 | void onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
egdaniel | f351aa3 | 2015-01-14 12:53:01 -0800 | [diff] [blame] | 114 | |
| 115 | bool onIsEqual(const GrXferProcessor& xpBase) const SK_OVERRIDE { |
| 116 | const GrArithmeticXP& xp = xpBase.cast<GrArithmeticXP>(); |
| 117 | if (fK1 != xp.fK1 || |
| 118 | fK2 != xp.fK2 || |
| 119 | fK3 != xp.fK3 || |
| 120 | fK4 != xp.fK4 || |
| 121 | fEnforcePMColor != xp.fEnforcePMColor) { |
| 122 | return false; |
| 123 | } |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | float fK1, fK2, fK3, fK4; |
| 128 | bool fEnforcePMColor; |
| 129 | |
| 130 | typedef GrXferProcessor INHERITED; |
| 131 | }; |
| 132 | |
| 133 | /////////////////////////////////////////////////////////////////////////////// |
| 134 | |
| 135 | class GrArithmeticXPFactory : public GrXPFactory { |
| 136 | public: |
| 137 | static GrXPFactory* Create(float k1, float k2, float k3, float k4, bool enforcePMColor) { |
| 138 | return SkNEW_ARGS(GrArithmeticXPFactory, (k1, k2, k3, k4, enforcePMColor)); |
| 139 | } |
| 140 | |
egdaniel | f351aa3 | 2015-01-14 12:53:01 -0800 | [diff] [blame] | 141 | bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const SK_OVERRIDE { |
| 142 | return true; |
| 143 | } |
| 144 | |
| 145 | bool canApplyCoverage(const GrProcOptInfo& colorPOI, |
| 146 | const GrProcOptInfo& coveragePOI) const SK_OVERRIDE { |
| 147 | return true; |
| 148 | } |
| 149 | |
| 150 | bool canTweakAlphaForCoverage() const SK_OVERRIDE { |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo& coveragePOI, |
| 155 | GrXPFactory::InvariantOutput*) const SK_OVERRIDE; |
| 156 | |
egdaniel | f351aa3 | 2015-01-14 12:53:01 -0800 | [diff] [blame] | 157 | private: |
| 158 | GrArithmeticXPFactory(float k1, float k2, float k3, float k4, bool enforcePMColor); |
| 159 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 160 | GrXferProcessor* onCreateXferProcessor(const GrProcOptInfo& colorPOI, |
| 161 | const GrProcOptInfo& coveragePOI, |
| 162 | const GrDeviceCoordTexture* dstCopy) const SK_OVERRIDE { |
| 163 | return GrArithmeticXP::Create(fK1, fK2, fK3, fK4, fEnforcePMColor, dstCopy, |
| 164 | this->willReadDstColor()); |
| 165 | } |
| 166 | |
| 167 | bool willReadDstColor() const SK_OVERRIDE { return true; } |
| 168 | |
egdaniel | f351aa3 | 2015-01-14 12:53:01 -0800 | [diff] [blame] | 169 | bool onIsEqual(const GrXPFactory& xpfBase) const SK_OVERRIDE { |
| 170 | const GrArithmeticXPFactory& xpf = xpfBase.cast<GrArithmeticXPFactory>(); |
| 171 | if (fK1 != xpf.fK1 || |
| 172 | fK2 != xpf.fK2 || |
| 173 | fK3 != xpf.fK3 || |
| 174 | fK4 != xpf.fK4 || |
| 175 | fEnforcePMColor != xpf.fEnforcePMColor) { |
| 176 | return false; |
| 177 | } |
| 178 | return true; |
| 179 | } |
| 180 | |
| 181 | GR_DECLARE_XP_FACTORY_TEST; |
| 182 | |
| 183 | float fK1, fK2, fK3, fK4; |
| 184 | bool fEnforcePMColor; |
| 185 | |
| 186 | typedef GrXPFactory INHERITED; |
| 187 | }; |
| 188 | |
egdaniel | 16a04b8 | 2015-01-14 10:49:18 -0800 | [diff] [blame] | 189 | #endif |
| 190 | #endif |