5#include <private/qobject_p.h>
6#include <private/qimage_p.h>
8#include <QtCore/qpointer.h>
9#include <QSharedMemory>
28#if QT_CONFIG(sharedmemory)
29struct SharedImageInfo {
31 QPointer<QSharedMemory> shmp;
38 SharedImageInfo *sii =
static_cast<SharedImageInfo *
>(cleanupInfo);
39 qCDebug(lcSharedImage) <<
"Cleanup called for" << sii->path;
40 if (sii->shmp.isNull()) {
41 qCDebug(lcSharedImage) <<
"shm is 0 for" << sii->path;
44 QSharedMemory *shm = sii->shmp.data();
79 h->width =
img.width();
80 h->height =
img.height();
81 h->bpl =
img.bytesPerLine();
82 h->format =
img.format();
85 memcpy(
p,
img.constBits(),
img.sizeInBytes());
107 if (
h->height *
h->bpl > availSize)
128#if QT_CONFIG(sharedmemory)
135 auto shm = std::make_unique<QSharedMemory>(QSharedMemory::legacyNativeKey(
q->key(
path,
params)));
138 if (!shm->attach(QSharedMemory::ReadOnly)) {
143 if (
size >
size_t(std::numeric_limits<int>::max())) {
144 qCDebug(lcSharedImage) <<
"Image" <<
path <<
"to large to load";
146 }
else if (shm->create(
int(
size))) {
147 qCDebug(lcSharedImage) <<
"Created new shm segment of size" <<
size <<
"for image" <<
path;
149 qCDebug(lcSharedImage) <<
"Lock1 failed!?" << shm->errorString();
154 }
else if (shm->error() == QSharedMemory::AlreadyExists) {
157 if (!shm->attach(QSharedMemory::ReadOnly)) {
158 qCDebug(lcSharedImage) <<
"Attach to existing failed?" << shm->errorString();
162 qCDebug(lcSharedImage) <<
"Create failed?" << shm->errorString();
171 qCDebug(lcSharedImage) <<
"Lock2 failed!?" << shm->errorString();
177 if (!
verifyMem(shm->constData(), shm->size())) {
178 qCDebug(lcSharedImage) <<
"Verifymem failed!?";
183 QSharedMemory *shmp = shm.release();
184 SharedImageInfo *sii =
new SharedImageInfo;
189 if (!shmp->unlock()) {
190 qCDebug(lcSharedImage) <<
"UnLock failed!?";
235#include "moc_qsharedimageloader_p.cpp"
qsizetype sizeInBytes() const
Format
The following image formats are available in Qt.
void storeImageToMem(void *data, const QImage &img)
bool verifyMem(const void *data, int size)
QImage createImageFromMem(const void *data, void *cleanupInfo)
QImage load(const QString &path, QSharedImageLoader::ImageParameters *params)
QSharedImageLoaderPrivate()
QSharedImageLoader(QObject *parent=nullptr)
virtual QString key(const QString &path, ImageParameters *params)
virtual QImage loadFile(const QString &path, ImageParameters *params)
QImage load(const QString &path, ImageParameters *params=nullptr)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Combined button and popup list for selecting options.
#define Q_STATIC_ASSERT(Condition)
int qt_depthForFormat(QImage::Format format)
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
void cleanupSharedImage(void *)