1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "GLManager.h"
8 #include "CompositorOGL.h"              // for CompositorOGL
9 #include "GLContext.h"                  // for GLContext
10 #include "mozilla/Attributes.h"         // for override
11 #include "mozilla/RefPtr.h"             // for RefPtr
12 #include "mozilla/layers/Compositor.h"  // for Compositor
13 #include "mozilla/layers/LayerManagerComposite.h"
14 #include "mozilla/layers/LayersTypes.h"
15 #include "mozilla/mozalloc.h"  // for operator new, etc
16 
17 using namespace mozilla::gl;
18 
19 namespace mozilla {
20 namespace layers {
21 
22 class GLManagerCompositor : public GLManager {
23  public:
GLManagerCompositor(CompositorOGL * aCompositor)24   explicit GLManagerCompositor(CompositorOGL* aCompositor)
25       : mImpl(aCompositor) {}
26 
gl() const27   virtual GLContext* gl() const override { return mImpl->gl(); }
28 
ActivateProgram(ShaderProgramOGL * aProg)29   virtual void ActivateProgram(ShaderProgramOGL* aProg) override {
30     mImpl->ActivateProgram(aProg);
31   }
32 
GetProgram(GLenum aTarget,gfx::SurfaceFormat aFormat)33   virtual ShaderProgramOGL* GetProgram(GLenum aTarget,
34                                        gfx::SurfaceFormat aFormat) override {
35     ShaderConfigOGL config = ShaderConfigFromTargetAndFormat(aTarget, aFormat);
36     return mImpl->GetShaderProgramFor(config);
37   }
38 
GetProjMatrix() const39   virtual const gfx::Matrix4x4& GetProjMatrix() const override {
40     return mImpl->GetProjMatrix();
41   }
42 
BindAndDrawQuad(ShaderProgramOGL * aProg,const gfx::Rect & aLayerRect,const gfx::Rect & aTextureRect)43   virtual void BindAndDrawQuad(ShaderProgramOGL* aProg,
44                                const gfx::Rect& aLayerRect,
45                                const gfx::Rect& aTextureRect) override {
46     mImpl->BindAndDrawQuad(aProg, aLayerRect, aTextureRect);
47   }
48 
49  private:
50   RefPtr<CompositorOGL> mImpl;
51 };
52 
CreateGLManager(LayerManagerComposite * aManager)53 /* static */ GLManager* GLManager::CreateGLManager(
54     LayerManagerComposite* aManager) {
55   if (aManager && aManager->GetCompositor()->GetBackendType() ==
56                       LayersBackend::LAYERS_OPENGL) {
57     return new GLManagerCompositor(
58         aManager->GetCompositor()->AsCompositorOGL());
59   }
60   return nullptr;
61 }
62 
63 }  // namespace layers
64 }  // namespace mozilla
65