| 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 326 |
| 327 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { | 327 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { |
| 328 // Caller must have accessed the render target, because it knows the rt must
be replaced. | 328 // Caller must have accessed the render target, because it knows the rt must
be replaced. |
| 329 SkASSERT(!fNeedClear); | 329 SkASSERT(!fNeedClear); |
| 330 | 330 |
| 331 SkSurface::Budgeted budgeted = | 331 SkSurface::Budgeted budgeted = |
| 332 fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgete
d | 332 fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgete
d |
| 333 : SkSurface::kNo_Budgeted
; | 333 : SkSurface::kNo_Budgeted
; |
| 334 | 334 |
| 335 SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( | 335 SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( |
| 336 fRenderTarget->getContext(), budgeted, this->imageInfo(), fRenderTarget-
>numSamples())); | 336 fRenderTarget->getContext(), budgeted, this->imageInfo(), fRenderTarget-
>desc().fSampleCnt)); |
| 337 | 337 |
| 338 if (NULL == newRT) { | 338 if (NULL == newRT) { |
| 339 return; | 339 return; |
| 340 } | 340 } |
| 341 | 341 |
| 342 if (shouldRetainContent) { | 342 if (shouldRetainContent) { |
| 343 if (fRenderTarget->wasDestroyed()) { | 343 if (fRenderTarget->wasDestroyed()) { |
| 344 return; | 344 return; |
| 345 } | 345 } |
| 346 this->context()->copySurface(newRT, fRenderTarget); | 346 this->context()->copySurface(newRT, fRenderTarget); |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 srcRect.fRight >= width && srcRect.fBottom >= height) { | 912 srcRect.fRight >= width && srcRect.fBottom >= height) { |
| 913 flags = (SkCanvas::DrawBitmapRectFlags) (flags | SkCanvas::kBleed_DrawBi
tmapRectFlag); | 913 flags = (SkCanvas::DrawBitmapRectFlags) (flags | SkCanvas::kBleed_DrawBi
tmapRectFlag); |
| 914 } | 914 } |
| 915 | 915 |
| 916 // If the render target is not msaa and draw is antialiased, we call | 916 // If the render target is not msaa and draw is antialiased, we call |
| 917 // drawRect instead of drawing on the render target directly. | 917 // drawRect instead of drawing on the render target directly. |
| 918 // FIXME: the tiled bitmap code path doesn't currently support | 918 // FIXME: the tiled bitmap code path doesn't currently support |
| 919 // anti-aliased edges, we work around that for now by drawing directly | 919 // anti-aliased edges, we work around that for now by drawing directly |
| 920 // if the image size exceeds maximum texture size. | 920 // if the image size exceeds maximum texture size. |
| 921 int maxTextureSize = fContext->caps()->maxTextureSize(); | 921 int maxTextureSize = fContext->caps()->maxTextureSize(); |
| 922 bool directDraw = fRenderTarget->isMultisampled() || | 922 bool directDraw = fRenderTarget->isUnifiedMultisampled() || |
| 923 !paint.isAntiAlias() || | 923 !paint.isAntiAlias() || |
| 924 bitmap.width() > maxTextureSize || | 924 bitmap.width() > maxTextureSize || |
| 925 bitmap.height() > maxTextureSize; | 925 bitmap.height() > maxTextureSize; |
| 926 | 926 |
| 927 // we check whether dst rect are pixel aligned | 927 // we check whether dst rect are pixel aligned |
| 928 if (!directDraw) { | 928 if (!directDraw) { |
| 929 bool staysRect = draw.fMatrix->rectStaysRect(); | 929 bool staysRect = draw.fMatrix->rectStaysRect(); |
| 930 | 930 |
| 931 if (staysRect) { | 931 if (staysRect) { |
| 932 SkRect rect; | 932 SkRect rect; |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 } | 1683 } |
| 1684 | 1684 |
| 1685 /////////////////////////////////////////////////////////////////////////////// | 1685 /////////////////////////////////////////////////////////////////////////////// |
| 1686 | 1686 |
| 1687 SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint
*) { | 1687 SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint
*) { |
| 1688 GrSurfaceDesc desc; | 1688 GrSurfaceDesc desc; |
| 1689 desc.fConfig = fRenderTarget->config(); | 1689 desc.fConfig = fRenderTarget->config(); |
| 1690 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 1690 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 1691 desc.fWidth = cinfo.fInfo.width(); | 1691 desc.fWidth = cinfo.fInfo.width(); |
| 1692 desc.fHeight = cinfo.fInfo.height(); | 1692 desc.fHeight = cinfo.fInfo.height(); |
| 1693 desc.fSampleCnt = fRenderTarget->numSamples(); | 1693 desc.fSampleCnt = fRenderTarget->desc().fSampleCnt; |
| 1694 | 1694 |
| 1695 SkAutoTUnref<GrTexture> texture; | 1695 SkAutoTUnref<GrTexture> texture; |
| 1696 // Skia's convention is to only clear a device if it is non-opaque. | 1696 // Skia's convention is to only clear a device if it is non-opaque. |
| 1697 unsigned flags = cinfo.fInfo.isOpaque() ? 0 : kNeedClear_Flag; | 1697 unsigned flags = cinfo.fInfo.isOpaque() ? 0 : kNeedClear_Flag; |
| 1698 | 1698 |
| 1699 // layers are never draw in repeat modes, so we can request an approx | 1699 // layers are never draw in repeat modes, so we can request an approx |
| 1700 // match and ignore any padding. | 1700 // match and ignore any padding. |
| 1701 const GrTextureProvider::ScratchTexMatch match = (kNever_TileUsage == cinfo.
fTileUsage) ? | 1701 const GrTextureProvider::ScratchTexMatch match = (kNever_TileUsage == cinfo.
fTileUsage) ? |
| 1702 GrTextureProvider::kApprox_Scr
atchTexMatch : | 1702 GrTextureProvider::kApprox_Scr
atchTexMatch : |
| 1703 GrTextureProvider::kExact_Scra
tchTexMatch; | 1703 GrTextureProvider::kExact_Scra
tchTexMatch; |
| 1704 texture.reset(fContext->textureProvider()->refScratchTexture(desc, match)); | 1704 texture.reset(fContext->textureProvider()->refScratchTexture(desc, match)); |
| 1705 | 1705 |
| 1706 if (texture) { | 1706 if (texture) { |
| 1707 SkSurfaceProps props(fSurfaceProps.flags(), cinfo.fPixelGeometry); | 1707 SkSurfaceProps props(fSurfaceProps.flags(), cinfo.fPixelGeometry); |
| 1708 return SkGpuDevice::Create( | 1708 return SkGpuDevice::Create( |
| 1709 texture->asRenderTarget(), cinfo.fInfo.width(), cinfo.fInfo.height()
, &props, flags); | 1709 texture->asRenderTarget(), cinfo.fInfo.width(), cinfo.fInfo.height()
, &props, flags); |
| 1710 } else { | 1710 } else { |
| 1711 SkErrorInternals::SetError( kInternalError_SkError, | 1711 SkErrorInternals::SetError( kInternalError_SkError, |
| 1712 "---- failed to create gpu device texture [%
d %d]\n", | 1712 "---- failed to create gpu device texture [%
d %d]\n", |
| 1713 cinfo.fInfo.width(), cinfo.fInfo.height()); | 1713 cinfo.fInfo.width(), cinfo.fInfo.height()); |
| 1714 return NULL; | 1714 return NULL; |
| 1715 } | 1715 } |
| 1716 } | 1716 } |
| 1717 | 1717 |
| 1718 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps
& props) { | 1718 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps
& props) { |
| 1719 // TODO: Change the signature of newSurface to take a budgeted parameter. | 1719 // TODO: Change the signature of newSurface to take a budgeted parameter. |
| 1720 static const SkSurface::Budgeted kBudgeted = SkSurface::kNo_Budgeted; | 1720 static const SkSurface::Budgeted kBudgeted = SkSurface::kNo_Budgeted; |
| 1721 return SkSurface::NewRenderTarget(fContext, kBudgeted, info, fRenderTarget->
numSamples(), | 1721 return SkSurface::NewRenderTarget(fContext, kBudgeted, info, fRenderTarget->
desc().fSampleCnt, |
| 1722 &props); | 1722 &props); |
| 1723 } | 1723 } |
| 1724 | 1724 |
| 1725 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
* mainPicture, | 1725 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
* mainPicture, |
| 1726 const SkMatrix* matrix, const SkPaint
* paint) { | 1726 const SkMatrix* matrix, const SkPaint
* paint) { |
| 1727 #ifndef SK_IGNORE_GPU_LAYER_HOISTING | 1727 #ifndef SK_IGNORE_GPU_LAYER_HOISTING |
| 1728 // todo: should handle this natively | 1728 // todo: should handle this natively |
| 1729 if (paint) { | 1729 if (paint) { |
| 1730 return false; | 1730 return false; |
| 1731 } | 1731 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1751 } | 1751 } |
| 1752 | 1752 |
| 1753 SkRect clipBounds = SkRect::Make(iBounds); | 1753 SkRect clipBounds = SkRect::Make(iBounds); |
| 1754 | 1754 |
| 1755 SkMatrix initialMatrix = mainCanvas->getTotalMatrix(); | 1755 SkMatrix initialMatrix = mainCanvas->getTotalMatrix(); |
| 1756 | 1756 |
| 1757 GrLayerHoister::FindLayersToAtlas(fContext, mainPicture, | 1757 GrLayerHoister::FindLayersToAtlas(fContext, mainPicture, |
| 1758 initialMatrix, | 1758 initialMatrix, |
| 1759 clipBounds, | 1759 clipBounds, |
| 1760 &atlasedNeedRendering, &atlasedRecycled, | 1760 &atlasedNeedRendering, &atlasedRecycled, |
| 1761 fRenderTarget->numSamples()); | 1761 fRenderTarget->numColorSamples()); |
| 1762 | 1762 |
| 1763 GrLayerHoister::DrawLayersToAtlas(fContext, atlasedNeedRendering); | 1763 GrLayerHoister::DrawLayersToAtlas(fContext, atlasedNeedRendering); |
| 1764 | 1764 |
| 1765 SkTDArray<GrHoistedLayer> needRendering, recycled; | 1765 SkTDArray<GrHoistedLayer> needRendering, recycled; |
| 1766 | 1766 |
| 1767 SkAutoCanvasMatrixPaint acmp(mainCanvas, matrix, paint, mainPicture->cullRec
t()); | 1767 SkAutoCanvasMatrixPaint acmp(mainCanvas, matrix, paint, mainPicture->cullRec
t()); |
| 1768 | 1768 |
| 1769 GrLayerHoister::FindLayersToHoist(fContext, mainPicture, | 1769 GrLayerHoister::FindLayersToHoist(fContext, mainPicture, |
| 1770 initialMatrix, | 1770 initialMatrix, |
| 1771 clipBounds, | 1771 clipBounds, |
| 1772 &needRendering, &recycled, | 1772 &needRendering, &recycled, |
| 1773 fRenderTarget->numSamples()); | 1773 fRenderTarget->numColorSamples()); |
| 1774 | 1774 |
| 1775 GrLayerHoister::DrawLayers(fContext, needRendering); | 1775 GrLayerHoister::DrawLayers(fContext, needRendering); |
| 1776 | 1776 |
| 1777 // Render the entire picture using new layers | 1777 // Render the entire picture using new layers |
| 1778 GrRecordReplaceDraw(mainPicture, mainCanvas, fContext->getLayerCache(), | 1778 GrRecordReplaceDraw(mainPicture, mainCanvas, fContext->getLayerCache(), |
| 1779 initialMatrix, NULL); | 1779 initialMatrix, NULL); |
| 1780 | 1780 |
| 1781 GrLayerHoister::UnlockLayers(fContext, needRendering); | 1781 GrLayerHoister::UnlockLayers(fContext, needRendering); |
| 1782 GrLayerHoister::UnlockLayers(fContext, recycled); | 1782 GrLayerHoister::UnlockLayers(fContext, recycled); |
| 1783 GrLayerHoister::UnlockLayers(fContext, atlasedNeedRendering); | 1783 GrLayerHoister::UnlockLayers(fContext, atlasedNeedRendering); |
| 1784 GrLayerHoister::UnlockLayers(fContext, atlasedRecycled); | 1784 GrLayerHoister::UnlockLayers(fContext, atlasedRecycled); |
| 1785 | 1785 |
| 1786 return true; | 1786 return true; |
| 1787 #else | 1787 #else |
| 1788 return false; | 1788 return false; |
| 1789 #endif | 1789 #endif |
| 1790 } | 1790 } |
| 1791 | 1791 |
| 1792 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1792 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1793 // We always return a transient cache, so it is freed after each | 1793 // We always return a transient cache, so it is freed after each |
| 1794 // filter traversal. | 1794 // filter traversal. |
| 1795 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1795 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 1796 } | 1796 } |
| 1797 | 1797 |
| 1798 #endif | 1798 #endif |
| OLD | NEW |