| 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 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 int* tileSize, | 751 int* tileSize, |
| 752 SkIRect* clippedSubset) const { | 752 SkIRect* clippedSubset) const { |
| 753 // if it's larger than the max tile size, then we have no choice but tiling. | 753 // if it's larger than the max tile size, then we have no choice but tiling. |
| 754 if (imageRect.width() > maxTileSize || imageRect.height() > maxTileSize) { | 754 if (imageRect.width() > maxTileSize || imageRect.height() > maxTileSize) { |
| 755 determine_clipped_src_rect(fRenderTarget, fClip, viewMatrix, imageRect.s
ize(), | 755 determine_clipped_src_rect(fRenderTarget, fClip, viewMatrix, imageRect.s
ize(), |
| 756 srcRectPtr, clippedSubset); | 756 srcRectPtr, clippedSubset); |
| 757 *tileSize = determine_tile_size(*clippedSubset, maxTileSize); | 757 *tileSize = determine_tile_size(*clippedSubset, maxTileSize); |
| 758 return true; | 758 return true; |
| 759 } | 759 } |
| 760 | 760 |
| 761 // If the image would only produce 4 tiles of the smaller size, don't bother
tiling it. |
| 761 const size_t area = imageRect.width() * imageRect.height(); | 762 const size_t area = imageRect.width() * imageRect.height(); |
| 762 if (area < 4 * kBmpSmallTileSize * kBmpSmallTileSize) { | 763 if (area < 4 * kBmpSmallTileSize * kBmpSmallTileSize) { |
| 763 return false; | 764 return false; |
| 764 } | 765 } |
| 765 | 766 |
| 766 // if the entire image/bitmap is already in our cache then no reason to tile
it | |
| 767 if (GrIsImageInCache(fContext, imageID, imageRect, nullptr, params)) { | |
| 768 return false; | |
| 769 } | |
| 770 | |
| 771 // At this point we know we could do the draw by uploading the entire bitmap | 767 // At this point we know we could do the draw by uploading the entire bitmap |
| 772 // as a texture. However, if the texture would be large compared to the | 768 // as a texture. However, if the texture would be large compared to the |
| 773 // cache size and we don't require most of it for this draw then tile to | 769 // cache size and we don't require most of it for this draw then tile to |
| 774 // reduce the amount of upload and cache spill. | 770 // reduce the amount of upload and cache spill. |
| 775 | 771 |
| 776 // assumption here is that sw bitmap size is a good proxy for its size as | 772 // assumption here is that sw bitmap size is a good proxy for its size as |
| 777 // a texture | 773 // a texture |
| 778 size_t bmpSize = area * sizeof(SkPMColor); // assume 32bit pixels | 774 size_t bmpSize = area * sizeof(SkPMColor); // assume 32bit pixels |
| 779 size_t cacheSize; | 775 size_t cacheSize; |
| 780 fContext->getResourceCacheLimits(nullptr, &cacheSize); | 776 fContext->getResourceCacheLimits(nullptr, &cacheSize); |
| 781 if (bmpSize < cacheSize / 2) { | 777 if (bmpSize < cacheSize / 2) { |
| 782 return false; | 778 return false; |
| 783 } | 779 } |
| 784 | 780 |
| 785 // Figure out how much of the src we will need based on the src rect and cli
pping. | 781 // Figure out how much of the src we will need based on the src rect and cli
pping. Reject if |
| 782 // tiling memory savings would be < 50%. |
| 786 determine_clipped_src_rect(fRenderTarget, fClip, viewMatrix, imageRect.size(
), srcRectPtr, | 783 determine_clipped_src_rect(fRenderTarget, fClip, viewMatrix, imageRect.size(
), srcRectPtr, |
| 787 clippedSubset); | 784 clippedSubset); |
| 788 *tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max
sized tile. | 785 *tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max
sized tile. |
| 789 size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) * | 786 size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) * |
| 790 kBmpSmallTileSize * kBmpSmallTileSize; | 787 kBmpSmallTileSize * kBmpSmallTileSize; |
| 791 | 788 |
| 792 return usedTileBytes < 2 * bmpSize; | 789 return usedTileBytes < 2 * bmpSize; |
| 793 } | 790 } |
| 794 | 791 |
| 795 bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap, | 792 bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap, |
| (...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2019 #endif | 2016 #endif |
| 2020 } | 2017 } |
| 2021 | 2018 |
| 2022 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2019 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 2023 // We always return a transient cache, so it is freed after each | 2020 // We always return a transient cache, so it is freed after each |
| 2024 // filter traversal. | 2021 // filter traversal. |
| 2025 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2022 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 2026 } | 2023 } |
| 2027 | 2024 |
| 2028 #endif | 2025 #endif |
| OLD | NEW |