aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/shaders
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-10-25 18:00:26 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-26 13:33:46 +0000
commitd4e9ec86cf934107cc441f651ee2429078188d02 (patch)
tree315aaedddf22666839b0c4e8524e67e71e37bdce /src/shaders
parentb87f798e5a629284cc008b4986bb2ddba7ed9cb1 (diff)
Delete GradientShaderCache
Dead code. Change-Id: If415e603b8e898da72ad95f32596445900794d23 Reviewed-on: https://skia-review.googlesource.com/63562 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'src/shaders')
-rw-r--r--src/shaders/gradients/SkGradientShader.cpp208
-rw-r--r--src/shaders/gradients/SkGradientShaderPriv.h123
-rw-r--r--src/shaders/gradients/SkLinearGradient.cpp4
-rw-r--r--src/shaders/gradients/SkRadialGradient.cpp3
-rw-r--r--src/shaders/gradients/SkSweepGradient.cpp3
-rw-r--r--src/shaders/gradients/SkTwoPointConicalGradient.cpp2
6 files changed, 48 insertions, 295 deletions
diff --git a/src/shaders/gradients/SkGradientShader.cpp b/src/shaders/gradients/SkGradientShader.cpp
index bd12bff38e..ddff2c2f5f 100644
--- a/src/shaders/gradients/SkGradientShader.cpp
+++ b/src/shaders/gradients/SkGradientShader.cpp
@@ -8,13 +8,16 @@
#include <algorithm>
#include "Sk4fLinearGradient.h"
#include "SkColorSpace_XYZ.h"
+#include "SkGradientBitmapCache.h"
#include "SkGradientShaderPriv.h"
#include "SkHalf.h"
#include "SkLinearGradient.h"
#include "SkMallocPixelRef.h"
#include "SkRadialGradient.h"
+#include "SkReadBuffer.h"
#include "SkSweepGradient.h"
#include "SkTwoPointConicalGradient.h"
+#include "SkWriteBuffer.h"
#include "../../jumper/SkJumper.h"
@@ -120,9 +123,7 @@ SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri
fGradFlags = static_cast<uint8_t>(desc.fGradFlags);
SkASSERT((unsigned)desc.fTileMode < SkShader::kTileModeCount);
- SkASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gTileProcs));
fTileMode = desc.fTileMode;
- fTileProc = gTileProcs[desc.fTileMode];
/* Note: we let the caller skip the first and/or last position.
i.e. pos[0] = 0.3, pos[1] = 0.7
@@ -497,135 +498,12 @@ bool SkGradientShaderBase::onAsLuminanceColor(SkColor* lum) const {
return true;
}
-SkGradientShaderBase::GradientShaderCache::GradientShaderCache(const SkGradientShaderBase& shader)
- : fCache32(nullptr) // Only initialize the cache in getCache32.
- , fShader(shader) {}
-
-SkGradientShaderBase::GradientShaderCache::~GradientShaderCache() {}
-
-/*
- * 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
- * SkPackARGB32() was being totally ignored whenever it was called with
- * a non-zero add (e.g. 0x8000).
- *
- * We found two work-arounds:
- * 1. change r,g,b to unsigned (or just one of them)
- * 2. change SkPackARGB32 to + its (a << SK_A32_SHIFT) value instead
- * of using |
- *
- * We chose #1 just because it was more localized.
- * See http://code.google.com/p/skia/issues/detail?id=1113
- *
- * The type SkUFixed encapsulate this need for unsigned, but logically Fixed.
- */
-typedef uint32_t SkUFixed;
-
-void SkGradientShaderBase::GradientShaderCache::Build32bitCache(SkPMColor cache[], SkColor c0,
- SkColor c1, int count,
- uint32_t gradFlags) {
- SkASSERT(count > 1);
-
- uint32_t a0 = SkColorGetA(c0);
- uint32_t a1 = SkColorGetA(c1);
-
- const bool interpInPremul = SkToBool(gradFlags &
- SkGradientShader::kInterpolateColorsInPremul_Flag);
-
- uint32_t r0 = SkColorGetR(c0);
- uint32_t g0 = SkColorGetG(c0);
- uint32_t b0 = SkColorGetB(c0);
-
- uint32_t r1 = SkColorGetR(c1);
- uint32_t g1 = SkColorGetG(c1);
- uint32_t b1 = SkColorGetB(c1);
-
- if (interpInPremul) {
- r0 = SkMulDiv255Round(r0, a0);
- g0 = SkMulDiv255Round(g0, a0);
- b0 = SkMulDiv255Round(b0, a0);
-
- r1 = SkMulDiv255Round(r1, a1);
- g1 = SkMulDiv255Round(g1, a1);
- b1 = SkMulDiv255Round(b1, a1);
- }
-
- SkFixed da = SkIntToFixed(a1 - a0) / (count - 1);
- SkFixed dr = SkIntToFixed(r1 - r0) / (count - 1);
- SkFixed dg = SkIntToFixed(g1 - g0) / (count - 1);
- SkFixed db = SkIntToFixed(b1 - b0) / (count - 1);
-
- const SkUFixed bias0 = 0x8000;
-
- SkUFixed a = SkIntToFixed(a0) + bias0;
- SkUFixed r = SkIntToFixed(r0) + bias0;
- SkUFixed g = SkIntToFixed(g0) + bias0;
- SkUFixed b = SkIntToFixed(b0) + bias0;
-
- if (0xFF == a0 && 0 == da) {
- do {
- *cache++ = SkPackARGB32(0xFF, r >> 16, g >> 16, b >> 16);
-
- r += dr;
- g += dg;
- b += db;
- } while (--count != 0);
- } else if (interpInPremul) {
- do {
- *cache++ = SkPackARGB32(a >> 16, r >> 16, g >> 16, b >> 16);
-
- a += da;
- r += dr;
- g += dg;
- b += db;
- } while (--count != 0);
- } else { // interpolate in unpreml space
- do {
- *cache++ = SkPremultiplyARGBInline(a >> 16, r >> 16, g >> 16, b >> 16);
-
- a += da;
- r += dr;
- g += dg;
- b += db;
- } while (--count != 0);
- }
-}
-
static inline int SkFixedToFFFF(SkFixed x) {
SkASSERT((unsigned)x <= SK_Fixed1);
return x - (x >> 16);
}
-const SkPMColor* SkGradientShaderBase::GradientShaderCache::getCache32() {
- fCache32InitOnce(SkGradientShaderBase::GradientShaderCache::initCache32, this);
- SkASSERT(fCache32);
- return fCache32;
-}
-
-void SkGradientShaderBase::GradientShaderCache::initCache32(GradientShaderCache* cache) {
- const SkImageInfo info = SkImageInfo::MakeN32Premul(kCache32Count, 1);
-
- SkASSERT(nullptr == cache->fCache32PixelRef);
- cache->fCache32PixelRef = SkMallocPixelRef::MakeAllocate(info, 0);
- cache->fCache32 = (SkPMColor*)cache->fCache32PixelRef->pixels();
- if (cache->fShader.fColorCount == 2) {
- Build32bitCache(cache->fCache32, cache->fShader.fOrigColors[0],
- cache->fShader.fOrigColors[1], kCache32Count, cache->fShader.fGradFlags);
- } else {
- Rec* rec = cache->fShader.fRecs;
- int prevIndex = 0;
- for (int i = 1; i < cache->fShader.fColorCount; i++) {
- int nextIndex = SkFixedToFFFF(rec[i].fPos) >> kCache32Shift;
- SkASSERT(nextIndex < kCache32Count);
-
- if (nextIndex > prevIndex)
- Build32bitCache(cache->fCache32 + prevIndex, cache->fShader.fOrigColors[i-1],
- cache->fShader.fOrigColors[i], nextIndex - prevIndex + 1,
- cache->fShader.fGradFlags);
- prevIndex = nextIndex;
- }
- }
-}
+static constexpr int kGradientTextureSize = 256;
void SkGradientShaderBase::initLinearBitmap(SkBitmap* bitmap, GradientBitmapType bitmapType) const {
const bool interpInPremul = SkToBool(fGradFlags &
@@ -662,11 +540,14 @@ void SkGradientShaderBase::initLinearBitmap(SkBitmap* bitmap, GradientBitmapType
// our own CS for identity/no transform.
auto* cs = bitmapType != GradientBitmapType::kLegacy ? fColorSpace.get() : nullptr;
+ // TODO: refactor to avoid using fRecs.
+ static constexpr unsigned kCacheShift = 8;
+
int prevIndex = 0;
for (int i = 1; i < fColorCount; i++) {
- int nextIndex = (fColorCount == 2) ? (kCache32Count - 1)
- : SkFixedToFFFF(fRecs[i].fPos) >> kCache32Shift;
- SkASSERT(nextIndex < kCache32Count);
+ int nextIndex = (fColorCount == 2) ? (kGradientTextureSize - 1)
+ : SkFixedToFFFF(fRecs[i].fPos) >> kCacheShift;
+ SkASSERT(nextIndex < kGradientTextureSize);
if (nextIndex > prevIndex) {
SkColor4f color0 = this->getXformedColor(i - 1, cs),
@@ -689,22 +570,7 @@ void SkGradientShaderBase::initLinearBitmap(SkBitmap* bitmap, GradientBitmapType
}
prevIndex = nextIndex;
}
- SkASSERT(prevIndex == kCache32Count - 1);
-}
-
-/*
- * The gradient holds a cache for the most recent value of alpha. Successive
- * callers with the same alpha value will share the same cache.
- */
-sk_sp<SkGradientShaderBase::GradientShaderCache> SkGradientShaderBase::refCache() const {
- SkAutoMutexAcquire ama(fCacheMutex);
- if (!fCache) {
- fCache = sk_make_sp<GradientShaderCache>(*this);
- }
- // Increment the ref counter inside the mutex to ensure the returned pointer is still valid.
- // Otherwise, the pointer may have been overwritten on a different thread before the object's
- // ref count was incremented.
- return fCache;
+ SkASSERT(prevIndex == kGradientTextureSize - 1);
}
SkColor4f SkGradientShaderBase::getXformedColor(size_t i, SkColorSpace* dstCS) const {
@@ -756,39 +622,27 @@ void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap,
size_t size = count * sizeof(int32_t);
if (!gCache->find(storage.get(), size, bitmap)) {
-#ifdef SK_SUPPORT_LEGACY_GPU_GRADIENT_TABLE
- if (GradientBitmapType::kLegacy == bitmapType) {
-#else
- if (false) {
-#endif
- sk_sp<GradientShaderCache> cache(this->refCache());
-
- // force our cache32pixelref to be built
- (void)cache->getCache32();
- bitmap->setInfo(SkImageInfo::MakeN32Premul(kCache32Count, 1));
- bitmap->setPixelRef(sk_ref_sp(cache->getCache32PixelRef()), 0, 0);
- } else {
- // For these cases we use the bitmap cache, but not the GradientShaderCache. So just
- // allocate and populate the bitmap's data directly.
-
- SkImageInfo info;
- switch (bitmapType) {
- case GradientBitmapType::kLegacy:
- info = SkImageInfo::Make(kCache32Count, 1, kRGBA_8888_SkColorType,
- kPremul_SkAlphaType);
- break;
- case GradientBitmapType::kSRGB:
- info = SkImageInfo::Make(kCache32Count, 1, kRGBA_8888_SkColorType,
- kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
- break;
- case GradientBitmapType::kHalfFloat:
- info = SkImageInfo::Make(kCache32Count, 1, kRGBA_F16_SkColorType,
- kPremul_SkAlphaType, SkColorSpace::MakeSRGBLinear());
- break;
- }
- bitmap->allocPixels(info);
- this->initLinearBitmap(bitmap, bitmapType);
+ // For these cases we use the bitmap cache, but not the GradientShaderCache. So just
+ // allocate and populate the bitmap's data directly.
+
+ SkImageInfo info;
+ switch (bitmapType) {
+ case GradientBitmapType::kLegacy:
+ info = SkImageInfo::Make(kGradientTextureSize, 1, kRGBA_8888_SkColorType,
+ kPremul_SkAlphaType);
+ break;
+ case GradientBitmapType::kSRGB:
+ info = SkImageInfo::Make(kGradientTextureSize, 1, kRGBA_8888_SkColorType,
+ kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
+ break;
+ case GradientBitmapType::kHalfFloat:
+ info = SkImageInfo::Make(kGradientTextureSize, 1, kRGBA_F16_SkColorType,
+ kPremul_SkAlphaType, SkColorSpace::MakeSRGBLinear());
+ break;
}
+
+ bitmap->allocPixels(info);
+ this->initLinearBitmap(bitmap, bitmapType);
gCache->add(storage.get(), size, *bitmap);
}
}
diff --git a/src/shaders/gradients/SkGradientShaderPriv.h b/src/shaders/gradients/SkGradientShaderPriv.h
index 3a181dd742..9aad102491 100644
--- a/src/shaders/gradients/SkGradientShaderPriv.h
+++ b/src/shaders/gradients/SkGradientShaderPriv.h
@@ -8,73 +8,19 @@
#ifndef SkGradientShaderPriv_DEFINED
#define SkGradientShaderPriv_DEFINED
-#include "SkGradientBitmapCache.h"
#include "SkGradientShader.h"
#include "SkArenaAlloc.h"
#include "SkAutoMalloc.h"
-#include "SkClampRange.h"
-#include "SkColorData.h"
-#include "SkColorSpace.h"
-#include "SkMatrixPriv.h"
-#include "SkOnce.h"
-#include "SkPM4fPriv.h"
-#include "SkRasterPipeline.h"
-#include "SkReadBuffer.h"
+#include "SkFixed.h"
+#include "SkMatrix.h"
#include "SkShaderBase.h"
-#include "SkUtils.h"
-#include "SkWriteBuffer.h"
-
-static inline void sk_memset32_dither(uint32_t dst[], uint32_t v0, uint32_t v1,
- int count) {
- if (count > 0) {
- if (v0 == v1) {
- sk_memset32(dst, v0, count);
- } else {
- int pairs = count >> 1;
- for (int i = 0; i < pairs; i++) {
- *dst++ = v0;
- *dst++ = v1;
- }
- if (count & 1) {
- *dst = v0;
- }
- }
- }
-}
-
-// Clamp
-
-static inline SkFixed clamp_tileproc(SkFixed x) {
- return SkClampMax(x, 0xFFFF);
-}
-
-// Repeat
-
-static inline SkFixed repeat_tileproc(SkFixed x) {
- return x & 0xFFFF;
-}
-
-// Mirror
+#include "SkTDArray.h"
-static inline SkFixed mirror_tileproc(SkFixed x) {
- int s = SkLeftShift(x, 15) >> 31;
- return (x ^ s) & 0xFFFF;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-typedef SkFixed (*TileProc)(SkFixed);
-
-///////////////////////////////////////////////////////////////////////////////
-
-static const TileProc gTileProcs[] = {
- clamp_tileproc,
- repeat_tileproc,
- mirror_tileproc
-};
-
-///////////////////////////////////////////////////////////////////////////////
+class SkColorSpace;
+class SkRasterPipeline;
+class SkReadBuffer;
+class SkWriteBuffer;
class SkGradientShaderBase : public SkShaderBase {
public:
@@ -119,32 +65,6 @@ public:
SkGradientShaderBase(const Descriptor& desc, const SkMatrix& ptsToUnit);
~SkGradientShaderBase() override;
- // The cache is initialized on-demand when getCache32 is called.
- class GradientShaderCache : public SkRefCnt {
- public:
- GradientShaderCache(const SkGradientShaderBase& shader);
- ~GradientShaderCache();
-
- const SkPMColor* getCache32();
-
- SkPixelRef* getCache32PixelRef() const { return fCache32PixelRef.get(); }
-
- private:
- // Working pointer. If it's nullptr, we need to recompute the cache values.
- SkPMColor* fCache32;
-
- sk_sp<SkPixelRef> fCache32PixelRef;
- const SkGradientShaderBase& fShader;
-
- // Make sure we only initialize the cache once.
- SkOnce fCache32InitOnce;
-
- static void initCache32(GradientShaderCache* cache);
-
- static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int count,
- uint32_t gradFlags);
- };
-
bool isOpaque() const override;
enum class GradientBitmapType : uint8_t {
@@ -155,19 +75,6 @@ public:
void getGradientTableBitmap(SkBitmap*, GradientBitmapType bitmapType) const;
- enum {
- /// Seems like enough for visual accuracy. TODO: if pos[] deserves
- /// it, use a larger cache.
- kCache32Bits = 8,
- kCache32Count = (1 << kCache32Bits),
- kCache32Shift = 16 - kCache32Bits,
- kSqrt32Shift = 8 - kCache32Bits,
-
- /// This value is used to *read* the dither cache; it may be 0
- /// if dithering is disabled.
- kDitherStride32 = kCache32Count,
- };
-
uint32_t getGradFlags() const { return fGradFlags; }
SkColor4f getXformedColor(size_t index, SkColorSpace*) const;
@@ -206,7 +113,6 @@ protected:
const SkMatrix fPtsToUnit;
TileMode fTileMode;
- TileProc fTileProc;
uint8_t fGradFlags;
Rec* fRecs;
@@ -233,26 +139,11 @@ public:
private:
bool fColorsAreOpaque;
- sk_sp<GradientShaderCache> refCache() const;
- mutable SkMutex fCacheMutex;
- mutable sk_sp<GradientShaderCache> fCache;
-
void initCommon();
typedef SkShaderBase INHERITED;
};
-
-static inline int init_dither_toggle(int x, int y) {
- x &= 1;
- y = (y & 1) << 1;
- return (x | y) * SkGradientShaderBase::kDitherStride32;
-}
-
-static inline int next_dither_toggle(int toggle) {
- return toggle ^ SkGradientShaderBase::kDitherStride32;
-}
-
///////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU
diff --git a/src/shaders/gradients/SkLinearGradient.cpp b/src/shaders/gradients/SkLinearGradient.cpp
index 10d0973c60..3b41e79710 100644
--- a/src/shaders/gradients/SkLinearGradient.cpp
+++ b/src/shaders/gradients/SkLinearGradient.cpp
@@ -6,9 +6,11 @@
*/
#include "SkLinearGradient.h"
+
#include "Sk4fLinearGradient.h"
#include "SkColorSpaceXformer.h"
-#include "SkRefCnt.h"
+#include "SkReadBuffer.h"
+#include "SkWriteBuffer.h"
static SkMatrix pts_to_unit_matrix(const SkPoint pts[2]) {
SkVector vec = pts[1] - pts[0];
diff --git a/src/shaders/gradients/SkRadialGradient.cpp b/src/shaders/gradients/SkRadialGradient.cpp
index d411c3a014..5014eaea75 100644
--- a/src/shaders/gradients/SkRadialGradient.cpp
+++ b/src/shaders/gradients/SkRadialGradient.cpp
@@ -7,6 +7,9 @@
#include "SkColorSpaceXformer.h"
#include "SkRadialGradient.h"
+#include "SkRasterPipeline.h"
+#include "SkReadBuffer.h"
+#include "SkWriteBuffer.h"
namespace {
diff --git a/src/shaders/gradients/SkSweepGradient.cpp b/src/shaders/gradients/SkSweepGradient.cpp
index b505426c58..75622217b4 100644
--- a/src/shaders/gradients/SkSweepGradient.cpp
+++ b/src/shaders/gradients/SkSweepGradient.cpp
@@ -6,10 +6,11 @@
*/
#include "SkColorSpaceXformer.h"
+#include "SkReadBuffer.h"
#include "SkSweepGradient.h"
-
#include "SkPM4fPriv.h"
#include "SkRasterPipeline.h"
+#include "SkWriteBuffer.h"
SkSweepGradient::SkSweepGradient(const SkPoint& center, SkScalar t0, SkScalar t1,
const Descriptor& desc)
diff --git a/src/shaders/gradients/SkTwoPointConicalGradient.cpp b/src/shaders/gradients/SkTwoPointConicalGradient.cpp
index 22555e02a3..86625de41e 100644
--- a/src/shaders/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/shaders/gradients/SkTwoPointConicalGradient.cpp
@@ -8,6 +8,8 @@
#include "SkTwoPointConicalGradient.h"
#include "SkRasterPipeline.h"
+#include "SkReadBuffer.h"
+#include "SkWriteBuffer.h"
#include "../../jumper/SkJumper.h"
sk_sp<SkShader> SkTwoPointConicalGradient::Create(const SkPoint& c0, SkScalar r0,