Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/gl/SharedSurfaceEGL.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
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
#ifndef SHARED_SURFACE_EGL_H_
7
#define SHARED_SURFACE_EGL_H_
8
9
#include "mozilla/Attributes.h"
10
#include "mozilla/Mutex.h"
11
#include "SharedSurface.h"
12
13
#ifdef MOZ_WIDGET_ANDROID
14
#include "GeneratedJNIWrappers.h"
15
#include "AndroidNativeWindow.h"
16
#endif
17
18
namespace mozilla {
19
namespace gl {
20
21
class GLContext;
22
class GLLibraryEGL;
23
24
class SharedSurface_EGLImage
25
    : public SharedSurface
26
{
27
public:
28
    static UniquePtr<SharedSurface_EGLImage> Create(GLContext* prodGL,
29
                                                    const GLFormats& formats,
30
                                                    const gfx::IntSize& size,
31
                                                    bool hasAlpha,
32
                                                    EGLContext context);
33
34
0
    static SharedSurface_EGLImage* Cast(SharedSurface* surf) {
35
0
        MOZ_ASSERT(surf->mType == SharedSurfaceType::EGLImageShare);
36
0
37
0
        return (SharedSurface_EGLImage*)surf;
38
0
    }
39
40
    static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl);
41
42
protected:
43
    mutable Mutex mMutex;
44
    GLLibraryEGL* const mEGL;
45
    const GLFormats mFormats;
46
    GLuint mProdTex;
47
public:
48
    const EGLImage mImage;
49
protected:
50
    EGLSync mSync;
51
52
    SharedSurface_EGLImage(GLContext* gl,
53
                           GLLibraryEGL* egl,
54
                           const gfx::IntSize& size,
55
                           bool hasAlpha,
56
                           const GLFormats& formats,
57
                           GLuint prodTex,
58
                           EGLImage image);
59
60
    EGLDisplay Display() const;
61
    void UpdateProdTexture(const MutexAutoLock& curAutoLock);
62
63
public:
64
    virtual ~SharedSurface_EGLImage();
65
66
0
    virtual layers::TextureFlags GetTextureFlags() const override {
67
0
      return layers::TextureFlags::DEALLOCATE_CLIENT;
68
0
    }
69
70
0
    virtual void LockProdImpl() override {}
71
0
    virtual void UnlockProdImpl() override {}
72
73
0
    virtual void ProducerAcquireImpl() override {}
74
    virtual void ProducerReleaseImpl() override;
75
76
    virtual void ProducerReadAcquireImpl() override;
77
0
    virtual void ProducerReadReleaseImpl() override {};
78
79
0
    virtual GLuint ProdTexture() override {
80
0
      return mProdTex;
81
0
    }
82
83
    // Implementation-specific functions below:
84
    // Returns texture and target
85
    virtual bool ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor) override;
86
87
    virtual bool ReadbackBySharedHandle(gfx::DataSourceSurface* out_surface) override;
88
};
89
90
91
92
class SurfaceFactory_EGLImage
93
    : public SurfaceFactory
94
{
95
public:
96
    // Fallible:
97
    static UniquePtr<SurfaceFactory_EGLImage> Create(GLContext* prodGL,
98
                                                     const SurfaceCaps& caps,
99
                                                     const RefPtr<layers::LayersIPCChannel>& allocator,
100
                                                     const layers::TextureFlags& flags);
101
102
protected:
103
    const EGLContext mContext;
104
105
    SurfaceFactory_EGLImage(GLContext* prodGL, const SurfaceCaps& caps,
106
                            const RefPtr<layers::LayersIPCChannel>& allocator,
107
                            const layers::TextureFlags& flags,
108
                            EGLContext context)
109
        : SurfaceFactory(SharedSurfaceType::EGLImageShare, prodGL, caps, allocator, flags)
110
        , mContext(context)
111
0
    { }
112
113
public:
114
0
    virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) override {
115
0
        bool hasAlpha = mReadCaps.alpha;
116
0
        return SharedSurface_EGLImage::Create(mGL, mFormats, size, hasAlpha, mContext);
117
0
    }
118
};
119
120
#ifdef MOZ_WIDGET_ANDROID
121
122
class SharedSurface_SurfaceTexture
123
    : public SharedSurface
124
{
125
public:
126
    static UniquePtr<SharedSurface_SurfaceTexture> Create(GLContext* prodGL,
127
                                                          const GLFormats& formats,
128
                                                          const gfx::IntSize& size,
129
                                                          bool hasAlpha,
130
                                                          java::GeckoSurface::Param surface);
131
132
    static SharedSurface_SurfaceTexture* Cast(SharedSurface* surf) {
133
        MOZ_ASSERT(surf->mType == SharedSurfaceType::AndroidSurfaceTexture);
134
135
        return (SharedSurface_SurfaceTexture*)surf;
136
    }
137
138
    java::GeckoSurface::Param JavaSurface() { return mSurface; }
139
140
protected:
141
    java::GeckoSurface::GlobalRef mSurface;
142
    EGLSurface mEglSurface;
143
    EGLSurface mOrigEglSurface;
144
145
    SharedSurface_SurfaceTexture(GLContext* gl,
146
                                 const gfx::IntSize& size,
147
                                 bool hasAlpha,
148
                                 const GLFormats& formats,
149
                                 java::GeckoSurface::Param surface,
150
                                 EGLSurface eglSurface);
151
152
public:
153
    virtual ~SharedSurface_SurfaceTexture();
154
155
    virtual layers::TextureFlags GetTextureFlags() const override {
156
      return layers::TextureFlags::DEALLOCATE_CLIENT;
157
    }
158
159
    virtual void LockProdImpl() override;
160
    virtual void UnlockProdImpl() override;
161
162
    virtual void ProducerAcquireImpl() override {}
163
    virtual void ProducerReleaseImpl() override {}
164
165
    virtual void ProducerReadAcquireImpl() override {}
166
    virtual void ProducerReadReleaseImpl() override {}
167
168
    // Implementation-specific functions below:
169
    // Returns texture and target
170
    virtual bool ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor) override;
171
172
    virtual bool ReadbackBySharedHandle(gfx::DataSourceSurface* out_surface) override { return false; }
173
174
    virtual void Commit() override;
175
176
    virtual void WaitForBufferOwnership() override;
177
178
    virtual bool IsBufferAvailable() const override;
179
};
180
181
182
183
class SurfaceFactory_SurfaceTexture
184
    : public SurfaceFactory
185
{
186
public:
187
    // Fallible:
188
    static UniquePtr<SurfaceFactory_SurfaceTexture> Create(GLContext* prodGL,
189
                                                           const SurfaceCaps& caps,
190
                                                           const RefPtr<layers::LayersIPCChannel>& allocator,
191
                                                           const layers::TextureFlags& flags);
192
193
protected:
194
    SurfaceFactory_SurfaceTexture(GLContext* prodGL, const SurfaceCaps& caps,
195
                            const RefPtr<layers::LayersIPCChannel>& allocator,
196
                            const layers::TextureFlags& flags)
197
        : SurfaceFactory(SharedSurfaceType::AndroidSurfaceTexture, prodGL, caps, allocator, flags)
198
    { }
199
200
public:
201
    virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) override;
202
};
203
204
#endif // MOZ_WIDGET_ANDROID
205
206
} // namespace gl
207
208
} /* namespace mozilla */
209
210
#endif /* SHARED_SURFACE_EGL_H_ */