diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 6266290dd9f6..39b44dd8a3a2 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -3680,7 +3680,7 @@ nsDOMWindowUtils::HandleFullscreenRequests(bool* aRetVal) { // extra resize reflow after this point. nsRect screenRect; if (nsPresContext* presContext = GetPresContext()) { - presContext->DeviceContext()->GetRect(screenRect); + screenRect = presContext->DeviceContext()->GetRect(); } nsSize oldSize; PrepareForFullscreenChange(GetDocShell(), screenRect.Size(), &oldSize); diff --git a/dom/base/nsScreen.cpp b/dom/base/nsScreen.cpp index 07614a7b8384..13ce6dfe9c1d 100644 --- a/dom/base/nsScreen.cpp +++ b/dom/base/nsScreen.cpp @@ -82,10 +82,7 @@ CSSIntRect nsScreen::GetRect() { if (NS_WARN_IF(!context)) { return {}; } - - nsRect r; - context->GetRect(r); - return CSSIntRect::FromAppUnitsRounded(r); + return CSSIntRect::FromAppUnitsRounded(context->GetRect()); } CSSIntRect nsScreen::GetAvailRect() { @@ -111,10 +108,7 @@ CSSIntRect nsScreen::GetAvailRect() { if (NS_WARN_IF(!context)) { return {}; } - - nsRect r; - context->GetClientRect(r); - return CSSIntRect::FromAppUnitsRounded(r); + return CSSIntRect::FromAppUnitsRounded(context->GetClientRect()); } uint16_t nsScreen::GetOrientationAngle() const { diff --git a/gfx/src/nsDeviceContext.cpp b/gfx/src/nsDeviceContext.cpp index 393844b49e00..82f275c5edca 100644 --- a/gfx/src/nsDeviceContext.cpp +++ b/gfx/src/nsDeviceContext.cpp @@ -201,37 +201,32 @@ bool nsDeviceContext::GetScreenIsHDR() { return screen->GetIsHDR(); } -nsresult nsDeviceContext::GetDeviceSurfaceDimensions(nscoord& aWidth, - nscoord& aHeight) { +nsSize nsDeviceContext::GetDeviceSurfaceDimensions() { + return GetRect().Size(); +} + +nsRect nsDeviceContext::GetRect() { if (IsPrinterContext()) { - aWidth = mWidth; - aHeight = mHeight; - } else { - nsRect area; - ComputeFullAreaUsingScreen(&area); - aWidth = area.Width(); - aHeight = area.Height(); + return {0, 0, mWidth, mHeight}; } - - return NS_OK; + RefPtr screen = FindScreen(); + if (!screen) { + return {}; + } + return LayoutDeviceIntRect::ToAppUnits(screen->GetRect(), + AppUnitsPerDevPixel()); } -nsresult nsDeviceContext::GetRect(nsRect& aRect) { +nsRect nsDeviceContext::GetClientRect() { if (IsPrinterContext()) { - aRect.SetRect(0, 0, mWidth, mHeight); - } else - ComputeFullAreaUsingScreen(&aRect); - - return NS_OK; -} - -nsresult nsDeviceContext::GetClientRect(nsRect& aRect) { - if (IsPrinterContext()) { - aRect.SetRect(0, 0, mWidth, mHeight); - } else - ComputeClientRectUsingScreen(&aRect); - - return NS_OK; + return {0, 0, mWidth, mHeight}; + } + RefPtr screen = FindScreen(); + if (!screen) { + return {}; + } + return LayoutDeviceIntRect::ToAppUnits(screen->GetAvailRect(), + AppUnitsPerDevPixel()); } nsresult nsDeviceContext::InitForPrinting(nsIDeviceContextSpec* aDevice) { @@ -358,33 +353,6 @@ nsresult nsDeviceContext::EndPage() { return NS_OK; } -void nsDeviceContext::ComputeClientRectUsingScreen(nsRect* outRect) { - // we always need to recompute the clientRect - // because the window may have moved onto a different screen. In the single - // monitor case, we only need to do the computation if we haven't done it - // once already, and remember that we have because we're assured it won't - // change. - if (RefPtr screen = FindScreen()) { - *outRect = LayoutDeviceIntRect::ToAppUnits(screen->GetAvailRect(), - AppUnitsPerDevPixel()); - } -} - -void nsDeviceContext::ComputeFullAreaUsingScreen(nsRect* outRect) { - // if we have more than one screen, we always need to recompute the clientRect - // because the window may have moved onto a different screen. In the single - // monitor case, we only need to do the computation if we haven't done it - // once already, and remember that we have because we're assured it won't - // change. - if (RefPtr screen = FindScreen()) { - *outRect = LayoutDeviceIntRect::ToAppUnits(screen->GetRect(), - AppUnitsPerDevPixel()); - mWidth = outRect->Width(); - mHeight = outRect->Height(); - } -} - -// // FindScreen // // Determines which screen intersects the largest area of the given surface. diff --git a/gfx/src/nsDeviceContext.h b/gfx/src/nsDeviceContext.h index 7bf7a6aee260..fea799e9fc16 100644 --- a/gfx/src/nsDeviceContext.h +++ b/gfx/src/nsDeviceContext.h @@ -155,37 +155,26 @@ class nsDeviceContext final { bool GetScreenIsHDR(); /** - * Get the size of the displayable area of the output device - * in app units. - * @param aWidth out parameter for width - * @param aHeight out parameter for height - * @return error status + * Get the size of the displayable area of the output device in app units. */ - nsresult GetDeviceSurfaceDimensions(nscoord& aWidth, nscoord& aHeight); + nsSize GetDeviceSurfaceDimensions(); /** * Get the size of the content area of the output device in app * units. This corresponds on a screen device, for instance, to * the entire screen. - * @param aRect out parameter for full rect. Position (x,y) will - * be (0,0) or relative to the primary monitor if - * this is not the primary. - * @return error status */ - nsresult GetRect(nsRect& aRect); + nsRect GetRect(); /** * Get the size of the content area of the output device in app * units. This corresponds on a screen device, for instance, to * the area reported by GetDeviceSurfaceDimensions, minus the * taskbar (Windows) or menubar (Macintosh). - * @param aRect out parameter for client rect. Position (x,y) will - * be (0,0) adjusted for any upper/left non-client - * space if present or relative to the primary - * monitor if this is not the primary. - * @return error status + * Position (x,y) will be (0,0) adjusted for any upper/left non-client space + * if present or relative to the primary monitor if this is not the primary. */ - nsresult GetClientRect(nsRect& aRect); + nsRect GetClientRect(); /** * Returns true if we're currently between BeginDocument() and @@ -289,8 +278,6 @@ class nsDeviceContext final { bool aWantReferenceContext); void SetDPI(); - void ComputeClientRectUsingScreen(nsRect* outRect); - void ComputeFullAreaUsingScreen(nsRect* outRect); already_AddRefed FindScreen(); // Return false if the surface is not right diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index d8778eae74b5..30adf756ad78 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -5080,8 +5080,7 @@ already_AddRefed PresShell::PaintRangePaintInfo( // if the image should not be resized, scale must be 1 float scale = 1.0; - nsRect maxSize; - pc->DeviceContext()->GetClientRect(maxSize); + const nsRect maxSize = pc->DeviceContext()->GetClientRect(); // check if the image should be resized bool resize = !!(aFlags & RenderImageFlags::AutoScale); diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 19ffab5db39b..11fbccffb74e 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -1543,9 +1543,8 @@ gfxSize nsPresContext::ScreenSizeInchesForFontInflation(bool* aChanged) { } nsDeviceContext* dx = DeviceContext(); - nsRect clientRect; - dx->GetClientRect(clientRect); // FIXME: GetClientRect looks expensive float unitsPerInch = dx->AppUnitsPerPhysicalInch(); + nsRect clientRect = dx->GetClientRect(); gfxSize deviceSizeInches(float(clientRect.width) / unitsPerInch, float(clientRect.height) / unitsPerInch); diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp index f4e528b4c1a0..e0ae51e10b41 100644 --- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -1229,9 +1229,7 @@ nsresult nsPrintJob::SetRootView(nsPrintObject* aPO, bool& doReturn, canCreateScrollbars = false; } } else { - nscoord pageWidth, pageHeight; - mPrt->mPrintDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight); - adjSize = nsSize(pageWidth, pageHeight); + adjSize = mPrt->mPrintDC->GetDeviceSurfaceDimensions(); documentIsTopLevel = true; parentView = GetParentViewForRoot(); } diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp index 4009a5eb9c1c..ca382a3cfba8 100644 --- a/layout/style/nsMediaFeatures.cpp +++ b/layout/style/nsMediaFeatures.cpp @@ -89,9 +89,7 @@ static nsSize GetDeviceSize(const Document& aDocument) { return pc->GetPageSize(); } - nsSize size; - pc->DeviceContext()->GetDeviceSurfaceDimensions(size.width, size.height); - return size; + return pc->DeviceContext()->GetDeviceSurfaceDimensions(); } bool Gecko_MediaFeatures_IsResourceDocument(const Document* aDocument) {