Index: include/core/SkShader.h |
diff --git a/include/core/SkShader.h b/include/core/SkShader.h |
index cc2cc751d8af6ca97436d5ad87ea164e91911f79..ec86c682b3640907a121638a93e8478c6dcb4383 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. |
scroggo
2014/04/24 18:24:47
Should there be a comment that its ref count is in
|
+ * @param localMatrix The new local matrix to replace the original shader's one. |
+ * @return Returns a new shader object or NULL if shader is 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); |
+ } |
+ |
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShaderWrapper); |
+ |
+protected: |
+ SkLocalMatrixShaderWrapper(SkShader* shader, const SkMatrix& localMatrix); |
+ SkLocalMatrixShaderWrapper(SkReadBuffer& buffer); |
+ virtual void flatten(SkWriteBuffer& buffer); |
+ |
+private: |
+ SkAutoTUnref<SkShader> fShader; |
+ |
+ typedef SkShader INHERITED; |
+}; |
+ |
#endif |