/src/mozilla-central/gfx/gl/SharedSurfaceGL.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_GL_H_ |
7 | | #define SHARED_SURFACE_GL_H_ |
8 | | |
9 | | #include "ScopedGLHelpers.h" |
10 | | #include "SharedSurface.h" |
11 | | #include "SurfaceTypes.h" |
12 | | #include "GLContextTypes.h" |
13 | | #include "gfxTypes.h" |
14 | | #include "mozilla/Mutex.h" |
15 | | |
16 | | #include <queue> |
17 | | |
18 | | namespace mozilla { |
19 | | namespace gl { |
20 | | class GLContext; |
21 | | } // namespace gl |
22 | | namespace gfx { |
23 | | class DataSourceSurface; |
24 | | } // namespace gfx |
25 | | } // namespace mozilla |
26 | | |
27 | | namespace mozilla { |
28 | | namespace gl { |
29 | | |
30 | | // For readback and bootstrapping: |
31 | | class SharedSurface_Basic |
32 | | : public SharedSurface |
33 | | { |
34 | | public: |
35 | | static UniquePtr<SharedSurface_Basic> Create(GLContext* gl, |
36 | | const GLFormats& formats, |
37 | | const gfx::IntSize& size, |
38 | | bool hasAlpha); |
39 | | |
40 | | static UniquePtr<SharedSurface_Basic> Wrap(GLContext* gl, |
41 | | const gfx::IntSize& size, |
42 | | bool hasAlpha, |
43 | | GLuint tex); |
44 | | |
45 | 0 | static SharedSurface_Basic* Cast(SharedSurface* surf) { |
46 | 0 | MOZ_ASSERT(surf->mType == SharedSurfaceType::Basic); |
47 | 0 |
|
48 | 0 | return (SharedSurface_Basic*)surf; |
49 | 0 | } |
50 | | |
51 | | protected: |
52 | | const GLuint mTex; |
53 | | const bool mOwnsTex; |
54 | | GLuint mFB; |
55 | | |
56 | | SharedSurface_Basic(GLContext* gl, |
57 | | const gfx::IntSize& size, |
58 | | bool hasAlpha, |
59 | | GLuint tex, |
60 | | bool ownsTex); |
61 | | |
62 | | public: |
63 | | virtual ~SharedSurface_Basic(); |
64 | | |
65 | 0 | virtual void LockProdImpl() override {} |
66 | 0 | virtual void UnlockProdImpl() override {} |
67 | | |
68 | 0 | virtual void ProducerAcquireImpl() override {} |
69 | 0 | virtual void ProducerReleaseImpl() override {} |
70 | | |
71 | 0 | virtual GLuint ProdTexture() override { |
72 | 0 | return mTex; |
73 | 0 | } |
74 | | |
75 | 0 | virtual bool ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor) override { |
76 | 0 | MOZ_CRASH("GFX: ToSurfaceDescriptor"); |
77 | 0 | return false; |
78 | 0 | } |
79 | | }; |
80 | | |
81 | | class SurfaceFactory_Basic |
82 | | : public SurfaceFactory |
83 | | { |
84 | | public: |
85 | | SurfaceFactory_Basic(GLContext* gl, const SurfaceCaps& caps, |
86 | | const layers::TextureFlags& flags); |
87 | | |
88 | 0 | virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) override { |
89 | 0 | bool hasAlpha = mReadCaps.alpha; |
90 | 0 | return SharedSurface_Basic::Create(mGL, mFormats, size, hasAlpha); |
91 | 0 | } |
92 | | }; |
93 | | |
94 | | |
95 | | // Using shared GL textures: |
96 | | class SharedSurface_GLTexture |
97 | | : public SharedSurface |
98 | | { |
99 | | public: |
100 | | static UniquePtr<SharedSurface_GLTexture> Create(GLContext* prodGL, |
101 | | const GLFormats& formats, |
102 | | const gfx::IntSize& size, |
103 | | bool hasAlpha); |
104 | | |
105 | 0 | static SharedSurface_GLTexture* Cast(SharedSurface* surf) { |
106 | 0 | MOZ_ASSERT(surf->mType == SharedSurfaceType::SharedGLTexture); |
107 | 0 |
|
108 | 0 | return (SharedSurface_GLTexture*)surf; |
109 | 0 | } |
110 | | |
111 | | protected: |
112 | | const GLuint mTex; |
113 | | GLsync mSync; |
114 | | |
115 | | SharedSurface_GLTexture(GLContext* prodGL, |
116 | | const gfx::IntSize& size, |
117 | | bool hasAlpha, |
118 | | GLuint tex) |
119 | | : SharedSurface(SharedSurfaceType::SharedGLTexture, |
120 | | AttachmentType::GLTexture, |
121 | | prodGL, |
122 | | size, |
123 | | hasAlpha, true) |
124 | | , mTex(tex) |
125 | | , mSync(0) |
126 | 0 | { |
127 | 0 | } |
128 | | |
129 | | public: |
130 | | virtual ~SharedSurface_GLTexture(); |
131 | | |
132 | 0 | virtual void LockProdImpl() override {} |
133 | 0 | virtual void UnlockProdImpl() override {} |
134 | | |
135 | 0 | virtual void ProducerAcquireImpl() override {} |
136 | | virtual void ProducerReleaseImpl() override; |
137 | | |
138 | 0 | virtual GLuint ProdTexture() override { |
139 | 0 | return mTex; |
140 | 0 | } |
141 | | |
142 | | virtual bool ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor) override; |
143 | | }; |
144 | | |
145 | | class SurfaceFactory_GLTexture |
146 | | : public SurfaceFactory |
147 | | { |
148 | | public: |
149 | | SurfaceFactory_GLTexture(GLContext* prodGL, |
150 | | const SurfaceCaps& caps, |
151 | | const RefPtr<layers::LayersIPCChannel>& allocator, |
152 | | const layers::TextureFlags& flags) |
153 | | : SurfaceFactory(SharedSurfaceType::SharedGLTexture, prodGL, caps, allocator, flags) |
154 | 0 | { |
155 | 0 | } |
156 | | |
157 | 0 | virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) override { |
158 | 0 | bool hasAlpha = mReadCaps.alpha; |
159 | 0 | return SharedSurface_GLTexture::Create(mGL, mFormats, size, hasAlpha); |
160 | 0 | } |
161 | | }; |
162 | | |
163 | | } // namespace gl |
164 | | |
165 | | } /* namespace mozilla */ |
166 | | |
167 | | #endif /* SHARED_SURFACE_GL_H_ */ |