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