From a85838c22e7c0fe08956ba856cc1bc0e95998bc4 Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Thu, 20 Sep 2018 14:35:34 -0400 Subject: [PATCH] send SkPMColor::toPMColor() through Sk4f_toL32() This doesn't fix that 8888 gradient if we stop clamping, but it seems like a good idea to land first anyway. Change-Id: Ie0feda67da5996223db2fe4458f99d57cf13db71 Reviewed-on: https://skia-review.googlesource.com/155782 Reviewed-by: Brian Osman Commit-Queue: Mike Klein --- src/core/SkPM4f.h | 26 +++++++++++++++++---- src/core/SkPM4fPriv.h | 26 --------------------- src/gpu/gradients/GrGradientBitmapCache.cpp | 1 + src/utils/SkPatchUtils.cpp | 1 + 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/core/SkPM4f.h b/src/core/SkPM4f.h index e1cb1cd27d..f9498578d2 100644 --- a/src/core/SkPM4f.h +++ b/src/core/SkPM4f.h @@ -23,6 +23,27 @@ static inline Sk4f swizzle_rb_if_bgra(const Sk4f& x) { #endif } +static inline Sk4f Sk4f_fromL32(uint32_t px) { + return SkNx_cast(Sk4b::Load(&px)) * (1/255.0f); +} + +static inline uint32_t Sk4f_toL32(const Sk4f& px) { + Sk4f v = px; + +#if !defined(SKNX_NO_SIMD) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 + // SkNx_cast() pins, and we don't anticipate giant floats +#elif !defined(SKNX_NO_SIMD) && defined(SK_ARM_HAS_NEON) + // SkNx_cast() pins, and so does Sk4f_round(). +#else + // No guarantee of a pin. + v = Sk4f::Max(0, Sk4f::Min(v, 1)); +#endif + + uint32_t l32; + SkNx_cast(Sk4f_round(v * 255.0f)).store(&l32); + return l32; +} + /* * The float values are 0...1 premultiplied in RGBA order (regardless of SkPMColor order) */ @@ -60,10 +81,7 @@ struct SK_API SkPM4f { Sk4f to4f_pmorder() const { return swizzle_rb_if_bgra(this->to4f()); } SkPMColor toPMColor() const { - Sk4f value = swizzle_rb_if_bgra(this->to4f()); - SkPMColor result; - SkNx_cast(value * Sk4f(255) + Sk4f(0.5f)).store(&result); - return result; + return Sk4f_toL32(swizzle_rb_if_bgra(this->to4f())); } void toF16(uint16_t[4]) const; diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h index 6c98cbc40d..06007b7c60 100644 --- a/src/core/SkPM4fPriv.h +++ b/src/core/SkPM4fPriv.h @@ -8,14 +8,9 @@ #ifndef SkPM4fPriv_DEFINED #define SkPM4fPriv_DEFINED -#include "SkColorData.h" -#include "SkColorSpace.h" #include "SkColorSpacePriv.h" #include "SkColorSpaceXformSteps.h" -#include "SkArenaAlloc.h" #include "SkPM4f.h" -#include "SkRasterPipeline.h" -#include "../jumper/SkJumper.h" // This file is mostly helper routines for doing color space management. // It probably wants a new name, and they likely don't need to be inline. @@ -27,27 +22,6 @@ // We'll start with the new as-encoded routines first, // and shove all the old broken routines towards the bottom. -static inline Sk4f Sk4f_fromL32(uint32_t px) { - return SkNx_cast(Sk4b::Load(&px)) * (1/255.0f); -} - -static inline uint32_t Sk4f_toL32(const Sk4f& px) { - Sk4f v = px; - -#if !defined(SKNX_NO_SIMD) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 - // SkNx_cast() pins, and we don't anticipate giant floats -#elif !defined(SKNX_NO_SIMD) && defined(SK_ARM_HAS_NEON) - // SkNx_cast() pins, and so does Sk4f_round(). -#else - // No guarantee of a pin. - v = Sk4f::Max(0, Sk4f::Min(v, 1)); -#endif - - uint32_t l32; - SkNx_cast(Sk4f_round(v * 255.0f)).store(&l32); - return l32; -} - static inline SkPM4f premul_in_dst_colorspace(SkColor4f color4f, SkColorSpace* srcCS, SkColorSpace* dstCS) { // TODO: In the very common case of srcCS being sRGB, diff --git a/src/gpu/gradients/GrGradientBitmapCache.cpp b/src/gpu/gradients/GrGradientBitmapCache.cpp index 459c13aba6..dd4e8425d0 100644 --- a/src/gpu/gradients/GrGradientBitmapCache.cpp +++ b/src/gpu/gradients/GrGradientBitmapCache.cpp @@ -12,6 +12,7 @@ #include "SkFloatBits.h" #include "SkHalf.h" #include "SkPM4fPriv.h" +#include "SkTemplates.h" #include diff --git a/src/utils/SkPatchUtils.cpp b/src/utils/SkPatchUtils.cpp index 83495bc8c3..ca92415d11 100644 --- a/src/utils/SkPatchUtils.cpp +++ b/src/utils/SkPatchUtils.cpp @@ -7,6 +7,7 @@ #include "SkPatchUtils.h" +#include "SkArenaAlloc.h" #include "SkColorData.h" #include "SkColorSpacePriv.h" #include "SkGeometry.h"