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 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 params.isBilerp())); | 1370 params.isBilerp())); |
1371 } else { | 1371 } else { |
1372 effect.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), param
s)); | 1372 effect.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), param
s)); |
1373 } | 1373 } |
1374 grPaint->colorStage(kBitmapEffectIdx)->setEffect(effect); | 1374 grPaint->colorStage(kBitmapEffectIdx)->setEffect(effect); |
1375 fContext->drawRectToRect(*grPaint, dstRect, paintRect, &m); | 1375 fContext->drawRectToRect(*grPaint, dstRect, paintRect, &m); |
1376 } | 1376 } |
1377 | 1377 |
1378 static bool filter_texture(SkDevice* device, GrContext* context, | 1378 static bool filter_texture(SkDevice* device, GrContext* context, |
1379 GrTexture* texture, SkImageFilter* filter, | 1379 GrTexture* texture, SkImageFilter* filter, |
1380 int w, int h, SkBitmap* result) { | 1380 int w, int h, SkBitmap* result, SkIPoint* offset) { |
1381 GrAssert(filter); | 1381 GrAssert(filter); |
1382 SkDeviceImageFilterProxy proxy(device); | 1382 SkDeviceImageFilterProxy proxy(device); |
1383 | 1383 |
1384 if (filter->canFilterImageGPU()) { | 1384 if (filter->canFilterImageGPU()) { |
1385 // Save the render target and set it to NULL, so we don't accidentally d
raw to it in the | 1385 // Save the render target and set it to NULL, so we don't accidentally d
raw to it in the |
1386 // filter. Also set the clip wide open and the matrix to identity. | 1386 // filter. Also set the clip wide open and the matrix to identity. |
1387 GrContext::AutoWideOpenIdentityDraw awo(context, NULL); | 1387 GrContext::AutoWideOpenIdentityDraw awo(context, NULL); |
1388 return filter->filterImageGPU(&proxy, wrap_texture(texture), result); | 1388 return filter->filterImageGPU(&proxy, wrap_texture(texture), result, off
set); |
1389 } else { | 1389 } else { |
1390 return false; | 1390 return false; |
1391 } | 1391 } |
1392 } | 1392 } |
1393 | 1393 |
1394 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, | 1394 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, |
1395 int left, int top, const SkPaint& paint) { | 1395 int left, int top, const SkPaint& paint) { |
1396 // drawSprite is defined to be in device coords. | 1396 // drawSprite is defined to be in device coords. |
1397 CHECK_SHOULD_DRAW(draw, true); | 1397 CHECK_SHOULD_DRAW(draw, true); |
1398 | 1398 |
(...skipping 13 matching lines...) Expand all Loading... |
1412 GrEffectStage* stage = grPaint.colorStage(kBitmapEffectIdx); | 1412 GrEffectStage* stage = grPaint.colorStage(kBitmapEffectIdx); |
1413 | 1413 |
1414 GrTexture* texture; | 1414 GrTexture* texture; |
1415 stage->reset(); | 1415 stage->reset(); |
1416 // draw sprite uses the default texture params | 1416 // draw sprite uses the default texture params |
1417 SkAutoCachedTexture act(this, bitmap, NULL, &texture); | 1417 SkAutoCachedTexture act(this, bitmap, NULL, &texture); |
1418 grPaint.colorStage(kBitmapEffectIdx)->setEffect( | 1418 grPaint.colorStage(kBitmapEffectIdx)->setEffect( |
1419 GrSimpleTextureEffect::Create(texture, SkMatrix::I()))->unref(); | 1419 GrSimpleTextureEffect::Create(texture, SkMatrix::I()))->unref(); |
1420 | 1420 |
1421 SkImageFilter* filter = paint.getImageFilter(); | 1421 SkImageFilter* filter = paint.getImageFilter(); |
| 1422 SkIPoint offset = SkIPoint::Make(0, 0); |
1422 if (NULL != filter) { | 1423 if (NULL != filter) { |
1423 SkBitmap filterBitmap; | 1424 SkBitmap filterBitmap; |
1424 if (filter_texture(this, fContext, texture, filter, w, h, &filterBitmap)
) { | 1425 if (filter_texture(this, fContext, texture, filter, w, h, &filterBitmap,
&offset)) { |
1425 grPaint.colorStage(kBitmapEffectIdx)->setEffect( | 1426 grPaint.colorStage(kBitmapEffectIdx)->setEffect( |
1426 GrSimpleTextureEffect::Create(filterBitmap.getTexture(), SkMatri
x::I()))->unref(); | 1427 GrSimpleTextureEffect::Create(filterBitmap.getTexture(), SkMatri
x::I()))->unref(); |
1427 texture = filterBitmap.getTexture(); | 1428 texture = filterBitmap.getTexture(); |
1428 w = filterBitmap.width(); | 1429 w = filterBitmap.width(); |
1429 h = filterBitmap.height(); | 1430 h = filterBitmap.height(); |
1430 } | 1431 } |
1431 } | 1432 } |
1432 | 1433 |
1433 fContext->drawRectToRect(grPaint, | 1434 fContext->drawRectToRect(grPaint, |
1434 GrRect::MakeXYWH(SkIntToScalar(left), | 1435 GrRect::MakeXYWH(SkIntToScalar(left), |
1435 SkIntToScalar(top), | 1436 SkIntToScalar(top), |
1436 SkIntToScalar(w), | 1437 SkIntToScalar(w), |
1437 SkIntToScalar(h)), | 1438 SkIntToScalar(h)), |
1438 GrRect::MakeWH(SK_Scalar1 * w / texture->width(), | 1439 GrRect::MakeXYWH(offset.fX, |
1439 SK_Scalar1 * h / texture->height())); | 1440 offset.fY, |
| 1441 SK_Scalar1 * w / texture->width(), |
| 1442 SK_Scalar1 * h / texture->height())
); |
1440 } | 1443 } |
1441 | 1444 |
1442 void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, | 1445 void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, |
1443 const SkRect* src, const SkRect& dst, | 1446 const SkRect* src, const SkRect& dst, |
1444 const SkPaint& paint) { | 1447 const SkPaint& paint) { |
1445 SkMatrix matrix; | 1448 SkMatrix matrix; |
1446 SkRect bitmapBounds, tmpSrc; | 1449 SkRect bitmapBounds, tmpSrc; |
1447 | 1450 |
1448 bitmapBounds.set(0, 0, | 1451 bitmapBounds.set(0, 0, |
1449 SkIntToScalar(bitmap.width()), | 1452 SkIntToScalar(bitmap.width()), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 GrTexture* devTex = (*grPaint.getColorStage(kBitmapEffectIdx).getEffect())->
texture(0); | 1494 GrTexture* devTex = (*grPaint.getColorStage(kBitmapEffectIdx).getEffect())->
texture(0); |
1492 SkASSERT(NULL != devTex); | 1495 SkASSERT(NULL != devTex); |
1493 | 1496 |
1494 const SkBitmap& bm = dev->accessBitmap(false); | 1497 const SkBitmap& bm = dev->accessBitmap(false); |
1495 int w = bm.width(); | 1498 int w = bm.width(); |
1496 int h = bm.height(); | 1499 int h = bm.height(); |
1497 | 1500 |
1498 SkImageFilter* filter = paint.getImageFilter(); | 1501 SkImageFilter* filter = paint.getImageFilter(); |
1499 if (NULL != filter) { | 1502 if (NULL != filter) { |
1500 SkBitmap filterBitmap; | 1503 SkBitmap filterBitmap; |
1501 if (filter_texture(this, fContext, devTex, filter, w, h, &filterBitmap))
{ | 1504 SkIPoint offset = SkIPoint::Make(0, 0); |
| 1505 if (filter_texture(this, fContext, devTex, filter, w, h, &filterBitmap,
&offset)) { |
1502 grPaint.colorStage(kBitmapEffectIdx)->setEffect( | 1506 grPaint.colorStage(kBitmapEffectIdx)->setEffect( |
1503 GrSimpleTextureEffect::Create(filterBitmap.getTexture(), SkMatri
x::I()))->unref(); | 1507 GrSimpleTextureEffect::Create(filterBitmap.getTexture(), SkMatri
x::I()))->unref(); |
1504 devTex = filterBitmap.getTexture(); | 1508 devTex = filterBitmap.getTexture(); |
1505 w = filterBitmap.width(); | 1509 w = filterBitmap.width(); |
1506 h = filterBitmap.height(); | 1510 h = filterBitmap.height(); |
| 1511 x += offset.fX; |
| 1512 y += offset.fY; |
1507 } | 1513 } |
1508 } | 1514 } |
1509 | 1515 |
1510 GrRect dstRect = GrRect::MakeXYWH(SkIntToScalar(x), | 1516 GrRect dstRect = GrRect::MakeXYWH(SkIntToScalar(x), |
1511 SkIntToScalar(y), | 1517 SkIntToScalar(y), |
1512 SkIntToScalar(w), | 1518 SkIntToScalar(w), |
1513 SkIntToScalar(h)); | 1519 SkIntToScalar(h)); |
1514 | 1520 |
1515 // The device being drawn may not fill up its texture (saveLayer uses | 1521 // The device being drawn may not fill up its texture (saveLayer uses |
1516 // the approximate ). | 1522 // the approximate ). |
(...skipping 18 matching lines...) Expand all Loading... |
1535 SkAutoLockPixels alp(src, !src.getTexture()); | 1541 SkAutoLockPixels alp(src, !src.getTexture()); |
1536 if (!src.getTexture() && !src.readyToDraw()) { | 1542 if (!src.getTexture() && !src.readyToDraw()) { |
1537 return false; | 1543 return false; |
1538 } | 1544 } |
1539 | 1545 |
1540 GrTexture* texture; | 1546 GrTexture* texture; |
1541 // We assume here that the filter will not attempt to tile the src. Otherwis
e, this cache lookup | 1547 // We assume here that the filter will not attempt to tile the src. Otherwis
e, this cache lookup |
1542 // must be pushed upstack. | 1548 // must be pushed upstack. |
1543 SkAutoCachedTexture act(this, src, NULL, &texture); | 1549 SkAutoCachedTexture act(this, src, NULL, &texture); |
1544 | 1550 |
1545 return filter_texture(this, fContext, texture, filter, src.width(), src.heig
ht(), result); | 1551 return filter_texture(this, fContext, texture, filter, src.width(), src.heig
ht(), result, offset); |
1546 } | 1552 } |
1547 | 1553 |
1548 /////////////////////////////////////////////////////////////////////////////// | 1554 /////////////////////////////////////////////////////////////////////////////// |
1549 | 1555 |
1550 // must be in SkCanvas::VertexMode order | 1556 // must be in SkCanvas::VertexMode order |
1551 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1557 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
1552 kTriangles_GrPrimitiveType, | 1558 kTriangles_GrPrimitiveType, |
1553 kTriangleStrip_GrPrimitiveType, | 1559 kTriangleStrip_GrPrimitiveType, |
1554 kTriangleFan_GrPrimitiveType, | 1560 kTriangleFan_GrPrimitiveType, |
1555 }; | 1561 }; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1779 GrTexture* texture, | 1785 GrTexture* texture, |
1780 bool needClear) | 1786 bool needClear) |
1781 : SkDevice(make_bitmap(context, texture->asRenderTarget())) { | 1787 : SkDevice(make_bitmap(context, texture->asRenderTarget())) { |
1782 | 1788 |
1783 GrAssert(texture && texture->asRenderTarget()); | 1789 GrAssert(texture && texture->asRenderTarget()); |
1784 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1790 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
1785 // cache. We pass true for the third argument so that it will get unlocked. | 1791 // cache. We pass true for the third argument so that it will get unlocked. |
1786 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1792 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1787 fNeedClear = needClear; | 1793 fNeedClear = needClear; |
1788 } | 1794 } |
OLD | NEW |