effects/magnifier: Reduce the number of heap allocations

Reserve enough of space for all vertices instead of dynamically
expanding the QVector to accommodate for new data.
This commit is contained in:
Vlad Zahorodnii 2023-02-23 23:33:10 +02:00
parent 42cff94f72
commit a62dc13161

View file

@ -132,13 +132,15 @@ void MagnifierEffect::paintScreen(int mask, const QRegion &region, ScreenPaintDa
m_texture->render(area.size(), scale);
ShaderManager::instance()->popShader();
m_texture->unbind();
QVector<float> verts;
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
vbo->reset();
vbo->setColor(QColor(0, 0, 0));
QRectF areaF = scaledRect(area, scale);
const QRectF frame = scaledRect(area.adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH), scale);
QVector<float> verts;
verts.reserve(4 * 6 * 2);
// top frame
verts << frame.right() << frame.top();
verts << frame.left() << frame.top();