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 | |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 13 | class GrFragmentStage; |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 14 | class GrInvariantOutput; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 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 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 37 | static const GrFragmentProcessor* Create(GrTexture*, bool swapRedAndBlue, PMConversion, |
| 38 | const SkMatrix&); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 39 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 40 | const char* name() const SK_OVERRIDE { return "Config Conversion"; } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 41 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 42 | void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const SK_OVERRIDE; |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 43 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 44 | GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 45 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 46 | bool swapsRedAndBlue() const { return fSwapRedAndBlue; } |
| 47 | PMConversion pmConversion() const { return fPMConversion; } |
| 48 | |
| 49 | // This function determines whether it is possible to choose PM->UPM and UPM->PM conversions |
| 50 | // for which in any PM->UPM->PM->UPM sequence the two UPM values are the same. This means that |
| 51 | // if pixels are read back to a UPM buffer, written back to PM to the GPU, and read back again |
| 52 | // both reads will produce the same result. This test is quite expensive and should not be run |
| 53 | // multiple times for a given context. |
| 54 | static void TestForPreservingPMConversions(GrContext* context, |
| 55 | PMConversion* PMToUPMRule, |
| 56 | PMConversion* UPMToPMRule); |
| 57 | |
| 58 | private: |
| 59 | GrConfigConversionEffect(GrTexture*, |
| 60 | bool swapRedAndBlue, |
bsalomon@google.com | b1456d7 | 2012-11-02 18:23:45 +0000 | [diff] [blame] | 61 | PMConversion pmConversion, |
| 62 | const SkMatrix& matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 63 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 64 | bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 65 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame^] | 66 | void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 67 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 68 | bool fSwapRedAndBlue; |
| 69 | PMConversion fPMConversion; |
| 70 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 71 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 72 | |
| 73 | typedef GrSingleTextureEffect INHERITED; |
| 74 | }; |
| 75 | |
| 76 | #endif |