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
|
|
|
|
|
|
|
|
#include "kwinglutils.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
|
|
|
static X11SyncManager *create();
|
|
|
|
~X11SyncManager();
|
|
|
|
|
|
|
|
bool endFrame();
|
|
|
|
|
|
|
|
void triggerFence();
|
|
|
|
void insertWait();
|
|
|
|
|
|
|
|
private:
|
|
|
|
X11SyncManager();
|
|
|
|
|
|
|
|
X11SyncObject *m_currentFence = nullptr;
|
|
|
|
QVector<X11SyncObject *> m_fences;
|
|
|
|
int m_next = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace KWin
|