gfx/layers/opengl/X11TextureSourceOGL.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial