diff options
author | Zeno Albisser <zeno.albisser@digia.com> | 2013-06-27 20:55:33 +0200 |
---|---|---|
committer | Zeno Albisser <zeno.albisser@digia.com> | 2013-07-03 14:42:47 +0200 |
commit | b046378c3363a9d2c4eaf74e26f1b4f4acfe13bb (patch) | |
tree | c7543ab773f68e9ec257e21abb9376bfcf1e6359 /lib/backing_store_qt.cpp | |
parent | 2a51875f1e5601f813dd9e9866dd581d3b1eac26 (diff) |
Uncomment and fix implementation of CopyFromBackingStore.
This was commented out when we were using QBackingStore.
But since we switched back to using a simple QPixmap,
this code can be reinserted.
However the copy part of the code required some fixes.
We copy rect.height() number of lines with
rect.width()*bytesPerPixel length each, and then apply
an offset of m_backingStore.width()*bytesPerPixel to get
the start of the next copy rect line.
Change-Id: I0979fab969b6237b847ce82e95a3dd3478f3cf7b
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'lib/backing_store_qt.cpp')
-rw-r--r-- | lib/backing_store_qt.cpp | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/lib/backing_store_qt.cpp b/lib/backing_store_qt.cpp index 5bef6f42e..5c23734cf 100644 --- a/lib/backing_store_qt.cpp +++ b/lib/backing_store_qt.cpp @@ -116,28 +116,44 @@ void BackingStoreQt::ScrollBackingStore(const gfx::Vector2d &delta, const gfx::R bool BackingStoreQt::CopyFromBackingStore(const gfx::Rect &rect, skia::PlatformBitmap *output) { - // const int width = std::min(m_pixelBuffer.width(), rect.width()); - // const int height = std::min(m_pixelBuffer.height(), rect.height()); + const int width = std::min(m_pixelBuffer.width(), rect.width()); + const int height = std::min(m_pixelBuffer.height(), rect.height()); - // if (!output->Allocate(width, height, true)) - // return false; + if (!output->Allocate(width, height, true)) + return false; - // // This code assumes a visual mode where a pixel is - // // represented using a 32-bit unsigned int, with a byte per component. - // const SkBitmap& bitmap = output->GetBitmap(); - // SkAutoLockPixels alp(bitmap); + // This code assumes a visual mode where a pixel is + // represented using a 32-bit unsigned int, with a byte per component. + const SkBitmap& bitmap = output->GetBitmap(); + if (bitmap.rowBytes() != 4) + return false; - // QPixmap cpy = m_pixelBuffer.copy(rect.x(), rect.y(), rect.width(), rect.height()); - // QImage img = cpy.toImage(); + SkAutoLockPixels alp(bitmap); - // // Convert the format and remove transparency. - // if (img.format() != QImage::Format_RGB32) - // img = img.convertToFormat(QImage::Format_RGB32); + QPixmap cpy = m_pixelBuffer.copy(rect.x(), rect.y(), rect.width(), rect.height()); + QImage img = cpy.toImage(); - // const uint8_t* src = img.bits(); - // uint8_t* dst = reinterpret_cast<uint8_t*>(bitmap.getAddr32(0,0)); - // memcpy(dst, src, width*height*32); + // Convert the format and remove transparency. + if (img.format() != QImage::Format_RGB32) + img = img.convertToFormat(QImage::Format_RGB32); - // return true; + const uint8_t* src = img.bits(); + uint8_t* dst = reinterpret_cast<uint8_t*>(bitmap.getAddr32(0,0)); + + int bytesPerLine = img.bytesPerLine(); + int bytesPerPixel = bytesPerLine / img.width(); + int copyLineLength = width * bytesPerPixel; + int lineOffset = rect.y() * img.width(); + int rowOffset = rect.x() * bytesPerPixel; + + const uint8_t* copyLineBegin = src + rowOffset + lineOffset; + + for (int lineNumber = 0; lineNumber < height; ++lineNumber) { + memcpy(dst, copyLineBegin, copyLineLength); + dst += copyLineLength; + copyLineBegin += img.width(); + } + + return true; } |