blob: e5fa10cd9bfa8a1692f5ce3382c09178f7812f19 [file] [log] [blame]
bsalomon@google.coma04e8e82012-08-27 12:53:13 +00001/*
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 Osmanee805322017-04-05 10:09:00 -040011#include "GrFragmentProcessor.h"
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000012
13/**
14 * This class is used to perform config conversions. Clients may want to read/write data that is
Brian Osmance425512017-03-22 14:37:50 -040015 * unpremultiplied.
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000016 */
Brian Osmanee805322017-04-05 10:09:00 -040017class GrConfigConversionEffect : public GrFragmentProcessor {
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000018public:
19 /**
20 * The PM->UPM or UPM->PM conversions to apply.
21 */
22 enum PMConversion {
Brian Osmance425512017-03-22 14:37:50 -040023 kMulByAlpha_RoundUp_PMConversion = 0,
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000024 kMulByAlpha_RoundDown_PMConversion,
25 kDivByAlpha_RoundUp_PMConversion,
26 kDivByAlpha_RoundDown_PMConversion,
27
28 kPMConversionCnt
29 };
30
Brian Osmanee805322017-04-05 10:09:00 -040031 /**
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 Phillips757914d2017-01-25 15:48:30 -050036
mtklein36352bf2015-03-25 18:17:31 -070037 const char* name() const override { return "Config Conversion"; }
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000038
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000039 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.coma04e8e82012-08-27 12:53:13 +000049private:
Brian Osmanee805322017-04-05 10:09:00 -040050 GrConfigConversionEffect(PMConversion);
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000051
egdaniel57d3b032015-11-13 11:57:27 -080052 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070053
Brian Salomon94efbf52016-11-29 13:43:05 -050054 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070055
mtklein36352bf2015-03-25 18:17:31 -070056 bool onIsEqual(const GrFragmentProcessor&) const override;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000057
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000058 PMConversion fPMConversion;
59
joshualittb0a8a372014-09-23 09:50:21 -070060 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000061
Brian Osmanee805322017-04-05 10:09:00 -040062 typedef GrFragmentProcessor INHERITED;
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000063};
64
65#endif