Bug 874721. Fallback for EnsureAllocated and compositor, and some more sanity checks. r=mattwoodrow

This commit is contained in:
Nicholas Cameron 2013-08-01 16:52:36 +12:00
parent 068a3c90a4
commit 9d09b0b60d
19 changed files with 113 additions and 54 deletions

View File

@ -2208,14 +2208,19 @@ TabChild::InitRenderingState()
if (id != 0) {
// Pushing layers transactions directly to a separate
// compositor context.
PCompositorChild* compositorChild = CompositorChild::Get();
PCompositorChild* compositorChild = CompositorChild::Get();
if (!compositorChild) {
NS_WARNING("failed to get CompositorChild instance");
return false;
}
bool success;
shadowManager =
compositorChild->SendPLayerTransactionConstructor(mTextureFactoryIdentifier.mParentBackend,
id, &mTextureFactoryIdentifier);
id, &mTextureFactoryIdentifier, &success);
if (!success) {
NS_WARNING("failed to properly allocate layer transaction");
return false;
}
} else {
// Pushing transactions to the parent content.
shadowManager = remoteFrame->SendPLayerTransactionConstructor();

View File

@ -104,7 +104,8 @@ enum DeprecatedTextureClientType
TEXTURE_SHARED_GL_EXTERNAL, // GLContext::SharedTextureHandle, the ownership of
// the SurfaceDescriptor passed to the texture
// remains with whoever passed it.
TEXTURE_STREAM_GL // WebGL streaming buffer
TEXTURE_STREAM_GL, // WebGL streaming buffer
TEXTURE_FALLBACK // A fallback path appropriate for the platform
};
/**

View File

@ -64,8 +64,16 @@ CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
gfxASurface::gfxContentType contentType = isOpaque
? gfxASurface::CONTENT_COLOR
: gfxASurface::CONTENT_COLOR_ALPHA;
mDeprecatedTextureClient->EnsureAllocated(aSize, contentType);
if (!mDeprecatedTextureClient->EnsureAllocated(aSize, contentType)) {
mDeprecatedTextureClient = CreateDeprecatedTextureClient(TEXTURE_FALLBACK);
if (!mDeprecatedTextureClient ||
!mDeprecatedTextureClient->EnsureAllocated(aSize, contentType)) {
NS_WARNING("Could not update texture, even with fallback texture client");
return;
}
}
gfxASurface* surface = mDeprecatedTextureClient->LockSurface();
aLayer->UpdateSurface(surface);
mDeprecatedTextureClient->Unlock();

View File

@ -134,6 +134,13 @@ CompositableClient::CreateDeprecatedTextureClient(DeprecatedTextureClientType aD
case TEXTURE_SHMEM:
result = new DeprecatedTextureClientShmem(GetForwarder(), GetTextureInfo());
break;
case TEXTURE_FALLBACK:
#ifdef XP_WIN
if (parentBackend == LAYERS_D3D9) {
result = new DeprecatedTextureClientShmem(GetForwarder(), GetTextureInfo());
}
#endif
break;
default:
MOZ_ASSERT(false, "Unhandled texture client type");
}

View File

@ -139,6 +139,25 @@ ContentClientRemoteBuffer::EndPaint()
}
}
bool
ContentClientRemoteBuffer::CreateAndAllocateDeprecatedTextureClient(RefPtr<DeprecatedTextureClient>& aClient)
{
aClient = CreateDeprecatedTextureClient(TEXTURE_CONTENT);
MOZ_ASSERT(aClient, "Failed to create texture client");
if (!aClient->EnsureAllocated(mSize, mContentType)) {
aClient = CreateDeprecatedTextureClient(TEXTURE_FALLBACK);
MOZ_ASSERT(aClient, "Failed to create texture client");
if (!aClient->EnsureAllocated(mSize, mContentType)) {
NS_WARNING("Could not allocate texture client");
return false;
}
}
MOZ_ASSERT(IsSurfaceDescriptorValid(*aClient->GetDescriptor()));
return true;
}
void
ContentClientRemoteBuffer::BuildDeprecatedTextureClients(ContentType aType,
const nsIntRect& aRect,
@ -156,22 +175,20 @@ ContentClientRemoteBuffer::BuildDeprecatedTextureClients(ContentType aType,
}
DestroyBuffers();
}
mTextureInfo.mTextureFlags = aFlags | TEXTURE_DEALLOCATE_HOST;
mDeprecatedTextureClient = CreateDeprecatedTextureClient(TEXTURE_CONTENT);
MOZ_ASSERT(mDeprecatedTextureClient, "Failed to create texture client");
if (aFlags & BUFFER_COMPONENT_ALPHA) {
mDeprecatedTextureClientOnWhite = CreateDeprecatedTextureClient(TEXTURE_CONTENT);
MOZ_ASSERT(mDeprecatedTextureClientOnWhite, "Failed to create texture client");
mTextureInfo.mTextureFlags |= ComponentAlpha;
}
mContentType = aType;
mSize = gfx::IntSize(aRect.width, aRect.height);
mDeprecatedTextureClient->EnsureAllocated(mSize, mContentType);
MOZ_ASSERT(IsSurfaceDescriptorValid(*mDeprecatedTextureClient->GetDescriptor()));
if (mDeprecatedTextureClientOnWhite) {
mDeprecatedTextureClientOnWhite->EnsureAllocated(mSize, mContentType);
MOZ_ASSERT(IsSurfaceDescriptorValid(*mDeprecatedTextureClientOnWhite->GetDescriptor()));
mTextureInfo.mTextureFlags = aFlags | TEXTURE_DEALLOCATE_HOST;
if (!CreateAndAllocateDeprecatedTextureClient(mDeprecatedTextureClient)) {
return;
}
if (aFlags & BUFFER_COMPONENT_ALPHA) {
if (!CreateAndAllocateDeprecatedTextureClient(mDeprecatedTextureClientOnWhite)) {
return;
}
mTextureInfo.mTextureFlags |= ComponentAlpha;
}
CreateFrontBufferAndNotify(aRect);
@ -284,18 +301,18 @@ ContentClientDoubleBuffered::~ContentClientDoubleBuffered()
void
ContentClientDoubleBuffered::CreateFrontBufferAndNotify(const nsIntRect& aBufferRect)
{
mFrontClient = CreateDeprecatedTextureClient(TEXTURE_CONTENT);
MOZ_ASSERT(mFrontClient, "Failed to create texture client");
mFrontClient->EnsureAllocated(mSize, mContentType);
if (!CreateAndAllocateDeprecatedTextureClient(mFrontClient)) {
return;
}
if (mTextureInfo.mTextureFlags & ComponentAlpha) {
if (!CreateAndAllocateDeprecatedTextureClient(mFrontClientOnWhite)) {
return;
}
}
mFrontBufferRect = aBufferRect;
mFrontBufferRotation = nsIntPoint();
if (mTextureInfo.mTextureFlags & ComponentAlpha) {
mFrontClientOnWhite = CreateDeprecatedTextureClient(TEXTURE_CONTENT);
MOZ_ASSERT(mFrontClientOnWhite, "Failed to create texture client");
mFrontClientOnWhite->EnsureAllocated(mSize, mContentType);
}
mForwarder->CreatedDoubleBuffer(this,
*mFrontClient->GetDescriptor(),

View File

@ -253,6 +253,8 @@ protected:
// lock it now.
virtual void LockFrontBuffer() {}
bool CreateAndAllocateDeprecatedTextureClient(RefPtr<DeprecatedTextureClient>& aClient);
RefPtr<DeprecatedTextureClient> mDeprecatedTextureClient;
RefPtr<DeprecatedTextureClient> mDeprecatedTextureClientOnWhite;
// keep a record of texture clients we have created and need to keep

View File

@ -276,7 +276,7 @@ DeprecatedTextureClientShmem::ReleaseResources()
}
}
void
bool
DeprecatedTextureClientShmem::EnsureAllocated(gfx::IntSize aSize,
gfxASurface::gfxContentType aContentType)
{
@ -293,6 +293,7 @@ DeprecatedTextureClientShmem::EnsureAllocated(gfx::IntSize aSize,
NS_WARNING("creating SurfaceDescriptor failed!");
}
}
return true;
}
void
@ -404,11 +405,12 @@ DeprecatedTextureClientShmemYCbCr::SetDescriptorFromReply(const SurfaceDescripto
}
}
void
bool
DeprecatedTextureClientShmemYCbCr::EnsureAllocated(gfx::IntSize aSize,
gfxASurface::gfxContentType aType)
{
NS_RUNTIMEABORT("not enough arguments to do this (need both Y and CbCr sizes)");
return false;
}
@ -420,7 +422,7 @@ DeprecatedTextureClientTile::DeprecatedTextureClientTile(CompositableForwarder*
mTextureInfo.mDeprecatedTextureHostFlags = TEXTURE_HOST_TILED;
}
void
bool
DeprecatedTextureClientTile::EnsureAllocated(gfx::IntSize aSize, gfxASurface::gfxContentType aType)
{
if (!mSurface ||
@ -431,6 +433,7 @@ DeprecatedTextureClientTile::EnsureAllocated(gfx::IntSize aSize, gfxASurface::gf
mSurface = new gfxReusableSurfaceWrapper(tmpTile);
mContentType = aType;
}
return true;
}
gfxImageSurface*

View File

@ -359,8 +359,9 @@ public:
/**
* Ensure that the texture client is suitable for the given size and content
* type and that any initialisation has taken place.
* Returns true if succeeded, false if failed.
*/
virtual void EnsureAllocated(gfx::IntSize aSize,
virtual bool EnsureAllocated(gfx::IntSize aSize,
gfxASurface::gfxContentType aType) = 0;
/**
@ -427,13 +428,13 @@ public:
virtual bool SupportsType(DeprecatedTextureClientType aType) MOZ_OVERRIDE
{
return aType == TEXTURE_SHMEM || aType == TEXTURE_CONTENT;
return aType == TEXTURE_SHMEM || aType == TEXTURE_CONTENT || aType == TEXTURE_FALLBACK;
}
virtual gfxImageSurface* LockImageSurface() MOZ_OVERRIDE;
virtual gfxASurface* LockSurface() MOZ_OVERRIDE { return GetSurface(); }
virtual gfx::DrawTarget* LockDrawTarget();
virtual void Unlock() MOZ_OVERRIDE;
virtual void EnsureAllocated(gfx::IntSize aSize, gfxASurface::gfxContentType aType) MOZ_OVERRIDE;
virtual bool EnsureAllocated(gfx::IntSize aSize, gfxASurface::gfxContentType aType) MOZ_OVERRIDE;
virtual void ReleaseResources() MOZ_OVERRIDE;
virtual void SetDescriptor(const SurfaceDescriptor& aDescriptor) MOZ_OVERRIDE;
@ -461,7 +462,7 @@ public:
~DeprecatedTextureClientShmemYCbCr() { ReleaseResources(); }
virtual bool SupportsType(DeprecatedTextureClientType aType) MOZ_OVERRIDE { return aType == TEXTURE_YCBCR; }
void EnsureAllocated(gfx::IntSize aSize, gfxASurface::gfxContentType aType) MOZ_OVERRIDE;
bool EnsureAllocated(gfx::IntSize aSize, gfxASurface::gfxContentType aType) MOZ_OVERRIDE;
virtual void SetDescriptorFromReply(const SurfaceDescriptor& aDescriptor) MOZ_OVERRIDE;
virtual void SetDescriptor(const SurfaceDescriptor& aDescriptor) MOZ_OVERRIDE;
virtual void ReleaseResources();
@ -476,7 +477,7 @@ public:
const TextureInfo& aTextureInfo);
~DeprecatedTextureClientTile();
virtual void EnsureAllocated(gfx::IntSize aSize,
virtual bool EnsureAllocated(gfx::IntSize aSize,
gfxASurface::gfxContentType aType) MOZ_OVERRIDE;
virtual gfxImageSurface* LockImageSurface() MOZ_OVERRIDE;

View File

@ -86,6 +86,7 @@ LayerManagerComposite::ClearCachedResources(Layer* aSubtree)
LayerManagerComposite::LayerManagerComposite(Compositor* aCompositor)
: mCompositor(aCompositor)
{
MOZ_ASSERT(aCompositor);
}
LayerManagerComposite::~LayerManagerComposite()

View File

@ -77,7 +77,7 @@ DeprecatedTextureClientD3D11::~DeprecatedTextureClientD3D11()
ClearDT();
}
void
bool
DeprecatedTextureClientD3D11::EnsureAllocated(gfx::IntSize aSize,
gfxASurface::gfxContentType aType)
{
@ -87,7 +87,7 @@ DeprecatedTextureClientD3D11::EnsureAllocated(gfx::IntSize aSize,
mTexture->GetDesc(&desc);
if (desc.Width == aSize.width && desc.Height == aSize.height) {
return;
return true;
}
mTexture = nullptr;
@ -109,7 +109,7 @@ DeprecatedTextureClientD3D11::EnsureAllocated(gfx::IntSize aSize,
if (FAILED(hr)) {
LOGD3D11("Error creating texture for client!");
return;
return false;
}
RefPtr<IDXGIResource> resource;
@ -126,6 +126,7 @@ DeprecatedTextureClientD3D11::EnsureAllocated(gfx::IntSize aSize,
aType == gfxASurface::CONTENT_COLOR_ALPHA);
mContentType = aType;
return true;
}
gfxASurface*

View File

@ -77,7 +77,7 @@ public:
return aType == TEXTURE_CONTENT;
}
virtual void EnsureAllocated(gfx::IntSize aSize,
virtual bool EnsureAllocated(gfx::IntSize aSize,
gfxASurface::gfxContentType aType) MOZ_OVERRIDE;
virtual gfxASurface* LockSurface() MOZ_OVERRIDE;

View File

@ -73,7 +73,8 @@ CompositorChild::Get()
PLayerTransactionChild*
CompositorChild::AllocPLayerTransactionChild(const LayersBackend& aBackendHint,
const uint64_t& aId,
TextureFactoryIdentifier*)
TextureFactoryIdentifier*,
bool*)
{
return new LayerTransactionChild();
}

View File

@ -41,7 +41,8 @@ protected:
virtual PLayerTransactionChild*
AllocPLayerTransactionChild(const LayersBackend& aBackendHint,
const uint64_t& aId,
TextureFactoryIdentifier* aTextureFactoryIdentifier) MOZ_OVERRIDE;
TextureFactoryIdentifier* aTextureFactoryIdentifier,
bool* aSuccess) MOZ_OVERRIDE;
virtual bool DeallocPLayerTransactionChild(PLayerTransactionChild *aChild) MOZ_OVERRIDE;

View File

@ -604,7 +604,8 @@ CompositorParent::ShadowLayersUpdated(LayerTransactionParent* aLayerTree,
PLayerTransactionParent*
CompositorParent::AllocPLayerTransactionParent(const LayersBackend& aBackendHint,
const uint64_t& aId,
TextureFactoryIdentifier* aTextureFactoryIdentifier)
TextureFactoryIdentifier* aTextureFactoryIdentifier,
bool *aSuccess)
{
MOZ_ASSERT(aId == 0);
@ -631,21 +632,24 @@ CompositorParent::AllocPLayerTransactionParent(const LayersBackend& aBackendHint
new LayerManagerComposite(new CompositorD3D9(mWidget));
#endif
} else {
NS_ERROR("Unsupported backend selected for Async Compositor");
return nullptr;
NS_WARNING("Unsupported backend selected for Async Compositor");
*aSuccess = false;
return new LayerTransactionParent(nullptr, this, 0);
}
mWidget = nullptr;
mLayerManager->SetCompositorID(mCompositorID);
if (!mLayerManager->Initialize()) {
NS_ERROR("Failed to init Compositor");
return nullptr;
NS_WARNING("Failed to init Compositor");
*aSuccess = false;
return new LayerTransactionParent(nullptr, this, 0);
}
mCompositionManager = new AsyncCompositionManager(mLayerManager);
*aTextureFactoryIdentifier = mLayerManager->GetTextureFactoryIdentifier();
*aSuccess = true;
return new LayerTransactionParent(mLayerManager, this, 0);
}
@ -835,7 +839,8 @@ public:
virtual PLayerTransactionParent*
AllocPLayerTransactionParent(const LayersBackend& aBackendType,
const uint64_t& aId,
TextureFactoryIdentifier* aTextureFactoryIdentifier) MOZ_OVERRIDE;
TextureFactoryIdentifier* aTextureFactoryIdentifier,
bool *aSuccess) MOZ_OVERRIDE;
virtual bool DeallocPLayerTransactionParent(PLayerTransactionParent* aLayers) MOZ_OVERRIDE;
@ -916,17 +921,20 @@ CrossProcessCompositorParent::ActorDestroy(ActorDestroyReason aWhy)
PLayerTransactionParent*
CrossProcessCompositorParent::AllocPLayerTransactionParent(const LayersBackend& aBackendType,
const uint64_t& aId,
TextureFactoryIdentifier* aTextureFactoryIdentifier)
TextureFactoryIdentifier* aTextureFactoryIdentifier,
bool *aSuccess)
{
MOZ_ASSERT(aId != 0);
if (sIndirectLayerTrees[aId].mParent) {
LayerManagerComposite* lm = sIndirectLayerTrees[aId].mParent->GetLayerManager();
*aTextureFactoryIdentifier = lm->GetTextureFactoryIdentifier();
*aSuccess = true;
return new LayerTransactionParent(lm, this, aId);
}
NS_WARNING("Created child without a matching parent?");
*aSuccess = false;
return new LayerTransactionParent(nullptr, this, aId);
}

View File

@ -208,7 +208,8 @@ protected:
virtual PLayerTransactionParent*
AllocPLayerTransactionParent(const LayersBackend& aBackendHint,
const uint64_t& aId,
TextureFactoryIdentifier* aTextureFactoryIdentifier);
TextureFactoryIdentifier* aTextureFactoryIdentifier,
bool* aSuccess);
virtual bool DeallocPLayerTransactionParent(PLayerTransactionParent* aLayers);
virtual void ScheduleTask(CancelableTask*, int);
virtual void Composite();

View File

@ -60,7 +60,7 @@ parent:
sync FlushRendering();
sync PLayerTransaction(LayersBackend layersBackendHint, uint64_t id)
returns (TextureFactoryIdentifier textureFactoryIdentifier);
returns (TextureFactoryIdentifier textureFactoryIdentifier, bool success);
};
} // layers

View File

@ -78,11 +78,12 @@ DeprecatedTextureClientSharedOGL::ReleaseResources()
// care of this for us though.
}
void
bool
DeprecatedTextureClientSharedOGL::EnsureAllocated(gfx::IntSize aSize,
gfxASurface::gfxContentType aContentType)
{
mSize = aSize;
return true;
}

View File

@ -56,7 +56,7 @@ public:
~DeprecatedTextureClientSharedOGL() { ReleaseResources(); }
virtual bool SupportsType(DeprecatedTextureClientType aType) MOZ_OVERRIDE { return aType == TEXTURE_SHARED_GL; }
virtual void EnsureAllocated(gfx::IntSize aSize, gfxASurface::gfxContentType aType);
virtual bool EnsureAllocated(gfx::IntSize aSize, gfxASurface::gfxContentType aType);
virtual void ReleaseResources();
virtual gfxASurface::gfxContentType GetContentType() MOZ_OVERRIDE { return gfxASurface::CONTENT_COLOR_ALPHA; }
@ -88,7 +88,7 @@ public:
~DeprecatedTextureClientStreamOGL() { ReleaseResources(); }
virtual bool SupportsType(DeprecatedTextureClientType aType) MOZ_OVERRIDE { return aType == TEXTURE_STREAM_GL; }
virtual void EnsureAllocated(gfx::IntSize aSize, gfxASurface::gfxContentType aType) { }
virtual bool EnsureAllocated(gfx::IntSize aSize, gfxASurface::gfxContentType aType) { return true; }
virtual void ReleaseResources() { mDescriptor = SurfaceDescriptor(); }
virtual gfxASurface::gfxContentType GetContentType() MOZ_OVERRIDE { return gfxASurface::CONTENT_COLOR_ALPHA; }
};

View File

@ -947,10 +947,11 @@ void nsBaseWidget::CreateCompositor(int aWidth, int aHeight)
PLayerTransactionChild* shadowManager;
mozilla::layers::LayersBackend backendHint = GetPreferredCompositorBackend();
bool success;
shadowManager = mCompositorChild->SendPLayerTransactionConstructor(
backendHint, 0, &textureFactoryIdentifier);
backendHint, 0, &textureFactoryIdentifier, &success);
if (shadowManager) {
if (success) {
ShadowLayerForwarder* lf = lm->AsShadowForwarder();
if (!lf) {
delete lm;