Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsurface.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include "qsurface.h"
7#include <qpa/qplatformintegration.h>
8#include <QtGui/private/qguiapplication_p.h>
9
11
12QT_IMPL_METATYPE_EXTERN_TAGGED(QSurface*, QSurface_ptr)
13
14/*!
15 \class QSurface
16 \inmodule QtGui
17 \since 5.0
18 \brief The QSurface class is an abstraction of renderable surfaces in Qt.
19
20 The size of the surface is accessible with the size() function. The rendering
21 specific attributes of the surface are accessible through the format() function.
22 */
23
24
25/*!
26 \enum QSurface::SurfaceClass
27
28 The SurfaceClass enum describes the actual subclass of the surface.
29
30 \value Window The surface is an instance of QWindow.
31 \value Offscreen The surface is an instance of QOffscreenSurface.
32 */
33
34/*!
35 \enum QSurface::SurfaceType
36
37 The SurfaceType enum describes what type of surface this is.
38
39 \value RasterSurface The surface is composed of pixels and can be rendered to using
40 a software rasterizer like Qt's raster paint engine.
41 \value OpenGLSurface The surface is an OpenGL compatible surface and can be used
42 in conjunction with QOpenGLContext.
43 \value OpenVGSurface The surface is an OpenVG compatible surface and can be used
44 in conjunction with OpenVG contexts.
45 \value VulkanSurface The surface is a Vulkan compatible surface and can be used
46 in conjunction with the Vulkan graphics API.
47 \value MetalSurface The surface is a Metal compatible surface and can be used
48 in conjunction with Apple's Metal graphics API. This surface type is only supported
49 on \macos and iOS.
50 \value Direct3DSurface The surface is a Direct 3D 11 and 12 compatible
51 surface and can be used in conjunction with the DXGI and Direct3D APIs. This
52 surface type is only supported on Windows.
53
54 \omitvalue RasterGLSurface
55 */
56
57/*!
58 \fn QSurfaceFormat QSurface::format() const
59
60 Returns the format of the surface.
61 */
62
63/*!
64 Returns true if the surface is OpenGL compatible and can be used in
65 conjunction with QOpenGLContext; otherwise returns false.
66
67 \since 5.3
68*/
69
70bool QSurface::supportsOpenGL() const
71{
72 static bool openGLOnRasterSurfaceSupported =
73 QGuiApplicationPrivate::instance()->platformIntegration()->hasCapability(QPlatformIntegration::OpenGLOnRasterSurface);
74 return surfaceType() == OpenGLSurface
75 || (surfaceType() == RasterSurface && openGLOnRasterSurfaceSupported);
76}
77
78/*!
79 \fn QPlatformSurface *QSurface::surfaceHandle() const
80
81 Returns a handle to the platform-specific implementation of the surface.
82 */
83
84/*!
85 \fn SurfaceType QSurface::surfaceType() const
86
87 Returns the type of the surface.
88 */
89
90/*!
91 \fn QSize QSurface::size() const
92
93 Returns the size of the surface in pixels.
94 */
95
96/*!
97 Creates a surface with the given \a type.
98*/
99QSurface::QSurface(SurfaceClass type)
100 : m_type(type), m_reserved(nullptr)
101{
102}
103
104/*!
105 Destroys the surface.
106*/
107QSurface::~QSurface()
108{
109#ifndef QT_NO_OPENGL
110 QOpenGLContext *context = QOpenGLContext::currentContext();
111 if (context && context->surface() == this)
112 context->doneCurrent();
113#endif
114}
115
116/*!
117 Returns the surface class of this surface.
118 */
119QSurface::SurfaceClass QSurface::surfaceClass() const
120{
121 return m_type;
122}
123
124QT_END_NAMESPACE
125
126#include "moc_qsurface.cpp"
Combined button and popup list for selecting options.