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 #include "SharedSurface.h"
9 #include "GLBlitHelper.h"
10 #include "GLContext.h"
11 #include "GLReadTexImageHelper.h"
12 #include "GLScreenBuffer.h"
13 #include "nsThreadUtils.h"
14 #include "ScopedGLHelpers.h"
15 #include "SharedSurfaceGL.h"
16 #include "SharedSurfaceEGL.h"
17 #include "mozilla/gfx/Logging.h"
18 #include "mozilla/layers/CompositorTypes.h"
19 #include "mozilla/layers/TextureClientSharedSurface.h"
20 #include "mozilla/layers/TextureForwarder.h"
21 #include "mozilla/StaticPrefs_webgl.h"
22 #include "mozilla/Unused.h"
23 #include "VRManagerChild.h"
26 # include "SharedSurfaceANGLE.h"
27 # include "SharedSurfaceD3D11Interop.h"
31 # include "SharedSurfaceIO.h"
35 # include "gfxPlatformGtk.h"
36 # include "SharedSurfaceDMABUF.h"
37 # include "mozilla/widget/DMABufLibWrapper.h"
40 #ifdef MOZ_WIDGET_ANDROID
41 # include "SharedSurfaceAndroidHardwareBuffer.h"
47 ////////////////////////////////////////////////////////////////////////
50 SharedSurface::SharedSurface(const SharedSurfaceDesc
& desc
,
51 UniquePtr
<MozFramebuffer
> fb
)
52 : mDesc(desc
), mFb(std::move(fb
)) {}
54 SharedSurface::~SharedSurface() = default;
56 void SharedSurface::LockProd() {
57 MOZ_ASSERT(!mIsLocked
);
61 mDesc
.gl
->LockSurface(this);
65 void SharedSurface::UnlockProd() {
66 if (!mIsLocked
) return;
70 mDesc
.gl
->UnlockSurface(this);
74 ////////////////////////////////////////////////////////////////////////
78 UniquePtr
<SurfaceFactory
> SurfaceFactory::Create(
79 GLContext
* const pGl
, const layers::TextureType consumerType
) {
82 switch (consumerType
) {
83 case layers::TextureType::D3D11
:
86 return SurfaceFactory_ANGLEShareHandle::Create(gl
);
88 if (StaticPrefs::webgl_dxgl_enabled()) {
89 return SurfaceFactory_D3D11Interop::Create(gl
);
94 case layers::TextureType::MacIOSurface
:
96 return MakeUnique
<SurfaceFactory_IOSurface
>(gl
);
101 case layers::TextureType::DMABUF
:
102 #ifdef MOZ_WIDGET_GTK
103 if (gl
.GetContextType() == GLContextType::EGL
&&
104 widget::DMABufDevice::IsDMABufWebGLEnabled()) {
105 return SurfaceFactory_DMABUF::Create(gl
);
110 case layers::TextureType::AndroidNativeWindow
:
111 #ifdef MOZ_WIDGET_ANDROID
112 return MakeUnique
<SurfaceFactory_SurfaceTexture
>(gl
);
117 case layers::TextureType::AndroidHardwareBuffer
:
118 #ifdef MOZ_WIDGET_ANDROID
119 if (XRE_IsGPUProcess()) {
120 // Enable SharedSurface of AndroidHardwareBuffer only in GPU process.
121 return SurfaceFactory_AndroidHardwareBuffer::Create(gl
);
126 case layers::TextureType::EGLImage
:
127 #ifdef MOZ_WIDGET_ANDROID
128 if (XRE_IsParentProcess()) {
129 return SurfaceFactory_EGLImage::Create(gl
);
134 case layers::TextureType::Unknown
:
135 case layers::TextureType::Last
:
140 // Silence a warning.
147 SurfaceFactory::SurfaceFactory(const PartialSharedSurfaceDesc
& partialDesc
)
148 : mDesc(partialDesc
), mMutex("SurfaceFactor::mMutex") {}
150 SurfaceFactory::~SurfaceFactory() = default;
153 } // namespace mozilla