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