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

Side by Side 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, 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 unified diff | Download patch
« no previous file with comments | « debugger/QT/SkDrawCommandGeometryWidget.h ('k') | debugger/QT/SkImageWidget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #include <QtGui>
10
11 #include "SkDebugger.h"
12 #include "SkDrawCommandGeometryWidget.h"
13
14 SkDrawCommandGeometryWidget::SkDrawCommandGeometryWidget(SkDebugger *debugger)
15 : QFrame()
16 , fDebugger(debugger) {
17 this->setStyleSheet("QFrame {background-color: black; border: 1px solid #ccc ccc;}");
18 }
19
20 void SkDrawCommandGeometryWidget::resizeEvent(QResizeEvent* event) {
21 this->QFrame::resizeEvent(event);
22 QRect r = this->contentsRect();
23 int dim = std::min(r.width(), r.height());
24 if (dim == 0) {
25 fSurface.reset(NULL);
26 } else {
27 SkImageInfo info = SkImageInfo::MakeN32Premul(dim, dim);
28 fSurface.reset(SkSurface::NewRaster(info));
29 this->updateImage();
30 }
31 }
32
33 void SkDrawCommandGeometryWidget::paintEvent(QPaintEvent* event) {
34 this->QFrame::paintEvent(event);
35
36 if (!fSurface) {
37 return;
38 }
39
40 QPainter painter(this);
41 painter.setRenderHint(QPainter::Antialiasing);
42
43 SkImageInfo info;
44 size_t rowPixels;
45 if (const void* pixels = fSurface->peekPixels(&info, &rowPixels)) {
46 SkASSERT(info.width() > 0);
47 SkASSERT(info.height() > 0);
48
49 QRectF resultRect;
50 if (this->width() < this->height()) {
51 float ratio = this->width() / info.width();
52 resultRect = QRectF(0, 0, this->width(), ratio * info.height());
53 } else {
54 float ratio = this->height() / info.height();
55 resultRect = QRectF(0, 0, ratio * info.width(), this->height());
56 }
57
58 resultRect.moveCenter(this->contentsRect().center());
59
60 QImage image(reinterpret_cast<const uchar*>(pixels),
61 info.width(),
62 info.height(),
63 QImage::Format_ARGB32_Premultiplied);
64 painter.drawImage(resultRect, image);
65 }
66 }
67
68 void SkDrawCommandGeometryWidget::updateImage() {
69 if (!fSurface) {
70 return;
71 }
72
73 bool didRender = false;
74 const SkTDArray<SkDrawCommand*>& commands = fDebugger->getDrawCommands();
75 if (0 != commands.count()) {
76 SkDrawCommand* command = commands[fDebugger->index()];
77 didRender = command->render(fSurface->getCanvas());
78 }
79
80 if (!didRender) {
81 fSurface->getCanvas()->clear(SK_ColorTRANSPARENT);
82 }
83
84 fSurface->getCanvas()->flush();
85 update();
86 }
OLDNEW
« 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