bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1 | /* |
Ethan Nicholas | 130fb3f | 2018-02-01 12:14:34 -0500 | [diff] [blame] | 2 | * Copyright 2018 Google Inc. |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 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 | |
Ethan Nicholas | 130fb3f | 2018-02-01 12:14:34 -0500 | [diff] [blame] | 8 | /************************************************************************************************** |
| 9 | *** This file was autogenerated from GrConfigConversionEffect.fp; do not modify. |
| 10 | **************************************************************************************************/ |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 11 | #ifndef GrConfigConversionEffect_DEFINED |
| 12 | #define GrConfigConversionEffect_DEFINED |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 13 | #include "SkTypes.h" |
| 14 | #if SK_SUPPORT_GPU |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 15 | |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 16 | #include "GrClip.h" |
| 17 | #include "GrContext.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 18 | #include "GrContextPriv.h" |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 19 | #include "GrProxyProvider.h" |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 20 | #include "GrRenderTargetContext.h" |
Brian Osman | ee80532 | 2017-04-05 10:09:00 -0400 | [diff] [blame] | 21 | #include "GrFragmentProcessor.h" |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 22 | #include "GrCoordTransform.h" |
Brian Osman | ee80532 | 2017-04-05 10:09:00 -0400 | [diff] [blame] | 23 | class GrConfigConversionEffect : public GrFragmentProcessor { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 24 | public: |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 25 | static bool TestForPreservingPMConversions(GrContext* context) { |
| 26 | static constexpr int kSize = 256; |
| 27 | static constexpr GrPixelConfig kConfig = kRGBA_8888_GrPixelConfig; |
| 28 | SkAutoTMalloc<uint32_t> data(kSize * kSize * 3); |
| 29 | uint32_t* srcData = data.get(); |
| 30 | uint32_t* firstRead = data.get() + kSize * kSize; |
| 31 | uint32_t* secondRead = data.get() + 2 * kSize * kSize; |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 32 | |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 33 | // Fill with every possible premultiplied A, color channel value. There will be 256-y |
| 34 | // duplicate values in row y. We set r, g, and b to the same value since they are handled |
| 35 | // identically. |
| 36 | for (int y = 0; y < kSize; ++y) { |
| 37 | for (int x = 0; x < kSize; ++x) { |
| 38 | uint8_t* color = reinterpret_cast<uint8_t*>(&srcData[kSize * y + x]); |
| 39 | color[3] = y; |
| 40 | color[2] = SkTMin(x, y); |
| 41 | color[1] = SkTMin(x, y); |
| 42 | color[0] = SkTMin(x, y); |
| 43 | } |
| 44 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 45 | |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 46 | const SkImageInfo ii = |
| 47 | SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 48 | |
| 49 | sk_sp<GrRenderTargetContext> readRTC(context->makeDeferredRenderTargetContext( |
| 50 | SkBackingFit::kExact, kSize, kSize, kConfig, nullptr)); |
| 51 | sk_sp<GrRenderTargetContext> tempRTC(context->makeDeferredRenderTargetContext( |
| 52 | SkBackingFit::kExact, kSize, kSize, kConfig, nullptr)); |
| 53 | if (!readRTC || !readRTC->asTextureProxy() || !tempRTC) { |
| 54 | return false; |
| 55 | } |
Greg Daniel | f44cb48 | 2018-02-27 14:26:32 -0500 | [diff] [blame] | 56 | // Adding discard to appease vulkan validation warning about loading uninitialized data on |
| 57 | // draw |
| 58 | readRTC->discard(); |
| 59 | |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 60 | GrSurfaceDesc desc; |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 61 | desc.fWidth = kSize; |
| 62 | desc.fHeight = kSize; |
| 63 | desc.fConfig = kConfig; |
| 64 | |
Robert Phillips | 579f094 | 2018-01-08 14:53:35 -0500 | [diff] [blame] | 65 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
| 66 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame^] | 67 | sk_sp<GrTextureProxy> dataProxy = proxyProvider->createTextureProxy( |
| 68 | desc, kTopLeft_GrSurfaceOrigin, SkBudgeted::kYes, data, 0); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 69 | if (!dataProxy) { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | static const SkRect kRect = SkRect::MakeIWH(kSize, kSize); |
| 74 | |
| 75 | // We do a PM->UPM draw from dataTex to readTex and read the data. Then we do a UPM->PM draw |
| 76 | // from readTex to tempTex followed by a PM->UPM draw to readTex and finally read the data. |
| 77 | // We then verify that two reads produced the same values. |
| 78 | |
| 79 | GrPaint paint1; |
| 80 | GrPaint paint2; |
| 81 | GrPaint paint3; |
| 82 | std::unique_ptr<GrFragmentProcessor> pmToUPM( |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 83 | new GrConfigConversionEffect(PMConversion::kToUnpremul)); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 84 | std::unique_ptr<GrFragmentProcessor> upmToPM( |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 85 | new GrConfigConversionEffect(PMConversion::kToPremul)); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 86 | |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 87 | paint1.addColorTextureProcessor(dataProxy, SkMatrix::I()); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 88 | paint1.addColorFragmentProcessor(pmToUPM->clone()); |
| 89 | paint1.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 90 | |
| 91 | readRTC->fillRectToRect(GrNoClip(), std::move(paint1), GrAA::kNo, SkMatrix::I(), kRect, |
| 92 | kRect); |
| 93 | if (!readRTC->readPixels(ii, firstRead, 0, 0, 0)) { |
| 94 | return false; |
| 95 | } |
| 96 | |
Greg Daniel | f44cb48 | 2018-02-27 14:26:32 -0500 | [diff] [blame] | 97 | // Adding discard to appease vulkan validation warning about loading uninitialized data on |
| 98 | // draw |
| 99 | tempRTC->discard(); |
| 100 | |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 101 | paint2.addColorTextureProcessor(readRTC->asTextureProxyRef(), SkMatrix::I()); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 102 | paint2.addColorFragmentProcessor(std::move(upmToPM)); |
| 103 | paint2.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 104 | |
| 105 | tempRTC->fillRectToRect(GrNoClip(), std::move(paint2), GrAA::kNo, SkMatrix::I(), kRect, |
| 106 | kRect); |
| 107 | |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 108 | paint3.addColorTextureProcessor(tempRTC->asTextureProxyRef(), SkMatrix::I()); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 109 | paint3.addColorFragmentProcessor(std::move(pmToUPM)); |
| 110 | paint3.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 111 | |
| 112 | readRTC->fillRectToRect(GrNoClip(), std::move(paint3), GrAA::kNo, SkMatrix::I(), kRect, |
| 113 | kRect); |
| 114 | |
| 115 | if (!readRTC->readPixels(ii, secondRead, 0, 0, 0)) { |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | for (int y = 0; y < kSize; ++y) { |
| 120 | for (int x = 0; x <= y; ++x) { |
| 121 | if (firstRead[kSize * y + x] != secondRead[kSize * y + x]) { |
| 122 | return false; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | return true; |
| 128 | } |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 129 | PMConversion pmConversion() const { return fPmConversion; } |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 130 | |
| 131 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp, |
| 132 | PMConversion pmConversion) { |
| 133 | if (!fp) { |
| 134 | return nullptr; |
| 135 | } |
| 136 | std::unique_ptr<GrFragmentProcessor> ccFP(new GrConfigConversionEffect(pmConversion)); |
| 137 | std::unique_ptr<GrFragmentProcessor> fpPipeline[] = {std::move(fp), std::move(ccFP)}; |
| 138 | return GrFragmentProcessor::RunInSeries(fpPipeline, 2); |
| 139 | } |
| 140 | GrConfigConversionEffect(const GrConfigConversionEffect& src); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 141 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 142 | const char* name() const override { return "ConfigConversionEffect"; } |
Brian Osman | 28804f3 | 2017-04-20 10:24:36 -0400 | [diff] [blame] | 143 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 144 | private: |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 145 | GrConfigConversionEffect(PMConversion pmConversion) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 146 | : INHERITED(kGrConfigConversionEffect_ClassID, kNone_OptimizationFlags) |
| 147 | , fPmConversion(pmConversion) {} |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 148 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 149 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 150 | bool onIsEqual(const GrFragmentProcessor&) const override; |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 151 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 152 | PMConversion fPmConversion; |
Brian Osman | ee80532 | 2017-04-05 10:09:00 -0400 | [diff] [blame] | 153 | typedef GrFragmentProcessor INHERITED; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 154 | }; |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 155 | #endif |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 156 | #endif |