Coverage Report

Created: 2026-02-10 07:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/gui/kernel/qsurface.cpp
Line
Count
Source
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 OpenVGSurface The surface is an OpenVG compatible surface and can be used
43
    in conjunction with OpenVG contexts.
44
    \value VulkanSurface The surface is a Vulkan compatible surface and can be used
45
    in conjunction with the Vulkan graphics API.
46
    \value MetalSurface The surface is a Metal compatible surface and can be used
47
    in conjunction with Apple's Metal graphics API. This surface type is only supported
48
    on \macos and iOS.
49
    \value Direct3DSurface The surface is a Direct 3D 11 and 12 compatible
50
    surface and can be used in conjunction with the DXGI and Direct3D APIs. This
51
    surface type is only supported on Windows.
52
53
    \omitvalue RasterGLSurface
54
 */
55
56
/*!
57
    \fn QSurfaceFormat QSurface::format() const
58
59
    Returns the format of the surface.
60
 */
61
62
/*!
63
  Returns true if the surface is OpenGL compatible and can be used in
64
  conjunction with QOpenGLContext; otherwise returns false.
65
66
  \since 5.3
67
*/
68
69
bool QSurface::supportsOpenGL() const
70
0
{
71
0
    static bool openGLOnRasterSurfaceSupported =
72
0
        QGuiApplicationPrivate::instance()->platformIntegration()->hasCapability(QPlatformIntegration::OpenGLOnRasterSurface);
73
0
    return surfaceType() == OpenGLSurface
74
0
           || (surfaceType() == RasterSurface && openGLOnRasterSurfaceSupported);
75
0
}
76
77
/*!
78
    \fn QPlatformSurface *QSurface::surfaceHandle() const
79
80
    Returns a handle to the platform-specific implementation of the surface.
81
 */
82
83
/*!
84
    \fn SurfaceType QSurface::surfaceType() const
85
86
    Returns the type of the surface.
87
 */
88
89
/*!
90
    \fn QSize QSurface::size() const
91
92
    Returns the size of the surface in pixels.
93
 */
94
95
/*!
96
    Creates a surface with the given \a type.
97
*/
98
QSurface::QSurface(SurfaceClass type)
99
0
    : m_type(type), m_reserved(nullptr)
100
0
{
101
0
}
102
103
/*!
104
    Destroys the surface.
105
*/
106
QSurface::~QSurface()
107
0
{
108
#ifndef QT_NO_OPENGL
109
    QOpenGLContext *context = QOpenGLContext::currentContext();
110
    if (context && context->surface() == this)
111
        context->doneCurrent();
112
#endif
113
0
}
114
115
/*!
116
   Returns the surface class of this surface.
117
 */
118
QSurface::SurfaceClass QSurface::surfaceClass() const
119
0
{
120
0
    return m_type;
121
0
}
122
123
QT_END_NAMESPACE
124
125
#include "moc_qsurface.cpp"
126