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 #include "GrSwizzle.h" |
12 | 13 |
13 class GrInvariantOutput; | 14 class GrInvariantOutput; |
14 | 15 |
15 /** | 16 /** |
16 * 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 |
17 * unpremultiplied. Also on some systems reading/writing BGRA or RGBA is faster.
In those cases we | 18 * unpremultiplied. Additionally, the channels may also be swizzled for optimal
readback/upload |
18 * read/write using the faster path and perform an R/B swap in the shader if the
client data is in | 19 * performance. |
19 * the slower config. | |
20 */ | 20 */ |
21 class GrConfigConversionEffect : public GrSingleTextureEffect { | 21 class GrConfigConversionEffect : public GrSingleTextureEffect { |
22 public: | 22 public: |
23 /** | 23 /** |
24 * The PM->UPM or UPM->PM conversions to apply. | 24 * The PM->UPM or UPM->PM conversions to apply. |
25 */ | 25 */ |
26 enum PMConversion { | 26 enum PMConversion { |
27 kNone_PMConversion = 0, | 27 kNone_PMConversion = 0, |
28 kMulByAlpha_RoundUp_PMConversion, | 28 kMulByAlpha_RoundUp_PMConversion, |
29 kMulByAlpha_RoundDown_PMConversion, | 29 kMulByAlpha_RoundDown_PMConversion, |
30 kDivByAlpha_RoundUp_PMConversion, | 30 kDivByAlpha_RoundUp_PMConversion, |
31 kDivByAlpha_RoundDown_PMConversion, | 31 kDivByAlpha_RoundDown_PMConversion, |
32 | 32 |
33 kPMConversionCnt | 33 kPMConversionCnt |
34 }; | 34 }; |
35 | 35 |
36 static const GrFragmentProcessor* Create(GrTexture*, bool swapRedAndBlue, PM
Conversion, | 36 static const GrFragmentProcessor* Create(GrTexture*, const GrSwizzle&, PMCon
version, |
37 const SkMatrix&); | 37 const SkMatrix&); |
38 | 38 |
39 const char* name() const override { return "Config Conversion"; } | 39 const char* name() const override { return "Config Conversion"; } |
40 | 40 |
41 bool swapsRedAndBlue() const { return fSwapRedAndBlue; } | 41 const GrSwizzle& swizzle() const { return fSwizzle; } |
42 PMConversion pmConversion() const { return fPMConversion; } | 42 PMConversion pmConversion() const { return fPMConversion; } |
43 | 43 |
44 // This function determines whether it is possible to choose PM->UPM and UPM
->PM conversions | 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 sam
e. This means that | 45 // for which in any PM->UPM->PM->UPM sequence the two UPM values are the sam
e. This means that |
46 // if pixels are read back to a UPM buffer, written back to PM to the GPU, a
nd read back again | 46 // if pixels are read back to a UPM buffer, written back to PM to the GPU, a
nd read back again |
47 // both reads will produce the same result. This test is quite expensive and
should not be run | 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. | 48 // multiple times for a given context. |
49 static void TestForPreservingPMConversions(GrContext* context, | 49 static void TestForPreservingPMConversions(GrContext* context, |
50 PMConversion* PMToUPMRule, | 50 PMConversion* PMToUPMRule, |
51 PMConversion* UPMToPMRule); | 51 PMConversion* UPMToPMRule); |
52 | 52 |
53 private: | 53 private: |
54 GrConfigConversionEffect(GrTexture*, | 54 GrConfigConversionEffect(GrTexture*, |
55 bool swapRedAndBlue, | 55 const GrSwizzle&, |
56 PMConversion pmConversion, | 56 PMConversion pmConversion, |
57 const SkMatrix& matrix); | 57 const SkMatrix& matrix); |
58 | 58 |
59 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 59 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
60 | 60 |
61 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; | 61 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; |
62 | 62 |
63 bool onIsEqual(const GrFragmentProcessor&) const override; | 63 bool onIsEqual(const GrFragmentProcessor&) const override; |
64 | 64 |
65 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 65 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
66 | 66 |
67 bool fSwapRedAndBlue; | 67 GrSwizzle fSwizzle; |
68 PMConversion fPMConversion; | 68 PMConversion fPMConversion; |
69 | 69 |
70 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 70 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
71 | 71 |
72 typedef GrSingleTextureEffect INHERITED; | 72 typedef GrSingleTextureEffect INHERITED; |
73 }; | 73 }; |
74 | 74 |
75 #endif | 75 #endif |
OLD | NEW |