skia2/debugger/QT/SkRasterWidget.cpp
kkinnunen 26e5400de4 Remove draw window size state from SkDebugCanvas
The SkDebugCanvas can be (or is currently) being used to draw to multiple
different canvases. If this use-case is intended, then storing draw
-related state in the canvas causes bugs.

Remove draw window size state form SkDebugCanvas. Instead, use the canvas
base layer size as the window size to clip to. This is consistent with
the current use in debugger.

This is part of work trying to remove bugs in debugger that result from
replaying one SkDrawCanvas to two different canvases. Currently the
SkDrawCanvas stores state that can only be valid if it is used for one
canvas.

Review URL: https://codereview.chromium.org/835113002
2015-01-05 12:58:56 -08:00

57 lines
1.5 KiB
C++

/*
* 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.allocN32Pixels(800, 800);
fBitmap.eraseColor(SK_ColorTRANSPARENT);
fDevice = new SkBitmapDevice(fBitmap);
fDebugger = debugger;
fCanvas = new SkCanvas(fDevice);
this->setStyleSheet("QWidget {background-color: black; border: 1px solid #cccccc;}");
}
SkRasterWidget::~SkRasterWidget() {
SkSafeUnref(fCanvas);
SkSafeUnref(fDevice);
}
void SkRasterWidget::resizeEvent(QResizeEvent* event) {
fBitmap.allocN32Pixels(event->size().width(), event->size().height());
fBitmap.eraseColor(SK_ColorTRANSPARENT);
SkSafeUnref(fCanvas);
SkSafeUnref(fDevice);
fDevice = new SkBitmapDevice(fBitmap);
fCanvas = new SkCanvas(fDevice);
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();
}
}