|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* vim: set ts=8 sts=4 et sw=4 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 #ifndef GLCONTEXTEGL_H_ |
|
8 #define GLCONTEXTEGL_H_ |
|
9 |
|
10 #include "GLContext.h" |
|
11 #include "GLLibraryEGL.h" |
|
12 |
|
13 #ifdef MOZ_WIDGET_GONK |
|
14 #include "HwcComposer2D.h" |
|
15 #endif |
|
16 |
|
17 namespace mozilla { |
|
18 namespace gl { |
|
19 |
|
20 class GLContextEGL : public GLContext |
|
21 { |
|
22 friend class TextureImageEGL; |
|
23 |
|
24 static already_AddRefed<GLContextEGL> |
|
25 CreateGLContext(const SurfaceCaps& caps, |
|
26 GLContextEGL *shareContext, |
|
27 bool isOffscreen, |
|
28 EGLConfig config, |
|
29 EGLSurface surface); |
|
30 |
|
31 public: |
|
32 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextEGL) |
|
33 GLContextEGL(const SurfaceCaps& caps, |
|
34 GLContext* shareContext, |
|
35 bool isOffscreen, |
|
36 EGLConfig config, |
|
37 EGLSurface surface, |
|
38 EGLContext context); |
|
39 |
|
40 ~GLContextEGL(); |
|
41 |
|
42 virtual GLContextType GetContextType() const MOZ_OVERRIDE { return GLContextType::EGL; } |
|
43 |
|
44 static GLContextEGL* Cast(GLContext* gl) { |
|
45 MOZ_ASSERT(gl->GetContextType() == GLContextType::EGL); |
|
46 return static_cast<GLContextEGL*>(gl); |
|
47 } |
|
48 |
|
49 bool Init() MOZ_OVERRIDE; |
|
50 |
|
51 virtual bool IsDoubleBuffered() const MOZ_OVERRIDE { |
|
52 return mIsDoubleBuffered; |
|
53 } |
|
54 |
|
55 void SetIsDoubleBuffered(bool aIsDB) { |
|
56 mIsDoubleBuffered = aIsDB; |
|
57 } |
|
58 |
|
59 virtual bool SupportsRobustness() const MOZ_OVERRIDE { |
|
60 return sEGLLibrary.HasRobustness(); |
|
61 } |
|
62 |
|
63 virtual bool IsANGLE() const MOZ_OVERRIDE { |
|
64 return sEGLLibrary.IsANGLE(); |
|
65 } |
|
66 |
|
67 virtual bool BindTexImage() MOZ_OVERRIDE; |
|
68 |
|
69 virtual bool ReleaseTexImage() MOZ_OVERRIDE; |
|
70 |
|
71 void SetEGLSurfaceOverride(EGLSurface surf); |
|
72 |
|
73 virtual bool MakeCurrentImpl(bool aForce) MOZ_OVERRIDE; |
|
74 |
|
75 virtual bool IsCurrent() MOZ_OVERRIDE; |
|
76 |
|
77 virtual bool RenewSurface() MOZ_OVERRIDE; |
|
78 |
|
79 virtual void ReleaseSurface() MOZ_OVERRIDE; |
|
80 |
|
81 virtual bool SetupLookupFunction() MOZ_OVERRIDE; |
|
82 |
|
83 virtual bool SwapBuffers() MOZ_OVERRIDE; |
|
84 |
|
85 // hold a reference to the given surface |
|
86 // for the lifetime of this context. |
|
87 void HoldSurface(gfxASurface *aSurf); |
|
88 |
|
89 EGLContext GetEGLContext() { |
|
90 return mContext; |
|
91 } |
|
92 |
|
93 bool BindTex2DOffscreen(GLContext *aOffscreen); |
|
94 void UnbindTex2DOffscreen(GLContext *aOffscreen); |
|
95 void BindOffscreenFramebuffer(); |
|
96 |
|
97 static already_AddRefed<GLContextEGL> |
|
98 CreateEGLPixmapOffscreenContext(const gfxIntSize& size); |
|
99 |
|
100 static already_AddRefed<GLContextEGL> |
|
101 CreateEGLPBufferOffscreenContext(const gfxIntSize& size); |
|
102 |
|
103 protected: |
|
104 friend class GLContextProviderEGL; |
|
105 |
|
106 EGLConfig mConfig; |
|
107 EGLSurface mSurface; |
|
108 EGLSurface mSurfaceOverride; |
|
109 EGLContext mContext; |
|
110 nsRefPtr<gfxASurface> mThebesSurface; |
|
111 bool mBound; |
|
112 |
|
113 bool mIsPBuffer; |
|
114 bool mIsDoubleBuffered; |
|
115 bool mCanBindToTexture; |
|
116 bool mShareWithEGLImage; |
|
117 #ifdef MOZ_WIDGET_GONK |
|
118 nsRefPtr<HwcComposer2D> mHwc; |
|
119 #endif |
|
120 bool mOwnsContext; |
|
121 |
|
122 static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(EGLConfig config, |
|
123 EGLenum bindToTextureFormat, |
|
124 gfxIntSize& pbsize); |
|
125 }; |
|
126 |
|
127 } |
|
128 } |
|
129 |
|
130 #endif // GLCONTEXTEGL_H_ |