gfx/layers/opengl/CompositingRenderTargetOGL.h

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 #ifndef MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H
     7 #define MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H
     9 #include "GLContextTypes.h"             // for GLContext
    10 #include "GLDefs.h"                     // for GLenum, LOCAL_GL_FRAMEBUFFER, etc
    11 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
    12 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
    13 #include "mozilla/RefPtr.h"             // for RefPtr, TemporaryRef
    14 #include "mozilla/gfx/Point.h"          // for IntSize, IntSizeTyped
    15 #include "mozilla/gfx/Types.h"          // for SurfaceFormat, etc
    16 #include "mozilla/layers/Compositor.h"  // for SurfaceInitMode, etc
    17 #include "mozilla/layers/TextureHost.h" // for CompositingRenderTarget
    18 #include "mozilla/layers/CompositorOGL.h"  // for CompositorOGL
    19 #include "mozilla/mozalloc.h"           // for operator new
    20 #include "nsAString.h"
    21 #include "nsCOMPtr.h"                   // for already_AddRefed
    22 #include "nsDebug.h"                    // for NS_ERROR, NS_WARNING
    23 #include "nsString.h"                   // for nsAutoCString
    26 namespace mozilla {
    27 namespace gl {
    28   class BindableTexture;
    29 }
    30 namespace gfx {
    31   class DataSourceSurface;
    32 }
    34 namespace layers {
    36 class TextureSource;
    38 class CompositingRenderTargetOGL : public CompositingRenderTarget
    39 {
    40   typedef mozilla::gl::GLContext GLContext;
    42   // For lazy initialisation of the GL stuff
    43   struct InitParams
    44   {
    45     InitParams() : mStatus(NO_PARAMS) {}
    46     InitParams(const gfx::IntSize& aSize,
    47                GLenum aFBOTextureTarget,
    48                SurfaceInitMode aInit)
    49       : mStatus(READY)
    50       , mSize(aSize)
    51       , mFBOTextureTarget(aFBOTextureTarget)
    52       , mInit(aInit)
    53     {}
    55     enum {
    56       NO_PARAMS,
    57       READY,
    58       INITIALIZED
    59     } mStatus;
    60     gfx::IntSize mSize;
    61     GLenum mFBOTextureTarget;
    62     SurfaceInitMode mInit;
    63   };
    65 public:
    66   CompositingRenderTargetOGL(CompositorOGL* aCompositor, const gfx::IntPoint& aOrigin,
    67                              GLuint aTexure, GLuint aFBO)
    68     : CompositingRenderTarget(aOrigin)
    69     , mInitParams()
    70     , mTransform()
    71     , mCompositor(aCompositor)
    72     , mGL(aCompositor->gl())
    73     , mTextureHandle(aTexure)
    74     , mFBO(aFBO)
    75   {}
    77   ~CompositingRenderTargetOGL();
    79   /**
    80    * Create a render target around the default FBO, for rendering straight to
    81    * the window.
    82    */
    83   static TemporaryRef<CompositingRenderTargetOGL>
    84   RenderTargetForWindow(CompositorOGL* aCompositor,
    85                         const gfx::IntSize& aSize,
    86                         const gfx::Matrix& aTransform)
    87   {
    88     RefPtr<CompositingRenderTargetOGL> result
    89       = new CompositingRenderTargetOGL(aCompositor, gfx::IntPoint(0, 0), 0, 0);
    90     result->mTransform = aTransform;
    91     result->mInitParams = InitParams(aSize, 0, INIT_MODE_NONE);
    92     result->mInitParams.mStatus = InitParams::INITIALIZED;
    93     return result.forget();
    94   }
    96   /**
    97    * Some initialisation work on the backing FBO and texture.
    98    * We do this lazily so that when we first set this render target on the
    99    * compositor we do not have to re-bind the FBO after unbinding it, or
   100    * alternatively leave the FBO bound after creation.
   101    */
   102   void Initialize(const gfx::IntSize& aSize,
   103                   GLenum aFBOTextureTarget,
   104                   SurfaceInitMode aInit)
   105   {
   106     MOZ_ASSERT(mInitParams.mStatus == InitParams::NO_PARAMS, "Initialized twice?");
   107     // postpone initialization until we actually want to use this render target
   108     mInitParams = InitParams(aSize, aFBOTextureTarget, aInit);
   109   }
   111   void BindTexture(GLenum aTextureUnit, GLenum aTextureTarget);
   113   /**
   114    * Call when we want to draw into our FBO
   115    */
   116   void BindRenderTarget();
   118   GLuint GetFBO() const
   119   {
   120     MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
   121     return mFBO;
   122   }
   124   GLuint GetTextureHandle() const
   125   {
   126     MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
   127     return mTextureHandle;
   128   }
   130   // TextureSourceOGL
   131   TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE
   132   {
   133     // XXX - Bug 900770
   134     MOZ_ASSERT(false, "CompositingRenderTargetOGL should not be used as a TextureSource");
   135     return nullptr;
   136   }
   137   gfx::IntSize GetSize() const MOZ_OVERRIDE
   138   {
   139     // XXX - Bug 900770
   140     MOZ_ASSERT(false, "CompositingRenderTargetOGL should not be used as a TextureSource");
   141     return gfx::IntSize(0, 0);
   142   }
   144   gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
   145   {
   146     // XXX - Should it be implemented ? is the above assert true ?
   147     MOZ_ASSERT(false, "Not implemented");
   148     return gfx::SurfaceFormat::UNKNOWN;
   149   }
   151   const gfx::Matrix& GetTransform() {
   152     return mTransform;
   153   }
   155 #ifdef MOZ_DUMP_PAINTING
   156   virtual TemporaryRef<gfx::DataSourceSurface> Dump(Compositor* aCompositor);
   157 #endif
   159 private:
   160   /**
   161    * Actually do the initialisation. Note that we leave our FBO bound, and so
   162    * calling this method is only suitable when about to use this render target.
   163    */
   164   void InitializeImpl();
   166   InitParams mInitParams;
   167   gfx::Matrix mTransform;
   168   CompositorOGL* mCompositor;
   169   GLContext* mGL;
   170   GLuint mTextureHandle;
   171   GLuint mFBO;
   172 };
   174 }
   175 }
   177 #endif /* MOZILLA_GFX_SURFACEOGL_H */

mercurial