Files
firefox/gfx/layers/composite/CompositableHost.cpp
T
sotaro eb2d5e90e3 Bug 1354411 - Rebuild CompositorSessions if WebRender is disabled r=kats
When WebRender creation is failed, WebRender is disabled in gecko. There is a case that WebRenderBridgeParents exist when WebRender is disabled. To handle this, gecko needs to rebuild all CompositorSessions.

There is also a problem related to gfxVars::UseWebRender on compositor thread. If e10s is enabled, but no-gpu process(default on linux and mac), gfxVars::UseWebRender change is soon notified by compositor thread tasks. If WebRender creation failure happens at 2nd WebRender creation, several WebRenderBridgeParents for 1st WebRender could exist. IPC messages from WebRenderLayerManager are normally async, then there is a chance that the WebRenderBridgeParents receive the messages after the gfxVars::UseWebRender change. Further the gfxVars::UseWebRender change in content process could be delayed than WebRenderBridgeParents, then content process does not have a way to stop sending PWebRenderBridge IPC until the change of gfxVars::UseWebRender is received. WebRenderBridgeParent related tasks handle the message, but some tasks are done based on gfxVars::UseWebRender. At this time, gfxVars::UseWebRender returned false on compositor thread, then it cause unexpected result for WebRenderBridgeParent and WebRender. To addres this inconsistent situation, WebRenderBridgeParent related tasks on compositor thread stop to use gfxVars::UseWebRender.
2017-08-04 14:36:41 +09:00

185 lines
5.0 KiB
C++

/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "CompositableHost.h"
#include <map> // for _Rb_tree_iterator, map, etc
#include <utility> // for pair
#include "ContentHost.h" // for ContentHostDoubleBuffered, etc
#include "Effects.h" // for EffectMask, Effect, etc
#include "gfxUtils.h"
#include "ImageHost.h" // for ImageHostBuffered, etc
#include "TiledContentHost.h" // for TiledContentHost
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
#include "mozilla/layers/TextureHost.h" // for TextureHost, etc
#include "mozilla/layers/WebRenderImageHost.h"
#include "mozilla/RefPtr.h" // for nsRefPtr
#include "nsDebug.h" // for NS_WARNING
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
#include "gfxPlatform.h" // for gfxPlatform
#include "IPDLActor.h"
namespace mozilla {
using namespace gfx;
namespace layers {
class Compositor;
CompositableHost::CompositableHost(const TextureInfo& aTextureInfo)
: mTextureInfo(aTextureInfo)
, mCompositorBridgeID(0)
, mLayer(nullptr)
, mFlashCounter(0)
, mAttached(false)
, mKeepAttached(false)
{
MOZ_COUNT_CTOR(CompositableHost);
}
CompositableHost::~CompositableHost()
{
MOZ_COUNT_DTOR(CompositableHost);
}
void
CompositableHost::UseTextureHost(const nsTArray<TimedTexture>& aTextures)
{
if (mTextureSourceProvider) {
for (auto& texture : aTextures) {
texture.mTexture->SetTextureSourceProvider(mTextureSourceProvider);
}
}
}
void
CompositableHost::UseComponentAlphaTextures(TextureHost* aTextureOnBlack,
TextureHost* aTextureOnWhite)
{
MOZ_ASSERT(aTextureOnBlack && aTextureOnWhite);
if (mTextureSourceProvider) {
aTextureOnBlack->SetTextureSourceProvider(mTextureSourceProvider);
aTextureOnWhite->SetTextureSourceProvider(mTextureSourceProvider);
}
}
void
CompositableHost::RemoveTextureHost(TextureHost* aTexture)
{}
void
CompositableHost::SetTextureSourceProvider(TextureSourceProvider* aProvider)
{
MOZ_ASSERT(aProvider);
mTextureSourceProvider = aProvider;
}
bool
CompositableHost::AddMaskEffect(EffectChain& aEffects,
const gfx::Matrix4x4& aTransform)
{
CompositableTextureSourceRef source;
RefPtr<TextureHost> host = GetAsTextureHost();
if (!host) {
NS_WARNING("Using compositable with no valid TextureHost as mask");
return false;
}
if (!host->Lock()) {
NS_WARNING("Failed to lock the mask texture");
return false;
}
if (!host->BindTextureSource(source)) {
NS_WARNING("The TextureHost was successfully locked but can't provide a TextureSource");
host->Unlock();
return false;
}
MOZ_ASSERT(source);
RefPtr<EffectMask> effect = new EffectMask(source,
source->GetSize(),
aTransform);
aEffects.mSecondaryEffects[EffectTypes::MASK] = effect;
return true;
}
void
CompositableHost::RemoveMaskEffect()
{
RefPtr<TextureHost> host = GetAsTextureHost();
if (host) {
host->Unlock();
}
}
/* static */ already_AddRefed<CompositableHost>
CompositableHost::Create(const TextureInfo& aTextureInfo, bool aUseWebRender)
{
RefPtr<CompositableHost> result;
switch (aTextureInfo.mCompositableType) {
case CompositableType::IMAGE_BRIDGE:
NS_ERROR("Cannot create an image bridge compositable this way");
break;
case CompositableType::CONTENT_TILED:
result = new TiledContentHost(aTextureInfo);
break;
case CompositableType::IMAGE:
if (aUseWebRender) {
result = new WebRenderImageHost(aTextureInfo);
} else {
result = new ImageHost(aTextureInfo);
}
break;
case CompositableType::CONTENT_SINGLE:
if (aUseWebRender) {
result = new WebRenderImageHost(aTextureInfo);
} else {
result = new ContentHostSingleBuffered(aTextureInfo);
}
break;
case CompositableType::CONTENT_DOUBLE:
MOZ_ASSERT(!aUseWebRender);
result = new ContentHostDoubleBuffered(aTextureInfo);
break;
default:
NS_ERROR("Unknown CompositableType");
}
return result.forget();
}
void
CompositableHost::DumpTextureHost(std::stringstream& aStream, TextureHost* aTexture)
{
if (!aTexture) {
return;
}
RefPtr<gfx::DataSourceSurface> dSurf = aTexture->GetAsSurface();
if (!dSurf) {
return;
}
aStream << gfxUtils::GetAsDataURI(dSurf).get();
}
HostLayerManager*
CompositableHost::GetLayerManager() const
{
if (!mLayer || !mLayer->Manager()) {
return nullptr;
}
return mLayer->Manager()->AsHostLayerManager();
}
TextureSourceProvider*
CompositableHost::GetTextureSourceProvider() const
{
return mTextureSourceProvider;
}
} // namespace layers
} // namespace mozilla