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"
15 #include "mozilla/Mutex.h"
25 class DataSourceSurface
;
32 // For readback and bootstrapping:
33 class SharedSurface_Basic
34 : public SharedSurface
37 static UniquePtr
<SharedSurface_Basic
> Create(GLContext
* gl
,
38 const GLFormats
& formats
,
39 const gfx::IntSize
& size
,
42 static SharedSurface_Basic
* Cast(SharedSurface
* surf
) {
43 MOZ_ASSERT(surf
->mType
== SharedSurfaceType::Basic
);
45 return (SharedSurface_Basic
*)surf
;
52 RefPtr
<gfx::DataSourceSurface
> mData
;
54 SharedSurface_Basic(GLContext
* gl
,
55 const gfx::IntSize
& size
,
57 gfx::SurfaceFormat format
,
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.
73 virtual bool PollSync() MOZ_OVERRIDE
{ return true; }
75 virtual GLuint
ProdTexture() MOZ_OVERRIDE
{
79 // Implementation-specific functions below:
80 gfx::DataSourceSurface
* GetData() {
85 class SurfaceFactory_Basic
86 : public SurfaceFactory
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
105 static UniquePtr
<SharedSurface_GLTexture
> Create(GLContext
* prodGL
,
107 const GLFormats
& formats
,
108 const gfx::IntSize
& size
,
112 static SharedSurface_GLTexture
* Cast(SharedSurface
* surf
) {
113 MOZ_ASSERT(surf
->mType
== SharedSurfaceType::GLTextureShare
);
115 return (SharedSurface_GLTexture
*)surf
;
123 mutable Mutex mMutex
;
125 SharedSurface_GLTexture(GLContext
* prodGL
,
127 const gfx::IntSize
& size
,
131 : SharedSurface(SharedSurfaceType::GLTextureShare
,
132 AttachmentType::GLTexture
,
140 , mMutex("SharedSurface_GLTexture mutex")
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
{
160 GLuint
ConsTexture(GLContext
* consGL
);
162 GLenum
ConsTextureTarget() const {
163 return ProdTextureTarget();
167 class SurfaceFactory_GLTexture
168 : public SurfaceFactory
171 GLContext
* const mConsGL
;
174 // If we don't know `consGL` at construction time, use `nullptr`, and call
175 // `SetConsumerGL()` on each `SharedSurface_GLTexture` before calling its
177 SurfaceFactory_GLTexture(GLContext
* prodGL
,
179 const SurfaceCaps
& caps
)
180 : SurfaceFactory(prodGL
, SharedSurfaceType::GLTextureShare
, caps
)
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_ */