Line data Source code
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 : namespace mozilla {
14 : namespace widget {
15 : class CompositorWidget;
16 : } // namespace widget
17 : namespace gl {
18 :
19 : class GLContextEGL : public GLContext
20 : {
21 : friend class TextureImageEGL;
22 :
23 : static already_AddRefed<GLContextEGL>
24 : CreateGLContext(CreateContextFlags flags,
25 : const SurfaceCaps& caps,
26 : bool isOffscreen,
27 : EGLConfig config,
28 : EGLSurface surface,
29 : nsACString* const out_failureId);
30 :
31 : public:
32 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextEGL, override)
33 : GLContextEGL(CreateContextFlags flags,
34 : const SurfaceCaps& caps,
35 : bool isOffscreen,
36 : EGLConfig config,
37 : EGLSurface surface,
38 : EGLContext context);
39 :
40 : ~GLContextEGL();
41 :
42 0 : virtual GLContextType GetContextType() const override { return GLContextType::EGL; }
43 :
44 0 : static GLContextEGL* Cast(GLContext* gl) {
45 0 : MOZ_ASSERT(gl->GetContextType() == GLContextType::EGL);
46 0 : return static_cast<GLContextEGL*>(gl);
47 : }
48 :
49 : bool Init() override;
50 :
51 0 : virtual bool IsDoubleBuffered() const override {
52 0 : return mIsDoubleBuffered;
53 : }
54 :
55 0 : void SetIsDoubleBuffered(bool aIsDB) {
56 0 : mIsDoubleBuffered = aIsDB;
57 0 : }
58 :
59 0 : virtual bool IsANGLE() const override {
60 0 : return sEGLLibrary.IsANGLE();
61 : }
62 :
63 0 : virtual bool IsWARP() const override {
64 0 : return sEGLLibrary.IsWARP();
65 : }
66 :
67 : virtual bool BindTexImage() override;
68 :
69 : virtual bool ReleaseTexImage() override;
70 :
71 : void SetEGLSurfaceOverride(EGLSurface surf);
72 : EGLSurface GetEGLSurfaceOverride() {
73 : return mSurfaceOverride;
74 : }
75 :
76 : virtual bool MakeCurrentImpl(bool aForce) override;
77 :
78 : virtual bool IsCurrent() override;
79 :
80 : virtual bool RenewSurface(widget::CompositorWidget* aWidget) override;
81 :
82 : virtual void ReleaseSurface() override;
83 :
84 : virtual bool SetupLookupFunction() override;
85 :
86 : virtual bool SwapBuffers() override;
87 :
88 : virtual void GetWSIInfo(nsCString* const out) const override;
89 :
90 : // hold a reference to the given surface
91 : // for the lifetime of this context.
92 : void HoldSurface(gfxASurface* aSurf);
93 :
94 : EGLSurface GetEGLSurface() const {
95 : return mSurface;
96 : }
97 :
98 : EGLDisplay GetEGLDisplay() const {
99 : return sEGLLibrary.Display();
100 : }
101 :
102 : bool BindTex2DOffscreen(GLContext* aOffscreen);
103 : void UnbindTex2DOffscreen(GLContext* aOffscreen);
104 : void BindOffscreenFramebuffer();
105 :
106 : static already_AddRefed<GLContextEGL>
107 : CreateEGLPBufferOffscreenContext(CreateContextFlags flags,
108 : const gfx::IntSize& size,
109 : const SurfaceCaps& minCaps,
110 : nsACString* const out_FailureId);
111 :
112 : protected:
113 : friend class GLContextProviderEGL;
114 : friend class GLContextEGLFactory;
115 :
116 : public:
117 : const EGLConfig mConfig;
118 : protected:
119 : EGLSurface mSurface;
120 : public:
121 : const EGLContext mContext;
122 : protected:
123 : EGLSurface mSurfaceOverride;
124 : RefPtr<gfxASurface> mThebesSurface;
125 : bool mBound;
126 :
127 : bool mIsPBuffer;
128 : bool mIsDoubleBuffered;
129 : bool mCanBindToTexture;
130 : bool mShareWithEGLImage;
131 : bool mOwnsContext;
132 :
133 : static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(EGLConfig config,
134 : EGLenum bindToTextureFormat,
135 : gfx::IntSize& pbsize);
136 : };
137 :
138 : } // namespace gl
139 : } // namespace mozilla
140 :
141 : #endif // GLCONTEXTEGL_H_
|