gfx/layers/opengl/X11TextureSourceOGL.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:e229079df2b6
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 #ifdef GL_PROVIDER_GLX
7
8 #include "X11TextureSourceOGL.h"
9 #include "mozilla/layers/CompositorOGL.h"
10 #include "gfxXlibSurface.h"
11 #include "gfx2DGlue.h"
12
13 using namespace mozilla;
14 using namespace mozilla::layers;
15 using namespace mozilla::gfx;
16
17 X11TextureSourceOGL::X11TextureSourceOGL(CompositorOGL* aCompositor, gfxXlibSurface* aSurface)
18 : mCompositor(aCompositor)
19 , mSurface(aSurface)
20 , mTexture(0)
21 {
22 }
23
24 X11TextureSourceOGL::~X11TextureSourceOGL()
25 {
26 DeallocateDeviceData();
27 }
28
29 void
30 X11TextureSourceOGL::DeallocateDeviceData()
31 {
32 if (mTexture) {
33 if (gl() && gl()->MakeCurrent()) {
34 gl::sGLXLibrary.ReleaseTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap());
35 gl()->fDeleteTextures(1, &mTexture);
36 mTexture = 0;
37 }
38 }
39 }
40
41 void
42 X11TextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
43 {
44 gl()->fActiveTexture(aTextureUnit);
45
46 if (!mTexture) {
47 gl()->fGenTextures(1, &mTexture);
48
49 gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
50
51 gl::sGLXLibrary.BindTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap());
52 } else {
53 gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
54 gl::sGLXLibrary.UpdateTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap());
55 }
56
57 ApplyFilterToBoundTexture(gl(), aFilter, LOCAL_GL_TEXTURE_2D);
58 }
59
60 IntSize
61 X11TextureSourceOGL::GetSize() const
62 {
63 return ToIntSize(mSurface->GetSize());
64 }
65
66 SurfaceFormat
67 X11TextureSourceOGL::GetFormat() const {
68 gfxContentType type = mSurface->GetContentType();
69 return X11TextureSourceOGL::ContentTypeToSurfaceFormat(type);
70 }
71
72 void
73 X11TextureSourceOGL::SetCompositor(Compositor* aCompositor)
74 {
75 MOZ_ASSERT(!aCompositor || aCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
76 if (mCompositor == aCompositor) {
77 return;
78 }
79 DeallocateDeviceData();
80 mCompositor = static_cast<CompositorOGL*>(aCompositor);
81 }
82
83 gl::GLContext*
84 X11TextureSourceOGL::gl() const
85 {
86 return mCompositor ? mCompositor->gl() : nullptr;
87 }
88
89 SurfaceFormat
90 X11TextureSourceOGL::ContentTypeToSurfaceFormat(gfxContentType aType)
91 {
92 // X11 uses a switched format and the OGL compositor
93 // doesn't support ALPHA / A8.
94 switch (aType) {
95 case gfxContentType::COLOR:
96 return SurfaceFormat::R8G8B8X8;
97 case gfxContentType::COLOR_ALPHA:
98 return SurfaceFormat::R8G8B8A8;
99 default:
100 return SurfaceFormat::UNKNOWN;
101 }
102 }
103
104 #endif

mercurial