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

Unified Diff: src/image/SkImage_Base.h

Issue 741763002: add SkImage::newSurface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: another warning fix Created 6 years, 1 month 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
« no previous file with comments | « src/image/SkImagePriv.cpp ('k') | src/image/SkImage_Gpu.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « src/image/SkImagePriv.cpp ('k') | src/image/SkImage_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698