aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkImage.h
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-27 18:02:50 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-27 18:02:50 +0000
commitf6627b78f933b77b358ac0791c520f99b0e79fca (patch)
treec8be16505506fc8fa0f73d588f3d0d9dc5ec7ee9 /include/core/SkImage.h
parent20a550c6ea947f0ab239da1d4ecba209d76a98fd (diff)
check-point for image experiment
git-svn-id: http://skia.googlecode.com/svn/trunk@4811 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core/SkImage.h')
-rw-r--r--include/core/SkImage.h75
1 files changed, 63 insertions, 12 deletions
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index 9f1bd1f12a..df71875e61 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -8,9 +8,20 @@
#ifndef SkImage_DEFINED
#define SkImage_DEFINED
+#include "SkRefCnt.h"
+#include "SkScalar.h"
+
+class SkData;
+class SkCanvas;
+class SkPaint;
+class SkShader;
+
+// need for TileMode
+#include "SkShader.h"
////// EXPERIMENTAL
+class SkColorSpace;
/**
* SkImage is an abstraction for drawing a rectagle of pixels, though the
@@ -25,18 +36,22 @@
class SkImage : public SkRefCnt {
public:
enum ColorType {
- kA8_ColorType,
+ kAlpha_8_ColorType,
kRGB_565_ColorType,
kRGBA_8888_ColorType,
kBGRA_8888_ColorType,
kPMColor_ColorType,
+
+ kLastEnum_ColorType = kPMColor_ColorType
};
enum AlphaType {
kIgnore_AlphaType,
kOpaque_AlphaType,
kPremul_AlphaType,
- kUnpremul_AlphaType
+ kUnpremul_AlphaType,
+
+ kLastEnum_AlphaType = kUnpremul_AlphaType
};
struct Info {
@@ -51,14 +66,31 @@ public:
static SkImage* NewRasterData(const Info&, SkColorSpace*, SkData* pixels, size_t rowBytes);
static SkImage* NewEncodedData(SkData*);
- int width() const;
- int height() const;
- uint32_t uniqueID() const;
-
+ int width() const { return fWidth; }
+ int height() const { return fHeight; }
+ uint32_t uniqueID() const { return fUniqueID; }
+
SkShader* newShaderClamp() const;
SkShader* newShader(SkShader::TileMode, SkShader::TileMode) const;
-
- void SkCanvas::drawImage(...);
+
+ void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*);
+
+protected:
+ SkImage(int width, int height) :
+ fWidth(width),
+ fHeight(height),
+ fUniqueID(NextUniqueID()) {
+
+ SkASSERT(width >= 0);
+ SkASSERT(height >= 0);
+ }
+
+private:
+ const int fWidth;
+ const int fHeight;
+ const uint32_t fUniqueID;
+
+ static uint32_t NextUniqueID();
};
/**
@@ -71,20 +103,39 @@ public:
*/
class SkSurface : public SkRefCnt {
public:
- static SkSurface* NewRasterDirect(const Info&, SkColorSpace*,
+ static SkSurface* NewRasterDirect(const SkImage::Info&, SkColorSpace*,
const void* pixels, size_t rowBytes);
- static SkSurface* NewRaster(const Info&, SkColorSpace*);
+ static SkSurface* NewRaster(const SkImage::Info&, SkColorSpace*);
static SkSurface* NewGpu(GrContext*);
static SkSurface* NewPDF(...);
static SkSurface* NewXPS(...);
static SkSurface* NewPicture(int width, int height);
/**
- * Return a canvas that will draw into this surface
+ * Return a canvas that will draw into this surface.
+ *
+ * LIFECYCLE QUESTIONS
+ * 1. Is this owned by the surface or the caller?
+ * 2. Can the caller get a 2nd canvas, or reset the state of the first?
*/
SkCanvas* newCanvas();
/**
+ * Return a new surface that is "compatible" with this one, in that it will
+ * efficiently be able to be drawn into this surface. Typical calling
+ * pattern:
+ *
+ * SkSurface* A = SkSurface::New...();
+ * SkCanvas* canvasA = surfaceA->newCanvas();
+ * ...
+ * SkSurface* surfaceB = surfaceA->newSurface(...);
+ * SkCanvas* canvasB = surfaceB->newCanvas();
+ * ... // draw using canvasB
+ * canvasA->drawSurface(surfaceB); // <--- this will always be optimal!
+ */
+ SkSurface* newSurface(int width, int height);
+
+ /**
* Returns an image of the current state of the surface pixels up to this
* point. Subsequent changes to the surface (by drawing into its canvas)
* will not be reflected in this image.
@@ -98,7 +149,7 @@ public:
* we'd know that the "snapshot" need only live until we've handed it off
* to the canvas.
*/
- void SkCanvas::drawSurface(...);
+ void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*);
};
#endif