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 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 // local coords with the bitmap draw since it may mess up texture look u
ps for the shader. | 1191 // local coords with the bitmap draw since it may mess up texture look u
ps for the shader. |
1192 // Thus we need to pass in the transform matrix directly to the texture
processor used for | 1192 // Thus we need to pass in the transform matrix directly to the texture
processor used for |
1193 // the bitmap draw. | 1193 // the bitmap draw. |
1194 texMatrix.setScale(wInv, hInv); | 1194 texMatrix.setScale(wInv, hInv); |
1195 } | 1195 } |
1196 | 1196 |
1197 SkRect textureDomain = SkRect::MakeEmpty(); | 1197 SkRect textureDomain = SkRect::MakeEmpty(); |
1198 | 1198 |
1199 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring | 1199 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring |
1200 // the rest from the SkPaint. | 1200 // the rest from the SkPaint. |
1201 SkAutoTUnref<const GrFragmentProcessor> fp; | 1201 sk_sp<GrFragmentProcessor> fp; |
1202 | 1202 |
1203 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint
)) { | 1203 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint
)) { |
1204 // Use a constrained texture domain to avoid color bleeding | 1204 // Use a constrained texture domain to avoid color bleeding |
1205 SkScalar left, top, right, bottom; | 1205 SkScalar left, top, right, bottom; |
1206 if (srcRect.width() > SK_Scalar1) { | 1206 if (srcRect.width() > SK_Scalar1) { |
1207 SkScalar border = SK_ScalarHalf / texture->width(); | 1207 SkScalar border = SK_ScalarHalf / texture->width(); |
1208 left = paintRect.left() + border; | 1208 left = paintRect.left() + border; |
1209 right = paintRect.right() - border; | 1209 right = paintRect.right() - border; |
1210 } else { | 1210 } else { |
1211 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); | 1211 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); |
1212 } | 1212 } |
1213 if (srcRect.height() > SK_Scalar1) { | 1213 if (srcRect.height() > SK_Scalar1) { |
1214 SkScalar border = SK_ScalarHalf / texture->height(); | 1214 SkScalar border = SK_ScalarHalf / texture->height(); |
1215 top = paintRect.top() + border; | 1215 top = paintRect.top() + border; |
1216 bottom = paintRect.bottom() - border; | 1216 bottom = paintRect.bottom() - border; |
1217 } else { | 1217 } else { |
1218 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); | 1218 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); |
1219 } | 1219 } |
1220 textureDomain.setLTRB(left, top, right, bottom); | 1220 textureDomain.setLTRB(left, top, right, bottom); |
1221 if (bicubic) { | 1221 if (bicubic) { |
1222 fp.reset(GrBicubicEffect::Create(texture, texMatrix, textureDomain))
; | 1222 fp = GrBicubicEffect::Make(texture, texMatrix, textureDomain); |
1223 } else { | 1223 } else { |
1224 fp.reset(GrTextureDomainEffect::Create(texture, | 1224 fp = GrTextureDomainEffect::Make(texture, texMatrix, textureDomain, |
1225 texMatrix, | 1225 GrTextureDomain::kClamp_Mode, param
s.filterMode()); |
1226 textureDomain, | |
1227 GrTextureDomain::kClamp_Mode, | |
1228 params.filterMode())); | |
1229 } | 1226 } |
1230 } else if (bicubic) { | 1227 } else if (bicubic) { |
1231 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); | 1228 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); |
1232 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil
eModeY() }; | 1229 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil
eModeY() }; |
1233 fp.reset(GrBicubicEffect::Create(texture, texMatrix, tileModes)); | 1230 fp = GrBicubicEffect::Make(texture, texMatrix, tileModes); |
1234 } else { | 1231 } else { |
1235 fp.reset(GrSimpleTextureEffect::Create(texture, texMatrix, params)); | 1232 fp = GrSimpleTextureEffect::Make(texture, texMatrix, params); |
1236 } | 1233 } |
1237 | 1234 |
1238 GrPaint grPaint; | 1235 GrPaint grPaint; |
1239 if (!SkPaintToGrPaintWithTexture(this->context(), paint, viewMatrix, fp, | 1236 if (!SkPaintToGrPaintWithTexture(this->context(), paint, viewMatrix, std::mo
ve(fp), |
1240 kAlpha_8_SkColorType == bitmap.colorType(), | 1237 kAlpha_8_SkColorType == bitmap.colorType(), |
1241 this->surfaceProps().isGammaCorrect(), &grP
aint)) { | 1238 this->surfaceProps().isGammaCorrect(), &grP
aint)) { |
1242 return; | 1239 return; |
1243 } | 1240 } |
1244 | 1241 |
1245 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) { | 1242 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) { |
1246 // We don't have local coords in this case and have previously set the t
ransform | 1243 // We don't have local coords in this case and have previously set the t
ransform |
1247 // matrices directly on the texture processor. | 1244 // matrices directly on the texture processor. |
1248 fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect); | 1245 fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect); |
1249 } else { | 1246 } else { |
(...skipping 23 matching lines...) Expand all Loading... |
1273 SkSourceGammaTreatment::kRespect, &texture); | 1270 SkSourceGammaTreatment::kRespect, &texture); |
1274 if (!texture) { | 1271 if (!texture) { |
1275 return; | 1272 return; |
1276 } | 1273 } |
1277 | 1274 |
1278 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); | 1275 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); |
1279 | 1276 |
1280 SkASSERT(!paint.getImageFilter()); | 1277 SkASSERT(!paint.getImageFilter()); |
1281 | 1278 |
1282 GrPaint grPaint; | 1279 GrPaint grPaint; |
1283 SkAutoTUnref<const GrFragmentProcessor> fp( | 1280 sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture, SkMatrix:
:I())); |
1284 GrSimpleTextureEffect::Create(texture, SkMatrix::I())); | |
1285 if (alphaOnly) { | 1281 if (alphaOnly) { |
1286 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); | 1282 fp = GrFragmentProcessor::MulOutputByInputUnpremulColor(std::move(fp)); |
1287 } else { | 1283 } else { |
1288 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); | 1284 fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp)); |
1289 } | 1285 } |
1290 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, | 1286 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, std::move(fp), |
1291 this->surfaceProps().isGammaCorrect(), &g
rPaint)) { | 1287 this->surfaceProps().isGammaCorrect(), &g
rPaint)) { |
1292 return; | 1288 return; |
1293 } | 1289 } |
1294 | 1290 |
1295 fDrawContext->fillRectToRect(fClip, | 1291 fDrawContext->fillRectToRect(fClip, |
1296 grPaint, | 1292 grPaint, |
1297 SkMatrix::I(), | 1293 SkMatrix::I(), |
1298 SkRect::MakeXYWH(SkIntToScalar(left), | 1294 SkRect::MakeXYWH(SkIntToScalar(left), |
1299 SkIntToScalar(top), | 1295 SkIntToScalar(top), |
1300 SkIntToScalar(w), | 1296 SkIntToScalar(w), |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 return; | 1404 return; |
1409 } | 1405 } |
1410 | 1406 |
1411 const SkImageInfo ii = dev->imageInfo(); | 1407 const SkImageInfo ii = dev->imageInfo(); |
1412 int w = ii.width(); | 1408 int w = ii.width(); |
1413 int h = ii.height(); | 1409 int h = ii.height(); |
1414 | 1410 |
1415 SkASSERT(!paint.getImageFilter()); | 1411 SkASSERT(!paint.getImageFilter()); |
1416 | 1412 |
1417 GrPaint grPaint; | 1413 GrPaint grPaint; |
1418 SkAutoTUnref<const GrFragmentProcessor> fp( | 1414 sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(devTex.get(), SkMa
trix::I())); |
1419 GrSimpleTextureEffect::Create(devTex.get(), SkMatrix::I())); | |
1420 if (GrPixelConfigIsAlphaOnly(devTex->config())) { | 1415 if (GrPixelConfigIsAlphaOnly(devTex->config())) { |
1421 // Can this happen? | 1416 // Can this happen? |
1422 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); | 1417 fp = GrFragmentProcessor::MulOutputByInputUnpremulColor(std::move(fp)); |
1423 } else { | 1418 } else { |
1424 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); | 1419 fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp)); |
1425 } | 1420 } |
1426 | 1421 |
1427 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, | 1422 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, std::move(fp), |
1428 this->surfaceProps().isGammaCorrect(), &g
rPaint)) { | 1423 this->surfaceProps().isGammaCorrect(), &g
rPaint)) { |
1429 return; | 1424 return; |
1430 } | 1425 } |
1431 | 1426 |
1432 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), | 1427 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), |
1433 SkIntToScalar(y), | 1428 SkIntToScalar(y), |
1434 SkIntToScalar(w), | 1429 SkIntToScalar(w), |
1435 SkIntToScalar(h)); | 1430 SkIntToScalar(h)); |
1436 | 1431 |
1437 // The device being drawn may not fill up its texture (e.g. saveLayer uses a
pproximate | 1432 // The device being drawn may not fill up its texture (e.g. saveLayer uses a
pproximate |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 this->drawTextureProducer(producer, &srcR, &dstR, SkCanvas::kStrict_
SrcRectConstraint, | 1517 this->drawTextureProducer(producer, &srcR, &dstR, SkCanvas::kStrict_
SrcRectConstraint, |
1523 *draw.fMatrix, fClip, paint); | 1518 *draw.fMatrix, fClip, paint); |
1524 } | 1519 } |
1525 return; | 1520 return; |
1526 } | 1521 } |
1527 | 1522 |
1528 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt
erMode; | 1523 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt
erMode; |
1529 bool gammaCorrect = this->surfaceProps().isGammaCorrect(); | 1524 bool gammaCorrect = this->surfaceProps().isGammaCorrect(); |
1530 SkSourceGammaTreatment gammaTreatment = gammaCorrect | 1525 SkSourceGammaTreatment gammaTreatment = gammaCorrect |
1531 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore; | 1526 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore; |
1532 SkAutoTUnref<const GrFragmentProcessor> fp( | 1527 sk_sp<GrFragmentProcessor> fp( |
1533 producer->createFragmentProcessor(SkMatrix::I(), | 1528 producer->createFragmentProcessor(SkMatrix::I(), |
1534 SkRect::MakeIWH(producer->width(), pro
ducer->height()), | 1529 SkRect::MakeIWH(producer->width(), pro
ducer->height()), |
1535 GrTextureProducer::kNo_FilterConstrain
t, true, | 1530 GrTextureProducer::kNo_FilterConstrain
t, true, |
1536 &kMode, gammaTreatment)); | 1531 &kMode, gammaTreatment)); |
1537 GrPaint grPaint; | 1532 GrPaint grPaint; |
1538 if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, fp, | 1533 if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, std:
:move(fp), |
1539 producer->isAlphaOnly(), gammaCorrect, &grP
aint)) { | 1534 producer->isAlphaOnly(), gammaCorrect, &grP
aint)) { |
1540 return; | 1535 return; |
1541 } | 1536 } |
1542 | 1537 |
1543 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, producer->width()
, | 1538 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, producer->width()
, |
1544 producer->height(), center, dst); | 1539 producer->height(), center, dst); |
1545 } | 1540 } |
1546 | 1541 |
1547 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, | 1542 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, |
1548 const SkIRect& center, const SkRect& dst, const
SkPaint& paint) { | 1543 const SkIRect& center, const SkRect& dst, const
SkPaint& paint) { |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 } | 1926 } |
1932 | 1927 |
1933 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1928 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
1934 ASSERT_SINGLE_OWNER | 1929 ASSERT_SINGLE_OWNER |
1935 // We always return a transient cache, so it is freed after each | 1930 // We always return a transient cache, so it is freed after each |
1936 // filter traversal. | 1931 // filter traversal. |
1937 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1932 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
1938 } | 1933 } |
1939 | 1934 |
1940 #endif | 1935 #endif |
OLD | NEW |