| 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 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config()); | 1581 bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config()); |
| 1582 if (!skPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint)) { | 1582 if (!skPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint)) { |
| 1583 return; | 1583 return; |
| 1584 } | 1584 } |
| 1585 | 1585 |
| 1586 fContext->drawRectToRect(grPaint, dstRect, paintRect, NULL); | 1586 fContext->drawRectToRect(grPaint, dstRect, paintRect, NULL); |
| 1587 } | 1587 } |
| 1588 | 1588 |
| 1589 static bool filter_texture(SkBaseDevice* device, GrContext* context, | 1589 static bool filter_texture(SkBaseDevice* device, GrContext* context, |
| 1590 GrTexture* texture, const SkImageFilter* filter, | 1590 GrTexture* texture, const SkImageFilter* filter, |
| 1591 int w, int h, const SkMatrix& ctm, SkBitmap* result, | 1591 int w, int h, const SkImageFilter::Context& ctx, |
| 1592 SkIPoint* offset) { | 1592 SkBitmap* result, SkIPoint* offset) { |
| 1593 SkASSERT(filter); | 1593 SkASSERT(filter); |
| 1594 SkDeviceImageFilterProxy proxy(device); | 1594 SkDeviceImageFilterProxy proxy(device); |
| 1595 | 1595 |
| 1596 if (filter->canFilterImageGPU()) { | 1596 if (filter->canFilterImageGPU()) { |
| 1597 // Save the render target and set it to NULL, so we don't accidentally d
raw to it in the | 1597 // Save the render target and set it to NULL, so we don't accidentally d
raw to it in the |
| 1598 // filter. Also set the clip wide open and the matrix to identity. | 1598 // filter. Also set the clip wide open and the matrix to identity. |
| 1599 GrContext::AutoWideOpenIdentityDraw awo(context, NULL); | 1599 GrContext::AutoWideOpenIdentityDraw awo(context, NULL); |
| 1600 return filter->filterImageGPU(&proxy, wrap_texture(texture), ctm, result
, offset); | 1600 return filter->filterImageGPU(&proxy, wrap_texture(texture), ctx, result
, offset); |
| 1601 } else { | 1601 } else { |
| 1602 return false; | 1602 return false; |
| 1603 } | 1603 } |
| 1604 } | 1604 } |
| 1605 | 1605 |
| 1606 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, | 1606 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, |
| 1607 int left, int top, const SkPaint& paint) { | 1607 int left, int top, const SkPaint& paint) { |
| 1608 // drawSprite is defined to be in device coords. | 1608 // drawSprite is defined to be in device coords. |
| 1609 CHECK_SHOULD_DRAW(draw, true); | 1609 CHECK_SHOULD_DRAW(draw, true); |
| 1610 | 1610 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1621 SkAutoCachedTexture act(this, bitmap, NULL, &texture); | 1621 SkAutoCachedTexture act(this, bitmap, NULL, &texture); |
| 1622 | 1622 |
| 1623 SkImageFilter* filter = paint.getImageFilter(); | 1623 SkImageFilter* filter = paint.getImageFilter(); |
| 1624 // This bitmap will own the filtered result as a texture. | 1624 // This bitmap will own the filtered result as a texture. |
| 1625 SkBitmap filteredBitmap; | 1625 SkBitmap filteredBitmap; |
| 1626 | 1626 |
| 1627 if (NULL != filter) { | 1627 if (NULL != filter) { |
| 1628 SkIPoint offset = SkIPoint::Make(0, 0); | 1628 SkIPoint offset = SkIPoint::Make(0, 0); |
| 1629 SkMatrix matrix(*draw.fMatrix); | 1629 SkMatrix matrix(*draw.fMatrix); |
| 1630 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); | 1630 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); |
| 1631 if (filter_texture(this, fContext, texture, filter, w, h, matrix, &filte
redBitmap, | 1631 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| 1632 SkImageFilter::Context ctx(matrix, clipBounds); |
| 1633 if (filter_texture(this, fContext, texture, filter, w, h, ctx, &filtered
Bitmap, |
| 1632 &offset)) { | 1634 &offset)) { |
| 1633 texture = (GrTexture*) filteredBitmap.getTexture(); | 1635 texture = (GrTexture*) filteredBitmap.getTexture(); |
| 1634 w = filteredBitmap.width(); | 1636 w = filteredBitmap.width(); |
| 1635 h = filteredBitmap.height(); | 1637 h = filteredBitmap.height(); |
| 1636 left += offset.x(); | 1638 left += offset.x(); |
| 1637 top += offset.y(); | 1639 top += offset.y(); |
| 1638 } else { | 1640 } else { |
| 1639 return; | 1641 return; |
| 1640 } | 1642 } |
| 1641 } | 1643 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1727 int h = bm.height(); | 1729 int h = bm.height(); |
| 1728 | 1730 |
| 1729 SkImageFilter* filter = paint.getImageFilter(); | 1731 SkImageFilter* filter = paint.getImageFilter(); |
| 1730 // This bitmap will own the filtered result as a texture. | 1732 // This bitmap will own the filtered result as a texture. |
| 1731 SkBitmap filteredBitmap; | 1733 SkBitmap filteredBitmap; |
| 1732 | 1734 |
| 1733 if (NULL != filter) { | 1735 if (NULL != filter) { |
| 1734 SkIPoint offset = SkIPoint::Make(0, 0); | 1736 SkIPoint offset = SkIPoint::Make(0, 0); |
| 1735 SkMatrix matrix(*draw.fMatrix); | 1737 SkMatrix matrix(*draw.fMatrix); |
| 1736 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); | 1738 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); |
| 1737 if (filter_texture(this, fContext, devTex, filter, w, h, matrix, &filter
edBitmap, | 1739 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height()); |
| 1740 SkImageFilter::Context ctx(matrix, clipBounds); |
| 1741 if (filter_texture(this, fContext, devTex, filter, w, h, ctx, &filteredB
itmap, |
| 1738 &offset)) { | 1742 &offset)) { |
| 1739 devTex = filteredBitmap.getTexture(); | 1743 devTex = filteredBitmap.getTexture(); |
| 1740 w = filteredBitmap.width(); | 1744 w = filteredBitmap.width(); |
| 1741 h = filteredBitmap.height(); | 1745 h = filteredBitmap.height(); |
| 1742 x += offset.fX; | 1746 x += offset.fX; |
| 1743 y += offset.fY; | 1747 y += offset.fY; |
| 1744 } else { | 1748 } else { |
| 1745 return; | 1749 return; |
| 1746 } | 1750 } |
| 1747 } | 1751 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1764 SK_Scalar1 * h / devTex->height()); | 1768 SK_Scalar1 * h / devTex->height()); |
| 1765 | 1769 |
| 1766 fContext->drawRectToRect(grPaint, dstRect, srcRect); | 1770 fContext->drawRectToRect(grPaint, dstRect, srcRect); |
| 1767 } | 1771 } |
| 1768 | 1772 |
| 1769 bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) { | 1773 bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) { |
| 1770 return filter->canFilterImageGPU(); | 1774 return filter->canFilterImageGPU(); |
| 1771 } | 1775 } |
| 1772 | 1776 |
| 1773 bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, | 1777 bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, |
| 1774 const SkMatrix& ctm, | 1778 const SkImageFilter::Context& ctx, |
| 1775 SkBitmap* result, SkIPoint* offset) { | 1779 SkBitmap* result, SkIPoint* offset) { |
| 1776 // want explicitly our impl, so guard against a subclass of us overriding it | 1780 // want explicitly our impl, so guard against a subclass of us overriding it |
| 1777 if (!this->SkGpuDevice::canHandleImageFilter(filter)) { | 1781 if (!this->SkGpuDevice::canHandleImageFilter(filter)) { |
| 1778 return false; | 1782 return false; |
| 1779 } | 1783 } |
| 1780 | 1784 |
| 1781 SkAutoLockPixels alp(src, !src.getTexture()); | 1785 SkAutoLockPixels alp(src, !src.getTexture()); |
| 1782 if (!src.getTexture() && !src.readyToDraw()) { | 1786 if (!src.getTexture() && !src.readyToDraw()) { |
| 1783 return false; | 1787 return false; |
| 1784 } | 1788 } |
| 1785 | 1789 |
| 1786 GrTexture* texture; | 1790 GrTexture* texture; |
| 1787 // We assume here that the filter will not attempt to tile the src. Otherwis
e, this cache lookup | 1791 // We assume here that the filter will not attempt to tile the src. Otherwis
e, this cache lookup |
| 1788 // must be pushed upstack. | 1792 // must be pushed upstack. |
| 1789 SkAutoCachedTexture act(this, src, NULL, &texture); | 1793 SkAutoCachedTexture act(this, src, NULL, &texture); |
| 1790 | 1794 |
| 1791 return filter_texture(this, fContext, texture, filter, src.width(), src.heig
ht(), ctm, result, | 1795 return filter_texture(this, fContext, texture, filter, src.width(), src.heig
ht(), ctx, |
| 1792 offset); | 1796 result, offset); |
| 1793 } | 1797 } |
| 1794 | 1798 |
| 1795 /////////////////////////////////////////////////////////////////////////////// | 1799 /////////////////////////////////////////////////////////////////////////////// |
| 1796 | 1800 |
| 1797 // must be in SkCanvas::VertexMode order | 1801 // must be in SkCanvas::VertexMode order |
| 1798 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1802 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
| 1799 kTriangles_GrPrimitiveType, | 1803 kTriangles_GrPrimitiveType, |
| 1800 kTriangleStrip_GrPrimitiveType, | 1804 kTriangleStrip_GrPrimitiveType, |
| 1801 kTriangleFan_GrPrimitiveType, | 1805 kTriangleFan_GrPrimitiveType, |
| 1802 }; | 1806 }; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1992 GrTexture* texture, | 1996 GrTexture* texture, |
| 1993 bool needClear) | 1997 bool needClear) |
| 1994 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1998 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
| 1995 | 1999 |
| 1996 SkASSERT(texture && texture->asRenderTarget()); | 2000 SkASSERT(texture && texture->asRenderTarget()); |
| 1997 // This constructor is called from onCreateDevice. It has locked the RT in t
he texture | 2001 // This constructor is called from onCreateDevice. It has locked the RT in t
he texture |
| 1998 // cache. We pass true for the third argument so that it will get unlocked. | 2002 // cache. We pass true for the third argument so that it will get unlocked. |
| 1999 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 2003 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
| 2000 fNeedClear = needClear; | 2004 fNeedClear = needClear; |
| 2001 } | 2005 } |
| OLD | NEW |