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 | |
| 13 | class GrGLConfigConversionEffect; |
| 14 | |
| 15 | /** |
| 16 | * This class is used to perform config conversions. Clients may want to read/write data that is |
| 17 | * unpremultiplied. Also on some systems reading/writing BGRA or RGBA is faster. In those cases we |
| 18 | * read/write using the faster path and perform an R/B swap in the shader if the client data is in |
| 19 | * the slower config. |
| 20 | */ |
| 21 | class GrConfigConversionEffect : public GrSingleTextureEffect { |
| 22 | public: |
| 23 | /** |
| 24 | * The PM->UPM or UPM->PM conversions to apply. |
| 25 | */ |
| 26 | enum PMConversion { |
| 27 | kNone_PMConversion = 0, |
| 28 | kMulByAlpha_RoundUp_PMConversion, |
| 29 | kMulByAlpha_RoundDown_PMConversion, |
| 30 | kDivByAlpha_RoundUp_PMConversion, |
| 31 | kDivByAlpha_RoundDown_PMConversion, |
| 32 | |
| 33 | kPMConversionCnt |
| 34 | }; |
| 35 | |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 36 | // Installs an effect in the GrEffectStage to perform a config conversion. |
| 37 | static bool InstallEffect(GrTexture*, |
| 38 | bool swapRedAndBlue, |
| 39 | PMConversion pmConversion, |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 40 | const SkMatrix& matrix, |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 41 | GrEffectStage* stage); |
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 | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 47 | virtual bool isEqual(const GrEffect&) const SK_OVERRIDE; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 48 | |
| 49 | bool swapsRedAndBlue() const { return fSwapRedAndBlue; } |
| 50 | PMConversion pmConversion() const { return fPMConversion; } |
| 51 | |
| 52 | // This function determines whether it is possible to choose PM->UPM and UPM->PM conversions |
| 53 | // for which in any PM->UPM->PM->UPM sequence the two UPM values are the same. This means that |
| 54 | // if pixels are read back to a UPM buffer, written back to PM to the GPU, and read back again |
| 55 | // both reads will produce the same result. This test is quite expensive and should not be run |
| 56 | // multiple times for a given context. |
| 57 | static void TestForPreservingPMConversions(GrContext* context, |
| 58 | PMConversion* PMToUPMRule, |
| 59 | PMConversion* UPMToPMRule); |
| 60 | |
| 61 | private: |
| 62 | GrConfigConversionEffect(GrTexture*, |
| 63 | bool swapRedAndBlue, |
bsalomon@google.com | b1456d7 | 2012-11-02 18:23:45 +0000 | [diff] [blame^] | 64 | PMConversion pmConversion, |
| 65 | const SkMatrix& matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 66 | |
| 67 | bool fSwapRedAndBlue; |
| 68 | PMConversion fPMConversion; |
| 69 | |
bsalomon@google.com | f271cc7 | 2012-10-24 19:35:13 +0000 | [diff] [blame] | 70 | GR_DECLARE_EFFECT_TEST; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 71 | |
| 72 | typedef GrSingleTextureEffect INHERITED; |
| 73 | }; |
| 74 | |
| 75 | #endif |