|
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/. */ |
|
5 |
|
6 #include "GLManager.h" |
|
7 #include "CompositorOGL.h" // for CompositorOGL |
|
8 #include "GLContext.h" // for GLContext |
|
9 #include "mozilla/Assertions.h" // for MOZ_CRASH |
|
10 #include "mozilla/Attributes.h" // for MOZ_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 #include "nsAutoPtr.h" // for nsRefPtr |
|
17 |
|
18 using namespace mozilla::gl; |
|
19 |
|
20 namespace mozilla { |
|
21 namespace layers { |
|
22 |
|
23 class GLManagerCompositor : public GLManager |
|
24 { |
|
25 public: |
|
26 GLManagerCompositor(CompositorOGL* aCompositor) |
|
27 : mImpl(aCompositor) |
|
28 {} |
|
29 |
|
30 virtual GLContext* gl() const MOZ_OVERRIDE |
|
31 { |
|
32 return mImpl->gl(); |
|
33 } |
|
34 |
|
35 virtual ShaderProgramOGL* GetProgram(GLenum aTarget, gfx::SurfaceFormat aFormat) MOZ_OVERRIDE |
|
36 { |
|
37 ShaderConfigOGL config = ShaderConfigFromTargetAndFormat(aTarget, aFormat); |
|
38 return mImpl->GetShaderProgramFor(config); |
|
39 } |
|
40 |
|
41 virtual const gfx::Matrix4x4& GetProjMatrix() const MOZ_OVERRIDE |
|
42 { |
|
43 return mImpl->GetProjMatrix(); |
|
44 } |
|
45 |
|
46 virtual void BindAndDrawQuad(ShaderProgramOGL *aProg) MOZ_OVERRIDE |
|
47 { |
|
48 mImpl->BindAndDrawQuad(aProg); |
|
49 } |
|
50 |
|
51 private: |
|
52 RefPtr<CompositorOGL> mImpl; |
|
53 }; |
|
54 |
|
55 /* static */ GLManager* |
|
56 GLManager::CreateGLManager(LayerManagerComposite* aManager) |
|
57 { |
|
58 if (aManager && |
|
59 Compositor::GetBackend() == LayersBackend::LAYERS_OPENGL) { |
|
60 return new GLManagerCompositor(static_cast<CompositorOGL*>( |
|
61 aManager->GetCompositor())); |
|
62 } |
|
63 return nullptr; |
|
64 } |
|
65 |
|
66 } |
|
67 } |