Load visualbench pictures one at a time.

Add flag to run in windowed mode.

NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/1183193003
This commit is contained in:
bsalomon 2015-06-16 13:52:18 -07:00 committed by Commit bot
parent 921827bbc7
commit 45171e20b3
2 changed files with 59 additions and 43 deletions

View File

@ -28,6 +28,7 @@ DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow
DEFINE_int32(samples, 10, "Number of times to render each skp."); DEFINE_int32(samples, 10, "Number of times to render each skp.");
DEFINE_int32(loops, 5, "Number of times to time."); DEFINE_int32(loops, 5, "Number of times to time.");
DEFINE_int32(msaa, 0, "Number of msaa samples."); DEFINE_int32(msaa, 0, "Number of msaa samples.");
DEFINE_bool2(fullscreen, f, true, "Run fullscreen.");
static SkString humanize(double ms) { static SkString humanize(double ms) {
if (FLAGS_verbose) { if (FLAGS_verbose) {
@ -41,37 +42,25 @@ static SkString humanize(double ms) {
VisualBench::VisualBench(void* hwnd, int argc, char** argv) VisualBench::VisualBench(void* hwnd, int argc, char** argv)
: INHERITED(hwnd) : INHERITED(hwnd)
, fLoop(0) , fLoop(0)
, fCurrentPicture(0) , fCurrentPictureIdx(-1)
, fCurrentSample(0) , fCurrentSample(0)
, fState(kPreWarm_State) { , fState(kPreWarm_State) {
SkCommandLineFlags::Parse(argc, argv); SkCommandLineFlags::Parse(argc, argv);
// load all SKPs // read all the skp file names.
SkTArray<SkString> skps;
for (int i = 0; i < FLAGS_skps.count(); i++) { for (int i = 0; i < FLAGS_skps.count(); i++) {
if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
skps.push_back() = FLAGS_skps[i]; fRecords.push_back().fFilename = FLAGS_skps[i];
fTimings.push_back().fName = FLAGS_skps[i];
} else { } else {
SkOSFile::Iter it(FLAGS_skps[i], ".skp"); SkOSFile::Iter it(FLAGS_skps[i], ".skp");
SkString path; SkString path;
while (it.next(&path)) { while (it.next(&path)) {
skps.push_back() = SkOSPath::Join(FLAGS_skps[i], path.c_str()); fRecords.push_back().fFilename = SkOSPath::Join(FLAGS_skps[i], path.c_str());;
fTimings.push_back().fName = path.c_str();
} }
} }
} }
for (int i = 0; i < skps.count(); i++) { if (fRecords.empty()) {
SkFILEStream stream(skps[i].c_str());
if (stream.isValid()) {
fPictures.push_back(SkPicture::CreateFromStream(&stream));
} else {
SkDebugf("couldn't load picture at \"path\"\n", skps[i].c_str());
}
}
if (fPictures.empty()) {
SkDebugf("no valid skps found\n"); SkDebugf("no valid skps found\n");
} }
@ -80,9 +69,6 @@ VisualBench::VisualBench(void* hwnd, int argc, char** argv)
} }
VisualBench::~VisualBench() { VisualBench::~VisualBench() {
for (int i = 0; i < fPictures.count(); i++) {
fPictures[i]->~SkPicture();
}
INHERITED::detach(); INHERITED::detach();
} }
@ -101,9 +87,11 @@ bool VisualBench::setupBackend() {
this->setVisibleP(true); this->setVisibleP(true);
this->setClipToBounds(false); this->setClipToBounds(false);
if (FLAGS_fullscreen) {
if (!this->makeFullscreen()) { if (!this->makeFullscreen()) {
SkDebugf("Could not go fullscreen!"); SkDebugf("Could not go fullscreen!");
} }
}
if (!this->attach(kNativeGL_BackEndType, FLAGS_msaa, &fAttachmentInfo)) { if (!this->attach(kNativeGL_BackEndType, FLAGS_msaa, &fAttachmentInfo)) {
SkDebugf("Not possible to create backend.\n"); SkDebugf("Not possible to create backend.\n");
INHERITED::detach(); INHERITED::detach();
@ -134,18 +122,19 @@ void VisualBench::setupRenderTarget() {
} }
inline void VisualBench::renderFrame(SkCanvas* canvas) { inline void VisualBench::renderFrame(SkCanvas* canvas) {
canvas->drawPicture(fPictures[fCurrentPicture]); canvas->drawPicture(fPicture);
fContext->flush(); fContext->flush();
INHERITED::present(); INHERITED::present();
} }
void VisualBench::printStats() { void VisualBench::printStats() {
const SkTArray<double>& measurements = fTimings[fCurrentPicture].fMeasurements; const SkTArray<double>& measurements = fRecords[fCurrentPictureIdx].fMeasurements;
SkString shortName = SkOSPath::Basename(fRecords[fCurrentPictureIdx].fFilename.c_str());
if (FLAGS_verbose) { if (FLAGS_verbose) {
for (int i = 0; i < measurements.count(); i++) { for (int i = 0; i < measurements.count(); i++) {
SkDebugf("%s ", HUMANIZE(measurements[i])); SkDebugf("%s ", HUMANIZE(measurements[i]));
} }
SkDebugf("%s\n", fTimings[fCurrentPicture].fName.c_str()); SkDebugf("%s\n", shortName.c_str());
} else { } else {
SkASSERT(measurements.count()); SkASSERT(measurements.count());
Stats stats(measurements.begin(), measurements.count()); Stats stats(measurements.begin(), measurements.count());
@ -158,11 +147,44 @@ void VisualBench::printStats() {
HUMANIZE(stats.mean), HUMANIZE(stats.mean),
HUMANIZE(stats.max), HUMANIZE(stats.max),
stdDevPercent, stdDevPercent,
fTimings[fCurrentPicture].fName.c_str()); shortName.c_str());
} }
} }
void VisualBench::timePicture(SkCanvas* canvas) { bool VisualBench::advanceRecordIfNecessary() {
if (fPicture) {
return true;
}
++fCurrentPictureIdx;
while (true) {
if (fCurrentPictureIdx >= fRecords.count()) {
return false;
}
if (this->loadPicture()) {
return true;
}
fRecords.removeShuffle(fCurrentPictureIdx);
}
}
bool VisualBench::loadPicture() {
const char* fileName = fRecords[fCurrentPictureIdx].fFilename.c_str();
SkFILEStream stream(fileName);
if (stream.isValid()) {
fPicture.reset(SkPicture::CreateFromStream(&stream));
if (SkToBool(fPicture)) {
return true;
}
}
SkDebugf("couldn't load picture at \"%s\"\n", fileName);
return false;
}
void VisualBench::draw(SkCanvas* canvas) {
if (!this->advanceRecordIfNecessary()) {
this->closeWindow();
return;
}
this->renderFrame(canvas); this->renderFrame(canvas);
switch (fState) { switch (fState) {
case kPreWarm_State: { case kPreWarm_State: {
@ -181,14 +203,14 @@ void VisualBench::timePicture(SkCanvas* canvas) {
case kTiming_State: { case kTiming_State: {
if (fCurrentSample >= FLAGS_samples) { if (fCurrentSample >= FLAGS_samples) {
fTimer.end(); fTimer.end();
fTimings[fCurrentPicture].fMeasurements.push_back(fTimer.fWall / FLAGS_samples); fRecords[fCurrentPictureIdx].fMeasurements.push_back(fTimer.fWall / FLAGS_samples);
this->resetContext(); this->resetContext();
fTimer = WallTimer(); fTimer = WallTimer();
fState = kPreWarm_State; fState = kPreWarm_State;
fCurrentSample = 0; fCurrentSample = 0;
if (fLoop++ > FLAGS_loops) { if (fLoop++ > FLAGS_loops) {
this->printStats(); this->printStats();
fCurrentPicture++; fPicture.reset(NULL);
fLoop = 0; fLoop = 0;
} }
} else { } else {
@ -197,14 +219,6 @@ void VisualBench::timePicture(SkCanvas* canvas) {
break; break;
} }
} }
}
void VisualBench::draw(SkCanvas* canvas) {
if (fCurrentPicture < fPictures.count()) {
this->timePicture(canvas);
} else {
this->closeWindow();
}
// Invalidate the window to force a redraw. Poor man's animation mechanism. // Invalidate the window to force a redraw. Poor man's animation mechanism.
this->inval(NULL); this->inval(NULL);

View File

@ -12,6 +12,7 @@
#include "SkWindow.h" #include "SkWindow.h"
#include "SkPicture.h" #include "SkPicture.h"
#include "SkString.h"
#include "SkSurface.h" #include "SkSurface.h"
#include "Timer.h" #include "Timer.h"
#include "gl/SkGLContext.h" #include "gl/SkGLContext.h"
@ -43,11 +44,12 @@ private:
void setupRenderTarget(); void setupRenderTarget();
bool onHandleChar(SkUnichar unichar) override; bool onHandleChar(SkUnichar unichar) override;
void printStats(); void printStats();
inline void timePicture(SkCanvas*); bool loadPicture();
bool advanceRecordIfNecessary();
inline void renderFrame(SkCanvas*); inline void renderFrame(SkCanvas*);
struct Timing { struct Record {
SkString fName; SkString fFilename;
SkTArray<double> fMeasurements; SkTArray<double> fMeasurements;
}; };
@ -57,10 +59,10 @@ private:
}; };
int fLoop; int fLoop;
int fCurrentPicture; int fCurrentPictureIdx;
SkAutoTUnref<SkPicture> fPicture;
int fCurrentSample; int fCurrentSample;
SkTArray<Timing> fTimings; SkTArray<Record> fRecords;
SkTArray<SkPicture*> fPictures;
WallTimer fTimer; WallTimer fTimer;
State fState; State fState;