/src/mozilla-central/gfx/layers/opengl/X11TextureSourceOGL.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "X11TextureSourceOGL.h" |
8 | | #include "gfxXlibSurface.h" |
9 | | #include "gfx2DGlue.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace layers { |
13 | | |
14 | | using namespace mozilla::gfx; |
15 | | |
16 | | X11TextureSourceOGL::X11TextureSourceOGL(CompositorOGL* aCompositor, gfxXlibSurface* aSurface) |
17 | | : mGL(aCompositor->gl()) |
18 | | , mSurface(aSurface) |
19 | | , mTexture(0) |
20 | | , mUpdated(false) |
21 | 0 | { |
22 | 0 | } |
23 | | |
24 | | X11TextureSourceOGL::~X11TextureSourceOGL() |
25 | 0 | { |
26 | 0 | DeallocateDeviceData(); |
27 | 0 | } |
28 | | |
29 | | void |
30 | | X11TextureSourceOGL::DeallocateDeviceData() |
31 | 0 | { |
32 | 0 | if (mTexture) { |
33 | 0 | if (gl() && gl()->MakeCurrent()) { |
34 | 0 | gl::sGLXLibrary.ReleaseTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap()); |
35 | 0 | gl()->fDeleteTextures(1, &mTexture); |
36 | 0 | mTexture = 0; |
37 | 0 | } |
38 | 0 | } |
39 | 0 | } |
40 | | |
41 | | void |
42 | | X11TextureSourceOGL::BindTexture(GLenum aTextureUnit, |
43 | | gfx::SamplingFilter aSamplingFilter) |
44 | 0 | { |
45 | 0 | gl()->fActiveTexture(aTextureUnit); |
46 | 0 |
|
47 | 0 | if (!mTexture) { |
48 | 0 | gl()->fGenTextures(1, &mTexture); |
49 | 0 |
|
50 | 0 | gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture); |
51 | 0 |
|
52 | 0 | gl::sGLXLibrary.BindTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap()); |
53 | 0 | } else { |
54 | 0 | gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture); |
55 | 0 | if (mUpdated) { |
56 | 0 | gl::sGLXLibrary.UpdateTexImage(mSurface->XDisplay(), mSurface->GetGLXPixmap()); |
57 | 0 | mUpdated = false; |
58 | 0 | } |
59 | 0 | } |
60 | 0 |
|
61 | 0 | ApplySamplingFilterToBoundTexture(gl(), aSamplingFilter, LOCAL_GL_TEXTURE_2D); |
62 | 0 | } |
63 | | |
64 | | IntSize |
65 | | X11TextureSourceOGL::GetSize() const |
66 | 0 | { |
67 | 0 | return mSurface->GetSize(); |
68 | 0 | } |
69 | | |
70 | | SurfaceFormat |
71 | 0 | X11TextureSourceOGL::GetFormat() const { |
72 | 0 | gfxContentType type = mSurface->GetContentType(); |
73 | 0 | return X11TextureSourceOGL::ContentTypeToSurfaceFormat(type); |
74 | 0 | } |
75 | | |
76 | | void |
77 | | X11TextureSourceOGL::SetTextureSourceProvider(TextureSourceProvider* aProvider) |
78 | 0 | { |
79 | 0 | gl::GLContext* newGL = aProvider ? aProvider->GetGLContext() : nullptr; |
80 | 0 | if (mGL != newGL) { |
81 | 0 | DeallocateDeviceData(); |
82 | 0 | } |
83 | 0 | mGL = newGL; |
84 | 0 | } |
85 | | |
86 | | SurfaceFormat |
87 | | X11TextureSourceOGL::ContentTypeToSurfaceFormat(gfxContentType aType) |
88 | | { |
89 | | // X11 uses a switched format and the OGL compositor |
90 | | // doesn't support ALPHA / A8. |
91 | | switch (aType) { |
92 | | case gfxContentType::COLOR: |
93 | | return SurfaceFormat::R8G8B8X8; |
94 | | case gfxContentType::COLOR_ALPHA: |
95 | | return SurfaceFormat::R8G8B8A8; |
96 | | default: |
97 | | return SurfaceFormat::UNKNOWN; |
98 | | } |
99 | | } |
100 | | |
101 | | } |
102 | | } |
103 | | |