aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authortedbo <tedbo@google.com>2010-11-10 17:07:37 -0800
committertedbo <tedbo@google.com>2010-11-11 09:21:15 -0800
commit20ab88413000fcc8668eeab25d9cb714097d0c45 (patch)
tree6510be768788bfe613b3061b1dbda0b848378b74 /include
parent25c9ae8253171f35b9a14dd2adc5775929330e7b (diff)
downloadexternal_skia-20ab88413000fcc8668eeab25d9cb714097d0c45.zip
external_skia-20ab88413000fcc8668eeab25d9cb714097d0c45.tar.gz
external_skia-20ab88413000fcc8668eeab25d9cb714097d0c45.tar.bz2
Skia: Merge upstream patch series that refactors SkCanvas to avoid subclassing.
This change merges upstream Skia revisions r604,r605,r618, and r623. The patch series refactors SkCanvas so that backends don't need to override it. The r623 patch was upstreamed explicitly so that this series can be made into a clean patch for Android to avoid merge conflicts in the future. The log messages from the original commits are as follows: * r604: http://code.google.com/p/skia/source/detail?r=604 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. * r605: http://code.google.com/p/skia/source/detail?r=605 Fix a memory leak in the new Canvas/Device workflow. The previous change made it difficult to inherit from SkCanvas without leaking memory. By making SkDeviceFactory not reference counted, the right thing happens more naturally, just NewCanvas : public SkCanvas(new NewDeviceFactory()) {...} * r618: http://code.google.com/p/skia/source/detail?r=618 Move the device capability method to SkDevice. These are not the capabilities of the factory, but of the device. Additionally, it is more often needed when you have a device then when you have a factory, which caused creating of a new factory. * r623: http://code.google.com/p/skia/source/detail?r=623 Remove include of SkGLDevice.h from SkGLCanvas.h The '#include "SkGLDevice.h"' from include/core/SkDevice.h requires internal Skia code to be added to the include search paths when using the deprecated API. This change adds back SkGLCanvas.cpp to avoid exposing SkGLDevice.h to the public API. The change also includes an explicit virtual destructor on SkDeviceFactory to silence a -Wnon-virtual-dtor warning and allow for -Werror. Change-Id: I3442e2801c1d8d8c9cb2a20259f15bc870c393dc
Diffstat (limited to 'include')
-rw-r--r--include/core/SkCanvas.h47
-rw-r--r--include/core/SkDevice.h45
-rw-r--r--include/utils/SkGLCanvas.h47
3 files changed, 68 insertions, 71 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index bfa0d10..b5ccca6 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
+ SkRasterDeviceFactory 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,
@@ -758,6 +768,7 @@ private:
SkBounder* fBounder;
SkDevice* fLastDeviceToGainFocus;
+ SkDeviceFactory* fDeviceFactory;
void prepareForDeviceDraw(SkDevice*);
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index 0d724ba..dbc8fcf 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,26 +22,53 @@
#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:
+ virtual ~SkDeviceFactory();
+ virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
+ bool isOpaque, bool isForLayer) = 0;
+};
+
+class SkRasterDeviceFactory : public SkDeviceFactory {
+public:
+ virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
+ bool isOpaque, bool isForLayer);
+};
+
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);
+ }
+
+ enum Capabilities {
+ kGL_Capability = 0x1, //!< mask indicating GL support
+ kVector_Capability = 0x2, //!< mask indicating a vector representation
+ kAll_Capabilities = 0x3
+ };
+ virtual uint32_t getDeviceCapabilities() { return 0; }
+
/** Return the width of the device (in pixels).
*/
int width() const { return fBitmap.width(); }
diff --git a/include/utils/SkGLCanvas.h b/include/utils/SkGLCanvas.h
index 40fc52d..eb99527 100644
--- a/include/utils/SkGLCanvas.h
+++ b/include/utils/SkGLCanvas.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 The Android Open Source Project
+ * Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,31 +19,11 @@
#include "SkCanvas.h"
-#ifdef SK_BUILD_FOR_MAC
- #include <OpenGL/gl.h>
-#elif defined(ANDROID)
- #include <GLES/gl.h>
-#endif
-
-class SkGLDevice;
-class SkGLClipIter;
-
+// Deprecated. You should now use SkGLDevice and SkGLDeviceFactory with
+// SkCanvas.
class SkGLCanvas : public SkCanvas {
public:
- // notice, we do NOT allow the SkCanvas(bitmap) constructor, since that
- // does not create a SkGLDevice, which we require
SkGLCanvas();
- virtual ~SkGLCanvas();
-
- // overrides from SkCanvas
-
- virtual bool getViewport(SkIPoint*) const;
- virtual bool setViewport(int width, int height);
-
- virtual SkDevice* createDevice(SkBitmap::Config, int width, int height,
- bool isOpaque, bool isForLayer);
-
- // settings for the global texture cache
static size_t GetTextureCacheMaxCount();
static void SetTextureCacheMaxCount(size_t count);
@@ -51,30 +31,9 @@ public:
static size_t GetTextureCacheMaxSize();
static void SetTextureCacheMaxSize(size_t size);
- /** Call glDeleteTextures for all textures (including those for text)
- This should be called while the gl-context is still valid. Its purpose
- is to free up gl resources. Note that if a bitmap or text is drawn after
- this call, new caches will be created.
- */
static void DeleteAllTextures();
- /** Forget all textures without calling delete (including those for text).
- This should be called if the gl-context has changed, and the texture
- IDs that have been cached are no longer valid.
- */
static void AbandonAllTextures();
-
-private:
- SkIPoint fViewportSize;
-
- // need to disallow this guy
- virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap) {
- sk_throw();
- return NULL;
- }
-
- typedef SkCanvas INHERITED;
};
#endif
-