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

Unified Diff: debugger/QT/SkDrawCommandGeometryWidget.cpp

Issue 787143004: debugger: Make draw command image widget resize (Closed) Base URL: https://skia.googlesource.com/skia.git@debugger-resize-01-settings-layout
Patch Set: address review comments Created 5 years, 12 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/SkDrawCommandGeometryWidget.h ('k') | debugger/QT/SkImageWidget.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: debugger/QT/SkDrawCommandGeometryWidget.cpp
diff --git a/debugger/QT/SkDrawCommandGeometryWidget.cpp b/debugger/QT/SkDrawCommandGeometryWidget.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1172e7952d5f3acffca4fa5ac18299e210c3f77a
--- /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();
+}
« no previous file with comments | « debugger/QT/SkDrawCommandGeometryWidget.h ('k') | debugger/QT/SkImageWidget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698