Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(774)

Unified Diff: src/effects/gradients/SkGradientShaderPriv.h

Issue 207683004: Extract most of the mutable state of SkShader into a separate Context object. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase & cleanup Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/effects/gradients/SkGradientShaderPriv.h
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index 83e0789853181950a65b8c70b30dcc5c64b4ad96..7d532b2ed7e70a191d8d893463905b7e47515c98 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -101,8 +101,46 @@ public:
SkGradientShaderBase(const Descriptor& desc);
virtual ~SkGradientShaderBase();
- virtual bool setContext(const SkBitmap&, const SkPaint&, const SkMatrix&) SK_OVERRIDE;
- virtual uint32_t getFlags() SK_OVERRIDE { return fFlags; }
+ // The cache is initialized on-demand when getCache16/32 is called.
+ class GradientShaderCache {
+ public:
+ GradientShaderCache(U8CPU alpha);
+ ~GradientShaderCache();
+
+ const uint16_t* getCache16(const SkGradientShaderBase& shader);
+ const SkPMColor* getCache32(const SkGradientShaderBase& shader);
+
+ SkMallocPixelRef* getCache32PixelRef() const { return fCache32PixelRef; }
+ private:
+ uint16_t* fCache16; // working ptr. If this is NULL, we need to recompute the cache values
scroggo 2014/04/03 15:35:54 nit: over 100 chars
Dominik Grewe 2014/04/04 10:59:41 Done.
+ SkPMColor* fCache32; // working ptr. If this is NULL, we need to recompute the cache values
+
+ uint16_t* fCache16Storage; // storage for fCache16, allocated on demand
+ SkMallocPixelRef* fCache32PixelRef;
+ unsigned fCacheAlpha; // the alpha value we used when we computed the cache.
+ // larger than 8bits so we can store uninitialized value
+
+ static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int count);
+ static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int count,
+ U8CPU alpha, uint32_t gradFlags);
+ };
+
+ class GradientShaderBaseContext : public SkShader::Context {
+ public:
+ GradientShaderBaseContext(const SkGradientShaderBase& shader, const SkBitmap& device,
+ const SkPaint& paint, const SkMatrix& matrix);
+ ~GradientShaderBaseContext() {}
+ protected:
+ SkMatrix fDstToIndex;
+ SkMatrix::MapXYProc fDstToIndexProc;
+ uint8_t fDstToIndexClass;
+ uint8_t fFlags;
+
+ GradientShaderCache fCache;
+
+ typedef SkShader::Context INHERITED;
+ };
+
virtual bool isOpaque() const SK_OVERRIDE;
void getGradientTableBitmap(SkBitmap*) const;
@@ -136,13 +174,9 @@ protected:
SkUnitMapper* fMapper;
SkMatrix fPtsToUnit; // set by subclass
- SkMatrix fDstToIndex;
- SkMatrix::MapXYProc fDstToIndexProc;
TileMode fTileMode;
TileProc fTileProc;
int fColorCount;
- uint8_t fDstToIndexClass;
- uint8_t fFlags;
uint8_t fGradFlags;
struct Rec {
@@ -151,9 +185,6 @@ protected:
};
Rec* fRecs;
- const uint16_t* getCache16() const;
- const SkPMColor* getCache32() const;
-
void commonAsAGradient(GradientInfo*) const;
private:
@@ -166,17 +197,6 @@ private:
SkColor* fOrigColors; // original colors, before modulation by paint in setContext
bool fColorsAreOpaque;
- mutable uint16_t* fCache16; // working ptr. If this is NULL, we need to recompute the cache values
- mutable SkPMColor* fCache32; // working ptr. If this is NULL, we need to recompute the cache values
-
- mutable uint16_t* fCache16Storage; // storage for fCache16, allocated on demand
- mutable SkMallocPixelRef* fCache32PixelRef;
- mutable unsigned fCacheAlpha; // the alpha value we used when we computed the cache. larger than 8bits so we can store uninitialized value
-
- static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int count);
- static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int count,
- U8CPU alpha, uint32_t gradFlags);
- void setCacheAlpha(U8CPU alpha) const;
void initCommon();
typedef SkShader INHERITED;

Powered by Google App Engine
This is Rietveld 408576698