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 | |
Brian Osman | ee80532 | 2017-04-05 10:09:00 -0400 | [diff] [blame^] | 11 | #include "GrFragmentProcessor.h" |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * This class is used to perform config conversions. Clients may want to read/write data that is |
Brian Osman | ce42551 | 2017-03-22 14:37:50 -0400 | [diff] [blame] | 15 | * unpremultiplied. |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 16 | */ |
Brian Osman | ee80532 | 2017-04-05 10:09:00 -0400 | [diff] [blame^] | 17 | class GrConfigConversionEffect : public GrFragmentProcessor { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 18 | public: |
| 19 | /** |
| 20 | * The PM->UPM or UPM->PM conversions to apply. |
| 21 | */ |
| 22 | enum PMConversion { |
Brian Osman | ce42551 | 2017-03-22 14:37:50 -0400 | [diff] [blame] | 23 | kMulByAlpha_RoundUp_PMConversion = 0, |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 24 | kMulByAlpha_RoundDown_PMConversion, |
| 25 | kDivByAlpha_RoundUp_PMConversion, |
| 26 | kDivByAlpha_RoundDown_PMConversion, |
| 27 | |
| 28 | kPMConversionCnt |
| 29 | }; |
| 30 | |
Brian Osman | ee80532 | 2017-04-05 10:09:00 -0400 | [diff] [blame^] | 31 | /** |
| 32 | * Returns a fragment processor that calls the passed in fragment processor, and then performs |
| 33 | * the requested premul or unpremul conversion. |
| 34 | */ |
| 35 | static sk_sp<GrFragmentProcessor> Make(sk_sp<GrFragmentProcessor>, PMConversion); |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 36 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 37 | const char* name() const override { return "Config Conversion"; } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 38 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 39 | PMConversion pmConversion() const { return fPMConversion; } |
| 40 | |
| 41 | // This function determines whether it is possible to choose PM->UPM and UPM->PM conversions |
| 42 | // for which in any PM->UPM->PM->UPM sequence the two UPM values are the same. This means that |
| 43 | // if pixels are read back to a UPM buffer, written back to PM to the GPU, and read back again |
| 44 | // both reads will produce the same result. This test is quite expensive and should not be run |
| 45 | // multiple times for a given context. |
| 46 | static void TestForPreservingPMConversions(GrContext* context, |
| 47 | PMConversion* PMToUPMRule, |
| 48 | PMConversion* UPMToPMRule); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 49 | private: |
Brian Osman | ee80532 | 2017-04-05 10:09:00 -0400 | [diff] [blame^] | 50 | GrConfigConversionEffect(PMConversion); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 51 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 52 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 53 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 54 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 55 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 56 | bool onIsEqual(const GrFragmentProcessor&) const override; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 57 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 58 | PMConversion fPMConversion; |
| 59 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 60 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 61 | |
Brian Osman | ee80532 | 2017-04-05 10:09:00 -0400 | [diff] [blame^] | 62 | typedef GrFragmentProcessor INHERITED; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | #endif |