2017-10-26 21:19:36 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_WAYLAND_H
|
|
|
|
#define _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_WAYLAND_H
|
|
|
|
|
|
|
|
#include <prthread.h>
|
2018-06-15 10:41:56 +03:00
|
|
|
#include "mozilla/gfx/Types.h"
|
2017-10-26 21:19:36 +03:00
|
|
|
|
2018-10-18 17:30:21 +03:00
|
|
|
#define BACK_BUFFER_NUM 2
|
|
|
|
|
2017-10-26 21:19:36 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
2018-11-22 21:09:34 +03:00
|
|
|
// Our general connection to Wayland display server,
|
|
|
|
// holds our display connection and runs event loop.
|
|
|
|
class nsWaylandDisplay : public nsISupports {
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit nsWaylandDisplay(wl_display *aDisplay);
|
|
|
|
|
|
|
|
wl_shm* GetShm();
|
|
|
|
void SetShm(wl_shm* aShm) { mShm = aShm; };
|
|
|
|
|
|
|
|
wl_display* GetDisplay() { return mDisplay; };
|
|
|
|
wl_event_queue* GetEventQueue() { return mEventQueue; };
|
|
|
|
gfx::SurfaceFormat GetSurfaceFormat() { return mFormat; };
|
|
|
|
bool DisplayLoop();
|
|
|
|
bool Matches(wl_display *aDisplay);
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~nsWaylandDisplay();
|
|
|
|
|
|
|
|
PRThread* mThreadId;
|
|
|
|
gfx::SurfaceFormat mFormat;
|
|
|
|
wl_shm* mShm;
|
|
|
|
wl_event_queue* mEventQueue;
|
|
|
|
wl_display* mDisplay;
|
|
|
|
};
|
|
|
|
|
2017-12-05 00:22:04 +03:00
|
|
|
// Allocates and owns shared memory for Wayland drawing surface
|
|
|
|
class WaylandShmPool {
|
|
|
|
public:
|
|
|
|
WaylandShmPool(nsWaylandDisplay* aDisplay, int aSize);
|
|
|
|
~WaylandShmPool();
|
|
|
|
|
|
|
|
bool Resize(int aSize);
|
|
|
|
wl_shm_pool* GetShmPool() { return mShmPool; };
|
|
|
|
void* GetImageData() { return mImageData; };
|
2017-12-18 13:53:30 +03:00
|
|
|
void SetImageDataFromPool(class WaylandShmPool* aSourcePool,
|
|
|
|
int aImageDataSize);
|
2017-12-05 00:22:04 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
int CreateTemporaryFile(int aSize);
|
|
|
|
|
|
|
|
wl_shm_pool* mShmPool;
|
|
|
|
int mShmPoolFd;
|
|
|
|
int mAllocatedSize;
|
|
|
|
void* mImageData;
|
|
|
|
};
|
|
|
|
|
2017-12-05 00:25:26 +03:00
|
|
|
// Holds actual graphics data for wl_surface
|
|
|
|
class WindowBackBuffer {
|
|
|
|
public:
|
|
|
|
WindowBackBuffer(nsWaylandDisplay* aDisplay, int aWidth, int aHeight);
|
|
|
|
~WindowBackBuffer();
|
|
|
|
|
2018-06-15 10:41:56 +03:00
|
|
|
already_AddRefed<gfx::DrawTarget> Lock();
|
2017-12-05 00:25:26 +03:00
|
|
|
|
|
|
|
void Attach(wl_surface* aSurface);
|
|
|
|
void Detach();
|
|
|
|
bool IsAttached() { return mAttached; }
|
|
|
|
|
2018-11-20 18:39:32 +03:00
|
|
|
void Clear();
|
2017-12-05 00:25:26 +03:00
|
|
|
bool Resize(int aWidth, int aHeight);
|
2018-09-04 14:05:54 +03:00
|
|
|
bool SetImageDataFromBuffer(class WindowBackBuffer* aSourceBuffer);
|
2017-12-05 00:25:26 +03:00
|
|
|
|
2017-12-05 00:29:08 +03:00
|
|
|
bool IsMatchingSize(int aWidth, int aHeight)
|
2017-12-05 00:25:26 +03:00
|
|
|
{
|
|
|
|
return aWidth == mWidth && aHeight == mHeight;
|
|
|
|
}
|
2017-12-05 00:29:08 +03:00
|
|
|
bool IsMatchingSize(class WindowBackBuffer *aBuffer)
|
2017-12-05 00:25:26 +03:00
|
|
|
{
|
|
|
|
return aBuffer->mWidth == mWidth && aBuffer->mHeight == mHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Create(int aWidth, int aHeight);
|
|
|
|
void Release();
|
|
|
|
|
|
|
|
// WaylandShmPool provides actual shared memory we draw into
|
|
|
|
WaylandShmPool mShmPool;
|
|
|
|
|
|
|
|
// wl_buffer is a wayland object that encapsulates the shared memory
|
|
|
|
// and passes it to wayland compositor by wl_surface object.
|
|
|
|
wl_buffer* mWaylandBuffer;
|
|
|
|
int mWidth;
|
|
|
|
int mHeight;
|
|
|
|
bool mAttached;
|
|
|
|
nsWaylandDisplay* mWaylandDisplay;
|
|
|
|
};
|
|
|
|
|
2017-12-05 00:29:08 +03:00
|
|
|
// WindowSurfaceWayland is an abstraction for wl_surface
|
|
|
|
// and related management
|
|
|
|
class WindowSurfaceWayland : public WindowSurface {
|
|
|
|
public:
|
2018-11-08 04:41:33 +03:00
|
|
|
explicit WindowSurfaceWayland(nsWindow *aWindow);
|
2017-12-05 00:29:08 +03:00
|
|
|
~WindowSurfaceWayland();
|
|
|
|
|
|
|
|
already_AddRefed<gfx::DrawTarget> Lock(const LayoutDeviceIntRegion& aRegion) override;
|
2018-02-06 09:46:57 +03:00
|
|
|
void Commit(const LayoutDeviceIntRegion& aInvalidRegion) final;
|
2017-12-05 00:29:08 +03:00
|
|
|
void FrameCallbackHandler();
|
2018-09-04 14:05:54 +03:00
|
|
|
void DelayedCommitHandler();
|
2017-12-05 00:29:08 +03:00
|
|
|
|
|
|
|
private:
|
2018-09-04 14:05:54 +03:00
|
|
|
WindowBackBuffer* GetWaylandBufferToDraw(int aWidth, int aHeight);
|
2017-12-05 00:29:08 +03:00
|
|
|
|
2018-11-20 18:39:32 +03:00
|
|
|
already_AddRefed<gfx::DrawTarget> LockWaylandBuffer(int aWidth, int aHeight,
|
|
|
|
bool aClearBuffer);
|
2018-06-15 10:41:56 +03:00
|
|
|
already_AddRefed<gfx::DrawTarget> LockImageSurface(const gfx::IntSize& aLockSize);
|
2018-09-04 14:05:54 +03:00
|
|
|
bool CommitImageSurfaceToWaylandBuffer(const LayoutDeviceIntRegion& aRegion);
|
|
|
|
void CommitWaylandBuffer();
|
2018-06-15 10:41:56 +03:00
|
|
|
|
2017-12-05 00:29:08 +03:00
|
|
|
// TODO: Do we need to hold a reference to nsWindow object?
|
|
|
|
nsWindow* mWindow;
|
|
|
|
nsWaylandDisplay* mWaylandDisplay;
|
2018-09-04 14:05:54 +03:00
|
|
|
WindowBackBuffer* mWaylandBuffer;
|
|
|
|
LayoutDeviceIntRegion mWaylandBufferDamage;
|
2018-10-18 17:30:21 +03:00
|
|
|
WindowBackBuffer* mBackupBuffer[BACK_BUFFER_NUM];
|
2018-06-15 10:41:56 +03:00
|
|
|
RefPtr<gfxImageSurface> mImageSurface;
|
2017-12-05 00:29:08 +03:00
|
|
|
wl_callback* mFrameCallback;
|
2018-09-06 12:06:10 +03:00
|
|
|
wl_surface* mLastCommittedSurface;
|
2017-12-20 16:18:18 +03:00
|
|
|
MessageLoop* mDisplayThreadMessageLoop;
|
2018-09-04 14:05:54 +03:00
|
|
|
WindowSurfaceWayland** mDelayedCommitHandle;
|
|
|
|
bool mDrawToWaylandBufferDirectly;
|
|
|
|
bool mPendingCommit;
|
|
|
|
bool mWaylandBufferFullScreenDamage;
|
2017-12-05 00:29:08 +03:00
|
|
|
bool mIsMainThread;
|
2018-09-06 12:06:10 +03:00
|
|
|
bool mNeedScaleFactorUpdate;
|
2017-12-05 00:29:08 +03:00
|
|
|
};
|
|
|
|
|
2017-10-26 21:19:36 +03:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_WAYLAND_H
|