diff options
author | chudy@google.com <chudy@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-07 16:12:23 +0000 |
---|---|---|
committer | chudy@google.com <chudy@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-07 16:12:23 +0000 |
commit | 607357fde8a9c4c70549d4223e0bd1181b012e0e (patch) | |
tree | 6a470db5cdf3652b0680b237a1dcd9371638fe61 /debugger | |
parent | 9ddef9b6807101e989e18ca8da7737d81f412512 (diff) |
Refactoring into a public facing facing SkDebugger class first pass.
Review URL: https://codereview.appspot.com/6450096
git-svn-id: http://skia.googlecode.com/svn/trunk@4986 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'debugger')
-rw-r--r-- | debugger/QT/SkCanvasWidget.cpp | 62 | ||||
-rw-r--r-- | debugger/QT/SkCanvasWidget.h | 73 | ||||
-rw-r--r-- | debugger/QT/SkDebuggerGUI.cpp | 80 | ||||
-rw-r--r-- | debugger/QT/SkDebuggerGUI.h | 3 | ||||
-rw-r--r-- | debugger/QT/SkGLWidget.cpp | 22 | ||||
-rw-r--r-- | debugger/QT/SkGLWidget.h | 25 | ||||
-rw-r--r-- | debugger/QT/SkRasterWidget.cpp | 12 | ||||
-rw-r--r-- | debugger/QT/SkRasterWidget.h | 35 | ||||
-rw-r--r-- | debugger/SkDebugCanvas.cpp | 2 | ||||
-rw-r--r-- | debugger/SkDebugCanvas.h | 2 | ||||
-rw-r--r-- | debugger/SkDebugger.cpp | 41 | ||||
-rw-r--r-- | debugger/SkDebugger.h | 112 | ||||
-rw-r--r-- | debugger/debuggermain.cpp | 17 |
13 files changed, 251 insertions, 235 deletions
diff --git a/debugger/QT/SkCanvasWidget.cpp b/debugger/QT/SkCanvasWidget.cpp index ee9e5dacb8..2f714d79ae 100644 --- a/debugger/QT/SkCanvasWidget.cpp +++ b/debugger/QT/SkCanvasWidget.cpp @@ -9,9 +9,15 @@ #include "SkCanvasWidget.h" -SkCanvasWidget::SkCanvasWidget(QWidget* parent) : QWidget(parent) +SkCanvasWidget::SkCanvasWidget(QWidget* parent, + SkDebugger* debugger) : QWidget(parent) , fHorizontalLayout(this) + , fRasterWidget(debugger) + , fGLWidget(debugger) { + + fDebugger = debugger; + fHorizontalLayout.setSpacing(6); fHorizontalLayout.setContentsMargins(0,0,0,0); fRasterWidget.setSizePolicy(QSizePolicy::Expanding, @@ -21,63 +27,37 @@ SkCanvasWidget::SkCanvasWidget(QWidget* parent) : QWidget(parent) fHorizontalLayout.addWidget(&fRasterWidget); fHorizontalLayout.addWidget(&fGLWidget); - fDebugCanvas = NULL; - fIndex = 0; fPreviousPoint.set(0,0); fUserOffset.set(0,0); fUserScaleFactor = 1.0; setWidgetVisibility(kGPU_WidgetType, true); - this->setDisabled(true); connect(&fRasterWidget, SIGNAL(drawComplete()), this->parentWidget(), SLOT(drawComplete())); } -SkCanvasWidget::~SkCanvasWidget() { - delete fDebugCanvas; -} +SkCanvasWidget::~SkCanvasWidget() {} void SkCanvasWidget::drawTo(int index) { - fIndex = index; - if (!fRasterWidget.isHidden()) { - fRasterWidget.drawTo(index); - } - if (!fGLWidget.isHidden()) { - fGLWidget.drawTo(index); - } - emit commandChanged(fIndex); -} - -void SkCanvasWidget::loadPicture(QString filename) { - this->setDisabled(false); - SkStream* stream = new SkFILEStream(filename.toAscii()); - SkPicture* picture = new SkPicture(stream); - - /* TODO(chudy): Implement function that doesn't require new - * instantiation of debug canvas. */ - delete fDebugCanvas; - fDebugCanvas = new SkDebugCanvas(picture->width(), picture->height()); - - picture->draw(fDebugCanvas); - fIndex = fDebugCanvas->getSize() - 1; - fRasterWidget.setDebugCanvas(fDebugCanvas); - fGLWidget.setDebugCanvas(fDebugCanvas); - fDebugCanvas->setBounds(this->width(), this->height()); + fDebugger->setIndex(index); + fRasterWidget.draw(); + fGLWidget.draw(); + emit commandChanged(fDebugger->index()); } void SkCanvasWidget::mouseMoveEvent(QMouseEvent* event) { SkIPoint eventPoint = SkIPoint::Make(event->globalX(), event->globalY()); fUserOffset += eventPoint - fPreviousPoint; fPreviousPoint = eventPoint; - fDebugCanvas->setUserOffset(fUserOffset); - drawTo(fIndex); + fDebugger->setUserOffset(fUserOffset); + drawTo(fDebugger->index()); } void SkCanvasWidget::mousePressEvent(QMouseEvent* event) { fPreviousPoint.set(event->globalX(), event->globalY()); - emit hitChanged(fDebugCanvas->getCommandAtPoint(event->x(), event->y(), - fIndex)); + emit hitChanged(fDebugger->getCommandAtPoint(event->x(), event->y(), + fDebugger->index())); } void SkCanvasWidget::mouseDoubleClickEvent(QMouseEvent* event) { @@ -87,10 +67,10 @@ void SkCanvasWidget::mouseDoubleClickEvent(QMouseEvent* event) { void SkCanvasWidget::resetWidgetTransform() { fUserOffset.set(0,0); fUserScaleFactor = 1.0; - fDebugCanvas->setUserOffset(fUserOffset); - fDebugCanvas->setUserScale(fUserScaleFactor); + fDebugger->setUserOffset(fUserOffset); + fDebugger->setUserScale(fUserScaleFactor); emit scaleFactorChanged(fUserScaleFactor); - drawTo(fIndex); + drawTo(fDebugger->index()); } void SkCanvasWidget::setWidgetVisibility(WidgetType type, bool isHidden) { @@ -112,6 +92,6 @@ void SkCanvasWidget::zoom(float zoomIncrement) { fUserScaleFactor = 2 * zoomIncrement; } emit scaleFactorChanged(fUserScaleFactor); - fDebugCanvas->setUserScale(fUserScaleFactor); - drawTo(fIndex); + fDebugger->setUserScale(fUserScaleFactor); + drawTo(fDebugger->index()); } diff --git a/debugger/QT/SkCanvasWidget.h b/debugger/QT/SkCanvasWidget.h index 13e4b2733b..ff72c60066 100644 --- a/debugger/QT/SkCanvasWidget.h +++ b/debugger/QT/SkCanvasWidget.h @@ -15,12 +15,13 @@ #include "SkStream.h" #include "SkRasterWidget.h" #include "SkGLWidget.h" +#include "SkDebugger.h" class SkCanvasWidget : public QWidget { Q_OBJECT public: - SkCanvasWidget(QWidget* parent); + SkCanvasWidget(QWidget* parent, SkDebugger* debugger); ~SkCanvasWidget(); @@ -29,77 +30,10 @@ public: kGPU_WidgetType = 1 << 1, }; - /** - Returns the visibility of the command at the specified index. - @param index The index of the draw command - */ - bool commandIsVisibleAtIndex(int index) { - return fDebugCanvas->getDrawCommandVisibilityAt(index); - } - - /** - Toggles the visibility / execution of the draw command at index i with - the value of toggle. - */ - void setCommandVisibliltyAtIndex(int index, bool toggle) { - fDebugCanvas->toggleCommand(index, toggle); - } - - /** - Returns a vector of strings with all the current canvas draw - commands. - */ - std::vector<std::string>* getDrawCommands() { - return fDebugCanvas->getDrawCommandsAsStrings(); - } - - SkDebugCanvas* getCurrentDebugCanvas() { - return fDebugCanvas; - } - void drawTo(int index); void setWidgetVisibility(WidgetType type, bool isHidden); - /** - Toggles drawing filter on all drawing commands previous to current. - */ - void toggleCurrentCommandFilter(bool toggle) { - fDebugCanvas->toggleFilter(toggle); - } - - /** - TODO(chudy): Refactor into a struct of char** - Returns parameter information about the ith draw command. - @param: i The index of the draw command we are accessing - */ - std::vector<std::string>* getCurrentCommandInfo(int i) { - return fDebugCanvas->getCommandInfoAt(i); - } - - const SkMatrix& getCurrentMatrix() { - return fDebugCanvas->getCurrentMatrix(); - } - - const SkIRect& getCurrentClip() { - return fDebugCanvas->getCurrentClip(); - } - - void loadPicture(QString filename); - - // TODO(chudy): Not full proof since fRasterWidget isn't always drawn to. - int getBitmapHeight() { - return fRasterWidget.getBitmapHeight(); - } - - int getBitmapWidth() { - return fRasterWidget.getBitmapWidth(); - } - - SkRasterWidget* getRasterWidget() { - return &fRasterWidget; - } - void zoom(float zoomIncrement); signals: @@ -116,11 +50,10 @@ private: QHBoxLayout fHorizontalLayout; SkRasterWidget fRasterWidget; SkGLWidget fGLWidget; - SkDebugCanvas* fDebugCanvas; + SkDebugger* fDebugger; SkIPoint fPreviousPoint; SkIPoint fUserOffset; float fUserScaleFactor; - int fIndex; void resetWidgetTransform(); diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp index 24eeabd30e..9863cc0191 100644 --- a/debugger/QT/SkDebuggerGUI.cpp +++ b/debugger/QT/SkDebuggerGUI.cpp @@ -38,7 +38,7 @@ SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) : , fMapper(this) , fListWidget(&fCentralWidget) , fDirectoryWidget(&fCentralWidget) - , fCanvasWidget(this) + , fCanvasWidget(this, &fDebugger) , fMenuBar(this) , fMenuFile(this) , fMenuNavigate(this) @@ -107,8 +107,8 @@ void SkDebuggerGUI::showDeletes() { fDeletesActivated = !fDeletesActivated; for (int row = 0; row < fListWidget.count(); row++) { QListWidgetItem *item = fListWidget.item(row); - bool isVisible = fCanvasWidget.commandIsVisibleAtIndex(row); - item->setHidden(isVisible && fDeletesActivated); + item->setHidden(fDebugger.isCommandVisible(row) + && fDeletesActivated); } } @@ -131,7 +131,7 @@ void SkDebuggerGUI::actionClearDeletes() { for (int row = 0; row < fListWidget.count(); row++) { QListWidgetItem* item = fListWidget.item(row); item->setData(Qt::UserRole + 2, QPixmap(":/images/Icons/blank.png")); - fCanvasWidget.setCommandVisibliltyAtIndex(row, true); + fDebugger.setCommandVisible(row, true); } if (fPause) { fCanvasWidget.drawTo(fPausedRow); @@ -141,7 +141,7 @@ void SkDebuggerGUI::actionClearDeletes() { } void SkDebuggerGUI::actionCommandFilter() { - fCanvasWidget.toggleCurrentCommandFilter( + fDebugger.highlightCurrentCommand( fSettingsWidget.getVisibilityButton()->isChecked()); fCanvasWidget.drawTo(fListWidget.currentRow()); } @@ -154,12 +154,12 @@ void SkDebuggerGUI::actionDelete() { int currentRow = fListWidget.currentRow(); QListWidgetItem* item = fListWidget.currentItem(); - if (fCanvasWidget.commandIsVisibleAtIndex(currentRow)) { + if (fDebugger.isCommandVisible(currentRow)) { item->setData(Qt::UserRole + 2, QPixmap(":/images/Icons/delete.png")); - fCanvasWidget.setCommandVisibliltyAtIndex(currentRow, false); + fDebugger.setCommandVisible(currentRow, false); } else { item->setData(Qt::UserRole + 2, QPixmap(":/images/Icons/blank.png")); - fCanvasWidget.setCommandVisibliltyAtIndex(currentRow, true); + fDebugger.setCommandVisible(currentRow, true); } if (fPause) { @@ -247,17 +247,13 @@ void SkDebuggerGUI::actionStepForward() { } void SkDebuggerGUI::drawComplete() { - fInspectorWidget.setMatrix(fCanvasWidget.getCurrentMatrix()); - fInspectorWidget.setClip(fCanvasWidget.getCurrentClip()); + fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix()); + fInspectorWidget.setClip(fDebugger.getCurrentClip()); } void SkDebuggerGUI::saveToFile(QString filename) { SkFILEWStream file(filename.toAscii()); - SkPicture picture; - SkCanvas* canvas = picture.beginRecording(100,100); - fCanvasWidget.getCurrentDebugCanvas()->draw(canvas); - picture.endRecording(); - picture.serialize(&file); + fDebugger.makePicture()->serialize(&file); } void SkDebuggerGUI::loadFile(QListWidgetItem *item) { @@ -284,14 +280,9 @@ void SkDebuggerGUI::openFile() { } void SkDebuggerGUI::pauseDrawing(bool isPaused) { - // Qt uses 0 for unchecked, 1 for partially enabled and 2 for checked. - if (isPaused) { - fPause = true; - fPausedRow = fListWidget.currentRow(); - } else { - fPause = false; - fCanvasWidget.drawTo(fListWidget.currentRow()); - } + fPause = isPaused; + fPausedRow = fListWidget.currentRow(); + fCanvasWidget.drawTo(fPausedRow); } void SkDebuggerGUI::registerListClick(QListWidgetItem *item) { @@ -302,7 +293,7 @@ void SkDebuggerGUI::registerListClick(QListWidgetItem *item) { if (!fPause) { fCanvasWidget.drawTo(currentRow); } - std::vector<std::string> *cuffInfo = fCanvasWidget.getCurrentCommandInfo( + std::vector<std::string> *cuffInfo = fDebugger.getCommandInfo( currentRow); /* TODO(chudy): Add command type before parameters. Rename v @@ -344,21 +335,13 @@ void SkDebuggerGUI::toggleBreakpoint() { } void SkDebuggerGUI::toggleDirectory() { - if (fDirectoryWidget.isHidden()) { - fDirectoryWidget.setHidden(false); - } else { - fDirectoryWidget.setHidden(true); - } + fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden()); } void SkDebuggerGUI::toggleFilter(QString string) { for (int row = 0; row < fListWidget.count(); row++) { QListWidgetItem *item = fListWidget.item(row); - if (item->text() == string) { - item->setHidden(false); - } else { - item->setHidden(true); - } + item->setHidden(item->text() != string); } } @@ -587,12 +570,21 @@ void SkDebuggerGUI::setupDirectoryWidget() { void SkDebuggerGUI::loadPicture(QString fileName) { fLoading = true; - fCanvasWidget.loadPicture(fileName); - std::vector<std::string> *cv = fCanvasWidget.getDrawCommands(); + SkStream* stream = new SkFILEStream(fileName.toAscii()); + SkPicture* picture = new SkPicture(stream); + fDebugger.loadPicture(picture); + SkSafeUnref(stream); + SkSafeUnref(picture); + + std::vector<std::string> *cv = fDebugger.getDrawCommands(); + /* fDebugCanvas is reinitialized every load picture. Need it to retain value - * of the visibility filter. */ - fCanvasWidget.toggleCurrentCommandFilter( - fSettingsWidget.getVisibilityButton()->isChecked()); + * of the visibility filter. + * TODO(chudy): This should be deprecated since fDebugger is not + * recreated. + * */ + fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked()); + setupListWidget(cv); setupComboBox(cv); fInspectorWidget.setDisabled(false); @@ -627,7 +619,7 @@ void SkDebuggerGUI::setupComboBox(std::vector<std::string>* cv) { } QString overview; - int counter; + int counter = 0; for (std::map<std::string, int>::iterator it = map.begin(); it != map.end(); ++it) { overview.append((it->first).c_str()); @@ -644,12 +636,12 @@ void SkDebuggerGUI::setupComboBox(std::vector<std::string>* cv) { overview.insert(0, total); overview.append("<br/>"); - overview.append("SkBitmap Width: "); + overview.append("SkPicture Width: "); // NOTE(chudy): This is where we can pull out the SkPictures width. - overview.append(QString::number(fCanvasWidget.getBitmapWidth())); + overview.append(QString::number(fDebugger.pictureWidth())); overview.append("px<br/>"); - overview.append("SkBitmap Height: "); - overview.append(QString::number(fCanvasWidget.getBitmapHeight())); + overview.append("SkPicture Height: "); + overview.append(QString::number(fDebugger.pictureHeight())); overview.append("px"); fInspectorWidget.setOverviewText(overview); diff --git a/debugger/QT/SkDebuggerGUI.h b/debugger/QT/SkDebuggerGUI.h index b1bbfa78a3..763f4bedd8 100644 --- a/debugger/QT/SkDebuggerGUI.h +++ b/debugger/QT/SkDebuggerGUI.h @@ -12,7 +12,7 @@ #include "SkCanvas.h" #include "SkCanvasWidget.h" -#include "SkDebugCanvas.h" +#include "SkDebugger.h" #include "SkGLWidget.h" #include "SkListWidget.h" #include "SkInspectorWidget.h" @@ -238,6 +238,7 @@ private: QListWidget fListWidget; QListWidget fDirectoryWidget; + SkDebugger fDebugger; SkCanvasWidget fCanvasWidget; SkInspectorWidget fInspectorWidget; SkSettingsWidget fSettingsWidget; diff --git a/debugger/QT/SkGLWidget.cpp b/debugger/QT/SkGLWidget.cpp index d3d5389163..36abce0dd3 100644 --- a/debugger/QT/SkGLWidget.cpp +++ b/debugger/QT/SkGLWidget.cpp @@ -9,12 +9,9 @@ #include "SkGLWidget.h" -SkGLWidget::SkGLWidget() : QGLWidget() { +SkGLWidget::SkGLWidget(SkDebugger* debugger) : QGLWidget() { this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}"); - fTransform.set(0,0); - fScaleFactor = 1.0; - fIndex = 0; - fDebugCanvas = NULL; + fDebugger = debugger; fCurIntf = NULL; fCurContext = NULL; fGpuDevice = NULL; @@ -47,15 +44,18 @@ void SkGLWidget::resizeGL(int w, int h) { SkSafeUnref(fCanvas); fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget); fCanvas = new SkCanvas(fGpuDevice); - drawTo(fIndex); + fDebugger->resize(w, h); + draw(); } void SkGLWidget::paintGL() { - glClearColor(1, 1, 1, 0); - fDebugCanvas->drawTo(fCanvas, fIndex); - // TODO(chudy): Implement an optional flush button in Gui. - fCanvas->flush(); - emit drawComplete(); + if (!this->isHidden()) { + glClearColor(1, 1, 1, 0); + fDebugger->draw(fCanvas); + // TODO(chudy): Implement an optional flush button in Gui. + fCanvas->flush(); + emit drawComplete(); + } } GrPlatformRenderTargetDesc SkGLWidget::getDesc(int w, int h) { diff --git a/debugger/QT/SkGLWidget.h b/debugger/QT/SkGLWidget.h index 5eeb1cbcad..e31d09c8a9 100644 --- a/debugger/QT/SkGLWidget.h +++ b/debugger/QT/SkGLWidget.h @@ -12,6 +12,7 @@ #include <QtOpenGL/QGLWidget> #include "SkDebugCanvas.h" +#include "SkDebugger.h" #include "SkDevice.h" #include "SkGpuDevice.h" @@ -24,29 +25,14 @@ class SkGLWidget : public QGLWidget { Q_OBJECT public: - SkGLWidget(); + SkGLWidget(SkDebugger* debugger); ~SkGLWidget(); - void setDebugCanvas(SkDebugCanvas* debugCanvas) { - fDebugCanvas = debugCanvas; - fIndex = debugCanvas->getSize() - 1; + void draw() { this->updateGL(); } - void drawTo(int index) { - fIndex = index; - this->updateGL(); - } - - void setTranslate(SkIPoint translate) { - fTransform = translate; - } - - void setScale(float scale) { - fScaleFactor = scale; - } - signals: void drawComplete(); @@ -61,10 +47,7 @@ private: GrContext* fCurContext; SkGpuDevice* fGpuDevice; SkCanvas* fCanvas; - SkDebugCanvas* fDebugCanvas; - int fIndex; - SkIPoint fTransform; - float fScaleFactor; + SkDebugger* fDebugger; GrPlatformRenderTargetDesc getDesc(int w, int h); }; diff --git a/debugger/QT/SkRasterWidget.cpp b/debugger/QT/SkRasterWidget.cpp index ecb949cc90..4f8537d50d 100644 --- a/debugger/QT/SkRasterWidget.cpp +++ b/debugger/QT/SkRasterWidget.cpp @@ -9,15 +9,12 @@ #include "SkRasterWidget.h" -SkRasterWidget::SkRasterWidget() : QWidget() { +SkRasterWidget::SkRasterWidget(SkDebugger *debugger) : QWidget() { fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 800, 800); fBitmap.allocPixels(); fBitmap.eraseColor(0); - fTransform.set(0,0); - fScaleFactor = 1.0; - fIndex = 0; fDevice = new SkDevice(fBitmap); - fDebugCanvas = NULL; + fDebugger = debugger; fCanvas = new SkCanvas(fDevice); this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}"); } @@ -34,12 +31,13 @@ void SkRasterWidget::resizeEvent(QResizeEvent* event) { SkSafeUnref(fDevice); fDevice = new SkDevice(fBitmap); fCanvas = new SkCanvas(fDevice); + fDebugger->resize(event->size().width(), event->size().height()); this->update(); } void SkRasterWidget::paintEvent(QPaintEvent* event) { - if (fDebugCanvas) { - fDebugCanvas->drawTo(fCanvas, fIndex); + if (!this->isHidden()) { + fDebugger->draw(fCanvas); QPainter painter(this); QStyleOption opt; opt.init(this); diff --git a/debugger/QT/SkRasterWidget.h b/debugger/QT/SkRasterWidget.h index b0ded020f8..a0355c1f17 100644 --- a/debugger/QT/SkRasterWidget.h +++ b/debugger/QT/SkRasterWidget.h @@ -11,7 +11,7 @@ #include "SkGpuDevice.h" #include "SkDevice.h" -#include "SkDebugCanvas.h" +#include "SkDebugger.h" #include <QApplication> #include <QtGui> @@ -21,37 +21,14 @@ class SkRasterWidget : public QWidget { Q_OBJECT public: - SkRasterWidget(); + SkRasterWidget(SkDebugger* debugger); ~SkRasterWidget(); - void drawTo(int index) { - fIndex = index; + void draw() { this->update(); } - void setDebugCanvas(SkDebugCanvas* debugCanvas) { - fDebugCanvas = debugCanvas; - fIndex = debugCanvas->getSize() - 1; - this->update(); - } - - int getBitmapHeight() { - return fBitmap.height(); - } - - int getBitmapWidth() { - return fBitmap.width(); - } - - void setTranslate(SkIPoint transform) { - fTransform = transform; - } - - void setScale(float scale) { - fScaleFactor = scale; - } - signals: void drawComplete(); @@ -62,13 +39,9 @@ protected: private: SkBitmap fBitmap; - SkDebugCanvas* fDebugCanvas; + SkDebugger* fDebugger; SkCanvas* fCanvas; SkDevice* fDevice; - - int fIndex; - SkIPoint fTransform; - float fScaleFactor; }; #endif /* SKRASTERWIDGET_H_ */ diff --git a/debugger/SkDebugCanvas.cpp b/debugger/SkDebugCanvas.cpp index 6371f111e0..64444bb8e8 100644 --- a/debugger/SkDebugCanvas.cpp +++ b/debugger/SkDebugCanvas.cpp @@ -124,7 +124,7 @@ SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) { return commandVector[index]; } -std::vector<std::string>* SkDebugCanvas::getCommandInfoAt(int index) { +std::vector<std::string>* SkDebugCanvas::getCommandInfo(int index) { SkASSERT(index < (int)commandVector.size()); return commandVector[index]->Info(); } diff --git a/debugger/SkDebugCanvas.h b/debugger/SkDebugCanvas.h index e02c34c4f8..7a83390a45 100644 --- a/debugger/SkDebugCanvas.h +++ b/debugger/SkDebugCanvas.h @@ -73,7 +73,7 @@ public: Returns information about the command at the given index. @param index The index of the command */ - std::vector<std::string>* getCommandInfoAt(int index); + std::vector<std::string>* getCommandInfo(int index); /** Returns the visibility of the command at the given index. diff --git a/debugger/SkDebugger.cpp b/debugger/SkDebugger.cpp index 86a45748a9..7934c736c0 100644 --- a/debugger/SkDebugger.cpp +++ b/debugger/SkDebugger.cpp @@ -6,12 +6,39 @@ * found in the LICENSE file. */ -#include "SkDebuggerGUI.h" -#include <QApplication> +#include "SkDebugger.h" -int main(int argc, char *argv[]) { - QApplication a(argc, argv); - SkDebuggerGUI w; - w.show(); - return a.exec(); +SkDebugger::SkDebugger() { + // Create this some other dynamic way? + fDebugCanvas = new SkDebugCanvas(100, 100); + fPicture = NULL; + fPictureWidth = 0; + fPictureHeight = 0; + fIndex = 0; +} + +SkDebugger::~SkDebugger() { + // Need to inherit from SkRef object in order for following to work + SkSafeUnref(fDebugCanvas); + SkSafeUnref(fPicture); +} + +void SkDebugger::loadPicture(SkPicture* picture) { + fPictureWidth = picture->width(); + fPictureHeight = picture->height(); + delete fDebugCanvas; + fDebugCanvas = new SkDebugCanvas(fPictureWidth, fPictureHeight); + fDebugCanvas->setBounds(fPictureWidth, fPictureHeight); + picture->draw(fDebugCanvas); + fIndex = fDebugCanvas->getSize() - 1; + SkRefCnt_SafeAssign(fPicture, picture); +} + +SkPicture* SkDebugger::makePicture() { + SkSafeUnref(fPicture); + fPicture = new SkPicture(); + SkCanvas* canvas = fPicture->beginRecording(fPictureWidth, fPictureHeight); + fDebugCanvas->draw(canvas); + fPicture->endRecording(); + return fPicture; } diff --git a/debugger/SkDebugger.h b/debugger/SkDebugger.h new file mode 100644 index 0000000000..eb724f3822 --- /dev/null +++ b/debugger/SkDebugger.h @@ -0,0 +1,112 @@ + +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + + +#ifndef SKDEBUGGER_H_ +#define SKDEBUGGER_H_ + +#include "SkDebugCanvas.h" +#include "SkPicture.h" + +class SkDebugger { +public: + SkDebugger(); + + ~SkDebugger(); + + void setIndex(int index) { + fIndex = index; + } + void draw(SkCanvas* canvas) { + if (fIndex > 0) { + fDebugCanvas->drawTo(canvas, fIndex); + } + } + + void step(); + void stepBack(); + void play(); + void rewind(); + + bool isCommandVisible(int index) { + return fDebugCanvas->getDrawCommandVisibilityAt(index); + } + + void setCommandVisible(int index, bool isVisible) { + fDebugCanvas->toggleCommand(index, isVisible); + } + + // TODO(chudy): Replace with SkTDArray + std::vector<std::string>* getDrawCommands() { + return fDebugCanvas->getDrawCommandsAsStrings(); + } + + void highlightCurrentCommand(bool on) { + fDebugCanvas->toggleFilter(on); + } + + void resize(int width, int height) { + fDebugCanvas->setBounds(width, height); + } + + void loadPicture(SkPicture* picture); + + SkPicture* makePicture(); + + int getSize() { + return fDebugCanvas->getSize(); + } + + void setUserOffset(SkIPoint userOffset) { + // Should this live in debugger instead? + fDebugCanvas->setUserOffset(userOffset); + } + + void setUserScale(float userScale) { + fDebugCanvas->setUserScale(userScale); + } + + int getCommandAtPoint(int x, int y, int index) { + return fDebugCanvas->getCommandAtPoint(x, y, index); + } + + std::vector<std::string>* getCommandInfo(int index) { + return fDebugCanvas->getCommandInfo(index); + } + + const SkMatrix& getCurrentMatrix() { + return fDebugCanvas->getCurrentMatrix(); + } + + const SkIRect& getCurrentClip() { + return fDebugCanvas->getCurrentClip(); + } + + int pictureHeight() { + return fPictureHeight; + } + + int pictureWidth() { + return fPictureWidth; + } + + int index() { + return fIndex; + } + +private: + SkDebugCanvas* fDebugCanvas; + SkPicture* fPicture; + + int fPictureWidth; + int fPictureHeight; + int fIndex; +}; + + +#endif /* SKDEBUGGER_H_ */ diff --git a/debugger/debuggermain.cpp b/debugger/debuggermain.cpp new file mode 100644 index 0000000000..86a45748a9 --- /dev/null +++ b/debugger/debuggermain.cpp @@ -0,0 +1,17 @@ + +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkDebuggerGUI.h" +#include <QApplication> + +int main(int argc, char *argv[]) { + QApplication a(argc, argv); + SkDebuggerGUI w; + w.show(); + return a.exec(); +} |