diff options
author | kkinnunen <kkinnunen@nvidia.com> | 2014-12-30 07:22:58 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-30 07:22:58 -0800 |
commit | 5037e9de94e57d36592cc596d831cc2b5ec45bd3 (patch) | |
tree | 816d7c02cb2d4640e2d4565b7c799ed86045ed17 | |
parent | d5e98713576a961d05b957465e83cdf992daca1b (diff) |
Change DebugCanvas API to not encourage memory leaks
Pass command strings and offset arrays as out parameters instead of
returning new arrays from the functions.
This simplifies debugger leak investigations, as the app leaks less by
design.
Review URL: https://codereview.chromium.org/821663003
-rw-r--r-- | debugger/QT/SkDebuggerGUI.cpp | 36 | ||||
-rw-r--r-- | debugger/QT/SkDebuggerGUI.h | 8 | ||||
-rw-r--r-- | debugger/SkDebugger.h | 10 | ||||
-rw-r--r-- | platform_tools/nacl/src/nacl_debugger.cpp | 5 | ||||
-rw-r--r-- | src/utils/debugger/SkDebugCanvas.cpp | 21 | ||||
-rw-r--r-- | src/utils/debugger/SkDebugCanvas.h | 10 |
6 files changed, 25 insertions, 65 deletions
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp index 949137fc28..25f70369fa 100644 --- a/debugger/QT/SkDebuggerGUI.cpp +++ b/debugger/QT/SkDebuggerGUI.cpp @@ -773,11 +773,6 @@ void SkDebuggerGUI::loadPicture(const SkString& fileName) { SkSafeUnref(stream); SkSafeUnref(picture); - // Will this automatically clear out due to nature of refcnt? - SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings(); - SkTDArray<size_t>* offsets = fDebugger.getDrawCommandOffsets(); - SkASSERT(commands->count() == offsets->count()); - fActionProfile.setDisabled(false); /* fDebugCanvas is reinitialized every load picture. Need it to retain value @@ -787,8 +782,8 @@ void SkDebuggerGUI::loadPicture(const SkString& fileName) { * */ fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityFilter()); - this->setupListWidget(commands, offsets); - this->setupComboBox(commands); + this->setupListWidget(); + this->setupComboBox(); this->setupOverviewText(NULL, 0.0, 1); fInspectorWidget.setDisabled(false); fSettingsWidget.setDisabled(false); @@ -801,31 +796,32 @@ void SkDebuggerGUI::loadPicture(const SkString& fileName) { actionPlay(); } -void SkDebuggerGUI::setupListWidget(SkTArray<SkString>* commands, SkTDArray<size_t>* offsets) { - SkASSERT(commands->count() == offsets->count()); +void SkDebuggerGUI::setupListWidget() { fListWidget.clear(); int counter = 0; int indent = 0; - for (int i = 0; i < commands->count(); i++) { + for (int i = 0; i < fDebugger.getSize(); i++) { QListWidgetItem *item = new QListWidgetItem(); - item->setData(Qt::DisplayRole, (*commands)[i].c_str()); + SkDrawCommand* command = fDebugger.getDrawCommandAt(i); + SkString commandString = command->toString(); + item->setData(Qt::DisplayRole, commandString.c_str()); item->setData(Qt::UserRole + 1, counter++); - if (0 == strcmp("Restore", (*commands)[i].c_str()) || - 0 == strcmp("EndCommentGroup", (*commands)[i].c_str())) { + if (0 == strcmp("Restore", commandString.c_str()) || + 0 == strcmp("EndCommentGroup", commandString.c_str())) { indent -= 10; } item->setData(Qt::UserRole + 3, indent); - if (0 == strcmp("Save", (*commands)[i].c_str()) || - 0 == strcmp("Save Layer", (*commands)[i].c_str()) || - 0 == strcmp("BeginCommentGroup", (*commands)[i].c_str())) { + if (0 == strcmp("Save", commandString.c_str()) || + 0 == strcmp("Save Layer", commandString.c_str()) || + 0 == strcmp("BeginCommentGroup", commandString.c_str())) { indent += 10; } item->setData(Qt::UserRole + 4, -1); - item->setData(Qt::UserRole + 5, (int)(*offsets)[i]); + item->setData(Qt::UserRole + 5, (int) command->offset()); fListWidget.addItem(item); } @@ -845,13 +841,13 @@ void SkDebuggerGUI::setupClipStackText() { fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType); } -void SkDebuggerGUI::setupComboBox(SkTArray<SkString>* command) { +void SkDebuggerGUI::setupComboBox() { fFilter.clear(); fFilter.addItem("--Filter By Available Commands--"); std::map<std::string, int> map; - for (int i = 0; i < command->count(); i++) { - map[(*command)[i].c_str()]++; + for (int i = 0; i < fDebugger.getSize(); i++) { + map[fDebugger.getDrawCommandAt(i)->toString().c_str()]++; } for (std::map<std::string, int>::iterator it = map.begin(); it != map.end(); diff --git a/debugger/QT/SkDebuggerGUI.h b/debugger/QT/SkDebuggerGUI.h index 3f445500c7..2a514baef1 100644 --- a/debugger/QT/SkDebuggerGUI.h +++ b/debugger/QT/SkDebuggerGUI.h @@ -334,14 +334,14 @@ private: void saveToFile(const SkString& filename); /** - Populates the list widget with the vector of strings passed in. + Populates the list widget with the debugger draw command info. */ - void setupListWidget(SkTArray<SkString>* commands, SkTDArray<size_t>* offsets); + void setupListWidget(); /** - Populates the combo box widget with the vector of strings passed in. + Populates the combo box widget with with the debugger draw command info. */ - void setupComboBox(SkTArray<SkString>* command); + void setupComboBox(); /** Fills in the overview pane with text diff --git a/debugger/SkDebugger.h b/debugger/SkDebugger.h index 5359b10fe9..683b98d6d9 100644 --- a/debugger/SkDebugger.h +++ b/debugger/SkDebugger.h @@ -44,12 +44,8 @@ public: fDebugCanvas->toggleCommand(index, isVisible); } - SkTArray<SkString>* getDrawCommandsAsStrings() { - return fDebugCanvas->getDrawCommandsAsStrings(); - } - - SkTDArray<size_t>* getDrawCommandOffsets() { - return fDebugCanvas->getDrawCommandOffsets(); + SkDrawCommand* getDrawCommandAt(int index) { + return fDebugCanvas->getDrawCommandAt(index); } const SkTDArray<SkDrawCommand*>& getDrawCommands() const { @@ -66,7 +62,7 @@ public: SkPicture* copyPicture(); - int getSize() { + int getSize() const { return fDebugCanvas->getSize(); } diff --git a/platform_tools/nacl/src/nacl_debugger.cpp b/platform_tools/nacl/src/nacl_debugger.cpp index b80dde0938..e7e26b8129 100644 --- a/platform_tools/nacl/src/nacl_debugger.cpp +++ b/platform_tools/nacl/src/nacl_debugger.cpp @@ -76,11 +76,10 @@ public: picture->unref(); // Set up the command list. - SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings(); PostMessage("ClearCommands"); - for (int i = 0; i < commands->count(); ++i) { + for (int i = 0; i < fDebugger.getSize(); ++i) { SkString addCommand("AddCommand:"); - addCommand.append((*commands)[i]); + addCommand.append(fDebugger.getDrawCommandAt(i)->toString()); PostMessage(addCommand.c_str()); } PostMessage("UpdateCommands"); diff --git a/src/utils/debugger/SkDebugCanvas.cpp b/src/utils/debugger/SkDebugCanvas.cpp index f2f92b8492..46c0b8b472 100644 --- a/src/utils/debugger/SkDebugCanvas.cpp +++ b/src/utils/debugger/SkDebugCanvas.cpp @@ -388,27 +388,6 @@ SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() { return fCommandVector; } -// TODO(chudy): Free command string memory. -SkTArray<SkString>* SkDebugCanvas::getDrawCommandsAsStrings() const { - SkTArray<SkString>* commandString = new SkTArray<SkString>(fCommandVector.count()); - if (!fCommandVector.isEmpty()) { - for (int i = 0; i < fCommandVector.count(); i ++) { - commandString->push_back() = fCommandVector[i]->toString(); - } - } - return commandString; -} - -SkTDArray<size_t>* SkDebugCanvas::getDrawCommandOffsets() const { - SkTDArray<size_t>* commandOffsets = new SkTDArray<size_t>; - if (!fCommandVector.isEmpty()) { - for (int i = 0; i < fCommandVector.count(); i ++) { - *commandOffsets->push() = fCommandVector[i]->offset(); - } - } - return commandOffsets; -} - void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level) { if (NULL == fTexOverrideFilter) { fTexOverrideFilter = new SkTexOverrideFilter; diff --git a/src/utils/debugger/SkDebugCanvas.h b/src/utils/debugger/SkDebugCanvas.h index 18f4c8d713..a526525f45 100644 --- a/src/utils/debugger/SkDebugCanvas.h +++ b/src/utils/debugger/SkDebugCanvas.h @@ -123,16 +123,6 @@ public: SkTDArray<SkDrawCommand*>& getDrawCommands(); /** - * Returns the string vector of draw commands - */ - SkTArray<SkString>* getDrawCommandsAsStrings() const; - - /** - * Returns an array containing an offset (in the SkPicture) for each command - */ - SkTDArray<size_t>* getDrawCommandOffsets() const; - - /** Returns length of draw command vector. */ int getSize() const { |