aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-28 12:19:02 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-28 12:19:02 +0000
commit97af1a64ae6bdddd346d8babfd9f188279dd6644 (patch)
tree00ed8f9919b9f2623b4d08e33ef61f80018d6eb4 /include/core
parent91ee3a11ed476f4f08e1e4ae183002c56349ec19 (diff)
Add caching of the snapshot image form a surface
Notify the surface when the canvas draws into it, so it can invalidate the cached image, and (if needed) perform a copy-on-write on the surface if it was being shared with the image. Review URL: https://codereview.appspot.com/6441115 git-svn-id: http://skia.googlecode.com/svn/trunk@5306 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkCanvas.h12
-rw-r--r--include/core/SkDevice.h6
-rw-r--r--include/core/SkImage.h2
-rw-r--r--include/core/SkSurface.h15
4 files changed, 29 insertions, 6 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 01e0c75a24..1f29e1c00a 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -26,6 +26,7 @@ class SkDevice;
class SkDraw;
class SkDrawFilter;
class SkPicture;
+class SkSurface_Base;
/** \class SkCanvas
@@ -950,6 +951,10 @@ protected:
bool clipRectBounds(const SkRect* bounds, SaveFlags flags,
SkIRect* intersection);
+ // notify our surface (if we have one) that we are about to draw, so it
+ // can perform copy-on-write or invalidate any cached images
+ void predrawNotify();
+
private:
class MCRec;
@@ -964,6 +969,13 @@ private:
SkDevice* fLastDeviceToGainFocus;
int fSaveLayerCount; // number of successful saveLayer calls
+ SkSurface_Base* fSurfaceBase;
+ SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
+ void setSurfaceBase(SkSurface_Base* sb) {
+ fSurfaceBase = sb;
+ }
+ friend class SkSurface_Base;
+
void prepareForDeviceDraw(SkDevice*, const SkMatrix&, const SkRegion&);
bool fDeviceCMDirty; // cleared by updateDeviceCMCache()
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index 326115ca31..41e316c9cc 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -380,6 +380,12 @@ private:
friend class SkDeviceFilteredPaint;
friend class DeviceImageFilterProxy;
+ friend class SkSurface_Raster;
+ // used to change the backend's pixels (and possibly config/rowbytes)
+ // but cannot change the width/height, so there should be no change to
+ // any clip information.
+ void replaceBitmapBackendForRasterSurface(const SkBitmap&);
+
// just called by SkCanvas when built as a layer
void setOrigin(int x, int y) { fOrigin.set(x, y); }
// just called by SkCanvas for saveLayer
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index 985a3bbbbb..b0071e28d8 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -37,7 +37,7 @@ class SkColorSpace;
*/
class SkImage : public SkRefCnt {
public:
- SK_DECLARE_INST_COUNT(SkImage)
+// SK_DECLARE_INST_COUNT(SkImage)
enum ColorType {
kAlpha_8_ColorType,
diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h
index 8e407b92f6..9f8908a3bd 100644
--- a/include/core/SkSurface.h
+++ b/include/core/SkSurface.h
@@ -26,7 +26,7 @@ class GrRenderTarget;
*/
class SkSurface : public SkRefCnt {
public:
- SK_DECLARE_INST_COUNT(SkSurface)
+// SK_DECLARE_INST_COUNT(SkSurface)
/**
* Create a new surface, using the specified pixels/rowbytes as its
@@ -78,7 +78,7 @@ public:
* If this surface is empty (i.e. has a zero-dimention), this will return
* 0.
*/
- uint32_t generationID() const;
+ uint32_t generationID();
/**
* Call this if the contents have changed. This will (lazily) force a new
@@ -128,10 +128,15 @@ public:
protected:
SkSurface(int width, int height);
+ // called by subclass if their contents have changed
+ void dirtyGenerationID() {
+ fGenerationID = 0;
+ }
+
private:
- const int fWidth;
- const int fHeight;
- mutable uint32_t fGenerationID;
+ const int fWidth;
+ const int fHeight;
+ uint32_t fGenerationID;
};
#endif