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__)
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 class GrPorterDuffXPFactory : public GrXPFactory {
25 public:
26     static const GrXPFactory* Get(SkBlendMode blendMode);
27 
28     /** Because src-over is so common we special case it for performance reasons. If this returns
29         null then the SimpleSrcOverXP() below should be used. */
30     static sk_sp<const GrXferProcessor> MakeSrcOverXferProcessor(const GrProcessorAnalysisColor&,
31                                                                  GrProcessorAnalysisCoverage,
32                                                                  bool hasMixedSamples,
33                                                                  const GrCaps&);
34 
35     /** Returns a simple non-LCD porter duff blend XP with no optimizations or coverage. */
36     static sk_sp<const GrXferProcessor> MakeNoCoverageXP(SkBlendMode);
37 
38     /** This XP implements non-LCD src-over using hw blend with no optimizations. It is returned
39         by reference because it is global and its ref-cnting methods are not thread safe. */
40     static const GrXferProcessor& SimpleSrcOverXP();
41 
42     static AnalysisProperties SrcOverAnalysisProperties(const GrProcessorAnalysisColor&,
43                                                         const GrProcessorAnalysisCoverage&,
44                                                         const GrCaps&);
45 
46 private:
47     constexpr GrPorterDuffXPFactory(SkBlendMode);
48 
49     sk_sp<const GrXferProcessor> makeXferProcessor(const GrProcessorAnalysisColor&,
50                                                    GrProcessorAnalysisCoverage,
51                                                    bool hasMixedSamples,
52                                                    const GrCaps&) const override;
53 
54     AnalysisProperties analysisProperties(const GrProcessorAnalysisColor&,
55                                           const GrProcessorAnalysisCoverage&,
56                                           const GrCaps&) 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__)
67 #pragma GCC diagnostic pop
68 #endif
69 #if defined(__clang__)
70 #pragma clang diagnostic pop
71 #endif
72 
73 #endif
74