| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrConfigConversionEffect.h" | 8 #include "GrConfigConversionEffect.h" |
| 9 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect); | 129 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect); |
| 130 | 130 |
| 131 GrFragmentProcessor* GrConfigConversionEffect::TestCreate(GrProcessorTestData* d
) { | 131 GrFragmentProcessor* GrConfigConversionEffect::TestCreate(GrProcessorTestData* d
) { |
| 132 PMConversion pmConv = static_cast<PMConversion>(d->fRandom->nextULessThan(kP
MConversionCnt)); | 132 PMConversion pmConv = static_cast<PMConversion>(d->fRandom->nextULessThan(kP
MConversionCnt)); |
| 133 bool swapRB; | 133 bool swapRB; |
| 134 if (kNone_PMConversion == pmConv) { | 134 if (kNone_PMConversion == pmConv) { |
| 135 swapRB = true; | 135 swapRB = true; |
| 136 } else { | 136 } else { |
| 137 swapRB = d->fRandom->nextBool(); | 137 swapRB = d->fRandom->nextBool(); |
| 138 } | 138 } |
| 139 return SkNEW_ARGS(GrConfigConversionEffect, | 139 return new GrConfigConversionEffect(d->fProcDataManager, |
| 140 (d->fProcDataManager, | 140 d->fTextures[GrProcessorUnitTest::kSkiaP
MTextureIdx], |
| 141 d->fTextures[GrProcessorUnitTest::kSkiaPM
TextureIdx], | 141 swapRB, pmConv, GrTest::TestMatrix(d->fR
andom)); |
| 142 swapRB, | |
| 143 pmConv, | |
| 144 GrTest::TestMatrix(d->fRandom))); | |
| 145 } | 142 } |
| 146 | 143 |
| 147 /////////////////////////////////////////////////////////////////////////////// | 144 /////////////////////////////////////////////////////////////////////////////// |
| 148 | 145 |
| 149 void GrConfigConversionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 146 void GrConfigConversionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 150 GrProcessorKeyBuilder* b) const
{ | 147 GrProcessorKeyBuilder* b) const
{ |
| 151 GrGLConfigConversionEffect::GenKey(*this, caps, b); | 148 GrGLConfigConversionEffect::GenKey(*this, caps, b); |
| 152 } | 149 } |
| 153 | 150 |
| 154 GrGLFragmentProcessor* GrConfigConversionEffect::onCreateGLInstance() const { | 151 GrGLFragmentProcessor* GrConfigConversionEffect::onCreateGLInstance() const { |
| 155 return SkNEW_ARGS(GrGLConfigConversionEffect, (*this)); | 152 return new GrGLConfigConversionEffect(*this); |
| 156 } | 153 } |
| 157 | 154 |
| 158 | 155 |
| 159 | 156 |
| 160 void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
, | 157 void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
, |
| 161 PMConversion* pmTo
UPMRule, | 158 PMConversion* pmTo
UPMRule, |
| 162 PMConversion* upmT
oPMRule) { | 159 PMConversion* upmT
oPMRule) { |
| 163 *pmToUPMRule = kNone_PMConversion; | 160 *pmToUPMRule = kNone_PMConversion; |
| 164 *upmToPMRule = kNone_PMConversion; | 161 *upmToPMRule = kNone_PMConversion; |
| 165 SkAutoTMalloc<uint32_t> data(256 * 256 * 3); | 162 SkAutoTMalloc<uint32_t> data(256 * 256 * 3); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 209 |
| 213 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); | 210 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); |
| 214 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); | 211 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); |
| 215 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw | 212 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw |
| 216 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. | 213 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. |
| 217 // We then verify that two reads produced the same values. | 214 // We then verify that two reads produced the same values. |
| 218 | 215 |
| 219 GrPaint paint1; | 216 GrPaint paint1; |
| 220 GrPaint paint2; | 217 GrPaint paint2; |
| 221 GrPaint paint3; | 218 GrPaint paint3; |
| 222 SkAutoTUnref<GrFragmentProcessor> pmToUPM1( | 219 SkAutoTUnref<GrFragmentProcessor> pmToUPM1(new GrConfigConversionEffect( |
| 223 SkNEW_ARGS(GrConfigConversionEffect, | 220 paint1.getProcessorDataManager(), dataTex, false, *pmToUPMRule,
SkMatrix::I())); |
| 224 (paint1.getProcessorDataManager(), dataTex, false, *p
mToUPMRule, | 221 SkAutoTUnref<GrFragmentProcessor> upmToPM(new GrConfigConversionEffect( |
| 225 SkMatrix::I()))); | 222 paint2.getProcessorDataManager(), readTex, false, *upmToPMRule,
SkMatrix::I())); |
| 226 SkAutoTUnref<GrFragmentProcessor> upmToPM( | 223 SkAutoTUnref<GrFragmentProcessor> pmToUPM2(new GrConfigConversionEffect( |
| 227 SkNEW_ARGS(GrConfigConversionEffect, | 224 paint3.getProcessorDataManager(), tempTex, false, *pmToUPMRule,
SkMatrix::I())); |
| 228 (paint2.getProcessorDataManager(), readTex, false, *u
pmToPMRule, | |
| 229 SkMatrix::I()))); | |
| 230 SkAutoTUnref<GrFragmentProcessor> pmToUPM2( | |
| 231 SkNEW_ARGS(GrConfigConversionEffect, | |
| 232 (paint3.getProcessorDataManager(), tempTex, false, *p
mToUPMRule, | |
| 233 SkMatrix::I()))); | |
| 234 | 225 |
| 235 paint1.addColorProcessor(pmToUPM1); | 226 paint1.addColorProcessor(pmToUPM1); |
| 236 | 227 |
| 237 | 228 |
| 238 GrDrawContext* readDrawContext = context->drawContext(); | 229 GrDrawContext* readDrawContext = context->drawContext(); |
| 239 if (!readDrawContext) { | 230 if (!readDrawContext) { |
| 240 failed = true; | 231 failed = true; |
| 241 break; | 232 break; |
| 242 } | 233 } |
| 243 | 234 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 // then we may pollute our texture cache with redundant shaders. So in t
he case that no | 298 // then we may pollute our texture cache with redundant shaders. So in t
he case that no |
| 308 // conversions were requested we instead return a GrSimpleTextureEffect. | 299 // conversions were requested we instead return a GrSimpleTextureEffect. |
| 309 return GrSimpleTextureEffect::Create(procDataManager, texture, matrix); | 300 return GrSimpleTextureEffect::Create(procDataManager, texture, matrix); |
| 310 } else { | 301 } else { |
| 311 if (kRGBA_8888_GrPixelConfig != texture->config() && | 302 if (kRGBA_8888_GrPixelConfig != texture->config() && |
| 312 kBGRA_8888_GrPixelConfig != texture->config() && | 303 kBGRA_8888_GrPixelConfig != texture->config() && |
| 313 kNone_PMConversion != pmConversion) { | 304 kNone_PMConversion != pmConversion) { |
| 314 // The PM conversions assume colors are 0..255 | 305 // The PM conversions assume colors are 0..255 |
| 315 return NULL; | 306 return NULL; |
| 316 } | 307 } |
| 317 return SkNEW_ARGS(GrConfigConversionEffect, (procDataManager, | 308 return new GrConfigConversionEffect(procDataManager, texture, swapRedAnd
Blue, pmConversion, |
| 318 texture, | 309 matrix); |
| 319 swapRedAndBlue, | |
| 320 pmConversion, | |
| 321 matrix)); | |
| 322 } | 310 } |
| 323 } | 311 } |
| OLD | NEW |