Backed out 3 changesets (bug 1828071) for causing leaks. CLOSED TREE

Backed out changeset 1e49ad06cd44 (bug 1828071)
Backed out changeset 12d28dd0b9e2 (bug 1828071)
Backed out changeset 328ba92c5afe (bug 1828071)
This commit is contained in:
Natalia Csoregi 2023-04-19 01:22:06 +03:00
Родитель 80cb6ab5df
Коммит 06077d4459
10 изменённых файлов: 185 добавлений и 154 удалений

Просмотреть файл

@ -100,7 +100,7 @@ UniquePtr<SurfaceFactory> SurfaceFactory::Create(
case layers::TextureType::DMABUF:
#ifdef MOZ_WAYLAND
if (gl.GetContextType() == GLContextType::EGL &&
widget::nsDMABufDevice::IsDMABufWebGLEnabled()) {
widget::GetDMABufDevice()->IsDMABufWebGLEnabled()) {
return SurfaceFactory_DMABUF::Create(gl);
}
#endif

Просмотреть файл

@ -89,7 +89,7 @@ Maybe<layers::SurfaceDescriptor> SharedSurface_DMABUF::ToSurfaceDescriptor() {
/*static*/
UniquePtr<SurfaceFactory_DMABUF> SurfaceFactory_DMABUF::Create(GLContext& gl) {
if (!widget::nsDMABufDevice::IsDMABufWebGLEnabled()) {
if (!widget::GetDMABufDevice()->IsDMABufWebGLEnabled()) {
return nullptr;
}
@ -100,7 +100,7 @@ UniquePtr<SurfaceFactory_DMABUF> SurfaceFactory_DMABUF::Create(GLContext& gl) {
LOGDMABUF(
("SurfaceFactory_DMABUF::Create() failed, fallback to SW buffers.\n"));
widget::nsDMABufDevice::DisableDMABufWebGL();
widget::GetDMABufDevice()->DisableDMABufWebGL();
return nullptr;
}

Просмотреть файл

@ -113,7 +113,7 @@ TextureType TexTypeForWebgl(KnowsCompositor* const knowsCompositor) {
#ifdef MOZ_WAYLAND
if (kIsWayland) {
if (!knowsCompositor->UsingSoftwareWebRender() &&
widget::nsDMABufDevice::IsDMABufWebGLEnabled()) {
widget::GetDMABufDevice()->IsDMABufWebGLEnabled()) {
return TextureType::DMABUF;
}
}

Просмотреть файл

@ -275,7 +275,7 @@ static TextureType GetTextureType(gfx::SurfaceFormat aFormat,
#ifdef MOZ_WAYLAND
if ((layersBackend == LayersBackend::LAYERS_WR &&
!aKnowsCompositor->UsingSoftwareWebRender()) &&
widget::nsDMABufDevice::IsDMABufTexturesEnabled() &&
widget::GetDMABufDevice()->IsDMABufTexturesEnabled() &&
aFormat != SurfaceFormat::A8) {
return TextureType::DMABUF;
}

Просмотреть файл

@ -212,7 +212,7 @@ void gfxPlatformGtk::InitDmabufConfig() {
gfxInfo->GetDrmRenderDevice(drmRenderDevice);
gfxVars::SetDrmRenderDevice(drmRenderDevice);
if (GetDMABufDevice()->IsEnabled(failureId)) {
if (!GetDMABufDevice()->Configure(failureId)) {
feature.ForceDisable(FeatureStatus::Failed, "Failed to configure",
failureId);
}

Просмотреть файл

@ -26,8 +26,6 @@ using namespace mozilla::gfx;
namespace mozilla {
namespace widget {
bool nsDMABufDevice::sUseWebGLDmabufBackend = true;
#define GBMLIB_NAME "libgbm.so.1"
#define DRMLIB_NAME "libdrm.so.2"
@ -130,43 +128,74 @@ bool nsGbmLib::Load() {
}
gbm_device* nsDMABufDevice::GetGbmDevice() { return mGbmDevice; }
int nsDMABufDevice::GetDRMFd() { return mDRMFd; }
bool nsDMABufDevice::IsEnabled(nsACString& aFailureId) {
if (mDRMFd == -1) {
aFailureId = mFailureId;
static void dmabuf_modifiers(void* data,
struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf,
uint32_t format, uint32_t modifier_hi,
uint32_t modifier_lo) {
// skip modifiers marked as invalid
if (modifier_hi == (DRM_FORMAT_MOD_INVALID >> 32) &&
modifier_lo == (DRM_FORMAT_MOD_INVALID & 0xffffffff)) {
return;
}
auto* device = static_cast<nsDMABufDevice*>(data);
switch (format) {
case GBM_FORMAT_ARGB8888:
device->AddFormatModifier(true, format, modifier_hi, modifier_lo);
break;
case GBM_FORMAT_XRGB8888:
device->AddFormatModifier(false, format, modifier_hi, modifier_lo);
break;
default:
break;
}
return mDRMFd != -1;
}
static void dmabuf_format(void* data,
struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf,
uint32_t format) {
// XXX: deprecated
}
static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener = {
dmabuf_format, dmabuf_modifiers};
static void global_registry_handler(void* data, wl_registry* registry,
uint32_t id, const char* interface,
uint32_t version) {
auto* device = static_cast<nsDMABufDevice*>(data);
if (strcmp(interface, "zwp_linux_dmabuf_v1") == 0 && version > 2) {
auto* dmabuf = WaylandRegistryBind<zwp_linux_dmabuf_v1>(
registry, id, &zwp_linux_dmabuf_v1_interface, 3);
LOGDMABUF(("zwp_linux_dmabuf_v1 is available."));
device->ResetFormatsModifiers();
zwp_linux_dmabuf_v1_add_listener(dmabuf, &dmabuf_listener, data);
} else if (strcmp(interface, "wl_drm") == 0) {
LOGDMABUF(("wl_drm is available."));
}
}
static void global_registry_remover(void* data, wl_registry* registry,
uint32_t id) {}
static const struct wl_registry_listener registry_listener = {
global_registry_handler, global_registry_remover};
nsDMABufDevice::nsDMABufDevice()
: mDRMFd(-1), mGbmDevice(nullptr), mInitialized(false) {
Configure();
}
nsDMABufDevice::~nsDMABufDevice() {
if (mGbmDevice) {
nsGbmLib::DestroyDevice(mGbmDevice);
mGbmDevice = nullptr;
}
if (mDRMFd != -1) {
close(mDRMFd);
mDRMFd = -1;
}
}
void nsDMABufDevice::Configure() {
if (mInitialized) {
return;
}
mInitialized = true;
LOGDMABUF(("nsDMABufDevice::Configure()"));
if (!nsGbmLib::IsAvailable()) {
LOGDMABUF(("nsGbmLib is not available!"));
mFailureId = "FEATURE_FAILURE_NO_LIBGBM";
return;
: mUseWebGLDmabufBackend(true),
mXRGBFormat({true, false, GBM_FORMAT_XRGB8888, nullptr, 0}),
mARGBFormat({true, true, GBM_FORMAT_ARGB8888, nullptr, 0}),
mDRMFd(-1),
mGbmDevice(nullptr),
mInitialized(false) {
if (GdkIsWaylandDisplay()) {
wl_display* display = WaylandDisplayGetWLDisplay();
wl_registry* registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, &registry_listener, this);
wl_display_roundtrip(display);
wl_display_roundtrip(display);
wl_registry_destroy(registry);
}
nsAutoCString drm_render_node(getenv("MOZ_DRM_DEVICE"));
@ -180,29 +209,50 @@ void nsDMABufDevice::Configure() {
if (mDRMFd < 0) {
LOGDMABUF(("Failed to open drm render node %s error %s\n",
drm_render_node.get(), strerror(errno)));
return;
}
} else {
LOGDMABUF(("We're missing DRM render device!\n"));
mFailureId = "FEATURE_FAILURE_NO_DRM_DEVICE";
return;
}
}
nsDMABufDevice::~nsDMABufDevice() {
if (mGbmDevice) {
nsGbmLib::DestroyDevice(mGbmDevice);
mGbmDevice = nullptr;
}
if (mDRMFd != -1) {
close(mDRMFd);
mDRMFd = -1;
}
}
int nsDMABufDevice::GetDRMFd() { return mDRMFd; }
bool nsDMABufDevice::Configure(nsACString& aFailureId) {
if (mInitialized) {
return true;
}
// mGbmDevice is optional and it's used to create dmabuf surfaces
// directly on GPU. Some drivers (NVIDIA) doesn't support that
// but we still can use mDRMFd to operate with dmabuf surfaces
// created by GFX drivers and exported by OpenGL.
LOGDMABUF(("nsDMABufDevice::Configure()"));
mInitialized = true;
if (!nsGbmLib::IsAvailable()) {
LOGDMABUF(("nsGbmLib is not available!"));
aFailureId = "FEATURE_FAILURE_NO_LIBGBM";
return false;
}
// fd passed to gbm_create_device() should be kept open until
// gbm_device_destroy() is called.
mGbmDevice = nsGbmLib::CreateDevice(mDRMFd);
mGbmDevice = nsGbmLib::CreateDevice(GetDRMFd());
if (!mGbmDevice) {
LOGDMABUF(
("Failed to create drm render device. Direct dmabuf surface creation "
"will be disabled."));
LOGDMABUF(("Failed to create drm render device"));
aFailureId = "FEATURE_FAILURE_BAD_DRM_RENDER_NODE";
return false;
}
LOGDMABUF(("DMABuf is enabled"));
return true;
}
#ifdef NIGHTLY_BUILD
@ -216,21 +266,68 @@ bool nsDMABufDevice::IsDMABufTexturesEnabled() { return false; }
bool nsDMABufDevice::IsDMABufWebGLEnabled() {
LOGDMABUF(
("nsDMABufDevice::IsDMABufWebGLEnabled: UseDMABuf %d "
"sUseWebGLDmabufBackend %d "
"mUseWebGLDmabufBackend %d "
"widget_dmabuf_webgl_enabled %d\n",
gfx::gfxVars::UseDMABuf(), sUseWebGLDmabufBackend,
gfx::gfxVars::UseDMABuf(), mUseWebGLDmabufBackend,
StaticPrefs::widget_dmabuf_webgl_enabled()));
return gfx::gfxVars::UseDMABuf() && sUseWebGLDmabufBackend &&
return gfx::gfxVars::UseDMABuf() && mUseWebGLDmabufBackend &&
StaticPrefs::widget_dmabuf_webgl_enabled();
}
void nsDMABufDevice::DisableDMABufWebGL() { sUseWebGLDmabufBackend = false; }
void nsDMABufDevice::DisableDMABufWebGL() { mUseWebGLDmabufBackend = false; }
GbmFormat* nsDMABufDevice::GetGbmFormat(bool aHasAlpha) {
GbmFormat* format = aHasAlpha ? &mARGBFormat : &mXRGBFormat;
return format->mIsSupported ? format : nullptr;
}
GbmFormat* nsDMABufDevice::GetExactGbmFormat(int aFormat) {
if (aFormat == mARGBFormat.mFormat) {
return &mARGBFormat;
} else if (aFormat == mXRGBFormat.mFormat) {
return &mXRGBFormat;
}
return nullptr;
}
void nsDMABufDevice::AddFormatModifier(bool aHasAlpha, int aFormat,
uint32_t mModifierHi,
uint32_t mModifierLo) {
GbmFormat* format = aHasAlpha ? &mARGBFormat : &mXRGBFormat;
format->mIsSupported = true;
format->mHasAlpha = aHasAlpha;
format->mFormat = aFormat;
format->mModifiersCount++;
format->mModifiers =
(uint64_t*)realloc(format->mModifiers,
format->mModifiersCount * sizeof(*format->mModifiers));
format->mModifiers[format->mModifiersCount - 1] =
((uint64_t)mModifierHi << 32) | mModifierLo;
}
void nsDMABufDevice::ResetFormatsModifiers() {
mARGBFormat.mModifiersCount = 0;
free(mARGBFormat.mModifiers);
mARGBFormat.mModifiers = nullptr;
mXRGBFormat.mModifiersCount = 0;
free(mXRGBFormat.mModifiers);
mXRGBFormat.mModifiers = nullptr;
}
// TODO: Make private or make sure it's configured
nsDMABufDevice* GetDMABufDevice() {
static nsDMABufDevice dmaBufDevice;
return &dmaBufDevice;
}
nsDMABufDevice* GetAndConfigureDMABufDevice() {
nsCString failureId;
if (GetDMABufDevice()->Configure(failureId)) {
return GetDMABufDevice();
}
return nullptr;
}
} // namespace widget
} // namespace mozilla

Просмотреть файл

@ -173,34 +173,49 @@ class nsGbmLib {
static mozilla::StaticMutex sDRILock MOZ_UNANNOTATED;
};
struct GbmFormat {
bool mIsSupported;
bool mHasAlpha;
int mFormat;
uint64_t* mModifiers;
int mModifiersCount;
};
class nsDMABufDevice {
public:
nsDMABufDevice();
~nsDMABufDevice();
int GetDRMFd();
gbm_device* GetGbmDevice();
bool IsEnabled(nsACString& aFailureId);
// Use dmabuf for WebRender general web content
static bool IsDMABufTexturesEnabled();
bool IsDMABufTexturesEnabled();
// Use dmabuf for WebGL content
static bool IsDMABufWebGLEnabled();
static void DisableDMABufWebGL();
bool IsDMABufWebGLEnabled();
void DisableDMABufWebGL();
int GetDRMFd();
GbmFormat* GetGbmFormat(bool aHasAlpha);
GbmFormat* GetExactGbmFormat(int aFormat);
void ResetFormatsModifiers();
void AddFormatModifier(bool aHasAlpha, int aFormat, uint32_t mModifierHi,
uint32_t mModifierLo);
bool Configure(nsACString& aFailureId);
private:
void Configure();
bool mUseWebGLDmabufBackend;
private:
GbmFormat mXRGBFormat;
GbmFormat mARGBFormat;
int mDRMFd;
gbm_device* mGbmDevice;
bool mInitialized;
nsCString mFailureId;
static bool sUseWebGLDmabufBackend;
};
nsDMABufDevice* GetDMABufDevice();
nsDMABufDevice* GetAndConfigureDMABufDevice();
} // namespace widget
} // namespace mozilla

Просмотреть файл

@ -398,7 +398,11 @@ bool DMABufSurfaceRGBA::Create(int aWidth, int aHeight,
return false;
}
mGmbFormat = nsWaylandDisplay::GetGbmFormat(mSurfaceFlags & DMABUF_ALPHA);
mGmbFormat = GetDMABufDevice()->GetGbmFormat(mSurfaceFlags & DMABUF_ALPHA);
if (!mGmbFormat) {
// Requested DRM format is not supported.
return false;
}
mDrmFormats[0] = mGmbFormat->mFormat;
bool useModifiers = (aDMABufSurfaceFlags & DMABUF_USE_MODIFIERS) &&
@ -1074,7 +1078,7 @@ bool DMABufSurfaceYUV::CreateYUVPlane(int aPlane) {
LOGDMABUF(("DMABufSurfaceYUV::CreateYUVPlane() UID %d size %d x %d", mUID,
mWidth[aPlane], mHeight[aPlane]));
if (!GetDMABufDevice()->GetGbmDevice()) {
if (!GetAndConfigureDMABufDevice()->GetGbmDevice()) {
LOGDMABUF((" Missing GbmDevice!"));
return false;
}

Просмотреть файл

@ -26,11 +26,6 @@ namespace mozilla::widget {
// compositor thread and render thread)
#define MAX_DISPLAY_CONNECTIONS 10
GbmFormat nsWaylandDisplay::sXRGBFormat = {true, false, GBM_FORMAT_XRGB8888,
nullptr, 0};
GbmFormat nsWaylandDisplay::sARGBFormat = {true, true, GBM_FORMAT_ARGB8888,
nullptr, 0};
// An array of active Wayland displays. We need a display for every thread
// where Wayland interface used as we need to dispatch Wayland's events there.
static StaticDataMutex<
@ -144,58 +139,6 @@ void nsWaylandDisplay::SetXdgActivation(xdg_activation_v1* aXdgActivation) {
mXdgActivation = aXdgActivation;
}
GbmFormat* nsWaylandDisplay::GetGbmFormat(bool aHasAlpha) {
return aHasAlpha ? &sARGBFormat : &sXRGBFormat;
}
void nsWaylandDisplay::AddFormatModifier(bool aHasAlpha, int aFormat,
uint32_t aModifierHi,
uint32_t aModifierLo) {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
GbmFormat* format = aHasAlpha ? &sARGBFormat : &sXRGBFormat;
format->mIsSupported = true;
format->mHasAlpha = aHasAlpha;
format->mFormat = aFormat;
format->mModifiersCount++;
format->mModifiers =
(uint64_t*)realloc(format->mModifiers,
format->mModifiersCount * sizeof(*format->mModifiers));
format->mModifiers[format->mModifiersCount - 1] =
((uint64_t)aModifierHi << 32) | aModifierLo;
}
static void dmabuf_modifiers(void* data,
struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf,
uint32_t format, uint32_t modifier_hi,
uint32_t modifier_lo) {
// skip modifiers marked as invalid
if (modifier_hi == (DRM_FORMAT_MOD_INVALID >> 32) &&
modifier_lo == (DRM_FORMAT_MOD_INVALID & 0xffffffff)) {
return;
}
switch (format) {
case GBM_FORMAT_ARGB8888:
nsWaylandDisplay::AddFormatModifier(true, format, modifier_hi,
modifier_lo);
break;
case GBM_FORMAT_XRGB8888:
nsWaylandDisplay::AddFormatModifier(false, format, modifier_hi,
modifier_lo);
break;
default:
break;
}
}
static void dmabuf_format(void* data,
struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf,
uint32_t format) {
// XXX: deprecated
}
static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener = {
dmabuf_format, dmabuf_modifiers};
static void global_registry_handler(void* data, wl_registry* registry,
uint32_t id, const char* interface,
uint32_t version) {
@ -250,9 +193,6 @@ static void global_registry_handler(void* data, wl_registry* registry,
registry, id, &zwp_linux_dmabuf_v1_interface, 3);
wl_proxy_set_queue((struct wl_proxy*)dmabuf, display->GetEventQueue());
display->SetDmabuf(dmabuf);
if (NS_IsMainThread()) {
zwp_linux_dmabuf_v1_add_listener(dmabuf, &dmabuf_listener, nullptr);
}
} else if (strcmp(interface, "xdg_activation_v1") == 0) {
auto* activation = WaylandRegistryBind<xdg_activation_v1>(
registry, id, &xdg_activation_v1_interface, 1);
@ -366,8 +306,6 @@ static void WlLogHandler(const char* format, va_list args) {
gfxCriticalNote << "Wayland protocol error: " << error;
}
// TODO: Make sure we always have nsWaylandDisplay for main thread
// and we keep it around.
nsWaylandDisplay::nsWaylandDisplay(wl_display* aDisplay)
: mThreadId(PR_GetCurrentThread()), mDisplay(aDisplay) {
// GTK sets the log handler on display creation, thus we overwrite it here
@ -397,14 +335,6 @@ nsWaylandDisplay::nsWaylandDisplay(wl_display* aDisplay)
"We're missing subcompositor interface!");
}
nsWaylandDisplay::~nsWaylandDisplay() {
ShutdownEventQueue();
if (NS_IsMainThread()) {
free(sARGBFormat.mModifiers);
sARGBFormat.mModifiers = nullptr;
free(sXRGBFormat.mModifiers);
sXRGBFormat.mModifiers = nullptr;
}
}
nsWaylandDisplay::~nsWaylandDisplay() { ShutdownEventQueue(); }
} // namespace mozilla::widget

Просмотреть файл

@ -23,14 +23,6 @@
namespace mozilla {
namespace widget {
struct GbmFormat {
bool mIsSupported;
bool mHasAlpha;
int mFormat;
uint64_t* mModifiers;
int mModifiersCount;
};
// Our general connection to Wayland display server,
// holds our display connection and runs event loop.
// We have a global nsWaylandDisplay object for each thread.
@ -86,10 +78,6 @@ class nsWaylandDisplay {
bool IsExplicitSyncEnabled() { return mExplicitSync; }
static GbmFormat* GetGbmFormat(bool aHasAlpha);
static void AddFormatModifier(bool aHasAlpha, int aFormat,
uint32_t aModifierHi, uint32_t aModifierLo);
private:
~nsWaylandDisplay();
@ -107,9 +95,6 @@ class nsWaylandDisplay {
zwp_linux_dmabuf_v1* mDmabuf = nullptr;
xdg_activation_v1* mXdgActivation = nullptr;
bool mExplicitSync = false;
static GbmFormat sXRGBFormat;
static GbmFormat sARGBFormat;
};
void WaylandDispatchDisplays();