blob: ad05d3966f75a49500f8e37cf1c81f7e93f6e254 [file] [log] [blame]
chudy@google.com38b08ce2012-07-28 23:26:10 +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
chudy@google.com38b08ce2012-07-28 23:26:10 +00009#include "SkRasterWidget.h"
10
chudy@google.com607357f2012-08-07 16:12:23 +000011SkRasterWidget::SkRasterWidget(SkDebugger *debugger) : QWidget() {
reed6c225732014-06-09 19:52:07 -070012 fBitmap.allocN32Pixels(800, 800);
junov@google.comdbfac8a2012-12-06 21:47:40 +000013 fBitmap.eraseColor(SK_ColorTRANSPARENT);
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000014 fDevice = new SkBitmapDevice(fBitmap);
chudy@google.com607357f2012-08-07 16:12:23 +000015 fDebugger = debugger;
chudy@google.com830b8792012-08-01 15:57:52 +000016 fCanvas = new SkCanvas(fDevice);
chudy@google.com38b08ce2012-07-28 23:26:10 +000017 this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}");
18}
19
20SkRasterWidget::~SkRasterWidget() {
chudy@google.com830b8792012-08-01 15:57:52 +000021 SkSafeUnref(fCanvas);
22 SkSafeUnref(fDevice);
chudy@google.com38b08ce2012-07-28 23:26:10 +000023}
24
25void SkRasterWidget::resizeEvent(QResizeEvent* event) {
reed6c225732014-06-09 19:52:07 -070026 fBitmap.allocN32Pixels(event->size().width(), event->size().height());
robertphillips@google.comf4741c12013-02-06 20:13:54 +000027 fBitmap.eraseColor(SK_ColorTRANSPARENT);
chudy@google.com830b8792012-08-01 15:57:52 +000028 SkSafeUnref(fCanvas);
29 SkSafeUnref(fDevice);
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000030 fDevice = new SkBitmapDevice(fBitmap);
chudy@google.com830b8792012-08-01 15:57:52 +000031 fCanvas = new SkCanvas(fDevice);
robertphillipsa8d7f0b2014-08-29 08:03:56 -070032 fDebugger->setWindowSize(event->size().width(), event->size().height());
chudy@google.com2d537a12012-07-31 12:49:52 +000033 this->update();
chudy@google.com38b08ce2012-07-28 23:26:10 +000034}
35
36void SkRasterWidget::paintEvent(QPaintEvent* event) {
chudy@google.com607357f2012-08-07 16:12:23 +000037 if (!this->isHidden()) {
38 fDebugger->draw(fCanvas);
chudy@google.com80a4a602012-07-30 18:54:07 +000039 QPainter painter(this);
40 QStyleOption opt;
41 opt.init(this);
42
43 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
44
45 QPoint origin(0,0);
46 QImage image((uchar *)fBitmap.getPixels(), fBitmap.width(),
47 fBitmap.height(), QImage::Format_ARGB32_Premultiplied);
48
humper@google.com5a867c72013-07-10 15:53:36 +000049#if SK_R32_SHIFT == 0
50 painter.drawImage(origin, image.rgbSwapped());
51#else
chudy@google.com80a4a602012-07-30 18:54:07 +000052 painter.drawImage(origin, image);
humper@google.com5a867c72013-07-10 15:53:36 +000053#endif
chudy@google.com80a4a602012-07-30 18:54:07 +000054 painter.end();
chudy@google.coma9e937c2012-08-03 17:32:05 +000055 emit drawComplete();
chudy@google.com38b08ce2012-07-28 23:26:10 +000056 }
chudy@google.com38b08ce2012-07-28 23:26:10 +000057}