diff options
author | krajcevski <krajcevski@google.com> | 2014-08-18 07:52:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-18 07:52:17 -0700 |
commit | b1aded8edd1d809cded20ff546c6e9218b43cda4 (patch) | |
tree | bc77d8b598e7ea9553199358e8881fffe16fb98c /tools | |
parent | de512d9a6cbbc5327521b65d06125810009f3dc1 (diff) |
Add flag to bench/render pictures
R=robertphillips@google.com, bsalomon@google.com
Author: krajcevski@google.com
Review URL: https://codereview.chromium.org/464423003
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CopyTilesRenderer.cpp | 10 | ||||
-rw-r--r-- | tools/CopyTilesRenderer.h | 4 | ||||
-rw-r--r-- | tools/PictureRenderer.cpp | 18 | ||||
-rw-r--r-- | tools/PictureRenderer.h | 38 | ||||
-rw-r--r-- | tools/PictureRenderingFlags.cpp | 30 | ||||
-rw-r--r-- | tools/bbh_shootout.cpp | 10 | ||||
-rw-r--r-- | tools/render_pictures_main.cpp | 5 |
7 files changed, 106 insertions, 9 deletions
diff --git a/tools/CopyTilesRenderer.cpp b/tools/CopyTilesRenderer.cpp index 509dd0e595..30a3256d63 100644 --- a/tools/CopyTilesRenderer.cpp +++ b/tools/CopyTilesRenderer.cpp @@ -16,10 +16,16 @@ #include "SkString.h" namespace sk_tools { +#if SK_SUPPORT_GPU + CopyTilesRenderer::CopyTilesRenderer(const GrContext::Options& opts, int x, int y) + : INHERITED(opts) + , fXTilesPerLargeTile(x) + , fYTilesPerLargeTile(y) { } +#else CopyTilesRenderer::CopyTilesRenderer(int x, int y) : fXTilesPerLargeTile(x) - , fYTilesPerLargeTile(y) { - } + , fYTilesPerLargeTile(y) { } +#endif void CopyTilesRenderer::init(const SkPicture* pict, const SkString* writePath, const SkString* mismatchPath, const SkString* inputFilename, bool useChecksumBasedFilenames) { diff --git a/tools/CopyTilesRenderer.h b/tools/CopyTilesRenderer.h index d7cf242fff..b24414223c 100644 --- a/tools/CopyTilesRenderer.h +++ b/tools/CopyTilesRenderer.h @@ -22,7 +22,11 @@ namespace sk_tools { class CopyTilesRenderer : public TiledPictureRenderer { public: +#if SK_SUPPORT_GPU + CopyTilesRenderer(const GrContext::Options &opts, int x, int y); +#else CopyTilesRenderer(int x, int y); +#endif virtual void init(const SkPicture* pict, const SkString* writePath, const SkString* mismatchPath, diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp index dd4cea481d..7325c201b8 100644 --- a/tools/PictureRenderer.cpp +++ b/tools/PictureRenderer.cpp @@ -444,8 +444,14 @@ SkString SimplePictureRenderer::getConfigNameInternal() { /////////////////////////////////////////////////////////////////////////////////////////////// +#if SK_SUPPORT_GPU +TiledPictureRenderer::TiledPictureRenderer(const GrContext::Options& opts) + : INHERITED(opts) + , fTileWidth(kDefaultTileWidth) +#else TiledPictureRenderer::TiledPictureRenderer() : fTileWidth(kDefaultTileWidth) +#endif , fTileHeight(kDefaultTileHeight) , fTileWidthPercentage(0.0) , fTileHeightPercentage(0.0) @@ -745,6 +751,10 @@ SkBBHFactory* PictureRenderer::getFactory() { class GatherRenderer : public PictureRenderer { public: +#if SK_SUPPORT_GPU + GatherRenderer(const GrContext::Options& opts) : INHERITED(opts) { } +#endif + virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE { SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->width()), SkIntToScalar(fPicture->height())); @@ -758,10 +768,18 @@ private: virtual SkString getConfigNameInternal() SK_OVERRIDE { return SkString("gather_pixelrefs"); } + + typedef PictureRenderer INHERITED; }; +#if SK_SUPPORT_GPU +PictureRenderer* CreateGatherPixelRefsRenderer(const GrContext::Options& opts) { + return SkNEW_ARGS(GatherRenderer, (opts)); +} +#else PictureRenderer* CreateGatherPixelRefsRenderer() { return SkNEW(GatherRenderer); } +#endif } // namespace sk_tools diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h index d197419080..f11b198cf3 100644 --- a/tools/PictureRenderer.h +++ b/tools/PictureRenderer.h @@ -403,6 +403,10 @@ public: GrContext* getGrContext() { return fGrContext; } + + const GrContext::Options& getGrContextOptions() { + return fGrContextFactory.getGlobalOptions(); + } #endif SkCanvas* getCanvas() { @@ -412,14 +416,19 @@ public: const SkPicture* getPicture() { return fPicture; } - + +#if SK_SUPPORT_GPU + explicit PictureRenderer(const GrContext::Options &opts) +#else PictureRenderer() +#endif : fJsonSummaryPtr(NULL) , fDeviceType(kBitmap_DeviceType) , fEnableWrites(false) , fBBoxHierarchyType(kNone_BBoxHierarchyType) , fScaleFactor(SK_Scalar1) #if SK_SUPPORT_GPU + , fGrContextFactory(opts) , fGrContext(NULL) , fSampleCount(0) #endif @@ -500,6 +509,11 @@ private: * to time. */ class RecordPictureRenderer : public PictureRenderer { +public: +#if SK_SUPPORT_GPU + RecordPictureRenderer(const GrContext::Options &opts) : INHERITED(opts) { } +#endif + virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); } @@ -511,10 +525,16 @@ protected: private: virtual SkString getConfigNameInternal() SK_OVERRIDE; + + typedef PictureRenderer INHERITED; }; class PipePictureRenderer : public PictureRenderer { public: +#if SK_SUPPORT_GPU + PipePictureRenderer(const GrContext::Options &opts) : INHERITED(opts) { } +#endif + virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; private: @@ -525,6 +545,10 @@ private: class SimplePictureRenderer : public PictureRenderer { public: +#if SK_SUPPORT_GPU + SimplePictureRenderer(const GrContext::Options &opts) : INHERITED(opts) { } +#endif + virtual void init(const SkPicture* pict, const SkString* writePath, const SkString* mismatchPath, @@ -541,7 +565,11 @@ private: class TiledPictureRenderer : public PictureRenderer { public: +#if SK_SUPPORT_GPU + TiledPictureRenderer(const GrContext::Options &opts); +#else TiledPictureRenderer(); +#endif virtual void init(const SkPicture* pict, const SkString* writePath, @@ -668,6 +696,10 @@ private: */ class PlaybackCreationRenderer : public PictureRenderer { public: +#if SK_SUPPORT_GPU + PlaybackCreationRenderer(const GrContext::Options &opts) : INHERITED(opts) { } +#endif + virtual void setup() SK_OVERRIDE; virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; @@ -684,7 +716,11 @@ private: typedef PictureRenderer INHERITED; }; +#if SK_SUPPORT_GPU +extern PictureRenderer* CreateGatherPixelRefsRenderer(const GrContext::Options& opts); +#else extern PictureRenderer* CreateGatherPixelRefsRenderer(); +#endif } diff --git a/tools/PictureRenderingFlags.cpp b/tools/PictureRenderingFlags.cpp index ccec158f95..ee7b8efea2 100644 --- a/tools/PictureRenderingFlags.cpp +++ b/tools/PictureRenderingFlags.cpp @@ -79,6 +79,8 @@ DEFINE_string(gpuAPI, "", "Force use of specific gpu API. Using \"gl\" " "forces OpenGL API. Using \"gles\" forces OpenGL ES API. " "Defaults to empty string, which selects the API native to the " "system."); +DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to " + "software path rendering."); #endif sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) { @@ -92,11 +94,19 @@ sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) { const char* mode = NULL; bool gridSupported = false; +#if SK_SUPPORT_GPU + GrContext::Options grContextOpts; + grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks; + #define RENDERER_ARGS (grContextOpts) +#else + #define RENDERER_ARGS () +#endif + SkAutoTUnref<sk_tools::PictureRenderer> renderer; if (FLAGS_mode.count() >= 1) { mode = FLAGS_mode[0]; if (0 == strcmp(mode, "record")) { - renderer.reset(SkNEW(sk_tools::RecordPictureRenderer)); + renderer.reset(SkNEW_ARGS(sk_tools::RecordPictureRenderer, RENDERER_ARGS)); gridSupported = true; } else if (0 == strcmp(mode, "tile") || 0 == strcmp(mode, "pow2tile") || 0 == strcmp(mode, "copyTile")) { @@ -123,13 +133,17 @@ sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) { heightString = FLAGS_mode[2]; } else if (0 == strcmp(mode, "playbackCreation") && kBench_PictureTool == tool) { - renderer.reset(SkNEW(sk_tools::PlaybackCreationRenderer)); + renderer.reset(SkNEW_ARGS(sk_tools::PlaybackCreationRenderer, RENDERER_ARGS)); gridSupported = true; // undocumented } else if (0 == strcmp(mode, "gatherPixelRefs") && kBench_PictureTool == tool) { +#if SK_SUPPORT_GPU + renderer.reset(sk_tools::CreateGatherPixelRefsRenderer(grContextOpts)); +#else renderer.reset(sk_tools::CreateGatherPixelRefsRenderer()); +#endif } else if (0 == strcmp(mode, "rerecord") && kRender_PictureTool == tool) { - renderer.reset(SkNEW(sk_tools::RecordPictureRenderer)); + renderer.reset(SkNEW_ARGS(sk_tools::RecordPictureRenderer, RENDERER_ARGS)); // Allow 'mode' to be set to 'simple', but do not create a renderer, so we can // ensure that pipe does not override a mode besides simple. The renderer will // be created below. @@ -167,9 +181,13 @@ sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) { } else { x = y = 4; } +#if SK_SUPPORT_GPU + tiledRenderer.reset(SkNEW_ARGS(sk_tools::CopyTilesRenderer, (grContextOpts, x, y))); +#else tiledRenderer.reset(SkNEW_ARGS(sk_tools::CopyTilesRenderer, (x, y))); +#endif } else { - tiledRenderer.reset(SkNEW(sk_tools::TiledPictureRenderer)); + tiledRenderer.reset(SkNEW_ARGS(sk_tools::TiledPictureRenderer, RENDERER_ARGS)); } if (isPowerOf2Mode) { @@ -230,12 +248,12 @@ sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) { error.printf("Pipe is incompatible with other modes.\n"); return NULL; } - renderer.reset(SkNEW(sk_tools::PipePictureRenderer)); + renderer.reset(SkNEW_ARGS(sk_tools::PipePictureRenderer, RENDERER_ARGS)); } } if (NULL == renderer) { - renderer.reset(SkNEW(sk_tools::SimplePictureRenderer)); + renderer.reset(SkNEW_ARGS(sk_tools::SimplePictureRenderer, RENDERER_ARGS)); } if (FLAGS_viewport.count() > 0) { diff --git a/tools/bbh_shootout.cpp b/tools/bbh_shootout.cpp index 64fc6d87d8..27818de73a 100644 --- a/tools/bbh_shootout.cpp +++ b/tools/bbh_shootout.cpp @@ -105,14 +105,24 @@ int tool_main(int argc, char** argv) { for (int bBoxType = 0; bBoxType < kBBoxTypeCount; ++bBoxType) { if (!includeBBoxType[bBoxType]) { continue; } if (FLAGS_playback > 0) { +#if SK_SUPPORT_GPU + GrContext::Options grContextOpts; + sk_tools::TiledPictureRenderer playbackRenderer(grContextOpts); +#else sk_tools::TiledPictureRenderer playbackRenderer; +#endif Timer playbackTimer; do_benchmark_work(&playbackRenderer, (BBoxType)bBoxType, picture, FLAGS_playback, &playbackTimer); measurement.fPlaybackAverage[bBoxType] = playbackTimer.fCpu; } if (FLAGS_record > 0) { +#if SK_SUPPORT_GPU + GrContext::Options grContextOpts; + sk_tools::RecordPictureRenderer recordRenderer(grContextOpts); +#else sk_tools::RecordPictureRenderer recordRenderer; +#endif Timer recordTimer; do_benchmark_work(&recordRenderer, (BBoxType)bBoxType, picture, FLAGS_record, &recordTimer); diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp index 13cef09bc5..e62c3bce77 100644 --- a/tools/render_pictures_main.cpp +++ b/tools/render_pictures_main.cpp @@ -292,7 +292,12 @@ static bool render_picture(const SkString& inputPath, const SkString* writePath, referenceRenderer->ref(); // to match auto unref below arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHierarchyType); } else { +#if SK_SUPPORT_GPU + referenceRenderer = SkNEW_ARGS(sk_tools::SimplePictureRenderer, + (renderer.getGrContextOptions())); +#else referenceRenderer = SkNEW(sk_tools::SimplePictureRenderer); +#endif } SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRenderer); |