OLD | NEW |
(Empty) | |
| 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 GrAdvancedBlendXferProcessor_DEFINED |
| 9 #define GrAdvancedBlendXferProcessor_DEFINED |
| 10 |
| 11 #include "GrTypes.h" |
| 12 #include "GrXferProcessor.h" |
| 13 |
| 14 /** |
| 15 * Provides Xfer processors that implement advanced blend modes in hardware, |
| 16 * without the need for a dst texture. Can only be used if supported by the GPU. |
| 17 */ |
| 18 class GrAdvancedEquationXPFactory : public GrXPFactory { |
| 19 public: |
| 20 static bool IsSupported(const GrContext*, SkXfermode::Mode); |
| 21 static GrXPFactory* Create(const GrContext*, SkXfermode::Mode); |
| 22 |
| 23 bool canTweakAlphaForCoverage() const override; |
| 24 bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const
override; |
| 25 bool willBlendCoherently(const GrDrawTargetCaps&) const override; |
| 26 |
| 27 void getInvariantOutput(const GrProcOptInfo&, const GrProcOptInfo&, |
| 28 GrXPFactory::InvariantOutput* output) const override
{ |
| 29 output->fWillBlendWithDst = true; |
| 30 output->fBlendedColorFlags = 0; |
| 31 } |
| 32 |
| 33 private: |
| 34 template<GrBlendEquation> static GrXPFactory* TakeFactoryRef(); |
| 35 |
| 36 GrAdvancedEquationXPFactory(GrBlendEquation equation) |
| 37 : fEquation(equation), |
| 38 fXferProcessorWithCoverage(equation), |
| 39 fXferProcessor(equation) {} |
| 40 |
| 41 GrXferProcessor* onCreateXferProcessor(const GrDrawTargetCaps& caps, |
| 42 const GrProcOptInfo& colorPOI, |
| 43 const GrProcOptInfo& coveragePOI, |
| 44 const GrDeviceCoordTexture* dstCopy)
const override; |
| 45 |
| 46 bool willReadDstColor(const GrDrawTargetCaps&, const GrProcOptInfo&, |
| 47 const GrProcOptInfo&) const override { |
| 48 return false; |
| 49 } |
| 50 |
| 51 bool onIsEqual(const GrXPFactory& xpfBase) const override { |
| 52 const GrAdvancedEquationXPFactory& xpf = xpfBase.cast<GrAdvancedEquation
XPFactory>(); |
| 53 return fEquation == xpf.fEquation; |
| 54 } |
| 55 |
| 56 class XferProcessorBase : public GrXferProcessor { |
| 57 public: |
| 58 XferProcessorBase(GrBlendEquation equation) : fEquation(equation) {} |
| 59 |
| 60 const char* name() const override { return "Blend Equation Advanced"; } |
| 61 bool hasSecondaryOutput() const override { return false; } |
| 62 |
| 63 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo&, const G
rProcOptInfo&, bool, |
| 64 GrColor*, const GrDrawTargetC
aps&) override { |
| 65 return GrXferProcessor::kNone_Opt; |
| 66 } |
| 67 |
| 68 protected: |
| 69 void onGetGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const
override; |
| 70 |
| 71 void onGetBlendInfo(BlendInfo*) const override; |
| 72 |
| 73 const GrBlendEquation fEquation; |
| 74 |
| 75 typedef GrXferProcessor INHERITED; |
| 76 }; |
| 77 |
| 78 template<bool HasCoverage> class XferProcessor : public XferProcessorBase { |
| 79 public: |
| 80 XferProcessor(GrBlendEquation equation) : INHERITED(equation) { |
| 81 this->initClassID<XferProcessor>(); |
| 82 } |
| 83 |
| 84 GrGLXferProcessor* createGLInstance() const override; |
| 85 |
| 86 private: |
| 87 bool onIsEqual(const GrXferProcessor& xpBase) const override { |
| 88 const XferProcessor& xp = xpBase.cast<XferProcessor>(); |
| 89 return fEquation == xp.fEquation; |
| 90 } |
| 91 |
| 92 typedef XferProcessorBase INHERITED; |
| 93 }; |
| 94 |
| 95 const GrBlendEquation fEquation; |
| 96 mutable XferProcessor<true> fXferProcessorWithCoverage; |
| 97 mutable XferProcessor<false> fXferProcessor; |
| 98 |
| 99 GR_DECLARE_XP_FACTORY_TEST; |
| 100 |
| 101 typedef GrXPFactory INHERITED; |
| 102 }; |
| 103 |
| 104 #endif |
OLD | NEW |