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 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 13 | class GrInvariantOutput; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 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 | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 36 | static const GrFragmentProcessor* Create(GrTexture*, bool swapRedAndBlue, PMConversion, |
| 37 | const SkMatrix&); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 38 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 39 | const char* name() const override { return "Config Conversion"; } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 40 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 41 | bool swapsRedAndBlue() const { return fSwapRedAndBlue; } |
| 42 | 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 | |
| 53 | private: |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 54 | GrConfigConversionEffect(GrTexture*, |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 55 | bool swapRedAndBlue, |
| 56 | PMConversion pmConversion, |
| 57 | const SkMatrix& matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 58 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 59 | GrGLFragmentProcessor* onCreateGLInstance() const override; |
| 60 | |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 61 | void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override; |
| 62 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 63 | bool onIsEqual(const GrFragmentProcessor&) const override; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 64 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 65 | void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 66 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 67 | bool fSwapRedAndBlue; |
| 68 | PMConversion fPMConversion; |
| 69 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 70 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 71 | |
| 72 | typedef GrSingleTextureEffect INHERITED; |
| 73 | }; |
| 74 | |
| 75 | #endif |