Commit 5543e52d authored by Jocelyn Turcotte's avatar Jocelyn Turcotte Committed by The Qt Project
Browse files

Use a QImage instead of QPixmap in BackingStoreQt.


This is mainly to get rid of the warning shown when using QQuickWebEngineView
without delegated rendering with the threaded scene graph render loop:
"QPainter: It is not safe to use drawPixmap() outside the GUI thread"

The main advantage that QPixmap gave us was that QPixmap::scroll is
provided. This patch pulls out some of its implementation to make the
use case work with QImage.

Since QPixmap is backed by a QImage with the raster paint engine, the
previous behavior should remain except on the DirectFB platform, which
we don't ship to yet.

Change-Id: If77c9079ee95218519be1d092cad24635e29a279
Reviewed-by: default avatarZeno Albisser <zeno.albisser@digia.com>
parent b83153f1
No related merge requests found
Showing with 23 additions and 20 deletions
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
#include "backing_store_qt.h" #include "backing_store_qt.h"
#include "type_conversion.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "ui/gfx/rect_conversions.h" #include "ui/gfx/rect_conversions.h"
...@@ -52,10 +54,15 @@ ...@@ -52,10 +54,15 @@
#include <QSizeF> #include <QSizeF>
#include <QWindow> #include <QWindow>
QT_BEGIN_NAMESPACE
// from qbackingstore.cpp
extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset);
QT_END_NAMESPACE
BackingStoreQt::BackingStoreQt(content::RenderWidgetHost *host, const gfx::Size &size, QWindow* parent) BackingStoreQt::BackingStoreQt(content::RenderWidgetHost *host, const gfx::Size &size, QWindow* parent)
: content::BackingStore(host, size) : content::BackingStore(host, size)
, m_deviceScaleFactor((parent && parent->screen()) ? parent->screen()->devicePixelRatio() : 1) , m_deviceScaleFactor((parent && parent->screen()) ? parent->screen()->devicePixelRatio() : 1)
, m_pixelBuffer(size.width() * m_deviceScaleFactor, size.height() * m_deviceScaleFactor) , m_pixelBuffer(size.width() * m_deviceScaleFactor, size.height() * m_deviceScaleFactor, QImage::Format_ARGB32_Premultiplied)
{ {
} }
...@@ -74,7 +81,7 @@ void BackingStoreQt::paintToTarget(QPainter* painter, const QRectF& rect) ...@@ -74,7 +81,7 @@ void BackingStoreQt::paintToTarget(QPainter* painter, const QRectF& rect)
qreal h = rect.height() * m_deviceScaleFactor; qreal h = rect.height() * m_deviceScaleFactor;
QRectF source(x, y, w, h); QRectF source(x, y, w, h);
painter->drawPixmap(rect, m_pixelBuffer, source); painter->drawImage(rect, m_pixelBuffer, source);
} }
void BackingStoreQt::PaintToBackingStore(content::RenderProcessHost *process, void BackingStoreQt::PaintToBackingStore(content::RenderProcessHost *process,
...@@ -125,13 +132,10 @@ void BackingStoreQt::ScrollBackingStore(const gfx::Vector2d &delta, const gfx::R ...@@ -125,13 +132,10 @@ void BackingStoreQt::ScrollBackingStore(const gfx::Vector2d &delta, const gfx::R
gfx::Rect pixel_rect = gfx::ToEnclosingRect(gfx::ScaleRect(clip_rect, m_deviceScaleFactor)); gfx::Rect pixel_rect = gfx::ToEnclosingRect(gfx::ScaleRect(clip_rect, m_deviceScaleFactor));
gfx::Vector2d pixel_delta = gfx::ToFlooredVector2d(gfx::ScaleVector2d(delta, m_deviceScaleFactor)); gfx::Vector2d pixel_delta = gfx::ToFlooredVector2d(gfx::ScaleVector2d(delta, m_deviceScaleFactor));
m_pixelBuffer.scroll(pixel_delta.x() // Logic borrowed from QPixmap::scroll and QRasterPlatformPixmap::scroll.
, pixel_delta.y() QRect dest = toQt(pixel_rect) & m_pixelBuffer.rect();
, pixel_rect.x() QRect src = dest.translated(-pixel_delta.x(), -pixel_delta.y()) & dest;
, pixel_rect.y() qt_scrollRectInImage(m_pixelBuffer, src, QPoint(pixel_delta.x(), pixel_delta.y()));
, pixel_rect.width()
, pixel_rect.height());
} }
bool BackingStoreQt::CopyFromBackingStore(const gfx::Rect &rect, skia::PlatformBitmap *output) bool BackingStoreQt::CopyFromBackingStore(const gfx::Rect &rect, skia::PlatformBitmap *output)
...@@ -150,20 +154,19 @@ bool BackingStoreQt::CopyFromBackingStore(const gfx::Rect &rect, skia::PlatformB ...@@ -150,20 +154,19 @@ bool BackingStoreQt::CopyFromBackingStore(const gfx::Rect &rect, skia::PlatformB
SkAutoLockPixels alp(bitmap); SkAutoLockPixels alp(bitmap);
QPixmap cpy = m_pixelBuffer.copy(rect.x(), rect.y(), rect.width(), rect.height()); QImage cpy = m_pixelBuffer.copy(rect.x(), rect.y(), rect.width(), rect.height());
QImage img = cpy.toImage();
// Convert the format and remove transparency. // Convert the format and remove transparency.
if (img.format() != QImage::Format_RGB32) if (cpy.format() != QImage::Format_RGB32)
img = img.convertToFormat(QImage::Format_RGB32); cpy = cpy.convertToFormat(QImage::Format_RGB32);
const uint8_t* src = img.bits(); const uint8_t* src = cpy.bits();
uint8_t* dst = reinterpret_cast<uint8_t*>(bitmap.getAddr32(0,0)); uint8_t* dst = reinterpret_cast<uint8_t*>(bitmap.getAddr32(0,0));
int bytesPerLine = img.bytesPerLine(); int bytesPerLine = cpy.bytesPerLine();
int bytesPerPixel = bytesPerLine / img.width(); int bytesPerPixel = bytesPerLine / cpy.width();
int copyLineLength = width * bytesPerPixel; int copyLineLength = width * bytesPerPixel;
int lineOffset = rect.y() * img.width(); int lineOffset = rect.y() * cpy.width();
int rowOffset = rect.x() * bytesPerPixel; int rowOffset = rect.x() * bytesPerPixel;
const uint8_t* copyLineBegin = src + rowOffset + lineOffset; const uint8_t* copyLineBegin = src + rowOffset + lineOffset;
...@@ -171,7 +174,7 @@ bool BackingStoreQt::CopyFromBackingStore(const gfx::Rect &rect, skia::PlatformB ...@@ -171,7 +174,7 @@ bool BackingStoreQt::CopyFromBackingStore(const gfx::Rect &rect, skia::PlatformB
for (int lineNumber = 0; lineNumber < height; ++lineNumber) { for (int lineNumber = 0; lineNumber < height; ++lineNumber) {
memcpy(dst, copyLineBegin, copyLineLength); memcpy(dst, copyLineBegin, copyLineLength);
dst += copyLineLength; dst += copyLineLength;
copyLineBegin += img.width(); copyLineBegin += cpy.width();
} }
return true; return true;
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
#include "content/browser/renderer_host/backing_store.h" #include "content/browser/renderer_host/backing_store.h"
#include <QPainter> #include <QPainter>
#include <QPixmap> #include <QImage>
class BackingStoreQt : public content::BackingStore class BackingStoreQt : public content::BackingStore
{ {
...@@ -66,7 +66,7 @@ private: ...@@ -66,7 +66,7 @@ private:
// Number of physical pixels per view unit. This is 1 or 2 in practice. // Number of physical pixels per view unit. This is 1 or 2 in practice.
float m_deviceScaleFactor; float m_deviceScaleFactor;
QPixmap m_pixelBuffer; QImage m_pixelBuffer;
}; };
#endif // BACKING_STORE_QT_H #endif // BACKING_STORE_QT_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment