Bug 1294857 - Compositor uses page's background color to clear in Fennec r=kats

This commit is contained in:
Randall Barker 2016-08-17 16:35:25 -07:00
parent 49a7faf599
commit a9be905342
6 changed files with 59 additions and 1 deletions

View File

@ -35,6 +35,13 @@ Compositor::Compositor(widget::CompositorWidget* aWidget,
, mScreenRotation(ROTATION_0)
, mWidget(aWidget)
, mIsDestroyed(false)
#if defined(MOZ_WIDGET_ANDROID)
// If the default color isn't white for Fennec, there is a black
// flash before the first page of a tab is loaded.
, mBeginFrameClearColor(1.0, 1.0, 1.0, 1.0)
#else
, mBeginFrameClearColor(0.0, 0.0, 0.0, 0.0)
#endif
{
}

View File

@ -349,6 +349,10 @@ public:
const gfx::IntRect& aClipRect = gfx::IntRect(),
const gfx::Matrix4x4& aTransform = gfx::Matrix4x4());
void SetBeginFrameClearColor(const gfx::Color& aColor) {
mBeginFrameClearColor = aColor;
}
/*
* Clear aRect on current render target.
*/
@ -634,6 +638,8 @@ protected:
FenceHandle mReleaseFenceHandle;
#endif
gfx::Color mBeginFrameClearColor;
private:
static LayersBackend sBackend;

View File

@ -150,6 +150,32 @@ LayerManager::GetScrollableLayers(nsTArray<Layer*>& aArray)
}
}
LayerMetricsWrapper
LayerManager::GetRootContentLayer()
{
if (!mRoot) {
return LayerMetricsWrapper();
}
nsTArray<Layer*> queue = { mRoot };
while (!queue.IsEmpty()) {
Layer* layer = queue[0];
queue.RemoveElementAt(0);
for (uint32_t i = 0; i < layer->GetScrollMetadataCount(); i++) {
if (layer->GetFrameMetrics(i).IsRootContent()) {
return LayerMetricsWrapper(layer, i);
}
}
for (Layer* child = layer->GetFirstChild(); child; child = child->GetNextSibling()) {
queue.AppendElement(child);
}
}
return LayerMetricsWrapper();
}
already_AddRefed<DrawTarget>
LayerManager::CreateOptimalDrawTarget(const gfx::IntSize &aSize,
SurfaceFormat aFormat)

View File

@ -354,6 +354,12 @@ public:
*/
void GetScrollableLayers(nsTArray<Layer*>& aArray);
/**
* Returns a LayerMetricsWrapper containing the Root
* Content Documents layer.
*/
LayerMetricsWrapper GetRootContentLayer();
/**
* CONSTRUCTION PHASE ONLY
* Called when a managee has mutated.

View File

@ -929,6 +929,12 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi
CompositorBench(mCompositor, bounds);
MOZ_ASSERT(mRoot->GetOpacity() == 1);
#if defined(MOZ_WIDGET_ANDROID)
LayerMetricsWrapper wrapper = GetRootContentLayer();
if (wrapper) {
mCompositor->SetBeginFrameClearColor(wrapper.Metadata().GetBackgroundColor());
}
#endif
if (mRoot->GetClipRect()) {
clipRect = *mRoot->GetClipRect();
IntRect rect(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
@ -996,6 +1002,13 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi
mCompositor->GetWidget()->PostRender(this);
RecordFrame();
#if defined(MOZ_WIDGET_ANDROID)
// Reset the clear color to white so that if a page is loaded with a different background
// color, the page will be white while the new page is loading instead of the background
// color of the previous page.
mCompositor->SetBeginFrameClearColor(gfx::Color(1.0, 1.0, 1.0, 1.0));
#endif
}
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)

View File

@ -707,7 +707,7 @@ CompositorOGL::BeginFrame(const nsIntRegion& aInvalidRegion,
aClipRectOut->SetRect(0, 0, width, height);
}
mGLContext->fClearColor(0.0, 0.0, 0.0, 0.0);
mGLContext->fClearColor(mBeginFrameClearColor.r, mBeginFrameClearColor.g, mBeginFrameClearColor.b, mBeginFrameClearColor.a);
mGLContext->fClear(LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT);
}