2021-06-11 11:11:57 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Fredrik Höglund <fredrik@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-11-14 13:53:24 +00:00
|
|
|
#include "opengl/glutils.h"
|
2021-06-11 11:11:57 +00:00
|
|
|
|
|
|
|
#include <xcb/sync.h>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <xcb/xcb.h>
|
2021-06-11 11:11:57 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2024-02-27 22:51:18 +00:00
|
|
|
class RenderBackend;
|
|
|
|
|
2021-06-11 11:11:57 +00:00
|
|
|
/**
|
|
|
|
* SyncObject represents a fence used to synchronize operations in the kwin command stream
|
|
|
|
* with operations in the X command stream.
|
|
|
|
*/
|
|
|
|
class X11SyncObject
|
|
|
|
{
|
|
|
|
public:
|
2022-03-23 10:13:38 +00:00
|
|
|
enum State {
|
|
|
|
Ready,
|
|
|
|
TriggerSent,
|
|
|
|
Waiting,
|
|
|
|
Done,
|
|
|
|
Resetting,
|
|
|
|
};
|
2021-06-11 11:11:57 +00:00
|
|
|
|
|
|
|
X11SyncObject();
|
|
|
|
~X11SyncObject();
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
State state() const
|
|
|
|
{
|
|
|
|
return m_state;
|
|
|
|
}
|
2021-06-11 11:11:57 +00:00
|
|
|
|
|
|
|
void trigger();
|
|
|
|
void wait();
|
|
|
|
bool finish();
|
|
|
|
void reset();
|
|
|
|
void finishResetting();
|
|
|
|
|
|
|
|
private:
|
|
|
|
State m_state;
|
|
|
|
GLsync m_sync;
|
|
|
|
xcb_sync_fence_t m_fence;
|
|
|
|
xcb_get_input_focus_cookie_t m_reset_cookie;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SyncManager manages a set of fences used for explicit synchronization with the X command
|
|
|
|
* stream.
|
|
|
|
*/
|
|
|
|
class X11SyncManager
|
|
|
|
{
|
|
|
|
public:
|
2022-03-23 10:13:38 +00:00
|
|
|
enum {
|
|
|
|
MaxFences = 4,
|
|
|
|
};
|
2021-06-11 11:11:57 +00:00
|
|
|
|
2024-02-27 22:51:18 +00:00
|
|
|
static X11SyncManager *create(RenderBackend *backend);
|
2021-06-11 11:11:57 +00:00
|
|
|
~X11SyncManager();
|
|
|
|
|
|
|
|
bool endFrame();
|
|
|
|
|
|
|
|
void triggerFence();
|
|
|
|
void insertWait();
|
|
|
|
|
|
|
|
private:
|
|
|
|
X11SyncManager();
|
|
|
|
|
|
|
|
X11SyncObject *m_currentFence = nullptr;
|
2023-10-19 06:50:15 +00:00
|
|
|
QList<X11SyncObject *> m_fences;
|
2021-06-11 11:11:57 +00:00
|
|
|
int m_next = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace KWin
|