OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrConfigConversionEffect_DEFINED | 8 #ifndef GrConfigConversionEffect_DEFINED |
9 #define GrConfigConversionEffect_DEFINED | 9 #define GrConfigConversionEffect_DEFINED |
10 | 10 |
11 #include "GrSingleTextureEffect.h" | 11 #include "GrSingleTextureEffect.h" |
12 | 12 |
13 class GrEffectStage; | 13 class GrProcessorStage; |
14 class GrGLConfigConversionEffect; | 14 class GrGLConfigConversionEffect; |
15 | 15 |
16 /** | 16 /** |
17 * This class is used to perform config conversions. Clients may want to read/wr
ite data that is | 17 * This class is used to perform config conversions. Clients may want to read/wr
ite data that is |
18 * unpremultiplied. Also on some systems reading/writing BGRA or RGBA is faster.
In those cases we | 18 * unpremultiplied. Also on some systems reading/writing BGRA or RGBA is faster.
In those cases we |
19 * read/write using the faster path and perform an R/B swap in the shader if the
client data is in | 19 * read/write using the faster path and perform an R/B swap in the shader if the
client data is in |
20 * the slower config. | 20 * the slower config. |
21 */ | 21 */ |
22 class GrConfigConversionEffect : public GrSingleTextureEffect { | 22 class GrConfigConversionEffect : public GrSingleTextureEffect { |
23 public: | 23 public: |
24 /** | 24 /** |
25 * The PM->UPM or UPM->PM conversions to apply. | 25 * The PM->UPM or UPM->PM conversions to apply. |
26 */ | 26 */ |
27 enum PMConversion { | 27 enum PMConversion { |
28 kNone_PMConversion = 0, | 28 kNone_PMConversion = 0, |
29 kMulByAlpha_RoundUp_PMConversion, | 29 kMulByAlpha_RoundUp_PMConversion, |
30 kMulByAlpha_RoundDown_PMConversion, | 30 kMulByAlpha_RoundDown_PMConversion, |
31 kDivByAlpha_RoundUp_PMConversion, | 31 kDivByAlpha_RoundUp_PMConversion, |
32 kDivByAlpha_RoundDown_PMConversion, | 32 kDivByAlpha_RoundDown_PMConversion, |
33 | 33 |
34 kPMConversionCnt | 34 kPMConversionCnt |
35 }; | 35 }; |
36 | 36 |
37 // Installs an effect in the GrEffectStage to perform a config conversion. | 37 // Installs an effect in the GrProcessorStage to perform a config conversion
. |
38 static const GrEffect* Create(GrTexture*, | 38 static const GrFragmentProcessor* Create(GrTexture*, bool swapRedAndBlue, PM
Conversion, |
39 bool swapRedAndBlue, | 39 const SkMatrix&); |
40 PMConversion pmConversion, | |
41 const SkMatrix& matrix); | |
42 | 40 |
43 static const char* Name() { return "Config Conversion"; } | 41 static const char* Name() { return "Config Conversion"; } |
44 typedef GrGLConfigConversionEffect GLEffect; | 42 typedef GrGLConfigConversionEffect GLProcessor; |
45 | 43 |
46 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 44 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; |
47 | 45 |
48 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | 46 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
49 | 47 |
50 bool swapsRedAndBlue() const { return fSwapRedAndBlue; } | 48 bool swapsRedAndBlue() const { return fSwapRedAndBlue; } |
51 PMConversion pmConversion() const { return fPMConversion; } | 49 PMConversion pmConversion() const { return fPMConversion; } |
52 | 50 |
53 // This function determines whether it is possible to choose PM->UPM and UPM
->PM conversions | 51 // This function determines whether it is possible to choose PM->UPM and UPM
->PM conversions |
54 // for which in any PM->UPM->PM->UPM sequence the two UPM values are the sam
e. This means that | 52 // for which in any PM->UPM->PM->UPM sequence the two UPM values are the sam
e. This means that |
55 // if pixels are read back to a UPM buffer, written back to PM to the GPU, a
nd read back again | 53 // if pixels are read back to a UPM buffer, written back to PM to the GPU, a
nd read back again |
56 // both reads will produce the same result. This test is quite expensive and
should not be run | 54 // both reads will produce the same result. This test is quite expensive and
should not be run |
57 // multiple times for a given context. | 55 // multiple times for a given context. |
58 static void TestForPreservingPMConversions(GrContext* context, | 56 static void TestForPreservingPMConversions(GrContext* context, |
59 PMConversion* PMToUPMRule, | 57 PMConversion* PMToUPMRule, |
60 PMConversion* UPMToPMRule); | 58 PMConversion* UPMToPMRule); |
61 | 59 |
62 private: | 60 private: |
63 GrConfigConversionEffect(GrTexture*, | 61 GrConfigConversionEffect(GrTexture*, |
64 bool swapRedAndBlue, | 62 bool swapRedAndBlue, |
65 PMConversion pmConversion, | 63 PMConversion pmConversion, |
66 const SkMatrix& matrix); | 64 const SkMatrix& matrix); |
67 | 65 |
68 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 66 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; |
69 | 67 |
70 bool fSwapRedAndBlue; | 68 bool fSwapRedAndBlue; |
71 PMConversion fPMConversion; | 69 PMConversion fPMConversion; |
72 | 70 |
73 GR_DECLARE_EFFECT_TEST; | 71 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
74 | 72 |
75 typedef GrSingleTextureEffect INHERITED; | 73 typedef GrSingleTextureEffect INHERITED; |
76 }; | 74 }; |
77 | 75 |
78 #endif | 76 #endif |
OLD | NEW |