Home | History | Annotate | Download | only in effects
      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 sk_sp<const GrXferProcessor> MakeSrcOverXferProcessor(const GrProcessorAnalysisColor&,
     27                                                                  GrProcessorAnalysisCoverage,
     28                                                                  bool hasMixedSamples,
     29                                                                  const GrCaps&);
     30 
     31     /** Returns a simple non-LCD porter duff blend XP with no optimizations or coverage. */
     32     static sk_sp<const GrXferProcessor> MakeNoCoverageXP(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 AnalysisProperties SrcOverAnalysisProperties(const GrProcessorAnalysisColor&,
     39                                                         const GrProcessorAnalysisCoverage&,
     40                                                         const GrCaps&);
     41 
     42 private:
     43     constexpr GrPorterDuffXPFactory(SkBlendMode);
     44 
     45     sk_sp<const GrXferProcessor> makeXferProcessor(const GrProcessorAnalysisColor&,
     46                                                    GrProcessorAnalysisCoverage,
     47                                                    bool hasMixedSamples,
     48                                                    const GrCaps&) const override;
     49 
     50     AnalysisProperties analysisProperties(const GrProcessorAnalysisColor&,
     51                                           const GrProcessorAnalysisCoverage&,
     52                                           const GrCaps&) const override;
     53 
     54     GR_DECLARE_XP_FACTORY_TEST
     55     static void TestGetXPOutputTypes(const GrXferProcessor*, int* outPrimary, int* outSecondary);
     56 
     57     SkBlendMode fBlendMode;
     58 
     59     friend class GrPorterDuffTest; // for TestGetXPOutputTypes()
     60     typedef GrXPFactory INHERITED;
     61 };
     62 #if defined(__GNUC__) || defined(__clang)
     63 #pragma GCC diagnostic pop
     64 #endif
     65 
     66 #endif
     67