skia2/debugger/QT/SkCanvasWidget.cpp
commit-bot@chromium.org fde1e7ccb4 Support MSAA in the picture debugger
Add radio buttons for setting the GL sample count to 0 ("off"), 4 or
16.

Change the default mode of the GL widget to MSAA4. Previous behavior
corresponded to "off".

BUG=1459
R=robertphillips@google.com

Author: kkinnunen@nvidia.com

Review URL: https://chromiumcodereview.appspot.com/21752002

git-svn-id: http://skia.googlecode.com/svn/trunk@10509 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-08-02 13:59:50 +00:00

145 lines
4.0 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 "SkCanvasWidget.h"
SkCanvasWidget::SkCanvasWidget(QWidget* parent,
SkDebugger* debugger) : QWidget(parent)
, fHorizontalLayout(this)
, fRasterWidget(debugger)
#if SK_SUPPORT_GPU
, fGLWidget(debugger)
#endif
{
fDebugger = debugger;
fHorizontalLayout.setSpacing(6);
fHorizontalLayout.setContentsMargins(0,0,0,0);
fRasterWidget.setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
#if SK_SUPPORT_GPU
fGLWidget.setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
#endif
fHorizontalLayout.addWidget(&fRasterWidget);
#if SK_SUPPORT_GPU
fHorizontalLayout.addWidget(&fGLWidget);
#endif
fPreviousPoint.set(0,0);
fUserMatrix.reset();
#if SK_SUPPORT_GPU
setWidgetVisibility(kGPU_WidgetType, true);
#endif
connect(&fRasterWidget, SIGNAL(drawComplete()),
this->parentWidget(), SLOT(drawComplete()));
}
SkCanvasWidget::~SkCanvasWidget() {}
void SkCanvasWidget::drawTo(int index) {
fDebugger->setIndex(index);
fRasterWidget.draw();
#if SK_SUPPORT_GPU
fGLWidget.draw();
#endif
emit commandChanged(fDebugger->index());
}
void SkCanvasWidget::mouseMoveEvent(QMouseEvent* event) {
SkIPoint eventPoint = SkIPoint::Make(event->globalX(), event->globalY());
SkIPoint eventOffset = eventPoint - fPreviousPoint;
fPreviousPoint = eventPoint;
fUserMatrix.postTranslate(eventOffset.fX, eventOffset.fY);
fDebugger->setUserMatrix(fUserMatrix);
drawTo(fDebugger->index());
}
void SkCanvasWidget::mousePressEvent(QMouseEvent* event) {
fPreviousPoint.set(event->globalX(), event->globalY());
emit hitChanged(fDebugger->getCommandAtPoint(event->x(), event->y(),
fDebugger->index()));
}
void SkCanvasWidget::mouseDoubleClickEvent(QMouseEvent* event) {
Qt::KeyboardModifiers modifiers = event->modifiers();
if (modifiers.testFlag(Qt::ControlModifier)) {
snapWidgetTransform();
} else {
resetWidgetTransform();
}
}
#define ZOOM_FACTOR (1.25f)
void SkCanvasWidget::wheelEvent(QWheelEvent* event) {
Qt::KeyboardModifiers modifiers = event->modifiers();
if (modifiers.testFlag(Qt::ControlModifier)) {
zoom(event->delta() > 0 ? ZOOM_FACTOR : (1.0f / ZOOM_FACTOR), event->x(), event->y());
} else {
if (Qt::Horizontal == event->orientation()) {
fUserMatrix.postTranslate(event->delta(), 0.0f);
} else {
fUserMatrix.postTranslate(0.0f, event->delta());
}
fDebugger->setUserMatrix(fUserMatrix);
drawTo(fDebugger->index());
}
}
void SkCanvasWidget::zoom(int zoomCommand) {
zoom(kIn_ZoomCommand == zoomCommand ? ZOOM_FACTOR : (1.0f / ZOOM_FACTOR),
this->size().width() / 2, this->size().height() / 2);
}
void SkCanvasWidget::snapWidgetTransform() {
double x, y;
modf(fUserMatrix.getTranslateX(), &x);
modf(fUserMatrix.getTranslateY(), &y);
fUserMatrix[SkMatrix::kMTransX] = x;
fUserMatrix[SkMatrix::kMTransY] = y;
fDebugger->setUserMatrix(fUserMatrix);
drawTo(fDebugger->index());
}
void SkCanvasWidget::resetWidgetTransform() {
fUserMatrix.reset();
fDebugger->setUserMatrix(fUserMatrix);
emit scaleFactorChanged(fUserMatrix.getScaleX());
drawTo(fDebugger->index());
}
void SkCanvasWidget::setWidgetVisibility(WidgetType type, bool isHidden) {
if (type == kRaster_8888_WidgetType) {
fRasterWidget.setHidden(isHidden);
}
#if SK_SUPPORT_GPU
else if (type == kGPU_WidgetType) {
fGLWidget.setHidden(isHidden);
}
#endif
}
#if SK_SUPPORT_GPU
void SkCanvasWidget::setGLSampleCount(int sampleCount)
{
fGLWidget.setSampleCount(sampleCount);
}
#endif
void SkCanvasWidget::zoom(float scale, int px, int py) {
fUserMatrix.postScale(scale, scale, px, py);
emit scaleFactorChanged(fUserMatrix.getScaleX());
fDebugger->setUserMatrix(fUserMatrix);
drawTo(fDebugger->index());
}