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 "GrTypes.h" 12 #include "GrXferProcessor.h" 13 #include "SkBlendMode.h" 14 15 // See the comment above GrXPFactory's definition about this warning suppression. 16 #if defined(__GNUC__) || defined(__clang) 17 #pragma GCC diagnostic push 18 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 19 #endif 20 class GrPorterDuffXPFactory : public GrXPFactory { 21 public: 22 static const GrXPFactory* Get(SkBlendMode blendMode); 23 24 /** Because src-over is so common we special case it for performance reasons. If this returns 25 null then the SimpleSrcOverXP() below should be used. */ 26 static GrXferProcessor* CreateSrcOverXferProcessor(const GrCaps& caps, 27 const FragmentProcessorAnalysis&, 28 bool hasMixedSamples, 29 const GrXferProcessor::DstTexture*); 30 31 /** Returns a simple non-LCD porter duff blend XP with no optimizations or coverage. */ 32 static sk_sp<GrXferProcessor> CreateNoCoverageXP(SkBlendMode); 33 34 /** This XP implements non-LCD src-over using hw blend with no optimizations. It is returned 35 by reference because it is global and its ref-cnting methods are not thread safe. */ 36 static const GrXferProcessor& SimpleSrcOverXP(); 37 38 static bool WillSrcOverNeedDstTexture(const GrCaps&, const FragmentProcessorAnalysis&); SrcOverIsCompatibleWithCoverageAsAlpha()39 static bool SrcOverIsCompatibleWithCoverageAsAlpha() { return true; } SrcOverCanCombineOverlappedStencilAndCover(bool colorIsOpaque)40 static bool SrcOverCanCombineOverlappedStencilAndCover(bool colorIsOpaque) { 41 return colorIsOpaque; 42 } 43 44 private: 45 constexpr GrPorterDuffXPFactory(SkBlendMode); 46 47 bool canCombineOverlappedStencilAndCover(bool colorIsOpaque) const override; 48 49 GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, 50 const FragmentProcessorAnalysis&, 51 bool hasMixedSamples, 52 const DstTexture*) const override; 53 54 bool willReadDstInShader(const GrCaps&, const FragmentProcessorAnalysis&) const override; 55 56 bool compatibleWithCoverageAsAlpha(bool colorIsOpaque) const override; 57 58 GR_DECLARE_XP_FACTORY_TEST; 59 static void TestGetXPOutputTypes(const GrXferProcessor*, int* outPrimary, int* outSecondary); 60 61 SkBlendMode fBlendMode; 62 63 friend class GrPorterDuffTest; // for TestGetXPOutputTypes() 64 typedef GrXPFactory INHERITED; 65 }; 66 #if defined(__GNUC__) || defined(__clang) 67 #pragma GCC diagnostic pop 68 #endif 69 70 #endif 71