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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 private: | 89 private: |
90 bool fSwapRedAndBlue; | 90 bool fSwapRedAndBlue; |
91 GrConfigConversionEffect::PMConversion fPMConversion; | 91 GrConfigConversionEffect::PMConversion fPMConversion; |
92 | 92 |
93 typedef GrGLFragmentProcessor INHERITED; | 93 typedef GrGLFragmentProcessor INHERITED; |
94 | 94 |
95 }; | 95 }; |
96 | 96 |
97 /////////////////////////////////////////////////////////////////////////////// | 97 /////////////////////////////////////////////////////////////////////////////// |
98 | 98 |
99 GrConfigConversionEffect::GrConfigConversionEffect(GrProcessorDataManager* procD
ataManager, | 99 GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture, |
100 GrTexture* texture, | |
101 bool swapRedAndBlue, | 100 bool swapRedAndBlue, |
102 PMConversion pmConversion, | 101 PMConversion pmConversion, |
103 const SkMatrix& matrix) | 102 const SkMatrix& matrix) |
104 : INHERITED(procDataManager, texture, matrix) | 103 : INHERITED(texture, matrix) |
105 , fSwapRedAndBlue(swapRedAndBlue) | 104 , fSwapRedAndBlue(swapRedAndBlue) |
106 , fPMConversion(pmConversion) { | 105 , fPMConversion(pmConversion) { |
107 this->initClassID<GrConfigConversionEffect>(); | 106 this->initClassID<GrConfigConversionEffect>(); |
108 // We expect to get here with non-BGRA/RGBA only if we're doing not doing a
premul/unpremul | 107 // We expect to get here with non-BGRA/RGBA only if we're doing not doing a
premul/unpremul |
109 // conversion. | 108 // conversion. |
110 SkASSERT((kRGBA_8888_GrPixelConfig == texture->config() || | 109 SkASSERT((kRGBA_8888_GrPixelConfig == texture->config() || |
111 kBGRA_8888_GrPixelConfig == texture->config()) || | 110 kBGRA_8888_GrPixelConfig == texture->config()) || |
112 kNone_PMConversion == pmConversion); | 111 kNone_PMConversion == pmConversion); |
113 // Why did we pollute our texture cache instead of using a GrSingleTextureEf
fect? | 112 // Why did we pollute our texture cache instead of using a GrSingleTextureEf
fect? |
114 SkASSERT(swapRedAndBlue || kNone_PMConversion != pmConversion); | 113 SkASSERT(swapRedAndBlue || kNone_PMConversion != pmConversion); |
(...skipping 14 matching lines...) Expand all Loading... |
129 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect); | 128 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect); |
130 | 129 |
131 const GrFragmentProcessor* GrConfigConversionEffect::TestCreate(GrProcessorTestD
ata* d) { | 130 const GrFragmentProcessor* GrConfigConversionEffect::TestCreate(GrProcessorTestD
ata* d) { |
132 PMConversion pmConv = static_cast<PMConversion>(d->fRandom->nextULessThan(kP
MConversionCnt)); | 131 PMConversion pmConv = static_cast<PMConversion>(d->fRandom->nextULessThan(kP
MConversionCnt)); |
133 bool swapRB; | 132 bool swapRB; |
134 if (kNone_PMConversion == pmConv) { | 133 if (kNone_PMConversion == pmConv) { |
135 swapRB = true; | 134 swapRB = true; |
136 } else { | 135 } else { |
137 swapRB = d->fRandom->nextBool(); | 136 swapRB = d->fRandom->nextBool(); |
138 } | 137 } |
139 return new GrConfigConversionEffect(d->fProcDataManager, | 138 return new GrConfigConversionEffect(d->fTextures[GrProcessorUnitTest::kSkiaP
MTextureIdx], |
140 d->fTextures[GrProcessorUnitTest::kSkiaP
MTextureIdx], | |
141 swapRB, pmConv, GrTest::TestMatrix(d->fR
andom)); | 139 swapRB, pmConv, GrTest::TestMatrix(d->fR
andom)); |
142 } | 140 } |
143 | 141 |
144 /////////////////////////////////////////////////////////////////////////////// | 142 /////////////////////////////////////////////////////////////////////////////// |
145 | 143 |
146 void GrConfigConversionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 144 void GrConfigConversionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
147 GrProcessorKeyBuilder* b) const
{ | 145 GrProcessorKeyBuilder* b) const
{ |
148 GrGLConfigConversionEffect::GenKey(*this, caps, b); | 146 GrGLConfigConversionEffect::GenKey(*this, caps, b); |
149 } | 147 } |
150 | 148 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); | 208 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); |
211 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); | 209 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); |
212 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw | 210 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw |
213 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. | 211 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. |
214 // We then verify that two reads produced the same values. | 212 // We then verify that two reads produced the same values. |
215 | 213 |
216 GrPaint paint1; | 214 GrPaint paint1; |
217 GrPaint paint2; | 215 GrPaint paint2; |
218 GrPaint paint3; | 216 GrPaint paint3; |
219 SkAutoTUnref<GrFragmentProcessor> pmToUPM1(new GrConfigConversionEffect( | 217 SkAutoTUnref<GrFragmentProcessor> pmToUPM1(new GrConfigConversionEffect( |
220 paint1.getProcessorDataManager(), dataTex, false, *pmToUPMRule,
SkMatrix::I())); | 218 dataTex, false, *pmToUPMRule, SkMatrix::I())); |
221 SkAutoTUnref<GrFragmentProcessor> upmToPM(new GrConfigConversionEffect( | 219 SkAutoTUnref<GrFragmentProcessor> upmToPM(new GrConfigConversionEffect( |
222 paint2.getProcessorDataManager(), readTex, false, *upmToPMRule,
SkMatrix::I())); | 220 readTex, false, *upmToPMRule, SkMatrix::I())); |
223 SkAutoTUnref<GrFragmentProcessor> pmToUPM2(new GrConfigConversionEffect( | 221 SkAutoTUnref<GrFragmentProcessor> pmToUPM2(new GrConfigConversionEffect( |
224 paint3.getProcessorDataManager(), tempTex, false, *pmToUPMRule,
SkMatrix::I())); | 222 tempTex, false, *pmToUPMRule, SkMatrix::I())); |
225 | 223 |
226 paint1.addColorFragmentProcessor(pmToUPM1); | 224 paint1.addColorFragmentProcessor(pmToUPM1); |
227 | 225 |
228 | 226 |
229 SkAutoTUnref<GrDrawContext> readDrawContext(context->drawContext()); | 227 SkAutoTUnref<GrDrawContext> readDrawContext(context->drawContext()); |
230 if (!readDrawContext) { | 228 if (!readDrawContext) { |
231 failed = true; | 229 failed = true; |
232 break; | 230 break; |
233 } | 231 } |
234 | 232 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 } | 279 } |
282 } | 280 } |
283 } | 281 } |
284 } | 282 } |
285 if (failed) { | 283 if (failed) { |
286 *pmToUPMRule = kNone_PMConversion; | 284 *pmToUPMRule = kNone_PMConversion; |
287 *upmToPMRule = kNone_PMConversion; | 285 *upmToPMRule = kNone_PMConversion; |
288 } | 286 } |
289 } | 287 } |
290 | 288 |
291 const GrFragmentProcessor* GrConfigConversionEffect::Create(GrProcessorDataManag
er* procDataManager, | 289 const GrFragmentProcessor* GrConfigConversionEffect::Create(GrTexture* texture, |
292 GrTexture* texture, | |
293 bool swapRedAndBlue, | 290 bool swapRedAndBlue, |
294 PMConversion pmConve
rsion, | 291 PMConversion pmConve
rsion, |
295 const SkMatrix& matr
ix) { | 292 const SkMatrix& matr
ix) { |
296 if (!swapRedAndBlue && kNone_PMConversion == pmConversion) { | 293 if (!swapRedAndBlue && kNone_PMConversion == pmConversion) { |
297 // If we returned a GrConfigConversionEffect that was equivalent to a Gr
SimpleTextureEffect | 294 // If we returned a GrConfigConversionEffect that was equivalent to a Gr
SimpleTextureEffect |
298 // then we may pollute our texture cache with redundant shaders. So in t
he case that no | 295 // then we may pollute our texture cache with redundant shaders. So in t
he case that no |
299 // conversions were requested we instead return a GrSimpleTextureEffect. | 296 // conversions were requested we instead return a GrSimpleTextureEffect. |
300 return GrSimpleTextureEffect::Create(procDataManager, texture, matrix); | 297 return GrSimpleTextureEffect::Create(texture, matrix); |
301 } else { | 298 } else { |
302 if (kRGBA_8888_GrPixelConfig != texture->config() && | 299 if (kRGBA_8888_GrPixelConfig != texture->config() && |
303 kBGRA_8888_GrPixelConfig != texture->config() && | 300 kBGRA_8888_GrPixelConfig != texture->config() && |
304 kNone_PMConversion != pmConversion) { | 301 kNone_PMConversion != pmConversion) { |
305 // The PM conversions assume colors are 0..255 | 302 // The PM conversions assume colors are 0..255 |
306 return nullptr; | 303 return nullptr; |
307 } | 304 } |
308 return new GrConfigConversionEffect(procDataManager, texture, swapRedAnd
Blue, pmConversion, | 305 return new GrConfigConversionEffect(texture, swapRedAndBlue, pmConversio
n, matrix); |
309 matrix); | |
310 } | 306 } |
311 } | 307 } |
OLD | NEW |