Bug 1619907 [Wayland] Provide logging to dmabuf code, r=jhorak

Differential Revision: https://phabricator.services.mozilla.com/D65307

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Martin Stransky 2020-03-05 09:19:59 +00:00
Родитель 60982bef74
Коммит 8416366bd0
3 изменённых файлов: 41 добавлений и 23 удалений

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

@ -44,6 +44,7 @@ LazyLogModule gWidgetFocusLog("WidgetFocus");
LazyLogModule gWidgetDragLog("WidgetDrag");
LazyLogModule gWidgetDrawLog("WidgetDraw");
LazyLogModule gWidgetWaylandLog("WidgetWayland");
LazyLogModule gWaylandDmabufLog("WaylandDmabuf");
LazyLogModule gClipboardLog("WidgetClipboard");
static GPollFunc sPollFunc;

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

@ -12,6 +12,17 @@
#include <sys/stat.h>
#include <fcntl.h>
#ifdef MOZ_LOGGING
# include "mozilla/Logging.h"
# include "nsTArray.h"
# include "Units.h"
extern mozilla::LazyLogModule gWaylandDmabufLog;
# define LOGDMABUF(args) \
MOZ_LOG(gWaylandDmabufLog, mozilla::LogLevel::Debug, args)
#else
# define LOGDMABUF(args)
#endif /* MOZ_LOGGING */
namespace mozilla {
namespace widget {
@ -252,6 +263,7 @@ static void global_registry_handler(void* data, wl_registry* registry,
} else if (strcmp(interface, "zwp_linux_dmabuf_v1") == 0 && version > 2) {
auto dmabuf = static_cast<zwp_linux_dmabuf_v1*>(
wl_registry_bind(registry, id, &zwp_linux_dmabuf_v1_interface, 3));
LOGDMABUF(("zwp_linux_dmabuf_v1 is available."));
display->SetDmabuf(dmabuf);
zwp_linux_dmabuf_v1_add_listener(dmabuf, &dmabuf_listener, data);
}
@ -329,6 +341,7 @@ bool nsWaylandDisplay::Matches(wl_display* aDisplay) {
bool nsWaylandDisplay::ConfigureGbm() {
if (!nsGbmLib::IsAvailable()) {
LOGDMABUF(("nsGbmLib is not available!"));
return false;
}
@ -340,22 +353,19 @@ bool nsWaylandDisplay::ConfigureGbm() {
mGbmFd = open(drm_render_node, O_RDWR);
if (mGbmFd < 0) {
NS_WARNING(
nsPrintfCString("Failed to open drm render node %s\n", drm_render_node)
.get());
LOGDMABUF(("Failed to open drm render node %s\n", drm_render_node));
return false;
}
mGbmDevice = nsGbmLib::CreateDevice(mGbmFd);
if (mGbmDevice == nullptr) {
NS_WARNING(nsPrintfCString("Failed to create drm render device %s\n",
drm_render_node)
.get());
LOGDMABUF(("Failed to create drm render device %s\n", drm_render_node));
close(mGbmFd);
mGbmFd = -1;
return false;
}
LOGDMABUF(("GBM device initialized"));
return true;
}
@ -455,6 +465,7 @@ bool nsWaylandDisplay::IsDMABufEnabled() {
// WaylandDisplayGet() loads dmabuf config prefs
nsWaylandDisplay* display = WaylandDisplayGet();
if (!display) {
LOGDMABUF(("IsDMABufEnabled(): Failed to get Wayland display!"));
return false;
}
@ -464,18 +475,20 @@ bool nsWaylandDisplay::IsDMABufEnabled() {
!StaticPrefs::widget_wayland_dmabuf_webgl_enabled() &&
!StaticPrefs::widget_wayland_dmabuf_vaapi_enabled()) {
// Disabled by user, just quit.
LOGDMABUF(("IsDMABufEnabled(): Disabled by preferences."));
return false;
}
if (!display->ConfigureGbm()) {
NS_WARNING("Failed to create GbmDevice, DMABUF/DRM won't be available!");
LOGDMABUF(("Failed to create GbmDevice, DMABUF/DRM won't be available!"));
return false;
}
if (!display->GetGbmFormat(/* aHasAlpha */ false) ||
!display->GetGbmFormat(/* aHasAlpha */ true)) {
NS_WARNING(
"Failed to create obtain pixel format, DMABUF/DRM won't be available!");
LOGDMABUF(
("Failed to create obtain pixel format, DMABUF/DRM won't be "
"available!"));
return false;
}
@ -523,25 +536,28 @@ GetOffsetFunc nsGbmLib::sGetOffset;
DeviceIsFormatSupportedFunc nsGbmLib::sDeviceIsFormatSupported;
DrmPrimeHandleToFDFunc nsGbmLib::sDrmPrimeHandleToFD;
bool nsGbmLib::IsAvailable() {
if (!Load()) {
return false;
}
bool nsGbmLib::IsLoaded() {
return sCreateDevice != nullptr && sCreate != nullptr &&
sCreateWithModifiers != nullptr && sImport != nullptr &&
sGetModifier != nullptr && sGetStride != nullptr &&
sGetFd != nullptr && sDestroy != nullptr && sMap != nullptr &&
sUnmap != nullptr && sGetPlaneCount != nullptr &&
sGetHandleForPlane != nullptr && sGetStrideForPlane != nullptr &&
sGetOffset != nullptr && sDeviceIsFormatSupported != nullptr &&
sDrmPrimeHandleToFD != nullptr;
sGetOffset != nullptr && sDeviceIsFormatSupported != nullptr;
}
bool nsGbmLib::IsAvailable() {
if (!Load()) {
return false;
}
return IsLoaded();
}
bool nsGbmLib::IsModifierAvailable() {
if (!Load()) {
return false;
}
return sDrmPrimeHandleToFD != nullptr;
return IsLoaded() && sDrmPrimeHandleToFD != nullptr;
}
bool nsGbmLib::Load() {
@ -550,9 +566,7 @@ bool nsGbmLib::Load() {
sGbmLibHandle = dlopen(GBMLIB_NAME, RTLD_LAZY | RTLD_LOCAL);
if (!sGbmLibHandle) {
NS_WARNING(nsPrintfCString("Failed to load %s, dmabuf isn't available.\n",
GBMLIB_NAME)
.get());
LOGDMABUF(("Failed to load %s, dmabuf isn't available.\n", GBMLIB_NAME));
return false;
}
@ -577,15 +591,17 @@ bool nsGbmLib::Load() {
sDeviceIsFormatSupported = (DeviceIsFormatSupportedFunc)dlsym(
sGbmLibHandle, "gbm_device_is_format_supported");
if (!IsLoaded()) {
LOGDMABUF(("Failed to load all symbols from %s\n", GBMLIB_NAME));
}
sXf86DrmLibHandle = dlopen(DRMLIB_NAME, RTLD_LAZY | RTLD_LOCAL);
if (sXf86DrmLibHandle) {
sDrmPrimeHandleToFD = (DrmPrimeHandleToFDFunc)dlsym(sXf86DrmLibHandle,
"drmPrimeHandleToFD");
if (!sDrmPrimeHandleToFD) {
NS_WARNING(nsPrintfCString(
"Failed to load %s, gbm modifiers are not available.\n",
DRMLIB_NAME)
.get());
LOGDMABUF(("Failed to load %s, gbm modifiers are not available.\n",
DRMLIB_NAME));
}
}
}

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

@ -152,6 +152,7 @@ typedef int (*DrmPrimeHandleToFDFunc)(int, uint32_t, uint32_t, int*);
class nsGbmLib {
public:
static bool Load();
static bool IsLoaded();
static bool IsAvailable();
static bool IsModifierAvailable();