Commit b7bd8472 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

scene: Reduce the call cost of Platform::supportsQpaContext()

Every time Platform::supportsQpaContext() is called, we go through the
list of supported extensions and perform a string comparison op. This is
not really cheap.
parent 968b57fe
......@@ -416,7 +416,7 @@ void Platform::warpPointer(const QPointF &globalPos)
bool Platform::supportsQpaContext() const
{
if (Compositor *c = Compositor::self()) {
return c->scene()->openGLPlatformInterfaceExtensions().contains(QByteArrayLiteral("EGL_KHR_surfaceless_context"));
return c->scene()->supportsSurfacelessContext();
}
return false;
}
......
......@@ -103,6 +103,7 @@ bool AbstractEglBackend::initEglAPI()
qCDebug(KWIN_OPENGL) << "EGL version: " << major << "." << minor;
const QByteArray eglExtensions = eglQueryString(m_display, EGL_EXTENSIONS);
setExtensions(eglExtensions.split(' '));
setSupportsSurfacelessContext(hasExtension(QByteArrayLiteral("EGL_KHR_surfaceless_context")));
return true;
}
......
......@@ -166,11 +166,9 @@ public:
return m_haveSwapBuffersWithDamage;
}
/**
* @returns whether the context is surfaceless
*/
bool isSurfaceLessContext() const {
return m_surfaceLessContext;
bool supportsSurfacelessContext() const
{
return m_haveSurfacelessContext;
}
/**
......@@ -267,6 +265,11 @@ protected:
m_haveSwapBuffersWithDamage = value;
}
void setSupportsSurfacelessContext(bool value)
{
m_haveSurfacelessContext = value;
}
/**
* @return const QRegion& Damage of previously rendered frame
*/
......@@ -285,13 +288,6 @@ protected:
m_renderTimer.start();
}
/**
* @param set whether the context is surface less
*/
void setSurfaceLessContext(bool set) {
m_surfaceLessContext = set;
}
/**
* Sets the platform-specific @p extensions.
*
......@@ -323,6 +319,10 @@ private:
*/
bool m_havePartialUpdate;
bool m_haveSwapBuffersWithDamage = false;
/**
* @brief Whether the backend supports EGL_KHR_surfaceless_context.
*/
bool m_haveSurfacelessContext = false;
/**
* @brief Whether the initialization failed, of course default to @c false.
*/
......@@ -339,7 +339,6 @@ private:
* @brief Timer to measure how long a frame renders.
*/
QElapsedTimer m_renderTimer;
bool m_surfaceLessContext = false;
QList<QByteArray> m_extensions;
};
......
......@@ -103,16 +103,14 @@ bool EglGbmBackend::initRenderingContext()
{
initBufferConfigs();
const char* eglExtensionsCString = eglQueryString(eglDisplay(), EGL_EXTENSIONS);
const QList<QByteArray> extensions = QByteArray::fromRawData(eglExtensionsCString, qstrlen(eglExtensionsCString)).split(' ');
if (!extensions.contains(QByteArrayLiteral("EGL_KHR_surfaceless_context"))) {
if (!supportsSurfacelessContext()) {
qCWarning(KWIN_VIRTUAL) << "EGL_KHR_surfaceless_context extension is unavailable";
return false;
}
if (!createContext()) {
return false;
}
setSurfaceLessContext(true);
return makeCurrent();
}
......
......@@ -860,6 +860,11 @@ void SceneOpenGL::doneOpenGLContextCurrent()
m_backend->doneCurrent();
}
bool SceneOpenGL::supportsSurfacelessContext() const
{
return m_backend->supportsSurfacelessContext();
}
Scene::EffectFrame *SceneOpenGL::createEffectFrame(EffectFrameImpl *frame)
{
return new SceneOpenGL::EffectFrame(frame, this);
......
......@@ -45,6 +45,7 @@ public:
bool syncsToVBlank() const override;
bool makeOpenGLContextCurrent() override;
void doneOpenGLContextCurrent() override;
bool supportsSurfacelessContext() const override;
Decoration::Renderer *createDecorationRenderer(Decoration::DecoratedClientImpl *impl) override;
void triggerFence() override;
virtual QMatrix4x4 projectionMatrix() const = 0;
......
......@@ -681,6 +681,11 @@ void Scene::doneOpenGLContextCurrent()
{
}
bool Scene::supportsSurfacelessContext() const
{
return false;
}
void Scene::triggerFence()
{
}
......
......@@ -139,6 +139,7 @@ public:
virtual bool makeOpenGLContextCurrent();
virtual void doneOpenGLContextCurrent();
virtual bool supportsSurfacelessContext() const;
virtual QMatrix4x4 screenProjectionMatrix() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment