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 "GrInvariantOutput.h" | 11 #include "GrInvariantOutput.h" |
11 #include "GrSimpleTextureEffect.h" | 12 #include "GrSimpleTextureEffect.h" |
12 #include "SkMatrix.h" | 13 #include "SkMatrix.h" |
13 #include "gl/GrGLProcessor.h" | 14 #include "gl/GrGLProcessor.h" |
14 #include "gl/builders/GrGLProgramBuilder.h" | 15 #include "gl/builders/GrGLProgramBuilder.h" |
15 | 16 |
16 class GrGLConfigConversionEffect : public GrGLFragmentProcessor { | 17 class GrGLConfigConversionEffect : public GrGLFragmentProcessor { |
17 public: | 18 public: |
18 GrGLConfigConversionEffect(const GrProcessor& processor) { | 19 GrGLConfigConversionEffect(const GrProcessor& processor) { |
19 const GrConfigConversionEffect& configConversionEffect = | 20 const GrConfigConversionEffect& configConversionEffect = |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 return; | 201 return; |
201 } | 202 } |
202 | 203 |
203 static const PMConversion kConversionRules[][2] = { | 204 static const PMConversion kConversionRules[][2] = { |
204 {kDivByAlpha_RoundDown_PMConversion, kMulByAlpha_RoundUp_PMConversion}, | 205 {kDivByAlpha_RoundDown_PMConversion, kMulByAlpha_RoundUp_PMConversion}, |
205 {kDivByAlpha_RoundUp_PMConversion, kMulByAlpha_RoundDown_PMConversion}, | 206 {kDivByAlpha_RoundUp_PMConversion, kMulByAlpha_RoundDown_PMConversion}, |
206 }; | 207 }; |
207 | 208 |
208 bool failed = true; | 209 bool failed = true; |
209 | 210 |
| 211 GrDrawContext* drawContext = context->drawContext(); |
| 212 if (!drawContext) { |
| 213 return; |
| 214 } |
| 215 |
210 for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) { | 216 for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) { |
211 *pmToUPMRule = kConversionRules[i][0]; | 217 *pmToUPMRule = kConversionRules[i][0]; |
212 *upmToPMRule = kConversionRules[i][1]; | 218 *upmToPMRule = kConversionRules[i][1]; |
213 | 219 |
214 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); | 220 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); |
215 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); | 221 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); |
216 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw | 222 // 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 fin
ally read the data. | 223 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. |
218 // We then verify that two reads produced the same values. | 224 // We then verify that two reads produced the same values. |
219 | 225 |
220 SkAutoTUnref<GrFragmentProcessor> pmToUPM1( | 226 SkAutoTUnref<GrFragmentProcessor> pmToUPM1( |
221 SkNEW_ARGS(GrConfigConversionEffect, | 227 SkNEW_ARGS(GrConfigConversionEffect, |
222 (dataTex, false, *pmToUPMRule, SkMatrix::I()))); | 228 (dataTex, false, *pmToUPMRule, SkMatrix::I()))); |
223 SkAutoTUnref<GrFragmentProcessor> upmToPM( | 229 SkAutoTUnref<GrFragmentProcessor> upmToPM( |
224 SkNEW_ARGS(GrConfigConversionEffect, | 230 SkNEW_ARGS(GrConfigConversionEffect, |
225 (readTex, false, *upmToPMRule, SkMatrix::I()))); | 231 (readTex, false, *upmToPMRule, SkMatrix::I()))); |
226 SkAutoTUnref<GrFragmentProcessor> pmToUPM2( | 232 SkAutoTUnref<GrFragmentProcessor> pmToUPM2( |
227 SkNEW_ARGS(GrConfigConversionEffect, | 233 SkNEW_ARGS(GrConfigConversionEffect, |
228 (tempTex, false, *pmToUPMRule, SkMatrix::I()))); | 234 (tempTex, false, *pmToUPMRule, SkMatrix::I()))); |
229 | 235 |
230 GrPaint paint1; | 236 GrPaint paint1; |
231 paint1.addColorProcessor(pmToUPM1); | 237 paint1.addColorProcessor(pmToUPM1); |
232 context->drawNonAARectToRect(readTex->asRenderTarget(), | 238 drawContext->drawNonAARectToRect(readTex->asRenderTarget(), |
233 GrClip::WideOpen(), | 239 GrClip::WideOpen(), |
234 paint1, | 240 paint1, |
235 SkMatrix::I(), | 241 SkMatrix::I(), |
236 kDstRect, | 242 kDstRect, |
237 kSrcRect); | 243 kSrcRect); |
238 | 244 |
239 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead)
; | 245 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead)
; |
240 | 246 |
241 GrPaint paint2; | 247 GrPaint paint2; |
242 paint2.addColorProcessor(upmToPM); | 248 paint2.addColorProcessor(upmToPM); |
243 context->drawNonAARectToRect(tempTex->asRenderTarget(), | 249 drawContext->drawNonAARectToRect(tempTex->asRenderTarget(), |
244 GrClip::WideOpen(), | 250 GrClip::WideOpen(), |
245 paint2, | 251 paint2, |
246 SkMatrix::I(), | 252 SkMatrix::I(), |
247 kDstRect, | 253 kDstRect, |
248 kSrcRect); | 254 kSrcRect); |
249 | 255 |
250 GrPaint paint3; | 256 GrPaint paint3; |
251 paint3.addColorProcessor(pmToUPM2); | 257 paint3.addColorProcessor(pmToUPM2); |
252 context->drawNonAARectToRect(readTex->asRenderTarget(), | 258 drawContext->drawNonAARectToRect(readTex->asRenderTarget(), |
253 GrClip::WideOpen(), | 259 GrClip::WideOpen(), |
254 paint3, | 260 paint3, |
255 SkMatrix::I(), | 261 SkMatrix::I(), |
256 kDstRect, | 262 kDstRect, |
257 kSrcRect); | 263 kSrcRect); |
258 | 264 |
259 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead
); | 265 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead
); |
260 | 266 |
261 failed = false; | 267 failed = false; |
262 for (int y = 0; y < 256 && !failed; ++y) { | 268 for (int y = 0; y < 256 && !failed; ++y) { |
263 for (int x = 0; x <= y; ++x) { | 269 for (int x = 0; x <= y; ++x) { |
264 if (firstRead[256 * y + x] != secondRead[256 * y + x]) { | 270 if (firstRead[256 * y + x] != secondRead[256 * y + x]) { |
265 failed = true; | 271 failed = true; |
266 break; | 272 break; |
267 } | 273 } |
(...skipping 21 matching lines...) Expand all Loading... |
289 kNone_PMConversion != pmConversion) { | 295 kNone_PMConversion != pmConversion) { |
290 // The PM conversions assume colors are 0..255 | 296 // The PM conversions assume colors are 0..255 |
291 return NULL; | 297 return NULL; |
292 } | 298 } |
293 return SkNEW_ARGS(GrConfigConversionEffect, (texture, | 299 return SkNEW_ARGS(GrConfigConversionEffect, (texture, |
294 swapRedAndBlue, | 300 swapRedAndBlue, |
295 pmConversion, | 301 pmConversion, |
296 matrix)); | 302 matrix)); |
297 } | 303 } |
298 } | 304 } |
OLD | NEW |