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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 void GrConfigConversionEffect::onComputeInvariantOutput(GrInvariantOutput* inout
) const { | 120 void GrConfigConversionEffect::onComputeInvariantOutput(GrInvariantOutput* inout
) const { |
121 this->updateInvariantOutputForModulation(inout); | 121 this->updateInvariantOutputForModulation(inout); |
122 } | 122 } |
123 | 123 |
124 /////////////////////////////////////////////////////////////////////////////// | 124 /////////////////////////////////////////////////////////////////////////////// |
125 | 125 |
126 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect); | 126 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect); |
127 | 127 |
128 const GrFragmentProcessor* GrConfigConversionEffect::TestCreate(GrProcessorTestD
ata* d) { | 128 sk_sp<GrFragmentProcessor> GrConfigConversionEffect::TestCreate(GrProcessorTestD
ata* d) { |
129 PMConversion pmConv = static_cast<PMConversion>(d->fRandom->nextULessThan(kP
MConversionCnt)); | 129 PMConversion pmConv = static_cast<PMConversion>(d->fRandom->nextULessThan(kP
MConversionCnt)); |
130 GrSwizzle swizzle; | 130 GrSwizzle swizzle; |
131 do { | 131 do { |
132 swizzle = GrSwizzle::CreateRandom(d->fRandom); | 132 swizzle = GrSwizzle::CreateRandom(d->fRandom); |
133 } while (pmConv == kNone_PMConversion && swizzle == GrSwizzle::RGBA()); | 133 } while (pmConv == kNone_PMConversion && swizzle == GrSwizzle::RGBA()); |
134 return new GrConfigConversionEffect(d->fTextures[GrProcessorUnitTest::kSkiaP
MTextureIdx], | 134 return sk_sp<GrFragmentProcessor>( |
135 swizzle, pmConv, GrTest::TestMatrix(d->f
Random)); | 135 new GrConfigConversionEffect(d->fTextures[GrProcessorUnitTest::kSkiaPMTe
xtureIdx], |
| 136 swizzle, pmConv, GrTest::TestMatrix(d->fRan
dom))); |
136 } | 137 } |
137 | 138 |
138 /////////////////////////////////////////////////////////////////////////////// | 139 /////////////////////////////////////////////////////////////////////////////// |
139 | 140 |
140 void GrConfigConversionEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, | 141 void GrConfigConversionEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, |
141 GrProcessorKeyBuilder* b) c
onst { | 142 GrProcessorKeyBuilder* b) c
onst { |
142 GrGLConfigConversionEffect::GenKey(*this, caps, b); | 143 GrGLConfigConversionEffect::GenKey(*this, caps, b); |
143 } | 144 } |
144 | 145 |
145 GrGLSLFragmentProcessor* GrConfigConversionEffect::onCreateGLSLInstance() const
{ | 146 GrGLSLFragmentProcessor* GrConfigConversionEffect::onCreateGLSLInstance() const
{ |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 208 |
208 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); | 209 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT
oScalar(256)); |
209 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); | 210 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); |
210 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw | 211 // We do a PM->UPM draw from dataTex to readTex and read the data. Then
we do a UPM->PM draw |
211 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. | 212 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin
ally read the data. |
212 // We then verify that two reads produced the same values. | 213 // We then verify that two reads produced the same values. |
213 | 214 |
214 GrPaint paint1; | 215 GrPaint paint1; |
215 GrPaint paint2; | 216 GrPaint paint2; |
216 GrPaint paint3; | 217 GrPaint paint3; |
217 SkAutoTUnref<GrFragmentProcessor> pmToUPM1(new GrConfigConversionEffect( | 218 sk_sp<GrFragmentProcessor> pmToUPM1(new GrConfigConversionEffect( |
218 dataTex, GrSwizzle::RGBA(), *pmToUPMRule, SkMatrix::I())); | 219 dataTex, GrSwizzle::RGBA(), *pmToUPMRule, SkMatrix::I())); |
219 SkAutoTUnref<GrFragmentProcessor> upmToPM(new GrConfigConversionEffect( | 220 sk_sp<GrFragmentProcessor> upmToPM(new GrConfigConversionEffect( |
220 readTex, GrSwizzle::RGBA(), *upmToPMRule, SkMatrix::I())); | 221 readTex, GrSwizzle::RGBA(), *upmToPMRule, SkMatrix::I())); |
221 SkAutoTUnref<GrFragmentProcessor> pmToUPM2(new GrConfigConversionEffect( | 222 sk_sp<GrFragmentProcessor> pmToUPM2(new GrConfigConversionEffect( |
222 tempTex, GrSwizzle::RGBA(), *pmToUPMRule, SkMatrix::I())); | 223 tempTex, GrSwizzle::RGBA(), *pmToUPMRule, SkMatrix::I())); |
223 | 224 |
224 paint1.addColorFragmentProcessor(pmToUPM1); | 225 paint1.addColorFragmentProcessor(std::move(pmToUPM1)); |
225 paint1.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 226 paint1.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
226 | 227 |
227 | |
228 sk_sp<GrDrawContext> readDrawContext( | 228 sk_sp<GrDrawContext> readDrawContext( |
229 context->drawContext(sk_ref_sp(readTex->asRe
nderTarget()))); | 229 context->drawContext(sk_ref_sp(readTex->asRe
nderTarget()))); |
230 if (!readDrawContext) { | 230 if (!readDrawContext) { |
231 failed = true; | 231 failed = true; |
232 break; | 232 break; |
233 } | 233 } |
234 | 234 |
235 readDrawContext->fillRectToRect(GrNoClip(), | 235 readDrawContext->fillRectToRect(GrNoClip(), |
236 paint1, | 236 paint1, |
237 SkMatrix::I(), | 237 SkMatrix::I(), |
238 kDstRect, | 238 kDstRect, |
239 kSrcRect); | 239 kSrcRect); |
240 | 240 |
241 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead)
; | 241 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead)
; |
242 | 242 |
243 paint2.addColorFragmentProcessor(upmToPM); | 243 paint2.addColorFragmentProcessor(std::move(upmToPM)); |
244 paint2.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 244 paint2.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
245 | 245 |
246 sk_sp<GrDrawContext> tempDrawContext( | 246 sk_sp<GrDrawContext> tempDrawContext( |
247 context->drawContext(sk_ref_sp(tempTex->asRe
nderTarget()))); | 247 context->drawContext(sk_ref_sp(tempTex->asRe
nderTarget()))); |
248 if (!tempDrawContext) { | 248 if (!tempDrawContext) { |
249 failed = true; | 249 failed = true; |
250 break; | 250 break; |
251 } | 251 } |
252 tempDrawContext->fillRectToRect(GrNoClip(), | 252 tempDrawContext->fillRectToRect(GrNoClip(), |
253 paint2, | 253 paint2, |
254 SkMatrix::I(), | 254 SkMatrix::I(), |
255 kDstRect, | 255 kDstRect, |
256 kSrcRect); | 256 kSrcRect); |
257 | 257 |
258 paint3.addColorFragmentProcessor(pmToUPM2); | 258 paint3.addColorFragmentProcessor(std::move(pmToUPM2)); |
259 paint3.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 259 paint3.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
260 | 260 |
261 readDrawContext = context->drawContext(sk_ref_sp(readTex->asRenderTarget
())); | 261 readDrawContext = context->drawContext(sk_ref_sp(readTex->asRenderTarget
())); |
262 if (!readDrawContext) { | 262 if (!readDrawContext) { |
263 failed = true; | 263 failed = true; |
264 break; | 264 break; |
265 } | 265 } |
266 | 266 |
267 readDrawContext->fillRectToRect(GrNoClip(), | 267 readDrawContext->fillRectToRect(GrNoClip(), |
268 paint3, | 268 paint3, |
(...skipping 12 matching lines...) Expand all Loading... |
281 } | 281 } |
282 } | 282 } |
283 } | 283 } |
284 } | 284 } |
285 if (failed) { | 285 if (failed) { |
286 *pmToUPMRule = kNone_PMConversion; | 286 *pmToUPMRule = kNone_PMConversion; |
287 *upmToPMRule = kNone_PMConversion; | 287 *upmToPMRule = kNone_PMConversion; |
288 } | 288 } |
289 } | 289 } |
290 | 290 |
291 const GrFragmentProcessor* GrConfigConversionEffect::Create(GrTexture* texture, | 291 sk_sp<GrFragmentProcessor> GrConfigConversionEffect::Make(GrTexture* texture, |
292 const GrSwizzle& swi
zzle, | 292 const GrSwizzle& swizz
le, |
293 PMConversion pmConve
rsion, | 293 PMConversion pmConvers
ion, |
294 const SkMatrix& matr
ix) { | 294 const SkMatrix& matrix
) { |
295 if (swizzle == GrSwizzle::RGBA() && kNone_PMConversion == pmConversion) { | 295 if (swizzle == GrSwizzle::RGBA() && kNone_PMConversion == pmConversion) { |
296 // If we returned a GrConfigConversionEffect that was equivalent to a Gr
SimpleTextureEffect | 296 // If we returned a GrConfigConversionEffect that was equivalent to a Gr
SimpleTextureEffect |
297 // then we may pollute our texture cache with redundant shaders. So in t
he case that no | 297 // then we may pollute our texture cache with redundant shaders. So in t
he case that no |
298 // conversions were requested we instead return a GrSimpleTextureEffect. | 298 // conversions were requested we instead return a GrSimpleTextureEffect. |
299 return GrSimpleTextureEffect::Create(texture, matrix); | 299 return GrSimpleTextureEffect::Make(texture, matrix); |
300 } else { | 300 } else { |
301 if (kRGBA_8888_GrPixelConfig != texture->config() && | 301 if (kRGBA_8888_GrPixelConfig != texture->config() && |
302 kBGRA_8888_GrPixelConfig != texture->config() && | 302 kBGRA_8888_GrPixelConfig != texture->config() && |
303 kNone_PMConversion != pmConversion) { | 303 kNone_PMConversion != pmConversion) { |
304 // The PM conversions assume colors are 0..255 | 304 // The PM conversions assume colors are 0..255 |
305 return nullptr; | 305 return nullptr; |
306 } | 306 } |
307 return new GrConfigConversionEffect(texture, swizzle, pmConversion, matr
ix); | 307 return sk_sp<GrFragmentProcessor>( |
| 308 new GrConfigConversionEffect(texture, swizzle, pmConversion, matrix)
); |
308 } | 309 } |
309 } | 310 } |
OLD | NEW |