diff options
author | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-18 18:04:41 +0000 |
---|---|---|
committer | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-18 18:04:41 +0000 |
commit | 770963f23f4fc313db0fa3bac18b1b8aafb55f17 (patch) | |
tree | e5260b887047621f440fdeca0ff716455d4849b7 | |
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
46 files changed, 297 insertions, 207 deletions
diff --git a/bench/PicturePlaybackBench.cpp b/bench/PicturePlaybackBench.cpp index 436b652e8c..08c96d59b5 100644 --- a/bench/PicturePlaybackBench.cpp +++ b/bench/PicturePlaybackBench.cpp @@ -9,6 +9,7 @@ #include "SkColor.h" #include "SkPaint.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkPoint.h" #include "SkRect.h" #include "SkString.h" diff --git a/bench/PictureRecordBench.cpp b/bench/PictureRecordBench.cpp index 62f02b6c2b..0666cc4211 100644 --- a/bench/PictureRecordBench.cpp +++ b/bench/PictureRecordBench.cpp @@ -9,6 +9,7 @@ #include "SkColor.h" #include "SkPaint.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkPoint.h" #include "SkRandom.h" #include "SkRect.h" diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp index 4bdc044a3f..9cdaa68ebc 100644 --- a/bench/benchmain.cpp +++ b/bench/benchmain.cpp @@ -20,6 +20,7 @@ #include "SkImageEncoder.h" #include "SkOSFile.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkString.h" #include "SkSurface.h" diff --git a/debugger/SkDebugger.cpp b/debugger/SkDebugger.cpp index 164c5d60a2..f4730d61b5 100644 --- a/debugger/SkDebugger.cpp +++ b/debugger/SkDebugger.cpp @@ -7,6 +7,7 @@ */ #include "SkDebugger.h" +#include "SkPictureRecorder.h" #include "SkString.h" diff --git a/dm/DMReplayTask.cpp b/dm/DMReplayTask.cpp index 791370d6ab..cea978f138 100644 --- a/dm/DMReplayTask.cpp +++ b/dm/DMReplayTask.cpp @@ -2,9 +2,9 @@ #include "DMWriteTask.h" #include "DMUtil.h" +#include "SkBBHFactory.h" #include "SkCommandLineFlags.h" #include "SkPicture.h" -#include "SkRTreePicture.h" DEFINE_bool(replay, true, "If true, run picture replay tests."); DEFINE_bool(rtree, true, "If true, run picture replay tests with an rtree."); diff --git a/dm/DMTileGridTask.cpp b/dm/DMTileGridTask.cpp index 9a036bfeae..4299bd7985 100644 --- a/dm/DMTileGridTask.cpp +++ b/dm/DMTileGridTask.cpp @@ -2,9 +2,9 @@ #include "DMWriteTask.h" #include "DMUtil.h" +#include "SkBBHFactory.h" #include "SkCommandLineFlags.h" #include "SkPicture.h" -#include "SkTileGridPicture.h" // TODO(mtklein): Tile grid tests are currently failing. (Skia issue 1198). When fixed, -> true. DEFINE_bool(tileGrid, false, "If true, run picture replay tests with a tile grid."); diff --git a/dm/DMUtil.cpp b/dm/DMUtil.cpp index bf7fbf9f40..9a4765abb0 100644 --- a/dm/DMUtil.cpp +++ b/dm/DMUtil.cpp @@ -1,6 +1,7 @@ #include "DMUtil.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" namespace DM { diff --git a/gm/distantclip.cpp b/gm/distantclip.cpp index 1fcded05bf..9c2a5b6de1 100644 --- a/gm/distantclip.cpp +++ b/gm/distantclip.cpp @@ -10,6 +10,7 @@ #include "gm.h" #include "SkCanvas.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" namespace skiagm { diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp index f8e55e1b1f..abec1055ae 100644 --- a/gm/gmmain.cpp +++ b/gm/gmmain.cpp @@ -34,16 +34,14 @@ #include "SkOSFile.h" #include "SkPDFRasterizer.h" #include "SkPicture.h" -#include "SkQuadTreePicture.h" +#include "SkPictureRecorder.h" #include "SkRefCnt.h" -#include "SkRTreePicture.h" #include "SkScalar.h" #include "SkStream.h" #include "SkString.h" #include "SkSurface.h" #include "SkTArray.h" #include "SkTDict.h" -#include "SkTileGridPicture.h" #include "SamplePipeControllers.h" #ifdef SK_DEBUG diff --git a/gm/optimizations.cpp b/gm/optimizations.cpp index 531a4f3270..d810420f0a 100644 --- a/gm/optimizations.cpp +++ b/gm/optimizations.cpp @@ -8,6 +8,7 @@ #include "gm.h" #include "SkDebugCanvas.h" #include "SkPictureFlat.h" +#include "SkPictureRecorder.h" #define WARN(msg) \ SkDebugf("%s:%d: %s\n", __FILE__, __LINE__, msg); diff --git a/gm/pathopsskpclip.cpp b/gm/pathopsskpclip.cpp index 4a08b31418..8346745bcd 100644 --- a/gm/pathopsskpclip.cpp +++ b/gm/pathopsskpclip.cpp @@ -13,6 +13,7 @@ #include "SkPath.h" #include "SkPathOps.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkRect.h" namespace skiagm { diff --git a/gm/pictureimagefilter.cpp b/gm/pictureimagefilter.cpp index 07d4a068be..b0fd057235 100644 --- a/gm/pictureimagefilter.cpp +++ b/gm/pictureimagefilter.cpp @@ -8,6 +8,7 @@ #include "gm.h" #include "SkPictureImageFilter.h" +#include "SkPictureRecorder.h" // This GM exercises the SkPictureImageFilter ImageFilter class. diff --git a/gm/pictureshader.cpp b/gm/pictureshader.cpp index 8889a0c5e7..195ee738bc 100644 --- a/gm/pictureshader.cpp +++ b/gm/pictureshader.cpp @@ -10,6 +10,7 @@ #include "SkBitmap.h" #include "SkPaint.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkShader.h" namespace skiagm { diff --git a/gyp/common_conditions.gypi b/gyp/common_conditions.gypi index 567b41b630..f312df9778 100644 --- a/gyp/common_conditions.gypi +++ b/gyp/common_conditions.gypi @@ -298,6 +298,7 @@ 'SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD', 'SK_SUPPORT_DEPRECATED_RECORD_FLAGS', 'SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES', + 'SK_SUPPORT_LEGACY_PICTURE_HEADERS', 'SK_SUPPORT_LEGACY_BLURDRAWLOOPERCONSTRUCTORS', ], }], diff --git a/gyp/core.gypi b/gyp/core.gypi index f1f88f8ec3..1bcde4cbb3 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -13,6 +13,7 @@ '<(skia_src_path)/core/SkAdvancedTypefaceMetrics.cpp', '<(skia_src_path)/core/SkAlphaRuns.cpp', '<(skia_src_path)/core/SkAntiRun.h', + '<(skia_src_path)/core/SkBBHFactory.cpp', '<(skia_src_path)/core/SkBBoxHierarchy.h', '<(skia_src_path)/core/SkBBoxRecord.cpp', '<(skia_src_path)/core/SkBBoxRecord.h', @@ -133,6 +134,7 @@ '<(skia_src_path)/core/SkPicturePlayback.h', '<(skia_src_path)/core/SkPictureRecord.cpp', '<(skia_src_path)/core/SkPictureRecord.h', + '<(skia_src_path)/core/SkPictureRecorder.cpp', '<(skia_src_path)/core/SkPictureShader.cpp', '<(skia_src_path)/core/SkPictureShader.h', '<(skia_src_path)/core/SkPictureStateTree.cpp', @@ -219,6 +221,7 @@ '<(skia_src_path)/pipe/SkGPipeWrite.cpp', '<(skia_include_path)/core/SkAdvancedTypefaceMetrics.h', + '<(skia_include_path)/core/SkBBHFactory.h', '<(skia_include_path)/core/SkBitmap.h', '<(skia_include_path)/core/SkBitmapDevice.h', '<(skia_include_path)/core/SkBlitRow.h', @@ -271,6 +274,7 @@ '<(skia_include_path)/core/SkPathMeasure.h', '<(skia_include_path)/core/SkPathRef.h', '<(skia_include_path)/core/SkPicture.h', + '<(skia_include_path)/core/SkPictureRecorder.h', '<(skia_include_path)/core/SkPixelRef.h', '<(skia_include_path)/core/SkPoint.h', '<(skia_include_path)/core/SkPreConfig.h', diff --git a/gyp/skia_for_chromium_defines.gypi b/gyp/skia_for_chromium_defines.gypi index cb65861e28..affd807f04 100644 --- a/gyp/skia_for_chromium_defines.gypi +++ b/gyp/skia_for_chromium_defines.gypi @@ -20,6 +20,7 @@ 'SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES', 'SK_SUPPORT_LEGACY_N32_NAME', 'SK_SUPPORT_LEGACY_PROCXFERMODE', + 'SK_SUPPORT_LEGACY_PICTURE_HEADERS', ], }, } 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 diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp index 4f4116b3b0..35eeabab12 100644 --- a/samplecode/SampleAll.cpp +++ b/samplecode/SampleAll.cpp @@ -26,6 +26,7 @@ #include "SkLayerRasterizer.h" #include "SkMath.h" #include "SkPath.h" +#include "SkPictureRecorder.h" #include "SkRegion.h" #include "SkShader.h" #include "SkComposeShader.h" diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 67be5be335..b7cc021d2b 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -14,6 +14,7 @@ #include "SkImageEncoder.h" #include "SkPaint.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkStream.h" #include "SkTSort.h" #include "SkTime.h" diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h index 13bc697bd5..fa859010c1 100644 --- a/samplecode/SampleApp.h +++ b/samplecode/SampleApp.h @@ -11,6 +11,7 @@ #include "SkOSMenu.h" #include "SkPath.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkScalar.h" #include "SkTDArray.h" #include "SkTouchGesture.h" diff --git a/samplecode/SamplePictFile.cpp b/samplecode/SamplePictFile.cpp index 59a7f4b55a..7b9584d305 100644 --- a/samplecode/SamplePictFile.cpp +++ b/samplecode/SamplePictFile.cpp @@ -15,12 +15,10 @@ #include "SkOSFile.h" #include "SkPath.h" #include "SkPicture.h" -#include "SkQuadTreePicture.h" +#include "SkPictureRecorder.h" #include "SkRandom.h" #include "SkRegion.h" -#include "SkRTreePicture.h" #include "SkShader.h" -#include "SkTileGridPicture.h" #include "SkUtils.h" #include "SkColorPriv.h" #include "SkColorFilter.h" diff --git a/samplecode/SamplePicture.cpp b/samplecode/SamplePicture.cpp index 202e172234..e6969037fd 100644 --- a/samplecode/SamplePicture.cpp +++ b/samplecode/SamplePicture.cpp @@ -17,6 +17,7 @@ #include "SkOSFile.h" #include "SkPath.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkRandom.h" #include "SkRegion.h" #include "SkShader.h" diff --git a/samplecode/SampleTiling.cpp b/samplecode/SampleTiling.cpp index ffae6a4d94..cc3b52915d 100644 --- a/samplecode/SampleTiling.cpp +++ b/samplecode/SampleTiling.cpp @@ -10,6 +10,7 @@ #include "SkCanvas.h" #include "SkPaint.h" #include "SkPath.h" +#include "SkPictureRecorder.h" #include "SkRegion.h" #include "SkShader.h" #include "SkUtils.h" diff --git a/src/core/SkBBHFactory.cpp b/src/core/SkBBHFactory.cpp new file mode 100644 index 0000000000..7411eb34da --- /dev/null +++ b/src/core/SkBBHFactory.cpp @@ -0,0 +1,44 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkBBHFactory.h" +#include "SkPictureStateTree.h" +#include "SkQuadTree.h" +#include "SkRTree.h" +#include "SkTileGrid.h" + + +SkBBoxHierarchy* SkQuadTreeFactory::operator()(int width, int height) const { + return SkNEW_ARGS(SkQuadTree, (SkIRect::MakeWH(width, height))); +} + +SkBBoxHierarchy* SkRTreeFactory::operator()(int width, int height) const { + // These values were empirically determined to produce reasonable + // performance in most cases. + static const int kRTreeMinChildren = 6; + static const int kRTreeMaxChildren = 11; + + SkScalar aspectRatio = SkScalarDiv(SkIntToScalar(width), + SkIntToScalar(height)); + bool sortDraws = false; // Do not sort draw calls when bulk loading. + + return SkRTree::Create(kRTreeMinChildren, kRTreeMaxChildren, + aspectRatio, sortDraws); +} + +SkBBoxHierarchy* SkTileGridFactory::operator()(int width, int height) const { + SkASSERT(fInfo.fMargin.width() >= 0); + SkASSERT(fInfo.fMargin.height() >= 0); + // Note: SkIRects are non-inclusive of the right() column and bottom() row. + // For example, an SkIRect at 0,0 with a size of (1,1) will only have + // content at pixel (0,0) and will report left=0 and right=1, hence the + // "-1"s below. + int xTileCount = (width + fInfo.fTileInterval.width() - 1) / fInfo.fTileInterval.width(); + int yTileCount = (height + fInfo.fTileInterval.height() - 1) / fInfo.fTileInterval.height(); + return SkNEW_ARGS(SkTileGrid, (xTileCount, yTileCount, fInfo, + SkTileGridNextDatum<SkPictureStateTree::Draw>)); +} diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index 85e018f48a..316994a24b 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -11,6 +11,7 @@ #include "SkPicturePlayback.h" #include "SkPictureRecord.h" +#include "SkBBHFactory.h" #include "SkBitmapDevice.h" #include "SkCanvas.h" #include "SkChunkAlloc.h" diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp new file mode 100644 index 0000000000..a22cf5df14 --- /dev/null +++ b/src/core/SkPictureRecorder.cpp @@ -0,0 +1,15 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkPictureRecorder.h" + +SkCanvas* SkPictureRecorder::beginRecording(int width, int height, + SkBBHFactory* bbhFactory /* = NULL */, + uint32_t recordFlags /* = 0 */) { + fPicture.reset(SkNEW(SkPicture)); + return fPicture->beginRecording(width, height, bbhFactory, recordFlags); +} diff --git a/src/core/SkQuadTreePicture.cpp b/src/core/SkQuadTreePicture.cpp index 36093c69d5..a76899ee29 100644 --- a/src/core/SkQuadTreePicture.cpp +++ b/src/core/SkQuadTreePicture.cpp @@ -5,16 +5,12 @@ * found in the LICENSE file. */ +#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES + #include "SkQuadTreePicture.h" #include "SkQuadTree.h" -SkBBoxHierarchy* SkQuadTreeFactory::operator()(int width, int height) const { - return SkNEW_ARGS(SkQuadTree, (SkIRect::MakeWH(width, height))); -} - -#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES - SkBBoxHierarchy* SkQuadTreePicture::createBBoxHierarchy() const { return SkNEW_ARGS(SkQuadTree, (fBounds)); } diff --git a/src/core/SkQuadTreePicture.h b/src/core/SkQuadTreePicture.h index 13d2c3da1c..5ebbef93cb 100644 --- a/src/core/SkQuadTreePicture.h +++ b/src/core/SkQuadTreePicture.h @@ -8,17 +8,13 @@ #ifndef SkQuadTreePicture_DEFINED #define SkQuadTreePicture_DEFINED -#include "SkPicture.h" - -class SkQuadTreeFactory : 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" #include "SkRect.h" /** diff --git a/src/core/SkRTreePicture.cpp b/src/core/SkRTreePicture.cpp index 78b654ecc5..a9118aeb5f 100644 --- a/src/core/SkRTreePicture.cpp +++ b/src/core/SkRTreePicture.cpp @@ -5,26 +5,12 @@ * found in the LICENSE file. */ +#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES + #include "SkRTreePicture.h" #include "SkRTree.h" -SkBBoxHierarchy* SkRTreeFactory::operator()(int width, int height) const { - // These values were empirically determined to produce reasonable - // performance in most cases. - static const int kRTreeMinChildren = 6; - static const int kRTreeMaxChildren = 11; - - SkScalar aspectRatio = SkScalarDiv(SkIntToScalar(width), - SkIntToScalar(height)); - bool sortDraws = false; // Do not sort draw calls when bulk loading. - - return SkRTree::Create(kRTreeMinChildren, kRTreeMaxChildren, - aspectRatio, sortDraws); -} - -#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES - SkBBoxHierarchy* SkRTreePicture::createBBoxHierarchy() const { // These values were empirically determined to produce reasonable // performance in most cases. diff --git a/src/core/SkTileGrid.h b/src/core/SkTileGrid.h index 034d28ecbc..0ec5c2c393 100644 --- a/src/core/SkTileGrid.h +++ b/src/core/SkTileGrid.h @@ -9,9 +9,9 @@ #ifndef SkTileGrid_DEFINED #define SkTileGrid_DEFINED +#include "SkBBHFactory.h" #include "SkBBoxHierarchy.h" #include "SkPictureStateTree.h" -#include "SkTileGridPicture.h" // for TileGridInfo /** * Subclass of SkBBoxHierarchy that stores elements in buckets that correspond diff --git a/src/core/SkTileGridPicture.cpp b/src/core/SkTileGridPicture.cpp index f2f44a0bde..4a43f8a063 100644 --- a/src/core/SkTileGridPicture.cpp +++ b/src/core/SkTileGridPicture.cpp @@ -5,27 +5,13 @@ * found in the LICENSE file. */ +#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES + #include "SkTileGridPicture.h" #include "SkPictureStateTree.h" #include "SkTileGrid.h" - -SkBBoxHierarchy* SkTileGridFactory::operator()(int width, int height) const { - SkASSERT(fInfo.fMargin.width() >= 0); - SkASSERT(fInfo.fMargin.height() >= 0); - // Note: SkIRects are non-inclusive of the right() column and bottom() row. - // For example, an SkIRect at 0,0 with a size of (1,1) will only have - // content at pixel (0,0) and will report left=0 and right=1, hence the - // "-1"s below. - int xTileCount = (width + fInfo.fTileInterval.width() - 1) / fInfo.fTileInterval.width(); - int yTileCount = (height + fInfo.fTileInterval.height() - 1) / fInfo.fTileInterval.height(); - return SkNEW_ARGS(SkTileGrid, (xTileCount, yTileCount, fInfo, - SkTileGridNextDatum<SkPictureStateTree::Draw>)); -} - -#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES - SkTileGridPicture::SkTileGridPicture(int width, int height, const SkTileGridFactory::TileGridInfo& info) { SkASSERT(info.fMargin.width() >= 0); diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index da3c13612e..3b259ab0f5 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -55,6 +55,7 @@ #include "SkPath.h" #include "SkPicture.h" #include "SkPictureRecord.h" +#include "SkPictureRecorder.h" #include "SkProxyCanvas.h" #include "SkRect.h" #include "SkRegion.h" diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index a58c3af5a0..f968a4e9c5 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -24,7 +24,7 @@ #include "SkMorphologyImageFilter.h" #include "SkOffsetImageFilter.h" #include "SkPicture.h" -#include "SkRTreePicture.h" +#include "SkPictureRecorder.h" #include "SkRect.h" #include "SkTileImageFilter.h" #include "SkXfermodeImageFilter.h" diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp index deeef46244..0a1c3c66fc 100644 --- a/tests/PictureTest.cpp +++ b/tests/PictureTest.cpp @@ -15,14 +15,12 @@ #include "SkImageGenerator.h" #include "SkPaint.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkPictureUtils.h" -#include "SkQuadTreePicture.h" #include "SkRRect.h" #include "SkRandom.h" -#include "SkRTreePicture.h" #include "SkShader.h" #include "SkStream.h" -#include "SkTileGrid.h" #include "Test.h" static const int gColorScale = 30; diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp index b857d32ede..94d09c0735 100644 --- a/tests/SerializationTest.cpp +++ b/tests/SerializationTest.cpp @@ -9,6 +9,7 @@ #include "SkBitmapSource.h" #include "SkCanvas.h" #include "SkMallocPixelRef.h" +#include "SkPictureRecorder.h" #include "SkTemplates.h" #include "SkWriteBuffer.h" #include "SkValidatingReadBuffer.h" diff --git a/tests/TileGridTest.cpp b/tests/TileGridTest.cpp index aff4a76531..da228a068d 100644 --- a/tests/TileGridTest.cpp +++ b/tests/TileGridTest.cpp @@ -7,8 +7,8 @@ #include "SkBitmapDevice.h" #include "SkCanvas.h" +#include "SkPictureRecorder.h" #include "SkTileGrid.h" -#include "SkTileGridPicture.h" #include "Test.h" enum Tile { diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp index cd87f608a8..e531a30dc0 100644 --- a/tools/PictureRenderer.cpp +++ b/tools/PictureRenderer.cpp @@ -24,16 +24,13 @@ #include "SkMatrix.h" #include "SkOSFile.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkPictureUtils.h" #include "SkPixelRef.h" -#include "SkQuadTree.h" -#include "SkQuadTreePicture.h" -#include "SkRTreePicture.h" #include "SkScalar.h" #include "SkStream.h" #include "SkString.h" #include "SkTemplates.h" -#include "SkTileGridPicture.h" #include "SkTDArray.h" #include "SkThreadUtils.h" #include "SkTypes.h" diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h index a8c0cc52c3..796162846b 100644 --- a/tools/PictureRenderer.h +++ b/tools/PictureRenderer.h @@ -15,13 +15,13 @@ #include "SkMath.h" #include "SkPaint.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkRect.h" #include "SkRefCnt.h" #include "SkRunnable.h" #include "SkString.h" #include "SkTDArray.h" #include "SkThreadPool.h" -#include "SkTileGridPicture.h" #include "SkTypes.h" #if SK_SUPPORT_GPU diff --git a/tools/bench_record.cpp b/tools/bench_record.cpp index 65198fa5ba..cff3490433 100644 --- a/tools/bench_record.cpp +++ b/tools/bench_record.cpp @@ -10,12 +10,10 @@ #include "SkGraphics.h" #include "SkOSFile.h" #include "SkPicture.h" -#include "SkQuadTreePicture.h" +#include "SkPictureRecorder.h" #include "SkRecording.h" -#include "SkRTreePicture.h" #include "SkStream.h" #include "SkString.h" -#include "SkTileGridPicture.h" #include "SkTime.h" #include "LazyDecodeBitmap.h" diff --git a/tools/filtermain.cpp b/tools/filtermain.cpp index ecd1eee5b5..36b9f925c5 100644 --- a/tools/filtermain.cpp +++ b/tools/filtermain.cpp @@ -15,6 +15,7 @@ #include "SkPicture.h" #include "SkPicturePlayback.h" #include "SkPictureRecord.h" +#include "SkPictureRecorder.h" #include "SkStream.h" #include "picture_utils.h" #include "path_utils.h" diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp index 444efd0c5f..352dbf38be 100644 --- a/tools/render_pictures_main.cpp +++ b/tools/render_pictures_main.cpp @@ -16,6 +16,7 @@ #include "SkMath.h" #include "SkOSFile.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkStream.h" #include "SkString.h" #include "PictureRenderer.h" diff --git a/tools/skpmaker.cpp b/tools/skpmaker.cpp index 0d46d045a6..390e5ca299 100644 --- a/tools/skpmaker.cpp +++ b/tools/skpmaker.cpp @@ -12,6 +12,7 @@ #include "SkCommandLineFlags.h" #include "SkPaint.h" #include "SkPicture.h" +#include "SkPictureRecorder.h" #include "SkScalar.h" #include "SkStream.h" |