Bug 1657747 [Wayland] Remove DMABuf backend from SW compositor, r=jhorak

Differential Revision: https://phabricator.services.mozilla.com/D86342
This commit is contained in:
Martin Stransky 2020-08-08 08:50:29 +00:00
Родитель aed118e1f6
Коммит 432226521b
5 изменённых файлов: 21 добавлений и 228 удалений

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

@ -9811,13 +9811,6 @@
# Keep those pref hidden on non-nightly builds to avoid people accidentally
# turning it on.
# Use DMABuf backend for Basic compositor.
# For testing purposes only.
- name: widget.wayland-dmabuf-basic-compositor.enabled
type: RelaxedAtomicBool
value: false
mirror: always
# Use DMABuf for content textures.
# For testing purposes only.
- name: widget.dmabuf-textures.enabled

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

@ -165,7 +165,6 @@ bool nsDMABufDevice::IsDMABufEnabled() {
mIsDMABufConfigured = true;
bool isDMABufUsed = (
#ifdef NIGHTLY_BUILD
StaticPrefs::widget_wayland_dmabuf_basic_compositor_enabled() ||
StaticPrefs::widget_dmabuf_textures_enabled() ||
#endif
StaticPrefs::widget_dmabuf_webgl_enabled() ||
@ -189,10 +188,6 @@ bool nsDMABufDevice::IsDMABufEnabled() {
}
#ifdef NIGHTLY_BUILD
bool nsDMABufDevice::IsDMABufBasicEnabled() {
return IsDMABufEnabled() &&
StaticPrefs::widget_wayland_dmabuf_basic_compositor_enabled();
}
bool nsDMABufDevice::IsDMABufTexturesEnabled() {
return gfx::gfxVars::UseEGL() && IsDMABufEnabled() &&
StaticPrefs::widget_dmabuf_textures_enabled();

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

@ -134,7 +134,6 @@ class nsDMABufDevice {
int GetGbmDeviceFd();
bool IsDMABufEnabled();
bool IsDMABufBasicEnabled();
bool IsDMABufTexturesEnabled();
bool IsDMABufVideoTexturesEnabled();
bool IsDMABufWebGLEnabled();

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

@ -6,7 +6,6 @@
#include "nsWaylandDisplay.h"
#include "WindowSurfaceWayland.h"
#include "DMABufLibWrapper.h"
#include "nsPrintfCString.h"
#include "mozilla/gfx/2D.h"
@ -40,9 +39,6 @@ extern mozilla::LazyLogModule gWidgetWaylandLog;
namespace mozilla {
namespace widget {
bool WindowSurfaceWayland::mUseDMABuf = false;
bool WindowSurfaceWayland::mUseDMABufInitialized = false;
/*
Wayland multi-thread rendering scheme
@ -104,33 +100,6 @@ bool WindowSurfaceWayland::mUseDMABufInitialized = false;
| ----------------------- |
---------------------------------
----------------------------------------------------------------
When WindowBackBufferDMABuf is used it's similar to
WindowBackBufferShm scheme:
|
|
|
----------------------------------- ------------------
| WindowSurfaceWayland |<------>| nsWindow |
| | ------------------
| -------------------------- |
| |WindowBackBufferDMABuf | |
| | | |
| | ---------------------- | |
| | |DMABufSurface | |
| | ---------------------- | |
| -------------------------- |
| |
| -------------------------- |
| |WindowBackBufferDMABuf | |
| | | |
| | ---------------------- | |
| | |DMABufSurface | |
| | ---------------------- | |
| -------------------------- |
-----------------------------------
nsWaylandDisplay
@ -187,15 +156,6 @@ between us and wayland compositor. We draw our graphics data to the shm and
handle to wayland compositor by WindowBackBuffer/WindowSurfaceWayland
(wl_buffer/wl_surface).
WindowBackBufferDMABuf
It's WindowBackBuffer implementation based on DMA Buffer.
It owns wl_buffer object, owns DMABufSurface
(which provides the DMA Buffer) and ties them together.
WindowBackBufferDMABuf backend is used only when DMABufSurface is
available and widget.wayland_dmabuf_backend.enabled preference is set.
*/
#define EVENT_LOOP_DELAY (1000 / 240)
@ -419,72 +379,6 @@ already_AddRefed<gfx::DrawTarget> WindowBackBufferShm::Lock() {
BUFFER_BPP * mWidth, GetSurfaceFormat());
}
WindowBackBufferDMABuf::WindowBackBufferDMABuf(
WindowSurfaceWayland* aWindowSurfaceWayland, int aWidth, int aHeight)
: WindowBackBuffer(aWindowSurfaceWayland) {
mDMAbufSurface = DMABufSurfaceRGBA::CreateDMABufSurface(
aWidth, aHeight, DMABUF_ALPHA | DMABUF_CREATE_WL_BUFFER);
LOGWAYLAND(
("WindowBackBufferDMABuf::WindowBackBufferDMABuf [%p] Created DMABuf "
"buffer [%d x %d]\n",
(void*)this, aWidth, aHeight));
}
WindowBackBufferDMABuf::~WindowBackBufferDMABuf() = default;
already_AddRefed<gfx::DrawTarget> WindowBackBufferDMABuf::Lock() {
LOGWAYLAND(
("WindowBackBufferDMABuf::Lock [%p] [%d x %d] wl_buffer %p ID %d\n",
(void*)this, GetWidth(), GetHeight(), (void*)GetWlBuffer(),
GetWlBuffer() ? wl_proxy_get_id((struct wl_proxy*)GetWlBuffer()) : -1));
uint32_t stride;
void* pixels = mDMAbufSurface->Map(&stride);
gfx::IntSize lockSize(GetWidth(), GetHeight());
return gfxPlatform::CreateDrawTargetForData(
static_cast<unsigned char*>(pixels), lockSize, stride,
GetSurfaceFormat());
}
void WindowBackBufferDMABuf::Unlock() { mDMAbufSurface->Unmap(); }
bool WindowBackBufferDMABuf::IsAttached() {
return mDMAbufSurface->WLBufferIsAttached();
}
void WindowBackBufferDMABuf::SetAttached() {
return mDMAbufSurface->WLBufferSetAttached();
}
int WindowBackBufferDMABuf::GetWidth() { return mDMAbufSurface->GetWidth(); }
int WindowBackBufferDMABuf::GetHeight() { return mDMAbufSurface->GetHeight(); }
wl_buffer* WindowBackBufferDMABuf::GetWlBuffer() {
return mDMAbufSurface->GetWLBuffer();
}
bool WindowBackBufferDMABuf::IsLocked() { return mDMAbufSurface->IsMapped(); }
bool WindowBackBufferDMABuf::Resize(int aWidth, int aHeight) {
return mDMAbufSurface->Resize(aWidth, aHeight);
}
bool WindowBackBufferDMABuf::SetImageDataFromBuffer(
class WindowBackBuffer* aSourceBuffer) {
NS_WARNING("WindowBackBufferDMABuf copy is not implemented!");
return true;
}
void WindowBackBufferDMABuf::Detach(wl_buffer* aBuffer) {
mDMAbufSurface->WLBufferDetach();
// Commit any potential cached drawings from latest Lock()/Commit() cycle.
mWindowSurfaceWayland->CommitWaylandBuffer();
}
void WindowBackBufferDMABuf::Clear() { mDMAbufSurface->Clear(); }
static void frame_callback_handler(void* data, struct wl_callback* callback,
uint32_t time) {
auto surface = reinterpret_cast<WindowSurfaceWayland*>(data);
@ -512,7 +406,6 @@ WindowSurfaceWayland::WindowSurfaceWayland(nsWindow* aWindow)
mIsMainThread(NS_IsMainThread()) {
for (int i = 0; i < BACK_BUFFER_NUM; i++) {
mShmBackupBuffer[i] = nullptr;
mDMABackupBuffer[i] = nullptr;
}
}
@ -538,51 +431,15 @@ WindowSurfaceWayland::~WindowSurfaceWayland() {
if (mShmBackupBuffer[i]) {
delete mShmBackupBuffer[i];
}
if (mDMABackupBuffer[i]) {
delete mDMABackupBuffer[i];
}
}
}
bool WindowSurfaceWayland::UseDMABufBackend() {
if (!mUseDMABufInitialized) {
mUseDMABuf = GetDMABufDevice()->IsDMABufBasicEnabled();
LOGWAYLAND(("WindowSurfaceWayland::UseDMABufBackend DMABuf state %d\n",
mUseDMABuf));
mUseDMABufInitialized = true;
}
return mUseDMABuf;
}
WindowBackBuffer* WindowSurfaceWayland::CreateWaylandBufferInternal(
int aWidth, int aHeight, bool aAllowDMABufBackend) {
if (aAllowDMABufBackend && UseDMABufBackend()) {
WindowBackBuffer* buffer =
new WindowBackBufferDMABuf(this, aWidth, aHeight);
if (buffer && buffer->GetWlBuffer() != nullptr) {
return buffer;
}
// Buffer was created as incomplete, delete it.
delete buffer;
NS_WARNING("Wayland DMABuf failed, switched back to Shm backend!");
mUseDMABuf = false;
}
return new WindowBackBufferShm(this, aWidth, aHeight);
}
WindowBackBuffer* WindowSurfaceWayland::CreateWaylandBuffer(
int aWidth, int aHeight, bool aAllowDMABufBackend) {
bool createDMABufBuffer = aAllowDMABufBackend && UseDMABufBackend();
WindowBackBuffer** backBufferStore =
createDMABufBuffer ? mDMABackupBuffer : mShmBackupBuffer;
WindowBackBuffer* WindowSurfaceWayland::CreateWaylandBuffer(int aWidth,
int aHeight) {
int availableBuffer;
for (availableBuffer = 0; availableBuffer < BACK_BUFFER_NUM;
availableBuffer++) {
if (!backBufferStore[availableBuffer]) {
if (!mShmBackupBuffer[availableBuffer]) {
break;
}
}
@ -592,25 +449,21 @@ WindowBackBuffer* WindowSurfaceWayland::CreateWaylandBuffer(
return nullptr;
}
WindowBackBuffer* buffer =
CreateWaylandBufferInternal(aWidth, aHeight, aAllowDMABufBackend);
WindowBackBuffer* buffer = new WindowBackBufferShm(this, aWidth, aHeight);
if (buffer) {
backBufferStore[availableBuffer] = buffer;
mShmBackupBuffer[availableBuffer] = buffer;
}
return buffer;
}
WindowBackBuffer* WindowSurfaceWayland::WaylandBufferFindAvailable(
int aWidth, int aHeight, bool aUseDMABufBackend) {
int aWidth, int aHeight) {
int availableBuffer;
WindowBackBuffer** backBufferStore =
aUseDMABufBackend ? mDMABackupBuffer : mShmBackupBuffer;
// Try to find a buffer which matches the size
for (availableBuffer = 0; availableBuffer < BACK_BUFFER_NUM;
availableBuffer++) {
WindowBackBuffer* buffer = backBufferStore[availableBuffer];
WindowBackBuffer* buffer = mShmBackupBuffer[availableBuffer];
if (buffer && !buffer->IsAttached() &&
buffer->IsMatchingSize(aWidth, aHeight)) {
return buffer;
@ -620,7 +473,7 @@ WindowBackBuffer* WindowSurfaceWayland::WaylandBufferFindAvailable(
// Try to find any buffer
for (availableBuffer = 0; availableBuffer < BACK_BUFFER_NUM;
availableBuffer++) {
WindowBackBuffer* buffer = backBufferStore[availableBuffer];
WindowBackBuffer* buffer = mShmBackupBuffer[availableBuffer];
if (buffer && !buffer->IsAttached()) {
return buffer;
}
@ -629,21 +482,18 @@ WindowBackBuffer* WindowSurfaceWayland::WaylandBufferFindAvailable(
return nullptr;
}
WindowBackBuffer* WindowSurfaceWayland::SetNewWaylandBuffer(
bool aUseDMABufBackend) {
WindowBackBuffer* WindowSurfaceWayland::SetNewWaylandBuffer() {
LOGWAYLAND(
("WindowSurfaceWayland::NewWaylandBuffer [%p] Requested buffer [%d "
"x %d] DMABuf %d\n",
(void*)this, mWLBufferRect.width, mWLBufferRect.height,
aUseDMABufBackend));
"x %d]\n",
(void*)this, mWLBufferRect.width, mWLBufferRect.height));
mWaylandBuffer = WaylandBufferFindAvailable(
mWLBufferRect.width, mWLBufferRect.height, aUseDMABufBackend);
mWaylandBuffer =
WaylandBufferFindAvailable(mWLBufferRect.width, mWLBufferRect.height);
if (!mWaylandBuffer) {
mWaylandBuffer = CreateWaylandBuffer(
mWLBufferRect.width, mWLBufferRect.height, aUseDMABufBackend);
mWaylandBuffer =
CreateWaylandBuffer(mWLBufferRect.width, mWLBufferRect.height);
}
return mWaylandBuffer;
}
@ -655,7 +505,7 @@ WindowBackBuffer* WindowSurfaceWayland::GetWaylandBufferRecent() {
// There's no buffer created yet, create a new one for partial screen updates.
if (!mWaylandBuffer) {
return SetNewWaylandBuffer(/* aAllowDMABufBackend */ false);
return SetNewWaylandBuffer();
}
if (mWaylandBuffer->IsAttached()) {
@ -684,9 +534,8 @@ WindowBackBuffer* WindowSurfaceWayland::GetWaylandBufferWithSwitch() {
(void*)this, mWLBufferRect.width, mWLBufferRect.height));
// There's no buffer created yet or actual buffer is attached, get a new one.
// Use DMABuf for fullscreen updates only.
if (!mWaylandBuffer || mWaylandBuffer->IsAttached()) {
return SetNewWaylandBuffer(UseDMABufBackend() && mWaylandFullscreenDamage);
return SetNewWaylandBuffer();
}
// Reuse existing buffer
@ -707,7 +556,7 @@ already_AddRefed<gfx::DrawTarget> WindowSurfaceWayland::LockWaylandBuffer() {
mWLBufferRect = LayoutDeviceIntRect(region.GetBounds());
// mCanSwitchWaylandBuffer set means we're getting buffer for fullscreen
// update. We can use DMABuf and we can get a new buffer for drawing.
// update.
WindowBackBuffer* buffer = mCanSwitchWaylandBuffer
? GetWaylandBufferWithSwitch()
: GetWaylandBufferRecent();

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

@ -13,7 +13,6 @@
#include "mozilla/gfx/Types.h"
#include "nsWaylandDisplay.h"
#include "nsWindow.h"
#include "DMABufSurface.h"
#include "WindowSurface.h"
#define BACK_BUFFER_NUM 3
@ -45,8 +44,6 @@ class WaylandShmPool {
// Holds actual graphics data for wl_surface
class WindowBackBuffer {
public:
virtual bool IsDMABufBuffer() { return false; };
virtual already_AddRefed<gfx::DrawTarget> Lock() = 0;
virtual void Unlock() = 0;
virtual bool IsLocked() = 0;
@ -127,35 +124,6 @@ class WindowBackBufferShm : public WindowBackBuffer {
bool mIsLocked;
};
class WindowBackBufferDMABuf : public WindowBackBuffer {
public:
WindowBackBufferDMABuf(WindowSurfaceWayland* aWindowSurfaceWayland,
int aWidth, int aHeight);
~WindowBackBufferDMABuf();
bool IsDMABufBuffer() { return true; };
bool IsAttached();
void SetAttached();
int GetWidth();
int GetHeight();
wl_buffer* GetWlBuffer();
bool SetImageDataFromBuffer(class WindowBackBuffer* aSourceBuffer);
already_AddRefed<gfx::DrawTarget> Lock();
bool IsLocked();
void Unlock();
void Clear();
void Detach(wl_buffer* aBuffer);
bool Resize(int aWidth, int aHeight);
private:
RefPtr<DMABufSurfaceRGBA> mDMAbufSurface;
};
class WindowImageSurface {
public:
static void Draw(gfx::SourceSurface* aSurface, gfx::DrawTarget* aDest,
@ -227,21 +195,15 @@ class WindowSurfaceWayland : public WindowSurface {
// is rendered.
CACHE_MISSING = 1,
// Don't cache anything, draw only when back buffer is available.
// Suitable for fullscreen content only like fullscreen video playback and
// may work well with dmabuf backend.
CACHE_NONE = 2
} RenderingCacheMode;
private:
WindowBackBuffer* GetWaylandBufferWithSwitch();
WindowBackBuffer* GetWaylandBufferRecent();
WindowBackBuffer* SetNewWaylandBuffer(bool aAllowDMABufBackend);
WindowBackBuffer* CreateWaylandBuffer(int aWidth, int aHeight,
bool aUseDMABufBackend);
WindowBackBuffer* CreateWaylandBufferInternal(int aWidth, int aHeight,
bool aUseDMABufBackend);
WindowBackBuffer* WaylandBufferFindAvailable(int aWidth, int aHeight,
bool aUseDMABufBackend);
WindowBackBuffer* SetNewWaylandBuffer();
WindowBackBuffer* CreateWaylandBuffer(int aWidth, int aHeight);
WindowBackBuffer* WaylandBufferFindAvailable(int aWidth, int aHeight);
already_AddRefed<gfx::DrawTarget> LockWaylandBuffer();
void UnlockWaylandBuffer();
@ -275,7 +237,6 @@ class WindowSurfaceWayland : public WindowSurface {
// the mBufferPendingCommit is set.
WindowBackBuffer* mWaylandBuffer;
WindowBackBuffer* mShmBackupBuffer[BACK_BUFFER_NUM];
WindowBackBuffer* mDMABackupBuffer[BACK_BUFFER_NUM];
// When mWaylandFullscreenDamage we invalidate whole surface,
// otherwise partial screen updates (mWaylandBufferDamage) are used.
@ -334,10 +295,6 @@ class WindowSurfaceWayland : public WindowSurface {
bool mSmoothRendering;
bool mIsMainThread;
static bool UseDMABufBackend();
static bool mUseDMABufInitialized;
static bool mUseDMABuf;
};
} // namespace widget