gfx/layers/opengl/CompositingRenderTargetOGL.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/opengl/CompositingRenderTargetOGL.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,177 @@
     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 +#ifndef MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H
    1.10 +#define MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H
    1.11 +
    1.12 +#include "GLContextTypes.h"             // for GLContext
    1.13 +#include "GLDefs.h"                     // for GLenum, LOCAL_GL_FRAMEBUFFER, etc
    1.14 +#include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
    1.15 +#include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
    1.16 +#include "mozilla/RefPtr.h"             // for RefPtr, TemporaryRef
    1.17 +#include "mozilla/gfx/Point.h"          // for IntSize, IntSizeTyped
    1.18 +#include "mozilla/gfx/Types.h"          // for SurfaceFormat, etc
    1.19 +#include "mozilla/layers/Compositor.h"  // for SurfaceInitMode, etc
    1.20 +#include "mozilla/layers/TextureHost.h" // for CompositingRenderTarget
    1.21 +#include "mozilla/layers/CompositorOGL.h"  // for CompositorOGL
    1.22 +#include "mozilla/mozalloc.h"           // for operator new
    1.23 +#include "nsAString.h"
    1.24 +#include "nsCOMPtr.h"                   // for already_AddRefed
    1.25 +#include "nsDebug.h"                    // for NS_ERROR, NS_WARNING
    1.26 +#include "nsString.h"                   // for nsAutoCString
    1.27 +
    1.28 +
    1.29 +namespace mozilla {
    1.30 +namespace gl {
    1.31 +  class BindableTexture;
    1.32 +}
    1.33 +namespace gfx {
    1.34 +  class DataSourceSurface;
    1.35 +}
    1.36 +
    1.37 +namespace layers {
    1.38 +
    1.39 +class TextureSource;
    1.40 +
    1.41 +class CompositingRenderTargetOGL : public CompositingRenderTarget
    1.42 +{
    1.43 +  typedef mozilla::gl::GLContext GLContext;
    1.44 +
    1.45 +  // For lazy initialisation of the GL stuff
    1.46 +  struct InitParams
    1.47 +  {
    1.48 +    InitParams() : mStatus(NO_PARAMS) {}
    1.49 +    InitParams(const gfx::IntSize& aSize,
    1.50 +               GLenum aFBOTextureTarget,
    1.51 +               SurfaceInitMode aInit)
    1.52 +      : mStatus(READY)
    1.53 +      , mSize(aSize)
    1.54 +      , mFBOTextureTarget(aFBOTextureTarget)
    1.55 +      , mInit(aInit)
    1.56 +    {}
    1.57 +
    1.58 +    enum {
    1.59 +      NO_PARAMS,
    1.60 +      READY,
    1.61 +      INITIALIZED
    1.62 +    } mStatus;
    1.63 +    gfx::IntSize mSize;
    1.64 +    GLenum mFBOTextureTarget;
    1.65 +    SurfaceInitMode mInit;
    1.66 +  };
    1.67 +
    1.68 +public:
    1.69 +  CompositingRenderTargetOGL(CompositorOGL* aCompositor, const gfx::IntPoint& aOrigin,
    1.70 +                             GLuint aTexure, GLuint aFBO)
    1.71 +    : CompositingRenderTarget(aOrigin)
    1.72 +    , mInitParams()
    1.73 +    , mTransform()
    1.74 +    , mCompositor(aCompositor)
    1.75 +    , mGL(aCompositor->gl())
    1.76 +    , mTextureHandle(aTexure)
    1.77 +    , mFBO(aFBO)
    1.78 +  {}
    1.79 +
    1.80 +  ~CompositingRenderTargetOGL();
    1.81 +
    1.82 +  /**
    1.83 +   * Create a render target around the default FBO, for rendering straight to
    1.84 +   * the window.
    1.85 +   */
    1.86 +  static TemporaryRef<CompositingRenderTargetOGL>
    1.87 +  RenderTargetForWindow(CompositorOGL* aCompositor,
    1.88 +                        const gfx::IntSize& aSize,
    1.89 +                        const gfx::Matrix& aTransform)
    1.90 +  {
    1.91 +    RefPtr<CompositingRenderTargetOGL> result
    1.92 +      = new CompositingRenderTargetOGL(aCompositor, gfx::IntPoint(0, 0), 0, 0);
    1.93 +    result->mTransform = aTransform;
    1.94 +    result->mInitParams = InitParams(aSize, 0, INIT_MODE_NONE);
    1.95 +    result->mInitParams.mStatus = InitParams::INITIALIZED;
    1.96 +    return result.forget();
    1.97 +  }
    1.98 +
    1.99 +  /**
   1.100 +   * Some initialisation work on the backing FBO and texture.
   1.101 +   * We do this lazily so that when we first set this render target on the
   1.102 +   * compositor we do not have to re-bind the FBO after unbinding it, or
   1.103 +   * alternatively leave the FBO bound after creation.
   1.104 +   */
   1.105 +  void Initialize(const gfx::IntSize& aSize,
   1.106 +                  GLenum aFBOTextureTarget,
   1.107 +                  SurfaceInitMode aInit)
   1.108 +  {
   1.109 +    MOZ_ASSERT(mInitParams.mStatus == InitParams::NO_PARAMS, "Initialized twice?");
   1.110 +    // postpone initialization until we actually want to use this render target
   1.111 +    mInitParams = InitParams(aSize, aFBOTextureTarget, aInit);
   1.112 +  }
   1.113 +
   1.114 +  void BindTexture(GLenum aTextureUnit, GLenum aTextureTarget);
   1.115 +
   1.116 +  /**
   1.117 +   * Call when we want to draw into our FBO
   1.118 +   */
   1.119 +  void BindRenderTarget();
   1.120 +
   1.121 +  GLuint GetFBO() const
   1.122 +  {
   1.123 +    MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
   1.124 +    return mFBO;
   1.125 +  }
   1.126 +
   1.127 +  GLuint GetTextureHandle() const
   1.128 +  {
   1.129 +    MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
   1.130 +    return mTextureHandle;
   1.131 +  }
   1.132 +
   1.133 +  // TextureSourceOGL
   1.134 +  TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE
   1.135 +  {
   1.136 +    // XXX - Bug 900770
   1.137 +    MOZ_ASSERT(false, "CompositingRenderTargetOGL should not be used as a TextureSource");
   1.138 +    return nullptr;
   1.139 +  }
   1.140 +  gfx::IntSize GetSize() const MOZ_OVERRIDE
   1.141 +  {
   1.142 +    // XXX - Bug 900770
   1.143 +    MOZ_ASSERT(false, "CompositingRenderTargetOGL should not be used as a TextureSource");
   1.144 +    return gfx::IntSize(0, 0);
   1.145 +  }
   1.146 +
   1.147 +  gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
   1.148 +  {
   1.149 +    // XXX - Should it be implemented ? is the above assert true ?
   1.150 +    MOZ_ASSERT(false, "Not implemented");
   1.151 +    return gfx::SurfaceFormat::UNKNOWN;
   1.152 +  }
   1.153 +
   1.154 +  const gfx::Matrix& GetTransform() {
   1.155 +    return mTransform;
   1.156 +  }
   1.157 +
   1.158 +#ifdef MOZ_DUMP_PAINTING
   1.159 +  virtual TemporaryRef<gfx::DataSourceSurface> Dump(Compositor* aCompositor);
   1.160 +#endif
   1.161 +
   1.162 +private:
   1.163 +  /**
   1.164 +   * Actually do the initialisation. Note that we leave our FBO bound, and so
   1.165 +   * calling this method is only suitable when about to use this render target.
   1.166 +   */
   1.167 +  void InitializeImpl();
   1.168 +
   1.169 +  InitParams mInitParams;
   1.170 +  gfx::Matrix mTransform;
   1.171 +  CompositorOGL* mCompositor;
   1.172 +  GLContext* mGL;
   1.173 +  GLuint mTextureHandle;
   1.174 +  GLuint mFBO;
   1.175 +};
   1.176 +
   1.177 +}
   1.178 +}
   1.179 +
   1.180 +#endif /* MOZILLA_GFX_SURFACEOGL_H */

mercurial