| 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 "effects/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 GrPaint* grp, GrTexture* mask) { | 579 GrPaint* grp, GrTexture* mask) { |
| 580 GrContext::AutoMatrix am; | 580 GrContext::AutoMatrix am; |
| 581 if (!am.setIdentity(context, grp)) { | 581 if (!am.setIdentity(context, grp)) { |
| 582 return false; | 582 return false; |
| 583 } | 583 } |
| 584 | 584 |
| 585 SkMatrix matrix; | 585 SkMatrix matrix; |
| 586 matrix.setTranslate(-maskRect.fLeft, -maskRect.fTop); | 586 matrix.setTranslate(-maskRect.fLeft, -maskRect.fTop); |
| 587 matrix.postIDiv(mask->width(), mask->height()); | 587 matrix.postIDiv(mask->width(), mask->height()); |
| 588 | 588 |
| 589 grp->addCoverageEffect(GrSimpleTextureEffect::Create(mask, matrix))->unref()
; | 589 grp->addCoverageProcessor(GrSimpleTextureEffect::Create(mask, matrix))->unre
f(); |
| 590 context->drawRect(*grp, maskRect); | 590 context->drawRect(*grp, maskRect); |
| 591 return true; | 591 return true; |
| 592 } | 592 } |
| 593 | 593 |
| 594 bool draw_with_mask_filter(GrContext* context, const SkPath& devPath, | 594 bool draw_with_mask_filter(GrContext* context, const SkPath& devPath, |
| 595 SkMaskFilter* filter, const SkRegion& clip, | 595 SkMaskFilter* filter, const SkRegion& clip, |
| 596 GrPaint* grp, SkPaint::Style style) { | 596 GrPaint* grp, SkPaint::Style style) { |
| 597 SkMask srcM, dstM; | 597 SkMask srcM, dstM; |
| 598 | 598 |
| 599 if (!SkDraw::DrawToMask(devPath, &clip.getBounds(), filter, &context->getMat
rix(), &srcM, | 599 if (!SkDraw::DrawToMask(devPath, &clip.getBounds(), filter, &context->getMat
rix(), &srcM, |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; | 1299 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; |
| 1300 SkRect paintRect; | 1300 SkRect paintRect; |
| 1301 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); | 1301 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); |
| 1302 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); | 1302 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); |
| 1303 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), | 1303 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), |
| 1304 SkScalarMul(srcRect.fTop, hInv), | 1304 SkScalarMul(srcRect.fTop, hInv), |
| 1305 SkScalarMul(srcRect.fRight, wInv), | 1305 SkScalarMul(srcRect.fRight, wInv), |
| 1306 SkScalarMul(srcRect.fBottom, hInv)); | 1306 SkScalarMul(srcRect.fBottom, hInv)); |
| 1307 | 1307 |
| 1308 SkRect textureDomain = SkRect::MakeEmpty(); | 1308 SkRect textureDomain = SkRect::MakeEmpty(); |
| 1309 SkAutoTUnref<GrEffect> effect; | 1309 SkAutoTUnref<GrFragmentProcessor> fp; |
| 1310 if (needsTextureDomain && !(flags & SkCanvas::kBleed_DrawBitmapRectFlag)) { | 1310 if (needsTextureDomain && !(flags & SkCanvas::kBleed_DrawBitmapRectFlag)) { |
| 1311 // Use a constrained texture domain to avoid color bleeding | 1311 // Use a constrained texture domain to avoid color bleeding |
| 1312 SkScalar left, top, right, bottom; | 1312 SkScalar left, top, right, bottom; |
| 1313 if (srcRect.width() > SK_Scalar1) { | 1313 if (srcRect.width() > SK_Scalar1) { |
| 1314 SkScalar border = SK_ScalarHalf / texture->width(); | 1314 SkScalar border = SK_ScalarHalf / texture->width(); |
| 1315 left = paintRect.left() + border; | 1315 left = paintRect.left() + border; |
| 1316 right = paintRect.right() - border; | 1316 right = paintRect.right() - border; |
| 1317 } else { | 1317 } else { |
| 1318 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); | 1318 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); |
| 1319 } | 1319 } |
| 1320 if (srcRect.height() > SK_Scalar1) { | 1320 if (srcRect.height() > SK_Scalar1) { |
| 1321 SkScalar border = SK_ScalarHalf / texture->height(); | 1321 SkScalar border = SK_ScalarHalf / texture->height(); |
| 1322 top = paintRect.top() + border; | 1322 top = paintRect.top() + border; |
| 1323 bottom = paintRect.bottom() - border; | 1323 bottom = paintRect.bottom() - border; |
| 1324 } else { | 1324 } else { |
| 1325 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); | 1325 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); |
| 1326 } | 1326 } |
| 1327 textureDomain.setLTRB(left, top, right, bottom); | 1327 textureDomain.setLTRB(left, top, right, bottom); |
| 1328 if (bicubic) { | 1328 if (bicubic) { |
| 1329 effect.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), texture
Domain)); | 1329 fp.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), textureDoma
in)); |
| 1330 } else { | 1330 } else { |
| 1331 effect.reset(GrTextureDomainEffect::Create(texture, | 1331 fp.reset(GrTextureDomainEffect::Create(texture, |
| 1332 SkMatrix::I(), | 1332 SkMatrix::I(), |
| 1333 textureDomain, | 1333 textureDomain, |
| 1334 GrTextureDomain::kClamp_M
ode, | 1334 GrTextureDomain::kClamp_M
ode, |
| 1335 params.filterMode())); | 1335 params.filterMode())); |
| 1336 } | 1336 } |
| 1337 } else if (bicubic) { | 1337 } else if (bicubic) { |
| 1338 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); | 1338 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); |
| 1339 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil
eModeY() }; | 1339 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil
eModeY() }; |
| 1340 effect.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), tileModes))
; | 1340 fp.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), tileModes)); |
| 1341 } else { | 1341 } else { |
| 1342 effect.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), param
s)); | 1342 fp.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), params)); |
| 1343 } | 1343 } |
| 1344 | 1344 |
| 1345 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring | 1345 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring |
| 1346 // the rest from the SkPaint. | 1346 // the rest from the SkPaint. |
| 1347 GrPaint grPaint; | 1347 GrPaint grPaint; |
| 1348 grPaint.addColorEffect(effect); | 1348 grPaint.addColorProcessor(fp); |
| 1349 bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); | 1349 bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); |
| 1350 GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()
) : | 1350 GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()
) : |
| 1351 SkColor2GrColor(paint.getColor()); | 1351 SkColor2GrColor(paint.getColor()); |
| 1352 SkPaint2GrPaintNoShader(this->context(), paint, paintColor, false, &grPaint)
; | 1352 SkPaint2GrPaintNoShader(this->context(), paint, paintColor, false, &grPaint)
; |
| 1353 | 1353 |
| 1354 fContext->drawRectToRect(grPaint, dstRect, paintRect); | 1354 fContext->drawRectToRect(grPaint, dstRect, paintRect); |
| 1355 } | 1355 } |
| 1356 | 1356 |
| 1357 static bool filter_texture(SkBaseDevice* device, GrContext* context, | 1357 static bool filter_texture(SkBaseDevice* device, GrContext* context, |
| 1358 GrTexture* texture, const SkImageFilter* filter, | 1358 GrTexture* texture, const SkImageFilter* filter, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 w = filteredBitmap.width(); | 1407 w = filteredBitmap.width(); |
| 1408 h = filteredBitmap.height(); | 1408 h = filteredBitmap.height(); |
| 1409 left += offset.x(); | 1409 left += offset.x(); |
| 1410 top += offset.y(); | 1410 top += offset.y(); |
| 1411 } else { | 1411 } else { |
| 1412 return; | 1412 return; |
| 1413 } | 1413 } |
| 1414 } | 1414 } |
| 1415 | 1415 |
| 1416 GrPaint grPaint; | 1416 GrPaint grPaint; |
| 1417 grPaint.addColorTextureEffect(texture, SkMatrix::I()); | 1417 grPaint.addColorTextureProcessor(texture, SkMatrix::I()); |
| 1418 | 1418 |
| 1419 SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColorJustAlpha(pai
nt.getColor()), | 1419 SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColorJustAlpha(pai
nt.getColor()), |
| 1420 false, &grPaint); | 1420 false, &grPaint); |
| 1421 | 1421 |
| 1422 fContext->drawRectToRect(grPaint, | 1422 fContext->drawRectToRect(grPaint, |
| 1423 SkRect::MakeXYWH(SkIntToScalar(left), | 1423 SkRect::MakeXYWH(SkIntToScalar(left), |
| 1424 SkIntToScalar(top), | 1424 SkIntToScalar(top), |
| 1425 SkIntToScalar(w), | 1425 SkIntToScalar(w), |
| 1426 SkIntToScalar(h)), | 1426 SkIntToScalar(h)), |
| 1427 SkRect::MakeXYWH(0, | 1427 SkRect::MakeXYWH(0, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1518 w = filteredBitmap.width(); | 1518 w = filteredBitmap.width(); |
| 1519 h = filteredBitmap.height(); | 1519 h = filteredBitmap.height(); |
| 1520 x += offset.fX; | 1520 x += offset.fX; |
| 1521 y += offset.fY; | 1521 y += offset.fY; |
| 1522 } else { | 1522 } else { |
| 1523 return; | 1523 return; |
| 1524 } | 1524 } |
| 1525 } | 1525 } |
| 1526 | 1526 |
| 1527 GrPaint grPaint; | 1527 GrPaint grPaint; |
| 1528 grPaint.addColorTextureEffect(devTex, SkMatrix::I()); | 1528 grPaint.addColorTextureProcessor(devTex, SkMatrix::I()); |
| 1529 | 1529 |
| 1530 SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColorJustAlpha(pai
nt.getColor()), | 1530 SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColorJustAlpha(pai
nt.getColor()), |
| 1531 false, &grPaint); | 1531 false, &grPaint); |
| 1532 | 1532 |
| 1533 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), | 1533 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), |
| 1534 SkIntToScalar(y), | 1534 SkIntToScalar(y), |
| 1535 SkIntToScalar(w), | 1535 SkIntToScalar(w), |
| 1536 SkIntToScalar(h)); | 1536 SkIntToScalar(h)); |
| 1537 | 1537 |
| 1538 // The device being drawn may not fill up its texture (e.g. saveLayer uses a
pproximate | 1538 // The device being drawn may not fill up its texture (e.g. saveLayer uses a
pproximate |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1879 GrLayerHoister::UnlockLayers(fContext->getLayerCache(), picture); | 1879 GrLayerHoister::UnlockLayers(fContext->getLayerCache(), picture); |
| 1880 | 1880 |
| 1881 return true; | 1881 return true; |
| 1882 } | 1882 } |
| 1883 | 1883 |
| 1884 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1884 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1885 // We always return a transient cache, so it is freed after each | 1885 // We always return a transient cache, so it is freed after each |
| 1886 // filter traversal. | 1886 // filter traversal. |
| 1887 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1887 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 1888 } | 1888 } |
| OLD | NEW |