From a37228e1fecb9eb0d767c3c549073e8ced23ae42 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 23 Sep 2015 23:41:30 -0700 Subject: [PATCH] Bug 1207944 (part 4) - Use SetColor(const Color&) when setting from an nscolor. r=jwatt. In various places SetColor() gets passed an nscolor. These are converted (either implicitly or explicitly) to a gfxRBGA, and then to a gfx::Color. This patch changes all these cases to avoid the middle step, by (a) constructing a gfx::Color directly instead of an nscolor, or (b) by converting an nscolor with Color::FromABGR(). --HG-- extra : rebase_source : ae423a422b37ada8ca0cb6f130350b4a71d58fc4 --- layout/base/nsCSSRendering.cpp | 8 ++++---- layout/base/nsLayoutUtils.cpp | 2 +- layout/base/nsPresShell.cpp | 26 ++++++++++++------------ layout/generic/TextOverflow.cpp | 2 +- layout/generic/nsBulletFrame.cpp | 2 +- layout/generic/nsImageFrame.cpp | 3 ++- layout/generic/nsPageFrame.cpp | 4 ++-- layout/generic/nsTextFrame.cpp | 4 ++-- layout/mathml/nsMathMLChar.cpp | 2 +- layout/mathml/nsMathMLContainerFrame.cpp | 2 +- layout/xul/nsTextBoxFrame.cpp | 2 +- layout/xul/tree/nsTreeBodyFrame.cpp | 2 +- 12 files changed, 30 insertions(+), 29 deletions(-) diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index 5bf99aafc6ed..bfd969f50481 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -2919,7 +2919,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext, // If we might be using a background color, go ahead and set it now. if (drawBackgroundColor && !isCanvasFrame) - ctx->SetColor(gfxRGBA(bgColor)); + ctx->SetColor(Color::FromABGR(bgColor)); // NOTE: no Save() yet, we do that later by calling autoSR.EnsureSaved(ctx) // in the cases we need it. @@ -3847,7 +3847,7 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext, AntialiasMode oldMode = ctx->CurrentAntialiasMode(); ctx->SetAntialiasMode(AntialiasMode::NONE); - ctx->SetColor(aBorderColor); + ctx->SetColor(Color::FromABGR(aBorderColor)); switch (aBorderStyle) { case NS_STYLE_BORDER_STYLE_NONE: @@ -3927,7 +3927,7 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext, aBGColor->mBackgroundColor, aBorderColor); // XXXbz is this SetColor call still needed? - ctx->SetColor(bevelColor); + ctx->SetColor(Color::FromABGR(bevelColor)); nsRect rect(aBorder); nscoord half; if (horizontal) { // top, bottom @@ -3964,7 +3964,7 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext, bevelColor = MakeBevelColor(ridgeGrooveSide, ridgeGroove, aBGColor->mBackgroundColor, aBorderColor); // XXXbz is this SetColor call still needed? - ctx->SetColor(bevelColor); + ctx->SetColor(Color::FromABGR(bevelColor)); if (horizontal) { rect.y = rect.y + half; rect.height = aBorder.height - half; diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 8e2ea013d7a9..d0c19cfbb063 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -5609,7 +5609,7 @@ nsLayoutUtils::PaintTextShadow(const nsIFrame* aFrame, aDestCtx->Save(); aDestCtx->NewPath(); - aDestCtx->SetColor(gfxRGBA(shadowColor)); + aDestCtx->SetColor(Color::FromABGR(shadowColor)); // The callback will draw whatever we want to blur as a shadow. aCallback(&renderingContext, shadowOffset, shadowColor, aCallbackData); diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 4592300c81fd..b81671bfeac2 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -4641,7 +4641,7 @@ PresShell::RenderDocument(const nsRect& aRect, uint32_t aFlags, nsIFrame* rootFrame = mFrameConstructor->GetRootFrame(); if (!rootFrame) { // Nothing to paint, just fill the rect - aThebesContext->SetColor(gfxRGBA(aBackgroundColor)); + aThebesContext->SetColor(Color::FromABGR(aBackgroundColor)); aThebesContext->Fill(); return NS_OK; } @@ -10233,23 +10233,23 @@ void ReflowCountMgr::PaintCount(const char* aName, fm->SetTextRunRTL(false); width = fm->GetWidth(buf, len, aRenderingContext);; - uint32_t color; - uint32_t color2; + Color color; + Color color2; if (aColor != 0) { - color = aColor; - color2 = NS_RGB(0,0,0); + color = Color::FromABGR(aColor); + color2 = Color(0.f, 0.f, 0.f); } else { - uint8_t rc = 0, gc = 0, bc = 0; + gfx::Float rc = 0.f, gc = 0.f, bc = 0.f; if (counter->mCount < 5) { - rc = 255; - gc = 255; - } else if ( counter->mCount < 11) { - gc = 255; + rc = 1.f; + gc = 1.f; + } else if (counter->mCount < 11) { + gc = 1.f; } else { - rc = 255; + rc = 1.f; } - color = NS_RGB(rc,gc,bc); - color2 = NS_RGB(rc/2,gc/2,bc/2); + color = Color(rc, gc, bc); + color2 = Color(rc/2, gc/2, bc/2); } nsRect rect(0,0, width+15, height+15); diff --git a/layout/generic/TextOverflow.cpp b/layout/generic/TextOverflow.cpp index d954b1543e48..5ddb90086ebd 100644 --- a/layout/generic/TextOverflow.cpp +++ b/layout/generic/TextOverflow.cpp @@ -217,7 +217,7 @@ nsDisplayTextOverflowMarker::Paint(nsDisplayListBuilder* aBuilder, nsLayoutUtils::PaintTextShadow(mFrame, aCtx, mRect, mVisibleRect, foregroundColor, PaintTextShadowCallback, (void*)this); - aCtx->ThebesContext()->SetColor(foregroundColor); + aCtx->ThebesContext()->SetColor(gfx::Color::FromABGR(foregroundColor)); PaintTextToContext(aCtx, nsPoint(0, 0)); } diff --git a/layout/generic/nsBulletFrame.cpp b/layout/generic/nsBulletFrame.cpp index 9811d3037c68..f1ceb316bef4 100644 --- a/layout/generic/nsBulletFrame.cpp +++ b/layout/generic/nsBulletFrame.cpp @@ -410,7 +410,7 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt, default: { aRenderingContext.ThebesContext()->SetColor( - nsLayoutUtils::GetColor(this, eCSSProperty_color)); + Color::FromABGR(nsLayoutUtils::GetColor(this, eCSSProperty_color))); nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm), GetFontSizeInflation()); diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 216029059c4e..955a20eba5a7 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -1131,7 +1131,8 @@ nsImageFrame::DisplayAltText(nsPresContext* aPresContext, const nsRect& aRect) { // Set font and color - aRenderingContext.ThebesContext()->SetColor(StyleColor()->mColor); + aRenderingContext.ThebesContext()-> + SetColor(Color::FromABGR(StyleColor()->mColor)); nsRefPtr fm; nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm), nsLayoutUtils::FontSizeInflationFor(this)); diff --git a/layout/generic/nsPageFrame.cpp b/layout/generic/nsPageFrame.cpp index 9c16c55461f1..377c2ee1fdbe 100644 --- a/layout/generic/nsPageFrame.cpp +++ b/layout/generic/nsPageFrame.cpp @@ -390,7 +390,7 @@ nsPageFrame::DrawHeaderFooter(nsRenderingContext& aRenderingContext, gfx->Save(); gfx->Clip(NSRectToSnappedRect(aRect, PresContext()->AppUnitsPerDevPixel(), *drawTarget)); - aRenderingContext.ThebesContext()->SetColor(NS_RGB(0,0,0)); + aRenderingContext.ThebesContext()->SetColor(Color(0.f, 0.f, 0.f)); nsLayoutUtils::DrawString(this, aFontMetrics, &aRenderingContext, str.get(), str.Length(), nsPoint(x, y + aAscent)); @@ -624,7 +624,7 @@ nsPageFrame::PaintHeaderFooter(nsRenderingContext& aRenderingContext, } nsRect rect(aPt, mRect.Size()); - aRenderingContext.ThebesContext()->SetColor(NS_RGB(0,0,0)); + aRenderingContext.ThebesContext()->SetColor(Color(0.f, 0.f, 0.f)); gfxContextAutoDisableSubpixelAntialiasing disable(aRenderingContext.ThebesContext(), aDisableSubpixelAA); diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 4b6aacee3875..e199655c2c4c 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -5691,7 +5691,7 @@ nsTextFrame::PaintOneShadow(uint32_t aOffset, uint32_t aLength, aCtx->Save(); aCtx->NewPath(); - aCtx->SetColor(gfxRGBA(shadowColor)); + aCtx->SetColor(Color::FromABGR(shadowColor)); // Draw the text onto our alpha-only surface to capture the alpha values. // Remember that the box blur context has a device offset on it, so we don't need to @@ -6337,7 +6337,7 @@ DrawTextRun(gfxTextRun* aTextRun, aProvider, aAdvanceWidth, aContextPaint, aCallbacks); aCallbacks->NotifyAfterText(); } else { - aCtx->SetColor(gfxRGBA(aTextColor)); + aCtx->SetColor(Color::FromABGR(aTextColor)); aTextRun->Draw(aCtx, aTextBaselinePt, drawMode, aOffset, aLength, aProvider, aAdvanceWidth, aContextPaint); } diff --git a/layout/mathml/nsMathMLChar.cpp b/layout/mathml/nsMathMLChar.cpp index 5175b63416d5..564362cf77eb 100644 --- a/layout/mathml/nsMathMLChar.cpp +++ b/layout/mathml/nsMathMLChar.cpp @@ -2136,7 +2136,7 @@ nsMathMLChar::PaintForeground(nsPresContext* aPresContext, fgColor = LookAndFeel::GetColor(LookAndFeel::eColorID_TextSelectForeground, fgColor); } - thebesContext->SetColor(fgColor); + thebesContext->SetColor(Color::FromABGR(fgColor)); thebesContext->Save(); nsRect r = mRect + aPt; ApplyTransforms(thebesContext, aPresContext->AppUnitsPerDevPixel(), r); diff --git a/layout/mathml/nsMathMLContainerFrame.cpp b/layout/mathml/nsMathMLContainerFrame.cpp index 0a7976ac2fed..1e42416e107d 100644 --- a/layout/mathml/nsMathMLContainerFrame.cpp +++ b/layout/mathml/nsMathMLContainerFrame.cpp @@ -108,7 +108,7 @@ void nsDisplayMathMLError::Paint(nsDisplayListBuilder* aBuilder, ColorPattern red(ToDeviceColor(Color(1.f, 0.f, 0.f, 1.f))); drawTarget->FillRect(rect, red); - aCtx->ThebesContext()->SetColor(NS_RGB(255,255,255)); + aCtx->ThebesContext()->SetColor(Color(1.f, 1.f, 1.f)); nscoord ascent = fm->MaxAscent(); NS_NAMED_LITERAL_STRING(errorMsg, "invalid-markup"); nsLayoutUtils::DrawUniDirString(errorMsg.get(), uint32_t(errorMsg.Length()), diff --git a/layout/xul/nsTextBoxFrame.cpp b/layout/xul/nsTextBoxFrame.cpp index 574b786610d5..dc5aab21e2d7 100644 --- a/layout/xul/nsTextBoxFrame.cpp +++ b/layout/xul/nsTextBoxFrame.cpp @@ -524,7 +524,7 @@ nsTextBoxFrame::DrawText(nsRenderingContext& aRenderingContext, nscolor c = aOverrideColor ? *aOverrideColor : StyleColor()->mColor; ColorPattern color(ToDeviceColor(c)); - aRenderingContext.ThebesContext()->SetColor(c); + aRenderingContext.ThebesContext()->SetColor(Color::FromABGR(c)); nsresult rv = NS_ERROR_FAILURE; diff --git a/layout/xul/tree/nsTreeBodyFrame.cpp b/layout/xul/tree/nsTreeBodyFrame.cpp index 0a19a5b53ed4..737c00741568 100644 --- a/layout/xul/tree/nsTreeBodyFrame.cpp +++ b/layout/xul/tree/nsTreeBodyFrame.cpp @@ -3695,7 +3695,7 @@ nsTreeBodyFrame::PaintText(int32_t aRowIndex, ctx->PushGroup(gfxContentType::COLOR_ALPHA); } - ctx->SetColor(textContext->StyleColor()->mColor); + ctx->SetColor(Color::FromABGR(textContext->StyleColor()->mColor)); nsLayoutUtils::DrawString(this, *fontMet, &aRenderingContext, text.get(), text.Length(), textRect.TopLeft() + nsPoint(0, baseline),