Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include <QtGui> | 9 #include <QtGui> |
| 10 | 10 |
| 11 #include "SkDebugger.h" | 11 #include "SkDebugger.h" |
| 12 #include "SkImageWidget.h" | 12 #include "SkImageWidget.h" |
| 13 | 13 |
| 14 SkImageWidget::SkImageWidget(SkDebugger *debugger) | 14 SkImageWidget::SkImageWidget(SkDebugger *debugger) |
| 15 : QWidget() | 15 : QWidget() |
| 16 , fDebugger(debugger) { | 16 , fDebugger(debugger) { |
| 17 this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cc cccc;}"); | 17 this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cc cccc;}"); |
| 18 | |
|
jvanverth1
2013/06/05 21:48:02
Why not declare fPixels as char fPixels[4*kImageWi
robertphillips
2013/06/05 22:00:12
Done.
| |
| 19 int rowBytes = kImageWidgetWidth * 4; | |
| 20 fPixels = new char[kImageWidgetHeight * rowBytes]; | |
| 21 | |
| 22 SkImage::Info info; | |
| 23 info.fWidth = kImageWidgetWidth; | |
| 24 info.fHeight = kImageWidgetHeight; | |
| 25 info.fColorType = SkImage::kPMColor_ColorType; | |
| 26 info.fAlphaType = SkImage::kPremul_AlphaType; | |
| 27 | |
| 28 fSurface = SkSurface::NewRasterDirect(info, fPixels, rowBytes); | |
| 18 } | 29 } |
| 19 | 30 |
| 20 void SkImageWidget::paintEvent(QPaintEvent* event) { | 31 void SkImageWidget::paintEvent(QPaintEvent* event) { |
| 21 if (this->isHidden()) { | 32 if (this->isHidden()) { |
| 22 return; | 33 return; |
| 23 } | 34 } |
| 24 | 35 |
| 25 QPainter painter(this); | 36 QPainter painter(this); |
| 26 QStyleOption opt; | 37 QStyleOption opt; |
| 27 opt.init(this); | 38 opt.init(this); |
| 28 | 39 |
| 29 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); | 40 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); |
| 30 | 41 |
| 31 const SkTDArray<SkDrawCommand*>& commands = fDebugger->getDrawCommands(); | 42 const SkTDArray<SkDrawCommand*>& commands = fDebugger->getDrawCommands(); |
| 32 if (0 != commands.count()) { | 43 if (0 != commands.count()) { |
| 33 SkDrawCommand* command = commands[fDebugger->index()]; | 44 SkDrawCommand* command = commands[fDebugger->index()]; |
| 34 | 45 |
| 35 const SkBitmap* bitmap = command->getBitmap(); | 46 if (command->render(fSurface->getCanvas())) { |
| 36 | |
| 37 if (NULL != bitmap) { | |
| 38 bitmap->lockPixels(); | |
| 39 | |
| 40 QPoint origin(0,0); | 47 QPoint origin(0,0); |
| 41 QImage image((uchar *)bitmap->getPixels(), bitmap->width(), | 48 QImage image((uchar*) fPixels, |
| 42 bitmap->height(), QImage::Format_ARGB32_Premultiplied); | 49 kImageWidgetWidth, |
| 50 kImageWidgetHeight, | |
| 51 QImage::Format_ARGB32_Premultiplied); | |
| 43 | 52 |
| 44 painter.drawImage(origin, image); | 53 painter.drawImage(origin, image); |
| 45 | |
| 46 bitmap->unlockPixels(); | |
| 47 } else { | 54 } else { |
| 48 painter.drawRect(0, 0, kImageWidgetWidth, kImageWidgetHeight); | 55 painter.drawRect(0, 0, kImageWidgetWidth, kImageWidgetHeight); |
| 49 } | 56 } |
| 50 } | 57 } |
| 51 | 58 |
| 52 painter.end(); | 59 painter.end(); |
| 53 emit drawComplete(); | 60 emit drawComplete(); |
| 54 } | 61 } |
| OLD | NEW |