diff options
author | Robert Phillips <robertphillips@google.com> | 2016-11-17 14:43:51 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-17 20:47:18 +0000 |
commit | b4460886905cc3b86987c6366a9721de77101111 (patch) | |
tree | 56d347bd093771a903a06e91cc697ee9621884e6 /src/gpu/GrSurface.cpp | |
parent | 684d7cef02121a42e217c0f63bdb4799d9ae4b53 (diff) |
Fix computation of texture size for approximately-fit deferred proxies
For approximate-fit deferred proxies asserts were firing when the instantiated size was larger than the pre-computed exact-fit size.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4972
Change-Id: I879e16b86ab4d9ef9834163c24ccd6507fe4b94a
Reviewed-on: https://skia-review.googlesource.com/4972
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/GrSurface.cpp')
-rw-r--r-- | src/gpu/GrSurface.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp index 7f571b875f..f67bfd4eb5 100644 --- a/src/gpu/GrSurface.cpp +++ b/src/gpu/GrSurface.cpp @@ -13,6 +13,7 @@ #include "SkBitmap.h" #include "SkGrPriv.h" #include "SkImageEncoder.h" +#include "SkMathPriv.h" #include <stdio.h> GrSurface::~GrSurface() { @@ -25,9 +26,12 @@ GrSurface::~GrSurface() { SkASSERT(NULL == fReleaseProc); } -size_t GrSurface::WorstCaseSize(const GrSurfaceDesc& desc) { +size_t GrSurface::WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2) { size_t size; + int width = useNextPow2 ? GrNextPow2(desc.fWidth) : desc.fWidth; + int height = useNextPow2 ? GrNextPow2(desc.fHeight) : desc.fHeight; + bool isRenderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); if (isRenderTarget) { // We own one color value for each MSAA sample. @@ -38,7 +42,7 @@ size_t GrSurface::WorstCaseSize(const GrSurfaceDesc& desc) { } SkASSERT(kUnknown_GrPixelConfig != desc.fConfig); SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); - size_t colorBytes = (size_t) desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig); + size_t colorBytes = (size_t) width * height * GrBytesPerPixel(desc.fConfig); // This would be a nice assert to have (i.e., we aren't creating 0 width/height surfaces). // Unfortunately Chromium seems to want to do this. @@ -48,9 +52,9 @@ size_t GrSurface::WorstCaseSize(const GrSurfaceDesc& desc) { size += colorBytes/3; // in case we have to mipmap } else { if (GrPixelConfigIsCompressed(desc.fConfig)) { - size = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fHeight); + size = GrCompressedFormatDataSize(desc.fConfig, width, height); } else { - size = (size_t) desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig); + size = (size_t) width * height * GrBytesPerPixel(desc.fConfig); } size += size/3; // in case we have to mipmap @@ -61,14 +65,18 @@ size_t GrSurface::WorstCaseSize(const GrSurfaceDesc& desc) { size_t GrSurface::ComputeSize(const GrSurfaceDesc& desc, int colorSamplesPerPixel, - bool hasMIPMaps) { + bool hasMIPMaps, + bool useNextPow2) { size_t colorSize; + int width = useNextPow2 ? GrNextPow2(desc.fWidth) : desc.fWidth; + int height = useNextPow2 ? GrNextPow2(desc.fHeight) : desc.fHeight; + SkASSERT(kUnknown_GrPixelConfig != desc.fConfig); if (GrPixelConfigIsCompressed(desc.fConfig)) { - colorSize = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fHeight); + colorSize = GrCompressedFormatDataSize(desc.fConfig, width, height); } else { - colorSize = (size_t) desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig); + colorSize = (size_t) width * height * GrBytesPerPixel(desc.fConfig); } SkASSERT(colorSize > 0); @@ -80,7 +88,7 @@ size_t GrSurface::ComputeSize(const GrSurfaceDesc& desc, finalSize += colorSize/3; } - SkASSERT(finalSize <= WorstCaseSize(desc)); + SkASSERT(finalSize <= WorstCaseSize(desc, useNextPow2)); return finalSize; } |