Backed out changeset cc1377cd7adb (bug 1778767) for causing Bug 1779364. a=backout

This commit is contained in:
Cosmin Sabou 2022-07-13 19:28:49 +03:00
parent 0d11f36609
commit f12c239da6
9 changed files with 22 additions and 56 deletions

View File

@ -9,7 +9,6 @@
#include <algorithm>
#include "gfxUtils.h"
#include "nsGtkUtils.h"
#include "GLContextProvider.h"
#include "GLBlitHelper.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
@ -390,10 +389,10 @@ NativeLayerWayland::~NativeLayerWayland() {
mSurfacePoolHandle->ReturnBufferToPool(mFrontBuffer);
mFrontBuffer = nullptr;
}
MozClearPointer(mCallback, wl_callback_destroy);
MozClearPointer(mViewport, wp_viewport_destroy);
MozClearPointer(mWlSubsurface, wl_subsurface_destroy);
MozClearPointer(mWlSurface, wl_surface_destroy);
g_clear_pointer(&mCallback, wl_callback_destroy);
g_clear_pointer(&mViewport, wp_viewport_destroy);
g_clear_pointer(&mWlSubsurface, wl_subsurface_destroy);
g_clear_pointer(&mWlSurface, wl_surface_destroy);
}
void NativeLayerWayland::AttachExternalImage(
@ -631,7 +630,7 @@ void NativeLayerWayland::EnsureParentSurface(wl_surface* aParentSurface) {
MutexAutoLock lock(mMutex);
if (aParentSurface != mParentWlSurface) {
MozClearPointer(mWlSubsurface, wl_subsurface_destroy);
g_clear_pointer(&mWlSubsurface, wl_subsurface_destroy);
mSubsurfacePosition = IntPoint(0, 0);
if (aParentSurface) {
@ -741,7 +740,7 @@ void NativeLayerWayland::FrameCallbackHandler(wl_callback* aCallback,
MutexAutoLock lock(mMutex);
MOZ_RELEASE_ASSERT(aCallback == mCallback);
MozClearPointer(mCallback, wl_callback_destroy);
g_clear_pointer(&mCallback, wl_callback_destroy);
for (const RefPtr<CallbackMultiplexHelper>& callbackMultiplexHelper :
mCallbackMultiplexHelpers) {

View File

@ -32,7 +32,6 @@
#include "ScopedGLHelpers.h"
#include "GLBlitHelper.h"
#include "GLReadTexImageHelper.h"
#include "nsGtkUtils.h"
#include "mozilla/layers/LayersSurfaces.h"
#include "mozilla/ScopeExit.h"
@ -710,7 +709,7 @@ bool DMABufSurfaceRGBA::CreateWlBuffer() {
}
void DMABufSurfaceRGBA::ReleaseWlBuffer() {
MozClearPointer(mWlBuffer, wl_buffer_destroy);
g_clear_pointer(&mWlBuffer, wl_buffer_destroy);
}
// We should synchronize DMA Buffer object access from CPU to avoid potential

View File

@ -219,7 +219,7 @@ void moz_container_wayland_add_initial_draw_callback(
static void moz_container_wayland_clear_initial_draw_callback_locked(
const MutexAutoLock& aProofOfLock, MozContainer* container) {
MozContainerWayland* wl_container = &MOZ_CONTAINER(container)->wl_container;
MozClearPointer(wl_container->frame_callback_handler, wl_callback_destroy);
g_clear_pointer(&wl_container->frame_callback_handler, wl_callback_destroy);
wl_container->initial_draw_cbs.clear();
}
@ -244,8 +244,7 @@ static void moz_container_wayland_frame_callback_handler(
{
// Protect mozcontainer internals changes by container_lock.
MutexAutoLock lock(*wl_container->container_lock);
wl_callback_destroy(wl_container->frame_callback_handler);
wl_container->frame_callback_handler = nullptr;
g_clear_pointer(&wl_container->frame_callback_handler, wl_callback_destroy);
// It's possible that container is already unmapped so quit in such case.
if (!wl_container->surface) {
LOGWAYLAND(" container is unmapped, quit.");
@ -343,10 +342,10 @@ static void moz_container_wayland_unmap_internal(MozContainer* container) {
wl_container->surface = nullptr;
}
MozClearPointer(wl_container->eglwindow, wl_egl_window_destroy);
MozClearPointer(wl_container->subsurface, wl_subsurface_destroy);
MozClearPointer(wl_container->surface, wl_surface_destroy);
MozClearPointer(wl_container->viewport, wp_viewport_destroy);
g_clear_pointer(&wl_container->eglwindow, wl_egl_window_destroy);
g_clear_pointer(&wl_container->subsurface, wl_subsurface_destroy);
g_clear_pointer(&wl_container->surface, wl_surface_destroy);
g_clear_pointer(&wl_container->viewport, wp_viewport_destroy);
wl_container->ready_to_draw = false;
wl_container->buffer_scale = 1;
@ -585,7 +584,7 @@ static bool moz_container_wayland_surface_create_locked(
wl_subcompositor_get_subsurface(WaylandDisplayGet()->GetSubcompositor(),
wl_container->surface, parent_surface);
if (!wl_container->subsurface) {
MozClearPointer(wl_container->surface, wl_surface_destroy);
g_clear_pointer(&wl_container->surface, wl_surface_destroy);
LOGWAYLAND(" Failed - can't create sub-surface!");
return false;
}
@ -603,7 +602,7 @@ static bool moz_container_wayland_surface_create_locked(
// If there's pending frame callback it's for wrong parent surface,
// so delete it.
if (wl_container->frame_callback_handler) {
MozClearPointer(wl_container->frame_callback_handler, wl_callback_destroy);
g_clear_pointer(&wl_container->frame_callback_handler, wl_callback_destroy);
}
wl_container->frame_callback_handler = wl_surface_frame(parent_surface);
wl_callback_add_listener(wl_container->frame_callback_handler,

View File

@ -343,7 +343,7 @@ bool ScreenGetterWayland::RemoveMonitorConfig(int aId) {
ScreenGetterWayland::ScreenGetterWayland() = default;
ScreenGetterWayland::~ScreenGetterWayland() {
MozClearPointer(mRegistry, wl_registry_destroy);
g_clear_pointer(&mRegistry, wl_registry_destroy);
}
static bool GdkMonitorGetWorkarea(GdkMonitor* monitor, GdkRectangle* workarea) {

View File

@ -16,7 +16,6 @@
#endif
class nsWindow;
struct wl_registry;
namespace mozilla {
namespace widget {
@ -80,7 +79,7 @@ class ScreenGetterWayland : public ScreenGetter {
bool MonitorUsesNonIntegerScale(int aMonitor);
private:
wl_registry* mRegistry = nullptr;
void* mRegistry = nullptr;
// We use UniquePtr<> here to ensure that MonitorConfig is heap-allocated
// so it's not invalidated by any change to mMonitors that could happen in the
// meantime.

View File

@ -14,7 +14,6 @@
#include "gfxPlatform.h"
#include "mozilla/WidgetUtilsGtk.h"
#include "mozilla/gfx/Tools.h"
#include "nsGtkUtils.h"
#include "nsPrintfCString.h"
#include "prenv.h" // For PR_GetEnv
@ -141,7 +140,7 @@ WaylandShmPool::~WaylandShmPool() {
munmap(mImageData, mAllocatedSize);
mImageData = MAP_FAILED;
}
MozClearPointer(mShmPool, wl_shm_pool_destroy);
g_clear_pointer(&mShmPool, wl_shm_pool_destroy);
if (mShmPoolFd >= 0) {
close(mShmPoolFd);
mShmPoolFd = -1;
@ -218,7 +217,7 @@ WaylandBufferSHM::WaylandBufferSHM(const LayoutDeviceIntSize& aSize)
: WaylandBuffer(aSize) {}
WaylandBufferSHM::~WaylandBufferSHM() {
MozClearPointer(mWLBuffer, wl_buffer_destroy);
g_clear_pointer(&mWLBuffer, wl_buffer_destroy);
}
already_AddRefed<gfx::DrawTarget> WaylandBufferSHM::Lock() {

View File

@ -28,7 +28,6 @@ if CONFIG["MOZ_WAYLAND"]:
EXPORTS += [
"MozContainer.h",
"nsGTKToolkit.h",
"nsGtkUtils.h",
"nsImageToPixbuf.h",
]

View File

@ -20,32 +20,4 @@ static inline gpointer FuncToGpointer(T aFunction) {
(reinterpret_cast<void (*)()>(aFunction)));
}
// Type-safe alternative to glib's g_clear_pointer.
//
// Using `g_clear_pointer` itself causes UBSan to report undefined
// behavior. The function-based definition of `g_clear_pointer` (as
// opposed to the older preprocessor macro) treats the `destroy`
// function as a `void (*)(void *)`, but the actual destroy functions
// that are used (say `wl_buffer_destroy`) usually have more specific
// pointer types.
//
// C++ draft n4901 [expr.call] para 6:
//
// Calling a function through an expression whose function type E
// is different from the function type F of the called functions
// definition results in undefined behavior unless the type
// “pointer to F” can be converted to the type “pointer to E” via
// a function pointer conversion (7.3.14).
//
// §7.3.14 only talks about converting between noexcept and ordinary
// function pointers.
template <class T>
static inline void MozClearPointer(T*& pointer, void (*destroy)(T*)) {
T* hold = pointer;
pointer = nullptr;
if (hold) {
destroy(hold);
}
}
#endif // nsGtkUtils_h__

View File

@ -580,7 +580,7 @@ void nsWindow::Destroy() {
mWaylandVsyncSource = nullptr;
}
mWaylandVsyncDispatcher = nullptr;
MozClearPointer(mXdgToken, xdg_activation_token_v1_destroy);
g_clear_pointer(&mXdgToken, xdg_activation_token_v1_destroy);
#endif
if (mCompositorPauseTimeoutID) {
@ -2820,7 +2820,7 @@ guint32 nsWindow::GetLastUserInputTime() {
#ifdef MOZ_WAYLAND
void nsWindow::FocusWaylandWindow(const char* aTokenID) {
auto releaseToken = mozilla::MakeScopeExit(
[&]() { MozClearPointer(mXdgToken, xdg_activation_token_v1_destroy); });
[&]() { g_clear_pointer(&mXdgToken, xdg_activation_token_v1_destroy); });
LOG("nsWindow::SetFocusWayland");
if (IsDestroyed()) {
@ -2897,7 +2897,7 @@ void nsWindow::RequestFocusWaylandWindow(RefPtr<nsWindow> aWindow) {
focusSerial, wl_proxy_get_id((struct wl_proxy*)KeymapWrapper::GetSeat()));
// Store activation token at activated window for further release.
MozClearPointer(aWindow->mXdgToken, xdg_activation_token_v1_destroy);
g_clear_pointer(&aWindow->mXdgToken, xdg_activation_token_v1_destroy);
aWindow->mXdgToken = xdg_activation_v1_get_activation_token(xdg_activation);
// Addref aWindow to avoid potential release untill we get token_done