Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / gfx / gl / SharedSurfaceGL.h
blob7a5d3cfcd202231eaf3254cebf32f663b6044976
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 namespace mozilla {
20 namespace gl {
21 class GLContext;
23 namespace gfx {
24 class DataSourceSurface;
28 namespace mozilla {
29 namespace gl {
31 // For readback and bootstrapping:
32 class SharedSurface_Basic
33 : public SharedSurface
35 public:
36 static UniquePtr<SharedSurface_Basic> Create(GLContext* gl,
37 const GLFormats& formats,
38 const gfx::IntSize& size,
39 bool hasAlpha);
41 static SharedSurface_Basic* Cast(SharedSurface* surf) {
42 MOZ_ASSERT(surf->mType == SharedSurfaceType::Basic);
44 return (SharedSurface_Basic*)surf;
47 protected:
48 const GLuint mTex;
49 GLuint mFB;
51 SharedSurface_Basic(GLContext* gl,
52 const gfx::IntSize& size,
53 bool hasAlpha,
54 gfx::SurfaceFormat format,
55 GLuint tex);
57 public:
58 virtual ~SharedSurface_Basic();
60 virtual void LockProdImpl() MOZ_OVERRIDE {}
61 virtual void UnlockProdImpl() MOZ_OVERRIDE {}
63 virtual void Fence() MOZ_OVERRIDE {}
64 virtual bool WaitSync() MOZ_OVERRIDE { return true; }
65 virtual bool PollSync() MOZ_OVERRIDE { return true; }
67 virtual GLuint ProdTexture() MOZ_OVERRIDE {
68 return mTex;
72 class SurfaceFactory_Basic
73 : public SurfaceFactory
75 public:
76 SurfaceFactory_Basic(GLContext* gl, const SurfaceCaps& caps)
77 : SurfaceFactory(gl, SharedSurfaceType::Basic, caps)
80 virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
81 bool hasAlpha = mReadCaps.alpha;
82 return SharedSurface_Basic::Create(mGL, mFormats, size, hasAlpha);
87 // Using shared GL textures:
88 class SharedSurface_GLTexture
89 : public SharedSurface
91 public:
92 static UniquePtr<SharedSurface_GLTexture> Create(GLContext* prodGL,
93 GLContext* consGL,
94 const GLFormats& formats,
95 const gfx::IntSize& size,
96 bool hasAlpha,
97 GLuint texture = 0);
99 static SharedSurface_GLTexture* Cast(SharedSurface* surf) {
100 MOZ_ASSERT(surf->mType == SharedSurfaceType::GLTextureShare);
102 return (SharedSurface_GLTexture*)surf;
105 protected:
106 GLContext* mConsGL;
107 const GLuint mTex;
108 const bool mOwnsTex;
109 GLsync mSync;
110 mutable Mutex mMutex;
112 SharedSurface_GLTexture(GLContext* prodGL,
113 GLContext* consGL,
114 const gfx::IntSize& size,
115 bool hasAlpha,
116 GLuint tex,
117 bool ownsTex)
118 : SharedSurface(SharedSurfaceType::GLTextureShare,
119 AttachmentType::GLTexture,
120 prodGL,
121 size,
122 hasAlpha)
123 , mConsGL(consGL)
124 , mTex(tex)
125 , mOwnsTex(ownsTex)
126 , mSync(0)
127 , mMutex("SharedSurface_GLTexture mutex")
131 public:
132 virtual ~SharedSurface_GLTexture();
134 virtual void LockProdImpl() MOZ_OVERRIDE {}
135 virtual void UnlockProdImpl() MOZ_OVERRIDE {}
137 virtual void Fence() MOZ_OVERRIDE;
138 virtual bool WaitSync() MOZ_OVERRIDE;
139 virtual bool PollSync() MOZ_OVERRIDE;
141 virtual GLuint ProdTexture() MOZ_OVERRIDE {
142 return mTex;
145 // Custom:
147 GLuint ConsTexture(GLContext* consGL);
149 GLenum ConsTextureTarget() const {
150 return ProdTextureTarget();
154 class SurfaceFactory_GLTexture
155 : public SurfaceFactory
157 protected:
158 GLContext* const mConsGL;
160 public:
161 // If we don't know `consGL` at construction time, use `nullptr`, and call
162 // `SetConsumerGL()` on each `SharedSurface_GLTexture` before calling its
163 // `WaitSync()`.
164 SurfaceFactory_GLTexture(GLContext* prodGL,
165 GLContext* consGL,
166 const SurfaceCaps& caps)
167 : SurfaceFactory(prodGL, SharedSurfaceType::GLTextureShare, caps)
168 , mConsGL(consGL)
170 MOZ_ASSERT(consGL != prodGL);
173 virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
174 bool hasAlpha = mReadCaps.alpha;
175 return SharedSurface_GLTexture::Create(mGL, mConsGL, mFormats, size, hasAlpha);
179 } /* namespace gfx */
180 } /* namespace mozilla */
182 #endif /* SHARED_SURFACE_GL_H_ */