1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/opengl/X11TextureSourceOGL.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,104 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifdef GL_PROVIDER_GLX 1.10 + 1.11 +#include "X11TextureSourceOGL.h" 1.12 +#include "mozilla/layers/CompositorOGL.h" 1.13 +#include "gfxXlibSurface.h" 1.14 +#include "gfx2DGlue.h" 1.15 + 1.16 +using namespace mozilla; 1.17 +using namespace mozilla::layers; 1.18 +using namespace mozilla::gfx; 1.19 + 1.20 +X11TextureSourceOGL::X11TextureSourceOGL(CompositorOGL* aCompositor, gfxXlibSurface* aSurface) 1.21 + : mCompositor(aCompositor) 1.22 + , mSurface(aSurface) 1.23 + , mTexture(0) 1.24 +{ 1.25 +} 1.26 + 1.27 +X11TextureSourceOGL::~X11TextureSourceOGL() 1.28 +{ 1.29 + DeallocateDeviceData(); 1.30 +} 1.31 + 1.32 +void 1.33 +X11TextureSourceOGL::DeallocateDeviceData() 1.34 +{ 1.35 + if (mTexture) { 1.36 + if (gl() && gl()->MakeCurrent()) { 1.37 + gl::sGLXLibrary.ReleaseTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap()); 1.38 + gl()->fDeleteTextures(1, &mTexture); 1.39 + mTexture = 0; 1.40 + } 1.41 + } 1.42 +} 1.43 + 1.44 +void 1.45 +X11TextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter) 1.46 +{ 1.47 + gl()->fActiveTexture(aTextureUnit); 1.48 + 1.49 + if (!mTexture) { 1.50 + gl()->fGenTextures(1, &mTexture); 1.51 + 1.52 + gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture); 1.53 + 1.54 + gl::sGLXLibrary.BindTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap()); 1.55 + } else { 1.56 + gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture); 1.57 + gl::sGLXLibrary.UpdateTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap()); 1.58 + } 1.59 + 1.60 + ApplyFilterToBoundTexture(gl(), aFilter, LOCAL_GL_TEXTURE_2D); 1.61 +} 1.62 + 1.63 +IntSize 1.64 +X11TextureSourceOGL::GetSize() const 1.65 +{ 1.66 + return ToIntSize(mSurface->GetSize()); 1.67 +} 1.68 + 1.69 +SurfaceFormat 1.70 +X11TextureSourceOGL::GetFormat() const { 1.71 + gfxContentType type = mSurface->GetContentType(); 1.72 + return X11TextureSourceOGL::ContentTypeToSurfaceFormat(type); 1.73 +} 1.74 + 1.75 +void 1.76 +X11TextureSourceOGL::SetCompositor(Compositor* aCompositor) 1.77 +{ 1.78 + MOZ_ASSERT(!aCompositor || aCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL); 1.79 + if (mCompositor == aCompositor) { 1.80 + return; 1.81 + } 1.82 + DeallocateDeviceData(); 1.83 + mCompositor = static_cast<CompositorOGL*>(aCompositor); 1.84 +} 1.85 + 1.86 +gl::GLContext* 1.87 +X11TextureSourceOGL::gl() const 1.88 +{ 1.89 + return mCompositor ? mCompositor->gl() : nullptr; 1.90 +} 1.91 + 1.92 +SurfaceFormat 1.93 +X11TextureSourceOGL::ContentTypeToSurfaceFormat(gfxContentType aType) 1.94 +{ 1.95 + // X11 uses a switched format and the OGL compositor 1.96 + // doesn't support ALPHA / A8. 1.97 + switch (aType) { 1.98 + case gfxContentType::COLOR: 1.99 + return SurfaceFormat::R8G8B8X8; 1.100 + case gfxContentType::COLOR_ALPHA: 1.101 + return SurfaceFormat::R8G8B8A8; 1.102 + default: 1.103 + return SurfaceFormat::UNKNOWN; 1.104 + } 1.105 +} 1.106 + 1.107 +#endif