1 /* 2 * Copyright 2014 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 GrCoverageSetOpXP_DEFINED 9 #define GrCoverageSetOpXP_DEFINED 10 11 #include "GrTypes.h" 12 #include "GrXferProcessor.h" 13 #include "SkRegion.h" 14 15 class GrProcOptInfo; 16 17 /** 18 * This xfer processor directly blends the the src coverage with the dst using a set operator. It is 19 * useful for rendering coverage masks using CSG. It can optionally invert the src coverage before 20 * applying the set operator. 21 */ 22 class GrCoverageSetOpXPFactory : public GrXPFactory { 23 public: 24 static GrXPFactory* Create(SkRegion::Op regionOp, bool invertCoverage = false); 25 supportsRGBCoverage(GrColor,uint32_t)26 bool supportsRGBCoverage(GrColor /*knownColor*/, 27 uint32_t /*knownColorFlags*/) const override { 28 return true; 29 } 30 31 void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo& coveragePOI, 32 GrXPFactory::InvariantOutput*) const override; 33 34 private: 35 GrCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage); 36 37 GrXferProcessor* onCreateXferProcessor(const GrDrawTargetCaps& caps, 38 const GrProcOptInfo& colorPOI, 39 const GrProcOptInfo& coveragePOI, 40 const GrDeviceCoordTexture* dstCopy) const override; 41 willReadDstColor(const GrDrawTargetCaps &,const GrProcOptInfo &,const GrProcOptInfo &)42 bool willReadDstColor(const GrDrawTargetCaps& /*caps*/, 43 const GrProcOptInfo& /*colorPOI*/, 44 const GrProcOptInfo& /*coveragePOI*/) const override { 45 return false; 46 } 47 onIsEqual(const GrXPFactory & xpfBase)48 bool onIsEqual(const GrXPFactory& xpfBase) const override { 49 const GrCoverageSetOpXPFactory& xpf = xpfBase.cast<GrCoverageSetOpXPFactory>(); 50 return fRegionOp == xpf.fRegionOp; 51 } 52 53 GR_DECLARE_XP_FACTORY_TEST; 54 55 SkRegion::Op fRegionOp; 56 bool fInvertCoverage; 57 58 typedef GrXPFactory INHERITED; 59 }; 60 #endif 61 62