| 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/SkBlendMode.h" |
| 12 | #include "include/gpu/GrTypes.h" |
| 13 | #include "src/gpu/GrXferProcessor.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 | GrClampType); |
| 46 | |
| 47 | private: |
| 48 | constexpr GrPorterDuffXPFactory(SkBlendMode); |
| 49 | |
| 50 | sk_sp<const GrXferProcessor> makeXferProcessor(const GrProcessorAnalysisColor&, |
| 51 | GrProcessorAnalysisCoverage, |
| 52 | bool hasMixedSamples, |
| 53 | const GrCaps&, |
| 54 | GrClampType) const override; |
| 55 | |
| 56 | AnalysisProperties analysisProperties(const GrProcessorAnalysisColor&, |
| 57 | const GrProcessorAnalysisCoverage&, |
| 58 | const GrCaps&, |
| 59 | GrClampType) const override; |
| 60 | |
| 61 | GR_DECLARE_XP_FACTORY_TEST |
| 62 | static void TestGetXPOutputTypes(const GrXferProcessor*, int* outPrimary, int* outSecondary); |
| 63 | |
| 64 | SkBlendMode fBlendMode; |
| 65 | |
| 66 | friend class GrPorterDuffTest; // for TestGetXPOutputTypes() |
| 67 | typedef GrXPFactory INHERITED; |
| 68 | }; |
| 69 | #if defined(__GNUC__) |
| 70 | #pragma GCC diagnostic pop |
| 71 | #endif |
| 72 | #if defined(__clang__) |
| 73 | #pragma clang diagnostic pop |
| 74 | #endif |
| 75 | |
| 76 | #endif |
| 77 | |