OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
9 | 9 |
10 #include "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1294 | 1294 |
1295 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; | 1295 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; |
1296 SkRect paintRect; | 1296 SkRect paintRect; |
1297 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); | 1297 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); |
1298 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); | 1298 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); |
1299 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), | 1299 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), |
1300 SkScalarMul(srcRect.fTop, hInv), | 1300 SkScalarMul(srcRect.fTop, hInv), |
1301 SkScalarMul(srcRect.fRight, wInv), | 1301 SkScalarMul(srcRect.fRight, wInv), |
1302 SkScalarMul(srcRect.fBottom, hInv)); | 1302 SkScalarMul(srcRect.fBottom, hInv)); |
1303 | 1303 |
1304 SkMatrix texMatrix; | |
1305 texMatrix.reset(); | |
1306 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) { | |
bsalomon
2015/10/09 17:07:09
Could use a comment here
egdaniel
2015/10/09 17:20:26
Done.
| |
1307 texMatrix.setScale(wInv, hInv); | |
1308 } | |
1309 | |
1304 SkRect textureDomain = SkRect::MakeEmpty(); | 1310 SkRect textureDomain = SkRect::MakeEmpty(); |
1305 | 1311 |
1306 // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring | 1312 // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring |
1307 // the rest from the SkPaint. | 1313 // the rest from the SkPaint. |
1308 GrPaint grPaint; | 1314 GrPaint grPaint; |
1309 SkAutoTUnref<const GrFragmentProcessor> fp; | 1315 SkAutoTUnref<const GrFragmentProcessor> fp; |
1310 | 1316 |
1311 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint )) { | 1317 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint )) { |
1312 // Use a constrained texture domain to avoid color bleeding | 1318 // Use a constrained texture domain to avoid color bleeding |
1313 SkScalar left, top, right, bottom; | 1319 SkScalar left, top, right, bottom; |
1314 if (srcRect.width() > SK_Scalar1) { | 1320 if (srcRect.width() > SK_Scalar1) { |
1315 SkScalar border = SK_ScalarHalf / texture->width(); | 1321 SkScalar border = SK_ScalarHalf / texture->width(); |
1316 left = paintRect.left() + border; | 1322 left = paintRect.left() + border; |
1317 right = paintRect.right() - border; | 1323 right = paintRect.right() - border; |
1318 } else { | 1324 } else { |
1319 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); | 1325 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); |
1320 } | 1326 } |
1321 if (srcRect.height() > SK_Scalar1) { | 1327 if (srcRect.height() > SK_Scalar1) { |
1322 SkScalar border = SK_ScalarHalf / texture->height(); | 1328 SkScalar border = SK_ScalarHalf / texture->height(); |
1323 top = paintRect.top() + border; | 1329 top = paintRect.top() + border; |
1324 bottom = paintRect.bottom() - border; | 1330 bottom = paintRect.bottom() - border; |
1325 } else { | 1331 } else { |
1326 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); | 1332 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); |
1327 } | 1333 } |
1328 textureDomain.setLTRB(left, top, right, bottom); | 1334 textureDomain.setLTRB(left, top, right, bottom); |
1329 if (bicubic) { | 1335 if (bicubic) { |
1330 fp.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), textureDoma in)); | 1336 fp.reset(GrBicubicEffect::Create(texture, texMatrix, textureDomain)) ; |
1331 } else { | 1337 } else { |
1332 fp.reset(GrTextureDomainEffect::Create(texture, | 1338 fp.reset(GrTextureDomainEffect::Create(texture, |
1333 SkMatrix::I(), | 1339 texMatrix, |
1334 textureDomain, | 1340 textureDomain, |
1335 GrTextureDomain::kClamp_Mode, | 1341 GrTextureDomain::kClamp_Mode, |
1336 params.filterMode())); | 1342 params.filterMode())); |
1337 } | 1343 } |
1338 } else if (bicubic) { | 1344 } else if (bicubic) { |
1339 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); | 1345 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); |
1340 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil eModeY() }; | 1346 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil eModeY() }; |
1341 fp.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), tileModes)); | 1347 fp.reset(GrBicubicEffect::Create(texture, texMatrix, tileModes)); |
1342 } else { | 1348 } else { |
1343 fp.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), params)); | 1349 fp.reset(GrSimpleTextureEffect::Create(texture, texMatrix, params)); |
1344 } | 1350 } |
1345 | 1351 |
1352 SkAutoTUnref<const GrFragmentProcessor> shaderFP; | |
1353 | |
1346 if (kAlpha_8_SkColorType == bitmap.colorType()) { | 1354 if (kAlpha_8_SkColorType == bitmap.colorType()) { |
1347 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); | 1355 if (const SkShader* shader = paint.getShader()) { |
1356 shaderFP.reset(shader->asFragmentProcessor(this->context(), | |
1357 viewMatrix, | |
1358 nullptr, | |
1359 paint.getFilterQuality()) ); | |
1360 const GrFragmentProcessor* fpSeries[] = { shaderFP.get(), fp.get() } ; | |
bsalomon
2015/10/09 17:07:09
if (!shaderFP) { return }
egdaniel
2015/10/09 17:20:26
Done.
| |
1361 fp.reset(GrFragmentProcessor::RunInSeries(fpSeries, 2)); | |
1362 } else { | |
1363 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); | |
1364 } | |
1348 } else { | 1365 } else { |
1349 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); | 1366 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); |
1350 } | 1367 } |
1351 | 1368 |
1352 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) { | 1369 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) { |
1353 return; | 1370 return; |
1354 } | 1371 } |
1355 | 1372 |
1356 fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix, dstRect, | 1373 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) { |
1357 paintRect); | 1374 fDrawContext->drawRect(fRenderTarget, fClip, grPaint, viewMatrix, dstRec t); |
1375 } else { | |
1376 fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMat rix, dstRect, | |
1377 paintRect); | |
1378 } | |
1358 } | 1379 } |
1359 | 1380 |
1360 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, | 1381 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, |
1361 int width, int height, | 1382 int width, int height, |
1362 const SkImageFilter* filter, | 1383 const SkImageFilter* filter, |
1363 const SkImageFilter::Context& ctx, | 1384 const SkImageFilter::Context& ctx, |
1364 SkBitmap* result, SkIPoint* offset) { | 1385 SkBitmap* result, SkIPoint* offset) { |
1365 SkASSERT(filter); | 1386 SkASSERT(filter); |
1366 | 1387 |
1367 SkImageFilter::Proxy proxy(this); | 1388 SkImageFilter::Proxy proxy(this); |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1994 #endif | 2015 #endif |
1995 } | 2016 } |
1996 | 2017 |
1997 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2018 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1998 // We always return a transient cache, so it is freed after each | 2019 // We always return a transient cache, so it is freed after each |
1999 // filter traversal. | 2020 // filter traversal. |
2000 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2021 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
2001 } | 2022 } |
2002 | 2023 |
2003 #endif | 2024 #endif |
OLD | NEW |