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
This commit is contained in:
kkinnunen 2014-12-30 23:03:56 -08:00 коммит произвёл Commit bot
Родитель 41c79cc0ff
Коммит 63a470227b
7 изменённых файлов: 136 добавлений и 118 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -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_ */

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -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_ */

Просмотреть файл

@ -117,6 +117,8 @@
'../debugger/debuggermain.cpp',
'../debugger/QT/SkDebuggerGUI.cpp',
'../debugger/QT/SkDebuggerGUI.h',
'../debugger/QT/SkDrawCommandGeometryWidget.h',
'../debugger/QT/SkDrawCommandGeometryWidget.cpp',
'../debugger/QT/SkCanvasWidget.cpp',
'../debugger/QT/SkCanvasWidget.h',
'../debugger/QT/SkInspectorWidget.h',
@ -129,8 +131,6 @@
'../debugger/QT/SkGLWidget.cpp',
'../debugger/QT/SkRasterWidget.h',
'../debugger/QT/SkRasterWidget.cpp',
'../debugger/QT/SkImageWidget.h',
'../debugger/QT/SkImageWidget.cpp',
# To update this file edit SkIcons.qrc and rerun rcc to generate cpp
'../debugger/QT/qrc_SkIcons.cpp',
@ -138,10 +138,10 @@
# Generated MOC files
'<(moc_gen_dir)/moc_SkCanvasWidget.cpp',
'<(moc_gen_dir)/moc_SkDebuggerGUI.cpp',
'<(moc_gen_dir)/moc_SkDrawCommandGeometryWidget.cpp',
'<(moc_gen_dir)/moc_SkInspectorWidget.cpp',
'<(moc_gen_dir)/moc_SkSettingsWidget.cpp',
'<(moc_gen_dir)/moc_SkRasterWidget.cpp',
'<(moc_gen_dir)/moc_SkImageWidget.cpp',
'<(moc_gen_dir)/moc_SkGLWidget.cpp',
],
'cflags': [
@ -169,10 +169,10 @@
'sources': [
'<(moc_src_dir)/SkCanvasWidget.h',
'<(moc_src_dir)/SkDebuggerGUI.h',
'<(moc_src_dir)/SkDrawCommandGeometryWidget.h',
'<(moc_src_dir)/SkInspectorWidget.h',
'<(moc_src_dir)/SkSettingsWidget.h',
'<(moc_src_dir)/SkRasterWidget.h',
'<(moc_src_dir)/SkImageWidget.h',
'<(moc_src_dir)/SkGLWidget.h',
],
'rules': [