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
56#ifdef SYS_memfd_create
57 fd = syscall(SYS_memfd_create,
"wayland-shm", MFD_CLOEXEC | MFD_ALLOW_SEALING);
59 fcntl(
fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_SEAL);
62 QScopedPointer<QFile> filePointer;
68 filePointer.reset(tmpFile);
72 filePointer.reset(
file);
75 if (!filePointer->isOpen() || !filePointer->resize(alloc)) {
79 fd = filePointer->handle();
84 mmap(
nullptr, alloc, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0);
95 mShmPool = wl_shm_create_pool(shm->object(),
fd, alloc);
96 init(wl_shm_pool_create_buffer(mShmPool,0,
size.width(),
size.height(),
102 delete mMarginsImage;
106 wl_shm_pool_destroy(mShmPool);
113 if (!margins.
isNull() && margins != mMargins) {
115 delete mMarginsImage;
125 delete mMarginsImage;
126 mMarginsImage =
nullptr;
133 return mMarginsImage;
142 auto copy = mBuffers;
147 mFrontBuffer =
nullptr;
158 w->setBackingStore(
nullptr);
171void QWaylandShmBackingStore::updateDirtyStates(
const QRegion ®ion)
176 if (
b != mBackBuffer)
177 b->dirtyRegion() += region;
198 p.fillRect(
rect, blank);
223 mPendingRegion |= region;
224 mPendingFlush =
true;
228 mPendingFlush =
false;
234 mFrontBuffer = mBackBuffer;
242 mRequestedSize =
size;
247 bufferWasRecreated =
false;
249 const auto copy = mBuffers;
252 if (
b->size() ==
size) {
256 if (mBackBuffer ==
b)
257 mBackBuffer =
nullptr;
263 static const size_t MAX_BUFFERS = 5;
264 if (mBuffers.size() < MAX_BUFFERS) {
267 bufferWasRecreated =
true;
268 mBuffers.push_front(
b);
276 bool bufferWasRecreated =
false;
291 qCDebug(lcWaylandBackingstore,
"QWaylandShmBackingStore: stalling waiting for a buffer to be released from the compositor...");
294 buffer = getBuffer(sizeWithMargins, bufferWasRecreated);
301 if (mBackBuffer !=
buffer && oldSizeInBytes == newSizeInBytes) {
310 const qreal sourceDevicePixelRatio = sourceImage->devicePixelRatio();
312 painter.
scale(1.0 / targetDevicePixelRatio, 1.0 / targetDevicePixelRatio);
316 QSizeF(
rect.size()) * sourceDevicePixelRatio);
318 QSizeF(
rect.size()) * targetDevicePixelRatio);
327 if (mBuffers.front() !=
buffer) {
329 mBuffers.push_front(
buffer);
337 return bufferWasRecreated;
342 return mBackBuffer->
image();
350void QWaylandShmBackingStore::updateDecorations()
357 int dpWidth = int(sourceImage.width() / dp);
358 int dpHeight = int(sourceImage.height() / dp);
360 sourceMatrix.
scale(dp, dp);
369 decorationPainter.drawImage(
target, sourceImage, sourceMatrix.mapRect(
target));
374 target.setHeight(dpHeight);
375 decorationPainter.drawImage(
target, sourceImage, sourceMatrix.mapRect(
target));
381 decorationPainter.drawImage(
target, sourceImage, sourceMatrix.mapRect(
target));
389 decorationPainter.drawImage(
target, sourceImage, sourceMatrix.mapRect(
target));
392 updateDirtyStates(dirtyRegion);
The QColor class provides colors based on RGB, HSV or CMYK values.
QFILE_MAYBE_NODISCARD 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.
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
qreal devicePixelRatio() const
The QPainter class performs low-level painting on widgets and other paint devices.
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or \nullptr if the painter is n...
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Draws the rectangular portion source of the given image into the target rectangle in the paint device...
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
The QRegion class specifies a clip region for a painter.
QRegion translated(int dx, int dy) const
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)
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
bool recreateBackBufferIfNeeded()
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)
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
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
const void GLsizei GLsizei stride
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