diff options
author | Derek Sollenberger <djsollen@google.com> | 2014-05-21 11:25:22 -0400 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2014-05-21 13:27:10 -0400 |
commit | e392c81f6b8f9ace0c0a48c9d4df117fda31fd13 (patch) | |
tree | 10a8e6944cc2aac5c9b5238e9058ef8c087436d7 /libs/hwui/utils | |
parent | 69b43b496472132c4eaee0f9007d453c6f6a49b2 (diff) | |
download | frameworks_base-e392c81f6b8f9ace0c0a48c9d4df117fda31fd13.zip frameworks_base-e392c81f6b8f9ace0c0a48c9d4df117fda31fd13.tar.gz frameworks_base-e392c81f6b8f9ace0c0a48c9d4df117fda31fd13.tar.bz2 |
Pass the radius as a float deeper into HWUI allowing RS to generate more accurate blurs.
Also, when converting radius to an integer value snap to the appropriate integer boundaries.
bug: 10650594
Change-Id: Icca4bc17d88162bbcbc6035d4f81bd1d98a4de2d
Diffstat (limited to 'libs/hwui/utils')
-rw-r--r-- | libs/hwui/utils/Blur.cpp | 12 | ||||
-rw-r--r-- | libs/hwui/utils/Blur.h | 6 |
2 files changed, 17 insertions, 1 deletions
diff --git a/libs/hwui/utils/Blur.cpp b/libs/hwui/utils/Blur.cpp index c020b40..877a422 100644 --- a/libs/hwui/utils/Blur.cpp +++ b/libs/hwui/utils/Blur.cpp @@ -19,6 +19,7 @@ #include <math.h> #include "Blur.h" +#include "MathUtils.h" namespace android { namespace uirenderer { @@ -35,6 +36,17 @@ float Blur::convertSigmaToRadius(float sigma) { return sigma > 0.5f ? (sigma - 0.5f) / BLUR_SIGMA_SCALE : 0.0f; } +// if the original radius was on an integer boundary and the resulting radius +// is within the conversion error tolerance then we attempt to snap to the +// original integer boundary. +uint32_t Blur::convertRadiusToInt(float radius) { + const float radiusCeil = ceilf(radius); + if (MathUtils::areEqual(radiusCeil, radius)) { + return radiusCeil; + } + return radius; +} + /** * HWUI has used a slightly different equation than Skia to generate the value * for sigma and to preserve compatibility we have kept that logic. diff --git a/libs/hwui/utils/Blur.h b/libs/hwui/utils/Blur.h index 79aff65..b145333 100644 --- a/libs/hwui/utils/Blur.h +++ b/libs/hwui/utils/Blur.h @@ -27,8 +27,12 @@ class Blur { public: // If radius > 0, return the corresponding sigma, else return 0 ANDROID_API static float convertRadiusToSigma(float radius); - // If sigma > 0.6, return the corresponding radius, else return 0 + // If sigma > 0.5, return the corresponding radius, else return 0 ANDROID_API static float convertSigmaToRadius(float sigma); + // If the original radius was on an integer boundary then after the sigma to + // radius conversion a small rounding error may be introduced. This function + // accounts for that error and snaps to the appropriate integer boundary. + static uint32_t convertRadiusToInt(float radius); static void generateGaussianWeights(float* weights, int32_t radius); static void horizontal(float* weights, int32_t radius, const uint8_t* source, |