1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/composite/X11TextureHost.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 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 +#include "X11TextureHost.h" 1.10 +#include "mozilla/layers/BasicCompositor.h" 1.11 +#include "mozilla/layers/X11TextureSourceBasic.h" 1.12 +#ifdef GL_PROVIDER_GLX 1.13 +#include "mozilla/layers/CompositorOGL.h" 1.14 +#include "mozilla/layers/X11TextureSourceOGL.h" 1.15 +#endif 1.16 +#include "gfxXlibSurface.h" 1.17 +#include "gfx2DGlue.h" 1.18 + 1.19 +using namespace mozilla; 1.20 +using namespace mozilla::layers; 1.21 +using namespace mozilla::gfx; 1.22 + 1.23 +X11TextureHost::X11TextureHost(TextureFlags aFlags, 1.24 + const SurfaceDescriptorX11& aDescriptor) 1.25 + : TextureHost(aFlags) 1.26 +{ 1.27 + nsRefPtr<gfxXlibSurface> surface = aDescriptor.OpenForeign(); 1.28 + mSurface = surface.get(); 1.29 + 1.30 + // The host always frees the pixmap. 1.31 + MOZ_ASSERT(!(aFlags & TEXTURE_DEALLOCATE_CLIENT)); 1.32 + mSurface->TakePixmap(); 1.33 +} 1.34 + 1.35 +bool 1.36 +X11TextureHost::Lock() 1.37 +{ 1.38 + if (!mCompositor) { 1.39 + return false; 1.40 + } 1.41 + 1.42 + if (!mTextureSource) { 1.43 + switch (mCompositor->GetBackendType()) { 1.44 + case LayersBackend::LAYERS_BASIC: 1.45 + mTextureSource = 1.46 + new X11TextureSourceBasic(static_cast<BasicCompositor*>(mCompositor), 1.47 + mSurface); 1.48 + break; 1.49 +#ifdef GL_PROVIDER_GLX 1.50 + case LayersBackend::LAYERS_OPENGL: 1.51 + mTextureSource = 1.52 + new X11TextureSourceOGL(static_cast<CompositorOGL*>(mCompositor), 1.53 + mSurface); 1.54 + break; 1.55 +#endif 1.56 + default: 1.57 + return false; 1.58 + } 1.59 + } 1.60 + 1.61 + return true; 1.62 +} 1.63 + 1.64 +void 1.65 +X11TextureHost::SetCompositor(Compositor* aCompositor) 1.66 +{ 1.67 + mCompositor = aCompositor; 1.68 + if (mTextureSource) { 1.69 + mTextureSource->SetCompositor(aCompositor); 1.70 + } 1.71 +} 1.72 + 1.73 +SurfaceFormat 1.74 +X11TextureHost::GetFormat() const 1.75 +{ 1.76 + gfxContentType type = mSurface->GetContentType(); 1.77 +#ifdef GL_PROVIDER_GLX 1.78 + if (mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL) { 1.79 + return X11TextureSourceOGL::ContentTypeToSurfaceFormat(type); 1.80 + } 1.81 +#endif 1.82 + return X11TextureSourceBasic::ContentTypeToSurfaceFormat(type); 1.83 +} 1.84 + 1.85 +IntSize 1.86 +X11TextureHost::GetSize() const 1.87 +{ 1.88 + return ToIntSize(mSurface->GetSize()); 1.89 +}