aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
authorGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2010-10-13 22:13:05 +0000
committerGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2010-10-13 22:13:05 +0000
commit8d84fac294682647694b0d2d8a87ac2bd19b6aab (patch)
tree2bfd3dea3c5c79bf42003ce620a51069526f28f0 /include/core
parent60eaa398ebdded0fb7957724c170baabef811e17 (diff)
Refactor SkCanvas so that backends don't need to override it.
Methods or classes that should go away are marked deprecated. The only thing I know of that breaks backward compatibility is SkCanvas((SkDevice*)NULL), but that is fairly unlikely to occur in the wild because that constructor had a default value of NULL. Review URL: http://codereview.appspot.com/2103045 git-svn-id: http://skia.googlecode.com/svn/trunk@604 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkCanvas.h47
-rw-r--r--include/core/SkDevice.h42
2 files changed, 63 insertions, 26 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 0ccc2dd999..6d995b8b55 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -29,6 +29,7 @@
class SkBounder;
class SkDevice;
+class SkDeviceFactory;
class SkDraw;
class SkDrawFilter;
class SkPicture;
@@ -51,29 +52,37 @@ class SkShape;
*/
class SkCanvas : public SkRefCnt {
public:
- /** Construct a canvas with the specified bitmap to draw into.
+ /** Construct a canvas with the given device factory.
+ @param factory Specify the factory for generating additional devices.
+ The factory may be null, in which case SkDeviceFactory
+ will be used.
+ */
+ explicit SkCanvas(SkDeviceFactory* factory = NULL);
+
+ /** Construct a canvas with the specified device to draw into. The device
+ factory will be retrieved from the passed device.
+ @param device Specifies a device for the canvas to draw into.
+ */
+ explicit SkCanvas(SkDevice* device);
+
+ /** Deprecated - Construct a canvas with the specified bitmap to draw into.
@param bitmap Specifies a bitmap for the canvas to draw into. Its
structure are copied to the canvas.
*/
explicit SkCanvas(const SkBitmap& bitmap);
- /** Construct a canvas with the specified device to draw into.
- @param device Specifies a device for the canvas to draw into. The
- device may be null.
- */
- explicit SkCanvas(SkDevice* device = NULL);
virtual ~SkCanvas();
///////////////////////////////////////////////////////////////////////////
- /** If this subclass of SkCanvas supports GL viewports, return true and set
- size (if not null) to the size of the viewport. If it is not supported,
- ignore vp and return false.
+ /** If the Device supports GL viewports, return true and set size (if not
+ null) to the size of the viewport. If it is not supported, ignore size
+ and return false.
*/
virtual bool getViewport(SkIPoint* size) const;
-
- /** If this subclass of SkCanvas supports GL viewports, return true and set
- the viewport to the specified x and y dimensions. If it is not
- supported, ignore x and y and return false.
+
+ /** If the Device supports GL viewports, return true and set the viewport
+ to the specified x and y dimensions. If it is not supported, ignore x
+ and y and return false.
*/
virtual bool setViewport(int x, int y);
@@ -88,15 +97,16 @@ public:
device, its reference count is decremented. The new device is returned.
*/
SkDevice* setDevice(SkDevice* device);
-
- /** Specify a bitmap for the canvas to draw into. This is a help method for
- setDevice(), and it creates a device for the bitmap by calling
- createDevice(). The structure of the bitmap is copied into the device.
+
+ /** Deprecated - Specify a bitmap for the canvas to draw into. This is a
+ helper method for setDevice(), and it creates a device for the bitmap by
+ calling createDevice(). The structure of the bitmap is copied into the
+ device.
*/
virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap);
///////////////////////////////////////////////////////////////////////////
-
+
enum SaveFlags {
/** save the matrix state, restoring it on restore() */
kMatrix_SaveFlag = 0x01,
@@ -749,6 +759,7 @@ private:
SkBounder* fBounder;
SkDevice* fLastDeviceToGainFocus;
+ SkDeviceFactory* fDeviceFactory;
void prepareForDeviceDraw(SkDevice*);
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index 4d678c6a40..b7a9cbcb3a 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -22,26 +22,52 @@
#include "SkCanvas.h"
#include "SkColor.h"
+class SkDevice;
class SkDraw;
struct SkIRect;
class SkMatrix;
class SkRegion;
+/** \class SkDeviceFactory
+
+ Devices that extend SkDevice should also provide a SkDeviceFactory class
+ to pass into SkCanvas. Doing so will eliminate the need to extend
+ SkCanvas as well.
+*/
+class SkDeviceFactory : public SkRefCnt {
+public:
+ virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
+ bool isOpaque, bool isForLayer) = 0;
+
+ enum Capabilities {
+ kGL_Capability = 0x1, //!< mask to indicate this device supports GL
+ kAll_Capabilities = 0x1
+ };
+ virtual uint32_t getDeviceCapabilities() = 0;
+};
+
+class SkRasterDeviceFactory : public SkDeviceFactory {
+public:
+ virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
+ bool isOpaque, bool isForLayer);
+ virtual uint32_t getDeviceCapabilities() { return 0; }
+};
+
class SkDevice : public SkRefCnt {
public:
SkDevice();
- /** Construct a new device, extracting the width/height/config/isOpaque values from
- the bitmap. If transferPixelOwnership is true, and the bitmap claims to own its
- own pixels (getOwnsPixels() == true), then transfer this responsibility to the
- device, and call setOwnsPixels(false) on the bitmap.
-
- Subclasses may override the destructor, which is virtual, even though this class
- doesn't have one. SkRefCnt does.
-
+ /** Construct a new device, extracting the width/height/config/isOpaque
+ values from the bitmap. Subclasses may override the destructor, which
+ is virtual, even though this class doesn't have one. SkRefCnt does.
+
@param bitmap A copy of this bitmap is made and stored in the device
*/
SkDevice(const SkBitmap& bitmap);
+ virtual SkDeviceFactory* getDeviceFactory() {
+ return SkNEW(SkRasterDeviceFactory);
+ }
+
/** Return the width of the device (in pixels).
*/
int width() const { return fBitmap.width(); }