Bug 974709 - Use a separate texture for each X11TextureSource and keep the pixmap bound. r=nical

--HG--
extra : rebase_source : 06012985e185f517d8a807788e35ea1efcaf39d8
This commit is contained in:
Matt Woodrow 2014-02-22 22:22:43 +13:00
parent c44927f681
commit c304736b73
2 changed files with 39 additions and 13 deletions

View File

@ -15,24 +15,44 @@ using namespace mozilla::layers;
using namespace mozilla::gfx;
X11TextureSourceOGL::X11TextureSourceOGL(CompositorOGL* aCompositor, gfxXlibSurface* aSurface)
: mCompositor(aCompositor),
mSurface(aSurface)
: mCompositor(aCompositor)
, mSurface(aSurface)
, mTexture(0)
{
}
X11TextureSourceOGL::~X11TextureSourceOGL()
{
DeallocateDeviceData();
}
void
X11TextureSourceOGL::DeallocateDeviceData()
{
if (mTexture) {
if (gl() && gl()->MakeCurrent()) {
gl::sGLXLibrary.ReleaseTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap());
gl()->fDeleteTextures(1, &mTexture);
mTexture = 0;
}
}
}
void
X11TextureSourceOGL::BindTexture(GLenum aTextureUnit)
{
GLuint tex = mCompositor->GetTemporaryTexture(aTextureUnit);
gl()->fActiveTexture(aTextureUnit);
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, tex);
gl::sGLXLibrary.xBindTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap(),
LOCAL_GLX_FRONT_LEFT_EXT, NULL);
if (!mTexture) {
gl()->fGenTextures(1, &mTexture);
gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
gl::sGLXLibrary.BindTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap());
} else {
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
gl::sGLXLibrary.UpdateTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap());
}
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
}
@ -52,7 +72,11 @@ X11TextureSourceOGL::GetFormat() const {
void
X11TextureSourceOGL::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
MOZ_ASSERT(!aCompositor || aCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
if (mCompositor == aCompositor) {
return;
}
DeallocateDeviceData();
mCompositor = static_cast<CompositorOGL*>(aCompositor);
}

View File

@ -21,6 +21,7 @@ class X11TextureSourceOGL
{
public:
X11TextureSourceOGL(CompositorOGL* aCompositor, gfxXlibSurface* aSurface);
~X11TextureSourceOGL();
virtual X11TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE { return this; }
@ -35,7 +36,7 @@ public:
return LOCAL_GL_CLAMP_TO_EDGE;
}
virtual void DeallocateDeviceData() MOZ_OVERRIDE { }
virtual void DeallocateDeviceData() MOZ_OVERRIDE;
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
@ -44,8 +45,9 @@ public:
protected:
CompositorOGL* mCompositor;
RefPtr<gfxXlibSurface> mSurface;
nsRefPtr<gfxXlibSurface> mSurface;
RefPtr<gfx::SourceSurface> mSourceSurface;
GLuint mTexture;
};
} // namespace layers
@ -53,4 +55,4 @@ protected:
#endif
#endif // MOZILLA_GFX_X11TEXTURESOURCEOGL__H
#endif // MOZILLA_GFX_X11TEXTURESOURCEOGL__H