Bumping manifests a=b2g-bump
[gecko.git] / gfx / gl / SharedSurfaceGL.h
blob4ce14fdfc78aaf21c59cb804a5828607689fd704
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/. */
6 #ifndef SHARED_SURFACE_GL_H_
7 #define SHARED_SURFACE_GL_H_
9 #include "ScopedGLHelpers.h"
10 #include "SharedSurface.h"
11 #include "SurfaceTypes.h"
12 #include "GLContextTypes.h"
13 #include "nsAutoPtr.h"
14 #include "gfxTypes.h"
15 #include "mozilla/Mutex.h"
17 #include <queue>
19 // Forwards:
20 namespace mozilla {
21 namespace gl {
22 class GLContext;
24 namespace gfx {
25 class DataSourceSurface;
29 namespace mozilla {
30 namespace gl {
32 // For readback and bootstrapping:
33 class SharedSurface_Basic
34 : public SharedSurface
36 public:
37 static UniquePtr<SharedSurface_Basic> Create(GLContext* gl,
38 const GLFormats& formats,
39 const gfx::IntSize& size,
40 bool hasAlpha);
42 static SharedSurface_Basic* Cast(SharedSurface* surf) {
43 MOZ_ASSERT(surf->mType == SharedSurfaceType::Basic);
45 return (SharedSurface_Basic*)surf;
48 protected:
49 const GLuint mTex;
50 GLuint mFB;
52 RefPtr<gfx::DataSourceSurface> mData;
54 SharedSurface_Basic(GLContext* gl,
55 const gfx::IntSize& size,
56 bool hasAlpha,
57 gfx::SurfaceFormat format,
58 GLuint tex);
60 public:
61 virtual ~SharedSurface_Basic();
63 virtual void LockProdImpl() MOZ_OVERRIDE {}
64 virtual void UnlockProdImpl() MOZ_OVERRIDE {}
67 virtual void Fence() MOZ_OVERRIDE;
69 virtual bool WaitSync() MOZ_OVERRIDE {
70 // Since we already store the data in Fence, we're always done already.
71 return true;
73 virtual bool PollSync() MOZ_OVERRIDE { return true; }
75 virtual GLuint ProdTexture() MOZ_OVERRIDE {
76 return mTex;
79 // Implementation-specific functions below:
80 gfx::DataSourceSurface* GetData() {
81 return mData;
85 class SurfaceFactory_Basic
86 : public SurfaceFactory
88 public:
89 SurfaceFactory_Basic(GLContext* gl, const SurfaceCaps& caps)
90 : SurfaceFactory(gl, SharedSurfaceType::Basic, caps)
93 virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
94 bool hasAlpha = mReadCaps.alpha;
95 return SharedSurface_Basic::Create(mGL, mFormats, size, hasAlpha);
100 // Using shared GL textures:
101 class SharedSurface_GLTexture
102 : public SharedSurface
104 public:
105 static UniquePtr<SharedSurface_GLTexture> Create(GLContext* prodGL,
106 GLContext* consGL,
107 const GLFormats& formats,
108 const gfx::IntSize& size,
109 bool hasAlpha,
110 GLuint texture = 0);
112 static SharedSurface_GLTexture* Cast(SharedSurface* surf) {
113 MOZ_ASSERT(surf->mType == SharedSurfaceType::GLTextureShare);
115 return (SharedSurface_GLTexture*)surf;
118 protected:
119 GLContext* mConsGL;
120 const GLuint mTex;
121 const bool mOwnsTex;
122 GLsync mSync;
123 mutable Mutex mMutex;
125 SharedSurface_GLTexture(GLContext* prodGL,
126 GLContext* consGL,
127 const gfx::IntSize& size,
128 bool hasAlpha,
129 GLuint tex,
130 bool ownsTex)
131 : SharedSurface(SharedSurfaceType::GLTextureShare,
132 AttachmentType::GLTexture,
133 prodGL,
134 size,
135 hasAlpha)
136 , mConsGL(consGL)
137 , mTex(tex)
138 , mOwnsTex(ownsTex)
139 , mSync(0)
140 , mMutex("SharedSurface_GLTexture mutex")
144 public:
145 virtual ~SharedSurface_GLTexture();
147 virtual void LockProdImpl() MOZ_OVERRIDE {}
148 virtual void UnlockProdImpl() MOZ_OVERRIDE {}
150 virtual void Fence() MOZ_OVERRIDE;
151 virtual bool WaitSync() MOZ_OVERRIDE;
152 virtual bool PollSync() MOZ_OVERRIDE;
154 virtual GLuint ProdTexture() MOZ_OVERRIDE {
155 return mTex;
158 // Custom:
160 GLuint ConsTexture(GLContext* consGL);
162 GLenum ConsTextureTarget() const {
163 return ProdTextureTarget();
167 class SurfaceFactory_GLTexture
168 : public SurfaceFactory
170 protected:
171 GLContext* const mConsGL;
173 public:
174 // If we don't know `consGL` at construction time, use `nullptr`, and call
175 // `SetConsumerGL()` on each `SharedSurface_GLTexture` before calling its
176 // `WaitSync()`.
177 SurfaceFactory_GLTexture(GLContext* prodGL,
178 GLContext* consGL,
179 const SurfaceCaps& caps)
180 : SurfaceFactory(prodGL, SharedSurfaceType::GLTextureShare, caps)
181 , mConsGL(consGL)
183 MOZ_ASSERT(consGL != prodGL);
186 virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
187 bool hasAlpha = mReadCaps.alpha;
188 return SharedSurface_GLTexture::Create(mGL, mConsGL, mFormats, size, hasAlpha);
192 } /* namespace gfx */
193 } /* namespace mozilla */
195 #endif /* SHARED_SURFACE_GL_H_ */