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"
15 class ISurfaceAllocator
;
16 class SurfaceDescriptorGralloc
;
23 class SharedSurface_Gralloc
24 : public SharedSurface_GL
27 static SharedSurface_Gralloc
* Create(GLContext
* prodGL
,
28 const GLFormats
& formats
,
29 const gfxIntSize
& size
,
31 layers::ISurfaceAllocator
* allocator
);
33 static SharedSurface_Gralloc
* Cast(SharedSurface
* surf
) {
34 MOZ_ASSERT(surf
->Type() == SharedSurfaceType::Gralloc
);
36 return (SharedSurface_Gralloc
*)surf
;
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
51 layers::SurfaceDescriptorGralloc mDesc
;
52 const GLuint mProdTex
;
54 SharedSurface_Gralloc(GLContext
* prodGL
,
55 const gfxIntSize
& size
,
58 layers::ISurfaceAllocator
* allocator
,
59 layers::SurfaceDescriptorGralloc
& desc
,
61 : SharedSurface_GL(SharedSurfaceType::Gralloc
,
62 AttachmentType::GLTexture
,
67 , mAllocator(allocator
->asWeakPtr())
72 static bool HasExtensions(GLLibraryEGL
* egl
, GLContext
* gl
);
75 virtual ~SharedSurface_Gralloc();
78 virtual bool WaitSync();
80 virtual void LockProdImpl();
81 virtual void UnlockProdImpl();
83 virtual GLuint
Texture() const {
87 layers::SurfaceDescriptorGralloc
& GetDescriptor() {
92 class SurfaceFactory_Gralloc
93 : public SurfaceFactory_GL
96 WeakPtr
<layers::ISurfaceAllocator
> mAllocator
;
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
;
108 return SharedSurface_Gralloc::Create(mGL
, mFormats
, size
, hasAlpha
, mAllocator
);
113 } /* namespace mozilla */
115 #endif /* SHARED_SURFACE_GRALLOC_H_ */