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/GrTextureDomainEffect.h" | 10 #include "effects/GrTextureDomainEffect.h" |
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 const SkPaint& paint) { | 1273 const SkPaint& paint) { |
1274 SkASSERT(bitmap.width() <= fContext->getMaxTextureSize() && | 1274 SkASSERT(bitmap.width() <= fContext->getMaxTextureSize() && |
1275 bitmap.height() <= fContext->getMaxTextureSize()); | 1275 bitmap.height() <= fContext->getMaxTextureSize()); |
1276 | 1276 |
1277 GrTexture* texture; | 1277 GrTexture* texture; |
1278 SkAutoCachedTexture act(this, bitmap, ¶ms, &texture); | 1278 SkAutoCachedTexture act(this, bitmap, ¶ms, &texture); |
1279 if (NULL == texture) { | 1279 if (NULL == texture) { |
1280 return; | 1280 return; |
1281 } | 1281 } |
1282 | 1282 |
1283 GrRect dstRect(srcRect); | 1283 SkRect dstRect(srcRect); |
1284 GrRect paintRect; | 1284 SkRect paintRect; |
1285 SkScalar wInv = SkScalarInvert(SkIntToScalar(bitmap.width())); | 1285 SkScalar wInv = SkScalarInvert(SkIntToScalar(bitmap.width())); |
1286 SkScalar hInv = SkScalarInvert(SkIntToScalar(bitmap.height())); | 1286 SkScalar hInv = SkScalarInvert(SkIntToScalar(bitmap.height())); |
1287 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), | 1287 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), |
1288 SkScalarMul(srcRect.fTop, hInv), | 1288 SkScalarMul(srcRect.fTop, hInv), |
1289 SkScalarMul(srcRect.fRight, wInv), | 1289 SkScalarMul(srcRect.fRight, wInv), |
1290 SkScalarMul(srcRect.fBottom, hInv)); | 1290 SkScalarMul(srcRect.fBottom, hInv)); |
1291 | 1291 |
1292 bool needsTextureDomain = false; | 1292 bool needsTextureDomain = false; |
1293 if (params.isBilerp()) { | 1293 if (params.isBilerp()) { |
1294 // Need texture domain if drawing a sub rect. | 1294 // Need texture domain if drawing a sub rect. |
1295 needsTextureDomain = srcRect.width() < bitmap.width() || | 1295 needsTextureDomain = srcRect.width() < bitmap.width() || |
1296 srcRect.height() < bitmap.height(); | 1296 srcRect.height() < bitmap.height(); |
1297 if (m.rectStaysRect() && fContext->getMatrix().rectStaysRect()) { | 1297 if (m.rectStaysRect() && fContext->getMatrix().rectStaysRect()) { |
1298 // sampling is axis-aligned | 1298 // sampling is axis-aligned |
1299 GrRect transformedRect; | 1299 SkRect transformedRect; |
1300 SkMatrix srcToDeviceMatrix(m); | 1300 SkMatrix srcToDeviceMatrix(m); |
1301 srcToDeviceMatrix.postConcat(fContext->getMatrix()); | 1301 srcToDeviceMatrix.postConcat(fContext->getMatrix()); |
1302 srcToDeviceMatrix.mapRect(&transformedRect, srcRect); | 1302 srcToDeviceMatrix.mapRect(&transformedRect, srcRect); |
1303 | 1303 |
1304 if (hasAlignedSamples(srcRect, transformedRect)) { | 1304 if (hasAlignedSamples(srcRect, transformedRect)) { |
1305 // We could also turn off filtering here (but we already did a c
ache lookup with | 1305 // We could also turn off filtering here (but we already did a c
ache lookup with |
1306 // params). | 1306 // params). |
1307 needsTextureDomain = false; | 1307 needsTextureDomain = false; |
1308 } else { | 1308 } else { |
1309 needsTextureDomain = needsTextureDomain && | 1309 needsTextureDomain = needsTextureDomain && |
1310 mayColorBleed(srcRect, transformedRect, m); | 1310 mayColorBleed(srcRect, transformedRect, m); |
1311 } | 1311 } |
1312 } | 1312 } |
1313 } | 1313 } |
1314 | 1314 |
1315 GrRect textureDomain = GrRect::MakeEmpty(); | 1315 SkRect textureDomain = SkRect::MakeEmpty(); |
1316 SkAutoTUnref<GrEffectRef> effect; | 1316 SkAutoTUnref<GrEffectRef> effect; |
1317 if (needsTextureDomain) { | 1317 if (needsTextureDomain) { |
1318 // Use a constrained texture domain to avoid color bleeding | 1318 // Use a constrained texture domain to avoid color bleeding |
1319 SkScalar left, top, right, bottom; | 1319 SkScalar left, top, right, bottom; |
1320 if (srcRect.width() > SK_Scalar1) { | 1320 if (srcRect.width() > SK_Scalar1) { |
1321 SkScalar border = SK_ScalarHalf / bitmap.width(); | 1321 SkScalar border = SK_ScalarHalf / bitmap.width(); |
1322 left = paintRect.left() + border; | 1322 left = paintRect.left() + border; |
1323 right = paintRect.right() - border; | 1323 right = paintRect.right() - border; |
1324 } else { | 1324 } else { |
1325 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); | 1325 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 } | 1398 } |
1399 | 1399 |
1400 GrPaint grPaint; | 1400 GrPaint grPaint; |
1401 grPaint.addColorTextureEffect(texture, SkMatrix::I()); | 1401 grPaint.addColorTextureEffect(texture, SkMatrix::I()); |
1402 | 1402 |
1403 if(!skPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) { | 1403 if(!skPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) { |
1404 return; | 1404 return; |
1405 } | 1405 } |
1406 | 1406 |
1407 fContext->drawRectToRect(grPaint, | 1407 fContext->drawRectToRect(grPaint, |
1408 GrRect::MakeXYWH(SkIntToScalar(left), | 1408 SkRect::MakeXYWH(SkIntToScalar(left), |
1409 SkIntToScalar(top), | 1409 SkIntToScalar(top), |
1410 SkIntToScalar(w), | 1410 SkIntToScalar(w), |
1411 SkIntToScalar(h)), | 1411 SkIntToScalar(h)), |
1412 GrRect::MakeXYWH(SkIntToScalar(offset.fX), | 1412 SkRect::MakeXYWH(SkIntToScalar(offset.fX), |
1413 SkIntToScalar(offset.fY), | 1413 SkIntToScalar(offset.fY), |
1414 SK_Scalar1 * w / texture->width(), | 1414 SK_Scalar1 * w / texture->width(), |
1415 SK_Scalar1 * h / texture->height()
)); | 1415 SK_Scalar1 * h / texture->height()
)); |
1416 } | 1416 } |
1417 | 1417 |
1418 void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, | 1418 void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, |
1419 const SkRect* src, const SkRect& dst, | 1419 const SkRect* src, const SkRect& dst, |
1420 const SkPaint& paint) { | 1420 const SkPaint& paint) { |
1421 SkMatrix matrix; | 1421 SkMatrix matrix; |
1422 SkRect bitmapBounds, tmpSrc; | 1422 SkRect bitmapBounds, tmpSrc; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 } | 1481 } |
1482 } | 1482 } |
1483 | 1483 |
1484 GrPaint grPaint; | 1484 GrPaint grPaint; |
1485 grPaint.addColorTextureEffect(devTex, SkMatrix::I()); | 1485 grPaint.addColorTextureEffect(devTex, SkMatrix::I()); |
1486 | 1486 |
1487 if (!skPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) { | 1487 if (!skPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) { |
1488 return; | 1488 return; |
1489 } | 1489 } |
1490 | 1490 |
1491 GrRect dstRect = GrRect::MakeXYWH(SkIntToScalar(x), | 1491 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), |
1492 SkIntToScalar(y), | 1492 SkIntToScalar(y), |
1493 SkIntToScalar(w), | 1493 SkIntToScalar(w), |
1494 SkIntToScalar(h)); | 1494 SkIntToScalar(h)); |
1495 | 1495 |
1496 // The device being drawn may not fill up its texture (e.g. saveLayer uses a
pproximate | 1496 // The device being drawn may not fill up its texture (e.g. saveLayer uses a
pproximate |
1497 // scratch texture). | 1497 // scratch texture). |
1498 GrRect srcRect = GrRect::MakeWH(SK_Scalar1 * w / devTex->width(), | 1498 SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(), |
1499 SK_Scalar1 * h / devTex->height()); | 1499 SK_Scalar1 * h / devTex->height()); |
1500 | 1500 |
1501 fContext->drawRectToRect(grPaint, dstRect, srcRect); | 1501 fContext->drawRectToRect(grPaint, dstRect, srcRect); |
1502 } | 1502 } |
1503 | 1503 |
1504 bool SkGpuDevice::canHandleImageFilter(SkImageFilter* filter) { | 1504 bool SkGpuDevice::canHandleImageFilter(SkImageFilter* filter) { |
1505 return filter->canFilterImageGPU(); | 1505 return filter->canFilterImageGPU(); |
1506 } | 1506 } |
1507 | 1507 |
1508 bool SkGpuDevice::filterImage(SkImageFilter* filter, const SkBitmap& src, | 1508 bool SkGpuDevice::filterImage(SkImageFilter* filter, const SkBitmap& src, |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1760 GrTexture* texture, | 1760 GrTexture* texture, |
1761 bool needClear) | 1761 bool needClear) |
1762 : SkDevice(make_bitmap(context, texture->asRenderTarget())) { | 1762 : SkDevice(make_bitmap(context, texture->asRenderTarget())) { |
1763 | 1763 |
1764 GrAssert(texture && texture->asRenderTarget()); | 1764 GrAssert(texture && texture->asRenderTarget()); |
1765 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1765 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
1766 // cache. We pass true for the third argument so that it will get unlocked. | 1766 // cache. We pass true for the third argument so that it will get unlocked. |
1767 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1767 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1768 fNeedClear = needClear; | 1768 fNeedClear = needClear; |
1769 } | 1769 } |
OLD | NEW |