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 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 case SkPaint::kLow_FilterLevel: | 1189 case SkPaint::kLow_FilterLevel: |
1190 tileFilterPad = 1; | 1190 tileFilterPad = 1; |
1191 textureFilterMode = GrTextureParams::kBilerp_FilterMode; | 1191 textureFilterMode = GrTextureParams::kBilerp_FilterMode; |
1192 break; | 1192 break; |
1193 case SkPaint::kMedium_FilterLevel: | 1193 case SkPaint::kMedium_FilterLevel: |
1194 tileFilterPad = 1; | 1194 tileFilterPad = 1; |
1195 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 1195 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
1196 break; | 1196 break; |
1197 case SkPaint::kHigh_FilterLevel: { | 1197 case SkPaint::kHigh_FilterLevel: { |
1198 // Minification can look bad with the bicubic effect. | 1198 // Minification can look bad with the bicubic effect. |
1199 if (fContext->getMatrix().getMinStretch() >= SK_Scalar1 && | 1199 if (fContext->getMatrix().getMinStretch() >= SK_Scalar1) { |
1200 (flags & SkCanvas::kBleed_DrawBitmapRectFlag)) { | |
1201 // We will install an effect that does the filtering in the shad
er. | 1200 // We will install an effect that does the filtering in the shad
er. |
1202 textureFilterMode = GrTextureParams::kNone_FilterMode; | 1201 textureFilterMode = GrTextureParams::kNone_FilterMode; |
1203 tileFilterPad = GrBicubicEffect::kFilterTexelPad; | 1202 tileFilterPad = GrBicubicEffect::kFilterTexelPad; |
1204 doBicubic = true; | 1203 doBicubic = true; |
1205 } else { | 1204 } else { |
1206 // We don't yet support doing bicubic filtering with an interior
clamp. Fall back | 1205 // We don't yet support doing bicubic filtering with an interior
clamp. Fall back |
1207 // to MIPs | 1206 // to MIPs |
1208 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 1207 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
1209 tileFilterPad = 1; | 1208 tileFilterPad = 1; |
1210 } | 1209 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 SkIntToScalar(iTileR.fTop)); | 1272 SkIntToScalar(iTileR.fTop)); |
1274 | 1273 |
1275 if (SkPaint::kNone_FilterLevel != paint.getFilterLevel() || bicubic)
{ | 1274 if (SkPaint::kNone_FilterLevel != paint.getFilterLevel() || bicubic)
{ |
1276 SkIRect iClampRect; | 1275 SkIRect iClampRect; |
1277 | 1276 |
1278 if (SkCanvas::kBleed_DrawBitmapRectFlag & flags) { | 1277 if (SkCanvas::kBleed_DrawBitmapRectFlag & flags) { |
1279 // In bleed mode we want to always expand the tile on all ed
ges | 1278 // In bleed mode we want to always expand the tile on all ed
ges |
1280 // but stay within the bitmap bounds | 1279 // but stay within the bitmap bounds |
1281 iClampRect = SkIRect::MakeWH(bitmap.width(), bitmap.height()
); | 1280 iClampRect = SkIRect::MakeWH(bitmap.width(), bitmap.height()
); |
1282 } else { | 1281 } else { |
1283 SkASSERT(!bicubic); // Bicubic is not supported with non-ble
ed yet. | |
1284 | |
1285 // In texture-domain/clamp mode we only want to expand the | 1282 // In texture-domain/clamp mode we only want to expand the |
1286 // tile on edges interior to "srcRect" (i.e., we want to | 1283 // tile on edges interior to "srcRect" (i.e., we want to |
1287 // not bleed across the original clamped edges) | 1284 // not bleed across the original clamped edges) |
1288 srcRect.roundOut(&iClampRect); | 1285 srcRect.roundOut(&iClampRect); |
1289 } | 1286 } |
1290 int outset = bicubic ? GrBicubicEffect::kFilterTexelPad : 1; | 1287 int outset = bicubic ? GrBicubicEffect::kFilterTexelPad : 1; |
1291 clamped_outset_with_offset(&iTileR, outset, &offset, iClampRect)
; | 1288 clamped_outset_with_offset(&iTileR, outset, &offset, iClampRect)
; |
1292 } | 1289 } |
1293 | 1290 |
1294 if (bitmap.extractSubset(&tmpB, iTileR)) { | 1291 if (bitmap.extractSubset(&tmpB, iTileR)) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 SkRect paintRect; | 1369 SkRect paintRect; |
1373 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); | 1370 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); |
1374 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); | 1371 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); |
1375 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), | 1372 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), |
1376 SkScalarMul(srcRect.fTop, hInv), | 1373 SkScalarMul(srcRect.fTop, hInv), |
1377 SkScalarMul(srcRect.fRight, wInv), | 1374 SkScalarMul(srcRect.fRight, wInv), |
1378 SkScalarMul(srcRect.fBottom, hInv)); | 1375 SkScalarMul(srcRect.fBottom, hInv)); |
1379 | 1376 |
1380 bool needsTextureDomain = false; | 1377 bool needsTextureDomain = false; |
1381 if (!(flags & SkCanvas::kBleed_DrawBitmapRectFlag) && | 1378 if (!(flags & SkCanvas::kBleed_DrawBitmapRectFlag) && |
1382 params.filterMode() != GrTextureParams::kNone_FilterMode) { | 1379 (bicubic || params.filterMode() != GrTextureParams::kNone_FilterMode)) { |
1383 SkASSERT(!bicubic); | 1380 // Need texture domain if drawing a sub rect |
1384 // Need texture domain if drawing a sub rect. | |
1385 needsTextureDomain = srcRect.width() < bitmap.width() || | 1381 needsTextureDomain = srcRect.width() < bitmap.width() || |
1386 srcRect.height() < bitmap.height(); | 1382 srcRect.height() < bitmap.height(); |
1387 if (needsTextureDomain && fContext->getMatrix().rectStaysRect()) { | 1383 if (!bicubic && needsTextureDomain && fContext->getMatrix().rectStaysRec
t()) { |
1388 const SkMatrix& matrix = fContext->getMatrix(); | 1384 const SkMatrix& matrix = fContext->getMatrix(); |
1389 // sampling is axis-aligned | 1385 // sampling is axis-aligned |
1390 SkRect transformedRect; | 1386 SkRect transformedRect; |
1391 matrix.mapRect(&transformedRect, srcRect); | 1387 matrix.mapRect(&transformedRect, srcRect); |
1392 | 1388 |
1393 if (has_aligned_samples(srcRect, transformedRect)) { | 1389 if (has_aligned_samples(srcRect, transformedRect)) { |
1394 // We could also turn off filtering here (but we already did a c
ache lookup with | 1390 // We could also turn off filtering here (but we already did a c
ache lookup with |
1395 // params). | 1391 // params). |
1396 needsTextureDomain = false; | 1392 needsTextureDomain = false; |
1397 } else { | 1393 } else { |
(...skipping 15 matching lines...) Expand all Loading... |
1413 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); | 1409 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); |
1414 } | 1410 } |
1415 if (srcRect.height() > SK_Scalar1) { | 1411 if (srcRect.height() > SK_Scalar1) { |
1416 SkScalar border = SK_ScalarHalf / texture->height(); | 1412 SkScalar border = SK_ScalarHalf / texture->height(); |
1417 top = paintRect.top() + border; | 1413 top = paintRect.top() + border; |
1418 bottom = paintRect.bottom() - border; | 1414 bottom = paintRect.bottom() - border; |
1419 } else { | 1415 } else { |
1420 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); | 1416 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); |
1421 } | 1417 } |
1422 textureDomain.setLTRB(left, top, right, bottom); | 1418 textureDomain.setLTRB(left, top, right, bottom); |
1423 effect.reset(GrTextureDomainEffect::Create(texture, | 1419 if (bicubic) { |
1424 SkMatrix::I(), | 1420 effect.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), texture
Domain)); |
1425 textureDomain, | 1421 } else { |
1426 GrTextureDomain::kClamp_Mode, | 1422 effect.reset(GrTextureDomainEffect::Create(texture, |
1427 params.filterMode())); | 1423 SkMatrix::I(), |
| 1424 textureDomain, |
| 1425 GrTextureDomain::kClamp_M
ode, |
| 1426 params.filterMode())); |
| 1427 } |
1428 } else if (bicubic) { | 1428 } else if (bicubic) { |
1429 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); | 1429 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); |
1430 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil
eModeY() }; | 1430 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil
eModeY() }; |
1431 effect.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), tileModes))
; | 1431 effect.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), tileModes))
; |
1432 } else { | 1432 } else { |
1433 effect.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), param
s)); | 1433 effect.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), param
s)); |
1434 } | 1434 } |
1435 | 1435 |
1436 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring | 1436 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring |
1437 // the rest from the SkPaint. | 1437 // the rest from the SkPaint. |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 GrTexture* texture, | 1900 GrTexture* texture, |
1901 bool needClear) | 1901 bool needClear) |
1902 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1902 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
1903 | 1903 |
1904 SkASSERT(texture && texture->asRenderTarget()); | 1904 SkASSERT(texture && texture->asRenderTarget()); |
1905 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1905 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
1906 // cache. We pass true for the third argument so that it will get unlocked. | 1906 // cache. We pass true for the third argument so that it will get unlocked. |
1907 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1907 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1908 fNeedClear = needClear; | 1908 fNeedClear = needClear; |
1909 } | 1909 } |
OLD | NEW |