diff options
-rw-r--r-- | src/core/SkMaskGamma.h | 5 | ||||
-rw-r--r-- | src/core/SkPaint.cpp | 14 | ||||
-rw-r--r-- | src/core/SkScalerContext.h | 8 | ||||
-rw-r--r-- | src/gpu/text/GrDistanceFieldAdjustTable.cpp | 8 |
4 files changed, 24 insertions, 11 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); diff --git a/src/gpu/text/GrDistanceFieldAdjustTable.cpp b/src/gpu/text/GrDistanceFieldAdjustTable.cpp index 3aa96b5f2d..dccf0102d2 100644 --- a/src/gpu/text/GrDistanceFieldAdjustTable.cpp +++ b/src/gpu/text/GrDistanceFieldAdjustTable.cpp @@ -63,7 +63,13 @@ SkScalar* build_distance_adjust_table(SkScalar paintGamma, SkScalar deviceGamma) SkScalar* table = new SkScalar[height]; SkAutoTArray<uint8_t> data((int)size); - SkScalerContext::GetGammaLUTData(contrast, paintGamma, deviceGamma, data.get()); + if (!SkScalerContext::GetGammaLUTData(contrast, paintGamma, deviceGamma, data.get())) { + // if no valid data is available simply do no adjustment + for (int row = 0; row < height; ++row) { + table[row] = 0; + } + return table; + } // find the inverse points where we cross 0.5 // binsearch might be better, but we only need to do this once on creation |