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"
24 class DataSourceSurface
;
31 // For readback and bootstrapping:
32 class SharedSurface_Basic
33 : public SharedSurface
36 static UniquePtr
<SharedSurface_Basic
> Create(GLContext
* gl
,
37 const GLFormats
& formats
,
38 const gfx::IntSize
& size
,
41 static SharedSurface_Basic
* Cast(SharedSurface
* surf
) {
42 MOZ_ASSERT(surf
->mType
== SharedSurfaceType::Basic
);
44 return (SharedSurface_Basic
*)surf
;
51 SharedSurface_Basic(GLContext
* gl
,
52 const gfx::IntSize
& size
,
54 gfx::SurfaceFormat format
,
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
{
72 class SurfaceFactory_Basic
73 : public SurfaceFactory
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
92 static UniquePtr
<SharedSurface_GLTexture
> Create(GLContext
* prodGL
,
94 const GLFormats
& formats
,
95 const gfx::IntSize
& size
,
99 static SharedSurface_GLTexture
* Cast(SharedSurface
* surf
) {
100 MOZ_ASSERT(surf
->mType
== SharedSurfaceType::GLTextureShare
);
102 return (SharedSurface_GLTexture
*)surf
;
110 mutable Mutex mMutex
;
112 SharedSurface_GLTexture(GLContext
* prodGL
,
114 const gfx::IntSize
& size
,
118 : SharedSurface(SharedSurfaceType::GLTextureShare
,
119 AttachmentType::GLTexture
,
127 , mMutex("SharedSurface_GLTexture mutex")
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
{
147 GLuint
ConsTexture(GLContext
* consGL
);
149 GLenum
ConsTextureTarget() const {
150 return ProdTextureTarget();
154 class SurfaceFactory_GLTexture
155 : public SurfaceFactory
158 GLContext
* const mConsGL
;
161 // If we don't know `consGL` at construction time, use `nullptr`, and call
162 // `SetConsumerGL()` on each `SharedSurface_GLTexture` before calling its
164 SurfaceFactory_GLTexture(GLContext
* prodGL
,
166 const SurfaceCaps
& caps
)
167 : SurfaceFactory(prodGL
, SharedSurfaceType::GLTextureShare
, caps
)
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_ */