Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/gl/GLContextEGL.h
Line
Count
Source (jump to first uncovered line)
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
    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
0
    }
48
49
    bool Init() override;
50
51
0
    virtual bool IsDoubleBuffered() const override {
52
0
        return mIsDoubleBuffered;
53
0
    }
54
55
0
    void SetIsDoubleBuffered(bool aIsDB) {
56
0
        mIsDoubleBuffered = aIsDB;
57
0
    }
58
59
0
    virtual bool IsANGLE() const override {
60
0
        return GLLibraryEGL::Get()->IsANGLE();
61
0
    }
62
63
0
    virtual bool IsWARP() const override {
64
0
        return GLLibraryEGL::Get()->IsWARP();
65
0
    }
66
67
    virtual bool BindTexImage() override;
68
69
    virtual bool ReleaseTexImage() override;
70
71
    void SetEGLSurfaceOverride(EGLSurface surf);
72
0
    EGLSurface GetEGLSurfaceOverride() {
73
0
        return mSurfaceOverride;
74
0
    }
75
76
    virtual bool MakeCurrentImpl() const override;
77
78
    virtual bool IsCurrentImpl() const 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
0
    EGLSurface GetEGLSurface() const {
95
0
        return mSurface;
96
0
    }
97
98
0
    EGLDisplay GetEGLDisplay() const {
99
0
        return GLLibraryEGL::Get()->Display();
100
0
    }
101
102
    bool BindTex2DOffscreen(GLContext* aOffscreen);
103
    void UnbindTex2DOffscreen(GLContext* aOffscreen);
104
    void BindOffscreenFramebuffer();
105
106
    void Destroy();
107
108
    static already_AddRefed<GLContextEGL>
109
    CreateEGLPBufferOffscreenContext(CreateContextFlags flags,
110
                                     const gfx::IntSize& size,
111
                                     const SurfaceCaps& minCaps,
112
                                     nsACString* const out_FailureId);
113
114
protected:
115
    friend class GLContextProviderEGL;
116
    friend class GLContextEGLFactory;
117
118
public:
119
    const EGLConfig mConfig;
120
protected:
121
    const RefPtr<GLLibraryEGL> mEgl;
122
    EGLSurface mSurface;
123
    const EGLSurface mFallbackSurface;
124
public:
125
    const EGLContext mContext;
126
protected:
127
    EGLSurface mSurfaceOverride = EGL_NO_SURFACE;
128
    RefPtr<gfxASurface> mThebesSurface;
129
    bool mBound = false;
130
131
    bool mIsPBuffer = false;
132
    bool mIsDoubleBuffered = false;
133
    bool mCanBindToTexture = false;
134
    bool mShareWithEGLImage = false;
135
    bool mOwnsContext = true;
136
137
    static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(EGLConfig config,
138
                                                           EGLenum bindToTextureFormat,
139
                                                           gfx::IntSize& pbsize);
140
#if defined(MOZ_WAYLAND)
141
    static EGLSurface CreateWaylandBufferSurface(EGLConfig config,
142
                                                 gfx::IntSize& pbsize);
143
#endif
144
#if defined(MOZ_WIDGET_ANDROID)
145
public:
146
    EGLSurface CreateCompatibleSurface(void* aWindow);
147
#endif // defined(MOZ_WIDGET_ANDROID)
148
};
149
150
bool CreateConfig(EGLConfig* config, int32_t depth, bool enableDepthBuffer);
151
152
} // namespace gl
153
} // namespace mozilla
154
155
#endif // GLCONTEXTEGL_H_