Merge m-c to b2g-inbound.
[gecko.git] / gfx / gl / SharedSurfaceGralloc.h
blob410c92b14ca6b243cce90d23657c3c3b8b5f10f3
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_GRALLOC_H_
7 #define SHARED_SURFACE_GRALLOC_H_
9 #include "SharedSurfaceGL.h"
10 #include "mozilla/layers/LayersSurfaces.h"
11 #include "mozilla/layers/ISurfaceAllocator.h"
13 namespace mozilla {
14 namespace layers {
15 class ISurfaceAllocator;
16 class SurfaceDescriptorGralloc;
19 namespace gl {
20 class GLContext;
21 class GLLibraryEGL;
23 class SharedSurface_Gralloc
24 : public SharedSurface_GL
26 public:
27 static SharedSurface_Gralloc* Create(GLContext* prodGL,
28 const GLFormats& formats,
29 const gfxIntSize& size,
30 bool hasAlpha,
31 layers::ISurfaceAllocator* allocator);
33 static SharedSurface_Gralloc* Cast(SharedSurface* surf) {
34 MOZ_ASSERT(surf->Type() == SharedSurfaceType::Gralloc);
36 return (SharedSurface_Gralloc*)surf;
39 protected:
40 GLLibraryEGL* const mEGL;
41 WeakPtr<layers::ISurfaceAllocator> mAllocator;
42 // We keep the SurfaceDescriptor around, because we'll end up
43 // using it often and it's handy to do so. The actual
44 // GraphicBuffer is kept alive by the sp<GraphicBuffer> in
45 // GrallocBufferActor; the actor will stay alive until we
46 // explicitly destroy this descriptor (and thus deallocate the
47 // actor) it in the destructor of this class. This is okay to do
48 // on the client, but is very bad to do on the server (because on
49 // the client, the actor has no chance of going away unless the
50 // whole app died).
51 layers::SurfaceDescriptorGralloc mDesc;
52 const GLuint mProdTex;
54 SharedSurface_Gralloc(GLContext* prodGL,
55 const gfxIntSize& size,
56 bool hasAlpha,
57 GLLibraryEGL* egl,
58 layers::ISurfaceAllocator* allocator,
59 layers::SurfaceDescriptorGralloc& desc,
60 GLuint prodTex)
61 : SharedSurface_GL(SharedSurfaceType::Gralloc,
62 AttachmentType::GLTexture,
63 prodGL,
64 size,
65 hasAlpha)
66 , mEGL(egl)
67 , mAllocator(allocator->asWeakPtr())
68 , mDesc(desc)
69 , mProdTex(prodTex)
72 static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl);
74 public:
75 virtual ~SharedSurface_Gralloc();
77 virtual void Fence();
78 virtual bool WaitSync();
80 virtual void LockProdImpl();
81 virtual void UnlockProdImpl();
83 virtual GLuint Texture() const {
84 return mProdTex;
87 layers::SurfaceDescriptorGralloc& GetDescriptor() {
88 return mDesc;
92 class SurfaceFactory_Gralloc
93 : public SurfaceFactory_GL
95 protected:
96 WeakPtr<layers::ISurfaceAllocator> mAllocator;
98 public:
99 SurfaceFactory_Gralloc(GLContext* prodGL,
100 const SurfaceCaps& caps,
101 layers::ISurfaceAllocator* allocator = nullptr);
103 virtual SharedSurface* CreateShared(const gfxIntSize& size) {
104 bool hasAlpha = mReadCaps.alpha;
105 if (!mAllocator) {
106 return nullptr;
108 return SharedSurface_Gralloc::Create(mGL, mFormats, size, hasAlpha, mAllocator);
112 } /* namespace gl */
113 } /* namespace mozilla */
115 #endif /* SHARED_SURFACE_GRALLOC_H_ */