Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: src/gpu/effects/GrConfigConversionEffect.cpp

Issue 939623005: Pass Rendertarget into context (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: sampleapp Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GrInvariantOutput.h" 10 #include "GrInvariantOutput.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 SkAutoTUnref<GrTexture> dataTex(context->createTexture(desc, true, data, 0)) ; 199 SkAutoTUnref<GrTexture> dataTex(context->createTexture(desc, true, data, 0)) ;
200 if (!dataTex.get()) { 200 if (!dataTex.get()) {
201 return; 201 return;
202 } 202 }
203 203
204 static const PMConversion kConversionRules[][2] = { 204 static const PMConversion kConversionRules[][2] = {
205 {kDivByAlpha_RoundDown_PMConversion, kMulByAlpha_RoundUp_PMConversion}, 205 {kDivByAlpha_RoundDown_PMConversion, kMulByAlpha_RoundUp_PMConversion},
206 {kDivByAlpha_RoundUp_PMConversion, kMulByAlpha_RoundDown_PMConversion}, 206 {kDivByAlpha_RoundUp_PMConversion, kMulByAlpha_RoundDown_PMConversion},
207 }; 207 };
208 208
209 GrContext::AutoWideOpenIdentityDraw awoid(context, NULL); 209 GrContext::AutoWideOpenIdentityDraw awoid(context);
210 210
211 bool failed = true; 211 bool failed = true;
212 212
213 for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) { 213 for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) {
214 *pmToUPMRule = kConversionRules[i][0]; 214 *pmToUPMRule = kConversionRules[i][0];
215 *upmToPMRule = kConversionRules[i][1]; 215 *upmToPMRule = kConversionRules[i][1];
216 216
217 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT oScalar(256)); 217 static const SkRect kDstRect = SkRect::MakeWH(SkIntToScalar(256), SkIntT oScalar(256));
218 static const SkRect kSrcRect = SkRect::MakeWH(SK_Scalar1, SK_Scalar1); 218 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 219 // 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. 220 // 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. 221 // We then verify that two reads produced the same values.
222 222
223 SkAutoTUnref<GrFragmentProcessor> pmToUPM1( 223 SkAutoTUnref<GrFragmentProcessor> pmToUPM1(
224 SkNEW_ARGS(GrConfigConversionEffect, 224 SkNEW_ARGS(GrConfigConversionEffect,
225 (dataTex, false, *pmToUPMRule, SkMatrix::I()))); 225 (dataTex, false, *pmToUPMRule, SkMatrix::I())));
226 SkAutoTUnref<GrFragmentProcessor> upmToPM( 226 SkAutoTUnref<GrFragmentProcessor> upmToPM(
227 SkNEW_ARGS(GrConfigConversionEffect, 227 SkNEW_ARGS(GrConfigConversionEffect,
228 (readTex, false, *upmToPMRule, SkMatrix::I()))); 228 (readTex, false, *upmToPMRule, SkMatrix::I())));
229 SkAutoTUnref<GrFragmentProcessor> pmToUPM2( 229 SkAutoTUnref<GrFragmentProcessor> pmToUPM2(
230 SkNEW_ARGS(GrConfigConversionEffect, 230 SkNEW_ARGS(GrConfigConversionEffect,
231 (tempTex, false, *pmToUPMRule, SkMatrix::I()))); 231 (tempTex, false, *pmToUPMRule, SkMatrix::I())));
232 232
233 context->setRenderTarget(readTex->asRenderTarget());
234 GrPaint paint1; 233 GrPaint paint1;
235 paint1.addColorProcessor(pmToUPM1); 234 paint1.addColorProcessor(pmToUPM1);
236 context->drawNonAARectToRect(paint1, SkMatrix::I(), kDstRect, kSrcRect); 235 context->drawNonAARectToRect(readTex->asRenderTarget(), paint1, SkMatrix ::I(), kDstRect,
236 kSrcRect);
237 237
238 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead) ; 238 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead) ;
239 239
240 context->setRenderTarget(tempTex->asRenderTarget());
241 GrPaint paint2; 240 GrPaint paint2;
242 paint2.addColorProcessor(upmToPM); 241 paint2.addColorProcessor(upmToPM);
243 context->drawNonAARectToRect(paint2, SkMatrix::I(), kDstRect, kSrcRect); 242 context->drawNonAARectToRect(tempTex->asRenderTarget(), paint2, SkMatrix ::I(), kDstRect,
244 context->setRenderTarget(readTex->asRenderTarget()); 243 kSrcRect);
245 244
246 GrPaint paint3; 245 GrPaint paint3;
247 paint3.addColorProcessor(pmToUPM2); 246 paint3.addColorProcessor(pmToUPM2);
248 context->drawNonAARectToRect(paint3, SkMatrix::I(), kDstRect, kSrcRect); 247 context->drawNonAARectToRect(readTex->asRenderTarget(), paint3, SkMatrix ::I(), kDstRect,
248 kSrcRect);
249 249
250 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead ); 250 readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead );
251 251
252 failed = false; 252 failed = false;
253 for (int y = 0; y < 256 && !failed; ++y) { 253 for (int y = 0; y < 256 && !failed; ++y) {
254 for (int x = 0; x <= y; ++x) { 254 for (int x = 0; x <= y; ++x) {
255 if (firstRead[256 * y + x] != secondRead[256 * y + x]) { 255 if (firstRead[256 * y + x] != secondRead[256 * y + x]) {
256 failed = true; 256 failed = true;
257 break; 257 break;
258 } 258 }
(...skipping 21 matching lines...) Expand all
280 kNone_PMConversion != pmConversion) { 280 kNone_PMConversion != pmConversion) {
281 // The PM conversions assume colors are 0..255 281 // The PM conversions assume colors are 0..255
282 return NULL; 282 return NULL;
283 } 283 }
284 return SkNEW_ARGS(GrConfigConversionEffect, (texture, 284 return SkNEW_ARGS(GrConfigConversionEffect, (texture,
285 swapRedAndBlue, 285 swapRedAndBlue,
286 pmConversion, 286 pmConversion,
287 matrix)); 287 matrix));
288 } 288 }
289 } 289 }
OLDNEW
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698