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

Unified Diff: include/core/SkShader.h

Issue 245963010: Move SkShader::fLocalMatrix into SkShader constructor. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add SkLocalMatrixShaderWrapper Created 6 years, 8 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: include/core/SkShader.h
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index cc2cc751d8af6ca97436d5ad87ea164e91911f79..69b85c2d00648df251c87735b319273389c2d84e 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -34,7 +34,7 @@ class SK_API SkShader : public SkFlattenable {
public:
SK_DECLARE_INST_COUNT(SkShader)
- SkShader();
+ SkShader(const SkMatrix* localMatrix = NULL);
virtual ~SkShader();
/**
@@ -371,7 +371,8 @@ public:
* @return Returns a new shader object. Note: this function never returns null.
*/
static SkShader* CreateBitmapShader(const SkBitmap& src,
- TileMode tmx, TileMode tmy);
+ TileMode tmx, TileMode tmy,
+ const SkMatrix* localMatrix = NULL);
/** Call this to create a new shader that will draw with the specified picture.
*
@@ -385,6 +386,15 @@ public:
*/
static SkShader* CreatePictureShader(SkPicture* src, TileMode tmx, TileMode tmy);
+ /** Call this to create a shader wrapper with a new local matrix. It behaves like the
+ * original shader but with the local matrix replaced.
+ *
+ * @param shader The shader being wrapped.
+ * @param localMatrix The new local matrix to replace the original shader's one.
+ * @return Returns a new shader object. Note: this function never returns null.
scroggo 2014/04/24 17:02:53 What if the caller calls with a NULL shader?
Dominik Grewe 2014/04/24 17:16:47 Good point. I currently assert that it's not NULL
+ */
+ static SkShader* CreateLocalMatrixWrapper(SkShader* shader, const SkMatrix& localMatrix);
+
SK_TO_STRING_VIRT()
SK_DEFINE_FLATTENABLE_TYPE(SkShader)
@@ -401,4 +411,55 @@ private:
typedef SkFlattenable INHERITED;
};
+
+/**
+ * Wrapper class for SkShader that allows us to overwrite the local matrix
+ * without having to create the shader again.
+ */
+class SK_API SkLocalMatrixShaderWrapper : public SkShader {
+public:
+ static SkLocalMatrixShaderWrapper* Create(SkShader* shader, const SkMatrix& localMatrix) {
+ return SkNEW_ARGS(SkLocalMatrixShaderWrapper, (shader, localMatrix));
+ }
+
+ // Forward all methods to the wrapped shader, apart from hasLocalMatrix and
+ // getLocalMatrix which use the wrapper's local matrix.
+ virtual bool isOpaque() const SK_OVERRIDE { return fShader->isOpaque(); }
+ virtual bool validContext(const SkBitmap& device,
+ const SkPaint& paint,
+ const SkMatrix& matrix,
+ SkMatrix* totalInverse = NULL) const SK_OVERRIDE {
+ return fShader->validContext(device, paint, matrix, totalInverse);
+ }
+ virtual Context* createContext(const SkBitmap& device,
+ const SkPaint& paint,
+ const SkMatrix& matrix,
+ void* storage) const SK_OVERRIDE {
+ return fShader->createContext(device, paint, matrix, storage);
+ }
+ virtual size_t contextSize() const SK_OVERRIDE { return fShader->contextSize(); }
+ virtual BitmapType asABitmap(SkBitmap* outTexture, SkMatrix* outMatrix,
+ TileMode xy[2]) const SK_OVERRIDE {
+ return fShader->asABitmap(outTexture, outMatrix, xy);
+ }
+ virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE {
+ return fShader->asAGradient(info);
+ }
+ virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) const SK_OVERRIDE {
+ return fShader->asNewEffect(context, paint);
scroggo 2014/04/24 17:02:53 This function may call getLocalMatrix (e.g. SkBitm
Dominik Grewe 2014/04/24 17:16:47 Thinking about this, I'm not sure what I've done h
+ }
+
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShaderWrapper);
+
+protected:
+ SkLocalMatrixShaderWrapper(SkShader* shader, const SkMatrix& localMatrix);
scroggo 2014/04/24 17:02:53 Any reason not to make this private?
Dominik Grewe 2014/04/24 17:16:47 As long as we never have any subclasses we can mak
scroggo 2014/04/24 18:24:47 My vote would be to make it private unless/until w
+ SkLocalMatrixShaderWrapper(SkReadBuffer& buffer);
+ virtual void flatten(SkWriteBuffer& buffer);
+
+private:
+ SkAutoTUnref<SkShader> fShader;
+
+ typedef SkShader INHERITED;
+};
+
#endif

Powered by Google App Engine
This is Rietveld 408576698