diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-06-14 16:25:21 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-06-19 12:23:52 +0200 |
commit | ddc65ad9a8462321279024ec1ae6931e11f8fa23 (patch) | |
tree | b36db91a8cf410b2d9982d270ef49189eb3067ef | |
parent | bbeaf3278de08da00f56aba3511951aaf6a8d233 (diff) |
Simplify the BackingStore handling.
This patch removes the black borders around the widget when resizing.
- No need to resize the BackingStore direcly, RenderWidgetHostImpl::WasResized
takes care of allocating a new one with the correct size.
- Get the backing store just before painting instead of pushing it when
scheduling an update. Getting the backing store has side effects that
assumes it is done that way.
- Remove the about_to_validate_and_paint_ check as all our painting updates
are scheduled back to the event loop and that we are now only fetching
the BackingStore at this point.
-rw-r--r-- | lib/render_widget_host_view_qt_delegate_quick.cpp | 26 | ||||
-rw-r--r-- | lib/render_widget_host_view_qt_delegate_quick.h | 6 | ||||
-rw-r--r-- | lib/render_widget_host_view_qt_delegate_widget.cpp | 22 | ||||
-rw-r--r-- | lib/render_widget_host_view_qt_delegate_widget.h | 2 | ||||
-rw-r--r-- | shared/backing_store_qt.cpp | 29 | ||||
-rw-r--r-- | shared/backing_store_qt.h | 4 | ||||
-rw-r--r-- | shared/render_widget_host_view_qt.cpp | 36 | ||||
-rw-r--r-- | shared/render_widget_host_view_qt.h | 10 | ||||
-rw-r--r-- | shared/render_widget_host_view_qt_delegate.h | 2 |
9 files changed, 34 insertions, 103 deletions
diff --git a/lib/render_widget_host_view_qt_delegate_quick.cpp b/lib/render_widget_host_view_qt_delegate_quick.cpp index 754e68239..13e4ef29f 100644 --- a/lib/render_widget_host_view_qt_delegate_quick.cpp +++ b/lib/render_widget_host_view_qt_delegate_quick.cpp @@ -2,6 +2,9 @@ #include "shared/backing_store_qt.h" #include "shared/render_widget_host_view_qt.h" + +#include "content/browser/renderer_host/render_view_host_impl.h" + #include <QQuickWindow> #include <QWindow> @@ -42,6 +45,7 @@ QWindow* RenderWidgetHostViewQtDelegateQuick::window() const void RenderWidgetHostViewQtDelegateQuick::update(const QRect& rect) { + polish(); QQuickPaintedItem::update(rect); } @@ -53,29 +57,19 @@ void RenderWidgetHostViewQtDelegateQuick::paint(QPainter *painter) m_backingStore->paintToTarget(painter, boundingRect()); } -void RenderWidgetHostViewQtDelegateQuick::setBackingStore(BackingStoreQt* backingStore) -{ - m_backingStore = backingStore; - if (m_backingStore) - m_backingStore->resize(QSize(width(), height())); -} - -QSGNode * RenderWidgetHostViewQtDelegateQuick::updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * data) +void RenderWidgetHostViewQtDelegateQuick::updatePolish() { - return QQuickPaintedItem::updatePaintNode(oldNode, data); + // paint will be called from the scene graph thread and this doesn't play well + // with chromium's use of TLS while getting the backing store. + // updatePolish() should be called from the GUI thread right before the rendering thread starts. + m_backingStore = m_view->GetBackingStore(); } void RenderWidgetHostViewQtDelegateQuick::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry); - resizeBackingStore(); -} - -void RenderWidgetHostViewQtDelegateQuick::resizeBackingStore() -{ - if (m_backingStore) - m_backingStore->resize(QSize(width(), height())); + m_view->GetRenderWidgetHost()->WasResized(); } void RenderWidgetHostViewQtDelegateQuick::focusInEvent(QFocusEvent *event) diff --git a/lib/render_widget_host_view_qt_delegate_quick.h b/lib/render_widget_host_view_qt_delegate_quick.h index 20725c621..20bd263f8 100644 --- a/lib/render_widget_host_view_qt_delegate_quick.h +++ b/lib/render_widget_host_view_qt_delegate_quick.h @@ -23,7 +23,6 @@ class RenderWidgetHostViewQtDelegateQuick : public QQuickPaintedItem, public Ren public: RenderWidgetHostViewQtDelegateQuick(content::RenderWidgetHostViewQt* view, QQuickItem *parent = 0); - virtual void setBackingStore(BackingStoreQt* backingStore); virtual QRectF screenRect() const; virtual void show(); virtual void hide(); @@ -43,11 +42,8 @@ public: void keyReleaseEvent(QKeyEvent*); void wheelEvent(QWheelEvent*); -protected Q_SLOTS: - void resizeBackingStore(); - protected: - QSGNode* updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * data); + void updatePolish(); void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); private: diff --git a/lib/render_widget_host_view_qt_delegate_widget.cpp b/lib/render_widget_host_view_qt_delegate_widget.cpp index 8be1d308f..9a659069f 100644 --- a/lib/render_widget_host_view_qt_delegate_widget.cpp +++ b/lib/render_widget_host_view_qt_delegate_widget.cpp @@ -3,13 +3,14 @@ #include "shared/backing_store_qt.h" #include "shared/render_widget_host_view_qt.h" +#include "content/browser/renderer_host/render_view_host_impl.h" + #include <QResizeEvent> #include <QPaintEvent> RenderWidgetHostViewQtDelegateWidget::RenderWidgetHostViewQtDelegateWidget(content::RenderWidgetHostViewQt* view, QWidget *parent) : QWidget(parent) , m_painter(0) - , m_backingStore(0) , m_view(view) { setFocusPolicy(Qt::ClickFocus); @@ -47,19 +48,12 @@ void RenderWidgetHostViewQtDelegateWidget::update(const QRect& rect) QWidget::update(rect); } -void RenderWidgetHostViewQtDelegateWidget::setBackingStore(BackingStoreQt* backingStore) -{ - m_backingStore = backingStore; - if (m_backingStore) - m_backingStore->resize(size()); -} - void RenderWidgetHostViewQtDelegateWidget::paintEvent(QPaintEvent * event) { - if (!m_backingStore) - return; - QPainter painter(this); - m_backingStore->paintToTarget(&painter, event->rect()); + if (BackingStoreQt *backingStore = m_view->GetBackingStore()) { + QPainter painter(this); + backingStore->paintToTarget(&painter, event->rect()); + } } QPainter* RenderWidgetHostViewQtDelegateWidget::painter() @@ -71,9 +65,7 @@ QPainter* RenderWidgetHostViewQtDelegateWidget::painter() void RenderWidgetHostViewQtDelegateWidget::resizeEvent(QResizeEvent *resizeEvent) { - if (m_backingStore) - m_backingStore->resize(resizeEvent->size()); - QWidget::update(); + m_view->GetRenderWidgetHost()->WasResized(); } bool RenderWidgetHostViewQtDelegateWidget::event(QEvent *event) diff --git a/lib/render_widget_host_view_qt_delegate_widget.h b/lib/render_widget_host_view_qt_delegate_widget.h index 9087ba017..f6da4f484 100644 --- a/lib/render_widget_host_view_qt_delegate_widget.h +++ b/lib/render_widget_host_view_qt_delegate_widget.h @@ -17,7 +17,6 @@ class RenderWidgetHostViewQtDelegateWidget : public QWidget, public RenderWidget public: RenderWidgetHostViewQtDelegateWidget(content::RenderWidgetHostViewQt* view, QWidget *parent = 0); - virtual void setBackingStore(BackingStoreQt* backingStore); virtual QRectF screenRect() const; virtual void show(); virtual void hide(); @@ -33,7 +32,6 @@ protected: void resizeEvent(QResizeEvent *resizeEvent); private: - BackingStoreQt* m_backingStore; QPainter* m_painter; content::RenderWidgetHostViewQt *m_view; }; diff --git a/shared/backing_store_qt.cpp b/shared/backing_store_qt.cpp index 8920b72c3..cee0d093e 100644 --- a/shared/backing_store_qt.cpp +++ b/shared/backing_store_qt.cpp @@ -49,34 +49,15 @@ #include <QPainter> BackingStoreQt::BackingStoreQt(content::RenderWidgetHost *host, const gfx::Size &size, QWindow* parent) - : m_host(content::RenderWidgetHostImpl::From(host)) + : content::BackingStore(host, size) , m_pixelBuffer(size.width(), size.height()) - , content::BackingStore(host, size) - , m_isValid(false) { - int width = size.width(); - int height = size.height(); - resize(QSize(width, height)); } BackingStoreQt::~BackingStoreQt() { } -void BackingStoreQt::resize(const QSize& size) -{ - m_isValid = false; - if (size != m_pixelBuffer.size()) { - QPixmap oldBackingStore = m_pixelBuffer; - m_pixelBuffer = QPixmap(size); - - QPainter painter(&m_pixelBuffer); - painter.drawPixmap(oldBackingStore.rect(), oldBackingStore); - - m_host->WasResized(); - } -} - void BackingStoreQt::paintToTarget(QPainter* painter, const QRectF& rect) { if (m_pixelBuffer.isNull()) @@ -105,9 +86,9 @@ void BackingStoreQt::PaintToBackingStore(content::RenderProcessHost *process, uint8_t* bitmapData = static_cast<uint8_t*>(dib->memory()); int width = m_pixelBuffer.size().width(); int height = m_pixelBuffer.size().height(); - QImage img(bitmapData, pixel_bitmap_rect.width(), pixel_bitmap_rect.height(), QImage::Format_ARGB32); + const QImage img(bitmapData, pixel_bitmap_rect.width(), pixel_bitmap_rect.height(), QImage::Format_ARGB32); - m_painter.begin(&m_pixelBuffer); + 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)); @@ -122,10 +103,8 @@ void BackingStoreQt::PaintToBackingStore(content::RenderProcessHost *process, , copy_rect.width() , copy_rect.height()); - m_painter.drawPixmap(destination, QPixmap::fromImage(img), source); + painter.drawImage(destination, img, source); } - - m_painter.end(); } void BackingStoreQt::ScrollBackingStore(const gfx::Vector2d &delta, const gfx::Rect &clip_rect, const gfx::Size &view_size) diff --git a/shared/backing_store_qt.h b/shared/backing_store_qt.h index 9f7e807d3..d2fa52f38 100644 --- a/shared/backing_store_qt.h +++ b/shared/backing_store_qt.h @@ -53,7 +53,6 @@ public: BackingStoreQt(content::RenderWidgetHost *host, const gfx::Size &size, QWindow* parent); ~BackingStoreQt(); - void resize(const QSize& size); void paintToTarget(QPainter*, const QRectF& rect); virtual void PaintToBackingStore(content::RenderProcessHost *process, TransportDIB::Id bitmap, const gfx::Rect &bitmap_rect, @@ -64,10 +63,7 @@ public: virtual bool CopyFromBackingStore(const gfx::Rect &rect, skia::PlatformBitmap *output); private: - QPainter m_painter; - content::RenderWidgetHost* m_host; QPixmap m_pixelBuffer; - bool m_isValid; }; #endif diff --git a/shared/render_widget_host_view_qt.cpp b/shared/render_widget_host_view_qt.cpp index 759667000..305a4f6b8 100644 --- a/shared/render_widget_host_view_qt.cpp +++ b/shared/render_widget_host_view_qt.cpp @@ -90,7 +90,6 @@ void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebKit::WebScreenInfo* resul RenderWidgetHostViewQt::RenderWidgetHostViewQt(content::RenderWidgetHost* widget) : m_host(content::RenderWidgetHostImpl::From(widget)) , m_delegate(0) - , about_to_validate_and_paint_(false) { m_host->SetView(this); } @@ -125,6 +124,12 @@ bool RenderWidgetHostViewQt::handleEvent(QEvent* event) { return true; } +BackingStoreQt* RenderWidgetHostViewQt::GetBackingStore() +{ + bool force_create = !m_host->empty(); + return static_cast<BackingStoreQt*>(m_host->GetBackingStore(force_create)); +} + content::BackingStore *RenderWidgetHostViewQt::AllocBackingStore(const gfx::Size &size) { return new BackingStoreQt(m_host, size, new QWindow); @@ -327,20 +332,13 @@ void RenderWidgetHostViewQt::DidUpdateBackingStore(const gfx::Rect& scroll_rect, if (!m_delegate->isVisible()) return; - if (about_to_validate_and_paint_) - invalid_rect_.Union(scroll_rect); - else - Paint(scroll_rect); + Paint(scroll_rect); for (size_t i = 0; i < copy_rects.size(); ++i) { gfx::Rect rect = gfx::SubtractRects(copy_rects[i], scroll_rect); if (rect.IsEmpty()) continue; - - if (about_to_validate_and_paint_) - invalid_rect_.Union(rect); - else - Paint(rect); + Paint(rect); } } @@ -458,22 +456,8 @@ void RenderWidgetHostViewQt::OnAccessibilityNotifications(const std::vector<Acce void RenderWidgetHostViewQt::Paint(const gfx::Rect& damage_rect) { - DCHECK(!about_to_validate_and_paint_); - - invalid_rect_ = damage_rect; - about_to_validate_and_paint_ = true; - - bool force_create = !m_host->empty(); - BackingStoreQt* backing_store = static_cast<BackingStoreQt*>(m_host->GetBackingStore(force_create)); - - // Calling GetBackingStore maybe have changed |invalid_rect_|... - about_to_validate_and_paint_ = false; - - if (backing_store) { - m_delegate->setBackingStore(backing_store); - QRect r(invalid_rect_.x(), invalid_rect_.y(), invalid_rect_.width(), invalid_rect_.height()); - m_delegate->update(r); - } + QRect r(damage_rect.x(), damage_rect.y(), damage_rect.width(), damage_rect.height()); + m_delegate->update(r); } bool RenderWidgetHostViewQt::IsPopup() const diff --git a/shared/render_widget_host_view_qt.h b/shared/render_widget_host_view_qt.h index 79b9921ae..9ff200c32 100644 --- a/shared/render_widget_host_view_qt.h +++ b/shared/render_widget_host_view_qt.h @@ -51,6 +51,7 @@ #define QT_NOT_YET_IMPLEMENTED qt_noop(); #endif +class BackingStoreQt; class QEvent; class QFocusEvent; class QKeyEvent; @@ -69,6 +70,7 @@ public: void SetDelegate(RenderWidgetHostViewQtDelegate* delegate) { m_delegate = delegate; } bool handleEvent(QEvent* event); + BackingStoreQt* GetBackingStore(); virtual content::BackingStore *AllocBackingStore(const gfx::Size &size); @@ -139,14 +141,6 @@ private: content::RenderWidgetHostImpl *m_host; RenderWidgetHostViewQtDelegate *m_delegate; gfx::Size m_requestedSize; - - // This is true when we are currently painting and thus should handle extra - // paint requests by expanding the invalid rect rather than actually - // painting. - bool about_to_validate_and_paint_; - - // This is the rectangle which we'll paint. - gfx::Rect invalid_rect_; }; } diff --git a/shared/render_widget_host_view_qt_delegate.h b/shared/render_widget_host_view_qt_delegate.h index c01d7d942..7f147dae6 100644 --- a/shared/render_widget_host_view_qt_delegate.h +++ b/shared/render_widget_host_view_qt_delegate.h @@ -3,13 +3,11 @@ #include <QRect> -class BackingStoreQt; class QWindow; class RenderWidgetHostViewQtDelegate { public: virtual ~RenderWidgetHostViewQtDelegate() {} - virtual void setBackingStore(BackingStoreQt* backingStore) = 0; virtual QRectF screenRect() const = 0; virtual void show() = 0; virtual void hide() = 0; |