Remove the unused 16-bit gradient cache
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2343863002 Review-Url: https://codereview.chromium.org/2343863002
This commit is contained in:
parent
9f1f6e2c28
commit
93110a84aa
@ -306,69 +306,15 @@ SkGradientShaderBase::GradientShaderCache::GradientShaderCache(
|
||||
, fCacheDither(dither)
|
||||
, fShader(shader)
|
||||
{
|
||||
// Only initialize the cache in getCache16/32.
|
||||
fCache16 = nullptr;
|
||||
// Only initialize the cache in getCache32.
|
||||
fCache32 = nullptr;
|
||||
fCache16Storage = nullptr;
|
||||
fCache32PixelRef = nullptr;
|
||||
}
|
||||
|
||||
SkGradientShaderBase::GradientShaderCache::~GradientShaderCache() {
|
||||
sk_free(fCache16Storage);
|
||||
SkSafeUnref(fCache32PixelRef);
|
||||
}
|
||||
|
||||
#define Fixed_To_Dot8(x) (((x) + 0x80) >> 8)
|
||||
|
||||
/** We take the original colors, not our premultiplied PMColors, since we can
|
||||
build a 16bit table as long as the original colors are opaque, even if the
|
||||
paint specifies a non-opaque alpha.
|
||||
*/
|
||||
void SkGradientShaderBase::GradientShaderCache::Build16bitCache(
|
||||
uint16_t cache[], SkColor c0, SkColor c1, int count, bool dither) {
|
||||
SkASSERT(count > 1);
|
||||
SkASSERT(SkColorGetA(c0) == 0xFF);
|
||||
SkASSERT(SkColorGetA(c1) == 0xFF);
|
||||
|
||||
SkFixed r = SkColorGetR(c0);
|
||||
SkFixed g = SkColorGetG(c0);
|
||||
SkFixed b = SkColorGetB(c0);
|
||||
|
||||
SkFixed dr = SkIntToFixed(SkColorGetR(c1) - r) / (count - 1);
|
||||
SkFixed dg = SkIntToFixed(SkColorGetG(c1) - g) / (count - 1);
|
||||
SkFixed db = SkIntToFixed(SkColorGetB(c1) - b) / (count - 1);
|
||||
|
||||
r = SkIntToFixed(r) + 0x8000;
|
||||
g = SkIntToFixed(g) + 0x8000;
|
||||
b = SkIntToFixed(b) + 0x8000;
|
||||
|
||||
if (dither) {
|
||||
do {
|
||||
unsigned rr = r >> 16;
|
||||
unsigned gg = g >> 16;
|
||||
unsigned bb = b >> 16;
|
||||
cache[0] = SkPackRGB16(SkR32ToR16(rr), SkG32ToG16(gg), SkB32ToB16(bb));
|
||||
cache[kCache16Count] = SkDitherPack888ToRGB16(rr, gg, bb);
|
||||
cache += 1;
|
||||
r += dr;
|
||||
g += dg;
|
||||
b += db;
|
||||
} while (--count != 0);
|
||||
} else {
|
||||
do {
|
||||
unsigned rr = r >> 16;
|
||||
unsigned gg = g >> 16;
|
||||
unsigned bb = b >> 16;
|
||||
cache[0] = SkPackRGB16(SkR32ToR16(rr), SkG32ToG16(gg), SkB32ToB16(bb));
|
||||
cache[kCache16Count] = cache[0];
|
||||
cache += 1;
|
||||
r += dr;
|
||||
g += dg;
|
||||
b += db;
|
||||
} while (--count != 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* r,g,b used to be SkFixed, but on gcc (4.2.1 mac and 4.6.3 goobuntu) in
|
||||
* release builds, we saw a compiler error where the 0xFF parameter in
|
||||
@ -525,39 +471,6 @@ static inline int SkFixedToFFFF(SkFixed x) {
|
||||
return x - (x >> 16);
|
||||
}
|
||||
|
||||
const uint16_t* SkGradientShaderBase::GradientShaderCache::getCache16() {
|
||||
fCache16InitOnce(SkGradientShaderBase::GradientShaderCache::initCache16, this);
|
||||
SkASSERT(fCache16);
|
||||
return fCache16;
|
||||
}
|
||||
|
||||
void SkGradientShaderBase::GradientShaderCache::initCache16(GradientShaderCache* cache) {
|
||||
// double the count for dither entries
|
||||
const int entryCount = kCache16Count * 2;
|
||||
const size_t allocSize = sizeof(uint16_t) * entryCount;
|
||||
|
||||
SkASSERT(nullptr == cache->fCache16Storage);
|
||||
cache->fCache16Storage = (uint16_t*)sk_malloc_throw(allocSize);
|
||||
cache->fCache16 = cache->fCache16Storage;
|
||||
if (cache->fShader.fColorCount == 2) {
|
||||
Build16bitCache(cache->fCache16, cache->fShader.fOrigColors[0],
|
||||
cache->fShader.fOrigColors[1], kCache16Count, cache->fCacheDither);
|
||||
} else {
|
||||
Rec* rec = cache->fShader.fRecs;
|
||||
int prevIndex = 0;
|
||||
for (int i = 1; i < cache->fShader.fColorCount; i++) {
|
||||
int nextIndex = SkFixedToFFFF(rec[i].fPos) >> kCache16Shift;
|
||||
SkASSERT(nextIndex < kCache16Count);
|
||||
|
||||
if (nextIndex > prevIndex)
|
||||
Build16bitCache(cache->fCache16 + prevIndex, cache->fShader.fOrigColors[i-1],
|
||||
cache->fShader.fOrigColors[i], nextIndex - prevIndex + 1,
|
||||
cache->fCacheDither);
|
||||
prevIndex = nextIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const SkPMColor* SkGradientShaderBase::GradientShaderCache::getCache32() {
|
||||
fCache32InitOnce(SkGradientShaderBase::GradientShaderCache::initCache32, this);
|
||||
SkASSERT(fCache32);
|
||||
|
@ -117,13 +117,12 @@ public:
|
||||
SkGradientShaderBase(const Descriptor& desc, const SkMatrix& ptsToUnit);
|
||||
virtual ~SkGradientShaderBase();
|
||||
|
||||
// The cache is initialized on-demand when getCache16/32 is called.
|
||||
// The cache is initialized on-demand when getCache32 is called.
|
||||
class GradientShaderCache : public SkRefCnt {
|
||||
public:
|
||||
GradientShaderCache(U8CPU alpha, bool dither, const SkGradientShaderBase& shader);
|
||||
~GradientShaderCache();
|
||||
|
||||
const uint16_t* getCache16();
|
||||
const SkPMColor* getCache32();
|
||||
|
||||
SkMallocPixelRef* getCache32PixelRef() const { return fCache32PixelRef; }
|
||||
@ -132,12 +131,9 @@ public:
|
||||
bool getDither() const { return fCacheDither; }
|
||||
|
||||
private:
|
||||
// Working pointers. If either is nullptr, we need to recompute the corresponding
|
||||
// cache values.
|
||||
uint16_t* fCache16;
|
||||
// Working pointer. If it's nullptr, we need to recompute the cache values.
|
||||
SkPMColor* fCache32;
|
||||
|
||||
uint16_t* fCache16Storage; // Storage for fCache16, allocated on demand.
|
||||
SkMallocPixelRef* fCache32PixelRef;
|
||||
const unsigned fCacheAlpha; // The alpha value we used when we computed the cache.
|
||||
// Larger than 8bits so we can store uninitialized
|
||||
@ -146,14 +142,11 @@ public:
|
||||
|
||||
const SkGradientShaderBase& fShader;
|
||||
|
||||
// Make sure we only initialize the caches once.
|
||||
SkOnce fCache16InitOnce,
|
||||
fCache32InitOnce;
|
||||
// Make sure we only initialize the cache once.
|
||||
SkOnce fCache32InitOnce;
|
||||
|
||||
static void initCache16(GradientShaderCache* cache);
|
||||
static void initCache32(GradientShaderCache* cache);
|
||||
|
||||
static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int count, bool dither);
|
||||
static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int count,
|
||||
U8CPU alpha, uint32_t gradFlags, bool dither);
|
||||
};
|
||||
@ -182,13 +175,6 @@ public:
|
||||
void getGradientTableBitmap(SkBitmap*) const;
|
||||
|
||||
enum {
|
||||
/// Seems like enough for visual accuracy. TODO: if pos[] deserves
|
||||
/// it, use a larger cache.
|
||||
kCache16Bits = 8,
|
||||
kCache16Count = (1 << kCache16Bits),
|
||||
kCache16Shift = 16 - kCache16Bits,
|
||||
kSqrt16Shift = 8 - kCache16Bits,
|
||||
|
||||
/// Seems like enough for visual accuracy. TODO: if pos[] deserves
|
||||
/// it, use a larger cache.
|
||||
kCache32Bits = 8,
|
||||
@ -199,7 +185,6 @@ public:
|
||||
/// This value is used to *read* the dither cache; it may be 0
|
||||
/// if dithering is disabled.
|
||||
kDitherStride32 = kCache32Count,
|
||||
kDitherStride16 = kCache16Count,
|
||||
};
|
||||
|
||||
uint32_t getGradFlags() const { return fGradFlags; }
|
||||
@ -276,14 +261,6 @@ static inline int next_dither_toggle(int toggle) {
|
||||
return toggle ^ SkGradientShaderBase::kDitherStride32;
|
||||
}
|
||||
|
||||
static inline int init_dither_toggle16(int x, int y) {
|
||||
return ((x ^ y) & 1) * SkGradientShaderBase::kDitherStride16;
|
||||
}
|
||||
|
||||
static inline int next_dither_toggle16(int toggle) {
|
||||
return toggle ^ SkGradientShaderBase::kDitherStride16;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
|
Loading…
Reference in New Issue
Block a user