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 /shared | |
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.
Diffstat (limited to 'shared')
-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 |
5 files changed, 16 insertions, 65 deletions
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; |