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 "GrTBackendEffectFactory.h" | 10 #include "GrTBackendEffectFactory.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 GrContext*, | 122 GrContext*, |
123 const GrDrawTargetCaps&, | 123 const GrDrawTargetCaps&, |
124 GrTexture* textures[]) { | 124 GrTexture* textures[]) { |
125 PMConversion pmConv = static_cast<PMConversion>(random->nextULessThan(kPMCon versionCnt)); | 125 PMConversion pmConv = static_cast<PMConversion>(random->nextULessThan(kPMCon versionCnt)); |
126 bool swapRB; | 126 bool swapRB; |
127 if (kNone_PMConversion == pmConv) { | 127 if (kNone_PMConversion == pmConv) { |
128 swapRB = true; | 128 swapRB = true; |
129 } else { | 129 } else { |
130 swapRB = random->nextBool(); | 130 swapRB = random->nextBool(); |
131 } | 131 } |
132 AutoEffectUnref effect(SkNEW_ARGS(GrConfigConversionEffect, | 132 return SkNEW_ARGS(GrConfigConversionEffect, |
133 (textures[GrEffectUnitTest::kSkiaPMTexture Idx], | 133 (textures[GrEffectUnitTest::kSkiaPMTexture Idx], |
134 swapRB, | 134 swapRB, |
135 pmConv, | 135 pmConv, |
136 GrEffectUnitTest::TestMatrix(random)))); | 136 GrEffectUnitTest::TestMatrix(random))); |
137 return CreateEffectRef(effect); | |
138 } | 137 } |
139 | 138 |
140 /////////////////////////////////////////////////////////////////////////////// | 139 /////////////////////////////////////////////////////////////////////////////// |
141 void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context , | 140 void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context , |
142 PMConversion* pmTo UPMRule, | 141 PMConversion* pmTo UPMRule, |
143 PMConversion* upmT oPMRule) { | 142 PMConversion* upmT oPMRule) { |
144 *pmToUPMRule = kNone_PMConversion; | 143 *pmToUPMRule = kNone_PMConversion; |
145 *upmToPMRule = kNone_PMConversion; | 144 *upmToPMRule = kNone_PMConversion; |
146 SkAutoTMalloc<uint32_t> data(256 * 256 * 3); | 145 SkAutoTMalloc<uint32_t> data(256 * 256 * 3); |
147 uint32_t* srcData = data.get(); | 146 uint32_t* srcData = data.get(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) { | 192 for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) { |
194 *pmToUPMRule = kConversionRules[i][0]; | 193 *pmToUPMRule = kConversionRules[i][0]; |
195 *upmToPMRule = kConversionRules[i][1]; | 194 *upmToPMRule = kConversionRules[i][1]; |
196 | 195 |
197 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT oScalar(256)); | 196 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT oScalar(256)); |
198 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); | 197 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); |
199 // We do a PM->UPM draw from dataTex to readTex and read the data. Then we do a UPM->PM draw | 198 // We do a PM->UPM draw from dataTex to readTex and read the data. Then we do a UPM->PM draw |
200 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin ally read the data. | 199 // from readTex to tempTex followed by a PM->UPM draw to readTex and fin ally read the data. |
201 // We then verify that two reads produced the same values. | 200 // We then verify that two reads produced the same values. |
202 | 201 |
203 AutoEffectUnref pmToUPM1(SkNEW_ARGS(GrConfigConversionEffect, (dataTex, | 202 SkAutoTUnref<GrEffect> pmToUPM1(SkNEW_ARGS(GrConfigConversionEffect, (da taTex, |
robertphillips
2014/07/07 22:06:47
Move last 3 params right 1 ?
bsalomon
2014/07/08 13:54:30
Done.
| |
204 false, | 203 fal se, |
205 *pmToUPMR ule, | 204 *pm ToUPMRule, |
206 SkMatrix: :I()))); | 205 SkM atrix::I()))); |
207 AutoEffectUnref upmToPM(SkNEW_ARGS(GrConfigConversionEffect, (readTex, | 206 SkAutoTUnref<GrEffect> upmToPM(SkNEW_ARGS(GrConfigConversionEffect, (rea dTex, |
robertphillips
2014/07/07 22:06:47
same here ?
bsalomon
2014/07/08 13:54:30
Done.
| |
208 false, | 207 fals e, |
209 *upmToPMRu le, | 208 *upm ToPMRule, |
210 SkMatrix:: I()))); | 209 SkMa trix::I()))); |
211 AutoEffectUnref pmToUPM2(SkNEW_ARGS(GrConfigConversionEffect, (tempTex, | 210 SkAutoTUnref<GrEffect> pmToUPM2(SkNEW_ARGS(GrConfigConversionEffect, (te mpTex, |
212 false, | 211 fa lse, |
213 *pmToUPMR ule, | 212 *p mToUPMRule, |
214 SkMatrix: :I()))); | 213 Sk Matrix::I()))); |
215 | |
216 SkAutoTUnref<GrEffectRef> pmToUPMEffect1(CreateEffectRef(pmToUPM1)); | |
217 SkAutoTUnref<GrEffectRef> upmToPMEffect(CreateEffectRef(upmToPM)); | |
218 SkAutoTUnref<GrEffectRef> pmToUPMEffect2(CreateEffectRef(pmToUPM2)); | |
219 | 214 |
220 context->setRenderTarget(readTex->asRenderTarget()); | 215 context->setRenderTarget(readTex->asRenderTarget()); |
221 GrPaint paint1; | 216 GrPaint paint1; |
222 paint1.addColorEffect(pmToUPMEffect1); | 217 paint1.addColorEffect(pmToUPM1); |
223 context->drawRectToRect(paint1, kDstRect, kSrcRect); | 218 context->drawRectToRect(paint1, kDstRect, kSrcRect); |
224 | 219 |
225 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead) ; | 220 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead) ; |
226 | 221 |
227 context->setRenderTarget(tempTex->asRenderTarget()); | 222 context->setRenderTarget(tempTex->asRenderTarget()); |
228 GrPaint paint2; | 223 GrPaint paint2; |
229 paint2.addColorEffect(upmToPMEffect); | 224 paint2.addColorEffect(upmToPM); |
230 context->drawRectToRect(paint2, kDstRect, kSrcRect); | 225 context->drawRectToRect(paint2, kDstRect, kSrcRect); |
231 context->setRenderTarget(readTex->asRenderTarget()); | 226 context->setRenderTarget(readTex->asRenderTarget()); |
232 | 227 |
233 GrPaint paint3; | 228 GrPaint paint3; |
234 paint3.addColorEffect(pmToUPMEffect2); | 229 paint3.addColorEffect(pmToUPM2); |
235 context->drawRectToRect(paint3, kDstRect, kSrcRect); | 230 context->drawRectToRect(paint3, kDstRect, kSrcRect); |
236 | 231 |
237 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead ); | 232 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead ); |
238 | 233 |
239 failed = false; | 234 failed = false; |
240 for (int y = 0; y < 256 && !failed; ++y) { | 235 for (int y = 0; y < 256 && !failed; ++y) { |
241 for (int x = 0; x <= y; ++x) { | 236 for (int x = 0; x <= y; ++x) { |
242 if (firstRead[256 * y + x] != secondRead[256 * y + x]) { | 237 if (firstRead[256 * y + x] != secondRead[256 * y + x]) { |
243 failed = true; | 238 failed = true; |
244 break; | 239 break; |
(...skipping 16 matching lines...) Expand all Loading... | |
261 // then we may pollute our texture cache with redundant shaders. So in t he case that no | 256 // then we may pollute our texture cache with redundant shaders. So in t he case that no |
262 // conversions were requested we instead return a GrSimpleTextureEffect. | 257 // conversions were requested we instead return a GrSimpleTextureEffect. |
263 return GrSimpleTextureEffect::Create(texture, matrix); | 258 return GrSimpleTextureEffect::Create(texture, matrix); |
264 } else { | 259 } else { |
265 if (kRGBA_8888_GrPixelConfig != texture->config() && | 260 if (kRGBA_8888_GrPixelConfig != texture->config() && |
266 kBGRA_8888_GrPixelConfig != texture->config() && | 261 kBGRA_8888_GrPixelConfig != texture->config() && |
267 kNone_PMConversion != pmConversion) { | 262 kNone_PMConversion != pmConversion) { |
268 // The PM conversions assume colors are 0..255 | 263 // The PM conversions assume colors are 0..255 |
269 return NULL; | 264 return NULL; |
270 } | 265 } |
271 AutoEffectUnref effect(SkNEW_ARGS(GrConfigConversionEffect, (texture, | 266 return SkNEW_ARGS(GrConfigConversionEffect, (texture, |
272 swapRedAndB lue, | 267 swapRedAndBlue, |
273 pmConversio n, | 268 pmConversion, |
274 matrix))); | 269 matrix)); |
275 return CreateEffectRef(effect); | |
276 } | 270 } |
277 } | 271 } |
OLD | NEW |