Qt 4.8
qplatformwindowformat_qpa.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
43 
44 #include <QtCore/QDebug>
45 
46 Q_GLOBAL_STATIC(QPlatformWindowFormat, q_platformwindow_default_format);
47 
49 {
50 public:
52  : ref(1)
56  | QPlatformWindowFormat::HasWindowSurface)
57  , depthSize(-1)
58  , accumSize(-1)
59  , stencilSize(-1)
60  , redSize(-1)
61  , greenSize(-1)
62  , blueSize(-1)
63  , alphaSize(-1)
64  , numSamples(-1)
65  , swapInterval(-1)
67  , sharedContext(0)
68  {
69  }
70 
72  : ref(1),
73  opts(other->opts),
74  depthSize(other->depthSize),
75  accumSize(other->accumSize),
76  stencilSize(other->stencilSize),
77  redSize(other->redSize),
78  greenSize(other->greenSize),
79  blueSize(other->blueSize),
80  alphaSize(other->alphaSize),
81  numSamples(other->numSamples),
82  swapInterval(other->swapInterval),
83  windowApi(other->windowApi),
85  {
86  }
88  QPlatformWindowFormat::FormatOptions opts;
89  int depthSize;
90  int accumSize;
92  int redSize;
93  int greenSize;
94  int blueSize;
95  int alphaSize;
100 };
101 
191 {
193 }
194 
195 
215 QPlatformWindowFormat::QPlatformWindowFormat(QPlatformWindowFormat::FormatOptions options)
216 {
218  QPlatformWindowFormat::FormatOptions newOpts = options;
219  d->opts = defaultFormat().d->opts;
220  d->opts |= (newOpts & 0xffff);
221  d->opts &= ~(newOpts >> 16);
222 }
223 
228 {
229  if (d->ref != 1) {
231  if (!d->ref.deref())
232  delete d;
233  d = newd;
234  }
235 }
236 
242 {
243  d = other.d;
244  d->ref.ref();
245 }
246 
252 {
253  if (d != other.d) {
254  other.d->ref.ref();
255  if (!d->ref.deref())
256  delete d;
257  d = other.d;
258  }
259  return *this;
260 }
261 
266 {
267  if (!d->ref.deref())
268  delete d;
269 }
270 
300 {
302 }
303 
304 
333 {
335 }
336 
337 
367 {
369 }
370 
371 
398 {
400 }
401 
402 
428 {
430 }
431 
432 
458 {
460 }
461 
462 
488 {
490 }
491 
492 
521 {
523 }
524 
546 {
548 }
549 
558 {
559  return d->numSamples;
560 }
561 
570 {
571  detach();
572  if (numSamples < 0) {
573  qWarning("QPlatformWindowFormat::setSamples: Cannot have negative number of samples per pixel %d", numSamples);
574  return;
575  }
576  d->numSamples = numSamples;
577  setSampleBuffers(numSamples > 0);
578 }
579 
602 {
603  detach();
604  d->swapInterval = interval;
605 }
606 
617 {
618  return d->swapInterval;
619 }
620 
622 {
623  detach();
624  d->windowApi = api;
625 }
626 
628 {
629  return d->windowApi;
630 }
631 
633 {
634  d->sharedContext = context;
635 }
636 
638 {
639  return d->sharedContext;
640 }
641 
664 {
666 }
667 
674 void QPlatformWindowFormat::setOption(QPlatformWindowFormat::FormatOptions opt)
675 {
676  detach();
677  if (opt & 0xffff)
678  d->opts |= opt;
679  else
680  d->opts &= ~(opt >> 16);
681 }
682 
683 
684 
691 bool QPlatformWindowFormat::testOption(QPlatformWindowFormat::FormatOptions opt) const
692 {
693  if (opt & 0xffff)
694  return (d->opts & opt) != 0;
695  else
696  return (d->opts & (opt >> 16)) == 0;
697 }
698 
705 {
706  detach();
707  if (size < 0) {
708  qWarning("QPlatformWindowFormat::setDepthBufferSize: Cannot set negative depth buffer size %d", size);
709  return;
710  }
711  d->depthSize = size;
712  setDepth(size > 0);
713 }
714 
721 {
722  return d->depthSize;
723 }
724 
736 {
737  detach();
738  if (size < 0) {
739  qWarning("QPlatformWindowFormat::setRedBufferSize: Cannot set negative red buffer size %d", size);
740  return;
741  }
742  d->redSize = size;
743 }
744 
756 {
757  return d->redSize;
758 }
759 
771 {
772  detach();
773  if (size < 0) {
774  qWarning("QPlatformWindowFormat::setGreenBufferSize: Cannot set negative green buffer size %d", size);
775  return;
776  }
777  d->greenSize = size;
778 }
779 
791 {
792  return d->greenSize;
793 }
794 
806 {
807  detach();
808  if (size < 0) {
809  qWarning("QPlatformWindowFormat::setBlueBufferSize: Cannot set negative blue buffer size %d", size);
810  return;
811  }
812  d->blueSize = size;
813 }
814 
826 {
827  return d->blueSize;
828 }
829 
837 {
838  detach();
839  if (size < 0) {
840  qWarning("QPlatformWindowFormat::setAlphaBufferSize: Cannot set negative alpha buffer size %d", size);
841  return;
842  }
843  d->alphaSize = size;
844  setAlpha(size > 0);
845 }
846 
853 {
854  return d->alphaSize;
855 }
856 
864 {
865  detach();
866  if (size < 0) {
867  qWarning("QPlatformWindowFormat::setAccumBufferSize: Cannot set negative accumulate buffer size %d", size);
868  return;
869  }
870  d->accumSize = size;
871  setAccum(size > 0);
872 }
873 
880 {
881  return d->accumSize;
882 }
883 
890 {
891  detach();
892  if (size < 0) {
893  qWarning("QPlatformWindowFormat::setStencilBufferSize: Cannot set negative stencil buffer size %d", size);
894  return;
895  }
896  d->stencilSize = size;
897  setStencil(size > 0);
898 }
899 
906 {
907  return d->stencilSize;
908 }
909 
923 {
924  return *q_platformwindow_default_format();
925 }
926 
937 {
938  *q_platformwindow_default_format() = f;
939 }
940 
941 
942 /*
943  Returns the default QPlatformWindowFormat for overlay contexts.
944 
945  The default overlay format is:
946  \list
947  <li> \link setDoubleBuffer() Double buffer:\endlink Disabled.
948  <li> \link setDepth() Depth buffer:\endlink Disabled.
949  <li> \link setRgba() RGBA:\endlink Disabled (i.e., color index enabled).
950  <li> \link setAlpha() Alpha channel:\endlink Disabled.
951  <li> \link setAccum() Accumulator buffer:\endlink Disabled.
952  <li> \link setStencil() Stencil buffer:\endlink Disabled.
953  <li> \link setStereo() Stereo:\endlink Disabled.
954  <li> \link setDirectRendering() Direct rendering:\endlink Enabled.
955  <li> \link setSampleBuffers() Multisample buffers:\endlink Disabled.
956  \endlist
957 
958  \sa setDefaultFormat()
959 */
960 
961 //QPlatformWindowFormat QPlatformWindowFormat::defaultOverlayFormat()
962 //{
963 // return *defaultOverlayFormatInstance();
964 //}
965 
967 // Sets a new default QPlatformWindowFormat for overlay contexts to \a f. This
968 // format is used whenever a QGLWidget is created with a format that
969 // hasOverlay() enabled.
970 
971 // For example, to get a double buffered overlay context (if
972 // available), use code like this:
973 
974 // \snippet doc/src/snippets/code/src_opengl_qgl.cpp 5
975 
976 // As usual, you can find out after widget creation whether the
977 // underlying OpenGL system was able to provide the requested
978 // specification:
979 
980 // \snippet doc/src/snippets/code/src_opengl_qgl.cpp 6
981 
982 // \sa defaultOverlayFormat()
983 //*/
984 
985 //void QPlatformWindowFormat::setDefaultOverlayFormat(const QPlatformWindowFormat &f)
986 //{
987 // QPlatformWindowFormat *defaultFormat = defaultOverlayFormatInstance();
988 // *defaultFormat = f;
989 // // Make sure the user doesn't request that the overlays themselves
990 // // have overlays, since it is unlikely that the system supports
991 // // infinitely many planes...
992 // defaultFormat->setOverlay(false);
993 //}
994 
995 
1009 {
1010  return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts
1011  && a.d->alphaSize == b.d->alphaSize
1012  && a.d->accumSize == b.d->accumSize
1013  && a.d->stencilSize == b.d->stencilSize
1014  && a.d->depthSize == b.d->depthSize
1015  && a.d->redSize == b.d->redSize
1016  && a.d->greenSize == b.d->greenSize
1017  && a.d->blueSize == b.d->blueSize
1018  && a.d->numSamples == b.d->numSamples
1019  && a.d->swapInterval == b.d->swapInterval
1020  && a.d->windowApi == b.d->windowApi);
1021 }
1022 
1023 
1037 {
1038  return !(a == b);
1039 }
1040 
1041 #ifndef QT_NO_DEBUG_STREAM
1043 {
1044  const QPlatformWindowFormatPrivate * const d = f.d;
1045 
1046  dbg.nospace() << "QGLFormat("
1047  << "options " << d->opts
1048  << ", depthBufferSize " << d->depthSize
1049  << ", accumBufferSize " << d->accumSize
1050  << ", stencilBufferSize " << d->stencilSize
1051  << ", redBufferSize " << d->redSize
1052  << ", greenBufferSize " << d->greenSize
1053  << ", blueBufferSize " << d->blueSize
1054  << ", alphaBufferSize " << d->alphaSize
1055  << ", samples " << d->numSamples
1056  << ", swapInterval " << d->swapInterval
1057  << ')';
1058 
1059  return dbg.space();
1060 }
1061 #endif
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
double d
Definition: qnumeric_p.h:62
Q_GLOBAL_STATIC(QPlatformWindowFormat, q_platformwindow_default_format)
QPlatformWindowFormat::FormatOptions opts
void setSharedContext(QPlatformGLContext *context)
int greenBufferSize() const
Returns the green buffer size.
void setOption(QPlatformWindowFormat::FormatOptions opt)
Sets the format option to opt.
int swapInterval() const
Returns the currently set swap interval.
QPlatformWindowFormat()
Constructs a QPlatformWindowFormat object with the following default settings:
void setSwapInterval(int interval)
Set the preferred swap interval.
void setDepthBufferSize(int size)
Set the minimum depth buffer size to size.
bool testOption(QPlatformWindowFormat::FormatOptions opt) const
Returns true if format option opt is set; otherwise returns false.
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Definition: qatomic.h:55
~QPlatformWindowFormat()
Destroys the QPlatformWindowFormat.
void setStereo(bool enable)
If enable is true enables stereo buffering; otherwise disables stereo buffering.
QDebug operator<<(QDebug dbg, const QPlatformWindowFormat &f)
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
void setDirectRendering(bool enable)
If enable is true enables direct rendering; otherwise disables direct rendering.
int samples() const
Returns the number of samples per pixel when multisampling is enabled.
Definition: qgl.h:147
static QPlatformWindowFormat defaultFormat()
Returns the default QPlatformWindowFormat for the application.
QPlatformWindowFormatPrivate * d
The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if po...
long ASN1_INTEGER_get ASN1_INTEGER * a
void setBlueBufferSize(int size)
Set the preferred blue buffer size to size.
bool operator!=(QBool b1, bool b2)
Definition: qglobal.h:2026
bool ref()
Atomically increments the value of this QAtomicInt.
void setStencilBufferSize(int size)
Set the preferred stencil buffer size to size.
int stencilBufferSize() const
Returns the stencil buffer size.
QPlatformGLContext * sharedGLContext() const
void setAccumBufferSize(int size)
Set the preferred accumulation buffer size, where size is the bit depth for each RGBA component...
void setAlphaBufferSize(int size)
Set the preferred alpha buffer size to size.
Q_CORE_EXPORT void qWarning(const char *,...)
int depthBufferSize() const
Returns the depth buffer size.
int alphaBufferSize() const
Returns the alpha buffer size.
int accumBufferSize() const
Returns the accumulation buffer size.
void setSamples(int numSamples)
Set the preferred number of samples per pixel when multisampling is enabled to numSamples.
void setDoubleBuffer(bool enable)
If enable is true sets double buffering; otherwise sets single buffering.
void setRgba(bool enable)
If enable is true sets RGBA mode.
QPlatformWindowFormat::WindowApi windowApi
The QPlatformGLContext class provides an abstraction for native GL contexts.
void setAlpha(bool enable)
If enable is true enables the alpha buffer; otherwise disables the alpha buffer.
void setSampleBuffers(bool enable)
If enable is true, a GL context with multisample buffer support is picked; otherwise ignored...
void setWindowApi(QPlatformWindowFormat::WindowApi api)
int blueBufferSize() const
Returns the blue buffer size.
void setStencil(bool enable)
If enable is true enables the stencil buffer; otherwise disables the stencil buffer.
int redBufferSize() const
Returns the red buffer size.
void setRedBufferSize(int size)
Set the preferred red buffer size to size.
QPlatformWindowFormatPrivate(const QPlatformWindowFormatPrivate *other)
void setWindowSurface(bool enable)
If enable is true a top level QWidget will create a QWindowSurface at creation;.
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
void setAccum(bool enable)
If enable is true enables the accumulation buffer; otherwise disables the accumulation buffer...
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
void setGreenBufferSize(int size)
Set the preferred green buffer size to size.
void setDepth(bool enable)
If enable is true enables the depth buffer; otherwise disables the depth buffer.
QPlatformWindowFormat & operator=(const QPlatformWindowFormat &other)
Assigns other to this object.
static void setDefaultFormat(const QPlatformWindowFormat &f)
Sets a new default QPlatformWindowFormat for the application to f.