aboutsummaryrefslogtreecommitdiffhomepage
path: root/debugger/QT/SkRasterWidget.cpp
blob: d78e5f85591e8e55d74f4b37e0e981f837ff87d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkRasterWidget.h"

SkRasterWidget::SkRasterWidget(SkDebugger *debugger) : QWidget() {
    fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 800, 800);
    fBitmap.allocPixels();
    fBitmap.eraseColor(SK_ColorTRANSPARENT);
    fDevice = new SkBitmapDevice(fBitmap);
    fDebugger = debugger;
    fCanvas = new SkCanvas(fDevice);
    this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}");
}

SkRasterWidget::~SkRasterWidget() {
    SkSafeUnref(fCanvas);
    SkSafeUnref(fDevice);
}

void SkRasterWidget::resizeEvent(QResizeEvent* event) {
    fBitmap.setConfig(SkBitmap::kARGB_8888_Config, event->size().width(), event->size().height());
    fBitmap.allocPixels();
    fBitmap.eraseColor(SK_ColorTRANSPARENT);
    SkSafeUnref(fCanvas);
    SkSafeUnref(fDevice);
    fDevice = new SkBitmapDevice(fBitmap);
    fCanvas = new SkCanvas(fDevice);
    fDebugger->resize(event->size().width(), event->size().height());
    this->update();
}

void SkRasterWidget::paintEvent(QPaintEvent* event) {
    if (!this->isHidden()) {
        fDebugger->draw(fCanvas);
        QPainter painter(this);
        QStyleOption opt;
        opt.init(this);

        style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);

        QPoint origin(0,0);
        QImage image((uchar *)fBitmap.getPixels(), fBitmap.width(),
                fBitmap.height(), QImage::Format_ARGB32_Premultiplied);

#if SK_R32_SHIFT == 0
        painter.drawImage(origin, image.rgbSwapped());
#else
        painter.drawImage(origin, image);
#endif
        painter.end();
        emit drawComplete();
    }
}