OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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 |
(...skipping 24 matching lines...) Expand all Loading... |
35 this->QFrame::paintEvent(event); | 35 this->QFrame::paintEvent(event); |
36 | 36 |
37 if (!fSurface) { | 37 if (!fSurface) { |
38 return; | 38 return; |
39 } | 39 } |
40 | 40 |
41 QPainter painter(this); | 41 QPainter painter(this); |
42 painter.setRenderHint(QPainter::Antialiasing); | 42 painter.setRenderHint(QPainter::Antialiasing); |
43 | 43 |
44 SkImageInfo info; | 44 SkImageInfo info; |
45 size_t rowPixels; | 45 size_t rowBytes; |
46 if (const void* pixels = fSurface->peekPixels(&info, &rowPixels)) { | 46 if (const void* pixels = fSurface->peekPixels(&info, &rowBytes)) { |
47 SkASSERT(info.width() > 0); | 47 SkASSERT(info.width() > 0); |
48 SkASSERT(info.height() > 0); | 48 SkASSERT(info.height() > 0); |
49 | 49 |
50 QRectF resultRect; | 50 QRectF resultRect; |
51 if (this->width() < this->height()) { | 51 if (this->width() < this->height()) { |
52 float ratio = this->width() / info.width(); | 52 float ratio = this->width() / info.width(); |
53 resultRect = QRectF(0, 0, this->width(), ratio * info.height()); | 53 resultRect = QRectF(0, 0, this->width(), ratio * info.height()); |
54 } else { | 54 } else { |
55 float ratio = this->height() / info.height(); | 55 float ratio = this->height() / info.height(); |
56 resultRect = QRectF(0, 0, ratio * info.width(), this->height()); | 56 resultRect = QRectF(0, 0, ratio * info.width(), this->height()); |
57 } | 57 } |
58 | 58 |
59 resultRect.moveCenter(this->contentsRect().center()); | 59 resultRect.moveCenter(this->contentsRect().center()); |
60 | 60 |
61 QImage image(reinterpret_cast<const uchar*>(pixels), | 61 QImage image(reinterpret_cast<const uchar*>(pixels), |
62 info.width(), | 62 info.width(), |
63 info.height(), | 63 info.height(), |
| 64 rowBytes, |
64 QImage::Format_ARGB32_Premultiplied); | 65 QImage::Format_ARGB32_Premultiplied); |
65 painter.drawImage(resultRect, image); | 66 painter.drawImage(resultRect, image); |
66 } | 67 } |
67 } | 68 } |
68 | 69 |
69 void SkDrawCommandGeometryWidget::setDrawCommandIndex(int commandIndex) { | 70 void SkDrawCommandGeometryWidget::setDrawCommandIndex(int commandIndex) { |
70 fCommandIndex = commandIndex; | 71 fCommandIndex = commandIndex; |
71 this->updateImage(); | 72 this->updateImage(); |
72 } | 73 } |
73 | 74 |
(...skipping 10 matching lines...) Expand all Loading... |
84 didRender = command->render(fSurface->getCanvas()); | 85 didRender = command->render(fSurface->getCanvas()); |
85 } | 86 } |
86 | 87 |
87 if (!didRender) { | 88 if (!didRender) { |
88 fSurface->getCanvas()->clear(SK_ColorTRANSPARENT); | 89 fSurface->getCanvas()->clear(SK_ColorTRANSPARENT); |
89 } | 90 } |
90 | 91 |
91 fSurface->getCanvas()->flush(); | 92 fSurface->getCanvas()->flush(); |
92 this->update(); | 93 this->update(); |
93 } | 94 } |
OLD | NEW |