diff options
Diffstat (limited to 'debugger')
-rw-r--r-- | debugger/QT/SkDebuggerGUI.cpp | 26 | ||||
-rw-r--r-- | debugger/QT/SkDebuggerGUI.h | 5 | ||||
-rw-r--r-- | debugger/QT/SkImageWidget.cpp | 54 | ||||
-rw-r--r-- | debugger/QT/SkImageWidget.h | 39 | ||||
-rw-r--r-- | debugger/SkDebugCanvas.cpp | 38 | ||||
-rw-r--r-- | debugger/SkDrawCommand.cpp | 14 | ||||
-rw-r--r-- | debugger/SkDrawCommand.h | 11 |
7 files changed, 176 insertions, 11 deletions
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp index 710791ace1..448e449fe4 100644 --- a/debugger/QT/SkDebuggerGUI.cpp +++ b/debugger/QT/SkDebuggerGUI.cpp @@ -45,6 +45,7 @@ SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) : , fListWidget(&fCentralWidget) , fDirectoryWidget(&fCentralWidget) , fCanvasWidget(this, &fDebugger) + , fImageWidget(&fDebugger) , fMenuBar(this) , fMenuFile(this) , fMenuNavigate(this) @@ -385,8 +386,10 @@ void SkDebuggerGUI::actionClearDeletes() { } if (fPause) { fCanvasWidget.drawTo(fPausedRow); + fImageWidget.draw(); } else { fCanvasWidget.drawTo(fListWidget.currentRow()); + fImageWidget.draw(); } } @@ -394,6 +397,7 @@ void SkDebuggerGUI::actionCommandFilter() { fDebugger.highlightCurrentCommand( fSettingsWidget.getVisibilityButton()->isChecked()); fCanvasWidget.drawTo(fListWidget.currentRow()); + fImageWidget.draw(); } void SkDebuggerGUI::actionClose() { @@ -414,8 +418,10 @@ void SkDebuggerGUI::actionDelete() { if (fPause) { fCanvasWidget.drawTo(fPausedRow); + fImageWidget.draw(); } else { fCanvasWidget.drawTo(currentRow); + fImageWidget.draw(); } } @@ -426,8 +432,10 @@ void SkDebuggerGUI::actionGLWidget(bool isToggled) { void SkDebuggerGUI::actionInspector() { if (fInspectorWidget.isHidden()) { fInspectorWidget.setHidden(false); + fImageWidget.setHidden(false); } else { fInspectorWidget.setHidden(true); + fImageWidget.setHidden(true); } } @@ -531,6 +539,7 @@ void SkDebuggerGUI::pauseDrawing(bool isPaused) { fPause = isPaused; fPausedRow = fListWidget.currentRow(); fCanvasWidget.drawTo(fPausedRow); + fImageWidget.draw(); } void SkDebuggerGUI::registerListClick(QListWidgetItem *item) { @@ -540,6 +549,7 @@ void SkDebuggerGUI::registerListClick(QListWidgetItem *item) { if (currentRow != -1) { if (!fPause) { fCanvasWidget.drawTo(currentRow); + fImageWidget.draw(); } SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo( currentRow); @@ -712,10 +722,17 @@ void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) { fCanvasWidget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + fImageWidget.setFixedSize(SkImageWidget::kImageWidgetWidth, + SkImageWidget::kImageWidgetHeight); + fInspectorWidget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); fInspectorWidget.setMaximumHeight(300); + fSettingsAndImageLayout.setSpacing(6); + fSettingsAndImageLayout.addWidget(&fSettingsWidget); + fSettingsAndImageLayout.addWidget(&fImageWidget); + fSettingsWidget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); fSettingsWidget.setMaximumWidth(250); @@ -724,12 +741,13 @@ void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) { fLeftColumnLayout.addWidget(&fListWidget); fLeftColumnLayout.addWidget(&fDirectoryWidget); - fCanvasAndSettingsLayout.setSpacing(6); - fCanvasAndSettingsLayout.addWidget(&fCanvasWidget); - fCanvasAndSettingsLayout.addWidget(&fSettingsWidget); + fCanvasSettingsAndImageLayout.setSpacing(6); + fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget); + fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout); + fMainAndRightColumnLayout.setSpacing(6); - fMainAndRightColumnLayout.addLayout(&fCanvasAndSettingsLayout); + fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout); fMainAndRightColumnLayout.addWidget(&fInspectorWidget); fCentralWidget.setLayout(&fContainerLayout); diff --git a/debugger/QT/SkDebuggerGUI.h b/debugger/QT/SkDebuggerGUI.h index c74ed80859..aed40721fe 100644 --- a/debugger/QT/SkDebuggerGUI.h +++ b/debugger/QT/SkDebuggerGUI.h @@ -17,6 +17,7 @@ #include "SkListWidget.h" #include "SkInspectorWidget.h" #include "SkRasterWidget.h" +#include "SkImageWidget.h" #include "SkSettingsWidget.h" #include <QtCore/QVariant> #include <QtGui/QAction> @@ -244,13 +245,15 @@ private: QHBoxLayout fContainerLayout; QVBoxLayout fLeftColumnLayout; QVBoxLayout fMainAndRightColumnLayout; - QHBoxLayout fCanvasAndSettingsLayout; + QHBoxLayout fCanvasSettingsAndImageLayout; + QVBoxLayout fSettingsAndImageLayout; QListWidget fListWidget; QListWidget fDirectoryWidget; SkDebugger fDebugger; SkCanvasWidget fCanvasWidget; + SkImageWidget fImageWidget; SkInspectorWidget fInspectorWidget; SkSettingsWidget fSettingsWidget; diff --git a/debugger/QT/SkImageWidget.cpp b/debugger/QT/SkImageWidget.cpp new file mode 100644 index 0000000000..36a1b3daf9 --- /dev/null +++ b/debugger/QT/SkImageWidget.cpp @@ -0,0 +1,54 @@ + +/* + * 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;}"); +} + +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()]; + + const SkBitmap* bitmap = command->getBitmap(); + + if (NULL != bitmap) { + bitmap->lockPixels(); + + QPoint origin(0,0); + QImage image((uchar *)bitmap->getPixels(), bitmap->width(), + bitmap->height(), QImage::Format_ARGB32_Premultiplied); + + painter.drawImage(origin, image); + + bitmap->unlockPixels(); + } else { + painter.drawRect(0, 0, kImageWidgetWidth, kImageWidgetHeight); + } + } + + painter.end(); + emit drawComplete(); +} diff --git a/debugger/QT/SkImageWidget.h b/debugger/QT/SkImageWidget.h new file mode 100644 index 0000000000..594b21a2f6 --- /dev/null +++ b/debugger/QT/SkImageWidget.h @@ -0,0 +1,39 @@ +/* + * 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> + +class SkDebugger; + +class SkImageWidget : public QWidget { + Q_OBJECT + +public: + SkImageWidget(SkDebugger* debugger); + + 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; +}; + +#endif /* SKIMAGEWIDGET_H_ */ diff --git a/debugger/SkDebugCanvas.cpp b/debugger/SkDebugCanvas.cpp index f6c8082c2d..acb9a7df6c 100644 --- a/debugger/SkDebugCanvas.cpp +++ b/debugger/SkDebugCanvas.cpp @@ -10,6 +10,8 @@ #include <iostream> #include "SkDebugCanvas.h" #include "SkDrawCommand.h" +#include "SkDevice.h" +#include "SkImageWidget.h" static SkBitmap make_noconfig_bm(int width, int height) { SkBitmap bm; @@ -165,8 +167,40 @@ void SkDebugCanvas::clear(SkColor color) { addDrawCommand(new Clear(color)); } +static SkBitmap createBitmap(const SkPath& path) { + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, + SkImageWidget::kImageWidgetWidth, + SkImageWidget::kImageWidgetHeight); + bitmap.allocPixels(); + bitmap.eraseColor(SK_ColorWHITE); + SkDevice* device = new SkDevice(bitmap); + + SkCanvas canvas(device); + device->unref(); + + const SkRect& bounds = path.getBounds(); + + if (bounds.width() > bounds.height()) { + canvas.scale(SkDoubleToScalar((0.9*SkImageWidget::kImageWidgetWidth)/bounds.width()), + SkDoubleToScalar((0.9*SkImageWidget::kImageWidgetHeight)/bounds.width())); + } else { + canvas.scale(SkDoubleToScalar((0.9*SkImageWidget::kImageWidgetWidth)/bounds.height()), + SkDoubleToScalar((0.9*SkImageWidget::kImageWidgetHeight)/bounds.height())); + } + canvas.translate(-bounds.fLeft+2, -bounds.fTop+2); + + SkPaint p; + p.setColor(SK_ColorBLACK); + p.setStyle(SkPaint::kStroke_Style); + + canvas.drawPath(path, p); + + return bitmap; +} + bool SkDebugCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { - addDrawCommand(new ClipPath(path, op, doAA)); + addDrawCommand(new ClipPath(path, op, doAA, createBitmap(path))); return true; } @@ -214,7 +248,7 @@ void SkDebugCanvas::drawPaint(const SkPaint& paint) { } void SkDebugCanvas::drawPath(const SkPath& path, const SkPaint& paint) { - addDrawCommand(new DrawPath(path, paint)); + addDrawCommand(new DrawPath(path, paint, createBitmap(path))); } void SkDebugCanvas::drawPicture(SkPicture& picture) { diff --git a/debugger/SkDrawCommand.cpp b/debugger/SkDrawCommand.cpp index 74c92588d0..45aaaf2c78 100644 --- a/debugger/SkDrawCommand.cpp +++ b/debugger/SkDrawCommand.cpp @@ -75,11 +75,12 @@ void Clear::execute(SkCanvas* canvas) { canvas->clear(this->fColor); } -ClipPath::ClipPath(const SkPath& path, SkRegion::Op op, bool doAA) { +ClipPath::ClipPath(const SkPath& path, SkRegion::Op op, bool doAA, SkBitmap& bitmap) { this->fPath = &path; this->fOp = op; this->fDoAA = doAA; this->fDrawType = CLIP_PATH; + this->fBitmap = bitmap; this->fInfo.push(SkObjectParser::PathToString(path)); this->fInfo.push(SkObjectParser::RegionOpToString(op)); @@ -90,6 +91,10 @@ void ClipPath::execute(SkCanvas* canvas) { canvas->clipPath(*this->fPath, this->fOp, this->fDoAA); } +const SkBitmap* ClipPath::getBitmap() const { + return &fBitmap; +} + ClipRegion::ClipRegion(const SkRegion& region, SkRegion::Op op) { this->fRegion = ®ion; this->fOp = op; @@ -220,9 +225,10 @@ void DrawPaint::execute(SkCanvas* canvas) { canvas->drawPaint(*this->fPaint); } -DrawPath::DrawPath(const SkPath& path, const SkPaint& paint) { +DrawPath::DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap) { this->fPath = &path; this->fPaint = &paint; + this->fBitmap = bitmap; this->fDrawType = DRAW_PATH; this->fInfo.push(SkObjectParser::PathToString(path)); @@ -233,6 +239,10 @@ void DrawPath::execute(SkCanvas* canvas) { canvas->drawPath(*this->fPath, *this->fPaint); } +const SkBitmap* DrawPath::getBitmap() const { + return &fBitmap; +} + DrawPicture::DrawPicture(SkPicture& picture) { this->fPicture = &picture; this->fDrawType = DRAW_PICTURE; diff --git a/debugger/SkDrawCommand.h b/debugger/SkDrawCommand.h index 54fbf9ee15..5d2c065fff 100644 --- a/debugger/SkDrawCommand.h +++ b/debugger/SkDrawCommand.h @@ -37,6 +37,8 @@ public: virtual void execute(SkCanvas* canvas)=0; DrawType getType() { return fDrawType; }; + virtual const SkBitmap* getBitmap() const { return NULL; } + static const char* GetCommandString(DrawType type); protected: @@ -63,12 +65,14 @@ private: class ClipPath : public SkDrawCommand { public: - ClipPath(const SkPath& path, SkRegion::Op op, bool doAA); + ClipPath(const SkPath& path, SkRegion::Op op, bool doAA, SkBitmap& bitmap); virtual void execute(SkCanvas* canvas) SK_OVERRIDE; + virtual const SkBitmap* getBitmap() const SK_OVERRIDE; private: const SkPath* fPath; SkRegion::Op fOp; bool fDoAA; + SkBitmap fBitmap; }; class ClipRegion : public SkDrawCommand { @@ -164,11 +168,14 @@ private: class DrawPath : public SkDrawCommand { public: - DrawPath(const SkPath& path, const SkPaint& paint); + DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap); virtual void execute(SkCanvas* canvas) SK_OVERRIDE; + virtual const SkBitmap* DrawPath::getBitmap() const SK_OVERRIDE; + private: const SkPath* fPath; const SkPaint* fPaint; + SkBitmap fBitmap; }; class DrawPicture : public SkDrawCommand { |