зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1578380 - [Wayland] Use WaylandDMABufSurface as ref-counted and store GLContext, r=jhorak
Depends on D46841 Differential Revision: https://phabricator.services.mozilla.com/D46842 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
e968a933f9
Коммит
d9e67b0424
|
@ -125,7 +125,7 @@ WaylandDMABufSurface::WaylandDMABufSurface()
|
|||
}
|
||||
}
|
||||
|
||||
WaylandDMABufSurface::~WaylandDMABufSurface() { Release(); }
|
||||
WaylandDMABufSurface::~WaylandDMABufSurface() { ReleaseDMABufSurface(); }
|
||||
|
||||
bool WaylandDMABufSurface::Create(int aWidth, int aHeight,
|
||||
int aWaylandDMABufSurfaceFlags) {
|
||||
|
@ -355,10 +355,13 @@ bool WaylandDMABufSurface::CreateEGLImage(mozilla::gl::GLContext* aGLContext) {
|
|||
}
|
||||
|
||||
aGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, savedFb);
|
||||
|
||||
mGL = aGLContext;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void WaylandDMABufSurface::ReleaseEGLImage(mozilla::gl::GLContext* aGLContext) {
|
||||
void WaylandDMABufSurface::ReleaseEGLImage() {
|
||||
if (mEGLImage) {
|
||||
auto* egl = gl::GLLibraryEGL::Get();
|
||||
egl->fDestroyImage(egl->Display(), mEGLImage);
|
||||
|
@ -366,15 +369,19 @@ void WaylandDMABufSurface::ReleaseEGLImage(mozilla::gl::GLContext* aGLContext) {
|
|||
}
|
||||
|
||||
if (mGLFbo) {
|
||||
aGLContext->MakeCurrent();
|
||||
aGLContext->fDeleteFramebuffers(1, &mGLFbo);
|
||||
if (mGL->MakeCurrent()) {
|
||||
mGL->fDeleteFramebuffers(1, &mGLFbo);
|
||||
}
|
||||
mGLFbo = 0;
|
||||
}
|
||||
|
||||
mGL = nullptr;
|
||||
}
|
||||
|
||||
void WaylandDMABufSurface::Release() {
|
||||
void WaylandDMABufSurface::ReleaseDMABufSurface() {
|
||||
MOZ_ASSERT(!IsMapped(), "We can't release mapped buffer!");
|
||||
MOZ_ASSERT(!mEGLImage && !mGLFbo, "Relase EGL image first!");
|
||||
|
||||
ReleaseEGLImage();
|
||||
|
||||
if (mWLBuffer) {
|
||||
wl_buffer_destroy(mWLBuffer);
|
||||
|
@ -481,3 +488,19 @@ gfx::SurfaceFormat WaylandDMABufSurface::GetFormat() {
|
|||
return HasAlpha() ? gfx::SurfaceFormat::B8G8R8A8
|
||||
: gfx::SurfaceFormat::B8G8R8X8;
|
||||
}
|
||||
|
||||
already_AddRefed<WaylandDMABufSurface>
|
||||
WaylandDMABufSurface::CreateDMABufSurface(int aWidth, int aHeight,
|
||||
int aWaylandDMABufSurfaceFlags) {
|
||||
RefPtr<WaylandDMABufSurface> surf = new WaylandDMABufSurface();
|
||||
surf->Create(aWidth, aHeight, aWaylandDMABufSurfaceFlags);
|
||||
return surf.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<WaylandDMABufSurface>
|
||||
WaylandDMABufSurface::CreateDMABufSurface(
|
||||
const mozilla::layers::SurfaceDescriptor& aDesc) {
|
||||
RefPtr<WaylandDMABufSurface> surf = new WaylandDMABufSurface();
|
||||
surf->Create(aDesc);
|
||||
return surf.forget();
|
||||
}
|
||||
|
|
|
@ -30,16 +30,21 @@ typedef enum {
|
|||
DMABUF_CREATE_WL_BUFFER = 1 << 2,
|
||||
} WaylandDMABufSurfaceFlags;
|
||||
|
||||
// TODO - create as ref-counted?
|
||||
class WaylandDMABufSurface {
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WaylandDMABufSurface)
|
||||
|
||||
static already_AddRefed<WaylandDMABufSurface> CreateDMABufSurface(
|
||||
int aWidth, int aHeight, int aWaylandDMABufSurfaceFlags);
|
||||
static already_AddRefed<WaylandDMABufSurface> CreateDMABufSurface(
|
||||
const mozilla::layers::SurfaceDescriptor& aDesc);
|
||||
|
||||
bool Create(int aWidth, int aHeight, int aWaylandDMABufSurfaceFlags);
|
||||
bool Create(const mozilla::layers::SurfaceDescriptor& aDesc);
|
||||
|
||||
bool Serialize(mozilla::layers::SurfaceDescriptor& aOutDescriptor);
|
||||
|
||||
bool Resize(int aWidth, int aHeight);
|
||||
void Release();
|
||||
void Clear();
|
||||
|
||||
bool CopyFrom(class WaylandDMABufSurface* aSourceSurface);
|
||||
|
@ -62,7 +67,7 @@ class WaylandDMABufSurface {
|
|||
|
||||
bool IsEGLSupported(mozilla::gl::GLContext* aGLContext);
|
||||
bool CreateEGLImage(mozilla::gl::GLContext* aGLContext);
|
||||
void ReleaseEGLImage(mozilla::gl::GLContext* aGLContext);
|
||||
void ReleaseEGLImage();
|
||||
EGLImageKHR GetEGLImage() { return mEGLImage; };
|
||||
|
||||
void SetWLBuffer(struct wl_buffer* aWLBuffer);
|
||||
|
@ -73,9 +78,12 @@ class WaylandDMABufSurface {
|
|||
void WLBufferSetAttached() { mWLBufferAttached = true; };
|
||||
|
||||
WaylandDMABufSurface();
|
||||
~WaylandDMABufSurface();
|
||||
|
||||
private:
|
||||
~WaylandDMABufSurface();
|
||||
|
||||
void ReleaseDMABufSurface();
|
||||
|
||||
bool CreateWLBuffer();
|
||||
|
||||
void FillFdData(struct gbm_import_fd_data& aData);
|
||||
|
@ -100,6 +108,7 @@ class WaylandDMABufSurface {
|
|||
uint32_t mOffsets[DMABUF_BUFFER_PLANES];
|
||||
uint32_t mGbmBufferFlags;
|
||||
|
||||
RefPtr<mozilla::gl::GLContext> mGL;
|
||||
EGLImageKHR mEGLImage;
|
||||
GLuint mGLFbo;
|
||||
|
||||
|
|
|
@ -429,16 +429,15 @@ already_AddRefed<gfx::DrawTarget> WindowBackBufferShm::Lock() {
|
|||
WindowBackBufferDMABuf::WindowBackBufferDMABuf(
|
||||
WindowSurfaceWayland* aWindowSurfaceWayland, int aWidth, int aHeight)
|
||||
: WindowBackBuffer(aWindowSurfaceWayland) {
|
||||
mDMAbufSurface.Create(aWidth, aHeight,
|
||||
DMABUF_ALPHA | DMABUF_CREATE_WL_BUFFER);
|
||||
|
||||
mDMAbufSurface = WaylandDMABufSurface::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() { mDMAbufSurface.Release(); }
|
||||
WindowBackBufferDMABuf::~WindowBackBufferDMABuf() {}
|
||||
|
||||
already_AddRefed<gfx::DrawTarget> WindowBackBufferDMABuf::Lock() {
|
||||
LOGWAYLAND(
|
||||
|
@ -447,53 +446,51 @@ already_AddRefed<gfx::DrawTarget> WindowBackBufferDMABuf::Lock() {
|
|||
GetWlBuffer() ? wl_proxy_get_id((struct wl_proxy*)GetWlBuffer()) : -1));
|
||||
|
||||
uint32_t stride;
|
||||
void* pixels = mDMAbufSurface.Map(&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(); }
|
||||
void WindowBackBufferDMABuf::Unlock() { mDMAbufSurface->Unmap(); }
|
||||
|
||||
bool WindowBackBufferDMABuf::IsAttached() {
|
||||
return mDMAbufSurface.WLBufferIsAttached();
|
||||
return mDMAbufSurface->WLBufferIsAttached();
|
||||
}
|
||||
|
||||
void WindowBackBufferDMABuf::SetAttached() {
|
||||
return mDMAbufSurface.WLBufferSetAttached();
|
||||
return mDMAbufSurface->WLBufferSetAttached();
|
||||
}
|
||||
|
||||
int WindowBackBufferDMABuf::GetWidth() { return mDMAbufSurface.GetWidth(); }
|
||||
int WindowBackBufferDMABuf::GetWidth() { return mDMAbufSurface->GetWidth(); }
|
||||
|
||||
int WindowBackBufferDMABuf::GetHeight() { return mDMAbufSurface.GetHeight(); }
|
||||
int WindowBackBufferDMABuf::GetHeight() { return mDMAbufSurface->GetHeight(); }
|
||||
|
||||
wl_buffer* WindowBackBufferDMABuf::GetWlBuffer() {
|
||||
return mDMAbufSurface.GetWLBuffer();
|
||||
return mDMAbufSurface->GetWLBuffer();
|
||||
}
|
||||
|
||||
bool WindowBackBufferDMABuf::IsLocked() { return mDMAbufSurface.IsMapped(); }
|
||||
bool WindowBackBufferDMABuf::IsLocked() { return mDMAbufSurface->IsMapped(); }
|
||||
|
||||
bool WindowBackBufferDMABuf::Resize(int aWidth, int aHeight) {
|
||||
return mDMAbufSurface.Resize(aWidth, aHeight);
|
||||
return mDMAbufSurface->Resize(aWidth, aHeight);
|
||||
}
|
||||
|
||||
bool WindowBackBufferDMABuf::SetImageDataFromBuffer(
|
||||
class WindowBackBuffer* aSourceBuffer) {
|
||||
WindowBackBufferDMABuf* source =
|
||||
static_cast<WindowBackBufferDMABuf*>(aSourceBuffer);
|
||||
mDMAbufSurface.CopyFrom(&source->mDMAbufSurface);
|
||||
NS_WARNING("WindowBackBufferDMABuf copy is not implemented!");
|
||||
return true;
|
||||
}
|
||||
|
||||
void WindowBackBufferDMABuf::Detach(wl_buffer* aBuffer) {
|
||||
mDMAbufSurface.WLBufferDetach();
|
||||
mDMAbufSurface->WLBufferDetach();
|
||||
|
||||
// Commit any potential cached drawings from latest Lock()/Commit() cycle.
|
||||
mWindowSurfaceWayland->CommitWaylandBuffer();
|
||||
}
|
||||
|
||||
void WindowBackBufferDMABuf::Clear() { mDMAbufSurface.Clear(); }
|
||||
void WindowBackBufferDMABuf::Clear() { mDMAbufSurface->Clear(); }
|
||||
|
||||
static void frame_callback_handler(void* data, struct wl_callback* callback,
|
||||
uint32_t time) {
|
||||
|
|
|
@ -147,7 +147,7 @@ class WindowBackBufferDMABuf : public WindowBackBuffer {
|
|||
bool Resize(int aWidth, int aHeight);
|
||||
|
||||
private:
|
||||
WaylandDMABufSurface mDMAbufSurface;
|
||||
RefPtr<WaylandDMABufSurface> mDMAbufSurface;
|
||||
};
|
||||
|
||||
class WindowImageSurface {
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "base/task.h" // for NewRunnableMethod, etc
|
||||
#include "mozilla/StaticMutex.h"
|
||||
|
||||
#include <xf86drm.h>
|
||||
#include "mozilla/widget/gbm.h"
|
||||
#include "mozilla/widget/linux-dmabuf-unstable-v1-client-protocol.h"
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче