Line data Source code
1 : /*
2 : * Copyright 2012 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 GrConfigConversionEffect_DEFINED
9 : #define GrConfigConversionEffect_DEFINED
10 :
11 : #include "GrFragmentProcessor.h"
12 :
13 : /**
14 : * This class is used to perform config conversions. Clients may want to read/write data that is
15 : * unpremultiplied.
16 : */
17 0 : class GrConfigConversionEffect : public GrFragmentProcessor {
18 : public:
19 : /**
20 : * The PM->UPM or UPM->PM conversions to apply.
21 : */
22 : enum PMConversion {
23 : kMulByAlpha_RoundUp_PMConversion = 0,
24 : kMulByAlpha_RoundDown_PMConversion,
25 : kMulByAlpha_RoundNearest_PMConversion,
26 :
27 : kDivByAlpha_RoundUp_PMConversion,
28 : kDivByAlpha_RoundDown_PMConversion,
29 : kDivByAlpha_RoundNearest_PMConversion,
30 :
31 : kPMConversionCnt
32 : };
33 :
34 : /**
35 : * Returns a fragment processor that calls the passed in fragment processor, and then performs
36 : * the requested premul or unpremul conversion.
37 : */
38 : static sk_sp<GrFragmentProcessor> Make(sk_sp<GrFragmentProcessor>, PMConversion);
39 :
40 0 : const char* name() const override { return "Config Conversion"; }
41 :
42 0 : PMConversion pmConversion() const { return fPMConversion; }
43 :
44 : // This function determines whether it is possible to choose PM->UPM and UPM->PM conversions
45 : // for which in any PM->UPM->PM->UPM sequence the two UPM values are the same. This means that
46 : // if pixels are read back to a UPM buffer, written back to PM to the GPU, and read back again
47 : // both reads will produce the same result. This test is quite expensive and should not be run
48 : // multiple times for a given context.
49 : static void TestForPreservingPMConversions(GrContext* context,
50 : PMConversion* PMToUPMRule,
51 : PMConversion* UPMToPMRule);
52 : private:
53 : GrConfigConversionEffect(PMConversion);
54 :
55 : GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
56 :
57 : void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
58 :
59 : bool onIsEqual(const GrFragmentProcessor&) const override;
60 :
61 : PMConversion fPMConversion;
62 :
63 : GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
64 :
65 : typedef GrFragmentProcessor INHERITED;
66 : };
67 :
68 : #endif
|