|
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_EGL_H_ |
|
7 #define SHARED_SURFACE_EGL_H_ |
|
8 |
|
9 #include "SharedSurfaceGL.h" |
|
10 #include "SurfaceFactory.h" |
|
11 #include "GLLibraryEGL.h" |
|
12 #include "SurfaceTypes.h" |
|
13 #include "mozilla/Attributes.h" |
|
14 #include "mozilla/Mutex.h" |
|
15 |
|
16 namespace mozilla { |
|
17 namespace gl { |
|
18 |
|
19 class GLContext; |
|
20 class TextureGarbageBin; |
|
21 |
|
22 class SharedSurface_EGLImage |
|
23 : public SharedSurface_GL |
|
24 { |
|
25 public: |
|
26 static SharedSurface_EGLImage* Create(GLContext* prodGL, |
|
27 const GLFormats& formats, |
|
28 const gfx::IntSize& size, |
|
29 bool hasAlpha, |
|
30 EGLContext context); |
|
31 |
|
32 static SharedSurface_EGLImage* Cast(SharedSurface* surf) { |
|
33 MOZ_ASSERT(surf->Type() == SharedSurfaceType::EGLImageShare); |
|
34 |
|
35 return (SharedSurface_EGLImage*)surf; |
|
36 } |
|
37 |
|
38 static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl); |
|
39 |
|
40 protected: |
|
41 mutable Mutex mMutex; |
|
42 GLLibraryEGL* const mEGL; |
|
43 const GLFormats mFormats; |
|
44 GLuint mProdTex; |
|
45 EGLImage mImage; |
|
46 GLContext* mCurConsGL; |
|
47 GLuint mConsTex; |
|
48 nsRefPtr<TextureGarbageBin> mGarbageBin; |
|
49 EGLSync mSync; |
|
50 |
|
51 SharedSurface_EGLImage(GLContext* gl, |
|
52 GLLibraryEGL* egl, |
|
53 const gfx::IntSize& size, |
|
54 bool hasAlpha, |
|
55 const GLFormats& formats, |
|
56 GLuint prodTex, |
|
57 EGLImage image); |
|
58 |
|
59 EGLDisplay Display() const; |
|
60 void UpdateProdTexture(const MutexAutoLock& curAutoLock); |
|
61 |
|
62 public: |
|
63 virtual ~SharedSurface_EGLImage(); |
|
64 |
|
65 virtual void LockProdImpl() MOZ_OVERRIDE {} |
|
66 virtual void UnlockProdImpl() MOZ_OVERRIDE {} |
|
67 |
|
68 |
|
69 virtual void Fence() MOZ_OVERRIDE; |
|
70 virtual bool WaitSync() MOZ_OVERRIDE; |
|
71 |
|
72 virtual GLuint ProdTexture() MOZ_OVERRIDE { |
|
73 return mProdTex; |
|
74 } |
|
75 |
|
76 // Implementation-specific functions below: |
|
77 // Returns texture and target |
|
78 void AcquireConsumerTexture(GLContext* consGL, GLuint* out_texture, GLuint* out_target); |
|
79 }; |
|
80 |
|
81 |
|
82 |
|
83 class SurfaceFactory_EGLImage |
|
84 : public SurfaceFactory_GL |
|
85 { |
|
86 public: |
|
87 // Fallible: |
|
88 static SurfaceFactory_EGLImage* Create(GLContext* prodGL, |
|
89 const SurfaceCaps& caps); |
|
90 |
|
91 protected: |
|
92 const EGLContext mContext; |
|
93 |
|
94 SurfaceFactory_EGLImage(GLContext* prodGL, |
|
95 EGLContext context, |
|
96 const SurfaceCaps& caps) |
|
97 : SurfaceFactory_GL(prodGL, SharedSurfaceType::EGLImageShare, caps) |
|
98 , mContext(context) |
|
99 {} |
|
100 |
|
101 public: |
|
102 virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE { |
|
103 bool hasAlpha = mReadCaps.alpha; |
|
104 return SharedSurface_EGLImage::Create(mGL, mFormats, size, hasAlpha, mContext); |
|
105 } |
|
106 }; |
|
107 |
|
108 } /* namespace gfx */ |
|
109 } /* namespace mozilla */ |
|
110 |
|
111 #endif /* SHARED_SURFACE_EGL_H_ */ |