Chromium Code Reviews| 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 "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "SkDrawProcs.h" | 23 #include "SkDrawProcs.h" |
| 24 #include "SkErrorInternals.h" | 24 #include "SkErrorInternals.h" |
| 25 #include "SkGlyphCache.h" | 25 #include "SkGlyphCache.h" |
| 26 #include "SkGrTexturePixelRef.h" | 26 #include "SkGrTexturePixelRef.h" |
| 27 #include "SkGr.h" | 27 #include "SkGr.h" |
| 28 #include "SkGrPriv.h" | 28 #include "SkGrPriv.h" |
| 29 #include "SkImage_Base.h" | 29 #include "SkImage_Base.h" |
| 30 #include "SkImageFilter.h" | 30 #include "SkImageFilter.h" |
| 31 #include "SkLayerInfo.h" | 31 #include "SkLayerInfo.h" |
| 32 #include "SkMaskFilter.h" | 32 #include "SkMaskFilter.h" |
| 33 #include "SkNinePatchIter.h" | |
| 33 #include "SkPathEffect.h" | 34 #include "SkPathEffect.h" |
| 34 #include "SkPicture.h" | 35 #include "SkPicture.h" |
| 35 #include "SkPictureData.h" | 36 #include "SkPictureData.h" |
| 36 #include "SkRRect.h" | 37 #include "SkRRect.h" |
| 37 #include "SkRecord.h" | 38 #include "SkRecord.h" |
| 38 #include "SkStroke.h" | 39 #include "SkStroke.h" |
| 39 #include "SkSurface.h" | 40 #include "SkSurface.h" |
| 40 #include "SkSurface_Gpu.h" | 41 #include "SkSurface_Gpu.h" |
| 41 #include "SkTLazy.h" | 42 #include "SkTLazy.h" |
| 42 #include "SkUtils.h" | 43 #include "SkUtils.h" |
| (...skipping 1677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1720 return; | 1721 return; |
| 1721 } | 1722 } |
| 1722 } else { | 1723 } else { |
| 1723 if (!wrap_as_bm(this->context(), image, &bm)) { | 1724 if (!wrap_as_bm(this->context(), image, &bm)) { |
| 1724 return; | 1725 return; |
| 1725 } | 1726 } |
| 1726 } | 1727 } |
| 1727 this->drawBitmapRect(draw, bm, src, dst, paint, constraint); | 1728 this->drawBitmapRect(draw, bm, src, dst, paint, constraint); |
| 1728 } | 1729 } |
| 1729 | 1730 |
| 1731 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, const SkIRect& center, | |
| 1732 const SkRect& dst, const SkPaint& paint) { | |
| 1733 | |
| 1734 SkBitmap bitmap; | |
| 1735 if (!wrap_as_bm(this->context(), image, &bitmap)) { | |
|
bsalomon
2015/11/17 22:26:09
Let's do a real impl here... this has a malloc hid
joshualitt
2015/11/18 17:46:15
per conversation, lets defer until you finish what
| |
| 1736 return; | |
| 1737 } | |
| 1738 | |
| 1739 this->drawBitmapNine(draw, bitmap, center, dst, paint); | |
| 1740 } | |
| 1741 | |
| 1742 void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, con st SkIRect& center, | |
| 1743 const SkRect& dst, const SkPaint& paint) { | |
| 1744 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawBitmapNine", fContext); | |
| 1745 | |
| 1746 CHECK_FOR_ANNOTATION(paint); | |
| 1747 CHECK_SHOULD_DRAW(draw); | |
| 1748 | |
|
bsalomon
2015/11/17 22:26:09
Let's just fail if the bitmap is texture backed. D
joshualitt
2015/11/18 17:46:15
we can't because it seems that wrap_as_bm seems to
| |
| 1749 bool useFallback = paint.getMaskFilter() || paint.isAntiAlias(); | |
| 1750 bool doBicubic; | |
| 1751 GrTextureParams::FilterMode textureFilterMode = | |
| 1752 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMat rix, SkMatrix::I(), | |
| 1753 &doBicubic); | |
| 1754 | |
| 1755 // TODO handle bilerp | |
| 1756 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture FilterMode) { | |
| 1757 SkNinePatchIter iter(bitmap.width(), bitmap.height(), center, dst); | |
| 1758 | |
| 1759 SkRect srcR, dstR; | |
| 1760 while (iter.next(&srcR, &dstR)) { | |
| 1761 this->drawBitmapRect(draw, bitmap, &srcR, dstR, paint, | |
| 1762 SkCanvas::kStrict_SrcRectConstraint); | |
| 1763 } | |
| 1764 return; | |
| 1765 } | |
| 1766 | |
| 1767 GrTextureParams params; | |
| 1768 if (GrTextureParams::kBilerp_FilterMode == textureFilterMode) { | |
| 1769 params = GrTextureParams::ClampBilerp(); | |
| 1770 } else { | |
| 1771 params = GrTextureParams::ClampNoFilter(); | |
| 1772 } | |
| 1773 | |
| 1774 GrTexture* texture; | |
| 1775 AutoBitmapTexture abt(fContext, bitmap, params, &texture); | |
|
bsalomon
2015/11/17 22:26:09
Let's not expand the use of this. It used to do a
joshualitt
2015/11/18 17:46:15
Acknowledged.
| |
| 1776 if (nullptr == texture) { | |
| 1777 return; | |
| 1778 } | |
| 1779 | |
| 1780 // TODO Brian, help? | |
| 1781 SkMatrix texMatrix = SkMatrix::I(); | |
|
bsalomon
2015/11/17 22:26:09
SkMatrix texMatrix;
texMatrix.setIDiv(texture->wid
joshualitt
2015/11/18 17:46:15
Acknowledged.
| |
| 1782 | |
| 1783 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); | |
| 1784 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); | |
| 1785 texMatrix.setScale(wInv, hInv); | |
| 1786 | |
| 1787 SkAutoTUnref<const GrFragmentProcessor> fp(GrSimpleTextureEffect::Create(tex ture, texMatrix, | |
| 1788 par ams)); | |
| 1789 SkAutoTUnref<const GrFragmentProcessor> shaderFP; | |
| 1790 | |
| 1791 if (kAlpha_8_SkColorType == bitmap.colorType()) { | |
|
bsalomon
2015/11/17 22:26:09
we do this logic in a bunch of places.. maybe this
joshualitt
2015/11/18 17:46:15
Acknowledged.
| |
| 1792 if (const SkShader* shader = paint.getShader()) { | |
| 1793 shaderFP.reset(shader->asFragmentProcessor(this->context(), | |
| 1794 *draw.fMatrix, | |
| 1795 nullptr, | |
| 1796 paint.getFilterQuality()) ); | |
| 1797 if (!shaderFP) { | |
| 1798 return; | |
| 1799 } | |
| 1800 const GrFragmentProcessor* fpSeries[] = { shaderFP.get(), fp.get() } ; | |
| 1801 fp.reset(GrFragmentProcessor::RunInSeries(fpSeries, 2)); | |
| 1802 } else { | |
| 1803 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); | |
| 1804 } | |
| 1805 } else { | |
| 1806 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); | |
| 1807 } | |
| 1808 | |
| 1809 GrPaint grPaint; | |
| 1810 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) { | |
| 1811 return; | |
| 1812 } | |
| 1813 | |
| 1814 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, bitmap.width(), b itmap.height(), | |
| 1815 center, dst); | |
| 1816 } | |
| 1817 | |
| 1730 /////////////////////////////////////////////////////////////////////////////// | 1818 /////////////////////////////////////////////////////////////////////////////// |
| 1731 | 1819 |
| 1732 // must be in SkCanvas::VertexMode order | 1820 // must be in SkCanvas::VertexMode order |
| 1733 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1821 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
| 1734 kTriangles_GrPrimitiveType, | 1822 kTriangles_GrPrimitiveType, |
| 1735 kTriangleStrip_GrPrimitiveType, | 1823 kTriangleStrip_GrPrimitiveType, |
| 1736 kTriangleFan_GrPrimitiveType, | 1824 kTriangleFan_GrPrimitiveType, |
| 1737 }; | 1825 }; |
| 1738 | 1826 |
| 1739 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, | 1827 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2067 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2155 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 2068 } | 2156 } |
| 2069 | 2157 |
| 2070 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2158 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 2071 // We always return a transient cache, so it is freed after each | 2159 // We always return a transient cache, so it is freed after each |
| 2072 // filter traversal. | 2160 // filter traversal. |
| 2073 return SkGpuDevice::NewImageFilterCache(); | 2161 return SkGpuDevice::NewImageFilterCache(); |
| 2074 } | 2162 } |
| 2075 | 2163 |
| 2076 #endif | 2164 #endif |
| OLD | NEW |