From 498f938f2d0a206b6864457cac9f96b179ac1216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Tue, 26 Apr 2011 09:56:43 +0200 Subject: Just some more on QWindow. Nothing works (cherry picked from commit 3acf7aa979630a57791e2a039b1b7b0b85b0aac8) --- src/gui/kernel/kernel.pri | 24 +- src/gui/kernel/qplatformintegration_qpa.h | 7 +- src/gui/kernel/qplatformwindowformat_qpa.cpp | 1008 -------------------------- src/gui/kernel/qplatformwindowformat_qpa.h | 290 -------- src/gui/kernel/qwindow_qpa.cpp | 305 ++++++++ src/gui/kernel/qwindow_qpa.h | 136 ++++ src/gui/kernel/qwindowformat_qpa.cpp | 1008 ++++++++++++++++++++++++++ src/gui/kernel/qwindowformat_qpa.h | 210 ++++++ 8 files changed, 1676 insertions(+), 1312 deletions(-) delete mode 100644 src/gui/kernel/qplatformwindowformat_qpa.cpp delete mode 100644 src/gui/kernel/qplatformwindowformat_qpa.h create mode 100644 src/gui/kernel/qwindow_qpa.cpp create mode 100644 src/gui/kernel/qwindow_qpa.h create mode 100644 src/gui/kernel/qwindowformat_qpa.cpp create mode 100644 src/gui/kernel/qwindowformat_qpa.h diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 3c57368bab..03313aa434 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -210,7 +210,7 @@ embedded { qpa { HEADERS += \ - kernel/qgenericpluginfactory_qpa.h \ + kernel/qgenericpluginfactory_qpa.h \ kernel/qgenericplugin_qpa.h \ kernel/qeventdispatcher_qpa_p.h \ kernel/qwindowsysteminterface_qpa.h \ @@ -226,17 +226,18 @@ qpa { kernel/qplatformeventloopintegration_qpa.h \ kernel/qplatformcursor_qpa.h \ kernel/qplatformclipboard_qpa.h \ - kernel/qplatformnativeinterface_qpa.h + kernel/qplatformnativeinterface_qpa.h \ + kernel/qwindow_qpa.cpp SOURCES += \ - kernel/qapplication_qpa.cpp \ - kernel/qclipboard_qpa.cpp \ - kernel/qcursor_qpa.cpp \ - kernel/qdnd_qws.cpp \ - kernel/qdesktopwidget_qpa.cpp \ - kernel/qgenericpluginfactory_qpa.cpp \ - kernel/qgenericplugin_qpa.cpp \ - kernel/qkeymapper_qws.cpp \ + kernel/qapplication_qpa.cpp \ + kernel/qclipboard_qpa.cpp \ + kernel/qcursor_qpa.cpp \ + kernel/qdnd_qws.cpp \ + kernel/qdesktopwidget_qpa.cpp \ + kernel/qgenericpluginfactory_qpa.cpp \ + kernel/qgenericplugin_qpa.cpp \ + kernel/qkeymapper_qws.cpp \ kernel/qwidget_qpa.cpp \ kernel/qeventdispatcher_qpa.cpp \ kernel/qwindowsysteminterface_qpa.cpp \ @@ -251,7 +252,8 @@ qpa { kernel/qplatformcursor_qpa.cpp \ kernel/qplatformclipboard_qpa.cpp \ kernel/qplatformnativeinterface_qpa.cpp \ - kernel/qsessionmanager_qpa.cpp + kernel/qsessionmanager_qpa.cpp \ + kernel/qwindow_qpa.cpp contains(QT_CONFIG, glib) { SOURCES += \ diff --git a/src/gui/kernel/qplatformintegration_qpa.h b/src/gui/kernel/qplatformintegration_qpa.h index d06272ce01..1517fc4fce 100644 --- a/src/gui/kernel/qplatformintegration_qpa.h +++ b/src/gui/kernel/qplatformintegration_qpa.h @@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Gui) class QPlatformWindow; -class QWindowSurface; +class QWindow; class QBlittable; class QWidget; class QPlatformEventLoopIntegration; @@ -62,6 +62,7 @@ class QPlatformFontDatabase; class QPlatformClipboard; class QPlatformNativeInterface; + class Q_GUI_EXPORT QPlatformIntegration { public: @@ -76,8 +77,8 @@ public: // GraphicsSystem functions virtual QPixmapData *createPixmapData(QPixmapData::PixelType type) const = 0; - virtual QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const = 0; - virtual QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const = 0; + virtual QPlatformWindow *createPlatformWindow(QWindow *window, const QWindowFormat &format) const = 0; + virtual QWindowSurface *createWindowSurface(QWindow *window, WId winId) const = 0; // Window System functions virtual QList screens() const = 0; diff --git a/src/gui/kernel/qplatformwindowformat_qpa.cpp b/src/gui/kernel/qplatformwindowformat_qpa.cpp deleted file mode 100644 index c165c8513a..0000000000 --- a/src/gui/kernel/qplatformwindowformat_qpa.cpp +++ /dev/null @@ -1,1008 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qplatformwindowformat_qpa.h" - -#include - -Q_GLOBAL_STATIC(QPlatformWindowFormat, q_platformwindow_default_format); - -class QPlatformWindowFormatPrivate -{ -public: - QPlatformWindowFormatPrivate() - : ref(1) - , opts(QPlatformWindowFormat::DoubleBuffer | QPlatformWindowFormat::DepthBuffer - | QPlatformWindowFormat::Rgba | QPlatformWindowFormat::DirectRendering - | QPlatformWindowFormat::StencilBuffer | QPlatformWindowFormat::DeprecatedFunctions - | QPlatformWindowFormat::HasWindowSurface) - , depthSize(-1) - , accumSize(-1) - , stencilSize(-1) - , redSize(-1) - , greenSize(-1) - , blueSize(-1) - , alphaSize(-1) - , numSamples(-1) - , swapInterval(-1) - , windowApi(QPlatformWindowFormat::Raster) - , sharedContext(0) - { - } - - QPlatformWindowFormatPrivate(const QPlatformWindowFormatPrivate *other) - : ref(1), - opts(other->opts), - depthSize(other->depthSize), - accumSize(other->accumSize), - stencilSize(other->stencilSize), - redSize(other->redSize), - greenSize(other->greenSize), - blueSize(other->blueSize), - alphaSize(other->alphaSize), - numSamples(other->numSamples), - swapInterval(other->swapInterval), - windowApi(other->windowApi), - sharedContext(other->sharedContext) - { - } - QAtomicInt ref; - QPlatformWindowFormat::FormatOptions opts; - int depthSize; - int accumSize; - int stencilSize; - int redSize; - int greenSize; - int blueSize; - int alphaSize; - int numSamples; - int swapInterval; - QPlatformWindowFormat::WindowApi windowApi; - QPlatformGLContext *sharedContext; -}; - -/*! - \class QPlatformWindowFormat - \brief The QPlatformWindowFormat class specifies the display format of an OpenGL - rendering context and if possible attributes of the corresponding QPlatformWindow. - - \ingroup painting - - QWidget has a setter and getter function for QPlatformWindowFormat. These functions can be used - by the application programmer to signal what kind of format he wants to the window and glcontext - should have. However, it is not always possible to fulfill these requirements. The application - programmer should therefore check the resulting QPlatformWindowFormat from QPlatformGLContext - to see the format that was actually created. - - A display format has several characteristics: - \list - \i \link setDoubleBuffer() Double or single buffering.\endlink - \i \link setDepth() Depth buffer.\endlink - \i \link setRgba() RGBA or color index mode.\endlink - \i \link setAlpha() Alpha channel.\endlink - \i \link setAccum() Accumulation buffer.\endlink - \i \link setStencil() Stencil buffer.\endlink - \i \link setStereo() Stereo buffers.\endlink - \i \link setDirectRendering() Direct rendering.\endlink - \i \link setOverlay() Presence of an overlay.\endlink - \i \link setPlane() Plane of an overlay.\endlink - \i \link setSampleBuffers() Multisample buffers.\endlink - \endlist - - You can also specify preferred bit depths for the color buffer, - depth buffer, alpha buffer, accumulation buffer and the stencil - buffer with the functions: setRedBufferSize(), setGreenBufferSize(), - setBlueBufferSize(), setDepthBufferSize(), setAlphaBufferSize(), - setAccumBufferSize() and setStencilBufferSize(). - - Note that even if you specify that you prefer a 32 bit depth - buffer (e.g. with setDepthBufferSize(32)), the format that is - chosen may not have a 32 bit depth buffer, even if there is a - format available with a 32 bit depth buffer. The main reason for - this is how the system dependant picking algorithms work on the - different platforms, and some format options may have higher - precedence than others. - - You create and tell a QPlatformWindowFormat object what rendering options you - want from an OpenGL rendering context. - - OpenGL drivers or accelerated hardware may or may not support - advanced features such as alpha channel or stereographic viewing. - If you request some features that the driver/hardware does not - provide when you create a QGLWidget, you will get a rendering - context with the nearest subset of features. - - There are different ways to define the display characteristics of - a rendering context. One is to create a QPlatformWindowFormat and make it the - default for the entire application: - \snippet doc/src/snippets/code/src_opengl_qgl.cpp 0 - - Or you can specify the desired format when creating an object of - your QGLWidget subclass: - \snippet doc/src/snippets/code/src_opengl_qgl.cpp 1 - - After the widget has been created, you can find out which of the - requested features the system was able to provide: - \snippet doc/src/snippets/code/src_opengl_qgl.cpp 2 - - \legalese - OpenGL is a trademark of Silicon Graphics, Inc. in the - United States and other countries. - \endlegalese - - \sa QPlatformContext, QWidget -*/ - -/*! - Constructs a QPlatformWindowFormat object with the following default settings: - \list - \i \link setDoubleBuffer() Double buffer:\endlink Enabled. - \i \link setDepth() Depth buffer:\endlink Enabled. - \i \link setRgba() RGBA:\endlink Enabled (i.e., color index disabled). - \i \link setAlpha() Alpha channel:\endlink Disabled. - \i \link setAccum() Accumulator buffer:\endlink Disabled. - \i \link setStencil() Stencil buffer:\endlink Enabled. - \i \link setStereo() Stereo:\endlink Disabled. - \i \link setDirectRendering() Direct rendering:\endlink Enabled. - \i \link setOverlay() Overlay:\endlink Disabled. - \i \link setPlane() Plane:\endlink 0 (i.e., normal plane). - \i \link setSampleBuffers() Multisample buffers:\endlink Disabled. - \endlist -*/ - -QPlatformWindowFormat::QPlatformWindowFormat() -{ - d = new QPlatformWindowFormatPrivate; -} - - -/*! - Creates a QPlatformWindowFormat object that is a copy of the current - defaultFormat(). - - If \a options is not 0, the default format is modified by the - specified format options. The \a options parameter should be - QGL::FormatOption values OR'ed together. - - This constructor makes it easy to specify a certain desired format - in classes derived from QGLWidget, for example: - \snippet doc/src/snippets/code/src_opengl_qgl.cpp 3 - - Note that there are QGL::FormatOption values to turn format settings - both on and off, e.g. QGL::DepthBuffer and QGL::NoDepthBuffer, - QGL::DirectRendering and QGL::IndirectRendering, etc. - - The \a plane parameter defaults to 0 and is the plane which this - format should be associated with. Not all OpenGL implementations - supports overlay/underlay rendering planes. - - \sa defaultFormat(), setOption(), setPlane() -*/ - -QPlatformWindowFormat::QPlatformWindowFormat(QPlatformWindowFormat::FormatOptions options) -{ - d = new QPlatformWindowFormatPrivate; - QPlatformWindowFormat::FormatOptions newOpts = options; - d->opts = defaultFormat().d->opts; - d->opts |= (newOpts & 0xffff); - d->opts &= ~(newOpts >> 16); -} - -/*! - \internal -*/ -void QPlatformWindowFormat::detach() -{ - if (d->ref != 1) { - QPlatformWindowFormatPrivate *newd = new QPlatformWindowFormatPrivate(d); - if (!d->ref.deref()) - delete d; - d = newd; - } -} - -/*! - Constructs a copy of \a other. -*/ - -QPlatformWindowFormat::QPlatformWindowFormat(const QPlatformWindowFormat &other) -{ - d = other.d; - d->ref.ref(); -} - -/*! - Assigns \a other to this object. -*/ - -QPlatformWindowFormat &QPlatformWindowFormat::operator=(const QPlatformWindowFormat &other) -{ - if (d != other.d) { - other.d->ref.ref(); - if (!d->ref.deref()) - delete d; - d = other.d; - } - return *this; -} - -/*! - Destroys the QPlatformWindowFormat. -*/ -QPlatformWindowFormat::~QPlatformWindowFormat() -{ - if (!d->ref.deref()) - delete d; -} - -/*! - \fn bool QPlatformWindowFormat::doubleBuffer() const - - Returns true if double buffering is enabled; otherwise returns - false. Double buffering is enabled by default. - - \sa setDoubleBuffer() -*/ - -/*! - If \a enable is true sets double buffering; otherwise sets single - buffering. - - Double buffering is enabled by default. - - Double buffering is a technique where graphics are rendered on an - off-screen buffer and not directly to the screen. When the drawing - has been completed, the program calls a swapBuffers() function to - exchange the screen contents with the buffer. The result is - flicker-free drawing and often better performance. - - \sa doubleBuffer(), QGLContext::swapBuffers(), - QGLWidget::swapBuffers() -*/ - -void QPlatformWindowFormat::setDoubleBuffer(bool enable) -{ - setOption(enable ? QPlatformWindowFormat::DoubleBuffer : QPlatformWindowFormat::SingleBuffer); -} - - -/*! - \fn bool QPlatformWindowFormat::depth() const - - Returns true if the depth buffer is enabled; otherwise returns - false. The depth buffer is enabled by default. - - \sa setDepth(), setDepthBufferSize() -*/ - -/*! - If \a enable is true enables the depth buffer; otherwise disables - the depth buffer. - - The depth buffer is enabled by default. - - The purpose of a depth buffer (or Z-buffering) is to remove hidden - surfaces. Pixels are assigned Z values based on the distance to - the viewer. A pixel with a high Z value is closer to the viewer - than a pixel with a low Z value. This information is used to - decide whether to draw a pixel or not. - - \sa depth(), setDepthBufferSize() -*/ - -void QPlatformWindowFormat::setDepth(bool enable) -{ - setOption(enable ? QPlatformWindowFormat::DepthBuffer : QPlatformWindowFormat::NoDepthBuffer); -} - - -/*! - \fn bool QPlatformWindowFormat::rgba() const - - Returns true if RGBA color mode is set. Returns false if color - index mode is set. The default color mode is RGBA. - - \sa setRgba() -*/ - -/*! - If \a enable is true sets RGBA mode. If \a enable is false sets - color index mode. - - The default color mode is RGBA. - - RGBA is the preferred mode for most OpenGL applications. In RGBA - color mode you specify colors as red + green + blue + alpha - quadruplets. - - In color index mode you specify an index into a color lookup - table. - - \sa rgba() -*/ - -void QPlatformWindowFormat::setRgba(bool enable) -{ - setOption(enable ? QPlatformWindowFormat::Rgba : QPlatformWindowFormat::ColorIndex); -} - - -/*! - \fn bool QPlatformWindowFormat::alpha() const - - Returns true if the alpha buffer in the framebuffer is enabled; - otherwise returns false. The alpha buffer is disabled by default. - - \sa setAlpha(), setAlphaBufferSize() -*/ - -/*! - If \a enable is true enables the alpha buffer; otherwise disables - the alpha buffer. - - The alpha buffer is disabled by default. - - The alpha buffer is typically used for implementing transparency - or translucency. The A in RGBA specifies the transparency of a - pixel. - - \sa alpha(), setAlphaBufferSize() -*/ - -void QPlatformWindowFormat::setAlpha(bool enable) -{ - setOption(enable ? QPlatformWindowFormat::AlphaChannel : QPlatformWindowFormat::NoAlphaChannel); -} - - -/*! - \fn bool QPlatformWindowFormat::accum() const - - Returns true if the accumulation buffer is enabled; otherwise - returns false. The accumulation buffer is disabled by default. - - \sa setAccum(), setAccumBufferSize() -*/ - -/*! - If \a enable is true enables the accumulation buffer; otherwise - disables the accumulation buffer. - - The accumulation buffer is disabled by default. - - The accumulation buffer is used to create blur effects and - multiple exposures. - - \sa accum(), setAccumBufferSize() -*/ - -void QPlatformWindowFormat::setAccum(bool enable) -{ - setOption(enable ? QPlatformWindowFormat::AccumBuffer : QPlatformWindowFormat::NoAccumBuffer); -} - - -/*! - \fn bool QPlatformWindowFormat::stencil() const - - Returns true if the stencil buffer is enabled; otherwise returns - false. The stencil buffer is enabled by default. - - \sa setStencil(), setStencilBufferSize() -*/ - -/*! - If \a enable is true enables the stencil buffer; otherwise - disables the stencil buffer. - - The stencil buffer is enabled by default. - - The stencil buffer masks certain parts of the drawing area so that - masked parts are not drawn on. - - \sa stencil(), setStencilBufferSize() -*/ - -void QPlatformWindowFormat::setStencil(bool enable) -{ - setOption(enable ? QPlatformWindowFormat::StencilBuffer: QPlatformWindowFormat::NoStencilBuffer); -} - - -/*! - \fn bool QPlatformWindowFormat::stereo() const - - Returns true if stereo buffering is enabled; otherwise returns - false. Stereo buffering is disabled by default. - - \sa setStereo() -*/ - -/*! - If \a enable is true enables stereo buffering; otherwise disables - stereo buffering. - - Stereo buffering is disabled by default. - - Stereo buffering provides extra color buffers to generate left-eye - and right-eye images. - - \sa stereo() -*/ - -void QPlatformWindowFormat::setStereo(bool enable) -{ - setOption(enable ? QPlatformWindowFormat::StereoBuffers : QPlatformWindowFormat::NoStereoBuffers); -} - - -/*! - \fn bool QPlatformWindowFormat::directRendering() const - - Returns true if direct rendering is enabled; otherwise returns - false. - - Direct rendering is enabled by default. - - \sa setDirectRendering() -*/ - -/*! - If \a enable is true enables direct rendering; otherwise disables - direct rendering. - - Direct rendering is enabled by default. - - Enabling this option will make OpenGL bypass the underlying window - system and render directly from hardware to the screen, if this is - supported by the system. - - \sa directRendering() -*/ - -void QPlatformWindowFormat::setDirectRendering(bool enable) -{ - setOption(enable ? QPlatformWindowFormat::DirectRendering : QPlatformWindowFormat::IndirectRendering); -} - -/*! - \fn bool QPlatformWindowFormat::sampleBuffers() const - - Returns true if multisample buffer support is enabled; otherwise - returns false. - - The multisample buffer is disabled by default. - - \sa setSampleBuffers() -*/ - -/*! - If \a enable is true, a GL context with multisample buffer support - is picked; otherwise ignored. - - \sa sampleBuffers(), setSamples(), samples() -*/ -void QPlatformWindowFormat::setSampleBuffers(bool enable) -{ - setOption(enable ? QPlatformWindowFormat::SampleBuffers : QPlatformWindowFormat::NoSampleBuffers); -} - -/*! - Returns the number of samples per pixel when multisampling is - enabled. By default, the highest number of samples that is - available is used. - - \sa setSampleBuffers(), sampleBuffers(), setSamples() -*/ -int QPlatformWindowFormat::samples() const -{ - return d->numSamples; -} - -/*! - Set the preferred number of samples per pixel when multisampling - is enabled to \a numSamples. By default, the highest number of - samples available is used. - - \sa setSampleBuffers(), sampleBuffers(), samples() -*/ -void QPlatformWindowFormat::setSamples(int numSamples) -{ - detach(); - if (numSamples < 0) { - qWarning("QPlatformWindowFormat::setSamples: Cannot have negative number of samples per pixel %d", numSamples); - return; - } - d->numSamples = numSamples; - setSampleBuffers(numSamples > 0); -} - -/*! - \since 4.2 - - Set the preferred swap interval. This can be used to sync the GL - drawing into a system window to the vertical refresh of the screen. - Setting an \a interval value of 0 will turn the vertical refresh syncing - off, any value higher than 0 will turn the vertical syncing on. - - Under Windows and under X11, where the \c{WGL_EXT_swap_control} - and \c{GLX_SGI_video_sync} extensions are used, the \a interval - parameter can be used to set the minimum number of video frames - that are displayed before a buffer swap will occur. In effect, - setting the \a interval to 10, means there will be 10 vertical - retraces between every buffer swap. - - Under Windows the \c{WGL_EXT_swap_control} extension has to be present, - and under X11 the \c{GLX_SGI_video_sync} extension has to be present. -*/ -void QPlatformWindowFormat::setSwapInterval(int interval) -{ - detach(); - d->swapInterval = interval; -} - -/*! - \since 4.2 - - Returns the currently set swap interval. -1 is returned if setting - the swap interval isn't supported in the system GL implementation. -*/ -int QPlatformWindowFormat::swapInterval() const -{ - return d->swapInterval; -} - -void QPlatformWindowFormat::setWindowApi(QPlatformWindowFormat::WindowApi api) -{ - detach(); - d->windowApi = api; -} - -QPlatformWindowFormat::WindowApi QPlatformWindowFormat::windowApi() const -{ - return d->windowApi; -} - -void QPlatformWindowFormat::setSharedContext(QPlatformGLContext *context) -{ - d->sharedContext = context; -} - -QPlatformGLContext *QPlatformWindowFormat::sharedGLContext() const -{ - return d->sharedContext; -} - -/*! - \fn bool QPlatformWindowFormat::hasWindowSurface() const - - Returns true if the corresponding widget has an instance of QWindowSurface. - - Otherwise returns false. - - WindowSurface is enabled by default. - - \sa setOverlay() -*/ - -/*! - If \a enable is true a top level QWidget will create a QWindowSurface at creation; - - otherwise the QWidget will only have a QPlatformWindow. - - This is useful for ie. QGLWidget where the QPlatformGLContext controls the surface. - - \sa hasOverlay() -*/ - -void QPlatformWindowFormat::setWindowSurface(bool enable) -{ - setOption(enable ? QPlatformWindowFormat::HasWindowSurface : QPlatformWindowFormat::NoWindowSurface); -} - -/*! - Sets the format option to \a opt. - - \sa testOption() -*/ - -void QPlatformWindowFormat::setOption(QPlatformWindowFormat::FormatOptions opt) -{ - detach(); - if (opt & 0xffff) - d->opts |= opt; - else - d->opts &= ~(opt >> 16); -} - - - -/*! - Returns true if format option \a opt is set; otherwise returns false. - - \sa setOption() -*/ - -bool QPlatformWindowFormat::testOption(QPlatformWindowFormat::FormatOptions opt) const -{ - if (opt & 0xffff) - return (d->opts & opt) != 0; - else - return (d->opts & (opt >> 16)) == 0; -} - -/*! - Set the minimum depth buffer size to \a size. - - \sa depthBufferSize(), setDepth(), depth() -*/ -void QPlatformWindowFormat::setDepthBufferSize(int size) -{ - detach(); - if (size < 0) { - qWarning("QPlatformWindowFormat::setDepthBufferSize: Cannot set negative depth buffer size %d", size); - return; - } - d->depthSize = size; - setDepth(size > 0); -} - -/*! - Returns the depth buffer size. - - \sa depth(), setDepth(), setDepthBufferSize() -*/ -int QPlatformWindowFormat::depthBufferSize() const -{ - return d->depthSize; -} - -/*! - \since 4.2 - - Set the preferred red buffer size to \a size. - - \sa setGreenBufferSize(), setBlueBufferSize(), setAlphaBufferSize() -*/ -void QPlatformWindowFormat::setRedBufferSize(int size) -{ - detach(); - if (size < 0) { - qWarning("QPlatformWindowFormat::setRedBufferSize: Cannot set negative red buffer size %d", size); - return; - } - d->redSize = size; -} - -/*! - \since 4.2 - - Returns the red buffer size. - - \sa setRedBufferSize() -*/ -int QPlatformWindowFormat::redBufferSize() const -{ - return d->redSize; -} - -/*! - \since 4.2 - - Set the preferred green buffer size to \a size. - - \sa setRedBufferSize(), setBlueBufferSize(), setAlphaBufferSize() -*/ -void QPlatformWindowFormat::setGreenBufferSize(int size) -{ - detach(); - if (size < 0) { - qWarning("QPlatformWindowFormat::setGreenBufferSize: Cannot set negative green buffer size %d", size); - return; - } - d->greenSize = size; -} - -/*! - \since 4.2 - - Returns the green buffer size. - - \sa setGreenBufferSize() -*/ -int QPlatformWindowFormat::greenBufferSize() const -{ - return d->greenSize; -} - -/*! - \since 4.2 - - Set the preferred blue buffer size to \a size. - - \sa setRedBufferSize(), setGreenBufferSize(), setAlphaBufferSize() -*/ -void QPlatformWindowFormat::setBlueBufferSize(int size) -{ - detach(); - if (size < 0) { - qWarning("QPlatformWindowFormat::setBlueBufferSize: Cannot set negative blue buffer size %d", size); - return; - } - d->blueSize = size; -} - -/*! - \since 4.2 - - Returns the blue buffer size. - - \sa setBlueBufferSize() -*/ -int QPlatformWindowFormat::blueBufferSize() const -{ - return d->blueSize; -} - -/*! - Set the preferred alpha buffer size to \a size. - This function implicitly enables the alpha channel. - - \sa setRedBufferSize(), setGreenBufferSize(), alphaBufferSize() -*/ -void QPlatformWindowFormat::setAlphaBufferSize(int size) -{ - detach(); - if (size < 0) { - qWarning("QPlatformWindowFormat::setAlphaBufferSize: Cannot set negative alpha buffer size %d", size); - return; - } - d->alphaSize = size; - setAlpha(size > 0); -} - -/*! - Returns the alpha buffer size. - - \sa alpha(), setAlpha(), setAlphaBufferSize() -*/ -int QPlatformWindowFormat::alphaBufferSize() const -{ - return d->alphaSize; -} - -/*! - Set the preferred accumulation buffer size, where \a size is the - bit depth for each RGBA component. - - \sa accum(), setAccum(), accumBufferSize() -*/ -void QPlatformWindowFormat::setAccumBufferSize(int size) -{ - detach(); - if (size < 0) { - qWarning("QPlatformWindowFormat::setAccumBufferSize: Cannot set negative accumulate buffer size %d", size); - return; - } - d->accumSize = size; - setAccum(size > 0); -} - -/*! - Returns the accumulation buffer size. - - \sa setAccumBufferSize(), accum(), setAccum() -*/ -int QPlatformWindowFormat::accumBufferSize() const -{ - return d->accumSize; -} - -/*! - Set the preferred stencil buffer size to \a size. - - \sa stencilBufferSize(), setStencil(), stencil() -*/ -void QPlatformWindowFormat::setStencilBufferSize(int size) -{ - detach(); - if (size < 0) { - qWarning("QPlatformWindowFormat::setStencilBufferSize: Cannot set negative stencil buffer size %d", size); - return; - } - d->stencilSize = size; - setStencil(size > 0); -} - -/*! - Returns the stencil buffer size. - - \sa stencil(), setStencil(), setStencilBufferSize() -*/ -int QPlatformWindowFormat::stencilBufferSize() const -{ - return d->stencilSize; -} - -/*! - Returns the default QPlatformWindowFormat for the application. All QGLWidget - objects that are created use this format unless another format is - specified, e.g. when they are constructed. - - If no special default format has been set using - setDefaultFormat(), the default format is the same as that created - with QPlatformWindowFormat(). - - \sa setDefaultFormat() -*/ - -QPlatformWindowFormat QPlatformWindowFormat::defaultFormat() -{ - return *q_platformwindow_default_format(); -} - -/*! - Sets a new default QPlatformWindowFormat for the application to \a f. For - example, to set single buffering as the default instead of double - buffering, your main() might contain code like this: - \snippet doc/src/snippets/code/src_opengl_qgl.cpp 4 - - \sa defaultFormat() -*/ - -void QPlatformWindowFormat::setDefaultFormat(const QPlatformWindowFormat &f) -{ - *q_platformwindow_default_format() = f; -} - - -/*! - Returns the default QPlatformWindowFormat for overlay contexts. - - The default overlay format is: - \list - \i \link setDoubleBuffer() Double buffer:\endlink Disabled. - \i \link setDepth() Depth buffer:\endlink Disabled. - \i \link setRgba() RGBA:\endlink Disabled (i.e., color index enabled). - \i \link setAlpha() Alpha channel:\endlink Disabled. - \i \link setAccum() Accumulator buffer:\endlink Disabled. - \i \link setStencil() Stencil buffer:\endlink Disabled. - \i \link setStereo() Stereo:\endlink Disabled. - \i \link setDirectRendering() Direct rendering:\endlink Enabled. - \i \link setOverlay() Overlay:\endlink Disabled. - \i \link setSampleBuffers() Multisample buffers:\endlink Disabled. - \i \link setPlane() Plane:\endlink 1 (i.e., first overlay plane). - \endlist - - \sa setDefaultFormat() -*/ - -//QPlatformWindowFormat QPlatformWindowFormat::defaultOverlayFormat() -//{ -// return *defaultOverlayFormatInstance(); -//} - -///*! -// Sets a new default QPlatformWindowFormat for overlay contexts to \a f. This -// format is used whenever a QGLWidget is created with a format that -// hasOverlay() enabled. - -// For example, to get a double buffered overlay context (if -// available), use code like this: - -// \snippet doc/src/snippets/code/src_opengl_qgl.cpp 5 - -// As usual, you can find out after widget creation whether the -// underlying OpenGL system was able to provide the requested -// specification: - -// \snippet doc/src/snippets/code/src_opengl_qgl.cpp 6 - -// \sa defaultOverlayFormat() -//*/ - -//void QPlatformWindowFormat::setDefaultOverlayFormat(const QPlatformWindowFormat &f) -//{ -// QPlatformWindowFormat *defaultFormat = defaultOverlayFormatInstance(); -// *defaultFormat = f; -// // Make sure the user doesn't request that the overlays themselves -// // have overlays, since it is unlikely that the system supports -// // infinitely many planes... -// defaultFormat->setOverlay(false); -//} - - -/*! - Returns true if all the options of the two QPlatformWindowFormat objects - \a a and \a b are equal; otherwise returns false. - - \relates QPlatformWindowFormat -*/ - -bool operator==(const QPlatformWindowFormat& a, const QPlatformWindowFormat& b) -{ - return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts - && a.d->alphaSize == b.d->alphaSize - && a.d->accumSize == b.d->accumSize - && a.d->stencilSize == b.d->stencilSize - && a.d->depthSize == b.d->depthSize - && a.d->redSize == b.d->redSize - && a.d->greenSize == b.d->greenSize - && a.d->blueSize == b.d->blueSize - && a.d->numSamples == b.d->numSamples - && a.d->swapInterval == b.d->swapInterval - && a.d->windowApi == b.d->windowApi); -} - - -/*! - Returns false if all the options of the two QPlatformWindowFormat objects - \a a and \a b are equal; otherwise returns true. - - \relates QPlatformWindowFormat -*/ - -bool operator!=(const QPlatformWindowFormat& a, const QPlatformWindowFormat& b) -{ - return !(a == b); -} - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, const QPlatformWindowFormat &f) -{ - const QPlatformWindowFormatPrivate * const d = f.d; - - dbg.nospace() << "QGLFormat(" - << "options " << d->opts - << ", depthBufferSize " << d->depthSize - << ", accumBufferSize " << d->accumSize - << ", stencilBufferSize " << d->stencilSize - << ", redBufferSize " << d->redSize - << ", greenBufferSize " << d->greenSize - << ", blueBufferSize " << d->blueSize - << ", alphaBufferSize " << d->alphaSize - << ", samples " << d->numSamples - << ", swapInterval " << d->swapInterval - << ')'; - - return dbg.space(); -} -#endif diff --git a/src/gui/kernel/qplatformwindowformat_qpa.h b/src/gui/kernel/qplatformwindowformat_qpa.h deleted file mode 100644 index 427318ea28..0000000000 --- a/src/gui/kernel/qplatformwindowformat_qpa.h +++ /dev/null @@ -1,290 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QPLATFORMWINDOWFORMAT_QPA_H -#define QPLATFORMWINDOWFORMAT_QPA_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QWindowFormatPrivate; - -class QWindowPrivate; - -class Q_GUI_EXPORT QWindow : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QWindow) - - Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle) - -public: - void setVisible(bool visible); - - WId winId() const; - void setParent(const QWindow *window); - - void setWindowTitle(const QString &title); - void raise(); - void lower(); - - void setOpacity(qreal level); - void requestActivateWindow(); - - Qt::WindowStates windowState() const; - void setWindowState(Qt::WindowStates state); - - QSize minimumSize() const; - QSize maximumSize() const; - - void setMinimumSize(const QSize &size) const; - void setMaximumSize(const QSize &size) const; - - void setGeometry(const QRect &rect); - QRect geometry() const; - - QString windowTitle() const; - - void setWindowIcon(const QImage &icon) const; - - QGLContext *glContext() const; - -public Q_SLOTS: - inline void show() { setVisible(true); } - inline void hide() { setVisible(false); } - - void showMinimized(); - void showMaximized(); - void showFullScreen(); - void showNormal(); - - bool close(); - void raise(); - void lower(); - - void setWindowTitle(const QString &); - -Q_SIGNALS: - void backBufferReady(); - -protected: - virtual void resizeEvent(QResizeEvent *); - - virtual void showEvent(QShowEvent *); - virtual void hideEvent(QHideEvent *); - - virtual bool event(QEvent *); - virtual void keyPressEvent(QKeyEvent *); - virtual void keyReleaseEvent(QKeyEvent *); - virtual void inputMethodEvent(QInputMethodEvent *); - virtual void mousePressEvent(QMouseEvent *); - virtual void mouseReleaseEvent(QMouseEvent *); - virtual void mouseDoubleClickEvent(QMouseEvent *); - virtual void mouseMoveEvent(QMouseEvent *); -#ifndef QT_NO_WHEELEVENT - virtual void wheelEvent(QWheelEvent *); -#endif - -private: - Q_DISABLE_COPY(QWindow) -}; - -class Q_GUI_EXPORT QWindowFormat -{ -public: - enum FormatOption { - StereoBuffers = 0x0001, - WindowSurface = 0x0002 - }; - Q_DECLARE_FLAGS(FormatOptions, FormatOption) - -#if 0 - enum WindowType { - Window = 0x00000001, - Dialog = 0x00000002, - Popup = 0x00000004, - ToolTip = 0x00000008 - }; - Q_DECLARE_FLAGS(WindowTypes, WindowType) -#endif - - enum ColorFormat { - InvalidColorFormat, - RGB565, - RGBA5658, - RGBA5551, - RGB888, - RGBA5658, - }; - - enum SwapBehavior { - DefaultSwapBehavior, - SingleBuffer, - DoubleBuffer, - TripleBuffer - }; - - enum OpenGLContextProfile { - NoProfile, - CoreProfile, - CompatibilityProfile - }; - - QWindowFormat(); - QWindowFormat(FormatOptions options); - QWindowFormat(const QWindowFormat &other); - QWindowFormat &operator=(const QWindowFormat &other); - ~QWindowFormat(); - - void setDepthBufferSize(int size); - int depthBufferSize() const; - - void setStencilBufferSize(int size); - int stencilBufferSize() const; - - void setSamples(int numSamples); - int samples() const; - - void setSwapBehavior(SwapBehavior behavior); - SwapBehavior swapBehavior() const; - - void setColorFormat(ColorFormat format); - ColorFormat colorFormat() const; - - void setProfile(OpenGLContextProfile profile); - OpenGLContextProfile profile() const; - - void setSharedContext(QPlatformGLContext *context); - QPlatformGLContext *sharedGLContext() const; - - bool depth() const; - void setDepth(bool enable); - bool stencil() const; - void setStencil(bool enable); - bool stereo() const; - void setStereo(bool enable); - bool hasWindowSurface() const; - void setWindowSurface(bool enable); - - void setOption(QWindowFormat::FormatOptions opt); - bool testOption(QWindowFormat::FormatOptions opt) const; - -private: - QWindowFormatPrivate *d; - - void detach(); - - friend Q_GUI_EXPORT bool operator==(const QWindowFormat&, const QWindowFormat&); - friend Q_GUI_EXPORT bool operator!=(const QWindowFormat&, const QWindowFormat&); -#ifndef QT_NO_DEBUG_STREAM - friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QWindowFormat &); -#endif -}; - -Q_GUI_EXPORT bool operator==(const QWindowFormat&, const QWindowFormat&); -Q_GUI_EXPORT bool operator!=(const QWindowFormat&, const QWindowFormat&); - -#ifndef QT_NO_DEBUG_STREAM -Q_OPENGL_EXPORT QDebug operator<<(QDebug, const QWindowFormat &); -#endif - -Q_DECLARE_OPERATORS_FOR_FLAGS(QWindowFormat::FormatOptions) -Q_DECLARE_OPERATORS_FOR_FLAGS(QWindowFormat::WindowTypes) - -inline bool QWindowFormat::doubleBuffer() const -{ - return testOption(QWindowFormat::DoubleBuffer); -} - -inline bool QWindowFormat::depth() const -{ - return testOption(QWindowFormat::DepthBuffer); -} - -inline bool QWindowFormat::rgba() const -{ - return testOption(QWindowFormat::Rgba); -} - -inline bool QWindowFormat::alpha() const -{ - return testOption(QWindowFormat::AlphaChannel); -} - -inline bool QWindowFormat::accum() const -{ - return testOption(QWindowFormat::AccumBuffer); -} - -inline bool QWindowFormat::stencil() const -{ - return testOption(QWindowFormat::StencilBuffer); -} - -inline bool QWindowFormat::stereo() const -{ - return testOption(QWindowFormat::StereoBuffers); -} - -inline bool QWindowFormat::directRendering() const -{ - return testOption(QWindowFormat::DirectRendering); -} - -inline bool QWindowFormat::hasWindowSurface() const -{ - return testOption(QWindowFormat::HasWindowSurface); -} - -inline bool QWindowFormat::sampleBuffers() const -{ - return testOption(QWindowFormat::SampleBuffers); -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif //QPLATFORMWINDOWFORMAT_QPA_H diff --git a/src/gui/kernel/qwindow_qpa.cpp b/src/gui/kernel/qwindow_qpa.cpp new file mode 100644 index 0000000000..ad5f22aaf9 --- /dev/null +++ b/src/gui/kernel/qwindow_qpa.cpp @@ -0,0 +1,305 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwindow_qpa.h" + +#include "qplatformwindow_qpa.h" +#include "qwindowformat_qpa.h" + +#include "qapplication_p.h" + +#include + +QT_BEGIN_NAMESPACE + +class QWindowPrivate : public QObjectPrivate{ + QWindowPrivate(const QWindowFormat &requestedFormat) + : QObjectPrivate() + , platformWindow(0) + , requestedFormat(requestedFormat) + , glContext(0) + { + + } + + ~QWindowPrivate() + { + + } + +private: + QPlatformWindow *platformWindow; + QWindowFormat requestedFormat; + QString windowTitle; + QRect geometry; + QGLContext *glContext; +}; + +QWindow::QWindow(const QWindowFormat &format, QWindow *parent) + : QObject(*new QWindowPrivate(format), parent) +{ + +} + +void QWindow::setVisible(bool visible) +{ + Q_D(QWindow); + if (!d->platformWindow) { + create(); + } + d->platformWindow->setVisible(visible); +} + +void QWindow::create() +{ + Q_D(QWindow); + d->platformWindow = QApplicationPrivate::platformIntegration()->createPlatformWindow(this,d->requestedFormat); + Q_ASSERT(d->platformWindow); +} + +WId QWindow::winId() const +{ + Q_D(QWindow); + if(d->platformWindow) { + return d->platformWindow->winId(); + } + return 0; +} + +void QWindow::setParent(const QWindow *parent) +{ + Q_D(QWindow); + //How should we support lazy init when setting parent + if (!parent->d_func()->platformWindow) { + parent->create(); + } + + if(!d->platformWindow) { + create(); + } + d->platformWindow->setParent(parent->d_func()->platformWindow); +} + +void QWindow::setWindowTitle(const QString &title) +{ + Q_D(QWindow); + d->windowTitle = title; + if (d->platformWindow) { + d->platformWindow->setWindowTitle(title); + } +} + +QString QWindow::windowTitle() const +{ + Q_D(const QWindow); + return d->windowTitle; +} + +void QWindow::raise() +{ + Q_D(QWindow); + if (d->platformWindow) { + d->platformWindow->raise(); + } +} + +void QWindow::lower() +{ + Q_D(QWindow); + if (d->platformWindow) { + d->platformWindow->lower(); + } +} + +void QWindow::setOpacity(qreal level) +{ + Q_D(QWindow); + if (d->platformWindow) { + d->platformWindow->setOpacity(level); + } +} + +void QWindow::requestActivateWindow() +{ + Q_D(QWindow); + if (d->platformWindow) { + d->platformWindow->requestActivateWindow(); + } +} + +Qt::WindowStates QWindow::windowState() const +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +void QWindow::setWindowState(Qt::WindowStates state) +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +QSize QWindow::minimumSize() const +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +QSize QWindow::maximumSize() const +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +void QWindow::setMinimumSize(const QSize &size) const +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +void QWindow::setMaximumSize(const QSize &size) const +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +void QWindow::setGeometry(const QRect &rect) +{ + Q_D(QWindow); + d->geometry = rect; + if (d->platformWindow) { + d->platformWindow->setGeometry(rect); + } +} + +QRect QWindow::geometry() const +{ + Q_D(const QWindow); + return d->geometry; +} + +void QWindow::setWindowIcon(const QImage &icon) const +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +QGLContext * QWindow::glContext() const +{ + Q_D(QWindow); + return d->glContext; +} + +void QWindow::showMinimized() +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +void QWindow::showMaximized() +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +void QWindow::showFullScreen() +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +void QWindow::showNormal() +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +bool QWindow::close() +{ + //should we have close? + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +void QWindow::resizeEvent(QResizeEvent *) +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +void QWindow::showEvent(QShowEvent *) +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +void QWindow::hideEvent(QHideEvent *) +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +bool QWindow::event(QEvent *) +{ + qDebug() << "unimplemented:" << __FILE__ << __LINE__; +} + +void QWindow::keyPressEvent(QKeyEvent *) +{ + +} + +void QWindow::keyReleaseEvent(QKeyEvent *) +{ +} + +void QWindow::inputMethodEvent(QInputMethodEvent *) +{ +} + +void QWindow::mousePressEvent(QMouseEvent *) +{ +} + +void QWindow::mouseReleaseEvent(QMouseEvent *) +{ +} + +void QWindow::mouseDoubleClickEvent(QMouseEvent *) +{ +} + +void QWindow::mouseMoveEvent(QMouseEvent *) +{ +} + +#ifndef QT_NO_WHEELEVENT +void QWindow::wheelEvent(QWheelEvent *) +{ +} +#endif //QT_NO_WHEELEVENT + +QT_END_NAMESPACE diff --git a/src/gui/kernel/qwindow_qpa.h b/src/gui/kernel/qwindow_qpa.h new file mode 100644 index 0000000000..62d8825236 --- /dev/null +++ b/src/gui/kernel/qwindow_qpa.h @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWINDOW_QPA_H +#define QWINDOW_QPA_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QWindowPrivate; +class QGLContext; + +class Q_GUI_EXPORT QWindow : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QWindow) + + Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle) + +public: + QWindow(const QWindowFormat &format, QWindow *parent); + void setVisible(bool visible); + void create(); + + WId winId() const; + void setParent(const QWindow *parent); + + QString windowTitle() const; + + void setOpacity(qreal level); + void requestActivateWindow(); + + Qt::WindowStates windowState() const; + void setWindowState(Qt::WindowStates state); + + QSize minimumSize() const; + QSize maximumSize() const; + + void setMinimumSize(const QSize &size) const; + void setMaximumSize(const QSize &size) const; + + void setGeometry(const QRect &rect); + QRect geometry() const; + + void setWindowIcon(const QImage &icon) const; + + QGLContext *glContext() const; + +public Q_SLOTS: + inline void show() { setVisible(true); } + inline void hide() { setVisible(false); } + + void showMinimized(); + void showMaximized(); + void showFullScreen(); + void showNormal(); + + bool close(); + void raise(); + void lower(); + + void setWindowTitle(const QString &); + +Q_SIGNALS: + void backBufferReady(); + +protected: + virtual void resizeEvent(QResizeEvent *); + + virtual void showEvent(QShowEvent *); + virtual void hideEvent(QHideEvent *); + + virtual bool event(QEvent *); + virtual void keyPressEvent(QKeyEvent *); + virtual void keyReleaseEvent(QKeyEvent *); + virtual void inputMethodEvent(QInputMethodEvent *); + virtual void mousePressEvent(QMouseEvent *); + virtual void mouseReleaseEvent(QMouseEvent *); + virtual void mouseDoubleClickEvent(QMouseEvent *); + virtual void mouseMoveEvent(QMouseEvent *); +#ifndef QT_NO_WHEELEVENT + virtual void wheelEvent(QWheelEvent *); +#endif + +private: + Q_DISABLE_COPY(QWindow) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QWINDOW_QPA_H diff --git a/src/gui/kernel/qwindowformat_qpa.cpp b/src/gui/kernel/qwindowformat_qpa.cpp new file mode 100644 index 0000000000..c165c8513a --- /dev/null +++ b/src/gui/kernel/qwindowformat_qpa.cpp @@ -0,0 +1,1008 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qplatformwindowformat_qpa.h" + +#include + +Q_GLOBAL_STATIC(QPlatformWindowFormat, q_platformwindow_default_format); + +class QPlatformWindowFormatPrivate +{ +public: + QPlatformWindowFormatPrivate() + : ref(1) + , opts(QPlatformWindowFormat::DoubleBuffer | QPlatformWindowFormat::DepthBuffer + | QPlatformWindowFormat::Rgba | QPlatformWindowFormat::DirectRendering + | QPlatformWindowFormat::StencilBuffer | QPlatformWindowFormat::DeprecatedFunctions + | QPlatformWindowFormat::HasWindowSurface) + , depthSize(-1) + , accumSize(-1) + , stencilSize(-1) + , redSize(-1) + , greenSize(-1) + , blueSize(-1) + , alphaSize(-1) + , numSamples(-1) + , swapInterval(-1) + , windowApi(QPlatformWindowFormat::Raster) + , sharedContext(0) + { + } + + QPlatformWindowFormatPrivate(const QPlatformWindowFormatPrivate *other) + : ref(1), + opts(other->opts), + depthSize(other->depthSize), + accumSize(other->accumSize), + stencilSize(other->stencilSize), + redSize(other->redSize), + greenSize(other->greenSize), + blueSize(other->blueSize), + alphaSize(other->alphaSize), + numSamples(other->numSamples), + swapInterval(other->swapInterval), + windowApi(other->windowApi), + sharedContext(other->sharedContext) + { + } + QAtomicInt ref; + QPlatformWindowFormat::FormatOptions opts; + int depthSize; + int accumSize; + int stencilSize; + int redSize; + int greenSize; + int blueSize; + int alphaSize; + int numSamples; + int swapInterval; + QPlatformWindowFormat::WindowApi windowApi; + QPlatformGLContext *sharedContext; +}; + +/*! + \class QPlatformWindowFormat + \brief The QPlatformWindowFormat class specifies the display format of an OpenGL + rendering context and if possible attributes of the corresponding QPlatformWindow. + + \ingroup painting + + QWidget has a setter and getter function for QPlatformWindowFormat. These functions can be used + by the application programmer to signal what kind of format he wants to the window and glcontext + should have. However, it is not always possible to fulfill these requirements. The application + programmer should therefore check the resulting QPlatformWindowFormat from QPlatformGLContext + to see the format that was actually created. + + A display format has several characteristics: + \list + \i \link setDoubleBuffer() Double or single buffering.\endlink + \i \link setDepth() Depth buffer.\endlink + \i \link setRgba() RGBA or color index mode.\endlink + \i \link setAlpha() Alpha channel.\endlink + \i \link setAccum() Accumulation buffer.\endlink + \i \link setStencil() Stencil buffer.\endlink + \i \link setStereo() Stereo buffers.\endlink + \i \link setDirectRendering() Direct rendering.\endlink + \i \link setOverlay() Presence of an overlay.\endlink + \i \link setPlane() Plane of an overlay.\endlink + \i \link setSampleBuffers() Multisample buffers.\endlink + \endlist + + You can also specify preferred bit depths for the color buffer, + depth buffer, alpha buffer, accumulation buffer and the stencil + buffer with the functions: setRedBufferSize(), setGreenBufferSize(), + setBlueBufferSize(), setDepthBufferSize(), setAlphaBufferSize(), + setAccumBufferSize() and setStencilBufferSize(). + + Note that even if you specify that you prefer a 32 bit depth + buffer (e.g. with setDepthBufferSize(32)), the format that is + chosen may not have a 32 bit depth buffer, even if there is a + format available with a 32 bit depth buffer. The main reason for + this is how the system dependant picking algorithms work on the + different platforms, and some format options may have higher + precedence than others. + + You create and tell a QPlatformWindowFormat object what rendering options you + want from an OpenGL rendering context. + + OpenGL drivers or accelerated hardware may or may not support + advanced features such as alpha channel or stereographic viewing. + If you request some features that the driver/hardware does not + provide when you create a QGLWidget, you will get a rendering + context with the nearest subset of features. + + There are different ways to define the display characteristics of + a rendering context. One is to create a QPlatformWindowFormat and make it the + default for the entire application: + \snippet doc/src/snippets/code/src_opengl_qgl.cpp 0 + + Or you can specify the desired format when creating an object of + your QGLWidget subclass: + \snippet doc/src/snippets/code/src_opengl_qgl.cpp 1 + + After the widget has been created, you can find out which of the + requested features the system was able to provide: + \snippet doc/src/snippets/code/src_opengl_qgl.cpp 2 + + \legalese + OpenGL is a trademark of Silicon Graphics, Inc. in the + United States and other countries. + \endlegalese + + \sa QPlatformContext, QWidget +*/ + +/*! + Constructs a QPlatformWindowFormat object with the following default settings: + \list + \i \link setDoubleBuffer() Double buffer:\endlink Enabled. + \i \link setDepth() Depth buffer:\endlink Enabled. + \i \link setRgba() RGBA:\endlink Enabled (i.e., color index disabled). + \i \link setAlpha() Alpha channel:\endlink Disabled. + \i \link setAccum() Accumulator buffer:\endlink Disabled. + \i \link setStencil() Stencil buffer:\endlink Enabled. + \i \link setStereo() Stereo:\endlink Disabled. + \i \link setDirectRendering() Direct rendering:\endlink Enabled. + \i \link setOverlay() Overlay:\endlink Disabled. + \i \link setPlane() Plane:\endlink 0 (i.e., normal plane). + \i \link setSampleBuffers() Multisample buffers:\endlink Disabled. + \endlist +*/ + +QPlatformWindowFormat::QPlatformWindowFormat() +{ + d = new QPlatformWindowFormatPrivate; +} + + +/*! + Creates a QPlatformWindowFormat object that is a copy of the current + defaultFormat(). + + If \a options is not 0, the default format is modified by the + specified format options. The \a options parameter should be + QGL::FormatOption values OR'ed together. + + This constructor makes it easy to specify a certain desired format + in classes derived from QGLWidget, for example: + \snippet doc/src/snippets/code/src_opengl_qgl.cpp 3 + + Note that there are QGL::FormatOption values to turn format settings + both on and off, e.g. QGL::DepthBuffer and QGL::NoDepthBuffer, + QGL::DirectRendering and QGL::IndirectRendering, etc. + + The \a plane parameter defaults to 0 and is the plane which this + format should be associated with. Not all OpenGL implementations + supports overlay/underlay rendering planes. + + \sa defaultFormat(), setOption(), setPlane() +*/ + +QPlatformWindowFormat::QPlatformWindowFormat(QPlatformWindowFormat::FormatOptions options) +{ + d = new QPlatformWindowFormatPrivate; + QPlatformWindowFormat::FormatOptions newOpts = options; + d->opts = defaultFormat().d->opts; + d->opts |= (newOpts & 0xffff); + d->opts &= ~(newOpts >> 16); +} + +/*! + \internal +*/ +void QPlatformWindowFormat::detach() +{ + if (d->ref != 1) { + QPlatformWindowFormatPrivate *newd = new QPlatformWindowFormatPrivate(d); + if (!d->ref.deref()) + delete d; + d = newd; + } +} + +/*! + Constructs a copy of \a other. +*/ + +QPlatformWindowFormat::QPlatformWindowFormat(const QPlatformWindowFormat &other) +{ + d = other.d; + d->ref.ref(); +} + +/*! + Assigns \a other to this object. +*/ + +QPlatformWindowFormat &QPlatformWindowFormat::operator=(const QPlatformWindowFormat &other) +{ + if (d != other.d) { + other.d->ref.ref(); + if (!d->ref.deref()) + delete d; + d = other.d; + } + return *this; +} + +/*! + Destroys the QPlatformWindowFormat. +*/ +QPlatformWindowFormat::~QPlatformWindowFormat() +{ + if (!d->ref.deref()) + delete d; +} + +/*! + \fn bool QPlatformWindowFormat::doubleBuffer() const + + Returns true if double buffering is enabled; otherwise returns + false. Double buffering is enabled by default. + + \sa setDoubleBuffer() +*/ + +/*! + If \a enable is true sets double buffering; otherwise sets single + buffering. + + Double buffering is enabled by default. + + Double buffering is a technique where graphics are rendered on an + off-screen buffer and not directly to the screen. When the drawing + has been completed, the program calls a swapBuffers() function to + exchange the screen contents with the buffer. The result is + flicker-free drawing and often better performance. + + \sa doubleBuffer(), QGLContext::swapBuffers(), + QGLWidget::swapBuffers() +*/ + +void QPlatformWindowFormat::setDoubleBuffer(bool enable) +{ + setOption(enable ? QPlatformWindowFormat::DoubleBuffer : QPlatformWindowFormat::SingleBuffer); +} + + +/*! + \fn bool QPlatformWindowFormat::depth() const + + Returns true if the depth buffer is enabled; otherwise returns + false. The depth buffer is enabled by default. + + \sa setDepth(), setDepthBufferSize() +*/ + +/*! + If \a enable is true enables the depth buffer; otherwise disables + the depth buffer. + + The depth buffer is enabled by default. + + The purpose of a depth buffer (or Z-buffering) is to remove hidden + surfaces. Pixels are assigned Z values based on the distance to + the viewer. A pixel with a high Z value is closer to the viewer + than a pixel with a low Z value. This information is used to + decide whether to draw a pixel or not. + + \sa depth(), setDepthBufferSize() +*/ + +void QPlatformWindowFormat::setDepth(bool enable) +{ + setOption(enable ? QPlatformWindowFormat::DepthBuffer : QPlatformWindowFormat::NoDepthBuffer); +} + + +/*! + \fn bool QPlatformWindowFormat::rgba() const + + Returns true if RGBA color mode is set. Returns false if color + index mode is set. The default color mode is RGBA. + + \sa setRgba() +*/ + +/*! + If \a enable is true sets RGBA mode. If \a enable is false sets + color index mode. + + The default color mode is RGBA. + + RGBA is the preferred mode for most OpenGL applications. In RGBA + color mode you specify colors as red + green + blue + alpha + quadruplets. + + In color index mode you specify an index into a color lookup + table. + + \sa rgba() +*/ + +void QPlatformWindowFormat::setRgba(bool enable) +{ + setOption(enable ? QPlatformWindowFormat::Rgba : QPlatformWindowFormat::ColorIndex); +} + + +/*! + \fn bool QPlatformWindowFormat::alpha() const + + Returns true if the alpha buffer in the framebuffer is enabled; + otherwise returns false. The alpha buffer is disabled by default. + + \sa setAlpha(), setAlphaBufferSize() +*/ + +/*! + If \a enable is true enables the alpha buffer; otherwise disables + the alpha buffer. + + The alpha buffer is disabled by default. + + The alpha buffer is typically used for implementing transparency + or translucency. The A in RGBA specifies the transparency of a + pixel. + + \sa alpha(), setAlphaBufferSize() +*/ + +void QPlatformWindowFormat::setAlpha(bool enable) +{ + setOption(enable ? QPlatformWindowFormat::AlphaChannel : QPlatformWindowFormat::NoAlphaChannel); +} + + +/*! + \fn bool QPlatformWindowFormat::accum() const + + Returns true if the accumulation buffer is enabled; otherwise + returns false. The accumulation buffer is disabled by default. + + \sa setAccum(), setAccumBufferSize() +*/ + +/*! + If \a enable is true enables the accumulation buffer; otherwise + disables the accumulation buffer. + + The accumulation buffer is disabled by default. + + The accumulation buffer is used to create blur effects and + multiple exposures. + + \sa accum(), setAccumBufferSize() +*/ + +void QPlatformWindowFormat::setAccum(bool enable) +{ + setOption(enable ? QPlatformWindowFormat::AccumBuffer : QPlatformWindowFormat::NoAccumBuffer); +} + + +/*! + \fn bool QPlatformWindowFormat::stencil() const + + Returns true if the stencil buffer is enabled; otherwise returns + false. The stencil buffer is enabled by default. + + \sa setStencil(), setStencilBufferSize() +*/ + +/*! + If \a enable is true enables the stencil buffer; otherwise + disables the stencil buffer. + + The stencil buffer is enabled by default. + + The stencil buffer masks certain parts of the drawing area so that + masked parts are not drawn on. + + \sa stencil(), setStencilBufferSize() +*/ + +void QPlatformWindowFormat::setStencil(bool enable) +{ + setOption(enable ? QPlatformWindowFormat::StencilBuffer: QPlatformWindowFormat::NoStencilBuffer); +} + + +/*! + \fn bool QPlatformWindowFormat::stereo() const + + Returns true if stereo buffering is enabled; otherwise returns + false. Stereo buffering is disabled by default. + + \sa setStereo() +*/ + +/*! + If \a enable is true enables stereo buffering; otherwise disables + stereo buffering. + + Stereo buffering is disabled by default. + + Stereo buffering provides extra color buffers to generate left-eye + and right-eye images. + + \sa stereo() +*/ + +void QPlatformWindowFormat::setStereo(bool enable) +{ + setOption(enable ? QPlatformWindowFormat::StereoBuffers : QPlatformWindowFormat::NoStereoBuffers); +} + + +/*! + \fn bool QPlatformWindowFormat::directRendering() const + + Returns true if direct rendering is enabled; otherwise returns + false. + + Direct rendering is enabled by default. + + \sa setDirectRendering() +*/ + +/*! + If \a enable is true enables direct rendering; otherwise disables + direct rendering. + + Direct rendering is enabled by default. + + Enabling this option will make OpenGL bypass the underlying window + system and render directly from hardware to the screen, if this is + supported by the system. + + \sa directRendering() +*/ + +void QPlatformWindowFormat::setDirectRendering(bool enable) +{ + setOption(enable ? QPlatformWindowFormat::DirectRendering : QPlatformWindowFormat::IndirectRendering); +} + +/*! + \fn bool QPlatformWindowFormat::sampleBuffers() const + + Returns true if multisample buffer support is enabled; otherwise + returns false. + + The multisample buffer is disabled by default. + + \sa setSampleBuffers() +*/ + +/*! + If \a enable is true, a GL context with multisample buffer support + is picked; otherwise ignored. + + \sa sampleBuffers(), setSamples(), samples() +*/ +void QPlatformWindowFormat::setSampleBuffers(bool enable) +{ + setOption(enable ? QPlatformWindowFormat::SampleBuffers : QPlatformWindowFormat::NoSampleBuffers); +} + +/*! + Returns the number of samples per pixel when multisampling is + enabled. By default, the highest number of samples that is + available is used. + + \sa setSampleBuffers(), sampleBuffers(), setSamples() +*/ +int QPlatformWindowFormat::samples() const +{ + return d->numSamples; +} + +/*! + Set the preferred number of samples per pixel when multisampling + is enabled to \a numSamples. By default, the highest number of + samples available is used. + + \sa setSampleBuffers(), sampleBuffers(), samples() +*/ +void QPlatformWindowFormat::setSamples(int numSamples) +{ + detach(); + if (numSamples < 0) { + qWarning("QPlatformWindowFormat::setSamples: Cannot have negative number of samples per pixel %d", numSamples); + return; + } + d->numSamples = numSamples; + setSampleBuffers(numSamples > 0); +} + +/*! + \since 4.2 + + Set the preferred swap interval. This can be used to sync the GL + drawing into a system window to the vertical refresh of the screen. + Setting an \a interval value of 0 will turn the vertical refresh syncing + off, any value higher than 0 will turn the vertical syncing on. + + Under Windows and under X11, where the \c{WGL_EXT_swap_control} + and \c{GLX_SGI_video_sync} extensions are used, the \a interval + parameter can be used to set the minimum number of video frames + that are displayed before a buffer swap will occur. In effect, + setting the \a interval to 10, means there will be 10 vertical + retraces between every buffer swap. + + Under Windows the \c{WGL_EXT_swap_control} extension has to be present, + and under X11 the \c{GLX_SGI_video_sync} extension has to be present. +*/ +void QPlatformWindowFormat::setSwapInterval(int interval) +{ + detach(); + d->swapInterval = interval; +} + +/*! + \since 4.2 + + Returns the currently set swap interval. -1 is returned if setting + the swap interval isn't supported in the system GL implementation. +*/ +int QPlatformWindowFormat::swapInterval() const +{ + return d->swapInterval; +} + +void QPlatformWindowFormat::setWindowApi(QPlatformWindowFormat::WindowApi api) +{ + detach(); + d->windowApi = api; +} + +QPlatformWindowFormat::WindowApi QPlatformWindowFormat::windowApi() const +{ + return d->windowApi; +} + +void QPlatformWindowFormat::setSharedContext(QPlatformGLContext *context) +{ + d->sharedContext = context; +} + +QPlatformGLContext *QPlatformWindowFormat::sharedGLContext() const +{ + return d->sharedContext; +} + +/*! + \fn bool QPlatformWindowFormat::hasWindowSurface() const + + Returns true if the corresponding widget has an instance of QWindowSurface. + + Otherwise returns false. + + WindowSurface is enabled by default. + + \sa setOverlay() +*/ + +/*! + If \a enable is true a top level QWidget will create a QWindowSurface at creation; + + otherwise the QWidget will only have a QPlatformWindow. + + This is useful for ie. QGLWidget where the QPlatformGLContext controls the surface. + + \sa hasOverlay() +*/ + +void QPlatformWindowFormat::setWindowSurface(bool enable) +{ + setOption(enable ? QPlatformWindowFormat::HasWindowSurface : QPlatformWindowFormat::NoWindowSurface); +} + +/*! + Sets the format option to \a opt. + + \sa testOption() +*/ + +void QPlatformWindowFormat::setOption(QPlatformWindowFormat::FormatOptions opt) +{ + detach(); + if (opt & 0xffff) + d->opts |= opt; + else + d->opts &= ~(opt >> 16); +} + + + +/*! + Returns true if format option \a opt is set; otherwise returns false. + + \sa setOption() +*/ + +bool QPlatformWindowFormat::testOption(QPlatformWindowFormat::FormatOptions opt) const +{ + if (opt & 0xffff) + return (d->opts & opt) != 0; + else + return (d->opts & (opt >> 16)) == 0; +} + +/*! + Set the minimum depth buffer size to \a size. + + \sa depthBufferSize(), setDepth(), depth() +*/ +void QPlatformWindowFormat::setDepthBufferSize(int size) +{ + detach(); + if (size < 0) { + qWarning("QPlatformWindowFormat::setDepthBufferSize: Cannot set negative depth buffer size %d", size); + return; + } + d->depthSize = size; + setDepth(size > 0); +} + +/*! + Returns the depth buffer size. + + \sa depth(), setDepth(), setDepthBufferSize() +*/ +int QPlatformWindowFormat::depthBufferSize() const +{ + return d->depthSize; +} + +/*! + \since 4.2 + + Set the preferred red buffer size to \a size. + + \sa setGreenBufferSize(), setBlueBufferSize(), setAlphaBufferSize() +*/ +void QPlatformWindowFormat::setRedBufferSize(int size) +{ + detach(); + if (size < 0) { + qWarning("QPlatformWindowFormat::setRedBufferSize: Cannot set negative red buffer size %d", size); + return; + } + d->redSize = size; +} + +/*! + \since 4.2 + + Returns the red buffer size. + + \sa setRedBufferSize() +*/ +int QPlatformWindowFormat::redBufferSize() const +{ + return d->redSize; +} + +/*! + \since 4.2 + + Set the preferred green buffer size to \a size. + + \sa setRedBufferSize(), setBlueBufferSize(), setAlphaBufferSize() +*/ +void QPlatformWindowFormat::setGreenBufferSize(int size) +{ + detach(); + if (size < 0) { + qWarning("QPlatformWindowFormat::setGreenBufferSize: Cannot set negative green buffer size %d", size); + return; + } + d->greenSize = size; +} + +/*! + \since 4.2 + + Returns the green buffer size. + + \sa setGreenBufferSize() +*/ +int QPlatformWindowFormat::greenBufferSize() const +{ + return d->greenSize; +} + +/*! + \since 4.2 + + Set the preferred blue buffer size to \a size. + + \sa setRedBufferSize(), setGreenBufferSize(), setAlphaBufferSize() +*/ +void QPlatformWindowFormat::setBlueBufferSize(int size) +{ + detach(); + if (size < 0) { + qWarning("QPlatformWindowFormat::setBlueBufferSize: Cannot set negative blue buffer size %d", size); + return; + } + d->blueSize = size; +} + +/*! + \since 4.2 + + Returns the blue buffer size. + + \sa setBlueBufferSize() +*/ +int QPlatformWindowFormat::blueBufferSize() const +{ + return d->blueSize; +} + +/*! + Set the preferred alpha buffer size to \a size. + This function implicitly enables the alpha channel. + + \sa setRedBufferSize(), setGreenBufferSize(), alphaBufferSize() +*/ +void QPlatformWindowFormat::setAlphaBufferSize(int size) +{ + detach(); + if (size < 0) { + qWarning("QPlatformWindowFormat::setAlphaBufferSize: Cannot set negative alpha buffer size %d", size); + return; + } + d->alphaSize = size; + setAlpha(size > 0); +} + +/*! + Returns the alpha buffer size. + + \sa alpha(), setAlpha(), setAlphaBufferSize() +*/ +int QPlatformWindowFormat::alphaBufferSize() const +{ + return d->alphaSize; +} + +/*! + Set the preferred accumulation buffer size, where \a size is the + bit depth for each RGBA component. + + \sa accum(), setAccum(), accumBufferSize() +*/ +void QPlatformWindowFormat::setAccumBufferSize(int size) +{ + detach(); + if (size < 0) { + qWarning("QPlatformWindowFormat::setAccumBufferSize: Cannot set negative accumulate buffer size %d", size); + return; + } + d->accumSize = size; + setAccum(size > 0); +} + +/*! + Returns the accumulation buffer size. + + \sa setAccumBufferSize(), accum(), setAccum() +*/ +int QPlatformWindowFormat::accumBufferSize() const +{ + return d->accumSize; +} + +/*! + Set the preferred stencil buffer size to \a size. + + \sa stencilBufferSize(), setStencil(), stencil() +*/ +void QPlatformWindowFormat::setStencilBufferSize(int size) +{ + detach(); + if (size < 0) { + qWarning("QPlatformWindowFormat::setStencilBufferSize: Cannot set negative stencil buffer size %d", size); + return; + } + d->stencilSize = size; + setStencil(size > 0); +} + +/*! + Returns the stencil buffer size. + + \sa stencil(), setStencil(), setStencilBufferSize() +*/ +int QPlatformWindowFormat::stencilBufferSize() const +{ + return d->stencilSize; +} + +/*! + Returns the default QPlatformWindowFormat for the application. All QGLWidget + objects that are created use this format unless another format is + specified, e.g. when they are constructed. + + If no special default format has been set using + setDefaultFormat(), the default format is the same as that created + with QPlatformWindowFormat(). + + \sa setDefaultFormat() +*/ + +QPlatformWindowFormat QPlatformWindowFormat::defaultFormat() +{ + return *q_platformwindow_default_format(); +} + +/*! + Sets a new default QPlatformWindowFormat for the application to \a f. For + example, to set single buffering as the default instead of double + buffering, your main() might contain code like this: + \snippet doc/src/snippets/code/src_opengl_qgl.cpp 4 + + \sa defaultFormat() +*/ + +void QPlatformWindowFormat::setDefaultFormat(const QPlatformWindowFormat &f) +{ + *q_platformwindow_default_format() = f; +} + + +/*! + Returns the default QPlatformWindowFormat for overlay contexts. + + The default overlay format is: + \list + \i \link setDoubleBuffer() Double buffer:\endlink Disabled. + \i \link setDepth() Depth buffer:\endlink Disabled. + \i \link setRgba() RGBA:\endlink Disabled (i.e., color index enabled). + \i \link setAlpha() Alpha channel:\endlink Disabled. + \i \link setAccum() Accumulator buffer:\endlink Disabled. + \i \link setStencil() Stencil buffer:\endlink Disabled. + \i \link setStereo() Stereo:\endlink Disabled. + \i \link setDirectRendering() Direct rendering:\endlink Enabled. + \i \link setOverlay() Overlay:\endlink Disabled. + \i \link setSampleBuffers() Multisample buffers:\endlink Disabled. + \i \link setPlane() Plane:\endlink 1 (i.e., first overlay plane). + \endlist + + \sa setDefaultFormat() +*/ + +//QPlatformWindowFormat QPlatformWindowFormat::defaultOverlayFormat() +//{ +// return *defaultOverlayFormatInstance(); +//} + +///*! +// Sets a new default QPlatformWindowFormat for overlay contexts to \a f. This +// format is used whenever a QGLWidget is created with a format that +// hasOverlay() enabled. + +// For example, to get a double buffered overlay context (if +// available), use code like this: + +// \snippet doc/src/snippets/code/src_opengl_qgl.cpp 5 + +// As usual, you can find out after widget creation whether the +// underlying OpenGL system was able to provide the requested +// specification: + +// \snippet doc/src/snippets/code/src_opengl_qgl.cpp 6 + +// \sa defaultOverlayFormat() +//*/ + +//void QPlatformWindowFormat::setDefaultOverlayFormat(const QPlatformWindowFormat &f) +//{ +// QPlatformWindowFormat *defaultFormat = defaultOverlayFormatInstance(); +// *defaultFormat = f; +// // Make sure the user doesn't request that the overlays themselves +// // have overlays, since it is unlikely that the system supports +// // infinitely many planes... +// defaultFormat->setOverlay(false); +//} + + +/*! + Returns true if all the options of the two QPlatformWindowFormat objects + \a a and \a b are equal; otherwise returns false. + + \relates QPlatformWindowFormat +*/ + +bool operator==(const QPlatformWindowFormat& a, const QPlatformWindowFormat& b) +{ + return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts + && a.d->alphaSize == b.d->alphaSize + && a.d->accumSize == b.d->accumSize + && a.d->stencilSize == b.d->stencilSize + && a.d->depthSize == b.d->depthSize + && a.d->redSize == b.d->redSize + && a.d->greenSize == b.d->greenSize + && a.d->blueSize == b.d->blueSize + && a.d->numSamples == b.d->numSamples + && a.d->swapInterval == b.d->swapInterval + && a.d->windowApi == b.d->windowApi); +} + + +/*! + Returns false if all the options of the two QPlatformWindowFormat objects + \a a and \a b are equal; otherwise returns true. + + \relates QPlatformWindowFormat +*/ + +bool operator!=(const QPlatformWindowFormat& a, const QPlatformWindowFormat& b) +{ + return !(a == b); +} + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const QPlatformWindowFormat &f) +{ + const QPlatformWindowFormatPrivate * const d = f.d; + + dbg.nospace() << "QGLFormat(" + << "options " << d->opts + << ", depthBufferSize " << d->depthSize + << ", accumBufferSize " << d->accumSize + << ", stencilBufferSize " << d->stencilSize + << ", redBufferSize " << d->redSize + << ", greenBufferSize " << d->greenSize + << ", blueBufferSize " << d->blueSize + << ", alphaBufferSize " << d->alphaSize + << ", samples " << d->numSamples + << ", swapInterval " << d->swapInterval + << ')'; + + return dbg.space(); +} +#endif diff --git a/src/gui/kernel/qwindowformat_qpa.h b/src/gui/kernel/qwindowformat_qpa.h new file mode 100644 index 0000000000..b0989d70e9 --- /dev/null +++ b/src/gui/kernel/qwindowformat_qpa.h @@ -0,0 +1,210 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QPLATFORMWINDOWFORMAT_QPA_H +#define QPLATFORMWINDOWFORMAT_QPA_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QWindowFormatPrivate; + +class Q_GUI_EXPORT QWindowFormat +{ +public: + enum FormatOption { + StereoBuffers = 0x0001, + WindowSurface = 0x0002 + }; + Q_DECLARE_FLAGS(FormatOptions, FormatOption) + +#if 0 + enum WindowType { + Window = 0x00000001, + Dialog = 0x00000002, + Popup = 0x00000004, + ToolTip = 0x00000008 + }; + Q_DECLARE_FLAGS(WindowTypes, WindowType) +#endif + + enum ColorFormat { + InvalidColorFormat, + RGB565, + RGBA5658, + RGBA5551, + RGB888, + RGBA5658, + }; + + enum SwapBehavior { + DefaultSwapBehavior, + SingleBuffer, + DoubleBuffer, + TripleBuffer + }; + + enum OpenGLContextProfile { + NoProfile, + CoreProfile, + CompatibilityProfile + }; + + QWindowFormat(); + QWindowFormat(FormatOptions options); + QWindowFormat(const QWindowFormat &other); + QWindowFormat &operator=(const QWindowFormat &other); + ~QWindowFormat(); + + void setDepthBufferSize(int size); + int depthBufferSize() const; + + void setStencilBufferSize(int size); + int stencilBufferSize() const; + + void setSamples(int numSamples); + int samples() const; + + void setSwapBehavior(SwapBehavior behavior); + SwapBehavior swapBehavior() const; + + void setColorFormat(ColorFormat format); + ColorFormat colorFormat() const; + + void setProfile(OpenGLContextProfile profile); + OpenGLContextProfile profile() const; + + void setSharedContext(QPlatformGLContext *context); + QPlatformGLContext *sharedGLContext() const; + + bool depth() const; + void setDepth(bool enable); + bool stencil() const; + void setStencil(bool enable); + bool stereo() const; + void setStereo(bool enable); + bool hasWindowSurface() const; + void setWindowSurface(bool enable); + + void setOption(QWindowFormat::FormatOptions opt); + bool testOption(QWindowFormat::FormatOptions opt) const; + +private: + QWindowFormatPrivate *d; + + void detach(); + + friend Q_GUI_EXPORT bool operator==(const QWindowFormat&, const QWindowFormat&); + friend Q_GUI_EXPORT bool operator!=(const QWindowFormat&, const QWindowFormat&); +#ifndef QT_NO_DEBUG_STREAM + friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QWindowFormat &); +#endif +}; + +Q_GUI_EXPORT bool operator==(const QWindowFormat&, const QWindowFormat&); +Q_GUI_EXPORT bool operator!=(const QWindowFormat&, const QWindowFormat&); + +#ifndef QT_NO_DEBUG_STREAM +Q_OPENGL_EXPORT QDebug operator<<(QDebug, const QWindowFormat &); +#endif + +Q_DECLARE_OPERATORS_FOR_FLAGS(QWindowFormat::FormatOptions) +Q_DECLARE_OPERATORS_FOR_FLAGS(QWindowFormat::WindowTypes) + +inline bool QWindowFormat::doubleBuffer() const +{ + return testOption(QWindowFormat::DoubleBuffer); +} + +inline bool QWindowFormat::depth() const +{ + return testOption(QWindowFormat::DepthBuffer); +} + +inline bool QWindowFormat::rgba() const +{ + return testOption(QWindowFormat::Rgba); +} + +inline bool QWindowFormat::alpha() const +{ + return testOption(QWindowFormat::AlphaChannel); +} + +inline bool QWindowFormat::accum() const +{ + return testOption(QWindowFormat::AccumBuffer); +} + +inline bool QWindowFormat::stencil() const +{ + return testOption(QWindowFormat::StencilBuffer); +} + +inline bool QWindowFormat::stereo() const +{ + return testOption(QWindowFormat::StereoBuffers); +} + +inline bool QWindowFormat::directRendering() const +{ + return testOption(QWindowFormat::DirectRendering); +} + +inline bool QWindowFormat::hasWindowSurface() const +{ + return testOption(QWindowFormat::HasWindowSurface); +} + +inline bool QWindowFormat::sampleBuffers() const +{ + return testOption(QWindowFormat::SampleBuffers); +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif //QPLATFORMWINDOWFORMAT_QPA_H -- cgit v1.2.3