add default impl for context methods on shader
These are reasonable return values, since both of these methods can return a known value (0)
which means that no context can be created. This also makes it easier for chrome's subclasses
which already do not want to create a context, but having them actually overridden makes
changing the virtual signatures much harder.
BUG=skia:
R=scroggo@google.com, dominikg@google.com, reed@chromium.org
Author: reed@google.com
Review URL: https://codereview.chromium.org/262703002
git-svn-id: http://skia.googlecode.com/svn/trunk@14491 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index 4af8f78..b0a7fd9 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -207,16 +207,22 @@
* Create the actual object that does the shading.
* Returns NULL if validContext() returns false.
* Size of storage must be >= contextSize.
+ * Your subclass must also override contextSize() if it overrides createContext().
+ *
+ * Base class implementation returns NULL.
*/
virtual Context* createContext(const SkBitmap& device,
const SkPaint& paint,
const SkMatrix& matrix,
- void* storage) const = 0;
+ void* storage) const;
/**
* Return the size of a Context returned by createContext.
+ *
+ * Override this if your subclass overrides createContext, to return the correct size of
+ * your subclass' context.
*/
- virtual size_t contextSize() const = 0;
+ virtual size_t contextSize() const;
/**
* Helper to check the flags to know if it is legal to call shadeSpan16()
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index 4ddd291..a449d0f 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -63,6 +63,15 @@
return this->computeTotalInverse(matrix, totalInverse);
}
+SkShader::Context* SkShader::createContext(const SkBitmap&, const SkPaint&, const SkMatrix&,
+ void* storage) const {
+ return NULL;
+}
+
+size_t SkShader::contextSize() const {
+ return 0;
+}
+
SkShader::Context::Context(const SkShader& shader, const SkBitmap& device,
const SkPaint& paint, const SkMatrix& matrix)
: fShader(shader)