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