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 GrCustomXfermodePriv_DEFINED 9 #define GrCustomXfermodePriv_DEFINED 10 11 #include "GrCoordTransform.h" 12 #include "GrDrawTargetCaps.h" 13 #include "GrFragmentProcessor.h" 14 #include "GrTextureAccess.h" 15 #include "GrXferProcessor.h" 16 #include "SkXfermode.h" 17 18 class GrGLCaps; 19 class GrGLFragmentProcessor; 20 class GrInvariantOutput; 21 class GrProcessorKeyBuilder; 22 class GrTexture; 23 24 /////////////////////////////////////////////////////////////////////////////// 25 // Fragment Processor 26 /////////////////////////////////////////////////////////////////////////////// 27 28 class GrCustomXferFP : public GrFragmentProcessor { 29 public: 30 GrCustomXferFP(SkXfermode::Mode mode, GrTexture* background); 31 32 void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override; 33 34 GrGLFragmentProcessor* createGLInstance() const override; 35 name()36 const char* name() const override { return "Custom Xfermode"; } 37 mode()38 SkXfermode::Mode mode() const { return fMode; } backgroundAccess()39 const GrTextureAccess& backgroundAccess() const { return fBackgroundAccess; } 40 41 private: 42 bool onIsEqual(const GrFragmentProcessor& other) const override; 43 44 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; 45 46 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 47 48 SkXfermode::Mode fMode; 49 GrCoordTransform fBackgroundTransform; 50 GrTextureAccess fBackgroundAccess; 51 52 typedef GrFragmentProcessor INHERITED; 53 }; 54 55 /////////////////////////////////////////////////////////////////////////////// 56 // Xfer Processor 57 /////////////////////////////////////////////////////////////////////////////// 58 59 class GrCustomXPFactory : public GrXPFactory { 60 public: 61 GrCustomXPFactory(SkXfermode::Mode mode); 62 supportsRGBCoverage(GrColor knownColor,uint32_t knownColorFlags)63 bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const override { 64 return true; 65 } 66 67 void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo& coveragePOI, 68 GrXPFactory::InvariantOutput*) const override; 69 70 private: 71 GrXferProcessor* onCreateXferProcessor(const GrDrawTargetCaps& caps, 72 const GrProcOptInfo& colorPOI, 73 const GrProcOptInfo& coveragePOI, 74 const GrDeviceCoordTexture* dstCopy) const override; 75 76 bool willReadDstColor(const GrDrawTargetCaps& caps, 77 const GrProcOptInfo& colorPOI, 78 const GrProcOptInfo& coveragePOI) const override; 79 onIsEqual(const GrXPFactory & xpfBase)80 bool onIsEqual(const GrXPFactory& xpfBase) const override { 81 const GrCustomXPFactory& xpf = xpfBase.cast<GrCustomXPFactory>(); 82 return fMode == xpf.fMode; 83 } 84 85 GR_DECLARE_XP_FACTORY_TEST; 86 87 SkXfermode::Mode fMode; 88 89 typedef GrXPFactory INHERITED; 90 }; 91 #endif 92 93