2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */
|
2013-02-14 03:26:24 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "SharedSurface.h"
|
|
|
|
|
2014-10-11 01:36:17 +04:00
|
|
|
#include "../2d/2D.h"
|
2014-07-12 02:10:49 +04:00
|
|
|
#include "GLBlitHelper.h"
|
2014-09-03 02:15:41 +04:00
|
|
|
#include "GLContext.h"
|
2014-10-11 01:36:17 +04:00
|
|
|
#include "GLReadTexImageHelper.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "GLScreenBuffer.h"
|
2014-09-03 02:15:41 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2014-07-12 02:10:49 +04:00
|
|
|
#include "ScopedGLHelpers.h"
|
|
|
|
#include "SharedSurfaceGL.h"
|
2020-06-15 21:25:55 +03:00
|
|
|
#include "SharedSurfaceEGL.h"
|
2019-06-17 07:40:13 +03:00
|
|
|
#include "mozilla/gfx/Logging.h"
|
2015-06-05 03:15:38 +03:00
|
|
|
#include "mozilla/layers/CompositorTypes.h"
|
|
|
|
#include "mozilla/layers/TextureClientSharedSurface.h"
|
2016-09-27 06:22:20 +03:00
|
|
|
#include "mozilla/layers/TextureForwarder.h"
|
2020-06-15 21:25:55 +03:00
|
|
|
#include "mozilla/StaticPrefs_webgl.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2017-05-24 14:01:45 +03:00
|
|
|
#include "VRManagerChild.h"
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
# include "SharedSurfaceANGLE.h"
|
|
|
|
# include "SharedSurfaceD3D11Interop.h"
|
|
|
|
#endif
|
2020-06-11 19:44:20 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
# include "SharedSurfaceIO.h"
|
|
|
|
#endif
|
2020-06-11 19:44:20 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
# include "GLXLibrary.h"
|
|
|
|
# include "SharedSurfaceGLX.h"
|
|
|
|
#endif
|
2020-06-11 19:44:20 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
# include "gfxPlatformGtk.h"
|
|
|
|
# include "SharedSurfaceDMABUF.h"
|
|
|
|
#endif
|
2020-06-11 19:44:20 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
2014-07-12 02:10:49 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// SharedSurface
|
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
SharedSurface::SharedSurface(const SharedSurfaceDesc& desc,
|
|
|
|
UniquePtr<MozFramebuffer> fb)
|
|
|
|
: mDesc(desc), mFb(std::move(fb)) {}
|
2014-09-03 02:15:41 +04:00
|
|
|
|
2017-12-20 11:43:11 +03:00
|
|
|
SharedSurface::~SharedSurface() = default;
|
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
void SharedSurface::LockProd() {
|
|
|
|
MOZ_ASSERT(!mIsLocked);
|
|
|
|
|
|
|
|
LockProdImpl();
|
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
mDesc.gl->LockSurface(this);
|
2014-07-12 02:10:49 +04:00
|
|
|
mIsLocked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SharedSurface::UnlockProd() {
|
|
|
|
if (!mIsLocked) return;
|
|
|
|
|
|
|
|
UnlockProdImpl();
|
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
mDesc.gl->UnlockSurface(this);
|
2014-07-12 02:10:49 +04:00
|
|
|
mIsLocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// SurfaceFactory
|
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
/* static */
|
|
|
|
UniquePtr<SurfaceFactory> SurfaceFactory::Create(
|
|
|
|
GLContext* const pGl, const layers::TextureType consumerType) {
|
|
|
|
auto& gl = *pGl;
|
|
|
|
switch (consumerType) {
|
|
|
|
case layers::TextureType::D3D11:
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (gl.IsANGLE()) {
|
|
|
|
return SurfaceFactory_ANGLEShareHandle::Create(gl);
|
2020-06-11 09:37:35 +03:00
|
|
|
}
|
2020-06-15 21:25:55 +03:00
|
|
|
if (StaticPrefs::webgl_dxgl_enabled()) {
|
|
|
|
return SurfaceFactory_D3D11Interop::Create(gl);
|
2020-06-11 19:44:20 +03:00
|
|
|
}
|
2020-06-15 21:25:55 +03:00
|
|
|
#endif
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
case layers::TextureType::MacIOSurface:
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
return MakeUnique<SurfaceFactory_IOSurface>(gl);
|
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case layers::TextureType::X11:
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
if (gl.GetContextType() != GLContextType::GLX) return nullptr;
|
|
|
|
if (!sGLXLibrary.UseTextureFromPixmap()) return nullptr;
|
|
|
|
return MakeUnique<SurfaceFactory_GLXDrawable>(gl);
|
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case layers::TextureType::WaylandDMABUF:
|
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
if (gl.GetContextType() != GLContextType::EGL) return nullptr;
|
|
|
|
if (!gfxPlatformGtk::GetPlatform()->UseWaylandDMABufWebGL())
|
|
|
|
return nullptr;
|
|
|
|
return MakeUnique<SurfaceFactory_DMABUF>(gl);
|
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case layers::TextureType::AndroidNativeWindow:
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
if (XRE_IsParentProcess() && !StaticPrefs::webgl_enable_surface_texture())
|
|
|
|
return nullptr;
|
|
|
|
return MakeUnique<SurfaceFactory_SurfaceTexture>(gl);
|
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case layers::TextureType::EGLImage:
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
return SurfaceFactory_EGLImage::Create(gl);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return nullptr;
|
2020-06-11 19:44:20 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
case layers::TextureType::Unknown:
|
|
|
|
case layers::TextureType::DIB:
|
|
|
|
case layers::TextureType::Last:
|
2020-06-15 21:26:05 +03:00
|
|
|
break;
|
2020-06-15 21:25:55 +03:00
|
|
|
}
|
2020-06-15 21:26:05 +03:00
|
|
|
return nullptr;
|
2020-06-11 19:44:20 +03:00
|
|
|
}
|
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
SurfaceFactory::SurfaceFactory(const PartialSharedSurfaceDesc& partialDesc)
|
|
|
|
: mDesc(partialDesc), mMutex("SurfaceFactor::mMutex") {}
|
2020-06-11 19:44:20 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
SurfaceFactory::~SurfaceFactory() = default;
|
2015-01-15 05:04:50 +03:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gl
|
2020-06-15 21:25:55 +03:00
|
|
|
} // namespace mozilla
|