|
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_GRALLOC_H_ |
|
7 #define SHARED_SURFACE_GRALLOC_H_ |
|
8 |
|
9 #include "SharedSurfaceGL.h" |
|
10 #include "mozilla/layers/ISurfaceAllocator.h" |
|
11 #include "mozilla/layers/LayersSurfaces.h" |
|
12 #include "mozilla/layers/TextureClient.h" |
|
13 |
|
14 namespace mozilla { |
|
15 namespace layers { |
|
16 class ISurfaceAllocator; |
|
17 } |
|
18 |
|
19 namespace gl { |
|
20 class GLContext; |
|
21 class GLLibraryEGL; |
|
22 |
|
23 class SharedSurface_Gralloc |
|
24 : public SharedSurface_GL |
|
25 { |
|
26 public: |
|
27 static SharedSurface_Gralloc* Create(GLContext* prodGL, |
|
28 const GLFormats& formats, |
|
29 const gfx::IntSize& size, |
|
30 bool hasAlpha, |
|
31 layers::ISurfaceAllocator* allocator); |
|
32 |
|
33 static SharedSurface_Gralloc* Cast(SharedSurface* surf) { |
|
34 MOZ_ASSERT(surf->Type() == SharedSurfaceType::Gralloc); |
|
35 |
|
36 return (SharedSurface_Gralloc*)surf; |
|
37 } |
|
38 |
|
39 protected: |
|
40 GLLibraryEGL* const mEGL; |
|
41 RefPtr<layers::ISurfaceAllocator> mAllocator; |
|
42 RefPtr<layers::TextureClient> mTextureClient; |
|
43 const GLuint mProdTex; |
|
44 |
|
45 SharedSurface_Gralloc(GLContext* prodGL, |
|
46 const gfx::IntSize& size, |
|
47 bool hasAlpha, |
|
48 GLLibraryEGL* egl, |
|
49 layers::ISurfaceAllocator* allocator, |
|
50 layers::TextureClient* textureClient, |
|
51 GLuint prodTex) |
|
52 : SharedSurface_GL(SharedSurfaceType::Gralloc, |
|
53 AttachmentType::GLTexture, |
|
54 prodGL, |
|
55 size, |
|
56 hasAlpha) |
|
57 , mEGL(egl) |
|
58 , mAllocator(allocator) |
|
59 , mTextureClient(textureClient) |
|
60 , mProdTex(prodTex) |
|
61 {} |
|
62 |
|
63 static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl); |
|
64 |
|
65 public: |
|
66 virtual ~SharedSurface_Gralloc(); |
|
67 |
|
68 virtual void Fence() MOZ_OVERRIDE; |
|
69 virtual bool WaitSync() MOZ_OVERRIDE; |
|
70 |
|
71 virtual void LockProdImpl() MOZ_OVERRIDE {} |
|
72 virtual void UnlockProdImpl() MOZ_OVERRIDE {} |
|
73 |
|
74 virtual GLuint ProdTexture() MOZ_OVERRIDE { |
|
75 return mProdTex; |
|
76 } |
|
77 |
|
78 layers::TextureClient* GetTextureClient() { |
|
79 return mTextureClient; |
|
80 } |
|
81 }; |
|
82 |
|
83 class SurfaceFactory_Gralloc |
|
84 : public SurfaceFactory_GL |
|
85 { |
|
86 protected: |
|
87 RefPtr<layers::ISurfaceAllocator> mAllocator; |
|
88 |
|
89 public: |
|
90 SurfaceFactory_Gralloc(GLContext* prodGL, |
|
91 const SurfaceCaps& caps, |
|
92 layers::ISurfaceAllocator* allocator = nullptr); |
|
93 |
|
94 virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE { |
|
95 bool hasAlpha = mReadCaps.alpha; |
|
96 if (!mAllocator) { |
|
97 return nullptr; |
|
98 } |
|
99 return SharedSurface_Gralloc::Create(mGL, mFormats, size, hasAlpha, mAllocator); |
|
100 } |
|
101 }; |
|
102 |
|
103 } /* namespace gl */ |
|
104 } /* namespace mozilla */ |
|
105 |
|
106 #endif /* SHARED_SURFACE_GRALLOC_H_ */ |