diff options
author | 2014-04-18 18:04:41 +0000 | |
---|---|---|
committer | 2014-04-18 18:04:41 +0000 | |
commit | 770963f23f4fc313db0fa3bac18b1b8aafb55f17 (patch) | |
tree | e5260b887047621f440fdeca0ff716455d4849b7 /include | |
parent | 7b8999b5047e059f8dbce2bb24586ac49d928731 (diff) |
Staging for cleanup of SkPicture-related headers
https://codereview.chromium.org/243173002
git-svn-id: http://skia.googlecode.com/svn/trunk@14258 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkBBHFactory.h | 69 | ||||
-rw-r--r-- | include/core/SkPicture.h | 102 | ||||
-rw-r--r-- | include/core/SkPictureRecorder.h | 107 | ||||
-rw-r--r-- | include/core/SkRTreePicture.h | 14 | ||||
-rw-r--r-- | include/core/SkTileGridPicture.h | 37 |
5 files changed, 190 insertions, 139 deletions
diff --git a/include/core/SkBBHFactory.h b/include/core/SkBBHFactory.h new file mode 100644 index 0000000000..bd85d94418 --- /dev/null +++ b/include/core/SkBBHFactory.h @@ -0,0 +1,69 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkBBHFactory_DEFINED +#define SkBBHFactory_DEFINED + +#include "SkSize.h" +#include "SkPoint.h" + +class SkBBoxHierarchy; + +class SkBBHFactory { +public: + /** + * Allocate a new SkBBoxHierarchy. Return NULL on failure. + */ + virtual SkBBoxHierarchy* operator()(int width, int height) const = 0; + virtual ~SkBBHFactory() {}; +}; + +class SkQuadTreeFactory : public SkBBHFactory { +public: + virtual SkBBoxHierarchy* operator()(int width, int height) const SK_OVERRIDE; +private: + typedef SkBBHFactory INHERITED; +}; + + +class SkRTreeFactory : public SkBBHFactory { +public: + virtual SkBBoxHierarchy* operator()(int width, int height) const SK_OVERRIDE; +private: + typedef SkBBHFactory INHERITED; +}; + +class SkTileGridFactory : public SkBBHFactory { +public: + struct TileGridInfo { + /** Tile placement interval */ + SkISize fTileInterval; + + /** Pixel coverage overlap between adjacent tiles */ + SkISize fMargin; + + /** Offset added to device-space bounding box positions to convert + * them to tile-grid space. This can be used to adjust the "phase" + * of the tile grid to match probable query rectangles that will be + * used to search into the tile grid. As long as the offset is smaller + * or equal to the margin, there is no need to extend the domain of + * the tile grid to prevent data loss. + */ + SkIPoint fOffset; + }; + + SkTileGridFactory(const TileGridInfo& info) : fInfo(info) { } + + virtual SkBBoxHierarchy* operator()(int width, int height) const SK_OVERRIDE; + +private: + TileGridInfo fInfo; + + typedef SkBBHFactory INHERITED; +}; + +#endif diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index 14296e9c29..1f588a42b9 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -434,106 +434,8 @@ private: #endif -class SkBBHFactory { -public: - /** - * Allocate a new SkBBoxHierarchy. Return NULL on failure. - */ - virtual SkBBoxHierarchy* operator()(int width, int height) const = 0; - virtual ~SkBBHFactory() {}; -}; - -class SK_API SkPictureRecorder : SkNoncopyable { -public: -#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES - - SkPictureRecorder(SkPictureFactory* factory = NULL) { - fFactory.reset(factory); - if (NULL != fFactory.get()) { - fFactory.get()->ref(); - } - } - - /** Returns the canvas that records the drawing commands. - @param width the base width for the picture, as if the recording - canvas' bitmap had this width. - @param height the base width for the picture, as if the recording - canvas' bitmap had this height. - @param recordFlags optional flags that control recording. - @return the canvas. - */ - SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0) { - if (NULL != fFactory) { - fPicture.reset(fFactory->create(width, height)); - recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; - } else { - fPicture.reset(SkNEW(SkPicture)); - } - - return fPicture->beginRecording(width, height, recordFlags); - } +#ifdef SK_SUPPORT_LEGACY_PICTURE_HEADERS +#include "SkPictureRecorder.h" #endif - /** Returns the canvas that records the drawing commands. - @param width the base width for the picture, as if the recording - canvas' bitmap had this width. - @param height the base width for the picture, as if the recording - canvas' bitmap had this height. - @param bbhFactory factory to create desired acceleration structure - @param recordFlags optional flags that control recording. - @return the canvas. - */ - // TODO: allow default parameters once the other beginRecoding entry point is gone - SkCanvas* beginRecording(int width, int height, - SkBBHFactory* bbhFactory /* = NULL */, - uint32_t recordFlags /* = 0 */) { - fPicture.reset(SkNEW(SkPicture)); - return fPicture->beginRecording(width, height, bbhFactory, recordFlags); - } - - /** Returns the recording canvas if one is active, or NULL if recording is - not active. This does not alter the refcnt on the canvas (if present). - */ - SkCanvas* getRecordingCanvas() { - if (NULL != fPicture.get()) { - return fPicture->getRecordingCanvas(); - } - return NULL; - } - - /** Signal that the caller is done recording. This invalidates the canvas - returned by beginRecording/getRecordingCanvas, and returns the - created SkPicture. Note that the returned picture has its creation - ref which the caller must take ownership of. - */ - SkPicture* endRecording() { - if (NULL != fPicture.get()) { - fPicture->endRecording(); - return fPicture.detach(); - } - return NULL; - } - - /** Enable/disable all the picture recording optimizations (i.e., - those in SkPictureRecord). It is mainly intended for testing the - existing optimizations (i.e., to actually have the pattern - appear in an .skp we have to disable the optimization). Call right - after 'beginRecording'. - */ - void internalOnly_EnableOpts(bool enableOpts) { - if (NULL != fPicture.get()) { - fPicture->internalOnly_EnableOpts(enableOpts); - } - } - -private: -#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES - SkAutoTUnref<SkPictureFactory> fFactory; -#endif - - SkAutoTUnref<SkPicture> fPicture; - - typedef SkNoncopyable INHERITED; -}; - #endif diff --git a/include/core/SkPictureRecorder.h b/include/core/SkPictureRecorder.h new file mode 100644 index 0000000000..95ba7b04c7 --- /dev/null +++ b/include/core/SkPictureRecorder.h @@ -0,0 +1,107 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkPictureRecorder_DEFINED +#define SkPictureRecorder_DEFINED + +#include "SkBBHFactory.h" +#include "SkPicture.h" +#include "SkRefCnt.h" + +class SkCanvas; + +class SK_API SkPictureRecorder : SkNoncopyable { +public: +#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES + + SkPictureRecorder(SkPictureFactory* factory = NULL) { + fFactory.reset(factory); + if (NULL != fFactory.get()) { + fFactory.get()->ref(); + } + } + + /** Returns the canvas that records the drawing commands. + @param width the base width for the picture, as if the recording + canvas' bitmap had this width. + @param height the base width for the picture, as if the recording + canvas' bitmap had this height. + @param recordFlags optional flags that control recording. + @return the canvas. + */ + SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0) { + if (NULL != fFactory) { + fPicture.reset(fFactory->create(width, height)); + recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; + } else { + fPicture.reset(SkNEW(SkPicture)); + } + + return fPicture->beginRecording(width, height, recordFlags); + } +#endif + + /** Returns the canvas that records the drawing commands. + @param width the base width for the picture, as if the recording + canvas' bitmap had this width. + @param height the base width for the picture, as if the recording + canvas' bitmap had this height. + @param bbhFactory factory to create desired acceleration structure + @param recordFlags optional flags that control recording. + @return the canvas. + */ + // TODO: allow default parameters once the other beginRecoding entry point is gone + SkCanvas* beginRecording(int width, int height, + SkBBHFactory* bbhFactory /* = NULL */, + uint32_t recordFlags /* = 0 */); + + /** Returns the recording canvas if one is active, or NULL if recording is + not active. This does not alter the refcnt on the canvas (if present). + */ + SkCanvas* getRecordingCanvas() { + if (NULL != fPicture.get()) { + return fPicture->getRecordingCanvas(); + } + return NULL; + } + + /** Signal that the caller is done recording. This invalidates the canvas + returned by beginRecording/getRecordingCanvas, and returns the + created SkPicture. Note that the returned picture has its creation + ref which the caller must take ownership of. + */ + SkPicture* endRecording() { + if (NULL != fPicture.get()) { + fPicture->endRecording(); + return fPicture.detach(); + } + return NULL; + } + + /** Enable/disable all the picture recording optimizations (i.e., + those in SkPictureRecord). It is mainly intended for testing the + existing optimizations (i.e., to actually have the pattern + appear in an .skp we have to disable the optimization). Call right + after 'beginRecording'. + */ + void internalOnly_EnableOpts(bool enableOpts) { + if (NULL != fPicture.get()) { + fPicture->internalOnly_EnableOpts(enableOpts); + } + } + +private: +#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES + SkAutoTUnref<SkPictureFactory> fFactory; +#endif + + SkAutoTUnref<SkPicture> fPicture; + + typedef SkNoncopyable INHERITED; +}; + +#endif diff --git a/include/core/SkRTreePicture.h b/include/core/SkRTreePicture.h index 78cb52e369..8e8a2aae47 100644 --- a/include/core/SkRTreePicture.h +++ b/include/core/SkRTreePicture.h @@ -8,16 +8,14 @@ #ifndef SkRTreePicture_DEFINED #define SkRTreePicture_DEFINED -#include "SkPicture.h" - -class SkRTreeFactory : public SkBBHFactory { -public: - virtual SkBBoxHierarchy* operator()(int width, int height) const SK_OVERRIDE; -private: - typedef SkBBHFactory INHERITED; -}; +#ifdef SK_SUPPORT_LEGACY_PICTURE_HEADERS +#include "SkBBHFactory.h" +#endif #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES + +#include "SkPicture.h" + /** * Subclass of SkPicture that creates an RTree acceleration structure. */ diff --git a/include/core/SkTileGridPicture.h b/include/core/SkTileGridPicture.h index 6dbe2fc63b..0196940919 100644 --- a/include/core/SkTileGridPicture.h +++ b/include/core/SkTileGridPicture.h @@ -8,41 +8,16 @@ #ifndef SkTileGridPicture_DEFINED #define SkTileGridPicture_DEFINED +#ifdef SK_SUPPORT_LEGACY_PICTURE_HEADERS +#include "SkBBHFactory.h" +#endif + +#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES + #include "SkPicture.h" #include "SkPoint.h" #include "SkSize.h" -class SkTileGridFactory : public SkBBHFactory { -public: - struct TileGridInfo { - /** Tile placement interval */ - SkISize fTileInterval; - - /** Pixel coverage overlap between adjacent tiles */ - SkISize fMargin; - - /** Offset added to device-space bounding box positions to convert - * them to tile-grid space. This can be used to adjust the "phase" - * of the tile grid to match probable query rectangles that will be - * used to search into the tile grid. As long as the offset is smaller - * or equal to the margin, there is no need to extend the domain of - * the tile grid to prevent data loss. - */ - SkIPoint fOffset; - }; - - SkTileGridFactory(const TileGridInfo& info) : fInfo(info) { } - - virtual SkBBoxHierarchy* operator()(int width, int height) const SK_OVERRIDE; - -private: - TileGridInfo fInfo; - - typedef SkBBHFactory INHERITED; -}; - -#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES - /** * Subclass of SkPicture that creates an SkTileGrid. The tile grid has lower recording * and playback costs then rTree, but is less effective at eliminating extraneous |