Index: tools/VisualBench/VisualLightweightBenchModule.cpp |
diff --git a/tools/VisualBench/VisualBench.cpp b/tools/VisualBench/VisualLightweightBenchModule.cpp |
similarity index 67% |
copy from tools/VisualBench/VisualBench.cpp |
copy to tools/VisualBench/VisualLightweightBenchModule.cpp |
index fd1293c19cbdbbf4e821d6adff217764dcbd5305..8f9e4881aa0a07cfd3b249f38448c701f88fc8bf 100644 |
--- a/tools/VisualBench/VisualBench.cpp |
+++ b/tools/VisualBench/VisualLightweightBenchModule.cpp |
@@ -6,7 +6,7 @@ |
* |
*/ |
-#include "VisualBench.h" |
+#include "VisualLightweightBenchModule.h" |
#include "ProcStats.h" |
#include "SkApplication.h" |
@@ -25,14 +25,11 @@ __SK_FORCE_IMAGE_DECODER_LINKING; |
// Between samples we reset context |
// Between frames we swap buffers |
-// Between flushes we call flush on GrContext |
DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allows to lag."); |
DEFINE_int32(samples, 10, "Number of times to time each skp."); |
DEFINE_int32(frames, 5, "Number of frames of each skp to render per sample."); |
DEFINE_double(loopMs, 5, "Target loop time in millseconds."); |
-DEFINE_int32(msaa, 0, "Number of msaa samples."); |
-DEFINE_bool2(fullscreen, f, true, "Run fullscreen."); |
DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver."); |
DEFINE_string(key, "", ""); // dummy to enable gm tests that have platform-specific names |
DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
@@ -48,19 +45,14 @@ static SkString humanize(double ms) { |
#define HUMANIZE(time) humanize(time).c_str() |
-VisualBench::VisualBench(void* hwnd, int argc, char** argv) |
- : INHERITED(hwnd) |
- , fCurrentSample(0) |
+VisualLightweightBenchModule::VisualLightweightBenchModule(VisualBench* owner) |
+ : fCurrentSample(0) |
, fCurrentFrame(0) |
, fLoops(1) |
, fState(kPreWarmLoops_State) |
, fBenchmark(nullptr) |
+ , fOwner(SkRef(owner)) |
, fResults(new ResultsWriter) { |
- SkCommandLineFlags::Parse(argc, argv); |
- |
- this->setTitle(); |
- this->setupBackend(); |
- |
fBenchmarkStream.reset(new VisualBenchmarkStream); |
// Print header |
@@ -80,73 +72,13 @@ VisualBench::VisualBench(void* hwnd, int argc, char** argv) |
} |
} |
-VisualBench::~VisualBench() { |
- INHERITED::detach(); |
-} |
- |
-void VisualBench::setTitle() { |
- SkString title("VisualBench"); |
- INHERITED::setTitle(title.c_str()); |
-} |
- |
-SkSurface* VisualBench::createSurface() { |
- if (!fSurface) { |
- SkSurfaceProps props(INHERITED::getSurfaceProps()); |
- fSurface.reset(SkSurface::NewRenderTargetDirect(fRenderTarget, &props)); |
- } |
- |
- // The caller will wrap the SkSurface in an SkAutoTUnref |
- return SkRef(fSurface.get()); |
-} |
- |
-bool VisualBench::setupBackend() { |
- this->setColorType(kRGBA_8888_SkColorType); |
- this->setVisibleP(true); |
- this->setClipToBounds(false); |
- |
- if (FLAGS_fullscreen) { |
- if (!this->makeFullscreen()) { |
- SkDebugf("Could not go fullscreen!"); |
- } |
- } |
- if (!this->attach(kNativeGL_BackEndType, FLAGS_msaa, &fAttachmentInfo)) { |
- SkDebugf("Not possible to create backend.\n"); |
- INHERITED::detach(); |
- return false; |
- } |
- |
- this->setVsync(false); |
- this->resetContext(); |
- return true; |
-} |
- |
-void VisualBench::resetContext() { |
- fSurface.reset(nullptr); |
- |
- fInterface.reset(GrGLCreateNativeInterface()); |
- SkASSERT(fInterface); |
- |
- // setup contexts |
- fContext.reset(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInterface.get())); |
- SkASSERT(fContext); |
- |
- // setup rendertargets |
- this->setupRenderTarget(); |
-} |
- |
-void VisualBench::setupRenderTarget() { |
- if (fContext) { |
- fRenderTarget.reset(this->renderTarget(fAttachmentInfo, fInterface, fContext)); |
- } |
-} |
- |
-inline void VisualBench::renderFrame(SkCanvas* canvas) { |
+inline void VisualLightweightBenchModule::renderFrame(SkCanvas* canvas) { |
fBenchmark->draw(fLoops, canvas); |
canvas->flush(); |
- INHERITED::present(); |
+ fOwner->present(); |
} |
-void VisualBench::printStats() { |
+void VisualLightweightBenchModule::printStats() { |
const SkTArray<double>& measurements = fRecords.back().fMeasurements; |
const char* shortName = fBenchmark->getUniqueName(); |
@@ -185,7 +117,7 @@ void VisualBench::printStats() { |
} |
} |
-bool VisualBench::advanceRecordIfNecessary(SkCanvas* canvas) { |
+bool VisualLightweightBenchModule::advanceRecordIfNecessary(SkCanvas* canvas) { |
if (fBenchmark) { |
return true; |
} |
@@ -205,17 +137,17 @@ bool VisualBench::advanceRecordIfNecessary(SkCanvas* canvas) { |
return true; |
} |
-inline void VisualBench::nextState(State nextState) { |
+inline void VisualLightweightBenchModule::nextState(State nextState) { |
fState = nextState; |
} |
-void VisualBench::perCanvasPreDraw(SkCanvas* canvas, State nextState) { |
+void VisualLightweightBenchModule::perCanvasPreDraw(SkCanvas* canvas, State nextState) { |
fBenchmark->perCanvasPreDraw(canvas); |
fCurrentFrame = 0; |
this->nextState(nextState); |
} |
-void VisualBench::preWarm(State nextState) { |
+void VisualLightweightBenchModule::preWarm(State nextState) { |
if (fCurrentFrame >= FLAGS_gpuFrameLag) { |
// we currently time across all frames to make sure we capture all GPU work |
this->nextState(nextState); |
@@ -226,10 +158,10 @@ void VisualBench::preWarm(State nextState) { |
} |
} |
-void VisualBench::draw(SkCanvas* canvas) { |
+void VisualLightweightBenchModule::draw(SkCanvas* canvas) { |
if (!this->advanceRecordIfNecessary(canvas)) { |
SkDebugf("Exiting VisualBench successfully\n"); |
- this->closeWindow(); |
+ fOwner->closeWindow(); |
return; |
} |
this->renderFrame(canvas); |
@@ -259,28 +191,25 @@ void VisualBench::draw(SkCanvas* canvas) { |
break; |
} |
} |
- |
- // Invalidate the window to force a redraw. Poor man's animation mechanism. |
- this->inval(nullptr); |
} |
-inline double VisualBench::elapsed() { |
+inline double VisualLightweightBenchModule::elapsed() { |
fTimer.end(); |
return fTimer.fWall; |
} |
-void VisualBench::resetTimingState() { |
+void VisualLightweightBenchModule::resetTimingState() { |
fCurrentFrame = 0; |
fTimer = WallTimer(); |
- this->resetContext(); |
+ fOwner->reset(); |
} |
-void VisualBench::scaleLoops(double elapsedMs) { |
+void VisualLightweightBenchModule::scaleLoops(double elapsedMs) { |
// Scale back the number of loops |
fLoops = (int)ceil(fLoops * FLAGS_loopMs / elapsedMs); |
} |
-inline void VisualBench::tuneLoops() { |
+inline void VisualLightweightBenchModule::tuneLoops() { |
if (1 << 30 == fLoops) { |
// We're about to wrap. Something's wrong with the bench. |
SkDebugf("InnerLoops wrapped\n"); |
@@ -298,19 +227,19 @@ inline void VisualBench::tuneLoops() { |
} |
} |
-void VisualBench::recordMeasurement() { |
+void VisualLightweightBenchModule::recordMeasurement() { |
double measurement = this->elapsed() / (FLAGS_frames * fLoops); |
fRecords.back().fMeasurements.push_back(measurement); |
} |
-void VisualBench::postDraw(SkCanvas* canvas) { |
+void VisualLightweightBenchModule::postDraw(SkCanvas* canvas) { |
fBenchmark->perCanvasPostDraw(canvas); |
fBenchmark.reset(nullptr); |
fCurrentSample = 0; |
fLoops = 1; |
} |
-inline void VisualBench::timing(SkCanvas* canvas) { |
+inline void VisualLightweightBenchModule::timing(SkCanvas* canvas) { |
if (fCurrentFrame >= FLAGS_frames) { |
this->recordMeasurement(); |
if (fCurrentSample++ >= FLAGS_samples) { |
@@ -325,27 +254,3 @@ inline void VisualBench::timing(SkCanvas* canvas) { |
fCurrentFrame++; |
} |
} |
- |
-void VisualBench::onSizeChange() { |
- this->setupRenderTarget(); |
-} |
- |
-bool VisualBench::onHandleChar(SkUnichar unichar) { |
- return true; |
-} |
- |
-// Externally declared entry points |
-void application_init() { |
- SkGraphics::Init(); |
- SkEvent::Init(); |
-} |
- |
-void application_term() { |
- SkEvent::Term(); |
- SkGraphics::Term(); |
-} |
- |
-SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { |
- return new VisualBench(hwnd, argc, argv); |
-} |
- |