Bug 1258768 - Check compositor backends before casting. r=dvander, a=kothari

This commit is contained in:
Nicolas Silva 2016-04-25 13:16:46 +02:00
parent 3d1031a6d5
commit b873957841
15 changed files with 164 additions and 49 deletions

View File

@ -127,6 +127,10 @@ class DataTextureSource;
class CompositingRenderTarget;
class CompositorParent;
class LayerManagerComposite;
class CompositorOGL;
class CompositorD3D9;
class CompositorD3D11;
class BasicCompositor;
enum SurfaceInitMode
{
@ -423,6 +427,11 @@ public:
virtual LayersBackend GetBackendType() const = 0;
virtual CompositorOGL* AsCompositorOGL() { return nullptr; }
virtual CompositorD3D9* AsCompositorD3D9() { return nullptr; }
virtual CompositorD3D11* AsCompositorD3D11() { return nullptr; }
virtual BasicCompositor* AsBasicCompositor() { return nullptr; }
/**
* Each Compositor has a unique ID.
* This ID is used to keep references to each Compositor in a map accessed

View File

@ -720,6 +720,14 @@ BasicCompositor::EndFrameForExternalComposition(const gfx::Matrix& aTransform)
mDidExternalComposition = true;
}
BasicCompositor*
AssertBasicCompositor(Compositor* aCompositor)
{
BasicCompositor* compositor = aCompositor ? aCompositor->AsBasicCompositor()
: nullptr;
MOZ_DIAGNOSTIC_ASSERT(!!compositor);
return compositor;
}
} // namespace layers
} // namespace mozilla

View File

@ -48,6 +48,9 @@ protected:
virtual ~BasicCompositor();
public:
virtual BasicCompositor* AsBasicCompositor() override { return this; }
virtual bool Initialize() override;
virtual void Destroy() override;
@ -142,6 +145,8 @@ private:
uint32_t mMaxTextureSize;
};
BasicCompositor* AssertBasicCompositor(Compositor* aCompositor);
} // namespace layers
} // namespace mozilla

View File

@ -180,7 +180,11 @@ GrallocTextureHostBasic::ClearTextureSource()
void
GrallocTextureHostBasic::SetCompositor(Compositor* aCompositor)
{
BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor);
BasicCompositor* compositor = AssertBasicCompositor(aCompositor);
if (!compositor) {
return;
}
mCompositor = compositor;
if (mTextureSource) {
mTextureSource->SetCompositor(compositor);

View File

@ -62,7 +62,7 @@ MacIOSurfaceTextureSourceBasic::GetSurface(gfx::DrawTarget* aTarget)
void
MacIOSurfaceTextureSourceBasic::SetCompositor(Compositor* aCompositor)
{
mCompositor = static_cast<BasicCompositor*>(aCompositor);
mCompositor = AssertBasicCompositor(aCompositor);
}
bool
@ -81,7 +81,11 @@ MacIOSurfaceTextureHostBasic::Lock()
void
MacIOSurfaceTextureHostBasic::SetCompositor(Compositor* aCompositor)
{
BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor);
BasicCompositor* compositor = AssertBasicCompositor(aCompositor);
if (!compositor) {
mTextureSource = nullptr;
return;
}
mCompositor = compositor;
if (mTextureSource) {
mTextureSource->SetCompositor(compositor);

View File

@ -45,9 +45,7 @@ X11TextureSourceBasic::GetSurface(DrawTarget* aTarget)
void
X11TextureSourceBasic::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor->GetBackendType() == LayersBackend::LAYERS_BASIC);
BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor);
mCompositor = compositor;
mCompositor = AssertBasicCompositor(aCompositor);
}
SurfaceFormat

View File

@ -45,6 +45,8 @@ public:
CompositorD3D11(CompositorParent* aParent, nsIWidget* aWidget);
~CompositorD3D11();
virtual CompositorD3D11* AsCompositorD3D11() override { return this; }
virtual bool Initialize() override;
virtual void Destroy() override {}

View File

@ -636,14 +636,29 @@ DXGITextureHostD3D11::GetDevice()
return gfxWindowsPlatform::GetPlatform()->GetD3D11Device();
}
static CompositorD3D11* AssertD3D11Compositor(Compositor* aCompositor)
{
CompositorD3D11* compositor = aCompositor ? aCompositor->AsCompositorD3D11()
: nullptr;
if (!compositor) {
gfxCriticalNote << "[D3D11] Attempt to set an incompatible compositor.";
}
return compositor;
}
void
DXGITextureHostD3D11::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
mCompositor = static_cast<CompositorD3D11*>(aCompositor);
if (mTextureSource) {
mTextureSource->SetCompositor(aCompositor);
}
CompositorD3D11* d3dCompositor = AssertD3D11Compositor(aCompositor);
if (!d3dCompositor) {
mCompositor = nullptr;
mTextureSource = nullptr;
return;
}
mCompositor = d3dCompositor;
if (mTextureSource) {
mTextureSource->SetCompositor(aCompositor);
}
}
bool
@ -747,9 +762,8 @@ DXGIYCbCrTextureHostD3D11::GetDevice()
void
DXGIYCbCrTextureHostD3D11::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
mCompositor = static_cast<CompositorD3D11*>(aCompositor);
if (mTextureSources[0]) {
mCompositor = AssertD3D11Compositor(aCompositor);
if (!mCompositor) {
mTextureSources[0]->SetCompositor(aCompositor);
}
}
@ -974,8 +988,11 @@ DataTextureSourceD3D11::GetTileRect()
void
DataTextureSourceD3D11::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
mCompositor = static_cast<CompositorD3D11*>(aCompositor);
CompositorD3D11* d3dCompositor = AssertD3D11Compositor(aCompositor);
if (!d3dCompositor) {
return;
}
mCompositor = d3dCompositor;
if (mNextSibling) {
mNextSibling->SetCompositor(aCompositor);
}

View File

@ -24,6 +24,8 @@ public:
CompositorD3D9(CompositorParent* aParent, nsIWidget *aWidget);
~CompositorD3D9();
virtual CompositorD3D9* AsCompositorD3D9() override { return this; }
virtual bool Initialize() override;
virtual void Destroy() override {}

View File

@ -493,11 +493,24 @@ DataTextureSourceD3D9::Update(gfx::DataSourceSurface* aSurface,
return true;
}
static CompositorD3D9* AssertD3D9Compositor(Compositor* aCompositor)
{
CompositorD3D9* compositor = aCompositor ? aCompositor->AsCompositorD3D9()
: nullptr;
if (!compositor) {
gfxCriticalNote << "[D3D9] Attempt to set an incompatible compositor";
}
return compositor;
}
void
DataTextureSourceD3D9::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
CompositorD3D9* d3dCompositor = static_cast<CompositorD3D9*>(aCompositor);
CompositorD3D9* d3dCompositor = AssertD3D9Compositor(aCompositor);
if (!d3dCompositor) {
Reset();
return;
}
if (mCompositor && mCompositor != d3dCompositor) {
Reset();
}
@ -910,7 +923,11 @@ TextureHostD3D9::GetDevice()
void
TextureHostD3D9::SetCompositor(Compositor* aCompositor)
{
mCompositor = static_cast<CompositorD3D9*>(aCompositor);
mCompositor = AssertD3D9Compositor(aCompositor);
if (!mCompositor) {
mTextureSource = nullptr;
return;
}
if (mTextureSource) {
mTextureSource->SetCompositor(aCompositor);
}
@ -1031,8 +1048,10 @@ DXGITextureHostD3D9::Unlock()
void
DXGITextureHostD3D9::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
mCompositor = static_cast<CompositorD3D9*>(aCompositor);
mCompositor = AssertD3D9Compositor(aCompositor);
if (!mCompositor) {
mTextureSource = nullptr;
}
}
void
@ -1066,8 +1085,12 @@ DXGIYCbCrTextureHostD3D9::GetDevice()
void
DXGIYCbCrTextureHostD3D9::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
mCompositor = static_cast<CompositorD3D9*>(aCompositor);
mCompositor = AssertD3D9Compositor(aCompositor);
if (!mCompositor) {
mTextureSources[0] = nullptr;
mTextureSources[1] = nullptr;
mTextureSources[2] = nullptr;
}
}
bool

View File

@ -201,6 +201,8 @@ protected:
virtual ~CompositorOGL();
public:
virtual CompositorOGL* AsCompositorOGL() override { return this; }
virtual already_AddRefed<DataTextureSource>
CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) override;

View File

@ -68,7 +68,13 @@ MacIOSurfaceTextureHostOGL::Lock()
void
MacIOSurfaceTextureHostOGL::SetCompositor(Compositor* aCompositor)
{
CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
CompositorOGL* glCompositor = AssertGLCompositor(aCompositor);
if (!glCompositor) {
mTextureSource = nullptr;
mCompositor = nullptr;
return;
}
if (mCompositor != glCompositor) {
// Cannot share GL texture identifiers across compositors.
mTextureSource = nullptr;
@ -141,8 +147,8 @@ MacIOSurfaceTextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilt
void
MacIOSurfaceTextureSourceOGL::SetCompositor(Compositor* aCompositor)
{
mCompositor = static_cast<CompositorOGL*>(aCompositor);
if (mNextSibling) {
mCompositor = AssertGLCompositor(aCompositor);
if (mCompositor && mNextSibling) {
mNextSibling->SetCompositor(aCompositor);
}
}

View File

@ -231,13 +231,25 @@ TextureImageTextureSourceOGL::CopyTo(const gfx::IntRect& aSourceRect,
dest->mTexImage->MarkValid();
}
CompositorOGL* AssertGLCompositor(Compositor* aCompositor)
{
CompositorOGL* compositor = aCompositor ? aCompositor->AsCompositorOGL()
: nullptr;
if (!compositor) {
gfxCriticalNote << "[GL] attempt to set an incompatible compositor.";
}
return compositor;
}
void
TextureImageTextureSourceOGL::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
if (!glCompositor || (mCompositor != glCompositor)) {
CompositorOGL* glCompositor = AssertGLCompositor(aCompositor);
if (!glCompositor) {
DeallocateDeviceData();
return;
}
if (mCompositor != glCompositor) {
DeallocateDeviceData();
mCompositor = glCompositor;
}
@ -340,13 +352,18 @@ GLTextureSource::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
void
GLTextureSource::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
if (mCompositor && mCompositor != aCompositor) {
gfxCriticalError() << "GLTextureSource does not support changing compositors";
CompositorOGL* glCompositor = AssertGLCompositor(aCompositor);
if (!glCompositor) {
return;
}
mCompositor = static_cast<CompositorOGL*>(aCompositor);
if (mCompositor && mCompositor != glCompositor) {
gfxCriticalNote << "GLTextureSource does not support changing compositors";
return;
}
mCompositor = glCompositor;
if (mNextSibling) {
mNextSibling->SetCompositor(aCompositor);
}
@ -408,12 +425,16 @@ SurfaceTextureSource::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
void
SurfaceTextureSource::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
if (mCompositor != aCompositor) {
CompositorOGL* glCompositor = AssertGLCompositor(aCompositor);
if (!glCompositor) {
DeallocateDeviceData();
return;
}
if (mCompositor != glCompositor) {
DeallocateDeviceData();
}
mCompositor = static_cast<CompositorOGL*>(aCompositor);
mCompositor = glCompositor;
}
bool
@ -500,8 +521,11 @@ SurfaceTextureHost::Unlock()
void
SurfaceTextureHost::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
CompositorOGL* glCompositor = AssertGLCompositor(aCompositor);
if (!glCompositor) {
DeallocateDeviceData();
return;
}
mCompositor = glCompositor;
if (mTextureSource) {
mTextureSource->SetCompositor(glCompositor);
@ -571,8 +595,7 @@ EGLImageTextureSource::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
void
EGLImageTextureSource::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
mCompositor = static_cast<CompositorOGL*>(aCompositor);
mCompositor = AssertGLCompositor(aCompositor);
}
bool
@ -662,8 +685,12 @@ EGLImageTextureHost::Unlock()
void
EGLImageTextureHost::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
CompositorOGL* glCompositor = AssertGLCompositor(aCompositor);
if (!glCompositor) {
mCompositor = nullptr;
mTextureSource = nullptr;
return;
}
mCompositor = glCompositor;
if (mTextureSource) {
mTextureSource->SetCompositor(glCompositor);
@ -733,8 +760,12 @@ GLTextureHost::Lock()
void
GLTextureHost::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
CompositorOGL* glCompositor = AssertGLCompositor(aCompositor);
if (!glCompositor) {
mCompositor = nullptr;
mTextureSource = nullptr;
return;
}
mCompositor = glCompositor;
if (mTextureSource) {
mTextureSource->SetCompositor(glCompositor);

View File

@ -521,6 +521,8 @@ protected:
RefPtr<EGLImageTextureSource> mTextureSource;
};
CompositorOGL* AssertGLCompositor(Compositor* aCompositor);
} // namespace layers
} // namespace mozilla

View File

@ -76,12 +76,14 @@ X11TextureSourceOGL::GetFormat() const {
void
X11TextureSourceOGL::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(!aCompositor || aCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
if (mCompositor == aCompositor) {
CompositorOGL* glCompositor = AssertGLCompositor(aCompositor);
if (mCompositor == glCompositor) {
return;
}
DeallocateDeviceData();
mCompositor = static_cast<CompositorOGL*>(aCompositor);
if (glCompositor) {
mCompositor = glCompositor;
}
}
gl::GLContext*