|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "X11TextureHost.h" |
|
7 #include "mozilla/layers/BasicCompositor.h" |
|
8 #include "mozilla/layers/X11TextureSourceBasic.h" |
|
9 #ifdef GL_PROVIDER_GLX |
|
10 #include "mozilla/layers/CompositorOGL.h" |
|
11 #include "mozilla/layers/X11TextureSourceOGL.h" |
|
12 #endif |
|
13 #include "gfxXlibSurface.h" |
|
14 #include "gfx2DGlue.h" |
|
15 |
|
16 using namespace mozilla; |
|
17 using namespace mozilla::layers; |
|
18 using namespace mozilla::gfx; |
|
19 |
|
20 X11TextureHost::X11TextureHost(TextureFlags aFlags, |
|
21 const SurfaceDescriptorX11& aDescriptor) |
|
22 : TextureHost(aFlags) |
|
23 { |
|
24 nsRefPtr<gfxXlibSurface> surface = aDescriptor.OpenForeign(); |
|
25 mSurface = surface.get(); |
|
26 |
|
27 // The host always frees the pixmap. |
|
28 MOZ_ASSERT(!(aFlags & TEXTURE_DEALLOCATE_CLIENT)); |
|
29 mSurface->TakePixmap(); |
|
30 } |
|
31 |
|
32 bool |
|
33 X11TextureHost::Lock() |
|
34 { |
|
35 if (!mCompositor) { |
|
36 return false; |
|
37 } |
|
38 |
|
39 if (!mTextureSource) { |
|
40 switch (mCompositor->GetBackendType()) { |
|
41 case LayersBackend::LAYERS_BASIC: |
|
42 mTextureSource = |
|
43 new X11TextureSourceBasic(static_cast<BasicCompositor*>(mCompositor), |
|
44 mSurface); |
|
45 break; |
|
46 #ifdef GL_PROVIDER_GLX |
|
47 case LayersBackend::LAYERS_OPENGL: |
|
48 mTextureSource = |
|
49 new X11TextureSourceOGL(static_cast<CompositorOGL*>(mCompositor), |
|
50 mSurface); |
|
51 break; |
|
52 #endif |
|
53 default: |
|
54 return false; |
|
55 } |
|
56 } |
|
57 |
|
58 return true; |
|
59 } |
|
60 |
|
61 void |
|
62 X11TextureHost::SetCompositor(Compositor* aCompositor) |
|
63 { |
|
64 mCompositor = aCompositor; |
|
65 if (mTextureSource) { |
|
66 mTextureSource->SetCompositor(aCompositor); |
|
67 } |
|
68 } |
|
69 |
|
70 SurfaceFormat |
|
71 X11TextureHost::GetFormat() const |
|
72 { |
|
73 gfxContentType type = mSurface->GetContentType(); |
|
74 #ifdef GL_PROVIDER_GLX |
|
75 if (mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL) { |
|
76 return X11TextureSourceOGL::ContentTypeToSurfaceFormat(type); |
|
77 } |
|
78 #endif |
|
79 return X11TextureSourceBasic::ContentTypeToSurfaceFormat(type); |
|
80 } |
|
81 |
|
82 IntSize |
|
83 X11TextureHost::GetSize() const |
|
84 { |
|
85 return ToIntSize(mSurface->GetSize()); |
|
86 } |