From b4513bb5c05d8742100c1563a947e8402a177a27 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 2 Dec 2015 21:45:41 -0800 Subject: [PATCH] Bug 1230047 (part 2) - Make several PaintWindow() functions use LayoutDevice coordinates. r=kats. Specifically, the PaintWindow() functions in the following classes: - nsIWidgetListener, and its subclasses nsView and nsWebBrowser; - nsChildView; - nsWindow (the one in widget/uikit/); - nsViewManager. --- embedding/browser/nsWebBrowser.cpp | 4 ++-- embedding/browser/nsWebBrowser.h | 3 ++- gfx/src/nsRect.cpp | 9 --------- gfx/src/nsRect.h | 9 ++++++++- view/nsView.cpp | 2 +- view/nsView.h | 4 +++- view/nsViewManager.cpp | 6 ++++-- view/nsViewManager.h | 5 +++-- widget/PuppetWidget.cpp | 2 +- widget/cocoa/nsChildView.h | 2 +- widget/cocoa/nsChildView.mm | 8 ++++---- widget/gtk/nsWindow.cpp | 4 ++-- widget/nsIWidgetListener.cpp | 2 +- widget/nsIWidgetListener.h | 4 +++- widget/qt/nsWindow.cpp | 3 ++- widget/uikit/nsWindow.h | 2 +- widget/uikit/nsWindow.mm | 17 +++++++++-------- widget/windows/nsWindowGfx.cpp | 8 +++++--- 18 files changed, 52 insertions(+), 42 deletions(-) diff --git a/embedding/browser/nsWebBrowser.cpp b/embedding/browser/nsWebBrowser.cpp index b9dafeeed74..878fc84105d 100644 --- a/embedding/browser/nsWebBrowser.cpp +++ b/embedding/browser/nsWebBrowser.cpp @@ -1729,7 +1729,7 @@ nsWebBrowser::WindowLowered(nsIWidget* aWidget) } bool -nsWebBrowser::PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) +nsWebBrowser::PaintWindow(nsIWidget* aWidget, LayoutDeviceIntRegion aRegion) { LayerManager* layerManager = aWidget->GetLayerManager(); NS_ASSERTION(layerManager, "Must be in paint event"); @@ -1737,7 +1737,7 @@ nsWebBrowser::PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) layerManager->BeginTransaction(); RefPtr root = layerManager->CreatePaintedLayer(); if (root) { - nsIntRect dirtyRect = aRegion.GetBounds(); + nsIntRect dirtyRect = aRegion.GetBounds().ToUnknownRect(); root->SetVisibleRegion(LayerIntRegion::FromUnknownRegion(dirtyRect)); layerManager->SetRoot(root); } diff --git a/embedding/browser/nsWebBrowser.h b/embedding/browser/nsWebBrowser.h index 4eb60881a49..867f058886f 100644 --- a/embedding/browser/nsWebBrowser.h +++ b/embedding/browser/nsWebBrowser.h @@ -122,7 +122,8 @@ protected: // nsIWidgetListener virtual void WindowRaised(nsIWidget* aWidget); virtual void WindowLowered(nsIWidget* aWidget); - virtual bool PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) override; + virtual bool PaintWindow(nsIWidget* aWidget, + mozilla::LayoutDeviceIntRegion aRegion) override; protected: RefPtr mDocShellTreeOwner; diff --git a/gfx/src/nsRect.cpp b/gfx/src/nsRect.cpp index b94d844e43e..562eb67cbc3 100644 --- a/gfx/src/nsRect.cpp +++ b/gfx/src/nsRect.cpp @@ -15,15 +15,6 @@ static_assert((int(NS_SIDE_TOP) == 0) && (int(NS_SIDE_LEFT) == 3), "The mozilla::css::Side sequence must match the nsMargin nscoord sequence"); -nsRect -ToAppUnits(const mozilla::gfx::IntRect& aRect, nscoord aAppUnitsPerPixel) -{ - return nsRect(NSIntPixelsToAppUnits(aRect.x, aAppUnitsPerPixel), - NSIntPixelsToAppUnits(aRect.y, aAppUnitsPerPixel), - NSIntPixelsToAppUnits(aRect.width, aAppUnitsPerPixel), - NSIntPixelsToAppUnits(aRect.height, aAppUnitsPerPixel)); -} - const mozilla::gfx::IntRect& GetMaxSizedIntRect() { static const mozilla::gfx::IntRect r(0, 0, INT32_MAX, INT32_MAX); return r; diff --git a/gfx/src/nsRect.h b/gfx/src/nsRect.h index 38a41f964f3..22481774d06 100644 --- a/gfx/src/nsRect.h +++ b/gfx/src/nsRect.h @@ -303,8 +303,15 @@ nsRect::RemoveResolution(const float aResolution) const const mozilla::gfx::IntRect& GetMaxSizedIntRect(); // app units are integer multiples of pixels, so no rounding needed +template nsRect -ToAppUnits(const mozilla::gfx::IntRect& aRect, nscoord aAppUnitsPerPixel); +ToAppUnits(const mozilla::gfx::IntRectTyped& aRect, nscoord aAppUnitsPerPixel) +{ + return nsRect(NSIntPixelsToAppUnits(aRect.x, aAppUnitsPerPixel), + NSIntPixelsToAppUnits(aRect.y, aAppUnitsPerPixel), + NSIntPixelsToAppUnits(aRect.width, aAppUnitsPerPixel), + NSIntPixelsToAppUnits(aRect.height, aAppUnitsPerPixel)); +} #ifdef DEBUG // Diagnostics diff --git a/view/nsView.cpp b/view/nsView.cpp index 4c47125d31b..2dd2449bf68 100644 --- a/view/nsView.cpp +++ b/view/nsView.cpp @@ -1062,7 +1062,7 @@ nsView::WillPaintWindow(nsIWidget* aWidget) } bool -nsView::PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) +nsView::PaintWindow(nsIWidget* aWidget, LayoutDeviceIntRegion aRegion) { NS_ASSERTION(this == nsView::GetViewFor(aWidget), "wrong view for widget?"); diff --git a/view/nsView.h b/view/nsView.h index bc6fd1698f4..a69909c3aab 100644 --- a/view/nsView.h +++ b/view/nsView.h @@ -59,6 +59,7 @@ public: friend class nsViewManager; typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect; + typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion; NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW @@ -382,7 +383,8 @@ public: virtual bool WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight) override; virtual bool RequestWindowClose(nsIWidget* aWidget) override; virtual void WillPaintWindow(nsIWidget* aWidget) override; - virtual bool PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) override; + virtual bool PaintWindow(nsIWidget* aWidget, + LayoutDeviceIntRegion aRegion) override; virtual void DidPaintWindow() override; virtual void DidCompositeWindow(const mozilla::TimeStamp& aCompositeStart, const mozilla::TimeStamp& aCompositeEnd) override; diff --git a/view/nsViewManager.cpp b/view/nsViewManager.cpp index 5fe87bacc5d..b345a74f646 100644 --- a/view/nsViewManager.cpp +++ b/view/nsViewManager.cpp @@ -281,7 +281,7 @@ nsView* nsViewManager::GetDisplayRootFor(nsView* aView) aContext may be null, in which case layers should be used for rendering. */ -void nsViewManager::Refresh(nsView *aView, const nsIntRegion& aRegion) +void nsViewManager::Refresh(nsView* aView, const LayoutDeviceIntRegion& aRegion) { NS_ASSERTION(aView->GetViewManager() == this, "wrong view manager"); @@ -291,6 +291,7 @@ void nsViewManager::Refresh(nsView *aView, const nsIntRegion& aRegion) // damageRegion is the damaged area, in twips, relative to the view origin nsRegion damageRegion = aRegion.ToAppUnits(AppUnitsPerDevPixel()); + // move region from widget coordinates into view coordinates damageRegion.MoveBy(-aView->ViewToWidgetOffset()); @@ -714,7 +715,8 @@ void nsViewManager::WillPaintWindow(nsIWidget* aWidget) } } -bool nsViewManager::PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) +bool nsViewManager::PaintWindow(nsIWidget* aWidget, + LayoutDeviceIntRegion aRegion) { if (!aWidget || !mContext) return false; diff --git a/view/nsViewManager.h b/view/nsViewManager.h index 1a26958a5cb..21759a1d9b9 100644 --- a/view/nsViewManager.h +++ b/view/nsViewManager.h @@ -28,6 +28,7 @@ public: friend class nsView; typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect; + typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion; NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW @@ -346,7 +347,7 @@ private: void InvalidateViews(nsView *aView); // aView is the view for aWidget and aRegion is relative to aWidget. - void Refresh(nsView *aView, const nsIntRegion& aRegion); + void Refresh(nsView* aView, const LayoutDeviceIntRegion& aRegion); // Utilities @@ -380,7 +381,7 @@ private: bool IsPaintingAllowed() { return RootViewManager()->mRefreshDisableCount == 0; } void WillPaintWindow(nsIWidget* aWidget); - bool PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion); + bool PaintWindow(nsIWidget* aWidget, LayoutDeviceIntRegion aRegion); void DidPaintWindow(); // Call this when you need to let the viewmanager know that it now has diff --git a/widget/PuppetWidget.cpp b/widget/PuppetWidget.cpp index 1dcecae381e..8135dfd4947 100644 --- a/widget/PuppetWidget.cpp +++ b/widget/PuppetWidget.cpp @@ -999,7 +999,7 @@ PuppetWidget::Paint() ctx->Clip(); AutoLayerManagerSetup setupLayerManager(this, ctx, BufferMode::BUFFER_NONE); - GetCurrentWidgetListener()->PaintWindow(this, region.ToUnknownRegion()); + GetCurrentWidgetListener()->PaintWindow(this, region); if (mTabChild) { mTabChild->NotifyPainted(); } diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index 844005dd28e..395c23e2164 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -476,7 +476,7 @@ public: virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent& event); void WillPaintWindow(); - bool PaintWindow(nsIntRegion aRegion); + bool PaintWindow(LayoutDeviceIntRegion aRegion); #ifdef ACCESSIBILITY already_AddRefed GetDocumentAccessible(); diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 96e0270a489..fef65107af2 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -1488,7 +1488,7 @@ void nsChildView::WillPaintWindow() } } -bool nsChildView::PaintWindow(nsIntRegion aRegion) +bool nsChildView::PaintWindow(LayoutDeviceIntRegion aRegion) { nsCOMPtr widget = GetWidgetForListenerEvents(); @@ -3756,10 +3756,10 @@ NSEvent* gLastDragMouseDownEvent = nil; if (mGeckoChild->GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_BASIC) { nsBaseWidget::AutoLayerManagerSetup setupLayerManager(mGeckoChild, targetContext, BufferMode::BUFFER_NONE); - painted = mGeckoChild->PaintWindow(region.ToUnknownRegion()); + painted = mGeckoChild->PaintWindow(region); } else if (mGeckoChild->GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_CLIENT) { // We only need this so that we actually get DidPaintWindow fired - painted = mGeckoChild->PaintWindow(region.ToUnknownRegion()); + painted = mGeckoChild->PaintWindow(region); } targetContext = nullptr; @@ -3830,7 +3830,7 @@ NSEvent* gLastDragMouseDownEvent = nil; mGeckoChild->GetBounds(geckoBounds); LayoutDeviceIntRegion region(geckoBounds); - mGeckoChild->PaintWindow(region.ToUnknownRegion()); + mGeckoChild->PaintWindow(region); // Force OpenGL to refresh the very first time we draw. This works around a // Mac OS X bug that stops windows updating on OS X when we use OpenGL. diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 00974125f59..ef82a47629c 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -2213,7 +2213,7 @@ nsWindow::OnExposeEvent(cairo_t *cr) // If this widget uses OMTC... if (GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_CLIENT) { - listener->PaintWindow(this, region.ToUnknownRegion()); + listener->PaintWindow(this, region); listener->DidPaintWindow(); return TRUE; } @@ -2277,7 +2277,7 @@ nsWindow::OnExposeEvent(cairo_t *cr) { if (GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_BASIC) { AutoLayerManagerSetup setupLayerManager(this, ctx, layerBuffering); - painted = listener->PaintWindow(this, region.ToUnknownRegion()); + painted = listener->PaintWindow(this, region); } } diff --git a/widget/nsIWidgetListener.cpp b/widget/nsIWidgetListener.cpp index 050ad8de131..97a05bb33ab 100644 --- a/widget/nsIWidgetListener.cpp +++ b/widget/nsIWidgetListener.cpp @@ -96,7 +96,7 @@ nsIWidgetListener::WillPaintWindow(nsIWidget* aWidget) bool nsIWidgetListener::PaintWindow(nsIWidget* aWidget, - nsIntRegion aRegion) + LayoutDeviceIntRegion aRegion) { return false; } diff --git a/widget/nsIWidgetListener.h b/widget/nsIWidgetListener.h index 76b87073f06..550c5e5c170 100644 --- a/widget/nsIWidgetListener.h +++ b/widget/nsIWidgetListener.h @@ -11,6 +11,7 @@ #include "mozilla/TimeStamp.h" #include "nsRegionFwd.h" +#include "Units.h" class nsView; class nsIPresShell; @@ -128,7 +129,8 @@ public: * This is called at a time when it is not OK to change the geometry of * this widget or of other widgets. */ - virtual bool PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion); + virtual bool PaintWindow(nsIWidget* aWidget, + mozilla::LayoutDeviceIntRegion aRegion); /** * Indicates that a paint occurred. diff --git a/widget/qt/nsWindow.cpp b/widget/qt/nsWindow.cpp index a490500f461..f2224e6d7a5 100644 --- a/widget/qt/nsWindow.cpp +++ b/widget/qt/nsWindow.cpp @@ -875,7 +875,8 @@ nsWindow::OnPaint() switch (GetLayerManager()->GetBackendType()) { case mozilla::layers::LayersBackend::LAYERS_CLIENT: { - nsIntRegion region(nsIntRect(0, 0, mWidget->width(), mWidget->height())); + LayoutDeviceIntRegion region( + LayoutDeviceIntRect(0, 0, mWidget->width(), mWidget->height())); listener->PaintWindow(this, region); break; } diff --git a/widget/uikit/nsWindow.h b/widget/uikit/nsWindow.h index 85b624ae819..7f716026fb3 100644 --- a/widget/uikit/nsWindow.h +++ b/widget/uikit/nsWindow.h @@ -91,7 +91,7 @@ public: } void WillPaintWindow(); - bool PaintWindow(nsIntRegion aRegion); + bool PaintWindow(LayoutDeviceIntRegion aRegion); bool HasModalDescendents() { return false; } diff --git a/widget/uikit/nsWindow.mm b/widget/uikit/nsWindow.mm index e6ca0f9bbe7..00433291ad4 100644 --- a/widget/uikit/nsWindow.mm +++ b/widget/uikit/nsWindow.mm @@ -282,7 +282,7 @@ private: mGeckoChild->GetBounds(geckoBounds); LayoutDeviceIntRegion region(geckoBounds); - mGeckoChild->PaintWindow(region.ToUnknownRegion()); + mGeckoChild->PaintWindow(region); } // Called asynchronously after setNeedsDisplay in order to avoid entering the @@ -344,10 +344,11 @@ private: CGContextSaveGState(aContext); - nsIntRegion region = nsIntRect(NSToIntRound(aRect.origin.x * scale), - NSToIntRound(aRect.origin.y * scale), - NSToIntRound(aRect.size.width * scale), - NSToIntRound(aRect.size.height * scale)); + LayoutDeviceIntRegion region = + LayoutDeviceIntRect(NSToIntRound(aRect.origin.x * scale), + NSToIntRound(aRect.origin.y * scale), + NSToIntRound(aRect.size.width * scale), + NSToIntRound(aRect.size.height * scale)); // Create Cairo objects. RefPtr targetSurface; @@ -376,10 +377,10 @@ private: } // Set up the clip region. - nsIntRegionRectIterator iter(region); + LayoutDeviceIntRegion::RectIterator iter(region); targetContext->NewPath(); for (;;) { - const nsIntRect* r = iter.Next(); + const LayoutDeviceIntRect* r = iter.Next(); if (!r) break; targetContext->Rectangle(gfxRect(r->x, r->y, r->width, r->height)); @@ -730,7 +731,7 @@ void nsWindow::WillPaintWindow() } } -bool nsWindow::PaintWindow(nsIntRegion aRegion) +bool nsWindow::PaintWindow(LayoutDeviceIntRegion aRegion) { if (!mWidgetListener) return false; diff --git a/widget/windows/nsWindowGfx.cpp b/widget/windows/nsWindowGfx.cpp index b0d086b1752..ecaab98ae84 100644 --- a/widget/windows/nsWindowGfx.cpp +++ b/widget/windows/nsWindowGfx.cpp @@ -406,8 +406,9 @@ bool nsWindow::OnPaint(HDC aDC, uint32_t aNestingLevel) { AutoLayerManagerSetup - setupLayerManager(this, thebesContext, doubleBuffering); - result = listener->PaintWindow(this, region); + setupLayerManager(this, thebesContext, doubleBuffering); + result = listener->PaintWindow( + this, LayoutDeviceIntRegion::FromUnknownRegion(region)); } #ifdef MOZ_XUL @@ -514,7 +515,8 @@ bool nsWindow::OnPaint(HDC aDC, uint32_t aNestingLevel) } break; case LayersBackend::LAYERS_CLIENT: - result = listener->PaintWindow(this, region); + result = listener->PaintWindow( + this, LayoutDeviceIntRegion::FromUnknownRegion(region)); break; default: NS_ERROR("Unknown layers backend used!");