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

Side by Side Diff: src/effects/gradients/SkGradientShader.cpp

Issue 2332213007: Bundle common arguments to GrGradientEffect creation (Closed)
Patch Set: Fix non-GPU compile errors Created 4 years, 3 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 | « no previous file | src/effects/gradients/SkGradientShaderPriv.h » ('j') | 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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "Sk4fLinearGradient.h" 8 #include "Sk4fLinearGradient.h"
9 #include "SkGradientShaderPriv.h" 9 #include "SkGradientShaderPriv.h"
10 #include "SkLinearGradient.h" 10 #include "SkLinearGradient.h"
(...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 fragBuilder->appendTextureLookupAndModulate(inputColor, texSamplers[ 0], "coord"); 1325 fragBuilder->appendTextureLookupAndModulate(inputColor, texSamplers[ 0], "coord");
1326 fragBuilder->codeAppend(";"); 1326 fragBuilder->codeAppend(";");
1327 1327
1328 break; 1328 break;
1329 } 1329 }
1330 } 1330 }
1331 } 1331 }
1332 1332
1333 ///////////////////////////////////////////////////////////////////// 1333 /////////////////////////////////////////////////////////////////////
1334 1334
1335 GrGradientEffect::GrGradientEffect(GrContext* ctx, 1335 GrGradientEffect::GrGradientEffect(const CreateArgs& args) {
1336 const SkGradientShaderBase& shader, 1336 const SkGradientShaderBase& shader(*args.fShader);
1337 const SkMatrix& matrix,
1338 SkShader::TileMode tileMode) {
1339 1337
1340 fIsOpaque = shader.isOpaque(); 1338 fIsOpaque = shader.isOpaque();
1341 1339
1342 fColorType = this->determineColorType(shader); 1340 fColorType = this->determineColorType(shader);
1343 1341
1344 if (kTexture_ColorType != fColorType) { 1342 if (kTexture_ColorType != fColorType) {
1345 if (shader.fOrigColors) { 1343 if (shader.fOrigColors) {
1346 fColors = SkTDArray<SkColor>(shader.fOrigColors, shader.fColorCount) ; 1344 fColors = SkTDArray<SkColor>(shader.fOrigColors, shader.fColorCount) ;
1347 } 1345 }
1348 1346
1349 #if GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS 1347 #if GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS
1350 if (shader.fOrigPos) { 1348 if (shader.fOrigPos) {
1351 fPositions = SkTDArray<SkScalar>(shader.fOrigPos, shader.fColorCount ); 1349 fPositions = SkTDArray<SkScalar>(shader.fOrigPos, shader.fColorCount );
1352 } 1350 }
1353 #endif 1351 #endif
1354 } 1352 }
1355 1353
1356 #if GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS 1354 #if GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS
1357 fTileMode = tileMode; 1355 fTileMode = args.fTileMode;
1358 #endif 1356 #endif
1359 1357
1360 switch (fColorType) { 1358 switch (fColorType) {
1361 // The two and three color specializations do not currently support tili ng. 1359 // The two and three color specializations do not currently support tili ng.
1362 case kTwo_ColorType: 1360 case kTwo_ColorType:
1363 case kThree_ColorType: 1361 case kThree_ColorType:
1364 #if GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS 1362 #if GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS
1365 case kHardStopLeftEdged_ColorType: 1363 case kHardStopLeftEdged_ColorType:
1366 case kHardStopRightEdged_ColorType: 1364 case kHardStopRightEdged_ColorType:
1367 case kHardStopCentered_ColorType: 1365 case kHardStopCentered_ColorType:
1368 #endif 1366 #endif
1369 fRow = -1; 1367 fRow = -1;
1370 1368
1371 if (SkGradientShader::kInterpolateColorsInPremul_Flag & shader.getGr adFlags()) { 1369 if (SkGradientShader::kInterpolateColorsInPremul_Flag & shader.getGr adFlags()) {
1372 fPremulType = kBeforeInterp_PremulType; 1370 fPremulType = kBeforeInterp_PremulType;
1373 } else { 1371 } else {
1374 fPremulType = kAfterInterp_PremulType; 1372 fPremulType = kAfterInterp_PremulType;
1375 } 1373 }
1376 1374
1377 fCoordTransform.reset(kCoordSet, matrix); 1375 fCoordTransform.reset(kCoordSet, *args.fMatrix);
1378 1376
1379 break; 1377 break;
1380 case kTexture_ColorType: 1378 case kTexture_ColorType:
1381 // doesn't matter how this is set, just be consistent because it is part of the 1379 // doesn't matter how this is set, just be consistent because it is part of the
1382 // effect key. 1380 // effect key.
1383 fPremulType = kBeforeInterp_PremulType; 1381 fPremulType = kBeforeInterp_PremulType;
1384 1382
1385 SkBitmap bitmap; 1383 SkBitmap bitmap;
1386 shader.getGradientTableBitmap(&bitmap); 1384 shader.getGradientTableBitmap(&bitmap);
1387 1385
1388 GrTextureStripAtlas::Desc desc; 1386 GrTextureStripAtlas::Desc desc;
1389 desc.fWidth = bitmap.width(); 1387 desc.fWidth = bitmap.width();
1390 desc.fHeight = 32; 1388 desc.fHeight = 32;
1391 desc.fRowHeight = bitmap.height(); 1389 desc.fRowHeight = bitmap.height();
1392 desc.fContext = ctx; 1390 desc.fContext = args.fContext;
1393 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap.info(), *ctx->caps() ); 1391 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap.info(), *args.fConte xt->caps());
1394 fAtlas = GrTextureStripAtlas::GetAtlas(desc); 1392 fAtlas = GrTextureStripAtlas::GetAtlas(desc);
1395 SkASSERT(fAtlas); 1393 SkASSERT(fAtlas);
1396 1394
1397 // We always filter the gradient table. Each table is one row of a t exture, always 1395 // We always filter the gradient table. Each table is one row of a t exture, always
1398 // y-clamp. 1396 // y-clamp.
1399 GrTextureParams params; 1397 GrTextureParams params;
1400 params.setFilterMode(GrTextureParams::kBilerp_FilterMode); 1398 params.setFilterMode(GrTextureParams::kBilerp_FilterMode);
1401 params.setTileModeX(tileMode); 1399 params.setTileModeX(args.fTileMode);
1402 1400
1403 fRow = fAtlas->lockRow(bitmap); 1401 fRow = fAtlas->lockRow(bitmap);
1404 if (-1 != fRow) { 1402 if (-1 != fRow) {
1405 fYCoord = fAtlas->getYOffset(fRow)+SK_ScalarHalf*fAtlas->getNorm alizedTexelHeight(); 1403 fYCoord = fAtlas->getYOffset(fRow)+SK_ScalarHalf*fAtlas->getNorm alizedTexelHeight();
1406 fCoordTransform.reset(kCoordSet, matrix, fAtlas->getTexture(), p arams.filterMode()); 1404 fCoordTransform.reset(kCoordSet, *args.fMatrix, fAtlas->getTextu re(),
1405 params.filterMode());
1407 fTextureAccess.reset(fAtlas->getTexture(), params); 1406 fTextureAccess.reset(fAtlas->getTexture(), params);
1408 } else { 1407 } else {
1409 SkAutoTUnref<GrTexture> texture( 1408 SkAutoTUnref<GrTexture> texture(
1410 GrRefCachedBitmapTexture(ctx, bitmap, params, 1409 GrRefCachedBitmapTexture(args.fContext, bitmap, params,
1411 SkSourceGammaTreatment::kRespect)); 1410 SkSourceGammaTreatment::kRespect));
1412 if (!texture) { 1411 if (!texture) {
1413 return; 1412 return;
1414 } 1413 }
1415 fCoordTransform.reset(kCoordSet, matrix, texture, params.filterM ode()); 1414 fCoordTransform.reset(kCoordSet, *args.fMatrix, texture, params. filterMode());
1416 fTextureAccess.reset(texture, params); 1415 fTextureAccess.reset(texture, params);
1417 fYCoord = SK_ScalarHalf; 1416 fYCoord = SK_ScalarHalf;
1418 } 1417 }
1419 1418
1420 this->addTextureAccess(&fTextureAccess); 1419 this->addTextureAccess(&fTextureAccess);
1421 1420
1422 break; 1421 break;
1423 } 1422 }
1424 1423
1425 this->addCoordTransform(&fCoordTransform); 1424 this->addCoordTransform(&fCoordTransform);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 (*stops)[i] = stop; 1484 (*stops)[i] = stop;
1486 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; 1485 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f;
1487 } 1486 }
1488 } 1487 }
1489 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); 1488 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount));
1490 1489
1491 return outColors; 1490 return outColors;
1492 } 1491 }
1493 1492
1494 #endif 1493 #endif
OLDNEW
« no previous file with comments | « no previous file | src/effects/gradients/SkGradientShaderPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698