| 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 "GrTBackendEffectFactory.h" | 10 #include "GrTBackendEffectFactory.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 for (size_t i = 0; i < GR_ARRAY_COUNT(kConversionRules) && failed; ++i) { | 212 for (size_t i = 0; i < GR_ARRAY_COUNT(kConversionRules) && failed; ++i) { |
| 213 *pmToUPMRule = kConversionRules[i][0]; | 213 *pmToUPMRule = kConversionRules[i][0]; |
| 214 *upmToPMRule = kConversionRules[i][1]; | 214 *upmToPMRule = kConversionRules[i][1]; |
| 215 | 215 |
| 216 static const GrRect kDstRect = GrRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); | 216 static const GrRect kDstRect = GrRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); |
| 217 static const GrRect kSrcRect = GrRect::MakeWH(SK_Scalar1, SK_Scalar1); | 217 static const GrRect kSrcRect = GrRect::MakeWH(SK_Scalar1, SK_Scalar1); |
| 218 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw | 218 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw |
| 219 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. | 219 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. |
| 220 // We then verify that two reads produced the same values. | 220 // We then verify that two reads produced the same values. |
| 221 | 221 |
| 222 GrPaint paint; | |
| 223 AutoEffectUnref pmToUPM1(SkNEW_ARGS(GrConfigConversionEffect, (dataTex, | 222 AutoEffectUnref pmToUPM1(SkNEW_ARGS(GrConfigConversionEffect, (dataTex, |
| 224 false, | 223 false, |
| 225 *pmToUPMR
ule, | 224 *pmToUPMR
ule, |
| 226 SkMatrix:
:I()))); | 225 SkMatrix:
:I()))); |
| 227 AutoEffectUnref upmToPM(SkNEW_ARGS(GrConfigConversionEffect, (readTex, | 226 AutoEffectUnref upmToPM(SkNEW_ARGS(GrConfigConversionEffect, (readTex, |
| 228 false, | 227 false, |
| 229 *upmToPMRu
le, | 228 *upmToPMRu
le, |
| 230 SkMatrix::
I()))); | 229 SkMatrix::
I()))); |
| 231 AutoEffectUnref pmToUPM2(SkNEW_ARGS(GrConfigConversionEffect, (tempTex, | 230 AutoEffectUnref pmToUPM2(SkNEW_ARGS(GrConfigConversionEffect, (tempTex, |
| 232 false, | 231 false, |
| 233 *pmToUPMR
ule, | 232 *pmToUPMR
ule, |
| 234 SkMatrix:
:I()))); | 233 SkMatrix:
:I()))); |
| 235 | 234 |
| 236 SkAutoTUnref<GrEffectRef> pmToUPMEffect1(CreateEffectRef(pmToUPM1)); | 235 SkAutoTUnref<GrEffectRef> pmToUPMEffect1(CreateEffectRef(pmToUPM1)); |
| 237 SkAutoTUnref<GrEffectRef> upmToPMEffect(CreateEffectRef(upmToPM)); | 236 SkAutoTUnref<GrEffectRef> upmToPMEffect(CreateEffectRef(upmToPM)); |
| 238 SkAutoTUnref<GrEffectRef> pmToUPMEffect2(CreateEffectRef(pmToUPM2)); | 237 SkAutoTUnref<GrEffectRef> pmToUPMEffect2(CreateEffectRef(pmToUPM2)); |
| 239 | 238 |
| 240 context->setRenderTarget(readTex->asRenderTarget()); | 239 context->setRenderTarget(readTex->asRenderTarget()); |
| 241 paint.colorStage(0)->setEffect(pmToUPMEffect1); | 240 GrPaint paint1; |
| 242 context->drawRectToRect(paint, kDstRect, kSrcRect); | 241 paint1.addColorEffect(pmToUPMEffect1); |
| 242 context->drawRectToRect(paint1, kDstRect, kSrcRect); |
| 243 | 243 |
| 244 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead)
; | 244 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead)
; |
| 245 | 245 |
| 246 context->setRenderTarget(tempTex->asRenderTarget()); | 246 context->setRenderTarget(tempTex->asRenderTarget()); |
| 247 paint.colorStage(0)->setEffect(upmToPMEffect); | 247 GrPaint paint2; |
| 248 context->drawRectToRect(paint, kDstRect, kSrcRect); | 248 paint2.addColorEffect(upmToPMEffect); |
| 249 context->drawRectToRect(paint2, kDstRect, kSrcRect); |
| 249 context->setRenderTarget(readTex->asRenderTarget()); | 250 context->setRenderTarget(readTex->asRenderTarget()); |
| 250 paint.colorStage(0)->setEffect(pmToUPMEffect2); | 251 |
| 251 context->drawRectToRect(paint, kDstRect, kSrcRect); | 252 GrPaint paint3; |
| 253 paint3.addColorEffect(pmToUPMEffect2); |
| 254 context->drawRectToRect(paint3, kDstRect, kSrcRect); |
| 252 | 255 |
| 253 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead
); | 256 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead
); |
| 254 | 257 |
| 255 failed = false; | 258 failed = false; |
| 256 for (int y = 0; y < 256 && !failed; ++y) { | 259 for (int y = 0; y < 256 && !failed; ++y) { |
| 257 for (int x = 0; x <= y; ++x) { | 260 for (int x = 0; x <= y; ++x) { |
| 258 if (firstRead[256 * y + x] != secondRead[256 * y + x]) { | 261 if (firstRead[256 * y + x] != secondRead[256 * y + x]) { |
| 259 failed = true; | 262 failed = true; |
| 260 break; | 263 break; |
| 261 } | 264 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 284 // The PM conversions assume colors are 0..255 | 287 // The PM conversions assume colors are 0..255 |
| 285 return NULL; | 288 return NULL; |
| 286 } | 289 } |
| 287 AutoEffectUnref effect(SkNEW_ARGS(GrConfigConversionEffect, (texture, | 290 AutoEffectUnref effect(SkNEW_ARGS(GrConfigConversionEffect, (texture, |
| 288 swapRedAndB
lue, | 291 swapRedAndB
lue, |
| 289 pmConversio
n, | 292 pmConversio
n, |
| 290 matrix))); | 293 matrix))); |
| 291 return CreateEffectRef(effect); | 294 return CreateEffectRef(effect); |
| 292 } | 295 } |
| 293 } | 296 } |
| OLD | NEW |