Changeset View
Changeset View
Standalone View
Standalone View
libkwineffects/kwineffectquickview.cpp
Show All 35 Lines | |||||
36 | #include <QOpenGLContext> | 36 | #include <QOpenGLContext> | ||
37 | #include <QOpenGLFramebufferObject> | 37 | #include <QOpenGLFramebufferObject> | ||
38 | #include <QTimer> | 38 | #include <QTimer> | ||
39 | 39 | | |||
40 | #include <KDeclarative/QmlObjectSharedEngine> | 40 | #include <KDeclarative/QmlObjectSharedEngine> | ||
41 | 41 | | |||
42 | using namespace KWin; | 42 | using namespace KWin; | ||
43 | 43 | | |||
44 | static std::unique_ptr<QOpenGLContext> s_shareContext; | 44 | static bool s_usingShareContexts = false; | ||
45 | 45 | | |||
46 | class Q_DECL_HIDDEN EffectQuickView::Private | 46 | class Q_DECL_HIDDEN EffectQuickView::Private | ||
47 | { | 47 | { | ||
48 | public: | 48 | public: | ||
49 | QQuickWindow *m_view; | 49 | QQuickWindow *m_view; | ||
50 | QQuickRenderControl *m_renderControl; | 50 | QQuickRenderControl *m_renderControl; | ||
51 | QScopedPointer<QOpenGLContext> m_glcontext; | 51 | QScopedPointer<QOpenGLContext> m_glcontext; | ||
52 | QScopedPointer<QOffscreenSurface> m_offscreenSurface; | 52 | QScopedPointer<QOffscreenSurface> m_offscreenSurface; | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 92 | if (!usingGl) { | |||
95 | d->m_renderControl->initialize(nullptr); | 95 | d->m_renderControl->initialize(nullptr); | ||
96 | } else { | 96 | } else { | ||
97 | QSurfaceFormat format; | 97 | QSurfaceFormat format; | ||
98 | format.setOption(QSurfaceFormat::ResetNotification); | 98 | format.setOption(QSurfaceFormat::ResetNotification); | ||
99 | format.setDepthBufferSize(16); | 99 | format.setDepthBufferSize(16); | ||
100 | format.setStencilBufferSize(8); | 100 | format.setStencilBufferSize(8); | ||
101 | 101 | | |||
102 | d->m_glcontext.reset(new QOpenGLContext); | 102 | d->m_glcontext.reset(new QOpenGLContext); | ||
103 | d->m_glcontext->setShareContext(s_shareContext.get()); | 103 | d->m_glcontext->setShareContext(QOpenGLContext::globalShareContext()); | ||
104 | d->m_glcontext->setFormat(format); | 104 | d->m_glcontext->setFormat(format); | ||
105 | d->m_glcontext->create(); | 105 | d->m_glcontext->create(); | ||
106 | 106 | | |||
107 | // and the offscreen surface | 107 | // and the offscreen surface | ||
108 | d->m_offscreenSurface.reset(new QOffscreenSurface); | 108 | d->m_offscreenSurface.reset(new QOffscreenSurface); | ||
109 | d->m_offscreenSurface->setFormat(d->m_glcontext->format()); | 109 | d->m_offscreenSurface->setFormat(d->m_glcontext->format()); | ||
110 | d->m_offscreenSurface->create(); | 110 | d->m_offscreenSurface->create(); | ||
111 | 111 | | |||
112 | d->m_glcontext->makeCurrent(d->m_offscreenSurface.data()); | 112 | d->m_glcontext->makeCurrent(d->m_offscreenSurface.data()); | ||
113 | d->m_renderControl->initialize(d->m_glcontext.data()); | 113 | d->m_renderControl->initialize(d->m_glcontext.data()); | ||
114 | d->m_glcontext->doneCurrent(); | 114 | d->m_glcontext->doneCurrent(); | ||
115 | 115 | | |||
116 | if (!d->m_glcontext->shareContext()) { | | |||
117 | qCDebug(LIBKWINEFFECTS) << "Failed to create a shared context, falling back to raster rendering"; | | |||
118 | 116 | | |||
119 | qCDebug(LIBKWINEFFECTS) << "Extra debug:"; | 117 | if (!s_usingShareContexts) { | ||
120 | qCDebug(LIBKWINEFFECTS) << "our context:" << d->m_glcontext.data(); | | |||
121 | qCDebug(LIBKWINEFFECTS) << "share context:" << s_shareContext.get(); | | |||
122 | | ||||
123 | // still render via GL, but blit for presentation | | |||
124 | d->m_useBlit = true; | 118 | d->m_useBlit = true; | ||
125 | } | 119 | } | ||
126 | } | 120 | } | ||
127 | 121 | | |||
128 | auto updateSize = [this]() { contentItem()->setSize(d->m_view->size()); }; | 122 | auto updateSize = [this]() { contentItem()->setSize(d->m_view->size()); }; | ||
129 | updateSize(); | 123 | updateSize(); | ||
130 | connect(d->m_view, &QWindow::widthChanged, this, updateSize); | 124 | connect(d->m_view, &QWindow::widthChanged, this, updateSize); | ||
131 | connect(d->m_view, &QWindow::heightChanged, this, updateSize); | 125 | connect(d->m_view, &QWindow::heightChanged, this, updateSize); | ||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Line(s) | |||||
244 | void EffectQuickView::forwardKeyEvent(QKeyEvent *keyEvent) | 238 | void EffectQuickView::forwardKeyEvent(QKeyEvent *keyEvent) | ||
245 | { | 239 | { | ||
246 | if (!d->m_visible) { | 240 | if (!d->m_visible) { | ||
247 | return; | 241 | return; | ||
248 | } | 242 | } | ||
249 | QCoreApplication::sendEvent(d->m_view, keyEvent); | 243 | QCoreApplication::sendEvent(d->m_view, keyEvent); | ||
250 | } | 244 | } | ||
251 | 245 | | |||
252 | void EffectQuickView::setShareContext(std::unique_ptr<QOpenGLContext> context) | 246 | void EffectQuickView::setUsingShareContexts(bool usingShare) | ||
253 | { | 247 | { | ||
254 | s_shareContext = std::move(context); | 248 | s_usingShareContexts = usingShare; | ||
255 | } | 249 | } | ||
256 | 250 | | |||
257 | QRect EffectQuickView::geometry() const | 251 | QRect EffectQuickView::geometry() const | ||
258 | { | 252 | { | ||
259 | return d->m_view->geometry(); | 253 | return d->m_view->geometry(); | ||
260 | } | 254 | } | ||
261 | 255 | | |||
262 | QQuickItem *EffectQuickView::contentItem() const | 256 | QQuickItem *EffectQuickView::contentItem() const | ||
▲ Show 20 Lines • Show All 127 Lines • Show Last 20 Lines |