2012-07-28 23:26:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2012-08-07 16:12:23 +00:00
|
|
|
SkRasterWidget::SkRasterWidget(SkDebugger *debugger) : QWidget() {
|
2014-06-10 02:52:07 +00:00
|
|
|
fBitmap.allocN32Pixels(800, 800);
|
2012-12-06 21:47:40 +00:00
|
|
|
fBitmap.eraseColor(SK_ColorTRANSPARENT);
|
2013-08-29 11:54:56 +00:00
|
|
|
fDevice = new SkBitmapDevice(fBitmap);
|
2012-08-07 16:12:23 +00:00
|
|
|
fDebugger = debugger;
|
2012-08-01 15:57:52 +00:00
|
|
|
fCanvas = new SkCanvas(fDevice);
|
2012-07-28 23:26:10 +00:00
|
|
|
this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkRasterWidget::~SkRasterWidget() {
|
2012-08-01 15:57:52 +00:00
|
|
|
SkSafeUnref(fCanvas);
|
|
|
|
SkSafeUnref(fDevice);
|
2012-07-28 23:26:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkRasterWidget::resizeEvent(QResizeEvent* event) {
|
2014-06-10 02:52:07 +00:00
|
|
|
fBitmap.allocN32Pixels(event->size().width(), event->size().height());
|
2013-02-06 20:13:54 +00:00
|
|
|
fBitmap.eraseColor(SK_ColorTRANSPARENT);
|
2012-08-01 15:57:52 +00:00
|
|
|
SkSafeUnref(fCanvas);
|
|
|
|
SkSafeUnref(fDevice);
|
2013-08-29 11:54:56 +00:00
|
|
|
fDevice = new SkBitmapDevice(fBitmap);
|
2012-08-01 15:57:52 +00:00
|
|
|
fCanvas = new SkCanvas(fDevice);
|
2014-08-29 15:03:56 +00:00
|
|
|
fDebugger->setWindowSize(event->size().width(), event->size().height());
|
2012-07-31 12:49:52 +00:00
|
|
|
this->update();
|
2012-07-28 23:26:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkRasterWidget::paintEvent(QPaintEvent* event) {
|
2012-08-07 16:12:23 +00:00
|
|
|
if (!this->isHidden()) {
|
|
|
|
fDebugger->draw(fCanvas);
|
2012-07-30 18:54:07 +00:00
|
|
|
QPainter painter(this);
|
|
|
|
QStyleOption opt;
|
|
|
|
opt.init(this);
|
2012-07-28 23:26:10 +00:00
|
|
|
|
2012-07-30 18:54:07 +00:00
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
|
2012-07-28 23:26:10 +00:00
|
|
|
|
2012-07-30 18:54:07 +00:00
|
|
|
QPoint origin(0,0);
|
|
|
|
QImage image((uchar *)fBitmap.getPixels(), fBitmap.width(),
|
|
|
|
fBitmap.height(), QImage::Format_ARGB32_Premultiplied);
|
2012-07-28 23:26:10 +00:00
|
|
|
|
2013-07-10 15:53:36 +00:00
|
|
|
#if SK_R32_SHIFT == 0
|
|
|
|
painter.drawImage(origin, image.rgbSwapped());
|
|
|
|
#else
|
2012-07-30 18:54:07 +00:00
|
|
|
painter.drawImage(origin, image);
|
2013-07-10 15:53:36 +00:00
|
|
|
#endif
|
2012-07-30 18:54:07 +00:00
|
|
|
painter.end();
|
2012-08-03 17:32:05 +00:00
|
|
|
emit drawComplete();
|
2012-07-30 18:54:07 +00:00
|
|
|
}
|
2012-07-28 23:26:10 +00:00
|
|
|
}
|