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 | |
4 | #include "qsurface.h" |
5 | #include "qopenglcontext.h" |
6 | #include <qpa/qplatformintegration.h> |
7 | #include <QtGui/private/qguiapplication_p.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | QT_IMPL_METATYPE_EXTERN_TAGGED(QSurface*, QSurface_ptr) |
12 | |
13 | /*! |
14 | \class QSurface |
15 | \inmodule QtGui |
16 | \since 5.0 |
17 | \brief The QSurface class is an abstraction of renderable surfaces in Qt. |
18 | |
19 | The size of the surface is accessible with the size() function. The rendering |
20 | specific attributes of the surface are accessible through the format() function. |
21 | */ |
22 | |
23 | |
24 | /*! |
25 | \enum QSurface::SurfaceClass |
26 | |
27 | The SurfaceClass enum describes the actual subclass of the surface. |
28 | |
29 | \value Window The surface is an instance of QWindow. |
30 | \value Offscreen The surface is an instance of QOffscreenSurface. |
31 | */ |
32 | |
33 | /*! |
34 | \enum QSurface::SurfaceType |
35 | |
36 | The SurfaceType enum describes what type of surface this is. |
37 | |
38 | \value RasterSurface The surface is composed of pixels and can be rendered to using |
39 | a software rasterizer like Qt's raster paint engine. |
40 | \value OpenGLSurface The surface is an OpenGL compatible surface and can be used |
41 | in conjunction with QOpenGLContext. |
42 | \value RasterGLSurface The surface can be rendered to using a software rasterizer, |
43 | and also supports OpenGL. This surface type is intended for internal Qt use, and |
44 | requires the use of private API. |
45 | \value OpenVGSurface The surface is an OpenVG compatible surface and can be used |
46 | in conjunction with OpenVG contexts. |
47 | \value VulkanSurface The surface is a Vulkan compatible surface and can be used |
48 | in conjunction with the Vulkan graphics API. |
49 | \value MetalSurface The surface is a Metal compatible surface and can be used |
50 | in conjunction with Apple's Metal graphics API. This surface type is only supported |
51 | on \macos and iOS. |
52 | \value Direct3DSurface The surface is a Direct 3D 11 and 12 compatible |
53 | surface and can be used in conjunction with the DXGI and Direct3D APIs. This |
54 | surface type is only supported on Windows. |
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 | |
70 | bool QSurface::supportsOpenGL() const |
71 | { |
72 | SurfaceType type = surfaceType(); |
73 | if (type == RasterSurface) { |
74 | QPlatformIntegration *integ = QGuiApplicationPrivate::instance()->platformIntegration(); |
75 | return integ->hasCapability(cap: QPlatformIntegration::OpenGLOnRasterSurface); |
76 | } |
77 | return type == OpenGLSurface || type == RasterGLSurface; |
78 | } |
79 | |
80 | /*! |
81 | \fn QPlatformSurface *QSurface::surfaceHandle() const |
82 | |
83 | Returns a handle to the platform-specific implementation of the surface. |
84 | */ |
85 | |
86 | /*! |
87 | \fn SurfaceType QSurface::surfaceType() const |
88 | |
89 | Returns the type of the surface. |
90 | */ |
91 | |
92 | /*! |
93 | \fn QSize QSurface::size() const |
94 | |
95 | Returns the size of the surface in pixels. |
96 | */ |
97 | |
98 | /*! |
99 | Creates a surface with the given \a type. |
100 | */ |
101 | QSurface::QSurface(SurfaceClass type) |
102 | : m_type(type), m_reserved(nullptr) |
103 | { |
104 | } |
105 | |
106 | /*! |
107 | Destroys the surface. |
108 | */ |
109 | QSurface::~QSurface() |
110 | { |
111 | #ifndef QT_NO_OPENGL |
112 | QOpenGLContext *context = QOpenGLContext::currentContext(); |
113 | if (context && context->surface() == this) |
114 | context->doneCurrent(); |
115 | #endif |
116 | } |
117 | |
118 | /*! |
119 | Returns the surface class of this surface. |
120 | */ |
121 | QSurface::SurfaceClass QSurface::surfaceClass() const |
122 | { |
123 | return m_type; |
124 | } |
125 | |
126 | QT_END_NAMESPACE |
127 | |
128 | #include "moc_qsurface.cpp" |
129 | |
130 | |