| 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 "GrBitmapTextContext.h" | 10 #include "GrBitmapTextContext.h" |
| (...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 SkColor2GrColor(paint.getColor()); | 1571 SkColor2GrColor(paint.getColor()); |
| 1572 SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, paintColor, f
alse, &grPaint); | 1572 SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, paintColor, f
alse, &grPaint); |
| 1573 | 1573 |
| 1574 fContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix, dst
Rect, | 1574 fContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix, dst
Rect, |
| 1575 paintRect); | 1575 paintRect); |
| 1576 } | 1576 } |
| 1577 | 1577 |
| 1578 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, | 1578 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, |
| 1579 const SkImageFilter* filter, | 1579 const SkImageFilter* filter, |
| 1580 const SkImageFilter::Context& ctx, | 1580 const SkImageFilter::Context& ctx, |
| 1581 SkBitmap* result, SkIPoint* offset) { | 1581 SkAutoTUnref<const SkImage>& result, SkIPoint* o
ffset) { |
| 1582 SkASSERT(filter); | 1582 SkASSERT(filter); |
| 1583 | 1583 |
| 1584 // FIXME: plumb actual surface props such that we don't have to lie about th
e flags here | 1584 // FIXME: plumb actual surface props such that we don't have to lie about th
e flags here |
| 1585 // (https://code.google.com/p/skia/issues/detail?id=3148). | 1585 // (https://code.google.com/p/skia/issues/detail?id=3148). |
| 1586 SkDeviceImageFilterProxy proxy(this, SkSurfaceProps(0, getLeakyProperties().
pixelGeometry())); | 1586 SkDeviceImageFilterProxy proxy(this, SkSurfaceProps(0, getLeakyProperties().
pixelGeometry())); |
| 1587 | 1587 |
| 1588 if (filter->canFilterImageGPU()) { | 1588 if (filter->canFilterImageGPU()) { |
| 1589 SkBitmap filterInput; | 1589 SkBitmap filterInput; |
| 1590 wrap_surface(texture, &filterInput); | 1590 wrap_surface(texture, &filterInput); |
| 1591 return filter->filterImageGPU(&proxy, filterInput, ctx, result, offset); | 1591 SkAutoTUnref<const SkImage> src(SkNewImageFromBitmapTexture(filterInput, |
| 1592 texture->des
c().fSampleCnt, |
| 1593 SkSurface::k
Yes_Budgeted)); |
| 1594 return filter->filterImageGPU(&proxy, src, ctx, result, offset); |
| 1592 } else { | 1595 } else { |
| 1593 return false; | 1596 return false; |
| 1594 } | 1597 } |
| 1595 } | 1598 } |
| 1596 | 1599 |
| 1597 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, | 1600 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, |
| 1598 int left, int top, const SkPaint& paint) { | 1601 int left, int top, const SkPaint& paint) { |
| 1599 // drawSprite is defined to be in device coords. | 1602 // drawSprite is defined to be in device coords. |
| 1600 CHECK_SHOULD_DRAW(draw); | 1603 CHECK_SHOULD_DRAW(draw); |
| 1601 | 1604 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1626 this->internalDrawSprite(draw, texture, left, top, image.width(), image.heig
ht(), paint); | 1629 this->internalDrawSprite(draw, texture, left, top, image.width(), image.heig
ht(), paint); |
| 1627 } | 1630 } |
| 1628 | 1631 |
| 1629 void SkGpuDevice::internalDrawSprite(const SkDraw& draw, GrTexture* texture, | 1632 void SkGpuDevice::internalDrawSprite(const SkDraw& draw, GrTexture* texture, |
| 1630 int left, int top, int width, int height, | 1633 int left, int top, int width, int height, |
| 1631 const SkPaint& paint) { | 1634 const SkPaint& paint) { |
| 1632 | 1635 |
| 1633 SkAutoTUnref<GrTexture> src(SkRef(texture)); | 1636 SkAutoTUnref<GrTexture> src(SkRef(texture)); |
| 1634 if (SkImageFilter* filter = paint.getImageFilter()) { | 1637 if (SkImageFilter* filter = paint.getImageFilter()) { |
| 1635 // This bitmap will own the filtered result as a texture. | 1638 // This bitmap will own the filtered result as a texture. |
| 1636 SkBitmap filteredBitmap; | 1639 SkAutoTUnref<const SkImage> filteredImage; |
| 1637 SkIPoint offset = SkIPoint::Make(0, 0); | 1640 SkIPoint offset = SkIPoint::Make(0, 0); |
| 1638 SkMatrix matrix(*draw.fMatrix); | 1641 SkMatrix matrix(*draw.fMatrix); |
| 1639 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); | 1642 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); |
| 1640 SkIRect clipBounds = SkIRect::MakeWH(width, height); | 1643 SkIRect clipBounds = SkIRect::MakeWH(width, height); |
| 1641 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); | 1644 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); |
| 1642 // This cache is transient, and is freed (along with all its contained | 1645 // This cache is transient, and is freed (along with all its contained |
| 1643 // textures) when it goes out of scope. | 1646 // textures) when it goes out of scope. |
| 1644 SkImageFilter::Context ctx(matrix, clipBounds, cache); | 1647 SkImageFilter::Context ctx(matrix, clipBounds, cache); |
| 1645 if (this->filterTexture(fContext, texture, filter, ctx, &filteredBitmap, | 1648 if (this->filterTexture(fContext, texture, filter, ctx, filteredImage, |
| 1646 &offset)) { | 1649 &offset)) { |
| 1647 src.reset(SkRef(filteredBitmap.getTexture())); | 1650 src.reset(SkRef(filteredImage->getTexture())); |
| 1648 width = filteredBitmap.width(); | 1651 width = filteredImage->width(); |
| 1649 height = filteredBitmap.height(); | 1652 height = filteredImage->height(); |
| 1650 left += offset.x(); | 1653 left += offset.x(); |
| 1651 top += offset.y(); | 1654 top += offset.y(); |
| 1652 } else { | 1655 } else { |
| 1653 return; | 1656 return; |
| 1654 } | 1657 } |
| 1655 } | 1658 } |
| 1656 | 1659 |
| 1657 GrPaint grPaint; | 1660 GrPaint grPaint; |
| 1658 grPaint.addColorTextureProcessor(src, SkMatrix::I()); | 1661 grPaint.addColorTextureProcessor(src, SkMatrix::I()); |
| 1659 | 1662 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1735 } | 1738 } |
| 1736 GrTexture* devTex = devImage->getTexture(); | 1739 GrTexture* devTex = devImage->getTexture(); |
| 1737 if (NULL == devTex) { | 1740 if (NULL == devTex) { |
| 1738 return; | 1741 return; |
| 1739 } | 1742 } |
| 1740 | 1743 |
| 1741 int w = devImage->width(); | 1744 int w = devImage->width(); |
| 1742 int h = devImage->height(); | 1745 int h = devImage->height(); |
| 1743 | 1746 |
| 1744 SkImageFilter* filter = paint.getImageFilter(); | 1747 SkImageFilter* filter = paint.getImageFilter(); |
| 1745 // This bitmap will own the filtered result as a texture. | 1748 SkAutoTUnref<const SkImage> filteredImage; |
| 1746 SkBitmap filteredBitmap; | |
| 1747 | 1749 |
| 1748 if (filter) { | 1750 if (filter) { |
| 1749 SkIPoint offset = SkIPoint::Make(0, 0); | 1751 SkIPoint offset = SkIPoint::Make(0, 0); |
| 1750 SkMatrix matrix(*draw.fMatrix); | 1752 SkMatrix matrix(*draw.fMatrix); |
| 1751 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); | 1753 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); |
| 1752 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height()); | 1754 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height()); |
| 1753 // This cache is transient, and is freed (along with all its contained | 1755 // This cache is transient, and is freed (along with all its contained |
| 1754 // textures) when it goes out of scope. | 1756 // textures) when it goes out of scope. |
| 1755 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); | 1757 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); |
| 1756 SkImageFilter::Context ctx(matrix, clipBounds, cache); | 1758 SkImageFilter::Context ctx(matrix, clipBounds, cache); |
| 1757 if (this->filterTexture(fContext, devTex, filter, ctx, &filteredBitmap, | 1759 if (this->filterTexture(fContext, devTex, filter, ctx, filteredImage, |
| 1758 &offset)) { | 1760 &offset)) { |
| 1759 devTex = filteredBitmap.getTexture(); | 1761 devTex = filteredImage->getTexture(); |
| 1760 w = filteredBitmap.width(); | 1762 w = filteredImage->width(); |
| 1761 h = filteredBitmap.height(); | 1763 h = filteredImage->height(); |
| 1762 x += offset.fX; | 1764 x += offset.fX; |
| 1763 y += offset.fY; | 1765 y += offset.fY; |
| 1764 } else { | 1766 } else { |
| 1765 return; | 1767 return; |
| 1766 } | 1768 } |
| 1767 } | 1769 } |
| 1768 // drawDevice is defined to be in device coords. | 1770 // drawDevice is defined to be in device coords. |
| 1769 CHECK_SHOULD_DRAW(draw); | 1771 CHECK_SHOULD_DRAW(draw); |
| 1770 | 1772 |
| 1771 GrPaint grPaint; | 1773 GrPaint grPaint; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1785 SK_Scalar1 * h / devTex->height()); | 1787 SK_Scalar1 * h / devTex->height()); |
| 1786 | 1788 |
| 1787 fContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, SkMatrix::I(),
dstRect, | 1789 fContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, SkMatrix::I(),
dstRect, |
| 1788 srcRect); | 1790 srcRect); |
| 1789 } | 1791 } |
| 1790 | 1792 |
| 1791 bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) { | 1793 bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) { |
| 1792 return filter->canFilterImageGPU(); | 1794 return filter->canFilterImageGPU(); |
| 1793 } | 1795 } |
| 1794 | 1796 |
| 1795 bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, | 1797 bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkImage* src, |
| 1796 const SkImageFilter::Context& ctx, | 1798 const SkImageFilter::Context& ctx, |
| 1797 SkBitmap* result, SkIPoint* offset) { | 1799 SkAutoTUnref<const SkImage>& result, SkIPoint* off
set) { |
| 1798 // want explicitly our impl, so guard against a subclass of us overriding it | 1800 // want explicitly our impl, so guard against a subclass of us overriding it |
| 1799 if (!this->SkGpuDevice::canHandleImageFilter(filter)) { | 1801 if (!this->SkGpuDevice::canHandleImageFilter(filter)) { |
| 1800 return false; | 1802 return false; |
| 1801 } | 1803 } |
| 1802 | 1804 |
| 1803 SkAutoLockPixels alp(src, !src.getTexture()); | 1805 //TODO: SkAutoLockPixels alp(src, !src.getTexture()); |
| 1804 if (!src.getTexture() && !src.readyToDraw()) { | 1806 //TODO: if !src->readyToDraw() |
| 1805 return false; | |
| 1806 } | |
| 1807 | 1807 |
| 1808 GrTexture* texture; | 1808 GrTexture* texture; |
| 1809 // We assume here that the filter will not attempt to tile the src. Otherwis
e, this cache lookup | 1809 // We assume here that the filter will not attempt to tile the src. Otherwis
e, this cache lookup |
| 1810 // must be pushed upstack. | 1810 // must be pushed upstack. |
| 1811 AutoBitmapTexture abt(fContext, src, NULL, &texture); | 1811 AutoBitmapTexture abt(fContext, src, NULL, &texture); |
| 1812 if (!texture) { |
| 1813 return false; |
| 1814 } |
| 1812 | 1815 |
| 1813 return this->filterTexture(fContext, texture, filter, ctx, result, offset); | 1816 return this->filterTexture(fContext, texture, filter, ctx, result, offset); |
| 1814 } | 1817 } |
| 1815 | 1818 |
| 1816 /////////////////////////////////////////////////////////////////////////////// | 1819 /////////////////////////////////////////////////////////////////////////////// |
| 1817 | 1820 |
| 1818 // must be in SkCanvas::VertexMode order | 1821 // must be in SkCanvas::VertexMode order |
| 1819 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1822 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
| 1820 kTriangles_GrPrimitiveType, | 1823 kTriangles_GrPrimitiveType, |
| 1821 kTriangleStrip_GrPrimitiveType, | 1824 kTriangleStrip_GrPrimitiveType, |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2113 #endif | 2116 #endif |
| 2114 } | 2117 } |
| 2115 | 2118 |
| 2116 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2119 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 2117 // We always return a transient cache, so it is freed after each | 2120 // We always return a transient cache, so it is freed after each |
| 2118 // filter traversal. | 2121 // filter traversal. |
| 2119 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2122 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 2120 } | 2123 } |
| 2121 | 2124 |
| 2122 #endif | 2125 #endif |
| OLD | NEW |