gfx/layers/opengl/X11TextureSourceOGL.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     6 #ifdef GL_PROVIDER_GLX
     8 #include "X11TextureSourceOGL.h"
     9 #include "mozilla/layers/CompositorOGL.h"
    10 #include "gfxXlibSurface.h"
    11 #include "gfx2DGlue.h"
    13 using namespace mozilla;
    14 using namespace mozilla::layers;
    15 using namespace mozilla::gfx;
    17 X11TextureSourceOGL::X11TextureSourceOGL(CompositorOGL* aCompositor, gfxXlibSurface* aSurface)
    18   : mCompositor(aCompositor)
    19   , mSurface(aSurface)
    20   , mTexture(0)
    21 {
    22 }
    24 X11TextureSourceOGL::~X11TextureSourceOGL()
    25 {
    26   DeallocateDeviceData();
    27 }
    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 }
    41 void
    42 X11TextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
    43 {
    44   gl()->fActiveTexture(aTextureUnit);
    46   if (!mTexture) {
    47     gl()->fGenTextures(1, &mTexture);
    49     gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
    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   }
    57   ApplyFilterToBoundTexture(gl(), aFilter, LOCAL_GL_TEXTURE_2D);
    58 }
    60 IntSize
    61 X11TextureSourceOGL::GetSize() const
    62 {
    63   return ToIntSize(mSurface->GetSize());
    64 }
    66 SurfaceFormat
    67 X11TextureSourceOGL::GetFormat() const {
    68   gfxContentType type = mSurface->GetContentType();
    69   return X11TextureSourceOGL::ContentTypeToSurfaceFormat(type);
    70 }
    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 }
    83 gl::GLContext*
    84 X11TextureSourceOGL::gl() const
    85 {
    86   return mCompositor ? mCompositor->gl() : nullptr;
    87 }
    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 }
   104 #endif

mercurial