From: kkinnunen Date: Wed, 14 Jan 2015 06:49:02 +0000 (-0800) Subject: debugger: SW rasterize the picture only when it changes X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~4096 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cfdc0e3fee69694e0f6b083d8455665b2a810589;p=platform%2Fupstream%2FlibSkiaSharp.git debugger: SW rasterize the picture only when it changes Rasterize the picture only when it changes, not every time raster widget paints itself. Removes include SkForceLinking.h while organizing the SkDebuggerGUI.cpp includes. This is part of the work trying to remove bugs that come from SkDebugCanvas stateful draw. Part of the state comes from some optimization that this tries to reproduce in a different way. Review URL: https://codereview.chromium.org/839743003 --- diff --git a/debugger/QT/SkCanvasWidget.cpp b/debugger/QT/SkCanvasWidget.cpp index 73de8c2..9d691cd 100644 --- a/debugger/QT/SkCanvasWidget.cpp +++ b/debugger/QT/SkCanvasWidget.cpp @@ -8,6 +8,7 @@ #include "SkCanvasWidget.h" +#include SkCanvasWidget::SkCanvasWidget(QWidget* parent, SkDebugger* debugger) : QWidget(parent) @@ -40,17 +41,17 @@ SkCanvasWidget::SkCanvasWidget(QWidget* parent, #if SK_SUPPORT_GPU setWidgetVisibility(kGPU_WidgetType, true); #endif - connect(&fRasterWidget, SIGNAL(drawComplete()), - this->parentWidget(), SLOT(drawComplete())); + connect(&fRasterWidget, SIGNAL(drawComplete()), this->parentWidget(), SLOT(drawComplete())); + connect(&fGLWidget, SIGNAL(drawComplete()), this->parentWidget(), SLOT(drawComplete())); } SkCanvasWidget::~SkCanvasWidget() {} void SkCanvasWidget::drawTo(int index) { fDebugger->setIndex(index); - fRasterWidget.draw(); + fRasterWidget.updateImage(); #if SK_SUPPORT_GPU - fGLWidget.draw(); + fGLWidget.updateImage(); #endif emit commandChanged(fDebugger->index()); } diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp index dade567..9e21298 100644 --- a/debugger/QT/SkDebuggerGUI.cpp +++ b/debugger/QT/SkDebuggerGUI.cpp @@ -6,12 +6,12 @@ */ #include "SkDebuggerGUI.h" -#include "SkForceLinking.h" -#include #include "PictureRenderer.h" +#include "SkPictureData.h" #include "SkPicturePlayback.h" #include "SkPictureRecord.h" -#include "SkPictureData.h" +#include +#include #if defined(SK_BUILD_FOR_WIN32) #include "SysTimer_windows.h" @@ -217,11 +217,7 @@ void SkDebuggerGUI::actionClearDeletes() { fDebugger.setCommandVisible(row, true); fSkipCommands[row] = false; } - if (this->isPaused()) { - fCanvasWidget.drawTo(fPausedRow); - } else { - fCanvasWidget.drawTo(fListWidget.currentRow()); - } + this->updateImage(); } void SkDebuggerGUI::actionClose() { @@ -248,13 +244,7 @@ void SkDebuggerGUI::actionDelete() { } } - int currentRow = fListWidget.currentRow(); - - if (this->isPaused()) { - fCanvasWidget.drawTo(fPausedRow); - } else { - fCanvasWidget.drawTo(currentRow); - } + this->updateImage(); } #if SK_SUPPORT_GPU @@ -291,14 +281,14 @@ void SkDebuggerGUI::actionRasterSettingsChanged() { fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !fSettingsWidget.isRasterEnabled()); fDebugger.setOverdrawViz(fSettingsWidget.isOverdrawVizEnabled()); - fCanvasWidget.update(); + this->updateImage(); } void SkDebuggerGUI::actionVisualizationsChanged() { fDebugger.setMegaViz(fSettingsWidget.isMegaVizEnabled()); fDebugger.setPathOps(fSettingsWidget.isPathOpsEnabled()); fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled()); - fCanvasWidget.drawTo(fListWidget.currentRow()); + this->updateImage(); } void SkDebuggerGUI::actionTextureFilter() { @@ -357,6 +347,10 @@ void SkDebuggerGUI::actionStepForward() { } void SkDebuggerGUI::drawComplete() { + SkString clipStack; + fDebugger.getClipStackText(&clipStack); + fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType); + fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix()); fInspectorWidget.setClip(fDebugger.getCurrentClip()); } @@ -398,9 +392,7 @@ void SkDebuggerGUI::openFile(const QString &filename) { void SkDebuggerGUI::pauseDrawing(bool isPaused) { fPausedRow = fListWidget.currentRow(); - if (!fLoading) { - fCanvasWidget.drawTo(fPausedRow); - } + this->updateDrawCommandInfo(); } void SkDebuggerGUI::updateDrawCommandInfo() { @@ -414,9 +406,8 @@ void SkDebuggerGUI::updateDrawCommandInfo() { fCurrentCommandBox.setText(""); fDrawCommandGeometryWidget.setDrawCommandIndex(-1); } else { - if (!this->isPaused()) { - fCanvasWidget.drawTo(currentRow); - } + this->updateImage(); + const SkTDArray *currInfo = fDebugger.getCommandInfo(currentRow); /* TODO(chudy): Add command type before parameters. Rename v @@ -431,10 +422,6 @@ void SkDebuggerGUI::updateDrawCommandInfo() { fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType); } - SkString clipStack; - fDebugger.getClipStackText(&clipStack); - fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType); - fCurrentCommandBox.setText(QString::number(currentRow)); fDrawCommandGeometryWidget.setDrawCommandIndex(currentRow); @@ -862,6 +849,14 @@ void SkDebuggerGUI::setupComboBox() { firstItem->setSelectable(false); } +void SkDebuggerGUI::updateImage() { + if (this->isPaused()) { + fCanvasWidget.drawTo(fPausedRow); + } else { + fCanvasWidget.drawTo(fListWidget.currentRow()); + } +} + void SkDebuggerGUI::updateHit(int newHit) { fCommandHitBox.setText(QString::number(newHit)); } diff --git a/debugger/QT/SkDebuggerGUI.h b/debugger/QT/SkDebuggerGUI.h index 8c6865b..d6c3f49 100644 --- a/debugger/QT/SkDebuggerGUI.h +++ b/debugger/QT/SkDebuggerGUI.h @@ -19,6 +19,7 @@ #include "SkRasterWidget.h" #include "SkDrawCommandGeometryWidget.h" #include "SkSettingsWidget.h" +#include #include #include #include @@ -233,6 +234,8 @@ private slots: void toggleFilter(QString string); void updateHit(int newHit); + + void updateImage(); private: QSplitter fCentralSplitter; QStatusBar fStatusBar; diff --git a/debugger/QT/SkDrawCommandGeometryWidget.cpp b/debugger/QT/SkDrawCommandGeometryWidget.cpp index 03572cf..9f19785 100644 --- a/debugger/QT/SkDrawCommandGeometryWidget.cpp +++ b/debugger/QT/SkDrawCommandGeometryWidget.cpp @@ -42,8 +42,8 @@ void SkDrawCommandGeometryWidget::paintEvent(QPaintEvent* event) { painter.setRenderHint(QPainter::Antialiasing); SkImageInfo info; - size_t rowPixels; - if (const void* pixels = fSurface->peekPixels(&info, &rowPixels)) { + size_t rowBytes; + if (const void* pixels = fSurface->peekPixels(&info, &rowBytes)) { SkASSERT(info.width() > 0); SkASSERT(info.height() > 0); @@ -61,6 +61,7 @@ void SkDrawCommandGeometryWidget::paintEvent(QPaintEvent* event) { QImage image(reinterpret_cast(pixels), info.width(), info.height(), + rowBytes, QImage::Format_ARGB32_Premultiplied); painter.drawImage(resultRect, image); } diff --git a/debugger/QT/SkGLWidget.cpp b/debugger/QT/SkGLWidget.cpp index a1f82e1..1c524aa 100644 --- a/debugger/QT/SkGLWidget.cpp +++ b/debugger/QT/SkGLWidget.cpp @@ -72,7 +72,6 @@ void SkGLWidget::createRenderTarget() { void SkGLWidget::resizeGL(int w, int h) { SkASSERT(w == this->width() && h == this->height()); this->createRenderTarget(); - draw(); } void SkGLWidget::paintGL() { diff --git a/debugger/QT/SkGLWidget.h b/debugger/QT/SkGLWidget.h index d78ff97..baef126 100644 --- a/debugger/QT/SkGLWidget.h +++ b/debugger/QT/SkGLWidget.h @@ -30,7 +30,7 @@ public: ~SkGLWidget(); - void draw() { + void updateImage() { this->updateGL(); } void setSampleCount(int sampleCount); diff --git a/debugger/QT/SkRasterWidget.cpp b/debugger/QT/SkRasterWidget.cpp index 5363d4a..72a742f 100644 --- a/debugger/QT/SkRasterWidget.cpp +++ b/debugger/QT/SkRasterWidget.cpp @@ -7,50 +7,67 @@ */ #include "SkRasterWidget.h" +#include "SkDebugger.h" +#include -SkRasterWidget::SkRasterWidget(SkDebugger *debugger) : QWidget() { - fBitmap.allocN32Pixels(800, 800); - fBitmap.eraseColor(SK_ColorTRANSPARENT); - fDevice = new SkBitmapDevice(fBitmap); - fDebugger = debugger; - fCanvas = new SkCanvas(fDevice); +SkRasterWidget::SkRasterWidget(SkDebugger *debugger) + : QWidget() + , fDebugger(debugger) + , fNeedImageUpdate(false) { this->setStyleSheet("QWidget {background-color: black; border: 1px solid #cccccc;}"); } -SkRasterWidget::~SkRasterWidget() { - SkSafeUnref(fCanvas); - SkSafeUnref(fDevice); -} - void SkRasterWidget::resizeEvent(QResizeEvent* event) { - fBitmap.allocN32Pixels(event->size().width(), event->size().height()); - fBitmap.eraseColor(SK_ColorTRANSPARENT); - SkSafeUnref(fCanvas); - SkSafeUnref(fDevice); - fDevice = new SkBitmapDevice(fBitmap); - fCanvas = new SkCanvas(fDevice); - this->update(); + this->QWidget::resizeEvent(event); + + QRect r = this->contentsRect(); + if (r.width() == 0 || r.height() == 0) { + fSurface.reset(NULL); + } else { + SkImageInfo info = SkImageInfo::MakeN32Premul(r.width(), r.height()); + fSurface.reset(SkSurface::NewRaster(info)); + } + this->updateImage(); } void SkRasterWidget::paintEvent(QPaintEvent* event) { - if (!this->isHidden()) { - fDebugger->draw(fCanvas); - QPainter painter(this); - QStyleOption opt; - opt.init(this); + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + QStyleOption opt; + opt.init(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); + if (!fSurface) { + return; + } - QPoint origin(0,0); - QImage image((uchar *)fBitmap.getPixels(), fBitmap.width(), - fBitmap.height(), QImage::Format_ARGB32_Premultiplied); + if (fNeedImageUpdate) { + fDebugger->draw(fSurface->getCanvas()); + fSurface->getCanvas()->flush(); + fNeedImageUpdate = false; + emit drawComplete(); + } + SkImageInfo info; + size_t rowBytes; + if (const void* pixels = fSurface->peekPixels(&info, &rowBytes)) { + QImage image(reinterpret_cast(pixels), + info.width(), + info.height(), + rowBytes, + QImage::Format_ARGB32_Premultiplied); #if SK_R32_SHIFT == 0 - painter.drawImage(origin, image.rgbSwapped()); + painter.drawImage(this->contentsRect(), image.rgbSwapped()); #else - painter.drawImage(origin, image); + painter.drawImage(this->contentsRect(), image); #endif - painter.end(); - emit drawComplete(); } } + +void SkRasterWidget::updateImage() { + if (!fSurface) { + return; + } + fNeedImageUpdate = true; + this->update(); +} diff --git a/debugger/QT/SkRasterWidget.h b/debugger/QT/SkRasterWidget.h index afad609..09b529c 100644 --- a/debugger/QT/SkRasterWidget.h +++ b/debugger/QT/SkRasterWidget.h @@ -9,15 +9,9 @@ #ifndef SKRASTERWIDGET_H_ #define SKRASTERWIDGET_H_ -#if SK_SUPPORT_GPU -#include "SkGpuDevice.h" -#endif +#include "SkSurface.h" +class SkDebugger; -#include "SkBitmapDevice.h" -#include "SkDebugger.h" - -#include -#include #include class SkRasterWidget : public QWidget { @@ -26,11 +20,7 @@ class SkRasterWidget : public QWidget { public: SkRasterWidget(SkDebugger* debugger); - ~SkRasterWidget(); - - void draw() { - this->update(); - } + void updateImage(); signals: void drawComplete(); @@ -41,10 +31,9 @@ protected: void resizeEvent(QResizeEvent* event); private: - SkBitmap fBitmap; SkDebugger* fDebugger; - SkCanvas* fCanvas; - SkBaseDevice* fDevice; + SkAutoTUnref fSurface; + bool fNeedImageUpdate; }; #endif /* SKRASTERWIDGET_H_ */