diff options
author | Andras Becsi <andras.becsi@digia.com> | 2013-08-28 20:03:55 +0200 |
---|---|---|
committer | Andras Becsi <andras.becsi@digia.com> | 2013-09-02 20:21:52 +0200 |
commit | c3f53cadb902f711a90b744c5b186208cf08826b (patch) | |
tree | 8eba9a17dd174e6647a9262cb86d4690b9a41cc4 /lib/backing_store_qt.cpp | |
parent | 7146fcc14dcd69f39f20a3e49a9b371bd306bb53 (diff) |
Fix rendering on Retina displays
Since the QWindow returned by the RWHV delegates was always 0 we never
actually propagated a valid WebScreenInfo to chromium.
Additionally the painting and scrolling in the backing store had to be
fixed so that the device pixel ratio is taken into account.
Change-Id: I22dc135e8e090362201292863ed911464b9fc133
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'lib/backing_store_qt.cpp')
-rw-r--r-- | lib/backing_store_qt.cpp | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/lib/backing_store_qt.cpp b/lib/backing_store_qt.cpp index bd33a0a4b..e16e9ab03 100644 --- a/lib/backing_store_qt.cpp +++ b/lib/backing_store_qt.cpp @@ -44,14 +44,21 @@ #include "content/public/browser/render_process_host.h" #include "ui/gfx/rect.h" #include "ui/gfx/rect_conversions.h" +#include "ui/gfx/vector2d_conversions.h" #include "skia/ext/platform_canvas.h" #include <QPainter> +#include <QScreen> +#include <QSizeF> +#include <QWindow> BackingStoreQt::BackingStoreQt(content::RenderWidgetHost *host, const gfx::Size &size, QWindow* parent) : content::BackingStore(host, size) - , m_pixelBuffer(size.width(), size.height()) + , m_deviceScaleFactor((parent && parent->screen()) ? parent->screen()->devicePixelRatio() : 1) + , m_pixelBuffer(size.width() * m_deviceScaleFactor, size.height() * m_deviceScaleFactor) { + Q_ASSERT(parent); + Q_ASSERT(parent->screen()); } BackingStoreQt::~BackingStoreQt() @@ -62,7 +69,14 @@ void BackingStoreQt::paintToTarget(QPainter* painter, const QRectF& rect) { if (m_pixelBuffer.isNull()) return; - painter->drawPixmap(rect, m_pixelBuffer, rect); + + qreal x = rect.x() * m_deviceScaleFactor; + qreal y = rect.y() * m_deviceScaleFactor; + qreal w = rect.width() * m_deviceScaleFactor; + qreal h = rect.height() * m_deviceScaleFactor; + + QRectF source(x, y, w, h); + painter->drawPixmap(rect, m_pixelBuffer, source); } void BackingStoreQt::PaintToBackingStore(content::RenderProcessHost *process, @@ -81,25 +95,26 @@ void BackingStoreQt::PaintToBackingStore(content::RenderProcessHost *process, if (!dib) return; - gfx::Rect pixel_bitmap_rect = bitmap_rect; + gfx::Rect pixel_bitmap_rect = gfx::ToEnclosingRect(gfx::ScaleRect(bitmap_rect, scale_factor)); uint8_t* bitmapData = static_cast<uint8_t*>(dib->memory()); const QImage img(bitmapData, pixel_bitmap_rect.width(), pixel_bitmap_rect.height(), QImage::Format_ARGB32); QPainter painter(&m_pixelBuffer); - for (size_t i = 0; i < copy_rects.size(); ++i) { - gfx::Rect copy_rect = gfx::ToEnclosedRect(gfx::ScaleRect(copy_rects[i], scale_factor)); + gfx::Rect copy_rect = gfx::ToEnclosingRect(gfx::ScaleRect(copy_rects[i], scale_factor)); QRect source = QRect( copy_rect.x() - pixel_bitmap_rect.x() , copy_rect.y() - pixel_bitmap_rect.y() , copy_rect.width() , copy_rect.height()); - QRect destination = QRect( copy_rect.x() - , copy_rect.y() - , copy_rect.width() - , copy_rect.height()); + gfx::Rect copy_rect_dst = gfx::ToEnclosingRect(gfx::ScaleRect(copy_rects[i], m_deviceScaleFactor)); + + QRect destination = QRect( copy_rect_dst.x() + , copy_rect_dst.y() + , copy_rect_dst.width() + , copy_rect_dst.height()); painter.drawImage(destination, img, source); } @@ -109,7 +124,16 @@ void BackingStoreQt::ScrollBackingStore(const gfx::Vector2d &delta, const gfx::R { DCHECK(delta.x() == 0 || delta.y() == 0); - m_pixelBuffer.scroll(delta.x(), delta.y(), clip_rect.x(), clip_rect.y(), clip_rect.width(), clip_rect.height()); + gfx::Rect pixel_rect = gfx::ToEnclosingRect(gfx::ScaleRect(clip_rect, m_deviceScaleFactor)); + gfx::Vector2d pixel_delta = gfx::ToFlooredVector2d(gfx::ScaleVector2d(delta, m_deviceScaleFactor)); + + m_pixelBuffer.scroll(pixel_delta.x() + , pixel_delta.y() + , pixel_rect.x() + , pixel_rect.y() + , pixel_rect.width() + , pixel_rect.height()); + } bool BackingStoreQt::CopyFromBackingStore(const gfx::Rect &rect, skia::PlatformBitmap *output) |