Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: src/gpu/SkGpuDevice.cpp

Issue 1954103002: Revert of Retract GrRenderTarget a bit within SkGpuDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/gpu/GrDrawContext.h ('k') | src/image/SkSurface_Gpu.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 737
738 if (maxTileTotalTileSize > 2 * smallTotalTileSize) { 738 if (maxTileTotalTileSize > 2 * smallTotalTileSize) {
739 return kBmpSmallTileSize; 739 return kBmpSmallTileSize;
740 } else { 740 } else {
741 return maxTileSize; 741 return maxTileSize;
742 } 742 }
743 } 743 }
744 744
745 // Given a bitmap, an optional src rect, and a context with a clip and matrix de termine what 745 // Given a bitmap, an optional src rect, and a context with a clip and matrix de termine what
746 // pixels from the bitmap are necessary. 746 // pixels from the bitmap are necessary.
747 static void determine_clipped_src_rect(int width, int height, 747 static void determine_clipped_src_rect(const GrRenderTarget* rt,
748 const GrClip& clip, 748 const GrClip& clip,
749 const SkMatrix& viewMatrix, 749 const SkMatrix& viewMatrix,
750 const SkISize& imageSize, 750 const SkISize& imageSize,
751 const SkRect* srcRectPtr, 751 const SkRect* srcRectPtr,
752 SkIRect* clippedSrcIRect) { 752 SkIRect* clippedSrcIRect) {
753 clip.getConservativeBounds(width, height, clippedSrcIRect, nullptr); 753 clip.getConservativeBounds(rt->width(), rt->height(), clippedSrcIRect, nullp tr);
754 SkMatrix inv; 754 SkMatrix inv;
755 if (!viewMatrix.invert(&inv)) { 755 if (!viewMatrix.invert(&inv)) {
756 clippedSrcIRect->setEmpty(); 756 clippedSrcIRect->setEmpty();
757 return; 757 return;
758 } 758 }
759 SkRect clippedSrcRect = SkRect::Make(*clippedSrcIRect); 759 SkRect clippedSrcRect = SkRect::Make(*clippedSrcIRect);
760 inv.mapRect(&clippedSrcRect); 760 inv.mapRect(&clippedSrcRect);
761 if (srcRectPtr) { 761 if (srcRectPtr) {
762 // we've setup src space 0,0 to map to the top left of the src rect. 762 // we've setup src space 0,0 to map to the top left of the src rect.
763 clippedSrcRect.offset(srcRectPtr->fLeft, srcRectPtr->fTop); 763 clippedSrcRect.offset(srcRectPtr->fLeft, srcRectPtr->fTop);
(...skipping 12 matching lines...) Expand all
776 bool SkGpuDevice::shouldTileImageID(uint32_t imageID, const SkIRect& imageRect, 776 bool SkGpuDevice::shouldTileImageID(uint32_t imageID, const SkIRect& imageRect,
777 const SkMatrix& viewMatrix, 777 const SkMatrix& viewMatrix,
778 const GrTextureParams& params, 778 const GrTextureParams& params,
779 const SkRect* srcRectPtr, 779 const SkRect* srcRectPtr,
780 int maxTileSize, 780 int maxTileSize,
781 int* tileSize, 781 int* tileSize,
782 SkIRect* clippedSubset) const { 782 SkIRect* clippedSubset) const {
783 ASSERT_SINGLE_OWNER 783 ASSERT_SINGLE_OWNER
784 // if it's larger than the max tile size, then we have no choice but tiling. 784 // if it's larger than the max tile size, then we have no choice but tiling.
785 if (imageRect.width() > maxTileSize || imageRect.height() > maxTileSize) { 785 if (imageRect.width() > maxTileSize || imageRect.height() > maxTileSize) {
786 determine_clipped_src_rect(fDrawContext->width(), fDrawContext->height() , 786 determine_clipped_src_rect(fRenderTarget, fClip, viewMatrix, imageRect.s ize(),
787 fClip, viewMatrix, imageRect.size(),
788 srcRectPtr, clippedSubset); 787 srcRectPtr, clippedSubset);
789 *tileSize = determine_tile_size(*clippedSubset, maxTileSize); 788 *tileSize = determine_tile_size(*clippedSubset, maxTileSize);
790 return true; 789 return true;
791 } 790 }
792 791
793 // If the image would only produce 4 tiles of the smaller size, don't bother tiling it. 792 // If the image would only produce 4 tiles of the smaller size, don't bother tiling it.
794 const size_t area = imageRect.width() * imageRect.height(); 793 const size_t area = imageRect.width() * imageRect.height();
795 if (area < 4 * kBmpSmallTileSize * kBmpSmallTileSize) { 794 if (area < 4 * kBmpSmallTileSize * kBmpSmallTileSize) {
796 return false; 795 return false;
797 } 796 }
798 797
799 // At this point we know we could do the draw by uploading the entire bitmap 798 // At this point we know we could do the draw by uploading the entire bitmap
800 // as a texture. However, if the texture would be large compared to the 799 // as a texture. However, if the texture would be large compared to the
801 // cache size and we don't require most of it for this draw then tile to 800 // cache size and we don't require most of it for this draw then tile to
802 // reduce the amount of upload and cache spill. 801 // reduce the amount of upload and cache spill.
803 802
804 // assumption here is that sw bitmap size is a good proxy for its size as 803 // assumption here is that sw bitmap size is a good proxy for its size as
805 // a texture 804 // a texture
806 size_t bmpSize = area * sizeof(SkPMColor); // assume 32bit pixels 805 size_t bmpSize = area * sizeof(SkPMColor); // assume 32bit pixels
807 size_t cacheSize; 806 size_t cacheSize;
808 fContext->getResourceCacheLimits(nullptr, &cacheSize); 807 fContext->getResourceCacheLimits(nullptr, &cacheSize);
809 if (bmpSize < cacheSize / 2) { 808 if (bmpSize < cacheSize / 2) {
810 return false; 809 return false;
811 } 810 }
812 811
813 // Figure out how much of the src we will need based on the src rect and cli pping. Reject if 812 // Figure out how much of the src we will need based on the src rect and cli pping. Reject if
814 // tiling memory savings would be < 50%. 813 // tiling memory savings would be < 50%.
815 determine_clipped_src_rect(fDrawContext->width(), fDrawContext->height(), 814 determine_clipped_src_rect(fRenderTarget, fClip, viewMatrix, imageRect.size( ), srcRectPtr,
816 fClip, viewMatrix, imageRect.size(), srcRectPtr,
817 clippedSubset); 815 clippedSubset);
818 *tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile. 816 *tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile.
819 size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) * 817 size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) *
820 kBmpSmallTileSize * kBmpSmallTileSize; 818 kBmpSmallTileSize * kBmpSmallTileSize;
821 819
822 return usedTileBytes < 2 * bmpSize; 820 return usedTileBytes < 2 * bmpSize;
823 } 821 }
824 822
825 bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap, 823 bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap,
826 const SkMatrix& viewMatrix, 824 const SkMatrix& viewMatrix,
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 "---- failed to create gpu device texture [% d %d]\n", 1766 "---- failed to create gpu device texture [% d %d]\n",
1769 cinfo.fInfo.width(), cinfo.fInfo.height()); 1767 cinfo.fInfo.width(), cinfo.fInfo.height());
1770 return nullptr; 1768 return nullptr;
1771 } 1769 }
1772 } 1770 }
1773 1771
1774 sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa ceProps& props) { 1772 sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa ceProps& props) {
1775 ASSERT_SINGLE_OWNER 1773 ASSERT_SINGLE_OWNER
1776 // TODO: Change the signature of newSurface to take a budgeted parameter. 1774 // TODO: Change the signature of newSurface to take a budgeted parameter.
1777 static const SkBudgeted kBudgeted = SkBudgeted::kNo; 1775 static const SkBudgeted kBudgeted = SkBudgeted::kNo;
1778 return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fDrawContext-> numColorSamples(), 1776 return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fRenderTarget- >desc().fSampleCnt,
1779 &props); 1777 &props);
1780 } 1778 }
1781 1779
1782 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture * mainPicture, 1780 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture * mainPicture,
1783 const SkMatrix* matrix, const SkPaint * paint) { 1781 const SkMatrix* matrix, const SkPaint * paint) {
1784 ASSERT_SINGLE_OWNER 1782 ASSERT_SINGLE_OWNER
1785 #ifndef SK_IGNORE_GPU_LAYER_HOISTING 1783 #ifndef SK_IGNORE_GPU_LAYER_HOISTING
1786 // todo: should handle this natively 1784 // todo: should handle this natively
1787 if (paint) { 1785 if (paint) {
1788 return false; 1786 return false;
(...skipping 22 matching lines...) Expand all
1811 SkRect clipBounds = SkRect::Make(iBounds); 1809 SkRect clipBounds = SkRect::Make(iBounds);
1812 1810
1813 SkMatrix initialMatrix = mainCanvas->getTotalMatrix(); 1811 SkMatrix initialMatrix = mainCanvas->getTotalMatrix();
1814 1812
1815 GrLayerHoister::Begin(fContext); 1813 GrLayerHoister::Begin(fContext);
1816 1814
1817 GrLayerHoister::FindLayersToAtlas(fContext, mainPicture, 1815 GrLayerHoister::FindLayersToAtlas(fContext, mainPicture,
1818 initialMatrix, 1816 initialMatrix,
1819 clipBounds, 1817 clipBounds,
1820 &atlasedNeedRendering, &atlasedRecycled, 1818 &atlasedNeedRendering, &atlasedRecycled,
1821 fDrawContext->numColorSamples()); 1819 fRenderTarget->numColorSamples());
1822 1820
1823 GrLayerHoister::DrawLayersToAtlas(fContext, atlasedNeedRendering); 1821 GrLayerHoister::DrawLayersToAtlas(fContext, atlasedNeedRendering);
1824 1822
1825 SkTDArray<GrHoistedLayer> needRendering, recycled; 1823 SkTDArray<GrHoistedLayer> needRendering, recycled;
1826 1824
1827 SkAutoCanvasMatrixPaint acmp(mainCanvas, matrix, paint, mainPicture->cullRec t()); 1825 SkAutoCanvasMatrixPaint acmp(mainCanvas, matrix, paint, mainPicture->cullRec t());
1828 1826
1829 GrLayerHoister::FindLayersToHoist(fContext, mainPicture, 1827 GrLayerHoister::FindLayersToHoist(fContext, mainPicture,
1830 initialMatrix, 1828 initialMatrix,
1831 clipBounds, 1829 clipBounds,
1832 &needRendering, &recycled, 1830 &needRendering, &recycled,
1833 fDrawContext->numColorSamples()); 1831 fRenderTarget->numColorSamples());
1834 1832
1835 GrLayerHoister::DrawLayers(fContext, needRendering); 1833 GrLayerHoister::DrawLayers(fContext, needRendering);
1836 1834
1837 // Render the entire picture using new layers 1835 // Render the entire picture using new layers
1838 GrRecordReplaceDraw(mainPicture, mainCanvas, fContext->getLayerCache(), 1836 GrRecordReplaceDraw(mainPicture, mainCanvas, fContext->getLayerCache(),
1839 initialMatrix, nullptr); 1837 initialMatrix, nullptr);
1840 1838
1841 GrLayerHoister::UnlockLayers(fContext, needRendering); 1839 GrLayerHoister::UnlockLayers(fContext, needRendering);
1842 GrLayerHoister::UnlockLayers(fContext, recycled); 1840 GrLayerHoister::UnlockLayers(fContext, recycled);
1843 GrLayerHoister::UnlockLayers(fContext, atlasedNeedRendering); 1841 GrLayerHoister::UnlockLayers(fContext, atlasedNeedRendering);
1844 GrLayerHoister::UnlockLayers(fContext, atlasedRecycled); 1842 GrLayerHoister::UnlockLayers(fContext, atlasedRecycled);
1845 GrLayerHoister::End(fContext); 1843 GrLayerHoister::End(fContext);
1846 1844
1847 return true; 1845 return true;
1848 #else 1846 #else
1849 return false; 1847 return false;
1850 #endif 1848 #endif
1851 } 1849 }
1852 1850
1853 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { 1851 SkImageFilterCache* SkGpuDevice::getImageFilterCache() {
1854 ASSERT_SINGLE_OWNER 1852 ASSERT_SINGLE_OWNER
1855 // We always return a transient cache, so it is freed after each 1853 // We always return a transient cache, so it is freed after each
1856 // filter traversal. 1854 // filter traversal.
1857 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); 1855 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize);
1858 } 1856 }
1859 1857
1860 #endif 1858 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrDrawContext.h ('k') | src/image/SkSurface_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698