Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2727)

Unified Diff: debugger/QT/SkRasterWidget.cpp

Issue 839743003: debugger: SW rasterize the picture only when it changes (Closed) Base URL: https://skia.googlesource.com/skia.git@debugcanvas-stateless-draw-01-no-resize
Patch Set: address review comment Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « debugger/QT/SkRasterWidget.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: debugger/QT/SkRasterWidget.cpp
diff --git a/debugger/QT/SkRasterWidget.cpp b/debugger/QT/SkRasterWidget.cpp
index 5363d4ad5f9ddf55264b38b36e7df462fb76bda9..72a742f7aa2610e512e08948695d4f145ab6ff7e 100644
--- a/debugger/QT/SkRasterWidget.cpp
+++ b/debugger/QT/SkRasterWidget.cpp
@@ -7,50 +7,67 @@
*/
#include "SkRasterWidget.h"
+#include "SkDebugger.h"
+#include <QtGui>
-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<const uchar*>(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();
+}
« no previous file with comments | « debugger/QT/SkRasterWidget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698