1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
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 The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qsurface.h" |
41 | #include "qopenglcontext.h" |
42 | #include <qpa/qplatformintegration.h> |
43 | #include <QtGui/private/qguiapplication_p.h> |
44 | |
45 | QT_BEGIN_NAMESPACE |
46 | |
47 | |
48 | /*! |
49 | \class QSurface |
50 | \inmodule QtGui |
51 | \since 5.0 |
52 | \brief The QSurface class is an abstraction of renderable surfaces in Qt. |
53 | |
54 | The size of the surface is accessible with the size() function. The rendering |
55 | specific attributes of the surface are accessible through the format() function. |
56 | */ |
57 | |
58 | |
59 | /*! |
60 | \enum QSurface::SurfaceClass |
61 | |
62 | The SurfaceClass enum describes the actual subclass of the surface. |
63 | |
64 | \value Window The surface is an instance of QWindow. |
65 | \value Offscreen The surface is an instance of QOffscreenSurface. |
66 | */ |
67 | |
68 | |
69 | /*! |
70 | \enum QSurface::SurfaceType |
71 | |
72 | The SurfaceType enum describes what type of surface this is. |
73 | |
74 | \value RasterSurface The surface is is composed of pixels and can be rendered to using |
75 | a software rasterizer like Qt's raster paint engine. |
76 | \value OpenGLSurface The surface is an OpenGL compatible surface and can be used |
77 | in conjunction with QOpenGLContext. |
78 | \value RasterGLSurface The surface can be rendered to using a software rasterizer, |
79 | and also supports OpenGL. This surface type is intended for internal Qt use, and |
80 | requires the use of private API. |
81 | \value OpenVGSurface The surface is an OpenVG compatible surface and can be used |
82 | in conjunction with OpenVG contexts. |
83 | \value VulkanSurface The surface is a Vulkan compatible surface and can be used |
84 | in conjunction with the Vulkan graphics API. |
85 | \value MetalSurface The surface is a Metal compatible surface and can be used |
86 | in conjunction with Apple's Metal graphics API. This surface type is supported |
87 | on macOS only. |
88 | |
89 | */ |
90 | |
91 | |
92 | /*! |
93 | \fn QSurfaceFormat QSurface::format() const |
94 | |
95 | Returns the format of the surface. |
96 | */ |
97 | |
98 | /*! |
99 | Returns true if the surface is OpenGL compatible and can be used in |
100 | conjunction with QOpenGLContext; otherwise returns false. |
101 | |
102 | \since 5.3 |
103 | */ |
104 | |
105 | bool QSurface::supportsOpenGL() const |
106 | { |
107 | SurfaceType type = surfaceType(); |
108 | if (type == RasterSurface) { |
109 | QPlatformIntegration *integ = QGuiApplicationPrivate::instance()->platformIntegration(); |
110 | return integ->hasCapability(cap: QPlatformIntegration::OpenGLOnRasterSurface); |
111 | } |
112 | return type == OpenGLSurface || type == RasterGLSurface; |
113 | } |
114 | |
115 | /*! |
116 | \fn QPlatformSurface *QSurface::surfaceHandle() const |
117 | |
118 | Returns a handle to the platform-specific implementation of the surface. |
119 | */ |
120 | |
121 | /*! |
122 | \fn SurfaceType QSurface::surfaceType() const |
123 | |
124 | Returns the type of the surface. |
125 | */ |
126 | |
127 | /*! |
128 | \fn QSize QSurface::size() const |
129 | |
130 | Returns the size of the surface in pixels. |
131 | */ |
132 | |
133 | /*! |
134 | Creates a surface with the given \a type. |
135 | */ |
136 | QSurface::QSurface(SurfaceClass type) |
137 | : m_type(type), m_reserved(nullptr) |
138 | { |
139 | } |
140 | |
141 | /*! |
142 | Destroys the surface. |
143 | */ |
144 | QSurface::~QSurface() |
145 | { |
146 | #ifndef QT_NO_OPENGL |
147 | QOpenGLContext *context = QOpenGLContext::currentContext(); |
148 | if (context && context->surface() == this) |
149 | context->doneCurrent(); |
150 | #endif |
151 | } |
152 | |
153 | /*! |
154 | Returns the surface class of this surface. |
155 | */ |
156 | QSurface::SurfaceClass QSurface::surfaceClass() const |
157 | { |
158 | return m_type; |
159 | } |
160 | |
161 | QT_END_NAMESPACE |
162 | |
163 | |