6#include <QtCore/qglobal.h>
7#include <QtCore/qrect.h>
8#include <QtCore/qpoint.h>
9#include <QtCore/qdatastream.h>
10#include <QtCore/qstack.h>
11#include <QtCore/qendian.h>
12#include <QtCore/qvarlengtharray.h>
78 return deallocateInNode(
rect.topLeft(), m_root);
83 if (
size.width() > currentRect.width() ||
size.height() > currentRect.height())
92 result = currentRect.topLeft();
99 QRect splitRect = currentRect;
100 if ((currentRect.width() -
size.width()) * currentRect.height() < (currentRect.height() -
size.height()) * currentRect.width()) {
102 node->
split = currentRect.top() +
size.height();
103 splitRect.setHeight(
size.height());
106 node->
split = currentRect.left() +
size.width();
107 splitRect.setWidth(
size.width());
113 QRect leftRect = currentRect;
114 QRect rightRect = currentRect;
117 rightRect.setTop(node->
split);
119 leftRect.setWidth(node->
split - leftRect.left());
120 rightRect.setLeft(node->
split);
140 mergeNodeWithNeighbors(node);
153 if (node->
parent ==
nullptr)
178 while (parent && current == parent->
left && parent->
splitType == splitType) {
183 if (parent && parent->
splitType == splitType) {
188 while (neighbor->right && neighbor->splitType == splitType)
189 neighbor = neighbor->
right;
191 if (neighbor->isLeaf() && neighbor->parent->splitType == splitType && !neighbor->isOccupied) {
193 parent->
split = neighbor->parent->split;
195 parent = neighbor->
parent;
196 sibling = neighbor == parent->
left ? parent->
right : parent->
left;
216 while (parent && current == parent->
right && parent->
splitType == splitType) {
221 if (parent && parent->
splitType == splitType) {
226 while (neighbor->left && neighbor->splitType == splitType)
227 neighbor = neighbor->
left;
229 if (neighbor->isLeaf() && neighbor->parent->splitType == splitType && !neighbor->isOccupied) {
231 parent->
split = neighbor->parent->split;
233 parent = neighbor->
parent;
234 sibling = neighbor == parent->
left ? parent->
right : parent->
left;
254 struct AreaAllocatorTable
280 template <
typename T>
286 template <
typename T>
296 QVarLengthArray<QSGAreaAllocatorNode *> nodesToProcess;
298 QStack<QSGAreaAllocatorNode *> nodes;
300 while (!nodes.isEmpty()) {
303 nodesToProcess.append(node);
304 if (node->
left !=
nullptr)
305 nodes.push(node->
left);
306 if (node->
right !=
nullptr)
307 nodes.push(node->
right);
311 ret.
resize(AreaAllocatorTable::HeaderSize + AreaAllocatorTable::NodeSize * nodesToProcess.size());
314 AreaAllocatorTable::put(
data, AreaAllocatorTable::majorVersion,
quint8(5));
315 AreaAllocatorTable::put(
data, AreaAllocatorTable::minorVersion,
quint8(12));
316 AreaAllocatorTable::put(
data, AreaAllocatorTable::width,
quint32(m_size.
width()));
317 AreaAllocatorTable::put(
data, AreaAllocatorTable::height,
quint32(m_size.
height()));
319 data += AreaAllocatorTable::HeaderSize;
321 AreaAllocatorTable::put(
data, AreaAllocatorTable::split,
qint32(node->
split));
325 (node->
isOccupied ? AreaAllocatorTable::IsOccupied : 0)
326 | (node->
left !=
nullptr ? AreaAllocatorTable::HasLeft : 0)
327 | (node->
right !=
nullptr ? AreaAllocatorTable::HasRight : 0);
328 AreaAllocatorTable::put(
data, AreaAllocatorTable::flags,
flags);
329 data += AreaAllocatorTable::NodeSize;
337 if (
uint(
size) < AreaAllocatorTable::HeaderSize) {
338 qWarning(
"QSGAreaAllocator::deserialize: Data not long enough to fit header");
344 quint8 majorVersion = AreaAllocatorTable::fetch<quint8>(
data, AreaAllocatorTable::majorVersion);
345 quint8 minorVersion = AreaAllocatorTable::fetch<quint8>(
data, AreaAllocatorTable::minorVersion);
346 if (majorVersion != 5 || minorVersion != 12) {
347 qWarning(
"Unrecognized version %d.%d of QSGAreaAllocator",
353 m_size =
QSize(AreaAllocatorTable::fetch<quint32>(
data, AreaAllocatorTable::width),
354 AreaAllocatorTable::fetch<quint32>(
data, AreaAllocatorTable::height));
360 QStack<QSGAreaAllocatorNode *> nodes;
363 data += AreaAllocatorTable::HeaderSize;
364 while (!nodes.isEmpty()) {
365 if (
data + AreaAllocatorTable::NodeSize >
end) {
366 qWarning(
"QSGAreaAllocator::deseriable: Data not long enough for nodes");
372 node->
split = AreaAllocatorTable::fetch<qint32>(
data, AreaAllocatorTable::split);
375 quint8 flags = AreaAllocatorTable::fetch<quint8>(
data, AreaAllocatorTable::flags);
378 if (
flags & AreaAllocatorTable::HasLeft) {
380 nodes.push(node->
left);
383 if (
flags & AreaAllocatorTable::HasRight) {
385 nodes.push(node->
right);
388 data += AreaAllocatorTable::NodeSize;
void resize(qsizetype size)
Sets the size of the byte array to size bytes.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr void setHeight(int h) noexcept
Sets the height of the rectangle to the given height.
QSGAreaAllocator(const QSize &size)
const char * deserialize(const char *data, int size)
QRect allocate(const QSize &size)
bool deallocate(const QRect &rect)
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
QPair< bool, quint32 > HeaderSize
QList< QAnyStringView > split(QAnyStringView source, QLatin1StringView sep)
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr T qToBigEndian(T source)
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
static const int maxMargin
manager put(request, myData, this, [this](QRestReply &reply) { if(reply.isSuccess()) })
[5]
QSGAreaAllocatorNode(QSGAreaAllocatorNode *parent)
QSGAreaAllocatorNode * parent
QSGAreaAllocatorNode * right
QSGAreaAllocatorNode * left