michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "X11TextureHost.h" michael@0: #include "mozilla/layers/BasicCompositor.h" michael@0: #include "mozilla/layers/X11TextureSourceBasic.h" michael@0: #ifdef GL_PROVIDER_GLX michael@0: #include "mozilla/layers/CompositorOGL.h" michael@0: #include "mozilla/layers/X11TextureSourceOGL.h" michael@0: #endif michael@0: #include "gfxXlibSurface.h" michael@0: #include "gfx2DGlue.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::layers; michael@0: using namespace mozilla::gfx; michael@0: michael@0: X11TextureHost::X11TextureHost(TextureFlags aFlags, michael@0: const SurfaceDescriptorX11& aDescriptor) michael@0: : TextureHost(aFlags) michael@0: { michael@0: nsRefPtr surface = aDescriptor.OpenForeign(); michael@0: mSurface = surface.get(); michael@0: michael@0: // The host always frees the pixmap. michael@0: MOZ_ASSERT(!(aFlags & TEXTURE_DEALLOCATE_CLIENT)); michael@0: mSurface->TakePixmap(); michael@0: } michael@0: michael@0: bool michael@0: X11TextureHost::Lock() michael@0: { michael@0: if (!mCompositor) { michael@0: return false; michael@0: } michael@0: michael@0: if (!mTextureSource) { michael@0: switch (mCompositor->GetBackendType()) { michael@0: case LayersBackend::LAYERS_BASIC: michael@0: mTextureSource = michael@0: new X11TextureSourceBasic(static_cast(mCompositor), michael@0: mSurface); michael@0: break; michael@0: #ifdef GL_PROVIDER_GLX michael@0: case LayersBackend::LAYERS_OPENGL: michael@0: mTextureSource = michael@0: new X11TextureSourceOGL(static_cast(mCompositor), michael@0: mSurface); michael@0: break; michael@0: #endif michael@0: default: michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: void michael@0: X11TextureHost::SetCompositor(Compositor* aCompositor) michael@0: { michael@0: mCompositor = aCompositor; michael@0: if (mTextureSource) { michael@0: mTextureSource->SetCompositor(aCompositor); michael@0: } michael@0: } michael@0: michael@0: SurfaceFormat michael@0: X11TextureHost::GetFormat() const michael@0: { michael@0: gfxContentType type = mSurface->GetContentType(); michael@0: #ifdef GL_PROVIDER_GLX michael@0: if (mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL) { michael@0: return X11TextureSourceOGL::ContentTypeToSurfaceFormat(type); michael@0: } michael@0: #endif michael@0: return X11TextureSourceBasic::ContentTypeToSurfaceFormat(type); michael@0: } michael@0: michael@0: IntSize michael@0: X11TextureHost::GetSize() const michael@0: { michael@0: return ToIntSize(mSurface->GetSize()); michael@0: }