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