gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,114 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "MacIOSurfaceTextureHostOGL.h"
    1.10 +#include "mozilla/gfx/MacIOSurface.h"
    1.11 +#include "mozilla/layers/CompositorOGL.h"
    1.12 +#include "GLContextCGL.h"
    1.13 +
    1.14 +namespace mozilla {
    1.15 +namespace layers {
    1.16 +
    1.17 +MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL(TextureFlags aFlags,
    1.18 +                                                       const SurfaceDescriptorMacIOSurface& aDescriptor)
    1.19 +  : TextureHost(aFlags)
    1.20 +{
    1.21 +  mSurface = MacIOSurface::LookupSurface(aDescriptor.surface(),
    1.22 +                                         aDescriptor.scaleFactor(),
    1.23 +                                         aDescriptor.hasAlpha());
    1.24 +}
    1.25 +
    1.26 +bool
    1.27 +MacIOSurfaceTextureHostOGL::Lock()
    1.28 +{
    1.29 +  if (!mCompositor || !mSurface) {
    1.30 +    return false;
    1.31 +  }
    1.32 +
    1.33 +  if (!mTextureSource) {
    1.34 +    mTextureSource = new MacIOSurfaceTextureSourceOGL(mCompositor, mSurface);
    1.35 +  }
    1.36 +  return true;
    1.37 +}
    1.38 +
    1.39 +void
    1.40 +MacIOSurfaceTextureHostOGL::SetCompositor(Compositor* aCompositor)
    1.41 +{
    1.42 +  CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
    1.43 +  mCompositor = glCompositor;
    1.44 +  if (mTextureSource) {
    1.45 +    mTextureSource->SetCompositor(glCompositor);
    1.46 +  }
    1.47 +}
    1.48 +
    1.49 +gfx::SurfaceFormat
    1.50 +MacIOSurfaceTextureHostOGL::GetFormat() const {
    1.51 +  if (!mSurface) {
    1.52 +    return gfx::SurfaceFormat::UNKNOWN;
    1.53 +  }
    1.54 +  return mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::B8G8R8X8;
    1.55 +}
    1.56 +
    1.57 +gfx::IntSize
    1.58 +MacIOSurfaceTextureHostOGL::GetSize() const {
    1.59 +  if (!mSurface) {
    1.60 +    return gfx::IntSize();
    1.61 +  }
    1.62 +  return gfx::IntSize(mSurface->GetDevicePixelWidth(),
    1.63 +                      mSurface->GetDevicePixelHeight());
    1.64 +}
    1.65 +
    1.66 +MacIOSurfaceTextureSourceOGL::MacIOSurfaceTextureSourceOGL(
    1.67 +                                CompositorOGL* aCompositor,
    1.68 +                                MacIOSurface* aSurface)
    1.69 +  : mCompositor(aCompositor)
    1.70 +  , mSurface(aSurface)
    1.71 +{}
    1.72 +
    1.73 +MacIOSurfaceTextureSourceOGL::~MacIOSurfaceTextureSourceOGL()
    1.74 +{}
    1.75 +
    1.76 +gfx::IntSize
    1.77 +MacIOSurfaceTextureSourceOGL::GetSize() const
    1.78 +{
    1.79 +  return gfx::IntSize(mSurface->GetDevicePixelWidth(),
    1.80 +                      mSurface->GetDevicePixelHeight());
    1.81 +}
    1.82 +
    1.83 +gfx::SurfaceFormat
    1.84 +MacIOSurfaceTextureSourceOGL::GetFormat() const
    1.85 +{
    1.86 +  return mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::B8G8R8X8;
    1.87 +}
    1.88 +
    1.89 +void
    1.90 +MacIOSurfaceTextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
    1.91 +{
    1.92 +  if (!gl()) {
    1.93 +    NS_WARNING("Trying to bind a texture without a GLContext");
    1.94 +    return;
    1.95 +  }
    1.96 +  GLuint tex = mCompositor->GetTemporaryTexture(GetTextureTarget(), aTextureUnit);
    1.97 +
    1.98 +  gl()->fActiveTexture(aTextureUnit);
    1.99 +  gl()->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, tex);
   1.100 +  mSurface->CGLTexImageIOSurface2D(gl::GLContextCGL::Cast(gl())->GetCGLContext());
   1.101 +  ApplyFilterToBoundTexture(gl(), aFilter, LOCAL_GL_TEXTURE_RECTANGLE_ARB);
   1.102 +}
   1.103 +
   1.104 +void
   1.105 +MacIOSurfaceTextureSourceOGL::SetCompositor(Compositor* aCompositor)
   1.106 +{
   1.107 +  mCompositor = static_cast<CompositorOGL*>(aCompositor);
   1.108 +}
   1.109 +
   1.110 +gl::GLContext*
   1.111 +MacIOSurfaceTextureSourceOGL::gl() const
   1.112 +{
   1.113 +  return mCompositor ? mCompositor->gl() : nullptr;
   1.114 +}
   1.115 +
   1.116 +}
   1.117 +}

mercurial