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 |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkTypes.h" |
Mike Reed | 46f5c5f | 2020-02-20 15:42:29 -0500 | [diff] [blame^] | 14 | #include "include/core/SkM44.h" |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 15 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/gpu/GrContext.h" |
Greg Daniel | 6f5441a | 2020-01-28 17:02:49 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrBitmapTextureMaker.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrClip.h" |
| 19 | #include "src/gpu/GrContextPriv.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrRenderTargetContext.h" |
| 22 | |
| 23 | #include "src/gpu/GrCoordTransform.h" |
| 24 | #include "src/gpu/GrFragmentProcessor.h" |
Brian Osman | ee80532 | 2017-04-05 10:09:00 -0400 | [diff] [blame] | 25 | class GrConfigConversionEffect : public GrFragmentProcessor { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 26 | public: |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 27 | static bool TestForPreservingPMConversions(GrContext* context) { |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 28 | static constexpr int kSize = 256; |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 29 | static constexpr GrColorType kColorType = GrColorType::kRGBA_8888; |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 30 | SkAutoTMalloc<uint32_t> data(kSize * kSize * 3); |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 31 | uint32_t* srcData = data.get(); |
| 32 | uint32_t* firstRead = data.get() + kSize * kSize; |
| 33 | uint32_t* secondRead = data.get() + 2 * kSize * kSize; |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 34 | |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 35 | // Fill with every possible premultiplied A, color channel value. There will be 256-y |
| 36 | // duplicate values in row y. We set r, g, and b to the same value since they are handled |
| 37 | // identically. |
| 38 | for (int y = 0; y < kSize; ++y) { |
| 39 | for (int x = 0; x < kSize; ++x) { |
| 40 | uint8_t* color = reinterpret_cast<uint8_t*>(&srcData[kSize * y + x]); |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 41 | color[3] = y; |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 42 | color[2] = std::min(x, y); |
| 43 | color[1] = std::min(x, y); |
| 44 | color[0] = std::min(x, y); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 45 | } |
| 46 | } |
Brian Salomon | 7b9b326 | 2018-04-27 17:38:06 -0400 | [diff] [blame] | 47 | memset(firstRead, 0, kSize * kSize * sizeof(uint32_t)); |
| 48 | memset(secondRead, 0, kSize * kSize * sizeof(uint32_t)); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 49 | |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 50 | const SkImageInfo ii = |
| 51 | SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 52 | |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 53 | auto readRTC = GrRenderTargetContext::Make(context, kColorType, nullptr, |
| 54 | SkBackingFit::kExact, {kSize, kSize}); |
| 55 | auto tempRTC = GrRenderTargetContext::Make(context, kColorType, nullptr, |
| 56 | SkBackingFit::kExact, {kSize, kSize}); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 57 | if (!readRTC || !readRTC->asTextureProxy() || !tempRTC) { |
| 58 | return false; |
| 59 | } |
Greg Daniel | f44cb48 | 2018-02-27 14:26:32 -0500 | [diff] [blame] | 60 | // Adding discard to appease vulkan validation warning about loading uninitialized data on |
| 61 | // draw |
| 62 | readRTC->discard(); |
| 63 | |
Greg Daniel | 6e9a4f6 | 2018-03-15 17:00:06 -0400 | [diff] [blame] | 64 | // This function is only ever called if we are in a GrContext that has a GrGpu since we are |
| 65 | // calling read pixels here. Thus the pixel data will be uploaded immediately and we don't |
| 66 | // need to keep the pixel data alive in the proxy. Therefore the ReleaseProc is nullptr. |
Greg Daniel | 6f5441a | 2020-01-28 17:02:49 -0500 | [diff] [blame] | 67 | SkBitmap bitmap; |
| 68 | bitmap.installPixels(ii, srcData, 4 * kSize); |
| 69 | bitmap.setImmutable(); |
| 70 | |
| 71 | GrBitmapTextureMaker maker(context, bitmap); |
Greg Daniel | c61d7e3 | 2020-02-04 14:27:45 -0500 | [diff] [blame] | 72 | auto[dataView, ct] = maker.view(GrMipMapped::kNo); |
Greg Daniel | 6f5441a | 2020-01-28 17:02:49 -0500 | [diff] [blame] | 73 | |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 74 | if (!dataView.proxy()) { |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 75 | return false; |
| 76 | } |
| 77 | |
| 78 | static const SkRect kRect = SkRect::MakeIWH(kSize, kSize); |
| 79 | |
| 80 | // We do a PM->UPM draw from dataTex to readTex and read the data. Then we do a UPM->PM draw |
| 81 | // from readTex to tempTex followed by a PM->UPM draw to readTex and finally read the data. |
| 82 | // We then verify that two reads produced the same values. |
| 83 | |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 84 | GrPaint paint1; |
| 85 | GrPaint paint2; |
| 86 | GrPaint paint3; |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 87 | std::unique_ptr<GrFragmentProcessor> pmToUPM( |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 88 | new GrConfigConversionEffect(PMConversion::kToUnpremul)); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 89 | std::unique_ptr<GrFragmentProcessor> upmToPM( |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 90 | new GrConfigConversionEffect(PMConversion::kToPremul)); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 91 | |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 92 | paint1.addColorFragmentProcessor( |
Greg Daniel | d2ccbb5 | 2020-02-05 10:45:39 -0500 | [diff] [blame] | 93 | GrTextureEffect::Make(std::move(dataView), kPremul_SkAlphaType)); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 94 | paint1.addColorFragmentProcessor(pmToUPM->clone()); |
| 95 | paint1.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 96 | |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 97 | readRTC->fillRectToRect(GrNoClip(), std::move(paint1), GrAA::kNo, SkMatrix::I(), kRect, |
| 98 | kRect); |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 99 | if (!readRTC->readPixels(ii, firstRead, 0, {0, 0})) { |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
Greg Daniel | f44cb48 | 2018-02-27 14:26:32 -0500 | [diff] [blame] | 103 | // Adding discard to appease vulkan validation warning about loading uninitialized data on |
| 104 | // draw |
| 105 | tempRTC->discard(); |
| 106 | |
Brian Salomon | bfb7211 | 2020-01-13 10:51:50 -0500 | [diff] [blame] | 107 | paint2.addColorFragmentProcessor( |
Greg Daniel | d2ccbb5 | 2020-02-05 10:45:39 -0500 | [diff] [blame] | 108 | GrTextureEffect::Make(readRTC->readSurfaceView(), kUnpremul_SkAlphaType)); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 109 | paint2.addColorFragmentProcessor(std::move(upmToPM)); |
| 110 | paint2.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 111 | |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 112 | tempRTC->fillRectToRect(GrNoClip(), std::move(paint2), GrAA::kNo, SkMatrix::I(), kRect, |
| 113 | kRect); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 114 | |
Brian Salomon | bfb7211 | 2020-01-13 10:51:50 -0500 | [diff] [blame] | 115 | paint3.addColorFragmentProcessor( |
Greg Daniel | d2ccbb5 | 2020-02-05 10:45:39 -0500 | [diff] [blame] | 116 | GrTextureEffect::Make(tempRTC->readSurfaceView(), kPremul_SkAlphaType)); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 117 | paint3.addColorFragmentProcessor(std::move(pmToUPM)); |
| 118 | paint3.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 119 | |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 120 | readRTC->fillRectToRect(GrNoClip(), std::move(paint3), GrAA::kNo, SkMatrix::I(), kRect, |
| 121 | kRect); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 122 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 123 | if (!readRTC->readPixels(ii, secondRead, 0, {0, 0})) { |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 124 | return false; |
| 125 | } |
| 126 | |
| 127 | for (int y = 0; y < kSize; ++y) { |
| 128 | for (int x = 0; x <= y; ++x) { |
| 129 | if (firstRead[kSize * y + x] != secondRead[kSize * y + x]) { |
| 130 | return false; |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | return true; |
| 136 | } |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 137 | |
| 138 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp, |
| 139 | PMConversion pmConversion) { |
| 140 | if (!fp) { |
| 141 | return nullptr; |
| 142 | } |
| 143 | std::unique_ptr<GrFragmentProcessor> ccFP(new GrConfigConversionEffect(pmConversion)); |
| 144 | std::unique_ptr<GrFragmentProcessor> fpPipeline[] = {std::move(fp), std::move(ccFP)}; |
| 145 | return GrFragmentProcessor::RunInSeries(fpPipeline, 2); |
| 146 | } |
| 147 | GrConfigConversionEffect(const GrConfigConversionEffect& src); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 148 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 149 | const char* name() const override { return "ConfigConversionEffect"; } |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 150 | PMConversion pmConversion; |
Brian Osman | 28804f3 | 2017-04-20 10:24:36 -0400 | [diff] [blame] | 151 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 152 | private: |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 153 | GrConfigConversionEffect(PMConversion pmConversion) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 154 | : INHERITED(kGrConfigConversionEffect_ClassID, kNone_OptimizationFlags) |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 155 | , pmConversion(pmConversion) {} |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 156 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 157 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 158 | bool onIsEqual(const GrFragmentProcessor&) const override; |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 159 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
Brian Osman | ee80532 | 2017-04-05 10:09:00 -0400 | [diff] [blame] | 160 | typedef GrFragmentProcessor INHERITED; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 161 | }; |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 162 | #endif |