blob: aad979406bb7c8f1e12002ef7335fa4796111cfe [file] [log] [blame]
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +00001
2/*
3 * Copyright 2012 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 "SkImageWidget.h"
13
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +000014SkImageWidget::SkImageWidget(SkDebugger *debugger)
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000015 : QWidget()
reede5ea5002014-09-03 11:54:58 -070016 , fDebugger(debugger)
17{
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000018 this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}");
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000019
reede5ea5002014-09-03 11:54:58 -070020 SkImageInfo info = SkImageInfo::MakeN32Premul(kImageWidgetWidth, kImageWidgetHeight);
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000021 fSurface = SkSurface::NewRasterDirect(info, fPixels, 4 * kImageWidgetWidth);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000022}
23
24void SkImageWidget::paintEvent(QPaintEvent* event) {
25 if (this->isHidden()) {
26 return;
27 }
28
29 QPainter painter(this);
30 QStyleOption opt;
31 opt.init(this);
32
33 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
34
35 const SkTDArray<SkDrawCommand*>& commands = fDebugger->getDrawCommands();
36 if (0 != commands.count()) {
37 SkDrawCommand* command = commands[fDebugger->index()];
38
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000039 if (command->render(fSurface->getCanvas())) {
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000040 QPoint origin(0,0);
skia.committer@gmail.coma0090832013-06-07 07:01:06 +000041 QImage image((uchar*) fPixels,
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000042 kImageWidgetWidth,
skia.committer@gmail.coma0090832013-06-07 07:01:06 +000043 kImageWidgetHeight,
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000044 QImage::Format_ARGB32_Premultiplied);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000045
46 painter.drawImage(origin, image);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000047 } else {
48 painter.drawRect(0, 0, kImageWidgetWidth, kImageWidgetHeight);
49 }
50 }
51
52 painter.end();
53 emit drawComplete();
54}