bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 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 "GrSingleTextureEffect.h" |
| 12 | |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 13 | class GrEffectStage; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 14 | class GrGLConfigConversionEffect; |
| 15 | |
| 16 | /** |
| 17 | * This class is used to perform config conversions. Clients may want to read/write data that is |
| 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 |
| 20 | * the slower config. |
| 21 | */ |
| 22 | class GrConfigConversionEffect : public GrSingleTextureEffect { |
| 23 | public: |
| 24 | /** |
| 25 | * The PM->UPM or UPM->PM conversions to apply. |
| 26 | */ |
| 27 | enum PMConversion { |
| 28 | kNone_PMConversion = 0, |
| 29 | kMulByAlpha_RoundUp_PMConversion, |
| 30 | kMulByAlpha_RoundDown_PMConversion, |
| 31 | kDivByAlpha_RoundUp_PMConversion, |
| 32 | kDivByAlpha_RoundDown_PMConversion, |
| 33 | |
| 34 | kPMConversionCnt |
| 35 | }; |
| 36 | |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 37 | // Installs an effect in the GrEffectStage to perform a config conversion. |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 38 | static const GrEffectRef* Create(GrTexture*, |
| 39 | bool swapRedAndBlue, |
| 40 | PMConversion pmConversion, |
| 41 | const SkMatrix& matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 42 | |
| 43 | static const char* Name() { return "Config Conversion"; } |
bsalomon@google.com | 422e81a | 2012-10-25 14:11:03 +0000 | [diff] [blame] | 44 | typedef GrGLConfigConversionEffect GLEffect; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 45 | |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 46 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 47 | |
| 48 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 49 | |
| 50 | bool swapsRedAndBlue() const { return fSwapRedAndBlue; } |
| 51 | PMConversion pmConversion() const { return fPMConversion; } |
| 52 | |
| 53 | // 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 same. This means that |
| 55 | // if pixels are read back to a UPM buffer, written back to PM to the GPU, and read back again |
| 56 | // both reads will produce the same result. This test is quite expensive and should not be run |
| 57 | // multiple times for a given context. |
| 58 | static void TestForPreservingPMConversions(GrContext* context, |
| 59 | PMConversion* PMToUPMRule, |
| 60 | PMConversion* UPMToPMRule); |
| 61 | |
| 62 | private: |
| 63 | GrConfigConversionEffect(GrTexture*, |
| 64 | bool swapRedAndBlue, |
bsalomon@google.com | b1456d7 | 2012-11-02 18:23:45 +0000 | [diff] [blame] | 65 | PMConversion pmConversion, |
| 66 | const SkMatrix& matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 67 | |
bsalomon@google.com | 8a252f7 | 2013-01-22 20:35:13 +0000 | [diff] [blame] | 68 | virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 69 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 70 | bool fSwapRedAndBlue; |
| 71 | PMConversion fPMConversion; |
| 72 | |
bsalomon@google.com | f271cc7 | 2012-10-24 19:35:13 +0000 | [diff] [blame] | 73 | GR_DECLARE_EFFECT_TEST; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 74 | |
| 75 | typedef GrSingleTextureEffect INHERITED; |
| 76 | }; |
| 77 | |
| 78 | #endif |