diff options
author | Jim Van Verth <jvanverth@google.com> | 2017-08-25 15:15:13 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-25 19:50:07 +0000 |
commit | 54ef7c057ac9cc8ff9cb18eba864686dd59c2d93 (patch) | |
tree | 1e8e4bb556f0a01e13820d8648b1ecfe0c5a00ce /src/core | |
parent | 9b0b32fda4871776eb9afdf9553e523e5c28aa63 (diff) |
Don't use uninitialized gamma data for adjusting SDF distance.
If the gamma is linear, the corresponding LUT for adjusting colors
is not initialized. This change takes that into account when computing
distance adjustments for SDF text.
Change-Id: I7ca1410bb27cf29ef08ccd666297bf5c3cd3dcdd
Reviewed-on: https://skia-review.googlesource.com/38940
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkMaskGamma.h | 5 | ||||
-rw-r--r-- | src/core/SkPaint.cpp | 14 | ||||
-rw-r--r-- | src/core/SkScalerContext.h | 8 |
3 files changed, 17 insertions, 10 deletions
diff --git a/src/core/SkMaskGamma.h b/src/core/SkMaskGamma.h index f90f75a878..3142534152 100644 --- a/src/core/SkMaskGamma.h +++ b/src/core/SkMaskGamma.h @@ -146,10 +146,11 @@ public: /** * Provides direct access to the full table set, so it can be uploaded - * into a texture. + * into a texture or analyzed in other ways. + * Returns nullptr if fGammaTables hasn't been initialized. */ const uint8_t* getGammaTables() const { - return (const uint8_t*) fGammaTables; + return fIsLinear ? nullptr : (const uint8_t*) fGammaTables; } private: diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 58f132d6d1..a41e6b55fb 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -1776,20 +1776,24 @@ size_t SkScalerContext::GetGammaLUTSize(SkScalar contrast, SkScalar paintGamma, return size; } -void SkScalerContext::GetGammaLUTData(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma, - void* data) { +bool SkScalerContext::GetGammaLUTData(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma, + uint8_t* data) { SkAutoMutexAcquire ama(gMaskGammaCacheMutex); const SkMaskGamma& maskGamma = cachedMaskGamma(contrast, paintGamma, deviceGamma); + const uint8_t* gammaTables = maskGamma.getGammaTables(); + if (!gammaTables) { + return false; + } + int width, height; maskGamma.getGammaTableDimensions(&width, &height); - size_t size = width*height*sizeof(uint8_t); - const uint8_t* gammaTables = maskGamma.getGammaTables(); + size_t size = width*height * sizeof(uint8_t); memcpy(data, gammaTables, size); + return true; } - /////////////////////////////////////////////////////////////////////////////// #include "SkStream.h" diff --git a/src/core/SkScalerContext.h b/src/core/SkScalerContext.h index 7bfdb92a52..6f220fe1c0 100644 --- a/src/core/SkScalerContext.h +++ b/src/core/SkScalerContext.h @@ -257,10 +257,12 @@ public: int* width, int* height); /** Get the associated gamma lookup table. The 'data' pointer must point to pre-allocated - memory, with size in bytes greater than or equal to the return value of getGammaLUTSize(). + * memory, with size in bytes greater than or equal to the return value of getGammaLUTSize(). + * + * If the lookup table hasn't been initialized (e.g., it's linear), this will return false. */ - static void GetGammaLUTData(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma, - void* data); + static bool GetGammaLUTData(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma, + uint8_t* data); static void MakeRec(const SkPaint&, const SkSurfaceProps* surfaceProps, const SkMatrix*, Rec* rec); |