qopenglcompositor.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/platformcompositor/qopenglcompositor.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4static QOpenGLCompositor *compositor = 0;-
5-
6QOpenGLCompositor::QOpenGLCompositor()-
7 : m_context(0),-
8 m_targetWindow(0)-
9{-
10 ((!(!compositor)) ? qt_assert("!compositor",__FILE__,83) : qt_noop());-
11 m_updateTimer.setSingleShot(true);-
12 m_updateTimer.setInterval(0);-
13 connect(&m_updateTimer, qFlagLocation("2""timeout()" "\0" __FILE__ ":" "86"), qFlagLocation("1""handleRenderAllRequest()" "\0" __FILE__ ":" "86"));-
14}
never executed: end of block
0
15-
16QOpenGLCompositor::~QOpenGLCompositor()-
17{-
18 ((!(compositor == this)) ? qt_assert("compositor == this",__FILE__,91) : qt_noop());-
19 m_blitter.destroy();-
20 compositor = 0;-
21}
never executed: end of block
0
22-
23void QOpenGLCompositor::setTarget(QOpenGLContext *context, QWindow *targetWindow)-
24{-
25 m_context = context;-
26 m_targetWindow = targetWindow;-
27}
never executed: end of block
0
28-
29void QOpenGLCompositor::update()-
30{-
31 if (!m_updateTimer.isActive()
!m_updateTimer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
32 m_updateTimer.start();
never executed: m_updateTimer.start();
0
33}
never executed: end of block
0
34-
35QImage QOpenGLCompositor::grab()-
36{-
37 ((!(m_context && m_targetWindow)) ? qt_assert("m_context && m_targetWindow",__FILE__,110) : qt_noop());-
38 m_context->makeCurrent(m_targetWindow);-
39 QScopedPointer<QOpenGLFramebufferObject> fbo(new QOpenGLFramebufferObject(m_targetWindow->geometry().size()));-
40 renderAll(fbo.data());-
41 return
never executed: return fbo->toImage();
fbo->toImage();
never executed: return fbo->toImage();
0
42}-
43-
44void QOpenGLCompositor::handleRenderAllRequest()-
45{-
46 ((!(m_context && m_targetWindow)) ? qt_assert("m_context && m_targetWindow",__FILE__,119) : qt_noop());-
47 m_context->makeCurrent(m_targetWindow);-
48 renderAll(0);-
49}
never executed: end of block
0
50-
51void QOpenGLCompositor::renderAll(QOpenGLFramebufferObject *fbo)-
52{-
53 if (fbo
fboDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
54 fbo->bind();
never executed: fbo->bind();
0
55-
56 glClear(0x00004000 | 0x00000100 | 0x00000400);-
57-
58 const QRect targetWindowRect(QPoint(0, 0), m_targetWindow->geometry().size());-
59 glViewport(0, 0, targetWindowRect.width(), targetWindowRect.height());-
60-
61 if (!m_blitter.isCreated()
!m_blitter.isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
62 m_blitter.create();
never executed: m_blitter.create();
0
63-
64 m_blitter.bind();-
65-
66 for (int i = 0; i < m_windows.size()
i < m_windows.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
67 m_windows.at(i)->beginCompositing();
never executed: m_windows.at(i)->beginCompositing();
0
68-
69 for (int i = 0; i < m_windows.size()
i < m_windows.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
70 render(m_windows.at(i));
never executed: render(m_windows.at(i));
0
71-
72 m_blitter.release();-
73 if (!fbo
!fboDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
74 m_context->swapBuffers(m_targetWindow);
never executed: m_context->swapBuffers(m_targetWindow);
0
75 else-
76 fbo->release();
never executed: fbo->release();
0
77-
78 for (int i = 0; i < m_windows.size()
i < m_windows.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
79 m_windows.at(i)->endCompositing();
never executed: m_windows.at(i)->endCompositing();
0
80}
never executed: end of block
0
81-
82struct BlendStateBinder-
83{-
84 BlendStateBinder() : m_blend(false) {-
85 glDisable(0x0BE2);-
86 }
never executed: end of block
0
87 void set(bool blend) {-
88 if (blend != m_blend
blend != m_blendDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
89 if (blend
blendDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
90 glEnable(0x0BE2);-
91 glBlendFunc(0x0302, 0x0303);-
92 }
never executed: end of block
else {
0
93 glDisable(0x0BE2);-
94 }
never executed: end of block
0
95 m_blend = blend;-
96 }
never executed: end of block
0
97 }
never executed: end of block
0
98 ~BlendStateBinder() {-
99 if (m_blend
m_blendDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
100 glDisable(0x0BE2);
never executed: glDisable(0x0BE2);
0
101 }
never executed: end of block
0
102 bool m_blend;-
103};-
104-
105static inline QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight)-
106{-
107 return
never executed: return QRect(topLeftRect.x(), windowHeight - topLeftRect.bottomRight().y() - 1, topLeftRect.width(), topLeftRect.height());
QRect(topLeftRect.x(), windowHeight - topLeftRect.bottomRight().y() - 1,
never executed: return QRect(topLeftRect.x(), windowHeight - topLeftRect.bottomRight().y() - 1, topLeftRect.width(), topLeftRect.height());
0
108 topLeftRect.width(), topLeftRect.height());
never executed: return QRect(topLeftRect.x(), windowHeight - topLeftRect.bottomRight().y() - 1, topLeftRect.width(), topLeftRect.height());
0
109}-
110-
111static void clippedBlit(const QPlatformTextureList *textures, int idx, const QRect &targetWindowRect, QOpenGLTextureBlitter *blitter)-
112{-
113 const QRect clipRect = textures->clipRect(idx);-
114 if (clipRect.isEmpty()
clipRect.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
115 return;
never executed: return;
0
116-
117 const QRect rectInWindow = textures->geometry(idx);-
118 const QRect clippedRectInWindow = rectInWindow & clipRect.translated(rectInWindow.topLeft());-
119 const QRect srcRect = toBottomLeftRect(clipRect, rectInWindow.height());-
120-
121 const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(clippedRectInWindow, targetWindowRect);-
122 const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(srcRect, rectInWindow.size(),-
123 QOpenGLTextureBlitter::OriginBottomLeft);-
124-
125 blitter->blit(textures->textureId(idx), target, source);-
126}
never executed: end of block
0
127-
128void QOpenGLCompositor::render(QOpenGLCompositorWindow *window)-
129{-
130 const QPlatformTextureList *textures = window->textures();-
131 if (!textures
!texturesDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
132 return;
never executed: return;
0
133-
134 const QRect targetWindowRect(QPoint(0, 0), m_targetWindow->geometry().size());-
135 float currentOpacity = 1.0f;-
136 BlendStateBinder blend;-
137-
138 for (int i = 0; i < textures->count()
i < textures->count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
139 uint textureId = textures->textureId(i);-
140 const float opacity = window->sourceWindow()->opacity();-
141 if (opacity != currentOpacity
opacity != currentOpacityDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
142 currentOpacity = opacity;-
143 m_blitter.setOpacity(currentOpacity);-
144 }
never executed: end of block
0
145-
146 if (textures->count() > 1
textures->count() > 1Description
TRUEnever evaluated
FALSEnever evaluated
&& i == textures->count() - 1
i == textures->count() - 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
147-
148 blend.set(true);-
149 const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), targetWindowRect);-
150 m_blitter.blit(textureId, target, QOpenGLTextureBlitter::OriginTopLeft);-
151 }
never executed: end of block
else if (textures->count() == 1
textures->count() == 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
152-
153 const bool translucent = window->sourceWindow()->requestedFormat().alphaBufferSize() > 0;-
154 blend.set(translucent);-
155 const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), targetWindowRect);-
156 m_blitter.blit(textureId, target, QOpenGLTextureBlitter::OriginTopLeft);-
157 }
never executed: end of block
else if (!textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)
!textures->fla...::StacksOnTop)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
158-
159 blend.set(false);-
160 clippedBlit(textures, i, targetWindowRect, &m_blitter);-
161 }
never executed: end of block
0
162 }
never executed: end of block
0
163-
164 for (int i = 0; i < textures->count()
i < textures->count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
165 if (textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)
textures->flag...::StacksOnTop)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
166 blend.set(true);-
167 clippedBlit(textures, i, targetWindowRect, &m_blitter);-
168 }
never executed: end of block
0
169 }
never executed: end of block
0
170-
171 m_blitter.setOpacity(1.0f);-
172}
never executed: end of block
0
173-
174QOpenGLCompositor *QOpenGLCompositor::instance()-
175{-
176 if (!compositor
!compositorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
177 compositor = new QOpenGLCompositor;
never executed: compositor = new QOpenGLCompositor;
0
178 return
never executed: return compositor;
compositor;
never executed: return compositor;
0
179}-
180-
181void QOpenGLCompositor::destroy()-
182{-
183 delete compositor;-
184 compositor = 0;-
185}
never executed: end of block
0
186-
187void QOpenGLCompositor::addWindow(QOpenGLCompositorWindow *window)-
188{-
189 if (!m_windows.contains(window)
!m_windows.contains(window)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
190 m_windows.append(window);-
191 topWindowChanged(window);-
192 }
never executed: end of block
0
193}
never executed: end of block
0
194-
195void QOpenGLCompositor::removeWindow(QOpenGLCompositorWindow *window)-
196{-
197 m_windows.removeOne(window);-
198 if (!m_windows.isEmpty()
!m_windows.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
199 topWindowChanged(m_windows.last());
never executed: topWindowChanged(m_windows.last());
0
200}
never executed: end of block
0
201-
202void QOpenGLCompositor::moveToTop(QOpenGLCompositorWindow *window)-
203{-
204 m_windows.removeOne(window);-
205 m_windows.append(window);-
206 topWindowChanged(window);-
207}
never executed: end of block
0
208-
209void QOpenGLCompositor::changeWindowIndex(QOpenGLCompositorWindow *window, int newIdx)-
210{-
211 int idx = m_windows.indexOf(window);-
212 if (idx != -1
idx != -1Description
TRUEnever evaluated
FALSEnever evaluated
&& idx != newIdx
idx != newIdxDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
213 m_windows.move(idx, newIdx);-
214 if (newIdx == m_windows.size() - 1
newIdx == m_windows.size() - 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
215 topWindowChanged(m_windows.last());
never executed: topWindowChanged(m_windows.last());
0
216 }
never executed: end of block
0
217}
never executed: end of block
0
218-
219-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9