QWindowsGLContext: replace homebrew Array with std::vector

std::vector is all that the Array original author dreamed about,
and more: never shrinks capacity, non CoWed, ...

Appart from append(), the Array API was modeled after std::vector
(size_t size_type, etc) already, so the port to std::vector is
minimal. The only change besides append() -> push_back() was not
assuming const_iterator being const T*.

Remove now-unused Array.

Change-Id: I02bc71441d01e554e320746d82dbc00f74c5466d
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
Marc Mutz 2016-02-18 20:20:09 +01:00
parent 611942f2d7
commit a425b5f19c
4 changed files with 12 additions and 115 deletions

View File

@ -1,102 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef ARRAY_H
#define ARRAY_H
#include <QtCore/QtGlobal>
#include <algorithm>
QT_BEGIN_NAMESPACE
/* A simple, non-shared array. */
template <class T>
class Array
{
Q_DISABLE_COPY(Array)
public:
enum { initialSize = 5 };
typedef T* const_iterator;
explicit Array(size_t size= 0) : data(0), m_capacity(0), m_size(0)
{ if (size) resize(size); }
~Array() { delete [] data; }
T *data;
inline size_t size() const { return m_size; }
inline const_iterator begin() const { return data; }
inline const_iterator end() const { return data + m_size; }
inline void append(const T &value)
{
const size_t oldSize = m_size;
resize(m_size + 1);
data[oldSize] = value;
}
inline void resize(size_t size)
{
if (size > m_size)
reserve(size > 1 ? size + size / 2 : size_t(initialSize));
m_size = size;
}
void reserve(size_t capacity)
{
if (capacity > m_capacity) {
const T *oldData = data;
data = new T[capacity];
if (oldData) {
std::copy(oldData, oldData + m_size, data);
delete [] oldData;
}
m_capacity = capacity;
}
}
private:
size_t m_capacity;
size_t m_size;
};
QT_END_NAMESPACE
#endif // ARRAY_H

View File

@ -1270,10 +1270,9 @@ bool QWindowsGLContext::updateObtainedParams(HDC hdc, int *obtainedSwapInterval)
void QWindowsGLContext::releaseDCs()
{
const QOpenGLContextData *end = m_windowContexts.end();
for (const QOpenGLContextData *p = m_windowContexts.begin(); p < end; ++p)
ReleaseDC(p->hwnd, p->hdc);
m_windowContexts.resize(0);
for (const auto &e : m_windowContexts)
ReleaseDC(e.hwnd, e.hdc);
m_windowContexts.clear();
}
static inline QWindowsWindow *glWindowOf(QPlatformSurface *s)
@ -1288,12 +1287,12 @@ static inline HWND handleOf(QPlatformSurface *s)
// Find a window in a context list.
static inline const QOpenGLContextData *
findByHWND(const Array<QOpenGLContextData> &data, HWND hwnd)
findByHWND(const std::vector<QOpenGLContextData> &data, HWND hwnd)
{
const QOpenGLContextData *end = data.end();
for (const QOpenGLContextData *p = data.begin(); p < end; ++p)
if (p->hwnd == hwnd)
return p;
for (const auto &e : data) {
if (e.hwnd == hwnd)
return &e;
}
return 0;
}
@ -1347,7 +1346,7 @@ bool QWindowsGLContext::makeCurrent(QPlatformSurface *surface)
if (m_obtainedFormat.swapBehavior() == QSurfaceFormat::DoubleBuffer)
window->setFlag(QWindowsWindow::OpenGLDoubleBuffered);
}
m_windowContexts.append(newContext);
m_windowContexts.push_back(newContext);
m_lost = false;
bool success = QOpenGLStaticContext::opengl32.wglMakeCurrent(newContext.hdc, newContext.renderingContext);

View File

@ -40,12 +40,13 @@
#ifndef QWINDOWSGLCONTEXT_H
#define QWINDOWSGLCONTEXT_H
#include "array.h"
#include "qtwindows_additional.h"
#include "qwindowsopenglcontext.h"
#include <QtGui/QOpenGLContext>
#include <vector>
QT_BEGIN_NAMESPACE
class QDebug;
@ -264,7 +265,7 @@ private:
QOpenGLContext *m_context;
QSurfaceFormat m_obtainedFormat;
HGLRC m_renderingContext;
Array<QOpenGLContextData> m_windowContexts;
std::vector<QOpenGLContextData> m_windowContexts;
PIXELFORMATDESCRIPTOR m_obtainedPixelFormatDescriptor;
int m_pixelFormat;
bool m_extensionsUsed;

View File

@ -55,7 +55,6 @@ HEADERS += \
$$PWD/qwindowsmime.h \
$$PWD/qwindowsinternalmimedata.h \
$$PWD/qwindowscursor.h \
$$PWD/array.h \
$$PWD/qwindowsinputcontext.h \
$$PWD/qwindowstheme.h \
$$PWD/qwindowsdialoghelpers.h \