diff options
author | kkinnunen <kkinnunen@nvidia.com> | 2014-12-30 23:03:56 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-30 23:03:56 -0800 |
commit | 63a470227beed0de553d769724e0108808391e42 (patch) | |
tree | d7b8bf2a1c1b13257ed3cd23a05a24feb52a9a3a /debugger | |
parent | 41c79cc0ff3003ef77cb48590f7887221856f941 (diff) |
debugger: Make draw command image widget resize
Make draw command image widget resize. The widget was not resizing,
effectively preventing the window from being resized smaller.
Make the rasterized draw command image be proportional to the widget
size. The draw rasterization canvas is still an equilateral rectangle
with dimensions of the smaller side of the widget.
Makes the widget re-rasterize the image only when the draw command
changes, not for each widget paint.
Renames the widget from "image widget" to "draw command geometry
widget".
Makes the background of the image black, similar to the raster widget
background.
Adds a tooltip saying "Command geometry" for the widget, so that user might
understand what the contents should be.
This commit is part of work that tries to make the debugger window to be
a bit more resizeable, so that it would fit 1900x1200 screen.
Review URL: https://codereview.chromium.org/787143004
Diffstat (limited to 'debugger')
-rw-r--r-- | debugger/QT/SkDebuggerGUI.cpp | 20 | ||||
-rw-r--r-- | debugger/QT/SkDebuggerGUI.h | 5 | ||||
-rw-r--r-- | debugger/QT/SkDrawCommandGeometryWidget.cpp | 86 | ||||
-rw-r--r-- | debugger/QT/SkDrawCommandGeometryWidget.h | 35 | ||||
-rw-r--r-- | debugger/QT/SkImageWidget.cpp | 54 | ||||
-rw-r--r-- | debugger/QT/SkImageWidget.h | 46 |
6 files changed, 132 insertions, 114 deletions
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp index 71d7b06a0b..05f4886616 100644 --- a/debugger/QT/SkDebuggerGUI.cpp +++ b/debugger/QT/SkDebuggerGUI.cpp @@ -61,7 +61,7 @@ SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) : , fListWidget(&fCentralSplitter) , fDirectoryWidget(&fCentralSplitter) , fCanvasWidget(this, &fDebugger) - , fImageWidget(&fDebugger) + , fDrawCommandGeometryWidget(&fDebugger) , fMenuBar(this) , fMenuFile(this) , fMenuNavigate(this) @@ -107,6 +107,8 @@ SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) : connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(updateHit(int))); connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float))); connect(&fCanvasWidget, SIGNAL(commandChanged(int)), this, SLOT(updateCommand(int))); + connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fDrawCommandGeometryWidget, SLOT(updateImage())); + connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs())); connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave())); @@ -232,10 +234,8 @@ void SkDebuggerGUI::actionClearDeletes() { } if (fPause) { fCanvasWidget.drawTo(fPausedRow); - fImageWidget.draw(); } else { fCanvasWidget.drawTo(fListWidget.currentRow()); - fImageWidget.draw(); } } @@ -267,10 +267,8 @@ void SkDebuggerGUI::actionDelete() { if (fPause) { fCanvasWidget.drawTo(fPausedRow); - fImageWidget.draw(); } else { fCanvasWidget.drawTo(currentRow); - fImageWidget.draw(); } } @@ -289,7 +287,7 @@ void SkDebuggerGUI::actionInspector() { fInspectorWidget.setHidden(newState); fViewStateFrame.setHidden(newState); - fImageWidget.setHidden(newState); + fDrawCommandGeometryWidget.setHidden(newState); } void SkDebuggerGUI::actionPlay() { @@ -316,7 +314,6 @@ void SkDebuggerGUI::actionVisualizationsChanged() { fDebugger.setPathOps(fSettingsWidget.isPathOpsEnabled()); fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled()); fCanvasWidget.drawTo(fListWidget.currentRow()); - fImageWidget.draw(); } void SkDebuggerGUI::actionTextureFilter() { @@ -418,7 +415,6 @@ void SkDebuggerGUI::pauseDrawing(bool isPaused) { fPause = isPaused; fPausedRow = fListWidget.currentRow(); fCanvasWidget.drawTo(fPausedRow); - fImageWidget.draw(); } void SkDebuggerGUI::registerListClick(QListWidgetItem *item) { @@ -428,7 +424,6 @@ void SkDebuggerGUI::registerListClick(QListWidgetItem *item) { if (currentRow != -1) { if (!fPause) { fCanvasWidget.drawTo(currentRow); - fImageWidget.draw(); } const SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(currentRow); @@ -612,8 +607,7 @@ void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) { fCanvasWidget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth, - SkImageWidget::kImageWidgetHeight); + fDrawCommandGeometryWidget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); fInspectorWidget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -625,6 +619,7 @@ void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) { fViewStateFrame.setFrameStyle(QFrame::Panel); fViewStateFrame.setLayout(&fViewStateFrameLayout); fViewStateFrameLayout.addWidget(&fViewStateGroup); + fViewStateGroup.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); fViewStateGroup.setTitle("View"); fViewStateLayout.addRow("Zoom Level", &fZoomBox); fZoomBox.setText("100%"); @@ -647,7 +642,8 @@ void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) { fViewStateGroup.setLayout(&fViewStateLayout); fSettingsAndImageLayout.addWidget(&fViewStateFrame); - fSettingsAndImageLayout.addWidget(&fImageWidget); + fDrawCommandGeometryWidget.setToolTip("Current Command Geometry"); + fSettingsAndImageLayout.addWidget(&fDrawCommandGeometryWidget); fLeftColumnSplitter.addWidget(&fListWidget); fLeftColumnSplitter.addWidget(&fDirectoryWidget); diff --git a/debugger/QT/SkDebuggerGUI.h b/debugger/QT/SkDebuggerGUI.h index b07f37a8a3..695a8582b9 100644 --- a/debugger/QT/SkDebuggerGUI.h +++ b/debugger/QT/SkDebuggerGUI.h @@ -17,7 +17,7 @@ #include "SkListWidget.h" #include "SkInspectorWidget.h" #include "SkRasterWidget.h" -#include "SkImageWidget.h" +#include "SkDrawCommandGeometryWidget.h" #include "SkSettingsWidget.h" #include <QtCore/QVariant> #include <QtGui/QAction> @@ -281,7 +281,7 @@ private: SkDebugger fDebugger; SkCanvasWidget fCanvasWidget; - SkImageWidget fImageWidget; + SkInspectorWidget fInspectorWidget; SkSettingsWidget fSettingsWidget; @@ -292,6 +292,7 @@ private: QLineEdit fCurrentCommandBox; QLineEdit fCommandHitBox; QLineEdit fZoomBox; + SkDrawCommandGeometryWidget fDrawCommandGeometryWidget; QString fPath; SkString fFileName; diff --git a/debugger/QT/SkDrawCommandGeometryWidget.cpp b/debugger/QT/SkDrawCommandGeometryWidget.cpp new file mode 100644 index 0000000000..1172e7952d --- /dev/null +++ b/debugger/QT/SkDrawCommandGeometryWidget.cpp @@ -0,0 +1,86 @@ + +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <QtGui> + +#include "SkDebugger.h" +#include "SkDrawCommandGeometryWidget.h" + +SkDrawCommandGeometryWidget::SkDrawCommandGeometryWidget(SkDebugger *debugger) + : QFrame() + , fDebugger(debugger) { + this->setStyleSheet("QFrame {background-color: black; border: 1px solid #cccccc;}"); +} + +void SkDrawCommandGeometryWidget::resizeEvent(QResizeEvent* event) { + this->QFrame::resizeEvent(event); + QRect r = this->contentsRect(); + int dim = std::min(r.width(), r.height()); + if (dim == 0) { + fSurface.reset(NULL); + } else { + SkImageInfo info = SkImageInfo::MakeN32Premul(dim, dim); + fSurface.reset(SkSurface::NewRaster(info)); + this->updateImage(); + } +} + +void SkDrawCommandGeometryWidget::paintEvent(QPaintEvent* event) { + this->QFrame::paintEvent(event); + + if (!fSurface) { + return; + } + + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + SkImageInfo info; + size_t rowPixels; + if (const void* pixels = fSurface->peekPixels(&info, &rowPixels)) { + SkASSERT(info.width() > 0); + SkASSERT(info.height() > 0); + + QRectF resultRect; + if (this->width() < this->height()) { + float ratio = this->width() / info.width(); + resultRect = QRectF(0, 0, this->width(), ratio * info.height()); + } else { + float ratio = this->height() / info.height(); + resultRect = QRectF(0, 0, ratio * info.width(), this->height()); + } + + resultRect.moveCenter(this->contentsRect().center()); + + QImage image(reinterpret_cast<const uchar*>(pixels), + info.width(), + info.height(), + QImage::Format_ARGB32_Premultiplied); + painter.drawImage(resultRect, image); + } +} + +void SkDrawCommandGeometryWidget::updateImage() { + if (!fSurface) { + return; + } + + bool didRender = false; + const SkTDArray<SkDrawCommand*>& commands = fDebugger->getDrawCommands(); + if (0 != commands.count()) { + SkDrawCommand* command = commands[fDebugger->index()]; + didRender = command->render(fSurface->getCanvas()); + } + + if (!didRender) { + fSurface->getCanvas()->clear(SK_ColorTRANSPARENT); + } + + fSurface->getCanvas()->flush(); + update(); +} diff --git a/debugger/QT/SkDrawCommandGeometryWidget.h b/debugger/QT/SkDrawCommandGeometryWidget.h new file mode 100644 index 0000000000..aa5d10a01a --- /dev/null +++ b/debugger/QT/SkDrawCommandGeometryWidget.h @@ -0,0 +1,35 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + + +#ifndef SKDRAWCOMMANDGEOMETRYWIDGET_H_ +#define SKDRAWCOMMANDGEOMETRYWIDGET_H_ + +#include <QFrame> + +#include "SkSurface.h" +class SkDebugger; + +class SkDrawCommandGeometryWidget : public QFrame { + Q_OBJECT + +public: + SkDrawCommandGeometryWidget(SkDebugger* debugger); + +public slots: + void updateImage(); + +protected: + void paintEvent(QPaintEvent* event); + void resizeEvent(QResizeEvent* event); + +private: + SkDebugger* fDebugger; + SkAutoTUnref<SkSurface> fSurface; +}; + +#endif /* SKDRAWCOMMANDGEOMETRYWIDGET_H_ */ diff --git a/debugger/QT/SkImageWidget.cpp b/debugger/QT/SkImageWidget.cpp deleted file mode 100644 index aad979406b..0000000000 --- a/debugger/QT/SkImageWidget.cpp +++ /dev/null @@ -1,54 +0,0 @@ - -/* - * 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 <QtGui> - -#include "SkDebugger.h" -#include "SkImageWidget.h" - -SkImageWidget::SkImageWidget(SkDebugger *debugger) - : QWidget() - , fDebugger(debugger) -{ - this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}"); - - SkImageInfo info = SkImageInfo::MakeN32Premul(kImageWidgetWidth, kImageWidgetHeight); - fSurface = SkSurface::NewRasterDirect(info, fPixels, 4 * kImageWidgetWidth); -} - -void SkImageWidget::paintEvent(QPaintEvent* event) { - if (this->isHidden()) { - return; - } - - QPainter painter(this); - QStyleOption opt; - opt.init(this); - - style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); - - const SkTDArray<SkDrawCommand*>& commands = fDebugger->getDrawCommands(); - if (0 != commands.count()) { - SkDrawCommand* command = commands[fDebugger->index()]; - - if (command->render(fSurface->getCanvas())) { - QPoint origin(0,0); - QImage image((uchar*) fPixels, - kImageWidgetWidth, - kImageWidgetHeight, - QImage::Format_ARGB32_Premultiplied); - - painter.drawImage(origin, image); - } else { - painter.drawRect(0, 0, kImageWidgetWidth, kImageWidgetHeight); - } - } - - painter.end(); - emit drawComplete(); -} diff --git a/debugger/QT/SkImageWidget.h b/debugger/QT/SkImageWidget.h deleted file mode 100644 index 7ee430f664..0000000000 --- a/debugger/QT/SkImageWidget.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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 SKIMAGEWIDGET_H_ -#define SKIMAGEWIDGET_H_ - -#include <QWidget> - -#include "SkSurface.h" -class SkDebugger; - -class SkImageWidget : public QWidget { - Q_OBJECT - -public: - SkImageWidget(SkDebugger* debugger); - - virtual ~SkImageWidget() { - fSurface->unref(); - } - - void draw() { - this->update(); - } - - static const int kImageWidgetWidth = 256; - static const int kImageWidgetHeight = 256; - -signals: - void drawComplete(); - -protected: - void paintEvent(QPaintEvent* event); - -private: - SkDebugger* fDebugger; - char fPixels[kImageWidgetHeight * 4 * kImageWidgetWidth]; - SkSurface* fSurface; -}; - -#endif /* SKIMAGEWIDGET_H_ */ |