2012-06-29 14:21:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2012-08-07 16:12:23 +00:00
|
|
|
#include "SkDebugger.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2013-03-12 13:07:40 +00:00
|
|
|
#include "SkString.h"
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2015-01-05 19:51:13 +00:00
|
|
|
SkDebugger::SkDebugger()
|
2015-08-27 14:41:13 +00:00
|
|
|
: fPicture(nullptr)
|
2015-01-05 19:51:13 +00:00
|
|
|
, fIndex(-1) {
|
2012-08-07 16:12:23 +00:00
|
|
|
// Create this some other dynamic way?
|
2014-08-29 15:03:56 +00:00
|
|
|
fDebugCanvas = new SkDebugCanvas(0, 0);
|
2012-08-07 16:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkDebugger::~SkDebugger() {
|
|
|
|
// Need to inherit from SkRef object in order for following to work
|
|
|
|
SkSafeUnref(fDebugCanvas);
|
|
|
|
SkSafeUnref(fPicture);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugger::loadPicture(SkPicture* picture) {
|
2014-08-29 15:03:56 +00:00
|
|
|
SkRefCnt_SafeAssign(fPicture, picture);
|
|
|
|
|
2012-08-07 16:12:23 +00:00
|
|
|
delete fDebugCanvas;
|
2014-08-29 15:03:56 +00:00
|
|
|
fDebugCanvas = new SkDebugCanvas(SkScalarCeilToInt(this->pictureCull().width()),
|
|
|
|
SkScalarCeilToInt(this->pictureCull().height()));
|
2014-03-25 23:31:33 +00:00
|
|
|
fDebugCanvas->setPicture(picture);
|
2014-09-04 15:42:50 +00:00
|
|
|
picture->playback(fDebugCanvas);
|
2015-08-27 14:41:13 +00:00
|
|
|
fDebugCanvas->setPicture(nullptr);
|
2012-08-07 16:12:23 +00:00
|
|
|
fIndex = fDebugCanvas->getSize() - 1;
|
|
|
|
}
|
|
|
|
|
2016-03-25 14:04:35 +00:00
|
|
|
sk_sp<SkPicture> SkDebugger::copyPicture() {
|
2013-01-22 18:03:56 +00:00
|
|
|
// We can't just call clone here since we want to removed the "deleted"
|
|
|
|
// commands. Playing back will strip those out.
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2014-08-29 15:03:56 +00:00
|
|
|
SkCanvas* canvas = recorder.beginRecording(this->pictureCull().width(),
|
|
|
|
this->pictureCull().height());
|
2014-03-25 23:31:33 +00:00
|
|
|
|
|
|
|
bool vizMode = fDebugCanvas->getMegaVizMode();
|
|
|
|
fDebugCanvas->setMegaVizMode(false);
|
|
|
|
bool overDraw = fDebugCanvas->getOverdrawViz();
|
|
|
|
fDebugCanvas->setOverdrawViz(false);
|
2014-05-19 13:53:10 +00:00
|
|
|
bool pathOps = fDebugCanvas->getAllowSimplifyClip();
|
|
|
|
fDebugCanvas->setAllowSimplifyClip(false);
|
2014-03-25 23:31:33 +00:00
|
|
|
|
2012-08-07 16:12:23 +00:00
|
|
|
fDebugCanvas->draw(canvas);
|
2014-03-25 23:31:33 +00:00
|
|
|
|
|
|
|
fDebugCanvas->setMegaVizMode(vizMode);
|
|
|
|
fDebugCanvas->setOverdrawViz(overDraw);
|
2014-05-19 13:53:10 +00:00
|
|
|
fDebugCanvas->setAllowSimplifyClip(pathOps);
|
2014-03-25 23:31:33 +00:00
|
|
|
|
2016-03-25 14:04:35 +00:00
|
|
|
return recorder.finishRecordingAsPicture();
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
2013-03-12 13:07:40 +00:00
|
|
|
|
|
|
|
void SkDebugger::getOverviewText(const SkTDArray<double>* typeTimes,
|
|
|
|
double totTime,
|
2013-03-12 15:33:40 +00:00
|
|
|
SkString* overview,
|
|
|
|
int numRuns) {
|
2013-03-12 13:07:40 +00:00
|
|
|
const SkTDArray<SkDrawCommand*>& commands = this->getDrawCommands();
|
|
|
|
|
|
|
|
SkTDArray<int> counts;
|
2015-02-13 19:13:00 +00:00
|
|
|
counts.setCount(SkDrawCommand::kOpTypeCount);
|
|
|
|
for (int i = 0; i < SkDrawCommand::kOpTypeCount; ++i) {
|
2013-03-12 13:07:40 +00:00
|
|
|
counts[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < commands.count(); i++) {
|
|
|
|
counts[commands[i]->getType()]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
overview->reset();
|
|
|
|
int total = 0;
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
double totPercent = 0, tempSum = 0;
|
|
|
|
#endif
|
2015-02-13 19:13:00 +00:00
|
|
|
for (int i = 0; i < SkDrawCommand::kOpTypeCount; ++i) {
|
2013-03-12 13:07:40 +00:00
|
|
|
if (0 == counts[i]) {
|
|
|
|
// if there were no commands of this type then they should've consumed no time
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(nullptr == typeTimes || 0.0 == (*typeTimes)[i]);
|
2013-03-12 13:07:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-02-13 19:13:00 +00:00
|
|
|
overview->append(SkDrawCommand::GetCommandString((SkDrawCommand::OpType) i));
|
2013-03-12 13:07:40 +00:00
|
|
|
overview->append(": ");
|
2013-03-12 15:33:40 +00:00
|
|
|
overview->appendS32(counts[i]);
|
2014-09-05 20:34:00 +00:00
|
|
|
if (typeTimes && totTime >= 0.0) {
|
2013-03-12 13:07:40 +00:00
|
|
|
overview->append(" - ");
|
2013-03-12 15:33:40 +00:00
|
|
|
overview->appendf("%.2f", (*typeTimes)[i]/(float)numRuns);
|
2013-03-12 13:07:40 +00:00
|
|
|
overview->append("ms");
|
|
|
|
overview->append(" - ");
|
|
|
|
double percent = 100.0*(*typeTimes)[i]/totTime;
|
2013-03-12 15:33:40 +00:00
|
|
|
overview->appendf("%.2f", percent);
|
2013-03-12 13:07:40 +00:00
|
|
|
overview->append("%");
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
totPercent += percent;
|
|
|
|
tempSum += (*typeTimes)[i];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
overview->append("<br/>");
|
|
|
|
total += counts[i];
|
|
|
|
}
|
|
|
|
#ifdef SK_DEBUG
|
2014-09-05 20:34:00 +00:00
|
|
|
if (typeTimes) {
|
2013-03-13 07:01:04 +00:00
|
|
|
SkASSERT(SkScalarNearlyEqual(SkDoubleToScalar(totPercent),
|
2013-03-12 15:33:40 +00:00
|
|
|
SkDoubleToScalar(100.0)));
|
2013-03-13 07:01:04 +00:00
|
|
|
SkASSERT(SkScalarNearlyEqual(SkDoubleToScalar(tempSum),
|
2013-03-12 15:33:40 +00:00
|
|
|
SkDoubleToScalar(totTime)));
|
2013-03-12 13:07:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (totTime > 0.0) {
|
|
|
|
overview->append("Total Time: ");
|
2013-03-12 15:33:40 +00:00
|
|
|
overview->appendf("%.2f", totTime/(float)numRuns);
|
2013-03-12 13:07:40 +00:00
|
|
|
overview->append("ms");
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
overview->append(" ");
|
2013-03-12 15:33:40 +00:00
|
|
|
overview->appendScalar(SkDoubleToScalar(totPercent));
|
2013-03-12 13:07:40 +00:00
|
|
|
overview->append("% ");
|
|
|
|
#endif
|
|
|
|
overview->append("<br/>");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString totalStr;
|
|
|
|
totalStr.append("Total Draw Commands: ");
|
2013-03-12 15:33:40 +00:00
|
|
|
totalStr.appendScalar(SkDoubleToScalar(total));
|
2013-03-12 13:07:40 +00:00
|
|
|
totalStr.append("<br/>");
|
|
|
|
overview->insert(0, totalStr);
|
|
|
|
|
2014-08-29 15:03:56 +00:00
|
|
|
overview->append("<br/>SkPicture L: ");
|
|
|
|
overview->appendScalar(this->pictureCull().fLeft);
|
|
|
|
overview->append(" T: ");
|
|
|
|
overview->appendScalar(this->pictureCull().fTop);
|
|
|
|
overview->append(" R: ");
|
|
|
|
overview->appendScalar(this->pictureCull().fRight);
|
|
|
|
overview->append(" B: ");
|
|
|
|
overview->appendScalar(this->pictureCull().fBottom);
|
2013-03-12 13:07:40 +00:00
|
|
|
overview->append("<br/>");
|
|
|
|
}
|
2014-05-19 13:53:10 +00:00
|
|
|
|
|
|
|
void SkDebugger::getClipStackText(SkString* clipStack) {
|
|
|
|
clipStack->set(fDebugCanvas->clipStackData());
|
|
|
|
}
|