From b046378c3363a9d2c4eaf74e26f1b4f4acfe13bb Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Thu, 27 Jun 2013 20:55:33 +0200 Subject: 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 --- lib/backing_store_qt.cpp | 50 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-) (limited to 'lib/backing_store_qt.cpp') 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(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(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; } -- cgit v1.2.3