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