| 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 return; | 200 return; |
| 201 } | 201 } |
| 202 | 202 |
| 203 static const PMConversion kConversionRules[][2] = { | 203 static const PMConversion kConversionRules[][2] = { |
| 204 {kDivByAlpha_RoundDown_PMConversion, kMulByAlpha_RoundUp_PMConversion}, | 204 {kDivByAlpha_RoundDown_PMConversion, kMulByAlpha_RoundUp_PMConversion}, |
| 205 {kDivByAlpha_RoundUp_PMConversion, kMulByAlpha_RoundDown_PMConversion}, | 205 {kDivByAlpha_RoundUp_PMConversion, kMulByAlpha_RoundDown_PMConversion}, |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 bool failed = true; | 208 bool failed = true; |
| 209 | 209 |
| 210 GrDrawContext* drawContext = context->drawContext(); | |
| 211 if (!drawContext) { | |
| 212 return; | |
| 213 } | |
| 214 | |
| 215 for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) { | 210 for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) { |
| 216 *pmToUPMRule = kConversionRules[i][0]; | 211 *pmToUPMRule = kConversionRules[i][0]; |
| 217 *upmToPMRule = kConversionRules[i][1]; | 212 *upmToPMRule = kConversionRules[i][1]; |
| 218 | 213 |
| 219 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); | 214 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); |
| 220 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); | 215 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); |
| 221 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw | 216 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw |
| 222 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. | 217 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. |
| 223 // We then verify that two reads produced the same values. | 218 // We then verify that two reads produced the same values. |
| 224 | 219 |
| 225 GrPaint paint1; | 220 GrPaint paint1; |
| 226 GrPaint paint2; | 221 GrPaint paint2; |
| 227 GrPaint paint3; | 222 GrPaint paint3; |
| 228 SkAutoTUnref<GrFragmentProcessor> pmToUPM1( | 223 SkAutoTUnref<GrFragmentProcessor> pmToUPM1( |
| 229 SkNEW_ARGS(GrConfigConversionEffect, | 224 SkNEW_ARGS(GrConfigConversionEffect, |
| 230 (paint1.getProcessorDataManager(), dataTex, false, *p
mToUPMRule, | 225 (paint1.getProcessorDataManager(), dataTex, false, *p
mToUPMRule, |
| 231 SkMatrix::I()))); | 226 SkMatrix::I()))); |
| 232 SkAutoTUnref<GrFragmentProcessor> upmToPM( | 227 SkAutoTUnref<GrFragmentProcessor> upmToPM( |
| 233 SkNEW_ARGS(GrConfigConversionEffect, | 228 SkNEW_ARGS(GrConfigConversionEffect, |
| 234 (paint2.getProcessorDataManager(), readTex, false, *u
pmToPMRule, | 229 (paint2.getProcessorDataManager(), readTex, false, *u
pmToPMRule, |
| 235 SkMatrix::I()))); | 230 SkMatrix::I()))); |
| 236 SkAutoTUnref<GrFragmentProcessor> pmToUPM2( | 231 SkAutoTUnref<GrFragmentProcessor> pmToUPM2( |
| 237 SkNEW_ARGS(GrConfigConversionEffect, | 232 SkNEW_ARGS(GrConfigConversionEffect, |
| 238 (paint3.getProcessorDataManager(), tempTex, false, *p
mToUPMRule, | 233 (paint3.getProcessorDataManager(), tempTex, false, *p
mToUPMRule, |
| 239 SkMatrix::I()))); | 234 SkMatrix::I()))); |
| 240 | 235 |
| 241 paint1.addColorProcessor(pmToUPM1); | 236 paint1.addColorProcessor(pmToUPM1); |
| 242 drawContext->drawNonAARectToRect(readTex->asRenderTarget(), | 237 |
| 243 GrClip::WideOpen(), | 238 |
| 244 paint1, | 239 GrDrawContext* readDrawContext = context->drawContext(); |
| 245 SkMatrix::I(), | 240 if (!readDrawContext) { |
| 246 kDstRect, | 241 failed = true; |
| 247 kSrcRect); | 242 break; |
| 243 } |
| 244 |
| 245 readDrawContext->drawNonAARectToRect(readTex->asRenderTarget(), |
| 246 GrClip::WideOpen(), |
| 247 paint1, |
| 248 SkMatrix::I(), |
| 249 kDstRect, |
| 250 kSrcRect); |
| 248 | 251 |
| 249 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead)
; | 252 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead)
; |
| 250 | 253 |
| 251 paint2.addColorProcessor(upmToPM); | 254 paint2.addColorProcessor(upmToPM); |
| 252 drawContext->drawNonAARectToRect(tempTex->asRenderTarget(), | 255 |
| 253 GrClip::WideOpen(), | 256 GrDrawContext* tempDrawContext = context->drawContext(); |
| 254 paint2, | 257 if (!tempDrawContext) { |
| 255 SkMatrix::I(), | 258 failed = true; |
| 256 kDstRect, | 259 break; |
| 257 kSrcRect); | 260 } |
| 261 tempDrawContext->drawNonAARectToRect(tempTex->asRenderTarget(), |
| 262 GrClip::WideOpen(), |
| 263 paint2, |
| 264 SkMatrix::I(), |
| 265 kDstRect, |
| 266 kSrcRect); |
| 258 | 267 |
| 259 paint3.addColorProcessor(pmToUPM2); | 268 paint3.addColorProcessor(pmToUPM2); |
| 260 drawContext->drawNonAARectToRect(readTex->asRenderTarget(), | 269 |
| 261 GrClip::WideOpen(), | 270 readDrawContext = context->drawContext(); |
| 262 paint3, | 271 if (!readDrawContext) { |
| 263 SkMatrix::I(), | 272 failed = true; |
| 264 kDstRect, | 273 break; |
| 265 kSrcRect); | 274 } |
| 275 |
| 276 readDrawContext->drawNonAARectToRect(readTex->asRenderTarget(), |
| 277 GrClip::WideOpen(), |
| 278 paint3, |
| 279 SkMatrix::I(), |
| 280 kDstRect, |
| 281 kSrcRect); |
| 266 | 282 |
| 267 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead
); | 283 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead
); |
| 268 | 284 |
| 269 failed = false; | 285 failed = false; |
| 270 for (int y = 0; y < 256 && !failed; ++y) { | 286 for (int y = 0; y < 256 && !failed; ++y) { |
| 271 for (int x = 0; x <= y; ++x) { | 287 for (int x = 0; x <= y; ++x) { |
| 272 if (firstRead[256 * y + x] != secondRead[256 * y + x]) { | 288 if (firstRead[256 * y + x] != secondRead[256 * y + x]) { |
| 273 failed = true; | 289 failed = true; |
| 274 break; | 290 break; |
| 275 } | 291 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 299 // The PM conversions assume colors are 0..255 | 315 // The PM conversions assume colors are 0..255 |
| 300 return NULL; | 316 return NULL; |
| 301 } | 317 } |
| 302 return SkNEW_ARGS(GrConfigConversionEffect, (procDataManager, | 318 return SkNEW_ARGS(GrConfigConversionEffect, (procDataManager, |
| 303 texture, | 319 texture, |
| 304 swapRedAndBlue, | 320 swapRedAndBlue, |
| 305 pmConversion, | 321 pmConversion, |
| 306 matrix)); | 322 matrix)); |
| 307 } | 323 } |
| 308 } | 324 } |
| OLD | NEW |