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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 private: | 93 private: |
94 bool fSwapRedAndBlue; | 94 bool fSwapRedAndBlue; |
95 GrConfigConversionEffect::PMConversion fPMConversion; | 95 GrConfigConversionEffect::PMConversion fPMConversion; |
96 | 96 |
97 typedef GrGLFragmentProcessor INHERITED; | 97 typedef GrGLFragmentProcessor INHERITED; |
98 | 98 |
99 }; | 99 }; |
100 | 100 |
101 /////////////////////////////////////////////////////////////////////////////// | 101 /////////////////////////////////////////////////////////////////////////////// |
102 | 102 |
103 GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture, | 103 GrConfigConversionEffect::GrConfigConversionEffect(GrProcessorDataManager* procD
ataManager, |
| 104 GrTexture* texture, |
104 bool swapRedAndBlue, | 105 bool swapRedAndBlue, |
105 PMConversion pmConversion, | 106 PMConversion pmConversion, |
106 const SkMatrix& matrix) | 107 const SkMatrix& matrix) |
107 : GrSingleTextureEffect(texture, matrix) | 108 : INHERITED(procDataManager, texture, matrix) |
108 , fSwapRedAndBlue(swapRedAndBlue) | 109 , fSwapRedAndBlue(swapRedAndBlue) |
109 , fPMConversion(pmConversion) { | 110 , fPMConversion(pmConversion) { |
110 this->initClassID<GrConfigConversionEffect>(); | 111 this->initClassID<GrConfigConversionEffect>(); |
111 SkASSERT(kRGBA_8888_GrPixelConfig == texture->config() || | 112 SkASSERT(kRGBA_8888_GrPixelConfig == texture->config() || |
112 kBGRA_8888_GrPixelConfig == texture->config()); | 113 kBGRA_8888_GrPixelConfig == texture->config()); |
113 // Why did we pollute our texture cache instead of using a GrSingleTextureEf
fect? | 114 // Why did we pollute our texture cache instead of using a GrSingleTextureEf
fect? |
114 SkASSERT(swapRedAndBlue || kNone_PMConversion != pmConversion); | 115 SkASSERT(swapRedAndBlue || kNone_PMConversion != pmConversion); |
115 } | 116 } |
116 | 117 |
117 bool GrConfigConversionEffect::onIsEqual(const GrFragmentProcessor& s) const { | 118 bool GrConfigConversionEffect::onIsEqual(const GrFragmentProcessor& s) const { |
(...skipping 12 matching lines...) Expand all Loading... |
130 | 131 |
131 GrFragmentProcessor* GrConfigConversionEffect::TestCreate(GrProcessorTestData* d
) { | 132 GrFragmentProcessor* GrConfigConversionEffect::TestCreate(GrProcessorTestData* d
) { |
132 PMConversion pmConv = static_cast<PMConversion>(d->fRandom->nextULessThan(kP
MConversionCnt)); | 133 PMConversion pmConv = static_cast<PMConversion>(d->fRandom->nextULessThan(kP
MConversionCnt)); |
133 bool swapRB; | 134 bool swapRB; |
134 if (kNone_PMConversion == pmConv) { | 135 if (kNone_PMConversion == pmConv) { |
135 swapRB = true; | 136 swapRB = true; |
136 } else { | 137 } else { |
137 swapRB = d->fRandom->nextBool(); | 138 swapRB = d->fRandom->nextBool(); |
138 } | 139 } |
139 return SkNEW_ARGS(GrConfigConversionEffect, | 140 return SkNEW_ARGS(GrConfigConversionEffect, |
140 (d->fTextures[GrProcessorUnitTest::kSkiaPM
TextureIdx], | 141 (d->fProcDataManager, |
| 142 d->fTextures[GrProcessorUnitTest::kSkiaPM
TextureIdx], |
141 swapRB, | 143 swapRB, |
142 pmConv, | 144 pmConv, |
143 GrTest::TestMatrix(d->fRandom))); | 145 GrTest::TestMatrix(d->fRandom))); |
144 } | 146 } |
145 | 147 |
146 /////////////////////////////////////////////////////////////////////////////// | 148 /////////////////////////////////////////////////////////////////////////////// |
147 | 149 |
148 void GrConfigConversionEffect::getGLProcessorKey(const GrGLSLCaps& caps, | 150 void GrConfigConversionEffect::getGLProcessorKey(const GrGLSLCaps& caps, |
149 GrProcessorKeyBuilder* b) const
{ | 151 GrProcessorKeyBuilder* b) const
{ |
150 GrGLConfigConversionEffect::GenKey(*this, caps, b); | 152 GrGLConfigConversionEffect::GenKey(*this, caps, b); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) { | 215 for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) { |
214 *pmToUPMRule = kConversionRules[i][0]; | 216 *pmToUPMRule = kConversionRules[i][0]; |
215 *upmToPMRule = kConversionRules[i][1]; | 217 *upmToPMRule = kConversionRules[i][1]; |
216 | 218 |
217 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); | 219 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); |
218 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); | 220 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); |
219 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw | 221 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw |
220 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. | 222 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. |
221 // We then verify that two reads produced the same values. | 223 // We then verify that two reads produced the same values. |
222 | 224 |
| 225 GrPaint paint1; |
| 226 GrPaint paint2; |
| 227 GrPaint paint3; |
223 SkAutoTUnref<GrFragmentProcessor> pmToUPM1( | 228 SkAutoTUnref<GrFragmentProcessor> pmToUPM1( |
224 SkNEW_ARGS(GrConfigConversionEffect, | 229 SkNEW_ARGS(GrConfigConversionEffect, |
225 (dataTex, false, *pmToUPMRule, SkMatrix::I()))); | 230 (paint1.getProcessorDataManager(), dataTex, false, *p
mToUPMRule, |
| 231 SkMatrix::I()))); |
226 SkAutoTUnref<GrFragmentProcessor> upmToPM( | 232 SkAutoTUnref<GrFragmentProcessor> upmToPM( |
227 SkNEW_ARGS(GrConfigConversionEffect, | 233 SkNEW_ARGS(GrConfigConversionEffect, |
228 (readTex, false, *upmToPMRule, SkMatrix::I()))); | 234 (paint2.getProcessorDataManager(), readTex, false, *u
pmToPMRule, |
| 235 SkMatrix::I()))); |
229 SkAutoTUnref<GrFragmentProcessor> pmToUPM2( | 236 SkAutoTUnref<GrFragmentProcessor> pmToUPM2( |
230 SkNEW_ARGS(GrConfigConversionEffect, | 237 SkNEW_ARGS(GrConfigConversionEffect, |
231 (tempTex, false, *pmToUPMRule, SkMatrix::I()))); | 238 (paint3.getProcessorDataManager(), tempTex, false, *p
mToUPMRule, |
| 239 SkMatrix::I()))); |
232 | 240 |
233 GrPaint paint1; | |
234 paint1.addColorProcessor(pmToUPM1); | 241 paint1.addColorProcessor(pmToUPM1); |
235 drawContext->drawNonAARectToRect(readTex->asRenderTarget(), | 242 drawContext->drawNonAARectToRect(readTex->asRenderTarget(), |
236 GrClip::WideOpen(), | 243 GrClip::WideOpen(), |
237 paint1, | 244 paint1, |
238 SkMatrix::I(), | 245 SkMatrix::I(), |
239 kDstRect, | 246 kDstRect, |
240 kSrcRect); | 247 kSrcRect); |
241 | 248 |
242 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead)
; | 249 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead)
; |
243 | 250 |
244 GrPaint paint2; | |
245 paint2.addColorProcessor(upmToPM); | 251 paint2.addColorProcessor(upmToPM); |
246 drawContext->drawNonAARectToRect(tempTex->asRenderTarget(), | 252 drawContext->drawNonAARectToRect(tempTex->asRenderTarget(), |
247 GrClip::WideOpen(), | 253 GrClip::WideOpen(), |
248 paint2, | 254 paint2, |
249 SkMatrix::I(), | 255 SkMatrix::I(), |
250 kDstRect, | 256 kDstRect, |
251 kSrcRect); | 257 kSrcRect); |
252 | 258 |
253 GrPaint paint3; | |
254 paint3.addColorProcessor(pmToUPM2); | 259 paint3.addColorProcessor(pmToUPM2); |
255 drawContext->drawNonAARectToRect(readTex->asRenderTarget(), | 260 drawContext->drawNonAARectToRect(readTex->asRenderTarget(), |
256 GrClip::WideOpen(), | 261 GrClip::WideOpen(), |
257 paint3, | 262 paint3, |
258 SkMatrix::I(), | 263 SkMatrix::I(), |
259 kDstRect, | 264 kDstRect, |
260 kSrcRect); | 265 kSrcRect); |
261 | 266 |
262 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead
); | 267 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead
); |
263 | 268 |
264 failed = false; | 269 failed = false; |
265 for (int y = 0; y < 256 && !failed; ++y) { | 270 for (int y = 0; y < 256 && !failed; ++y) { |
266 for (int x = 0; x <= y; ++x) { | 271 for (int x = 0; x <= y; ++x) { |
267 if (firstRead[256 * y + x] != secondRead[256 * y + x]) { | 272 if (firstRead[256 * y + x] != secondRead[256 * y + x]) { |
268 failed = true; | 273 failed = true; |
269 break; | 274 break; |
270 } | 275 } |
271 } | 276 } |
272 } | 277 } |
273 } | 278 } |
274 if (failed) { | 279 if (failed) { |
275 *pmToUPMRule = kNone_PMConversion; | 280 *pmToUPMRule = kNone_PMConversion; |
276 *upmToPMRule = kNone_PMConversion; | 281 *upmToPMRule = kNone_PMConversion; |
277 } | 282 } |
278 } | 283 } |
279 | 284 |
280 const GrFragmentProcessor* GrConfigConversionEffect::Create(GrTexture* texture, | 285 const GrFragmentProcessor* GrConfigConversionEffect::Create(GrProcessorDataManag
er* procDataManager, |
281 bool swapRedAndBlue, | 286 GrTexture* texture, |
282 PMConversion pmConversion, | 287 bool swapRedAndBlue, |
283 const SkMatrix& matrix) { | 288 PMConversion pmConve
rsion, |
| 289 const SkMatrix& matr
ix) { |
284 if (!swapRedAndBlue && kNone_PMConversion == pmConversion) { | 290 if (!swapRedAndBlue && kNone_PMConversion == pmConversion) { |
285 // If we returned a GrConfigConversionEffect that was equivalent to a Gr
SimpleTextureEffect | 291 // If we returned a GrConfigConversionEffect that was equivalent to a Gr
SimpleTextureEffect |
286 // then we may pollute our texture cache with redundant shaders. So in t
he case that no | 292 // then we may pollute our texture cache with redundant shaders. So in t
he case that no |
287 // conversions were requested we instead return a GrSimpleTextureEffect. | 293 // conversions were requested we instead return a GrSimpleTextureEffect. |
288 return GrSimpleTextureEffect::Create(texture, matrix); | 294 return GrSimpleTextureEffect::Create(procDataManager, texture, matrix); |
289 } else { | 295 } else { |
290 if (kRGBA_8888_GrPixelConfig != texture->config() && | 296 if (kRGBA_8888_GrPixelConfig != texture->config() && |
291 kBGRA_8888_GrPixelConfig != texture->config() && | 297 kBGRA_8888_GrPixelConfig != texture->config() && |
292 kNone_PMConversion != pmConversion) { | 298 kNone_PMConversion != pmConversion) { |
293 // The PM conversions assume colors are 0..255 | 299 // The PM conversions assume colors are 0..255 |
294 return NULL; | 300 return NULL; |
295 } | 301 } |
296 return SkNEW_ARGS(GrConfigConversionEffect, (texture, | 302 return SkNEW_ARGS(GrConfigConversionEffect, (procDataManager, |
| 303 texture, |
297 swapRedAndBlue, | 304 swapRedAndBlue, |
298 pmConversion, | 305 pmConversion, |
299 matrix)); | 306 matrix)); |
300 } | 307 } |
301 } | 308 } |
OLD | NEW |