diff options
author | 2012-08-20 15:03:47 +0000 | |
---|---|---|
committer | 2012-08-20 15:03:47 +0000 | |
commit | 77a5522d0e4437ef2b856acd7b135b6afda64cee (patch) | |
tree | d0600565a033eca37abb1f1fa574f724302e845d | |
parent | 78a35c5f1dcc00b2b442069a94f9e7c996f8d7f9 (diff) |
State reset and gpu timers added.
git-svn-id: http://skia.googlecode.com/svn/trunk@5177 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | tools/PictureBenchmark.cpp | 66 | ||||
-rw-r--r-- | tools/PictureBenchmark.h | 3 | ||||
-rw-r--r-- | tools/PictureRenderer.cpp | 12 | ||||
-rw-r--r-- | tools/PictureRenderer.h | 9 |
4 files changed, 67 insertions, 23 deletions
diff --git a/tools/PictureBenchmark.cpp b/tools/PictureBenchmark.cpp index bb0d9fc3ea..9a2f3ca820 100644 --- a/tools/PictureBenchmark.cpp +++ b/tools/PictureBenchmark.cpp @@ -15,6 +15,20 @@ namespace sk_tools { +BenchTimer* PictureBenchmark::setupTimer() { +#if SK_SUPPORT_GPU + PictureRenderer* renderer = getRenderer(); + + if (renderer != NULL && renderer->isUsingGpuDevice()) { + return new BenchTimer(renderer->getGLContext()); + } else { + return new BenchTimer(NULL); + } +#else + return new BenchTimer(NULL); +#endif +} + void PipePictureBenchmark::run(SkPicture* pict) { SkASSERT(pict); if (NULL == pict) { @@ -27,20 +41,23 @@ void PipePictureBenchmark::run(SkPicture* pict) { // program) fRenderer.render(); - BenchTimer timer = BenchTimer(NULL); - timer.start(); + BenchTimer* timer = this->setupTimer(); + + timer->start(); for (int i = 0; i < fRepeats; ++i) { fRenderer.render(); } - timer.end(); + timer->end(); fRenderer.end(); - SkDebugf("pipe: msecs = %6.2f", timer.fWall / fRepeats); + SkDebugf("pipe: msecs = %6.2f", timer->fWall / fRepeats); if (fRenderer.isUsingGpuDevice()) { - SkDebugf(" gmsecs = %6.2f", timer.fGpu / fRepeats); + SkDebugf(" gmsecs = %6.2f", timer->fGpu / fRepeats); } SkDebugf("\n"); + + delete timer; } void RecordPictureBenchmark::run(SkPicture* pict) { @@ -49,20 +66,20 @@ void RecordPictureBenchmark::run(SkPicture* pict) { return; } - BenchTimer timer = BenchTimer(NULL); + BenchTimer* timer = setupTimer(); double wall_time = 0; for (int i = 0; i < fRepeats + 1; ++i) { SkPicture replayer; SkCanvas* recorder = replayer.beginRecording(pict->width(), pict->height()); - timer.start(); + timer->start(); recorder->drawPicture(*pict); - timer.end(); + timer->end(); // We want to ignore first time effects if (i > 0) { - wall_time += timer.fWall; + wall_time += timer->fWall; } } @@ -81,20 +98,23 @@ void SimplePictureBenchmark::run(SkPicture* pict) { // program) fRenderer.render(); - BenchTimer timer = BenchTimer(NULL); - timer.start(); + BenchTimer* timer = this->setupTimer(); + + timer->start(); for (int i = 0; i < fRepeats; ++i) { fRenderer.render(); } - timer.end(); + timer->end(); fRenderer.end(); - SkDebugf("simple: msecs = %6.2f", timer.fWall / fRepeats); + SkDebugf("simple: msecs = %6.2f", timer->fWall / fRepeats); if (fRenderer.isUsingGpuDevice()) { - SkDebugf(" gmsecs = %6.2f", timer.fGpu / fRepeats); + SkDebugf(" gmsecs = %6.2f", timer->fGpu / fRepeats); } SkDebugf("\n"); + + delete timer; } void TiledPictureBenchmark::run(SkPicture* pict) { @@ -109,19 +129,19 @@ void TiledPictureBenchmark::run(SkPicture* pict) { // program) fRenderer.drawTiles(); - BenchTimer timer = BenchTimer(NULL); - timer.start(); + BenchTimer* timer = setupTimer(); + timer->start(); for (int i = 0; i < fRepeats; ++i) { fRenderer.drawTiles(); } - timer.end(); + timer->end(); fRenderer.end(); SkDebugf("%i_tiles_%ix%i: msecs = %6.2f", fRenderer.numTiles(), fRenderer.getTileWidth(), - fRenderer.getTileHeight(), timer.fWall / fRepeats); + fRenderer.getTileHeight(), timer->fWall / fRepeats); if (fRenderer.isUsingGpuDevice()) { - SkDebugf(" gmsecs = %6.2f", timer.fGpu / fRepeats); + SkDebugf(" gmsecs = %6.2f", timer->fGpu / fRepeats); } SkDebugf("\n"); } @@ -132,7 +152,7 @@ void UnflattenPictureBenchmark::run(SkPicture* pict) { return; } - BenchTimer timer = BenchTimer(NULL); + BenchTimer* timer = setupTimer(); double wall_time = 0; for (int i = 0; i < fRepeats + 1; ++i) { @@ -141,13 +161,13 @@ void UnflattenPictureBenchmark::run(SkPicture* pict) { recorder->drawPicture(*pict); - timer.start(); + timer->start(); replayer.endRecording(); - timer.end(); + timer->end(); // We want to ignore first time effects if (i > 0) { - wall_time += timer.fWall; + wall_time += timer->fWall; } } diff --git a/tools/PictureBenchmark.h b/tools/PictureBenchmark.h index 309f570743..e0fdd7fab2 100644 --- a/tools/PictureBenchmark.h +++ b/tools/PictureBenchmark.h @@ -11,6 +11,7 @@ #include "SkRefCnt.h" #include "PictureRenderer.h" +class BenchTimer; class SkPicture; class SkString; @@ -36,6 +37,8 @@ public: } } + BenchTimer* setupTimer(); + #if SK_SUPPORT_GPU void setUseGpuDevice() { sk_tools::PictureRenderer* renderer = getRenderer(); diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp index 4142fa4294..84e7f85db3 100644 --- a/tools/PictureRenderer.cpp +++ b/tools/PictureRenderer.cpp @@ -54,10 +54,22 @@ void PictureRenderer::init(SkPicture* pict) { } void PictureRenderer::end() { + this->resetState(); fPicture = NULL; fCanvas.reset(NULL); } +void PictureRenderer::resetState() { + fCanvas->flush(); + + if (this->isUsingGpuDevice()) { + SkGLContext* glContext = fGrContextFactory.getGLContext( + GrContextFactory::kNative_GLContextType); + SK_GL(*glContext, Finish()); + fGrContext->freeGpuResources(); + } +} + void PipePictureRenderer::render() { SkASSERT(fCanvas.get() != NULL); SkASSERT(fPicture != NULL); diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h index 914857d1fd..b419900036 100644 --- a/tools/PictureRenderer.h +++ b/tools/PictureRenderer.h @@ -28,6 +28,7 @@ public: virtual void init(SkPicture* pict); virtual void render() = 0; virtual void end(); + virtual void resetState(); SkCanvas* getCanvas() { return fCanvas.get(); @@ -49,6 +50,14 @@ public: bool isUsingGpuDevice() { return kGPU_DeviceType == fDeviceType; } + + SkGLContext* getGLContext() { + if (this->isUsingGpuDevice()) { + return fGrContextFactory.getGLContext(GrContextFactory::kNative_GLContextType); + } else { + return NULL; + } + } #endif PictureRenderer() |