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 | #include "GrConfigConversionEffect.h" |
bsalomon@google.com | b1456d7 | 2012-11-02 18:23:45 +0000 | [diff] [blame] | 9 | #include "GrContext.h" |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 10 | #include "GrTBackendEffectFactory.h" |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 11 | #include "GrSimpleTextureEffect.h" |
bsalomon@google.com | d698f77 | 2012-10-25 13:22:00 +0000 | [diff] [blame] | 12 | #include "gl/GrGLEffect.h" |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 13 | #include "gl/GrGLShaderBuilder.h" |
bsalomon@google.com | b1456d7 | 2012-11-02 18:23:45 +0000 | [diff] [blame] | 14 | #include "SkMatrix.h" |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 15 | |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 16 | class GrGLConfigConversionEffect : public GrGLEffect { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 17 | public: |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 18 | GrGLConfigConversionEffect(const GrBackendEffectFactory& factory, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 19 | const GrDrawEffect& drawEffect) |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 20 | : INHERITED (factory) { |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 21 | const GrConfigConversionEffect& effect = drawEffect.castEffect<GrConfigConversionEffect>(); |
bsalomon@google.com | 021fc73 | 2012-10-25 12:47:42 +0000 | [diff] [blame] | 22 | fSwapRedAndBlue = effect.swapsRedAndBlue(); |
| 23 | fPMConversion = effect.pmConversion(); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 24 | } |
| 25 | |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 26 | virtual void emitCode(GrGLShaderBuilder* builder, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 27 | const GrDrawEffect&, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 28 | const GrEffectKey& key, |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 29 | const char* outputColor, |
| 30 | const char* inputColor, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 31 | const TransformedCoordsArray& coords, |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 32 | const TextureSamplerArray& samplers) SK_OVERRIDE { |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 33 | builder->fsCodeAppendf("\t\t%s = ", outputColor); |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 34 | builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0].type()); |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 35 | builder->fsCodeAppend(";\n"); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 36 | if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 37 | SkASSERT(fSwapRedAndBlue); |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 38 | builder->fsCodeAppendf("\t%s = %s.bgra;\n", outputColor, outputColor); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 39 | } else { |
| 40 | const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb"; |
| 41 | switch (fPMConversion) { |
| 42 | case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion: |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 43 | builder->fsCodeAppendf( |
bsalomon@google.com | 868a8e7 | 2012-08-30 19:11:34 +0000 | [diff] [blame] | 44 | "\t\t%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a);\n", |
| 45 | outputColor, outputColor, swiz, outputColor, outputColor); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 46 | break; |
| 47 | case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversion: |
commit-bot@chromium.org | b4e200e | 2013-06-19 11:41:02 +0000 | [diff] [blame] | 48 | // Add a compensation(0.001) here to avoid the side effect of the floor operation. |
| 49 | // In Intel GPUs, the integer value converted from floor(%s.r * 255.0) / 255.0 |
| 50 | // is less than the integer value converted from %s.r by 1 when the %s.r is |
| 51 | // converted from the integer value 2^n, such as 1, 2, 4, 8, etc. |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 52 | builder->fsCodeAppendf( |
commit-bot@chromium.org | b4e200e | 2013-06-19 11:41:02 +0000 | [diff] [blame] | 53 | "\t\t%s = vec4(floor(%s.%s * %s.a * 255.0 + 0.001) / 255.0, %s.a);\n", |
bsalomon@google.com | 868a8e7 | 2012-08-30 19:11:34 +0000 | [diff] [blame] | 54 | outputColor, outputColor, swiz, outputColor, outputColor); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 55 | break; |
| 56 | case GrConfigConversionEffect::kDivByAlpha_RoundUp_PMConversion: |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 57 | builder->fsCodeAppendf("\t\t%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(ceil(%s.%s / %s.a * 255.0) / 255.0, %s.a);\n", |
bsalomon@google.com | 868a8e7 | 2012-08-30 19:11:34 +0000 | [diff] [blame] | 58 | outputColor, outputColor, outputColor, swiz, outputColor, outputColor); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 59 | break; |
| 60 | case GrConfigConversionEffect::kDivByAlpha_RoundDown_PMConversion: |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 61 | builder->fsCodeAppendf("\t\t%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(%s.%s / %s.a * 255.0) / 255.0, %s.a);\n", |
bsalomon@google.com | 868a8e7 | 2012-08-30 19:11:34 +0000 | [diff] [blame] | 62 | outputColor, outputColor, outputColor, swiz, outputColor, outputColor); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 63 | break; |
robertphillips@google.com | 2af1b18 | 2012-08-28 11:23:09 +0000 | [diff] [blame] | 64 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 65 | SkFAIL("Unknown conversion op."); |
robertphillips@google.com | 2af1b18 | 2012-08-28 11:23:09 +0000 | [diff] [blame] | 66 | break; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 67 | } |
| 68 | } |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 69 | SkString modulate; |
| 70 | GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
| 71 | builder->fsCodeAppend(modulate.c_str()); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 72 | } |
| 73 | |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 74 | static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 75 | GrEffectKeyBuilder* b) { |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 76 | const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigConversionEffect>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 77 | uint32_t key = (conv.swapsRedAndBlue() ? 0 : 1) | (conv.pmConversion() << 1); |
| 78 | b->add32(key); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | private: |
| 82 | bool fSwapRedAndBlue; |
| 83 | GrConfigConversionEffect::PMConversion fPMConversion; |
| 84 | |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 85 | typedef GrGLEffect INHERITED; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 86 | |
| 87 | }; |
| 88 | |
| 89 | /////////////////////////////////////////////////////////////////////////////// |
| 90 | |
| 91 | GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture, |
| 92 | bool swapRedAndBlue, |
bsalomon@google.com | b1456d7 | 2012-11-02 18:23:45 +0000 | [diff] [blame] | 93 | PMConversion pmConversion, |
| 94 | const SkMatrix& matrix) |
| 95 | : GrSingleTextureEffect(texture, matrix) |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 96 | , fSwapRedAndBlue(swapRedAndBlue) |
| 97 | , fPMConversion(pmConversion) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 98 | SkASSERT(kRGBA_8888_GrPixelConfig == texture->config() || |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 99 | kBGRA_8888_GrPixelConfig == texture->config()); |
| 100 | // Why did we pollute our texture cache instead of using a GrSingleTextureEffect? |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 101 | SkASSERT(swapRedAndBlue || kNone_PMConversion != pmConversion); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 102 | } |
| 103 | |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 104 | const GrBackendEffectFactory& GrConfigConversionEffect::getFactory() const { |
| 105 | return GrTBackendEffectFactory<GrConfigConversionEffect>::getInstance(); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 106 | } |
| 107 | |
bsalomon@google.com | 8a252f7 | 2013-01-22 20:35:13 +0000 | [diff] [blame] | 108 | bool GrConfigConversionEffect::onIsEqual(const GrEffect& s) const { |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 109 | const GrConfigConversionEffect& other = CastEffect<GrConfigConversionEffect>(s); |
bsalomon@google.com | 8a252f7 | 2013-01-22 20:35:13 +0000 | [diff] [blame] | 110 | return this->texture(0) == s.texture(0) && |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 111 | other.fSwapRedAndBlue == fSwapRedAndBlue && |
| 112 | other.fPMConversion == fPMConversion; |
| 113 | } |
| 114 | |
| 115 | void GrConfigConversionEffect::getConstantColorComponents(GrColor* color, |
| 116 | uint32_t* validFlags) const { |
| 117 | this->updateConstantColorComponentsForModulation(color, validFlags); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /////////////////////////////////////////////////////////////////////////////// |
| 121 | |
bsalomon@google.com | f271cc7 | 2012-10-24 19:35:13 +0000 | [diff] [blame] | 122 | GR_DEFINE_EFFECT_TEST(GrConfigConversionEffect); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 123 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 124 | GrEffect* GrConfigConversionEffect::TestCreate(SkRandom* random, |
| 125 | GrContext*, |
| 126 | const GrDrawTargetCaps&, |
| 127 | GrTexture* textures[]) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 128 | PMConversion pmConv = static_cast<PMConversion>(random->nextULessThan(kPMConversionCnt)); |
| 129 | bool swapRB; |
| 130 | if (kNone_PMConversion == pmConv) { |
| 131 | swapRB = true; |
| 132 | } else { |
| 133 | swapRB = random->nextBool(); |
| 134 | } |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 135 | return SkNEW_ARGS(GrConfigConversionEffect, |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 136 | (textures[GrEffectUnitTest::kSkiaPMTextureIdx], |
| 137 | swapRB, |
| 138 | pmConv, |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 139 | GrEffectUnitTest::TestMatrix(random))); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /////////////////////////////////////////////////////////////////////////////// |
| 143 | void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context, |
| 144 | PMConversion* pmToUPMRule, |
| 145 | PMConversion* upmToPMRule) { |
| 146 | *pmToUPMRule = kNone_PMConversion; |
| 147 | *upmToPMRule = kNone_PMConversion; |
| 148 | SkAutoTMalloc<uint32_t> data(256 * 256 * 3); |
| 149 | uint32_t* srcData = data.get(); |
| 150 | uint32_t* firstRead = data.get() + 256 * 256; |
| 151 | uint32_t* secondRead = data.get() + 2 * 256 * 256; |
| 152 | |
| 153 | // Fill with every possible premultiplied A, color channel value. There will be 256-y duplicate |
| 154 | // values in row y. We set r,g, and b to the same value since they are handled identically. |
| 155 | for (int y = 0; y < 256; ++y) { |
| 156 | for (int x = 0; x < 256; ++x) { |
| 157 | uint8_t* color = reinterpret_cast<uint8_t*>(&srcData[256*y + x]); |
| 158 | color[3] = y; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 159 | color[2] = SkTMin(x, y); |
| 160 | color[1] = SkTMin(x, y); |
| 161 | color[0] = SkTMin(x, y); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | |
| 165 | GrTextureDesc desc; |
| 166 | desc.fFlags = kRenderTarget_GrTextureFlagBit | |
| 167 | kNoStencil_GrTextureFlagBit; |
| 168 | desc.fWidth = 256; |
| 169 | desc.fHeight = 256; |
| 170 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 171 | |
| 172 | SkAutoTUnref<GrTexture> readTex(context->createUncachedTexture(desc, NULL, 0)); |
| 173 | if (!readTex.get()) { |
| 174 | return; |
| 175 | } |
| 176 | SkAutoTUnref<GrTexture> tempTex(context->createUncachedTexture(desc, NULL, 0)); |
| 177 | if (!tempTex.get()) { |
| 178 | return; |
| 179 | } |
| 180 | desc.fFlags = kNone_GrTextureFlags; |
| 181 | SkAutoTUnref<GrTexture> dataTex(context->createUncachedTexture(desc, data, 0)); |
| 182 | if (!dataTex.get()) { |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | static const PMConversion kConversionRules[][2] = { |
| 187 | {kDivByAlpha_RoundDown_PMConversion, kMulByAlpha_RoundUp_PMConversion}, |
| 188 | {kDivByAlpha_RoundUp_PMConversion, kMulByAlpha_RoundDown_PMConversion}, |
| 189 | }; |
| 190 | |
| 191 | GrContext::AutoWideOpenIdentityDraw awoid(context, NULL); |
| 192 | |
| 193 | bool failed = true; |
| 194 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 195 | for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 196 | *pmToUPMRule = kConversionRules[i][0]; |
| 197 | *upmToPMRule = kConversionRules[i][1]; |
| 198 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 199 | static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntToScalar(256)); |
| 200 | static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 201 | // We do a PM->UPM draw from dataTex to readTex and read the data. Then we do a UPM->PM draw |
| 202 | // from readTex to tempTex followed by a PM->UPM draw to readTex and finally read the data. |
| 203 | // We then verify that two reads produced the same values. |
| 204 | |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 205 | SkAutoTUnref<GrEffect> pmToUPM1(SkNEW_ARGS(GrConfigConversionEffect, (dataTex, |
| 206 | false, |
| 207 | *pmToUPMRule, |
| 208 | SkMatrix::I()))); |
| 209 | SkAutoTUnref<GrEffect> upmToPM(SkNEW_ARGS(GrConfigConversionEffect, (readTex, |
| 210 | false, |
| 211 | *upmToPMRule, |
| 212 | SkMatrix::I()))); |
| 213 | SkAutoTUnref<GrEffect> pmToUPM2(SkNEW_ARGS(GrConfigConversionEffect, (tempTex, |
| 214 | false, |
| 215 | *pmToUPMRule, |
| 216 | SkMatrix::I()))); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 217 | |
| 218 | context->setRenderTarget(readTex->asRenderTarget()); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 219 | GrPaint paint1; |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 220 | paint1.addColorEffect(pmToUPM1); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 221 | context->drawRectToRect(paint1, kDstRect, kSrcRect); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 222 | |
| 223 | readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead); |
| 224 | |
| 225 | context->setRenderTarget(tempTex->asRenderTarget()); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 226 | GrPaint paint2; |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 227 | paint2.addColorEffect(upmToPM); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 228 | context->drawRectToRect(paint2, kDstRect, kSrcRect); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 229 | context->setRenderTarget(readTex->asRenderTarget()); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 230 | |
| 231 | GrPaint paint3; |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 232 | paint3.addColorEffect(pmToUPM2); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 233 | context->drawRectToRect(paint3, kDstRect, kSrcRect); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 234 | |
| 235 | readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead); |
| 236 | |
| 237 | failed = false; |
| 238 | for (int y = 0; y < 256 && !failed; ++y) { |
| 239 | for (int x = 0; x <= y; ++x) { |
| 240 | if (firstRead[256 * y + x] != secondRead[256 * y + x]) { |
| 241 | failed = true; |
| 242 | break; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | if (failed) { |
| 248 | *pmToUPMRule = kNone_PMConversion; |
| 249 | *upmToPMRule = kNone_PMConversion; |
| 250 | } |
| 251 | } |
| 252 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 253 | const GrEffect* GrConfigConversionEffect::Create(GrTexture* texture, |
| 254 | bool swapRedAndBlue, |
| 255 | PMConversion pmConversion, |
| 256 | const SkMatrix& matrix) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 257 | if (!swapRedAndBlue && kNone_PMConversion == pmConversion) { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 258 | // If we returned a GrConfigConversionEffect that was equivalent to a GrSimpleTextureEffect |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 259 | // then we may pollute our texture cache with redundant shaders. So in the case that no |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 260 | // conversions were requested we instead return a GrSimpleTextureEffect. |
| 261 | return GrSimpleTextureEffect::Create(texture, matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 262 | } else { |
| 263 | if (kRGBA_8888_GrPixelConfig != texture->config() && |
| 264 | kBGRA_8888_GrPixelConfig != texture->config() && |
| 265 | kNone_PMConversion != pmConversion) { |
| 266 | // The PM conversions assume colors are 0..255 |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 267 | return NULL; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 268 | } |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 269 | return SkNEW_ARGS(GrConfigConversionEffect, (texture, |
| 270 | swapRedAndBlue, |
| 271 | pmConversion, |
| 272 | matrix)); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 273 | } |
| 274 | } |