QVector<BufferSharedPtr>::iterator ShmPoolPrivate::reuseBuffer(const QSize &s, qint32 stride, Shm::Format format) { Q_Q(ShmPool); // We can't return a shared pointer here so we just return // the iterator of the buffers vector that can be used to // retrieve the actual shared pointer // Try to reuse an existing buffer for (auto it = buffers.begin(); it != buffers.end(); ++it) { QSharedPointer<Buffer> buffer = (*it); // Skip buffers that are in use or do not match what the user is looking for if (!buffer->isReleased() || buffer->isUsed()) continue; if (buffer->size() != s || buffer->stride() != stride || buffer->format() != format) continue; // We found the buffer buffer->setReleased(false); return it; } // No buffer found: resize the pool to accomodate a new buffer const qint32 bytesCount = s.height() * stride; if (offset + bytesCount > size) { if (!resizePool(bytesCount + size)) return Q_NULLPTR; } // No buffer can be reused, create a new one and advance the offset wl_buffer *nativeBuffer = create_buffer(offset, s.width(), s.height(), stride, format); if (!nativeBuffer) return Q_NULLPTR; Buffer *buffer = new Buffer(q, s, stride, offset, format); BufferPrivate::get(buffer)->init(nativeBuffer); offset += bytesCount; return buffers.insert(buffers.end(), BufferSharedPtr(buffer)); }
const BufferSharedPtr & VertexAttributeSet::getVertexBuffer(unsigned int attrib) const { return BufferSharedPtr (); }