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 GrPorterDuffXferProcessor_DEFINED 9 #define GrPorterDuffXferProcessor_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "src/gpu/ganesh/GrCaps.h" 13 #include "src/gpu/ganesh/GrProcessorAnalysis.h" 14 #include "src/gpu/ganesh/GrProcessorUnitTest.h" 15 #include "src/gpu/ganesh/GrXferProcessor.h" 16 17 enum class GrClampType; 18 enum class SkBlendMode; 19 20 // See the comment above GrXPFactory's definition about this warning suppression. 21 #if defined(__GNUC__) 22 #pragma GCC diagnostic push 23 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 24 #endif 25 #if defined(__clang__) 26 #pragma clang diagnostic push 27 #pragma clang diagnostic ignored "-Wnon-virtual-dtor" 28 #endif 29 class GrPorterDuffXPFactory : public GrXPFactory { 30 public: 31 static const GrXPFactory* Get(SkBlendMode blendMode); 32 33 /** Because src-over is so common we special case it for performance reasons. If this returns 34 null then the SimpleSrcOverXP() below should be used. */ 35 static sk_sp<const GrXferProcessor> MakeSrcOverXferProcessor(const GrProcessorAnalysisColor&, 36 GrProcessorAnalysisCoverage, 37 const GrCaps&); 38 39 /** Returns a simple non-LCD porter duff blend XP with no optimizations or coverage. */ 40 static sk_sp<const GrXferProcessor> MakeNoCoverageXP(SkBlendMode); 41 42 /** This XP implements non-LCD src-over using hw blend with no optimizations. It is returned 43 by reference because it is global and its ref-cnting methods are not thread safe. */ 44 static const GrXferProcessor& SimpleSrcOverXP(); 45 46 static AnalysisProperties SrcOverAnalysisProperties(const GrProcessorAnalysisColor&, 47 const GrProcessorAnalysisCoverage&, 48 const GrCaps&, 49 GrClampType); 50 51 private: 52 constexpr GrPorterDuffXPFactory(SkBlendMode); 53 54 sk_sp<const GrXferProcessor> makeXferProcessor(const GrProcessorAnalysisColor&, 55 GrProcessorAnalysisCoverage, 56 const GrCaps&, 57 GrClampType) const override; 58 59 AnalysisProperties analysisProperties(const GrProcessorAnalysisColor&, 60 const GrProcessorAnalysisCoverage&, 61 const GrCaps&, 62 GrClampType) const override; 63 64 GR_DECLARE_XP_FACTORY_TEST 65 static void TestGetXPOutputTypes(const GrXferProcessor*, int* outPrimary, int* outSecondary); 66 67 SkBlendMode fBlendMode; 68 69 friend class GrPorterDuffTest; // for TestGetXPOutputTypes() 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