aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-04-26 11:48:33 +0000
committerGravatar mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-04-26 11:48:33 +0000
commitea4ac97dec2eb291139bd906939e0d2e05cdd7ef (patch)
treed9eee5c680c32669a48c21a564515a66e00a1258 /include
parent9ce767c41333682c858ff26e99be2b800a2ef2b0 (diff)
make SkDeviceFactory reference counted
git-svn-id: http://skia.googlecode.com/svn/trunk@1180 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r--include/core/SkCanvas.h7
-rw-r--r--include/core/SkDevice.h21
-rw-r--r--include/gpu/SkGpuDevice.h3
-rw-r--r--include/pdf/SkPDFDevice.h8
4 files changed, 29 insertions, 10 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 6b2ee10e75..b1222eb874 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -126,12 +126,15 @@ public:
SkDevice* setBitmapDevice(const SkBitmap& bitmap, bool forLayer = false);
/**
- * Return the current device factory, or NULL.
+ * Return the current device factory, or NULL. The reference count of
+ * the returned factory is not changed.
*/
SkDeviceFactory* getDeviceFactory() const { return fDeviceFactory; }
/**
- * Replace any existing factory with the specified factory.
+ * Replace any existing factory with the specified factory, unrefing the
+ * previous (if any), and refing the new one (if any). For convenience,
+ * the factory parameter is also returned.
*/
SkDeviceFactory* setDeviceFactory(SkDeviceFactory*);
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index 5755e955e0..d9a4fde4c2 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -36,8 +36,9 @@ class SkRegion;
to pass into SkCanvas. Doing so will eliminate the need to extend
SkCanvas as well.
*/
-class SK_API SkDeviceFactory {
+class SK_API SkDeviceFactory : public SkRefCnt {
public:
+ SkDeviceFactory();
virtual ~SkDeviceFactory();
virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width,
int height, bool isOpaque, bool isLayer) = 0;
@@ -65,9 +66,12 @@ public:
SkDevice(SkCanvas*, const SkBitmap& bitmap, bool forOffscreen);
virtual ~SkDevice();
- virtual SkDeviceFactory* getDeviceFactory() {
- return SkNEW(SkRasterDeviceFactory);
- }
+ /**
+ * Return the factory that will create this subclass of SkDevice.
+ * The returned factory is cached by the device, and so its reference count
+ * is not changed by this call.
+ */
+ SkDeviceFactory* getDeviceFactory();
enum Capabilities {
kGL_Capability = 0x1, //!< mask indicating GL support
@@ -247,6 +251,13 @@ public:
virtual bool filterTextFlags(const SkPaint& paint, TextFlags*);
protected:
+ /**
+ * subclasses must override this to return a new (or ref'd) instance of
+ * a device factory that will create this subclass of device. This value
+ * is cached, so it should get called at most once for a given instance.
+ */
+ virtual SkDeviceFactory* onNewDeviceFactory();
+
/** Update as needed the pixel value in the bitmap, so that the caller can access
the pixels directly. Note: only the pixels field should be altered. The config/width/height/rowbytes
must remain unchanged.
@@ -269,6 +280,8 @@ private:
SkBitmap fBitmap;
SkIPoint fOrigin;
SkMetaData* fMetaData;
+
+ SkDeviceFactory* fCachedDeviceFactory;
};
#endif
diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h
index ff1bb0d362..15def87942 100644
--- a/include/gpu/SkGpuDevice.h
+++ b/include/gpu/SkGpuDevice.h
@@ -121,6 +121,9 @@ public:
virtual void makeRenderTargetCurrent();
protected:
+ // override
+ virtual SkDeviceFactory* onNewDeviceFactory();
+
class TexCache;
TexCache* lockCachedTexture(const SkBitmap& bitmap,
const GrSamplerState& sampler,
diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h
index ac9ef20fc4..0d06fe6715 100644
--- a/include/pdf/SkPDFDevice.h
+++ b/include/pdf/SkPDFDevice.h
@@ -61,10 +61,6 @@ public:
SkPDFDevice(int width, int height, const SkMatrix& initialTransform);
virtual ~SkPDFDevice();
- virtual SkDeviceFactory* getDeviceFactory() {
- return SkNEW(SkPDFDeviceFactory);
- }
-
virtual uint32_t getDeviceCapabilities() { return kVector_Capability; }
virtual int width() const { return fWidth; };
@@ -138,6 +134,10 @@ public:
*/
SkStream* content() const;
+protected:
+ // override
+ virtual SkDeviceFactory* onNewDeviceFactory();
+
private:
int fWidth;
int fHeight;