blob: fe8f50bdf5a7dab22ff96d55c6987ebe784baaf4 [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 Osman28804f32017-04-20 10:24:36 -040023 kToPremul_PMConversion = 0,
24 kToUnpremul_PMConversion,
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000025 kPMConversionCnt
26 };
27
Brian Osmanee805322017-04-05 10:09:00 -040028 /**
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 Phillips757914d2017-01-25 15:48:30 -050033
mtklein36352bf2015-03-25 18:17:31 -070034 const char* name() const override { return "Config Conversion"; }
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000035
Brian Salomonfcc527b2017-07-26 12:21:21 -040036 sk_sp<GrFragmentProcessor> clone() const override;
37
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000038 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 Osman28804f32017-04-20 10:24:36 -040045 static bool TestForPreservingPMConversions(GrContext* context);
46
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000047private:
Brian Osmanee805322017-04-05 10:09:00 -040048 GrConfigConversionEffect(PMConversion);
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000049
egdaniel57d3b032015-11-13 11:57:27 -080050 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070051
Brian Salomon94efbf52016-11-29 13:43:05 -050052 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070053
mtklein36352bf2015-03-25 18:17:31 -070054 bool onIsEqual(const GrFragmentProcessor&) const override;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000055
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000056 PMConversion fPMConversion;
57
Brian Salomon0c26a9d2017-07-06 10:09:38 -040058 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000059
Brian Osmanee805322017-04-05 10:09:00 -040060 typedef GrFragmentProcessor INHERITED;
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000061};
62
63#endif