10#include <QtCore/qdebug.h>
11#include <QtCore/qstandardpaths.h>
12#include <QtCore/qtemporaryfile.h>
13#include <QtGui/QPainter>
14#include <QtGui/QTransform>
15#include <QMutexLocker>
17#include <QtWaylandClient/private/wayland-wayland-client-protocol.h>
24# include <sys/syscall.h>
27# define MFD_CLOEXEC 0x0001U
29# ifndef MFD_ALLOW_SEALING
30# define MFD_ALLOW_SEALING 0x0002U
34# define F_ADD_SEALS 1033
37# define F_SEAL_SEAL 0x0001
40# define F_SEAL_SHRINK 0x0002
55#ifdef SYS_memfd_create
56 fd = syscall(SYS_memfd_create,
"wayland-shm", MFD_CLOEXEC | MFD_ALLOW_SEALING);
58 fcntl(
fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_SEAL);
67 filePointer.
reset(tmpFile);
73 if (!filePointer->isOpen() || !filePointer->resize(alloc)) {
77 fd = filePointer->handle();
82 mmap(
nullptr, alloc, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0);
93 mShmPool = wl_shm_create_pool(shm->object(),
fd, alloc);
94 init(wl_shm_pool_create_buffer(mShmPool,0,
size.width(),
size.height(),
100 delete mMarginsImage;
104 wl_shm_pool_destroy(mShmPool);
111 if (!margins.
isNull() && margins != mMargins) {
113 delete mMarginsImage;
123 delete mMarginsImage;
124 mMarginsImage =
nullptr;
131 return mMarginsImage;
140 auto copy = mBuffers;
145 mFrontBuffer =
nullptr;
156 w->setBackingStore(
nullptr);
181 p.fillRect(
rect, blank);
214 mPendingRegion |= region;
215 mPendingFlush =
true;
219 mPendingFlush =
false;
225 mFrontBuffer = mBackBuffer;
233 mRequestedSize =
size;
238 const auto copy = mBuffers;
241 if (
b->size() ==
size) {
245 if (mBackBuffer ==
b)
246 mBackBuffer =
nullptr;
252 static const size_t MAX_BUFFERS = 5;
253 if (mBuffers.size() < MAX_BUFFERS) {
256 mBuffers.push_front(
b);
278 qCDebug(lcWaylandBackingstore,
"QWaylandShmBackingStore: stalling waiting for a buffer to be released from the compositor...");
281 buffer = getBuffer(sizeWithMargins);
288 if (mBackBuffer !=
buffer && oldSizeInBytes == newSizeInBytes)
295 if (mBuffers.front() !=
buffer) {
297 mBuffers.push_front(
buffer);
306 return mBackBuffer->
image();
314void QWaylandShmBackingStore::updateDecorations()
321 int dpWidth = int(sourceImage.
width() / dp);
322 int dpHeight = int(sourceImage.
height() / dp);
324 sourceMatrix.
scale(dp, dp);
336 target.setHeight(dpHeight);
The QColor class provides colors based on RGB, HSV or CMYK values.
bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false.
qsizetype bytesPerLine() const
Returns the number of bytes per image scanline.
qsizetype sizeInBytes() const
QSize size() const
Returns the size of the image, i.e.
int width() const
Returns the width of the image.
int height() const
Returns the height of the image.
Format
The following image formats are available in Qt.
Format format() const
Returns the format of the image.
void setDevicePixelRatio(qreal scaleFactor)
Sets the device pixel ratio for the image.
qreal devicePixelRatio() const
Returns the device pixel ratio for the image.
const uchar * constBits() const
Returns a pointer to the first pixel data.
constexpr int bottom() const noexcept
Returns the bottom margin.
constexpr bool isNull() const noexcept
Returns true if all margins are is 0; otherwise returns false.
constexpr int left() const noexcept
Returns the left margin.
constexpr int right() const noexcept
Returns the right margin.
constexpr int top() const noexcept
Returns the top margin.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
The QPainter class performs low-level painting on widgets and other paint devices.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
The QRegion class specifies a clip region for a painter.
QRegion translated(int dx, int dy) const
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
static QString writableLocation(StandardLocation type)
\inmodule QtCore \reentrant
virtual QMargins margins(MarginsType marginsType=Full) const =0
const QImage & contentImage()
void init(wl_buffer *buf)
void blockingReadEvents()
void beginPaint(const QRegion ®ion) override
This function is called before painting onto the surface begins, with the region in which the paintin...
QPaintDevice * paintDevice() override
Implement this function to return the appropriate paint device.
~QWaylandShmBackingStore() override
QMargins windowDecorationMargins() const
void endPaint() override
This function is called after painting onto the surface has ended.
QWaylandWindow * waylandWindow() const
void flush(QWindow *window, const QRegion ®ion, const QPoint &offset) override
Flushes the given region from the specified window.
QImage * contentSurface() const
QImage * entireSurface() const
void resize(const QSize &size, const QRegion &staticContents) override
QWaylandShmBackingStore(QWindow *window, QWaylandDisplay *display)
QWaylandAbstractDecoration * windowDecoration() const
QWaylandShmBuffer(QWaylandDisplay *display, const QSize &size, QImage::Format format, qreal scale=1)
QImage * imageInsideMargins(const QMargins &margins)
~QWaylandShmBuffer() override
static wl_shm_format formatFrom(QImage::Format format)
void setBackingStore(QWaylandShmBackingStore *backingStore)
QWaylandAbstractDecoration * decoration() const
void safeCommit(QWaylandBuffer *buffer, const QRegion &damage)
void setCanResize(bool canResize)
qDeleteAll(list.begin(), list.end())
void qErrnoWarning(const char *msg,...)
struct wl_display * display
Combined button and popup list for selecting options.
static jboolean copy(JNIEnv *, jobject)
#define qCDebug(category,...)
GLboolean GLboolean GLboolean b
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
const void GLsizei GLsizei stride
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
GLenum GLenum GLenum GLenum GLenum scale
#define qUtf8Printable(string)
QLatin1StringView QLatin1String