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

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

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