1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */
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_EGL_H_
7 #define SHARED_SURFACE_EGL_H_
9 #include "mozilla/Attributes.h"
10 #include "mozilla/Mutex.h"
11 #include "CompositorTypes.h"
12 #include "SharedSurface.h"
14 #ifdef MOZ_WIDGET_ANDROID
15 # include "AndroidNativeWindow.h"
16 # include "GLLibraryEGL.h"
27 class SharedSurface_EGLImage final
: public SharedSurface
{
28 mutable Mutex mMutex MOZ_UNANNOTATED
;
32 const EGLImage mImage
;
34 static UniquePtr
<SharedSurface_EGLImage
> Create(const SharedSurfaceDesc
&);
37 SharedSurface_EGLImage(const SharedSurfaceDesc
&,
38 UniquePtr
<MozFramebuffer
>&& fb
, EGLImage
);
40 void UpdateProdTexture(const MutexAutoLock
& curAutoLock
);
43 virtual ~SharedSurface_EGLImage();
45 virtual void LockProdImpl() override
{}
46 virtual void UnlockProdImpl() override
{}
48 virtual void ProducerAcquireImpl() override
{}
49 virtual void ProducerReleaseImpl() override
;
51 virtual void ProducerReadAcquireImpl() override
;
52 virtual void ProducerReadReleaseImpl() override
{};
54 Maybe
<layers::SurfaceDescriptor
> ToSurfaceDescriptor() override
;
57 class SurfaceFactory_EGLImage final
: public SurfaceFactory
{
59 static UniquePtr
<SurfaceFactory_EGLImage
> Create(GLContext
&);
62 explicit SurfaceFactory_EGLImage(const PartialSharedSurfaceDesc
& desc
)
63 : SurfaceFactory(desc
) {}
66 virtual UniquePtr
<SharedSurface
> CreateSharedImpl(
67 const SharedSurfaceDesc
& desc
) override
{
68 return SharedSurface_EGLImage::Create(desc
);
75 #ifdef MOZ_WIDGET_ANDROID
77 class SharedSurface_SurfaceTexture final
: public SharedSurface
{
78 const java::GeckoSurface::GlobalRef mSurface
;
79 const EGLSurface mEglSurface
;
80 const std::weak_ptr
<EglDisplay
> mEglDisplay
;
81 EGLSurface mOrigEglSurface
= 0;
84 static UniquePtr
<SharedSurface_SurfaceTexture
> Create(
85 const SharedSurfaceDesc
&);
87 java::GeckoSurface::Param
JavaSurface() { return mSurface
; }
90 SharedSurface_SurfaceTexture(const SharedSurfaceDesc
&,
91 java::GeckoSurface::Param surface
, EGLSurface
);
94 virtual ~SharedSurface_SurfaceTexture();
96 virtual void LockProdImpl() override
;
97 virtual void UnlockProdImpl() override
;
99 virtual void ProducerAcquireImpl() override
{}
100 virtual void ProducerReleaseImpl() override
{}
101 virtual void ProducerReadReleaseImpl() override
;
103 Maybe
<layers::SurfaceDescriptor
> ToSurfaceDescriptor() override
;
105 virtual void Commit() override
;
107 virtual void WaitForBufferOwnership() override
;
109 virtual bool IsBufferAvailable() const override
;
111 bool IsValid() const override
;
114 class SurfaceFactory_SurfaceTexture final
: public SurfaceFactory
{
116 explicit SurfaceFactory_SurfaceTexture(GLContext
&);
118 virtual UniquePtr
<SharedSurface
> CreateSharedImpl(
119 const SharedSurfaceDesc
& desc
) override
{
120 return SharedSurface_SurfaceTexture::Create(desc
);
124 #endif // MOZ_WIDGET_ANDROID
128 } /* namespace mozilla */
130 #endif /* SHARED_SURFACE_EGL_H_ */