blob: 03c7e7e0f978ab2ea6a68f05ae7b4af6548cc27f [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()
16 , fDebugger(debugger) {
17 this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}");
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000018
reed@google.com2bd8b812013-11-01 13:46:54 +000019 SkImageInfo info;
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000020 info.fWidth = kImageWidgetWidth;
21 info.fHeight = kImageWidgetHeight;
commit-bot@chromium.org149e9a12014-04-09 20:45:29 +000022 info.fColorType = kN32_SkColorType;
reed@google.combeb0c2a2013-09-20 20:05:01 +000023 info.fAlphaType = kPremul_SkAlphaType;
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000024
25 fSurface = SkSurface::NewRasterDirect(info, fPixels, 4 * kImageWidgetWidth);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000026}
27
28void SkImageWidget::paintEvent(QPaintEvent* event) {
29 if (this->isHidden()) {
30 return;
31 }
32
33 QPainter painter(this);
34 QStyleOption opt;
35 opt.init(this);
36
37 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
38
39 const SkTDArray<SkDrawCommand*>& commands = fDebugger->getDrawCommands();
40 if (0 != commands.count()) {
41 SkDrawCommand* command = commands[fDebugger->index()];
42
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000043 if (command->render(fSurface->getCanvas())) {
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000044 QPoint origin(0,0);
skia.committer@gmail.coma0090832013-06-07 07:01:06 +000045 QImage image((uchar*) fPixels,
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000046 kImageWidgetWidth,
skia.committer@gmail.coma0090832013-06-07 07:01:06 +000047 kImageWidgetHeight,
robertphillips@google.com6ede1fe2013-06-06 23:59:28 +000048 QImage::Format_ARGB32_Premultiplied);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000049
50 painter.drawImage(origin, image);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000051 } else {
52 painter.drawRect(0, 0, kImageWidgetWidth, kImageWidgetHeight);
53 }
54 }
55
56 painter.end();
57 emit drawComplete();
58}