diff options
author | 2016-09-20 12:57:45 -0700 | |
---|---|---|
committer | 2016-09-20 12:57:45 -0700 | |
commit | d5797b3059a4037a6dce4c0a66693ba471b1588e (patch) | |
tree | e24bce5b0a0ab041b91d439bd6971686b86dc5dc /src/gpu/vk/GrVkGpu.cpp | |
parent | ad001fdc77b2dfe32c1723cb58636728dfb776d8 (diff) |
Fix possible divide by zero in vulkan granularity adjustments
This should fix the divide by zero crash on the nexus player bots
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2358613002
Review-Url: https://codereview.chromium.org/2358613002
Diffstat (limited to 'src/gpu/vk/GrVkGpu.cpp')
-rw-r--r-- | src/gpu/vk/GrVkGpu.cpp | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index a892e1b71c..6823bbc109 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -1795,31 +1795,41 @@ bool GrVkGpu::onReadPixels(GrSurface* surface, void adjust_bounds_to_granularity(SkIRect* dstBounds, const SkIRect& srcBounds, const VkExtent2D& granularity, int maxWidth, int maxHeight) { // Adjust Width - // Start with the right side of rect so we know if we end up going pass the maxWidth. - int rightAdj = srcBounds.fRight % granularity.width; - if (rightAdj != 0) { - rightAdj = granularity.width - rightAdj; - } - dstBounds->fRight = srcBounds.fRight + rightAdj; - if (dstBounds->fRight > maxWidth) { - dstBounds->fRight = maxWidth; - dstBounds->fLeft = 0; + if ((0 != granularity.width && 1 != granularity.width)) { + // Start with the right side of rect so we know if we end up going pass the maxWidth. + int rightAdj = srcBounds.fRight % granularity.width; + if (rightAdj != 0) { + rightAdj = granularity.width - rightAdj; + } + dstBounds->fRight = srcBounds.fRight + rightAdj; + if (dstBounds->fRight > maxWidth) { + dstBounds->fRight = maxWidth; + dstBounds->fLeft = 0; + } else { + dstBounds->fLeft = srcBounds.fLeft - srcBounds.fLeft % granularity.width; + } } else { - dstBounds->fLeft = srcBounds.fLeft - srcBounds.fLeft % granularity.width; + dstBounds->fLeft = srcBounds.fLeft; + dstBounds->fRight = srcBounds.fRight; } // Adjust height - // Start with the bottom side of rect so we know if we end up going pass the maxHeight. - int bottomAdj = srcBounds.fBottom % granularity.height; - if (bottomAdj != 0) { - bottomAdj = granularity.height - bottomAdj; - } - dstBounds->fBottom = srcBounds.fBottom + bottomAdj; - if (dstBounds->fBottom > maxHeight) { - dstBounds->fBottom = maxHeight; - dstBounds->fTop = 0; + if ((0 != granularity.height && 1 != granularity.height)) { + // Start with the bottom side of rect so we know if we end up going pass the maxHeight. + int bottomAdj = srcBounds.fBottom % granularity.height; + if (bottomAdj != 0) { + bottomAdj = granularity.height - bottomAdj; + } + dstBounds->fBottom = srcBounds.fBottom + bottomAdj; + if (dstBounds->fBottom > maxHeight) { + dstBounds->fBottom = maxHeight; + dstBounds->fTop = 0; + } else { + dstBounds->fTop = srcBounds.fTop - srcBounds.fTop % granularity.height; + } } else { - dstBounds->fTop = srcBounds.fTop - srcBounds.fTop % granularity.height; + dstBounds->fTop = srcBounds.fTop; + dstBounds->fBottom = srcBounds.fBottom; } } |