2021-05-17 12:13:21 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* 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/. */
|
|
|
|
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
#include "WaylandBuffer.h"
|
2021-05-17 12:13:21 +00:00
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "gfx2DGlue.h"
|
|
|
|
#include "gfxPlatform.h"
|
2022-02-23 13:59:33 +00:00
|
|
|
#include "mozilla/WidgetUtilsGtk.h"
|
2021-05-17 12:13:21 +00:00
|
|
|
#include "mozilla/gfx/Tools.h"
|
2022-07-14 04:28:34 +00:00
|
|
|
#include "nsGtkUtils.h"
|
2021-05-17 12:13:21 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2021-05-26 22:53:30 +00:00
|
|
|
#include "prenv.h" // For PR_GetEnv
|
2021-05-17 12:13:21 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
# include "mozilla/Logging.h"
|
|
|
|
# include "mozilla/ScopeExit.h"
|
|
|
|
# include "Units.h"
|
|
|
|
extern mozilla::LazyLogModule gWidgetWaylandLog;
|
2022-02-21 10:04:36 +00:00
|
|
|
# define LOGWAYLAND(...) \
|
|
|
|
MOZ_LOG(gWidgetWaylandLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
|
2021-05-17 12:13:21 +00:00
|
|
|
#else
|
2022-02-21 10:04:36 +00:00
|
|
|
# define LOGWAYLAND(...)
|
2021-05-17 12:13:21 +00:00
|
|
|
#endif /* MOZ_LOGGING */
|
|
|
|
|
2021-11-15 12:39:38 +00:00
|
|
|
using namespace mozilla::gl;
|
|
|
|
|
2021-05-17 12:13:21 +00:00
|
|
|
namespace mozilla::widget {
|
|
|
|
|
|
|
|
#define BUFFER_BPP 4
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
gfx::SurfaceFormat WaylandBuffer::mFormat = gfx::SurfaceFormat::B8G8R8A8;
|
2021-05-17 12:13:21 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_LOGGING
|
Bug 1920718 - Annotate all global variable with runtime initialization attributes r=glandium,application-update-reviewers,media-playback-reviewers,anti-tracking-reviewers,places-reviewers,profiler-reviewers,gfx-reviewers,aosmond,lina,nalexander,aabh,geckoview-reviewers,win-reviewers,gstoll,m_kato
MOZ_RUNINIT => initialized at runtime
MOZ_CONSTINIT => initialized at compile time
MOZ_GLOBINIT => initialized either at runtime or compile time, depending on template parameter, macro parameter etc
This annotation is only understood by our clang-tidy plugin. It has no
effect on regular compilation.
Differential Revision: https://phabricator.services.mozilla.com/D223341
2024-10-30 11:05:24 +00:00
|
|
|
MOZ_RUNINIT int WaylandBufferSHM::mDumpSerial =
|
2021-05-17 12:13:21 +00:00
|
|
|
PR_GetEnv("MOZ_WAYLAND_DUMP_WL_BUFFERS") ? 1 : 0;
|
Bug 1920718 - Annotate all global variable with runtime initialization attributes r=glandium,application-update-reviewers,media-playback-reviewers,anti-tracking-reviewers,places-reviewers,profiler-reviewers,gfx-reviewers,aosmond,lina,nalexander,aabh,geckoview-reviewers,win-reviewers,gstoll,m_kato
MOZ_RUNINIT => initialized at runtime
MOZ_CONSTINIT => initialized at compile time
MOZ_GLOBINIT => initialized either at runtime or compile time, depending on template parameter, macro parameter etc
This annotation is only understood by our clang-tidy plugin. It has no
effect on regular compilation.
Differential Revision: https://phabricator.services.mozilla.com/D223341
2024-10-30 11:05:24 +00:00
|
|
|
MOZ_RUNINIT char* WaylandBufferSHM::mDumpDir =
|
|
|
|
PR_GetEnv("MOZ_WAYLAND_DUMP_DIR");
|
2021-05-17 12:13:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* static */
|
2023-04-26 20:57:17 +00:00
|
|
|
RefPtr<WaylandShmPool> WaylandShmPool::Create(nsWaylandDisplay* aWaylandDisplay,
|
|
|
|
int aSize) {
|
2022-10-11 20:09:59 +00:00
|
|
|
if (!aWaylandDisplay->GetShm()) {
|
2023-05-26 07:04:26 +00:00
|
|
|
NS_WARNING("WaylandShmPool: Missing Wayland shm interface!");
|
2022-10-11 20:09:59 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-05-26 07:04:26 +00:00
|
|
|
RefPtr<WaylandShmPool> shmPool = new WaylandShmPool();
|
2021-05-17 12:13:21 +00:00
|
|
|
|
2024-10-21 18:43:25 +00:00
|
|
|
shmPool->mShm = MakeRefPtr<ipc::SharedMemory>();
|
2023-05-26 07:04:26 +00:00
|
|
|
if (!shmPool->mShm->Create(aSize)) {
|
|
|
|
NS_WARNING("WaylandShmPool: Unable to allocate shared memory!");
|
2021-05-17 12:13:21 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-05-26 07:04:26 +00:00
|
|
|
shmPool->mSize = aSize;
|
|
|
|
shmPool->mShmPool = wl_shm_create_pool(
|
|
|
|
aWaylandDisplay->GetShm(), shmPool->mShm->CloneHandle().get(), aSize);
|
2021-05-17 12:13:21 +00:00
|
|
|
if (!shmPool->mShmPool) {
|
2023-05-26 07:04:26 +00:00
|
|
|
NS_WARNING("WaylandShmPool: Unable to allocate shared memory pool!");
|
2021-05-17 12:13:21 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return shmPool;
|
|
|
|
}
|
|
|
|
|
2023-05-26 07:04:26 +00:00
|
|
|
void* WaylandShmPool::GetImageData() {
|
|
|
|
if (mImageData) {
|
|
|
|
return mImageData;
|
|
|
|
}
|
|
|
|
if (!mShm->Map(mSize)) {
|
|
|
|
NS_WARNING("WaylandShmPool: Failed to map Shm!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2024-10-21 18:43:25 +00:00
|
|
|
mImageData = mShm->Memory();
|
2023-05-26 07:04:26 +00:00
|
|
|
return mImageData;
|
|
|
|
}
|
2021-05-17 12:13:21 +00:00
|
|
|
|
|
|
|
WaylandShmPool::~WaylandShmPool() {
|
2022-07-14 04:28:34 +00:00
|
|
|
MozClearPointer(mShmPool, wl_shm_pool_destroy);
|
2021-05-17 12:13:21 +00:00
|
|
|
}
|
|
|
|
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
static const struct wl_buffer_listener sBufferListenerWaylandBuffer = {
|
|
|
|
WaylandBuffer::BufferReleaseCallbackHandler};
|
|
|
|
|
|
|
|
WaylandBuffer::WaylandBuffer(const LayoutDeviceIntSize& aSize) : mSize(aSize) {}
|
|
|
|
|
|
|
|
void WaylandBuffer::AttachAndCommit(wl_surface* aSurface) {
|
|
|
|
LOGWAYLAND(
|
2022-02-21 10:04:36 +00:00
|
|
|
"WaylandBuffer::AttachAndCommit [%p] wl_surface %p ID %d wl_buffer "
|
|
|
|
"%p ID %d\n",
|
|
|
|
(void*)this, (void*)aSurface,
|
|
|
|
aSurface ? wl_proxy_get_id((struct wl_proxy*)aSurface) : -1,
|
|
|
|
(void*)GetWlBuffer(),
|
|
|
|
GetWlBuffer() ? wl_proxy_get_id((struct wl_proxy*)GetWlBuffer()) : -1);
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
|
|
|
|
wl_buffer* buffer = GetWlBuffer();
|
|
|
|
if (buffer) {
|
|
|
|
mAttached = true;
|
|
|
|
wl_surface_attach(aSurface, buffer, 0, 0);
|
|
|
|
wl_surface_commit(aSurface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandBuffer::BufferReleaseCallbackHandler(wl_buffer* aBuffer) {
|
|
|
|
mAttached = false;
|
|
|
|
|
|
|
|
if (mBufferReleaseFunc) {
|
|
|
|
mBufferReleaseFunc(mBufferReleaseData, aBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandBuffer::BufferReleaseCallbackHandler(void* aData,
|
|
|
|
wl_buffer* aBuffer) {
|
|
|
|
auto* buffer = reinterpret_cast<WaylandBuffer*>(aData);
|
|
|
|
buffer->BufferReleaseCallbackHandler(aBuffer);
|
|
|
|
}
|
2021-05-17 12:13:21 +00:00
|
|
|
|
|
|
|
/* static */
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
RefPtr<WaylandBufferSHM> WaylandBufferSHM::Create(
|
2021-05-17 12:13:21 +00:00
|
|
|
const LayoutDeviceIntSize& aSize) {
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
RefPtr<WaylandBufferSHM> buffer = new WaylandBufferSHM(aSize);
|
2023-04-26 20:57:17 +00:00
|
|
|
nsWaylandDisplay* waylandDisplay = WaylandDisplayGet();
|
2021-05-17 12:13:21 +00:00
|
|
|
|
|
|
|
int size = aSize.width * aSize.height * BUFFER_BPP;
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
buffer->mShmPool = WaylandShmPool::Create(waylandDisplay, size);
|
2021-05-17 12:13:21 +00:00
|
|
|
if (!buffer->mShmPool) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer->mWLBuffer = wl_shm_pool_create_buffer(
|
|
|
|
buffer->mShmPool->GetShmPool(), 0, aSize.width, aSize.height,
|
|
|
|
aSize.width * BUFFER_BPP, WL_SHM_FORMAT_ARGB8888);
|
|
|
|
if (!buffer->mWLBuffer) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
wl_buffer_add_listener(buffer->GetWlBuffer(), &sBufferListenerWaylandBuffer,
|
2021-05-17 12:13:21 +00:00
|
|
|
buffer.get());
|
|
|
|
|
2022-02-21 10:04:36 +00:00
|
|
|
LOGWAYLAND("WaylandBufferSHM Created [%p] WaylandDisplay [%p]\n",
|
2023-04-26 20:57:17 +00:00
|
|
|
buffer.get(), waylandDisplay);
|
2021-05-17 12:13:21 +00:00
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
WaylandBufferSHM::WaylandBufferSHM(const LayoutDeviceIntSize& aSize)
|
|
|
|
: WaylandBuffer(aSize) {}
|
2021-05-17 12:13:21 +00:00
|
|
|
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
WaylandBufferSHM::~WaylandBufferSHM() {
|
2022-07-14 04:28:34 +00:00
|
|
|
MozClearPointer(mWLBuffer, wl_buffer_destroy);
|
2021-05-17 12:13:21 +00:00
|
|
|
}
|
|
|
|
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
already_AddRefed<gfx::DrawTarget> WaylandBufferSHM::Lock() {
|
2021-05-17 12:13:21 +00:00
|
|
|
return gfxPlatform::CreateDrawTargetForData(
|
|
|
|
static_cast<unsigned char*>(mShmPool->GetImageData()),
|
|
|
|
mSize.ToUnknownSize(), BUFFER_BPP * mSize.width, GetSurfaceFormat());
|
|
|
|
}
|
|
|
|
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
void WaylandBufferSHM::Clear() {
|
2021-05-17 12:13:21 +00:00
|
|
|
memset(mShmPool->GetImageData(), 0, mSize.height * mSize.width * BUFFER_BPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_LOGGING
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
void WaylandBufferSHM::DumpToFile(const char* aHint) {
|
2021-05-17 12:13:21 +00:00
|
|
|
if (!mDumpSerial) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_surface_t* surface = nullptr;
|
|
|
|
auto unmap = MakeScopeExit([&] {
|
|
|
|
if (surface) {
|
|
|
|
cairo_surface_destroy(surface);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
surface = cairo_image_surface_create_for_data(
|
|
|
|
(unsigned char*)mShmPool->GetImageData(), CAIRO_FORMAT_ARGB32,
|
|
|
|
mSize.width, mSize.height, BUFFER_BPP * mSize.width);
|
|
|
|
if (cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS) {
|
|
|
|
nsCString filename;
|
|
|
|
if (mDumpDir) {
|
|
|
|
filename.Append(mDumpDir);
|
|
|
|
filename.Append('/');
|
|
|
|
}
|
|
|
|
filename.Append(
|
|
|
|
nsPrintfCString("firefox-wl-buffer-%.5d-%s.png", mDumpSerial++, aHint));
|
|
|
|
cairo_surface_write_to_png(surface, filename.get());
|
2022-02-21 10:04:36 +00:00
|
|
|
LOGWAYLAND("Dumped wl_buffer to %s\n", filename.get());
|
2021-05-17 12:13:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
Bug 1720375 - Restructure surface pool into a buffer pool,r=stransky,gfx-reviewers,lsalzman
Note: Sorry in advance that this patch is so big. Unfortunately
splitting it up would create lots of redundant changes.
This should be the last big refactoring for the Wayland compositor
backend for now.
Up until now SurfacePoolWayland was a pool of actual `wl_surface`s,
as before bug 1718569 we had no direct access to `wl_buffer`s when
using EGL. However, the way `SurfacePoolCA` manages native surfaces
is closer to what in Wayland terminology would be a buffer pool:
buffers are heavy-weight and expansive to allocate, while
`wl_surface` objects are cheap to recreate.
So instead of having a pool of surfaces, each of them having its
own pool of buffers, make `wl_surface`s part of tiles and make
`SurfacePoolWayland` manage `wl_buffer`s (in the form of SHM- or
DMABuf buffers). This will allow us to share buffers (especially
depth buffers) more efficiently, reducing VRAM usage and allocation
times.
Apart from that it will also simplify our tile management logic.
Most importantly, we'll need to reorder `wl_surface`s less often and
less complex (no `place_below` the parent surface) and can also drop
reattaching subsurfaces to compositors. Especially the former will
likely decrease CPU time in compositors.
Overall this patch makes `NativeLayerWayland` behave more like
`NativeLayerCA` while taking in lessons learned from
`WindowSurfaceWaylandMB`.
Differential Revision: https://phabricator.services.mozilla.com/D119993
2021-08-04 12:43:21 +00:00
|
|
|
/* static */
|
|
|
|
RefPtr<WaylandBufferDMABUF> WaylandBufferDMABUF::Create(
|
|
|
|
const LayoutDeviceIntSize& aSize, GLContext* aGL) {
|
|
|
|
RefPtr<WaylandBufferDMABUF> buffer = new WaylandBufferDMABUF(aSize);
|
|
|
|
|
|
|
|
const auto flags =
|
|
|
|
static_cast<DMABufSurfaceFlags>(DMABUF_TEXTURE | DMABUF_ALPHA);
|
|
|
|
buffer->mDMABufSurface =
|
|
|
|
DMABufSurfaceRGBA::CreateDMABufSurface(aSize.width, aSize.height, flags);
|
|
|
|
if (!buffer->mDMABufSurface || !buffer->mDMABufSurface->CreateTexture(aGL)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!buffer->mDMABufSurface->CreateWlBuffer()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_buffer_add_listener(buffer->GetWlBuffer(), &sBufferListenerWaylandBuffer,
|
|
|
|
buffer.get());
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaylandBufferDMABUF::WaylandBufferDMABUF(const LayoutDeviceIntSize& aSize)
|
|
|
|
: WaylandBuffer(aSize) {}
|
|
|
|
|
2021-05-17 12:13:21 +00:00
|
|
|
} // namespace mozilla::widget
|