Bug 1024148 - Part 2: Merge nsDisplayOpacity into nsDisplayBackgroundColor. r=mattwoodrow

--HG--
extra : rebase_source : c48cc799414ff83b74caff8df5503a743dbf74b1
This commit is contained in:
Benoit Girard 2014-06-14 11:10:45 -04:00
parent 8147665edf
commit 2175dbff83
8 changed files with 60 additions and 30 deletions

View File

@ -29,6 +29,10 @@ typedef uint32_t nscolor;
#define NS_RGBA(_r,_g,_b,_a) \
((nscolor) (((_a) << 24) | ((_b)<<16) | ((_g)<<8) | (_r)))
// Make a color out of a gfxRGBA.
#define NS_RGBA_FROM_GFXRGBA(gfxColor) \
((nscolor) (gfxColor.Packed()))
// Extract color components from nscolor
#define NS_GET_R(_rgba) ((uint8_t) ((_rgba) & 0xff))
#define NS_GET_G(_rgba) ((uint8_t) (((_rgba) >> 8) & 0xff))

View File

@ -1602,7 +1602,8 @@ nsCSSRendering::PaintBackground(nsPresContext* aPresContext,
}
void
nsCSSRendering::PaintBackgroundColor(nsPresContext* aPresContext,
nsCSSRendering::PaintBackgroundColor(gfxRGBA aColor,
nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsIFrame* aForFrame,
const nsRect& aDirtyRect,
@ -1634,7 +1635,7 @@ nsCSSRendering::PaintBackgroundColor(nsPresContext* aPresContext,
sc = aForFrame->StyleContext();
}
PaintBackgroundColorWithSC(aPresContext, aRenderingContext, aForFrame,
PaintBackgroundColorWithSC(aColor, aPresContext, aRenderingContext, aForFrame,
aDirtyRect, aBorderArea, sc,
*aForFrame->StyleBorder(), aFlags);
}
@ -2873,7 +2874,8 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
}
void
nsCSSRendering::PaintBackgroundColorWithSC(nsPresContext* aPresContext,
nsCSSRendering::PaintBackgroundColorWithSC(gfxRGBA aColor,
nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsIFrame* aForFrame,
const nsRect& aDirtyRect,
@ -2903,11 +2905,11 @@ nsCSSRendering::PaintBackgroundColorWithSC(nsPresContext* aPresContext,
// background colors.
bool drawBackgroundImage;
bool drawBackgroundColor;
nscolor bgColor = DetermineBackgroundColor(aPresContext,
aBackgroundSC,
aForFrame,
drawBackgroundImage,
drawBackgroundColor);
DetermineBackgroundColor(aPresContext,
aBackgroundSC,
aForFrame,
drawBackgroundImage,
drawBackgroundColor);
NS_ASSERTION(drawBackgroundImage || drawBackgroundColor,
"Should not be trying to paint a background if we don't have one");
@ -2951,7 +2953,7 @@ nsCSSRendering::PaintBackgroundColorWithSC(nsPresContext* aPresContext,
aDirtyRect, haveRoundedCorners, bgRadii, appUnitsPerPixel,
&clipState);
ctx->SetColor(gfxRGBA(bgColor));
ctx->SetColor(aColor);
gfxContextAutoSaveRestore autoSR;
DrawBackgroundColor(clipState, ctx, haveRoundedCorners, appUnitsPerPixel);

View File

@ -495,8 +495,9 @@ struct nsCSSRendering {
uint32_t aFlags,
nsRect* aBGClipRect = nullptr,
int32_t aLayer = -1);
static void PaintBackgroundColor(nsPresContext* aPresContext,
static void PaintBackgroundColor(gfxRGBA aColor,
nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsIFrame* aForFrame,
const nsRect& aDirtyRect,
@ -523,7 +524,8 @@ struct nsCSSRendering {
nsRect* aBGClipRect = nullptr,
int32_t aLayer = -1);
static void PaintBackgroundColorWithSC(nsPresContext* aPresContext,
static void PaintBackgroundColorWithSC(gfxRGBA aColor,
nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsIFrame* aForFrame,
const nsRect& aDirtyRect,

View File

@ -2593,9 +2593,21 @@ nsDisplayThemedBackground::GetBoundsInternal() {
return r + ToReferenceFrame();
}
bool
nsDisplayBackgroundColor::ApplyOpacity(nsDisplayListBuilder* aBuilder,
float aOpacity,
const DisplayItemClip* aClip)
{
mColor.a = mColor.a * aOpacity;
if (aClip) {
IntersectClip(aBuilder, *aClip);
}
return true;
}
void
nsDisplayBackgroundColor::Paint(nsDisplayListBuilder* aBuilder,
nsRenderingContext* aCtx)
nsRenderingContext* aCtx)
{
if (mColor == NS_RGBA(0, 0, 0, 0)) {
return;
@ -2604,7 +2616,7 @@ nsDisplayBackgroundColor::Paint(nsDisplayListBuilder* aBuilder,
nsPoint offset = ToReferenceFrame();
uint32_t flags = aBuilder->GetBackgroundPaintFlags();
CheckForBorderItem(this, flags);
nsCSSRendering::PaintBackgroundColor(mFrame->PresContext(), *aCtx, mFrame,
nsCSSRendering::PaintBackgroundColor(mColor, mFrame->PresContext(), *aCtx, mFrame,
mVisibleRect,
nsRect(offset, mFrame->GetSize()),
flags);
@ -2612,9 +2624,9 @@ nsDisplayBackgroundColor::Paint(nsDisplayListBuilder* aBuilder,
nsRegion
nsDisplayBackgroundColor::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
bool* aSnap)
bool* aSnap)
{
if (NS_GET_A(mColor) != 255) {
if (mColor.a != 1) {
return nsRegion();
}
@ -2630,9 +2642,9 @@ nsDisplayBackgroundColor::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
}
bool
nsDisplayBackgroundColor::IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor)
nsDisplayBackgroundColor::IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor)
{
*aColor = mColor;
*aColor = NS_RGBA_FROM_GFXRGBA(mColor);
if (!mBackgroundStyle)
return true;
@ -2659,9 +2671,9 @@ nsDisplayBackgroundColor::HitTest(nsDisplayListBuilder* aBuilder,
void
nsDisplayBackgroundColor::WriteDebugInfo(nsACString& aTo)
{
aTo += nsPrintfCString(" (rgba %d,%d,%d,%d)",
NS_GET_R(mColor), NS_GET_G(mColor),
NS_GET_B(mColor), NS_GET_A(mColor));
aTo += nsPrintfCString(" (rgba %f,%f,%f,%f)",
mColor.r, mColor.g,
mColor.b, mColor.a);
}
#endif

View File

@ -2325,17 +2325,21 @@ public:
nscolor aColor)
: nsDisplayItem(aBuilder, aFrame)
, mBackgroundStyle(aBackgroundStyle)
, mColor(aColor)
, mColor(gfxRGBA(aColor))
{ }
virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) MOZ_OVERRIDE;
virtual nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
bool* aSnap) MOZ_OVERRIDE;
virtual bool IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor) MOZ_OVERRIDE;
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) MOZ_OVERRIDE;
virtual bool ApplyOpacity(nsDisplayListBuilder* aBuilder,
float aOpacity,
const DisplayItemClip* aClip) MOZ_OVERRIDE;
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE
{
*aSnap = true;
@ -2344,14 +2348,20 @@ public:
virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE
{
return new nsDisplayItemBoundsGeometry(this, aBuilder);
return new nsDisplaySolidColorGeometry(this, aBuilder,
NS_RGBA_FROM_GFXRGBA(mColor));
}
virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
const nsDisplayItemGeometry* aGeometry,
nsRegion* aInvalidRegion) MOZ_OVERRIDE
{
const nsDisplayItemBoundsGeometry* geometry = static_cast<const nsDisplayItemBoundsGeometry*>(aGeometry);
const nsDisplaySolidColorGeometry* geometry = static_cast<const nsDisplaySolidColorGeometry*>(aGeometry);
if (NS_RGBA_FROM_GFXRGBA(mColor) != geometry->mColor) {
bool dummy;
aInvalidRegion->Or(geometry->mBounds, GetBounds(aBuilder, &dummy));
return;
}
ComputeInvalidationRegionDifference(aBuilder, geometry, aInvalidRegion);
}
@ -2362,7 +2372,7 @@ public:
protected:
const nsStyleBackground* mBackgroundStyle;
nscolor mColor;
gfxRGBA mColor;
};
/**

View File

@ -11,7 +11,7 @@
#inner {
width: 380px;
height: 260px;
background-color: #7fff7f;
background-color: #66ff66;
}
</style>
</head>

View File

@ -7,7 +7,7 @@
width: 300px;
overflow:hidden;
border-radius:30px;
opacity: 0.5;
opacity: 0.6;
}
#inner {
width: 380px;

View File

@ -1719,7 +1719,7 @@ skip-if(B2G) == 751012-1a.html 751012-1-ref.html
skip-if(B2G) == 751012-1b.html 751012-1-ref.html
random-if(Android||(B2G&&browserIsRemote)) == 753329-1.html about:blank
== 758561-1.html 758561-1-ref.html
fuzzy-if(true,1,19) fails-if(d2d) random-if(Android&&AndroidVersion<15) == 759036-1.html 759036-1-ref.html
fuzzy-if(true,1,90) random-if(Android&&AndroidVersion<15) == 759036-1.html 759036-1-ref.html
fuzzy-if(true,17,5879) random-if(Android&&AndroidVersion<15) == 759036-2.html 759036-2-ref.html
random-if(Android&&AndroidVersion<15) == 776265-1a.html 776265-1-ref.html
== 776265-1b.html 776265-1-ref.html
@ -1778,7 +1778,7 @@ skip-if(B2G&&browserIsRemote) == 858803-1.html 858803-1-ref.html # bug 974780
random-if(B2G&&browserIsRemote) == 894931-1.html 894931-1-ref.html
== 897491-1.html 897491-1-ref.html
== 897491-2.html 897491-2-ref.html
fuzzy(1,10000) fuzzy-if(Android&&AndroidVersion>=15,5,10000) == 902330-1.html 902330-1-ref.html
fuzzy(2,10000) fuzzy-if(Android&&AndroidVersion>=15,5,10000) == 902330-1.html 902330-1-ref.html
fuzzy-if(Android,8,400) == 906199-1.html 906199-1-ref.html
== 921716-1.html 921716-1-ref.html
test-pref(layout.css.sticky.enabled,true) random-if(B2G&&browserIsRemote) == 926155-1.html 926155-1-ref.html