aboutsummaryrefslogtreecommitdiffhomepage
path: root/debugger
diff options
context:
space:
mode:
authorGravatar chudy@google.com <chudy@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-30 18:54:07 +0000
committerGravatar chudy@google.com <chudy@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-30 18:54:07 +0000
commit80a4a60f96c33ccd850f9b0eb4b69ab08c198196 (patch)
tree5d61bfd7c1594c51bb2b465e28f65fb60449bcd4 /debugger
parent58b21ec7f06cfa8b7d7403a6108c0216345b3510 (diff)
Canvas size initializes correctly when drawing from a skia picture
Review URL: https://codereview.appspot.com/6450065 git-svn-id: http://skia.googlecode.com/svn/trunk@4837 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'debugger')
-rw-r--r--debugger/QT/SkCanvasWidget.cpp23
-rw-r--r--debugger/QT/SkRasterWidget.cpp53
-rw-r--r--debugger/SkDebugCanvas.cpp6
-rw-r--r--debugger/SkDebugCanvas.h2
4 files changed, 48 insertions, 36 deletions
diff --git a/debugger/QT/SkCanvasWidget.cpp b/debugger/QT/SkCanvasWidget.cpp
index ec6c0c8159..47db709d55 100644
--- a/debugger/QT/SkCanvasWidget.cpp
+++ b/debugger/QT/SkCanvasWidget.cpp
@@ -23,7 +23,7 @@ SkCanvasWidget::SkCanvasWidget(QWidget* parent) : QWidget(parent)
fHorizontalLayout.addWidget(&fRasterWidget);
fHorizontalLayout.addWidget(&fGLWidget);
- fDebugCanvas = new SkDebugCanvas();
+ fDebugCanvas = NULL;
fIndex = 0;
fPreviousPoint.set(0,0);
@@ -31,6 +31,7 @@ SkCanvasWidget::SkCanvasWidget(QWidget* parent) : QWidget(parent)
fScaleFactor = 1.0;
setWidgetVisibility(kGPU_WidgetType, true);
+ this->setDisabled(true);
}
void SkCanvasWidget::drawTo(int index) {
@@ -45,18 +46,22 @@ void SkCanvasWidget::drawTo(int index) {
}
void SkCanvasWidget::loadPicture(QString filename) {
+ this->setDisabled(false);
SkStream* stream = new SkFILEStream(filename.toAscii());
SkPicture* picture = new SkPicture(stream);
/* TODO(chudy): Implement function that doesn't require new
* instantiation of debug canvas. */
delete fDebugCanvas;
- fDebugCanvas = new SkDebugCanvas();
- fDebugCanvas->setBounds(this->width(), this->height());
+ fDebugCanvas = new SkDebugCanvas(picture->width(), picture->height());
+
picture->draw(fDebugCanvas);
fIndex = fDebugCanvas->getSize();
fRasterWidget.setDebugCanvas(fDebugCanvas);
fGLWidget.setDebugCanvas(fDebugCanvas);
+
+ // TODO(chudy): Remove bounds from debug canvas storage.
+ fDebugCanvas->setBounds(this->width(), this->height());
}
void SkCanvasWidget::mouseMoveEvent(QMouseEvent* event) {
@@ -69,11 +74,13 @@ void SkCanvasWidget::mouseMoveEvent(QMouseEvent* event) {
void SkCanvasWidget::mousePressEvent(QMouseEvent* event) {
fPreviousPoint.set(event->globalX(), event->globalY());
- fDebugCanvas->getBoxClass()->setHitPoint(event->x(), event->y());
- fDebugCanvas->isCalculatingHits(true);
- drawTo(fIndex);
- emit hitChanged(fDebugCanvas->getHitBoxPoint());
- fDebugCanvas->isCalculatingHits(false);
+ if (fDebugCanvas) {
+ fDebugCanvas->getBoxClass()->setHitPoint(event->x(), event->y());
+ fDebugCanvas->isCalculatingHits(true);
+ drawTo(fIndex);
+ emit hitChanged(fDebugCanvas->getHitBoxPoint());
+ fDebugCanvas->isCalculatingHits(false);
+ }
}
void SkCanvasWidget::mouseDoubleClickEvent(QMouseEvent* event) {
diff --git a/debugger/QT/SkRasterWidget.cpp b/debugger/QT/SkRasterWidget.cpp
index 0549649543..8c6a2847a8 100644
--- a/debugger/QT/SkRasterWidget.cpp
+++ b/debugger/QT/SkRasterWidget.cpp
@@ -16,8 +16,7 @@ SkRasterWidget::SkRasterWidget(QWidget* parent) : QWidget(parent) {
fTransform.set(0,0);
fScaleFactor = 1.0;
fIndex = 0;
-
- fDebugCanvas = new SkDebugCanvas();
+ fDebugCanvas = NULL;
this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}");
}
@@ -31,34 +30,40 @@ void SkRasterWidget::resizeEvent(QResizeEvent* event) {
fBitmap.allocPixels();
delete fDevice;
fDevice = new SkDevice(fBitmap);
- fDebugCanvas->setBounds(event->size().width(), event->size().height());
- this->update();
+ //TODO(chudy): Debug Canvas shouldn't store current size. The bitmap
+ //or texture backend should already have it. Refactor.
+ if (fDebugCanvas) {
+ fDebugCanvas->setBounds(event->size().width(), event->size().height());
+ this->update();
+ }
}
void SkRasterWidget::paintEvent(QPaintEvent* event) {
- fBitmap.eraseColor(0);
- SkCanvas canvas(fDevice);
- canvas.translate(fTransform.fX, fTransform.fY);
- if (fScaleFactor < 0) {
- canvas.scale((1.0 / -fScaleFactor), (1.0 / -fScaleFactor));
- } else if (fScaleFactor > 0) {
- canvas.scale(fScaleFactor, fScaleFactor);
- }
+ if (fDebugCanvas) {
+ fBitmap.eraseColor(0);
+ SkCanvas canvas(fDevice);
+ canvas.translate(fTransform.fX, fTransform.fY);
+ if (fScaleFactor < 0) {
+ canvas.scale((1.0 / -fScaleFactor), (1.0 / -fScaleFactor));
+ } else if (fScaleFactor > 0) {
+ canvas.scale(fScaleFactor, fScaleFactor);
+ }
- fMatrix = canvas.getTotalMatrix();
- fClip = canvas.getTotalClip().getBounds();
- fDebugCanvas->drawTo(&canvas, fIndex+1, &fBitmap);
+ fMatrix = canvas.getTotalMatrix();
+ fClip = canvas.getTotalClip().getBounds();
+ fDebugCanvas->drawTo(&canvas, fIndex+1, &fBitmap);
- QPainter painter(this);
- QStyleOption opt;
- opt.init(this);
+ QPainter painter(this);
+ QStyleOption opt;
+ opt.init(this);
- style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, 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);
+ QPoint origin(0,0);
+ QImage image((uchar *)fBitmap.getPixels(), fBitmap.width(),
+ fBitmap.height(), QImage::Format_ARGB32_Premultiplied);
- painter.drawImage(origin, image);
- painter.end();
+ painter.drawImage(origin, image);
+ painter.end();
+ }
}
diff --git a/debugger/SkDebugCanvas.cpp b/debugger/SkDebugCanvas.cpp
index 9510e65643..12d7127ff8 100644
--- a/debugger/SkDebugCanvas.cpp
+++ b/debugger/SkDebugCanvas.cpp
@@ -11,10 +11,10 @@
#include "SkDebugCanvas.h"
#include "SkDrawCommand.h"
-SkDebugCanvas::SkDebugCanvas() {
+SkDebugCanvas::SkDebugCanvas(int width, int height) {
// TODO(chudy): Free up memory from all draw commands in destructor.
- fWidth = 100;
- fHeight = 100;
+ fWidth = width;
+ fHeight = height;
fBm.setConfig(SkBitmap::kNo_Config, fWidth, fHeight);
this->setBitmapDevice(fBm);
fFilter = false;
diff --git a/debugger/SkDebugCanvas.h b/debugger/SkDebugCanvas.h
index 373ef5df49..fa2d7570be 100644
--- a/debugger/SkDebugCanvas.h
+++ b/debugger/SkDebugCanvas.h
@@ -18,7 +18,7 @@
class SkDebugCanvas : public SkCanvas {
public:
- SkDebugCanvas();
+ SkDebugCanvas(int width, int height);
~SkDebugCanvas();
void toggleFilter(bool toggle);