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 "SkXfermode.h" 14 15 class GrProcOptInfo; 16 17 class GrPorterDuffXPFactory : public GrXPFactory { 18 public: 19 static GrXPFactory* Create(SkXfermode::Mode mode); 20 21 void getInvariantBlendedColor(const GrProcOptInfo& colorPOI, 22 GrXPFactory::InvariantBlendedColor*) const override; 23 24 25 /** Because src-over is so common we special case it for performance reasons. If this returns 26 null then the SimpleSrcOverXP() below should be used. */ 27 static GrXferProcessor* CreateSrcOverXferProcessor(const GrCaps& caps, 28 const GrPipelineOptimizations& optimizations, 29 bool hasMixedSamples, 30 const GrXferProcessor::DstTexture*); 31 /** This XP implements non-LCD src-over using hw blend with no optimizations. It is returned 32 by reference because it is global and its ref-cnting methods are not thread safe. */ 33 static const GrXferProcessor& SimpleSrcOverXP(); 34 35 static inline void SrcOverInvariantBlendedColor( 36 GrColor inputColor, 37 GrColorComponentFlags validColorFlags, 38 bool isOpaque, 39 GrXPFactory::InvariantBlendedColor* blendedColor) { 40 if (!isOpaque) { 41 blendedColor->fWillBlendWithDst = true; 42 blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; 43 return; 44 } 45 blendedColor->fWillBlendWithDst = false; 46 47 blendedColor->fKnownColor = inputColor; 48 blendedColor->fKnownColorFlags = validColorFlags; 49 } 50 51 static bool SrcOverWillNeedDstTexture(const GrCaps& caps, 52 const GrPipelineOptimizations& optimizations, 53 bool hasMixedSamples); 54 55 private: 56 GrPorterDuffXPFactory(SkXfermode::Mode); 57 58 GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, 59 const GrPipelineOptimizations& optimizations, 60 bool hasMixedSamples, 61 const DstTexture*) const override; 62 63 bool onWillReadDstColor(const GrCaps& caps, 64 const GrPipelineOptimizations& optimizations, 65 bool hasMixedSamples) const override; 66 67 bool onIsEqual(const GrXPFactory& xpfBase) const override { 68 const GrPorterDuffXPFactory& xpf = xpfBase.cast<GrPorterDuffXPFactory>(); 69 return fXfermode == xpf.fXfermode; 70 } 71 72 GR_DECLARE_XP_FACTORY_TEST; 73 static void TestGetXPOutputTypes(const GrXferProcessor*, int* outPrimary, int* outSecondary); 74 75 SkXfermode::Mode fXfermode; 76 77 friend class GrPorterDuffTest; // for TestGetXPOutputTypes() 78 typedef GrXPFactory INHERITED; 79 }; 80 81 #endif 82