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" |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 13 | #include "gl/builders/GrGLProgramBuilder.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, |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 19 | const GrEffect& effect) |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 20 | : INHERITED (factory) { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 21 | const GrConfigConversionEffect& configConversionEffect = effect.cast<GrConfigConversionEffect>(); |
| 22 | fSwapRedAndBlue = configConversionEffect.swapsRedAndBlue(); |
| 23 | fPMConversion = configConversionEffect.pmConversion(); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 24 | } |
| 25 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 26 | virtual void emitCode(GrGLProgramBuilder* builder, |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 27 | const GrEffect&, |
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 { |
changjun.yang | cecc91c | 2014-08-19 18:24:30 -0700 | [diff] [blame] | 33 | // Using highp for GLES here in order to avoid some precision issues on specific GPUs. |
| 34 | GrGLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, GrGLShaderVar::kHigh_Precision); |
| 35 | SkString tmpDecl; |
| 36 | tmpVar.appendDecl(builder->ctxInfo(), &tmpDecl); |
changjun.yang | cecc91c | 2014-08-19 18:24:30 -0700 | [diff] [blame] | 37 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 38 | GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 39 | |
| 40 | fsBuilder->codeAppendf("%s;", tmpDecl.c_str()); |
| 41 | |
| 42 | fsBuilder->codeAppendf("%s = ", tmpVar.c_str()); |
| 43 | fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0].type()); |
| 44 | fsBuilder->codeAppend(";"); |
changjun.yang | cecc91c | 2014-08-19 18:24:30 -0700 | [diff] [blame] | 45 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 46 | if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 47 | SkASSERT(fSwapRedAndBlue); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 48 | fsBuilder->codeAppendf("%s = %s.bgra;", outputColor, tmpVar.c_str()); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 49 | } else { |
| 50 | const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb"; |
| 51 | switch (fPMConversion) { |
| 52 | case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion: |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 53 | fsBuilder->codeAppendf( |
changjun.yang | cecc91c | 2014-08-19 18:24:30 -0700 | [diff] [blame] | 54 | "%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a);", |
| 55 | tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tmpVar.c_str()); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 56 | break; |
| 57 | case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversion: |
commit-bot@chromium.org | b4e200e | 2013-06-19 11:41:02 +0000 | [diff] [blame] | 58 | // Add a compensation(0.001) here to avoid the side effect of the floor operation. |
| 59 | // In Intel GPUs, the integer value converted from floor(%s.r * 255.0) / 255.0 |
| 60 | // is less than the integer value converted from %s.r by 1 when the %s.r is |
| 61 | // converted from the integer value 2^n, such as 1, 2, 4, 8, etc. |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 62 | fsBuilder->codeAppendf( |
changjun.yang | cecc91c | 2014-08-19 18:24:30 -0700 | [diff] [blame] | 63 | "%s = vec4(floor(%s.%s * %s.a * 255.0 + 0.001) / 255.0, %s.a);", |
| 64 | tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tmpVar.c_str()); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 65 | break; |
| 66 | case GrConfigConversionEffect::kDivByAlpha_RoundUp_PMConversion: |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 67 | fsBuilder->codeAppendf( |
changjun.yang | cecc91c | 2014-08-19 18:24:30 -0700 | [diff] [blame] | 68 | "%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(ceil(%s.%s / %s.a * 255.0) / 255.0, %s.a);", |
| 69 | tmpVar.c_str(), tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tmpVar.c_str()); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 70 | break; |
| 71 | case GrConfigConversionEffect::kDivByAlpha_RoundDown_PMConversion: |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 72 | fsBuilder->codeAppendf( |
changjun.yang | cecc91c | 2014-08-19 18:24:30 -0700 | [diff] [blame] | 73 | "%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(%s.%s / %s.a * 255.0) / 255.0, %s.a);", |
| 74 | tmpVar.c_str(), tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tmpVar.c_str()); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 75 | break; |
robertphillips@google.com | 2af1b18 | 2012-08-28 11:23:09 +0000 | [diff] [blame] | 76 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 77 | SkFAIL("Unknown conversion op."); |
robertphillips@google.com | 2af1b18 | 2012-08-28 11:23:09 +0000 | [diff] [blame] | 78 | break; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 79 | } |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 80 | fsBuilder->codeAppendf("%s = %s;", outputColor, tmpVar.c_str()); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 81 | } |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 82 | SkString modulate; |
| 83 | GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 84 | fsBuilder->codeAppend(modulate.c_str()); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 85 | } |
| 86 | |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 87 | static inline void GenKey(const GrEffect& effect, const GrGLCaps&, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 88 | GrEffectKeyBuilder* b) { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 89 | const GrConfigConversionEffect& conv = effect.cast<GrConfigConversionEffect>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 90 | uint32_t key = (conv.swapsRedAndBlue() ? 0 : 1) | (conv.pmConversion() << 1); |
| 91 | b->add32(key); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | private: |
| 95 | bool fSwapRedAndBlue; |
| 96 | GrConfigConversionEffect::PMConversion fPMConversion; |
| 97 | |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 98 | typedef GrGLEffect INHERITED; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 99 | |
| 100 | }; |
| 101 | |
| 102 | /////////////////////////////////////////////////////////////////////////////// |
| 103 | |
| 104 | GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture, |
| 105 | bool swapRedAndBlue, |
bsalomon@google.com | b1456d7 | 2012-11-02 18:23:45 +0000 | [diff] [blame] | 106 | PMConversion pmConversion, |
| 107 | const SkMatrix& matrix) |
| 108 | : GrSingleTextureEffect(texture, matrix) |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 109 | , fSwapRedAndBlue(swapRedAndBlue) |
| 110 | , fPMConversion(pmConversion) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 111 | SkASSERT(kRGBA_8888_GrPixelConfig == texture->config() || |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 112 | kBGRA_8888_GrPixelConfig == texture->config()); |
| 113 | // 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] | 114 | SkASSERT(swapRedAndBlue || kNone_PMConversion != pmConversion); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 115 | } |
| 116 | |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 117 | const GrBackendEffectFactory& GrConfigConversionEffect::getFactory() const { |
| 118 | return GrTBackendEffectFactory<GrConfigConversionEffect>::getInstance(); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 119 | } |
| 120 | |
bsalomon@google.com | 8a252f7 | 2013-01-22 20:35:13 +0000 | [diff] [blame] | 121 | bool GrConfigConversionEffect::onIsEqual(const GrEffect& s) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 122 | const GrConfigConversionEffect& other = s.cast<GrConfigConversionEffect>(); |
bsalomon@google.com | 8a252f7 | 2013-01-22 20:35:13 +0000 | [diff] [blame] | 123 | return this->texture(0) == s.texture(0) && |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 124 | other.fSwapRedAndBlue == fSwapRedAndBlue && |
| 125 | other.fPMConversion == fPMConversion; |
| 126 | } |
| 127 | |
| 128 | void GrConfigConversionEffect::getConstantColorComponents(GrColor* color, |
| 129 | uint32_t* validFlags) const { |
| 130 | this->updateConstantColorComponentsForModulation(color, validFlags); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /////////////////////////////////////////////////////////////////////////////// |
| 134 | |
bsalomon@google.com | f271cc7 | 2012-10-24 19:35:13 +0000 | [diff] [blame] | 135 | GR_DEFINE_EFFECT_TEST(GrConfigConversionEffect); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 136 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 137 | GrEffect* GrConfigConversionEffect::TestCreate(SkRandom* random, |
| 138 | GrContext*, |
| 139 | const GrDrawTargetCaps&, |
| 140 | GrTexture* textures[]) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 141 | PMConversion pmConv = static_cast<PMConversion>(random->nextULessThan(kPMConversionCnt)); |
| 142 | bool swapRB; |
| 143 | if (kNone_PMConversion == pmConv) { |
| 144 | swapRB = true; |
| 145 | } else { |
| 146 | swapRB = random->nextBool(); |
| 147 | } |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 148 | return SkNEW_ARGS(GrConfigConversionEffect, |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 149 | (textures[GrEffectUnitTest::kSkiaPMTextureIdx], |
| 150 | swapRB, |
| 151 | pmConv, |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 152 | GrEffectUnitTest::TestMatrix(random))); |
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; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 172 | color[2] = SkTMin(x, y); |
| 173 | color[1] = SkTMin(x, y); |
| 174 | color[0] = SkTMin(x, y); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 208 | 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] | 209 | *pmToUPMRule = kConversionRules[i][0]; |
| 210 | *upmToPMRule = kConversionRules[i][1]; |
| 211 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 212 | static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntToScalar(256)); |
| 213 | static const SkRect kSrcRect = SkRect::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 | |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 218 | SkAutoTUnref<GrEffect> pmToUPM1(SkNEW_ARGS(GrConfigConversionEffect, (dataTex, |
| 219 | false, |
| 220 | *pmToUPMRule, |
| 221 | SkMatrix::I()))); |
| 222 | SkAutoTUnref<GrEffect> upmToPM(SkNEW_ARGS(GrConfigConversionEffect, (readTex, |
| 223 | false, |
| 224 | *upmToPMRule, |
| 225 | SkMatrix::I()))); |
| 226 | SkAutoTUnref<GrEffect> pmToUPM2(SkNEW_ARGS(GrConfigConversionEffect, (tempTex, |
| 227 | false, |
| 228 | *pmToUPMRule, |
| 229 | SkMatrix::I()))); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 230 | |
| 231 | context->setRenderTarget(readTex->asRenderTarget()); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 232 | GrPaint paint1; |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 233 | paint1.addColorEffect(pmToUPM1); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 234 | context->drawRectToRect(paint1, kDstRect, kSrcRect); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 235 | |
| 236 | readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead); |
| 237 | |
| 238 | context->setRenderTarget(tempTex->asRenderTarget()); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 239 | GrPaint paint2; |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 240 | paint2.addColorEffect(upmToPM); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 241 | context->drawRectToRect(paint2, kDstRect, kSrcRect); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 242 | context->setRenderTarget(readTex->asRenderTarget()); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 243 | |
| 244 | GrPaint paint3; |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 245 | paint3.addColorEffect(pmToUPM2); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 246 | context->drawRectToRect(paint3, kDstRect, kSrcRect); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 247 | |
| 248 | readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead); |
| 249 | |
| 250 | failed = false; |
| 251 | for (int y = 0; y < 256 && !failed; ++y) { |
| 252 | for (int x = 0; x <= y; ++x) { |
| 253 | if (firstRead[256 * y + x] != secondRead[256 * y + x]) { |
| 254 | failed = true; |
| 255 | break; |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | if (failed) { |
| 261 | *pmToUPMRule = kNone_PMConversion; |
| 262 | *upmToPMRule = kNone_PMConversion; |
| 263 | } |
| 264 | } |
| 265 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 266 | const GrEffect* GrConfigConversionEffect::Create(GrTexture* texture, |
| 267 | bool swapRedAndBlue, |
| 268 | PMConversion pmConversion, |
| 269 | const SkMatrix& matrix) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 270 | if (!swapRedAndBlue && kNone_PMConversion == pmConversion) { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 271 | // If we returned a GrConfigConversionEffect that was equivalent to a GrSimpleTextureEffect |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 272 | // 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] | 273 | // conversions were requested we instead return a GrSimpleTextureEffect. |
| 274 | return GrSimpleTextureEffect::Create(texture, matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 275 | } else { |
| 276 | if (kRGBA_8888_GrPixelConfig != texture->config() && |
| 277 | kBGRA_8888_GrPixelConfig != texture->config() && |
| 278 | kNone_PMConversion != pmConversion) { |
| 279 | // The PM conversions assume colors are 0..255 |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 280 | return NULL; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 281 | } |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 282 | return SkNEW_ARGS(GrConfigConversionEffect, (texture, |
| 283 | swapRedAndBlue, |
| 284 | pmConversion, |
| 285 | matrix)); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 286 | } |
| 287 | } |