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 "include/core/SkRegion.h" 12 #include "include/gpu/GrTypes.h" 13 #include "src/gpu/GrXferProcessor.h" 14 15 // See the comment above GrXPFactory's definition about this warning suppression. 16 #if defined(__GNUC__) 17 #pragma GCC diagnostic push 18 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 19 #endif 20 #if defined(__clang__) 21 #pragma clang diagnostic push 22 #pragma clang diagnostic ignored "-Wnon-virtual-dtor" 23 #endif 24 25 /** 26 * This xfer processor directly blends the the src coverage with the dst using a set operator. It is 27 * useful for rendering coverage masks using CSG. It can optionally invert the src coverage before 28 * applying the set operator. 29 */ 30 class GrCoverageSetOpXPFactory : public GrXPFactory { 31 public: 32 static const GrXPFactory* Get(SkRegion::Op regionOp, bool invertCoverage = false); 33 34 private: 35 constexpr GrCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage); 36 37 sk_sp<const GrXferProcessor> makeXferProcessor(const GrProcessorAnalysisColor&, 38 GrProcessorAnalysisCoverage, 39 const GrCaps&, 40 GrClampType) const override; 41 analysisProperties(const GrProcessorAnalysisColor & color,const GrProcessorAnalysisCoverage & coverage,const GrCaps &,GrClampType)42 AnalysisProperties analysisProperties(const GrProcessorAnalysisColor& color, 43 const GrProcessorAnalysisCoverage& coverage, 44 const GrCaps&, 45 GrClampType) const override { 46 auto props = AnalysisProperties::kIgnoresInputColor; 47 switch (fRegionOp) { 48 case SkRegion::kReplace_Op: 49 props |= AnalysisProperties::kUnaffectedByDstValue; 50 break; 51 case SkRegion::kUnion_Op: 52 case SkRegion::kDifference_Op: 53 // FIXME: If we can formalize the fact that this op only operates on alpha, we can 54 // set AnalysisProperties::kUnaffectedByDstValue if color/coverage are all opaque. 55 break; 56 case SkRegion::kIntersect_Op: 57 case SkRegion::kXOR_Op: 58 case SkRegion::kReverseDifference_Op: 59 break; 60 } 61 return props; 62 } 63 64 65 GR_DECLARE_XP_FACTORY_TEST 66 67 SkRegion::Op fRegionOp; 68 bool fInvertCoverage; 69 70 using INHERITED = GrXPFactory; 71 }; 72 #if defined(__GNUC__) 73 #pragma GCC diagnostic pop 74 #endif 75 #if defined(__clang__) 76 #pragma clang diagnostic pop 77 #endif 78 79 #endif 80