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