Index: src/image/SkImage_Base.h |
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h |
index 4ff6a25965166beca7f6aef96008936f8e8929fd..8f0fefe4f8622c110669c3f48fb60b557e522903 100644 |
--- a/src/image/SkImage_Base.h |
+++ b/src/image/SkImage_Base.h |
@@ -9,14 +9,37 @@ |
#define SkImage_Base_DEFINED |
#include "SkImage.h" |
+#include "SkSurface.h" |
+ |
+static SkSurfaceProps copy_or_safe_defaults(const SkSurfaceProps* props) { |
+ return props ? *props : SkSurfaceProps(0, kUnknown_SkPixelGeometry); |
+} |
class SkImage_Base : public SkImage { |
public: |
- SkImage_Base(int width, int height) : INHERITED(width, height) {} |
+ SkImage_Base(int width, int height, const SkSurfaceProps* props) |
+ : INHERITED(width, height) |
+ , fProps(copy_or_safe_defaults(props)) |
+ {} |
+ |
+ /** |
+ * If the props weren't know at constructor time, call this but only before the image is |
+ * ever released into the wild (since the props field must appear to be immutable). |
+ */ |
+ void initWithProps(const SkSurfaceProps& props) { |
+ SkASSERT(this->unique()); // only viewed by one thread |
+ SkSurfaceProps* mutableProps = const_cast<SkSurfaceProps*>(&fProps); |
+ SkASSERT(mutableProps != &props); // check for self-assignment |
+ mutableProps->~SkSurfaceProps(); |
+ new (mutableProps) SkSurfaceProps(props); |
+ } |
+ |
+ const SkSurfaceProps& props() const { return fProps; } |
virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const = 0; |
virtual void onDrawRect(SkCanvas*, const SkRect* src, |
const SkRect& dst, const SkPaint*) const = 0; |
+ virtual SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const = 0; |
// Default impl calls onDraw |
virtual bool onReadPixels(SkBitmap*, const SkIRect& subset) const; |
@@ -34,8 +57,19 @@ public: |
virtual SkShader* onNewShader(SkShader::TileMode, |
SkShader::TileMode, |
const SkMatrix* localMatrix) const { return NULL; }; |
+ |
private: |
+ const SkSurfaceProps fProps; |
+ |
typedef SkImage INHERITED; |
}; |
+static inline SkImage_Base* as_IB(SkImage* image) { |
+ return static_cast<SkImage_Base*>(image); |
+} |
+ |
+static inline const SkImage_Base* as_IB(const SkImage* image) { |
+ return static_cast<const SkImage_Base*>(image); |
+} |
+ |
#endif |