diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkCanvas.h | 47 | ||||
-rw-r--r-- | include/core/SkDevice.h | 45 | ||||
-rw-r--r-- | include/utils/SkGLCanvas.h | 47 |
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 - |