mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-14 05:12:25 +08:00
Wayland implementation cleanup
Removed wayland-display in favour of screen-root, it should automatically switch between X11 and Wayland implementations Removed all the window-server-specific code from CWallpaperApplication Moved COutput from CWallpaperApplication to each CVideoDriver as the output is tied to the driver Moved CFullScreenDetector from CWallpaperApplication to each CVideoDriver as the detection is tied to the video driver Applied the Driver treatment to the Input, this way CInputContext doesn't depend on the driver used Updated CRenderContext to be aware of viewport-specific context updates Viewport information is now held inside COutputViewport instead of being a simple map Merged CLayerSurface and SWaylandOutput, inheriting from the new COutputViewport to standarize the minimum requirements of a viewport (makeCurrent and swapOutput are common requirements, X11 was the outlier not needing these per-viewport) Moved all the viewport-specific code of Wayland from CWaylandOpenGLDriver to It's own class CWaylandOutputViewport Fixed an issue under Wayland where sometimes the background surfaces wouldn't get anything drawn because the CWaylandOutput wasn't reset Updated screenshot-taking code to be standard for all drivers again Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
2b7367662f
commit
f21a6e64a7
@ -73,9 +73,19 @@ if (ENABLE_WAYLAND)
|
|||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
add_compile_definitions(ENABLE_WAYLAND)
|
add_compile_definitions(ENABLE_WAYLAND)
|
||||||
set(WAYLAND_SOURCES "src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h" "src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.cpp" "src/WallpaperEngine/Render/Drivers/Detectors/CWaylandFullScreenDetector.cpp"
|
set(WAYLAND_SOURCES
|
||||||
"src/WallpaperEngine/Render/Drivers/Detectors/CWaylandFullScreenDetector.h" "src/WallpaperEngine/Render/Drivers/Output/CWaylandOutput.cpp" "src/WallpaperEngine/Render/Drivers/Output/CWaylandOutput.h"
|
"src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h"
|
||||||
"src/WallpaperEngine/Input/CWaylandMouseInput.cpp" "src/WallpaperEngine/Input/CWaylandMouseInput.h" "xdg-shell-protocol.c" "wlr-layer-shell-unstable-v1-protocol.c")
|
"src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.cpp"
|
||||||
|
"src/WallpaperEngine/Render/Drivers/Detectors/CWaylandFullScreenDetector.cpp"
|
||||||
|
"src/WallpaperEngine/Render/Drivers/Detectors/CWaylandFullScreenDetector.h"
|
||||||
|
"src/WallpaperEngine/Render/Drivers/Output/CWaylandOutput.cpp"
|
||||||
|
"src/WallpaperEngine/Render/Drivers/Output/CWaylandOutput.h"
|
||||||
|
"src/WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.cpp"
|
||||||
|
"src/WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.h"
|
||||||
|
"src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.cpp"
|
||||||
|
"src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.h"
|
||||||
|
"xdg-shell-protocol.c"
|
||||||
|
"wlr-layer-shell-unstable-v1-protocol.c")
|
||||||
else()
|
else()
|
||||||
set(WAYLAND_SOURCES "")
|
set(WAYLAND_SOURCES "")
|
||||||
endif()
|
endif()
|
||||||
@ -142,8 +152,8 @@ add_executable(
|
|||||||
src/WallpaperEngine/Input/CInputContext.h
|
src/WallpaperEngine/Input/CInputContext.h
|
||||||
src/WallpaperEngine/Input/CMouseInput.cpp
|
src/WallpaperEngine/Input/CMouseInput.cpp
|
||||||
src/WallpaperEngine/Input/CMouseInput.h
|
src/WallpaperEngine/Input/CMouseInput.h
|
||||||
src/WallpaperEngine/Input/CGLFWMouseInput.cpp
|
src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.cpp
|
||||||
src/WallpaperEngine/Input/CGLFWMouseInput.h
|
src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.h
|
||||||
|
|
||||||
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h
|
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h
|
||||||
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp
|
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp
|
||||||
@ -175,6 +185,10 @@ add_executable(
|
|||||||
src/WallpaperEngine/Render/Drivers/Output/CX11Output.h
|
src/WallpaperEngine/Render/Drivers/Output/CX11Output.h
|
||||||
src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.cpp
|
src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.cpp
|
||||||
src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.h
|
src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.h
|
||||||
|
src/WallpaperEngine/Render/Drivers/Output/COutputViewport.cpp
|
||||||
|
src/WallpaperEngine/Render/Drivers/Output/COutputViewport.h
|
||||||
|
src/WallpaperEngine/Render/Drivers/Output/CX11OutputViewport.cpp
|
||||||
|
src/WallpaperEngine/Render/Drivers/Output/CX11OutputViewport.h
|
||||||
src/WallpaperEngine/Render/Drivers/CX11OpenGLDriver.h
|
src/WallpaperEngine/Render/Drivers/CX11OpenGLDriver.h
|
||||||
src/WallpaperEngine/Render/Drivers/CX11OpenGLDriver.cpp
|
src/WallpaperEngine/Render/Drivers/CX11OpenGLDriver.cpp
|
||||||
src/WallpaperEngine/Render/Drivers/CVideoDriver.h
|
src/WallpaperEngine/Render/Drivers/CVideoDriver.h
|
||||||
|
@ -13,7 +13,6 @@ using namespace WallpaperEngine::Application;
|
|||||||
|
|
||||||
struct option long_options[] = {
|
struct option long_options[] = {
|
||||||
{ "screen-root", required_argument, nullptr, 'r' },
|
{ "screen-root", required_argument, nullptr, 'r' },
|
||||||
{ "wayland-display", required_argument, nullptr, 'i' },
|
|
||||||
{ "bg", required_argument, nullptr, 'b' },
|
{ "bg", required_argument, nullptr, 'b' },
|
||||||
{ "window", required_argument, nullptr, 'w' },
|
{ "window", required_argument, nullptr, 'w' },
|
||||||
{ "pkg", required_argument, nullptr, 'p' },
|
{ "pkg", required_argument, nullptr, 'p' },
|
||||||
@ -85,7 +84,7 @@ CApplicationContext::CApplicationContext (int argc, char* argv[])
|
|||||||
|
|
||||||
std::string lastScreen;
|
std::string lastScreen;
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, "b:ri:p:d:shf:a:w:mn", long_options, nullptr)) != -1)
|
while ((c = getopt_long (argc, argv, "b:r:p:d:shf:a:w:mn", long_options, nullptr)) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
@ -125,25 +124,13 @@ CApplicationContext::CApplicationContext (int argc, char* argv[])
|
|||||||
if (this->settings.render.mode == EXPLICIT_WINDOW)
|
if (this->settings.render.mode == EXPLICIT_WINDOW)
|
||||||
sLog.exception ("Cannot run in both background and window mode");
|
sLog.exception ("Cannot run in both background and window mode");
|
||||||
|
|
||||||
this->settings.render.mode = X11_BACKGROUND;
|
this->settings.render.mode = DESKTOP_BACKGROUND;
|
||||||
lastScreen = optarg;
|
lastScreen = optarg;
|
||||||
this->settings.general.screenBackgrounds[lastScreen] = "";
|
this->settings.general.screenBackgrounds[lastScreen] = "";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
|
||||||
if (this->settings.general.screenBackgrounds.find (optarg) != this->settings.general.screenBackgrounds.end ())
|
|
||||||
sLog.exception ("Cannot specify the same screen more than once: ", optarg);
|
|
||||||
if (this->settings.render.mode == EXPLICIT_WINDOW)
|
|
||||||
sLog.exception ("Cannot run in both background and window mode");
|
|
||||||
|
|
||||||
this->settings.render.mode = WAYLAND_LAYER_SHELL;
|
|
||||||
lastScreen = optarg;
|
|
||||||
this->settings.general.screenBackgrounds[lastScreen] = "";
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
if (this->settings.render.mode == X11_BACKGROUND)
|
if (this->settings.render.mode == DESKTOP_BACKGROUND)
|
||||||
sLog.exception ("Cannot run in both background and window mode");
|
sLog.exception ("Cannot run in both background and window mode");
|
||||||
|
|
||||||
if (optarg != nullptr)
|
if (optarg != nullptr)
|
||||||
|
@ -25,12 +25,10 @@ namespace WallpaperEngine::Application
|
|||||||
{
|
{
|
||||||
/** Default window mode */
|
/** Default window mode */
|
||||||
NORMAL_WINDOW = 0,
|
NORMAL_WINDOW = 0,
|
||||||
/** Draw to X11 background */
|
/** Draw to the window server desktop */
|
||||||
X11_BACKGROUND = 1,
|
DESKTOP_BACKGROUND = 1,
|
||||||
/** Explicit window mode with specified geometry */
|
/** Explicit window mode with specified geometry */
|
||||||
EXPLICIT_WINDOW = 2,
|
EXPLICIT_WINDOW = 2,
|
||||||
/** Wayland mode - zwlr_layer_shell_v1 */
|
|
||||||
WAYLAND_LAYER_SHELL = 3,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
@ -8,6 +8,11 @@
|
|||||||
#include "WallpaperEngine/Render/CRenderContext.h"
|
#include "WallpaperEngine/Render/CRenderContext.h"
|
||||||
#include "WallpaperEngine/Application/CApplicationState.h"
|
#include "WallpaperEngine/Application/CApplicationState.h"
|
||||||
#include "WallpaperEngine/Audio/Drivers/Detectors/CPulseAudioPlayingDetector.h"
|
#include "WallpaperEngine/Audio/Drivers/Detectors/CPulseAudioPlayingDetector.h"
|
||||||
|
#include "WallpaperEngine/Input/Drivers/CWaylandMouseInput.h"
|
||||||
|
#include "WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h"
|
||||||
|
#include "WallpaperEngine/Input/Drivers/CGLFWMouseInput.h"
|
||||||
|
#include "WallpaperEngine/Render/Drivers/Detectors/CWaylandFullScreenDetector.h"
|
||||||
|
#include "WallpaperEngine/Render/Drivers/Output/CWaylandOutput.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -223,134 +228,87 @@ namespace WallpaperEngine::Application
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
// this should be getting called at the end of the frame, so the right thing should be bound already
|
// this should be getting called at the end of the frame, so the right thing should be bound already
|
||||||
|
int width = context.getOutput ().getFullWidth ();
|
||||||
int width = context.getOutput ()->getFullWidth ();
|
int height = context.getOutput ().getFullHeight ();
|
||||||
int height = context.getOutput ()->getFullHeight ();
|
|
||||||
|
|
||||||
// make room for storing the pixel data
|
|
||||||
uint8_t* buffer = new uint8_t[width * height * sizeof (uint8_t) * 3];
|
|
||||||
uint8_t* pixel = buffer;
|
|
||||||
|
|
||||||
// read the image into the buffer
|
|
||||||
glReadPixels (0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
|
||||||
|
|
||||||
// build the output file with FreeImage
|
// build the output file with FreeImage
|
||||||
static FIBITMAP* bitmap = FreeImage_Allocate (width, height, 24);
|
static FIBITMAP* bitmap = FreeImage_Allocate (width, height, 24);
|
||||||
RGBQUAD color;
|
RGBQUAD color;
|
||||||
|
int xoffset = 0;
|
||||||
|
|
||||||
|
for (const auto& viewport : context.getOutput ().getViewports ())
|
||||||
|
{
|
||||||
|
// activate opengl context so we can read from the framebuffer
|
||||||
|
viewport.second->makeCurrent ();
|
||||||
|
// make room for storing the pixel of this viewport
|
||||||
|
uint8_t* buffer = new uint8_t[viewport.second->viewport.z * viewport.second->viewport.w * sizeof (uint8_t) * 3];
|
||||||
|
uint8_t* pixel = buffer;
|
||||||
|
|
||||||
|
// read the viewport data into the pixel buffer
|
||||||
|
glReadPixels (
|
||||||
|
viewport.second->viewport.x, viewport.second->viewport.y,
|
||||||
|
viewport.second->viewport.z, viewport.second->viewport.w,
|
||||||
|
GL_RGB, GL_UNSIGNED_BYTE, buffer
|
||||||
|
);
|
||||||
|
|
||||||
if (!context.getDriver().requiresSeparateFlips()) {
|
|
||||||
// now get access to the pixels
|
// now get access to the pixels
|
||||||
for (int y = height; y > 0; y--)
|
for (int y = viewport.second->viewport.w; y > 0; y--)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < width; x++)
|
for (int x = 0; x < viewport.second->viewport.z; x++)
|
||||||
{
|
{
|
||||||
color.rgbRed = *pixel++;
|
color.rgbRed = *pixel++;
|
||||||
color.rgbGreen = *pixel++;
|
color.rgbGreen = *pixel++;
|
||||||
color.rgbBlue = *pixel++;
|
color.rgbBlue = *pixel++;
|
||||||
|
|
||||||
// set the pixel in the destination
|
// set the pixel in the destination
|
||||||
FreeImage_SetPixelColor (bitmap, x, (context.getOutput()->renderVFlip() ? (height - y) : y), &color);
|
FreeImage_SetPixelColor (bitmap, x + xoffset, context.getOutput ().renderVFlip() ? (viewport.second->viewport.w - y) : y, &color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally save the file
|
if (viewport.second->single)
|
||||||
FreeImage_Save (format, bitmap, filename.c_str (), 0);
|
xoffset += viewport.second->viewport.z;
|
||||||
|
|
||||||
// free all the used memory
|
// free the buffer allocated for the viewport
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
|
|
||||||
FreeImage_Unload (bitmap);
|
|
||||||
|
|
||||||
const_cast<CWallpaperApplication*>(&context.getApp())->getContext().settings.screenshot.take = false;
|
|
||||||
} else {
|
|
||||||
const auto RENDERING = context.getDriver().getCurrentlyRendered();
|
|
||||||
static int xoff = 0;
|
|
||||||
|
|
||||||
for (int y = height; y > 0; y--)
|
|
||||||
{
|
|
||||||
for (int x = 0; x < width; x++)
|
|
||||||
{
|
|
||||||
color.rgbRed = *pixel++;
|
|
||||||
color.rgbGreen = *pixel++;
|
|
||||||
color.rgbBlue = *pixel++;
|
|
||||||
|
|
||||||
// set the pixel in the destination
|
|
||||||
FreeImage_SetPixelColor (bitmap, x + xoff, (context.getOutput()->renderVFlip() ? (height - y) : y), &color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& [name, data] : context.getOutput()->getViewports()) {
|
|
||||||
if (name == RENDERING) {
|
|
||||||
xoff += data.viewport.z;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const_cast<CWallpaperApplication*>(&context.getApp())->screenshotOutputsDone.push_back(RENDERING);
|
|
||||||
|
|
||||||
if (const_cast<CWallpaperApplication*>(&context.getApp())->screenshotOutputsDone.size() >= context.getOutput()->getViewports().size()) {
|
|
||||||
// finally save the file
|
|
||||||
FreeImage_Save (format, bitmap, filename.c_str (), 0);
|
|
||||||
|
|
||||||
// free all the used memory
|
|
||||||
delete[] buffer;
|
|
||||||
|
|
||||||
FreeImage_Unload (bitmap);
|
|
||||||
|
|
||||||
const_cast<CWallpaperApplication*>(&context.getApp())->getContext().settings.screenshot.take = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// finally save the file
|
||||||
|
FreeImage_Save (format, bitmap, filename.c_str (), 0);
|
||||||
|
|
||||||
|
FreeImage_Unload (bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWallpaperApplication::show ()
|
void CWallpaperApplication::show ()
|
||||||
{
|
{
|
||||||
// initialize OpenGL driver
|
const bool WAYLAND_DISPLAY = getenv ("WAYLAND_DISPLAY");
|
||||||
#ifdef ENABLE_WAYLAND
|
|
||||||
const bool WAYLAND = getenv("WAYLAND_DISPLAY") && this->m_context.settings.render.mode == CApplicationContext::WAYLAND_LAYER_SHELL;
|
// setup the right video driver based on the environment and the startup mode requested
|
||||||
if (WAYLAND) {
|
if (WAYLAND_DISPLAY && this->m_context.settings.render.mode == CApplicationContext::DESKTOP_BACKGROUND)
|
||||||
videoDriver = std::make_unique<WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver>("wallpaperengine", this->m_context, this);
|
{
|
||||||
inputContext = std::make_unique<WallpaperEngine::Input::CInputContext>(*(WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver*)videoDriver.get());
|
auto waylandDriver = new WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver (this->m_context, *this);
|
||||||
} else {
|
inputContext = new WallpaperEngine::Input::CInputContext (new WallpaperEngine::Input::Drivers::CWaylandMouseInput (waylandDriver));
|
||||||
#endif
|
|
||||||
videoDriver = std::make_unique<WallpaperEngine::Render::Drivers::CX11OpenGLDriver>("wallpaperengine", this->m_context);
|
videoDriver = waylandDriver;
|
||||||
inputContext = std::make_unique<WallpaperEngine::Input::CInputContext>(*(WallpaperEngine::Render::Drivers::CX11OpenGLDriver*)videoDriver.get());
|
}
|
||||||
#ifdef ENABLE_WAYLAND
|
else
|
||||||
|
{
|
||||||
|
auto x11Driver = new WallpaperEngine::Render::Drivers::CX11OpenGLDriver ("wallpaperengine", this->m_context, *this);
|
||||||
|
// no wayland detected, try the old X11 method
|
||||||
|
inputContext = new WallpaperEngine::Input::CInputContext (new WallpaperEngine::Input::Drivers::CGLFWMouseInput (x11Driver));
|
||||||
|
|
||||||
|
videoDriver = x11Driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WAYLAND)
|
|
||||||
fullscreenDetector = std::make_unique<WallpaperEngine::Render::Drivers::Detectors::CWaylandFullScreenDetector>(this->m_context, *(WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver*)videoDriver.get());
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
fullscreenDetector = std::make_unique<WallpaperEngine::Render::Drivers::Detectors::CX11FullScreenDetector>(this->m_context, *videoDriver);
|
|
||||||
// stereo mix recorder for audio processing
|
// stereo mix recorder for audio processing
|
||||||
WallpaperEngine::Audio::Drivers::Recorders::CPulseAudioPlaybackRecorder audioRecorder;
|
WallpaperEngine::Audio::Drivers::Recorders::CPulseAudioPlaybackRecorder audioRecorder;
|
||||||
// audio playing detector
|
// audio playing detector
|
||||||
WallpaperEngine::Audio::Drivers::Detectors::CPulseAudioPlayingDetector audioDetector (this->m_context, *fullscreenDetector);
|
WallpaperEngine::Audio::Drivers::Detectors::CPulseAudioPlayingDetector audioDetector (this->m_context, videoDriver->getFullscreenDetector ());
|
||||||
// initialize sdl audio driver
|
// initialize sdl audio driver
|
||||||
audioDriver = std::make_unique<WallpaperEngine::Audio::Drivers::CSDLAudioDriver> (this->m_context, audioDetector, audioRecorder);
|
audioDriver = new WallpaperEngine::Audio::Drivers::CSDLAudioDriver (this->m_context, audioDetector, audioRecorder);
|
||||||
// initialize audio context
|
// initialize audio context
|
||||||
audioContext = std::make_unique<WallpaperEngine::Audio::CAudioContext> (*audioDriver);
|
audioContext = new WallpaperEngine::Audio::CAudioContext (*audioDriver);
|
||||||
|
|
||||||
// initialize the requested output
|
|
||||||
switch (this->m_context.settings.render.mode)
|
|
||||||
{
|
|
||||||
case CApplicationContext::EXPLICIT_WINDOW:
|
|
||||||
case CApplicationContext::NORMAL_WINDOW:
|
|
||||||
output = new WallpaperEngine::Render::Drivers::Output::CGLFWWindowOutput (this->m_context, *videoDriver, *fullscreenDetector);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CApplicationContext::X11_BACKGROUND:
|
|
||||||
output = new WallpaperEngine::Render::Drivers::Output::CX11Output (this->m_context, *videoDriver, *fullscreenDetector);
|
|
||||||
break;
|
|
||||||
#ifdef ENABLE_WAYLAND
|
|
||||||
case CApplicationContext::WAYLAND_LAYER_SHELL:
|
|
||||||
output = new WallpaperEngine::Render::Drivers::Output::CWaylandOutput (this->m_context, *videoDriver, *fullscreenDetector);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// initialize render context
|
// initialize render context
|
||||||
context = std::make_unique<WallpaperEngine::Render::CRenderContext> (output, *videoDriver, *inputContext, *this);
|
context = new WallpaperEngine::Render::CRenderContext (*videoDriver, *inputContext, *this);
|
||||||
|
|
||||||
// set all the specific wallpapers required
|
// set all the specific wallpapers required
|
||||||
for (const auto& it : this->m_backgrounds)
|
for (const auto& it : this->m_backgrounds)
|
||||||
@ -365,30 +323,8 @@ namespace WallpaperEngine::Application
|
|||||||
this->m_defaultBackground->getWallpaper (), *context, *audioContext
|
this->m_defaultBackground->getWallpaper (), *context, *audioContext
|
||||||
));
|
));
|
||||||
|
|
||||||
#ifdef ENABLE_WAYLAND
|
while (this->m_context.state.general.keepRunning && !videoDriver->closeRequested ())
|
||||||
if (WAYLAND) {
|
videoDriver->dispatchEventQueue ();
|
||||||
renderFrame();
|
|
||||||
|
|
||||||
while (this->m_context.state.general.keepRunning && !videoDriver->closeRequested ()) {
|
|
||||||
videoDriver->dispatchEventQueue();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
#endif
|
|
||||||
while (!videoDriver->closeRequested () && this->m_context.state.general.keepRunning) {
|
|
||||||
static float startTime, endTime, minimumTime = 1.0f / this->m_context.settings.render.maximumFPS;
|
|
||||||
// get the start time of the frame
|
|
||||||
startTime = videoDriver->getRenderTime ();
|
|
||||||
renderFrame();
|
|
||||||
// get the end time of the frame
|
|
||||||
endTime = videoDriver->getRenderTime ();
|
|
||||||
|
|
||||||
// ensure the frame time is correct to not overrun FPS
|
|
||||||
if ((endTime - startTime) < minimumTime)
|
|
||||||
usleep ((minimumTime - (endTime - startTime)) * CLOCKS_PER_SEC);
|
|
||||||
}
|
|
||||||
#ifdef ENABLE_WAYLAND
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ensure this is updated as sometimes it might not come from a signal
|
// ensure this is updated as sometimes it might not come from a signal
|
||||||
this->m_context.state.general.keepRunning = false;
|
this->m_context.state.general.keepRunning = false;
|
||||||
@ -398,7 +334,8 @@ namespace WallpaperEngine::Application
|
|||||||
SDL_Quit ();
|
SDL_Quit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWallpaperApplication::renderFrame() {
|
void CWallpaperApplication::update()
|
||||||
|
{
|
||||||
static time_t seconds;
|
static time_t seconds;
|
||||||
static struct tm* timeinfo;
|
static struct tm* timeinfo;
|
||||||
|
|
||||||
@ -422,10 +359,8 @@ namespace WallpaperEngine::Application
|
|||||||
if (!this->m_context.settings.screenshot.take || videoDriver->getFrameCounter () < 5)
|
if (!this->m_context.settings.screenshot.take || videoDriver->getFrameCounter () < 5)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (std::find_if(screenshotOutputsDone.begin(), screenshotOutputsDone.end(), [&] (const auto& other) { return other == context->getDriver().getCurrentlyRendered(); }) != screenshotOutputsDone.end())
|
|
||||||
return;
|
|
||||||
|
|
||||||
this->takeScreenshot (*context, this->m_context.settings.screenshot.path, this->m_context.settings.screenshot.format);
|
this->takeScreenshot (*context, this->m_context.settings.screenshot.path, this->m_context.settings.screenshot.format);
|
||||||
|
this->m_context.settings.screenshot.take = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWallpaperApplication::signal (int signal)
|
void CWallpaperApplication::signal (int signal)
|
||||||
@ -447,8 +382,4 @@ namespace WallpaperEngine::Application
|
|||||||
{
|
{
|
||||||
return this->m_context;
|
return this->m_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
WallpaperEngine::Render::Drivers::Output::COutput* CWallpaperApplication::getOutput() const {
|
|
||||||
return this->output;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -65,7 +65,7 @@ namespace WallpaperEngine::Application
|
|||||||
/**
|
/**
|
||||||
* Renders a frame
|
* Renders a frame
|
||||||
*/
|
*/
|
||||||
void renderFrame();
|
void update();
|
||||||
/**
|
/**
|
||||||
* Gets the output
|
* Gets the output
|
||||||
*/
|
*/
|
||||||
@ -116,13 +116,11 @@ namespace WallpaperEngine::Application
|
|||||||
/** Maps screens to backgrounds */
|
/** Maps screens to backgrounds */
|
||||||
std::map <std::string, Core::CProject*> m_backgrounds;
|
std::map <std::string, Core::CProject*> m_backgrounds;
|
||||||
|
|
||||||
std::unique_ptr<WallpaperEngine::Render::Drivers::CVideoDriver> videoDriver;
|
WallpaperEngine::Render::Drivers::CVideoDriver* videoDriver;
|
||||||
std::unique_ptr<WallpaperEngine::Input::CInputContext> inputContext;
|
WallpaperEngine::Input::CInputContext* inputContext;
|
||||||
WallpaperEngine::Render::Drivers::Output::COutput* output;
|
WallpaperEngine::Audio::Drivers::CSDLAudioDriver* audioDriver;
|
||||||
std::unique_ptr<WallpaperEngine::Render::Drivers::Detectors::CFullScreenDetector> fullscreenDetector;
|
WallpaperEngine::Render::CRenderContext* context;
|
||||||
std::unique_ptr<WallpaperEngine::Audio::Drivers::CSDLAudioDriver> audioDriver;
|
WallpaperEngine::Audio::CAudioContext* audioContext;
|
||||||
std::unique_ptr<WallpaperEngine::Render::CRenderContext> context;
|
|
||||||
std::unique_ptr<WallpaperEngine::Audio::CAudioContext> audioContext;
|
|
||||||
|
|
||||||
std::vector<std::string> screenshotOutputsDone;
|
std::vector<std::string> screenshotOutputsDone;
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,7 @@ namespace WallpaperEngine::Audio::Drivers::Detectors
|
|||||||
{
|
{
|
||||||
CAudioPlayingDetector::CAudioPlayingDetector (
|
CAudioPlayingDetector::CAudioPlayingDetector (
|
||||||
Application::CApplicationContext& appContext,
|
Application::CApplicationContext& appContext,
|
||||||
Render::Drivers::Detectors::CFullScreenDetector& fullscreenDetector) :
|
const Render::Drivers::Detectors::CFullScreenDetector& fullscreenDetector) :
|
||||||
m_applicationContext (appContext),
|
m_applicationContext (appContext),
|
||||||
m_fullscreenDetector (fullscreenDetector),
|
m_fullscreenDetector (fullscreenDetector),
|
||||||
m_isPlaying (false)
|
m_isPlaying (false)
|
||||||
@ -21,7 +21,7 @@ namespace WallpaperEngine::Audio::Drivers::Detectors
|
|||||||
return this->m_applicationContext;
|
return this->m_applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
Render::Drivers::Detectors::CFullScreenDetector& CAudioPlayingDetector::getFullscreenDetector ()
|
const Render::Drivers::Detectors::CFullScreenDetector& CAudioPlayingDetector::getFullscreenDetector () const
|
||||||
{
|
{
|
||||||
return this->m_fullscreenDetector;
|
return this->m_fullscreenDetector;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ namespace WallpaperEngine
|
|||||||
class CAudioPlayingDetector
|
class CAudioPlayingDetector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CAudioPlayingDetector (Application::CApplicationContext& appContext, Render::Drivers::Detectors::CFullScreenDetector& fullscreenDetector);
|
CAudioPlayingDetector (Application::CApplicationContext& appContext, const Render::Drivers::Detectors::CFullScreenDetector& fullscreenDetector);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If any kind of sound is currently playing on the default audio device
|
* @return If any kind of sound is currently playing on the default audio device
|
||||||
@ -48,13 +48,13 @@ namespace WallpaperEngine
|
|||||||
/**
|
/**
|
||||||
* @return The fullscreen detector used
|
* @return The fullscreen detector used
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] Render::Drivers::Detectors::CFullScreenDetector& getFullscreenDetector ();
|
[[nodiscard]] const Render::Drivers::Detectors::CFullScreenDetector& getFullscreenDetector () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_isPlaying;
|
bool m_isPlaying;
|
||||||
|
|
||||||
Application::CApplicationContext& m_applicationContext;
|
Application::CApplicationContext& m_applicationContext;
|
||||||
Render::Drivers::Detectors::CFullScreenDetector& m_fullscreenDetector;
|
const Render::Drivers::Detectors::CFullScreenDetector& m_fullscreenDetector;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ namespace WallpaperEngine::Audio::Drivers::Detectors
|
|||||||
|
|
||||||
CPulseAudioPlayingDetector::CPulseAudioPlayingDetector (
|
CPulseAudioPlayingDetector::CPulseAudioPlayingDetector (
|
||||||
Application::CApplicationContext& appContext,
|
Application::CApplicationContext& appContext,
|
||||||
Render::Drivers::Detectors::CFullScreenDetector& fullscreenDetector) :
|
const Render::Drivers::Detectors::CFullScreenDetector& fullscreenDetector) :
|
||||||
CAudioPlayingDetector (appContext, fullscreenDetector),
|
CAudioPlayingDetector (appContext, fullscreenDetector),
|
||||||
m_mainloop (nullptr),
|
m_mainloop (nullptr),
|
||||||
m_mainloopApi (nullptr),
|
m_mainloopApi (nullptr),
|
||||||
|
@ -10,7 +10,7 @@ namespace WallpaperEngine::Audio::Drivers::Detectors
|
|||||||
class CPulseAudioPlayingDetector : public CAudioPlayingDetector
|
class CPulseAudioPlayingDetector : public CAudioPlayingDetector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CPulseAudioPlayingDetector (Application::CApplicationContext& appContext, Render::Drivers::Detectors::CFullScreenDetector&);
|
explicit CPulseAudioPlayingDetector (Application::CApplicationContext& appContext, const Render::Drivers::Detectors::CFullScreenDetector&);
|
||||||
~CPulseAudioPlayingDetector ();
|
~CPulseAudioPlayingDetector ();
|
||||||
|
|
||||||
void update () override;
|
void update () override;
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
#include <glm/common.hpp>
|
|
||||||
#include "CGLFWMouseInput.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Input;
|
|
||||||
|
|
||||||
CGLFWMouseInput::CGLFWMouseInput (GLFWwindow* window) : m_reportedPosition (), m_mousePosition (), m_window (window) {}
|
|
||||||
|
|
||||||
void CGLFWMouseInput::update ()
|
|
||||||
{
|
|
||||||
if (!m_window)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// update current mouse position
|
|
||||||
glfwGetCursorPos (this->m_window, &this->m_mousePosition.x, &this->m_mousePosition.y);
|
|
||||||
// interpolate to the new position
|
|
||||||
this->m_reportedPosition = glm::mix (this->m_reportedPosition, this->m_mousePosition, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::dvec2 CGLFWMouseInput::position() const {
|
|
||||||
return this->m_reportedPosition;
|
|
||||||
}
|
|
@ -1,26 +1,13 @@
|
|||||||
#include "CInputContext.h"
|
#include "CInputContext.h"
|
||||||
#include "WallpaperEngine/Render/Drivers/CX11OpenGLDriver.h"
|
|
||||||
#include "WallpaperEngine/Input/CGLFWMouseInput.h"
|
|
||||||
#ifdef ENABLE_WAYLAND
|
|
||||||
#include "WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h"
|
|
||||||
#include "WallpaperEngine/Input/CWaylandMouseInput.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Input;
|
using namespace WallpaperEngine::Input;
|
||||||
using namespace WallpaperEngine::Render::Drivers;
|
using namespace WallpaperEngine::Render::Drivers;
|
||||||
|
|
||||||
CInputContext::CInputContext (CX11OpenGLDriver& videoDriver)
|
CInputContext::CInputContext (CMouseInput* mouseInput) :
|
||||||
|
m_mouse (mouseInput)
|
||||||
{
|
{
|
||||||
m_mouse = std::make_unique<CGLFWMouseInput>(videoDriver.getWindow());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_WAYLAND
|
|
||||||
CInputContext::CInputContext (CWaylandOpenGLDriver& videoDriver)
|
|
||||||
{
|
|
||||||
m_mouse = std::make_unique<CWaylandMouseInput>(&videoDriver);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void CInputContext::update ()
|
void CInputContext::update ()
|
||||||
{
|
{
|
||||||
this->m_mouse->update ();
|
this->m_mouse->update ();
|
||||||
@ -28,5 +15,5 @@ void CInputContext::update ()
|
|||||||
|
|
||||||
const CMouseInput& CInputContext::getMouseInput () const
|
const CMouseInput& CInputContext::getMouseInput () const
|
||||||
{
|
{
|
||||||
return *this->m_mouse.get();
|
return *this->m_mouse;
|
||||||
}
|
}
|
@ -1,14 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "WallpaperEngine/Render/Drivers/CX11OpenGLDriver.h"
|
|
||||||
#ifdef ENABLE_WAYLAND
|
|
||||||
#include "WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h"
|
|
||||||
#endif
|
|
||||||
#include "CMouseInput.h"
|
#include "CMouseInput.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Drivers
|
namespace WallpaperEngine::Render::Drivers
|
||||||
{
|
{
|
||||||
class CX11OpenGLDriver;
|
class CVideoDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace WallpaperEngine::Input
|
namespace WallpaperEngine::Input
|
||||||
@ -16,15 +12,16 @@ namespace WallpaperEngine::Input
|
|||||||
class CInputContext
|
class CInputContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CInputContext (Render::Drivers::CX11OpenGLDriver& videoDriver);
|
explicit CInputContext (CMouseInput* mouseInput);
|
||||||
#ifdef ENABLE_WAYLAND
|
|
||||||
explicit CInputContext (Render::Drivers::CWaylandOpenGLDriver& videoDriver);
|
/**
|
||||||
#endif
|
* Updates input information
|
||||||
|
*/
|
||||||
void update ();
|
void update ();
|
||||||
|
|
||||||
[[nodiscard]] const CMouseInput& getMouseInput () const;
|
[[nodiscard]] const CMouseInput& getMouseInput () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<CMouseInput> m_mouse;
|
CMouseInput* m_mouse;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
#include <glm/common.hpp>
|
|
||||||
#include "CMouseInput.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Input;
|
|
@ -1,12 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef ENABLE_WAYLAND
|
|
||||||
#include "../Render/Drivers/CWaylandOpenGLDriver.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
#include "GLFW/glfw3.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Input
|
namespace WallpaperEngine::Input
|
||||||
{
|
{
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
#include <glm/common.hpp>
|
|
||||||
#include "CWaylandMouseInput.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Input;
|
|
||||||
|
|
||||||
CWaylandMouseInput::CWaylandMouseInput(WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver* driver) {
|
|
||||||
waylandDriver = driver;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CWaylandMouseInput::update ()
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::dvec2 CWaylandMouseInput::position() const {
|
|
||||||
if (!waylandDriver || !waylandDriver->lastLSInFocus)
|
|
||||||
return {0, 0};
|
|
||||||
|
|
||||||
for (auto& o : waylandDriver->m_outputs) {
|
|
||||||
if (!o->rendering)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
return o->layerSurface.get() == waylandDriver->lastLSInFocus ? o->layerSurface->mousePos : glm::dvec2{-1337, -1337};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {0, 0};
|
|
||||||
}
|
|
24
src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.cpp
Normal file
24
src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <glm/common.hpp>
|
||||||
|
#include "CGLFWMouseInput.h"
|
||||||
|
|
||||||
|
#include "WallpaperEngine/Render/Drivers/CX11OpenGLDriver.h"
|
||||||
|
|
||||||
|
using namespace WallpaperEngine::Input::Drivers;
|
||||||
|
|
||||||
|
CGLFWMouseInput::CGLFWMouseInput (Render::Drivers::CX11OpenGLDriver* driver) :
|
||||||
|
m_reportedPosition (),
|
||||||
|
m_mousePosition (),
|
||||||
|
m_driver (driver) {}
|
||||||
|
|
||||||
|
void CGLFWMouseInput::update ()
|
||||||
|
{
|
||||||
|
// update current mouse position
|
||||||
|
glfwGetCursorPos (this->m_driver->getWindow (), &this->m_mousePosition.x, &this->m_mousePosition.y);
|
||||||
|
// interpolate to the new position
|
||||||
|
this->m_reportedPosition = glm::mix (this->m_reportedPosition, this->m_mousePosition, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::dvec2 CGLFWMouseInput::position() const
|
||||||
|
{
|
||||||
|
return this->m_reportedPosition;
|
||||||
|
}
|
@ -1,11 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CMouseInput.h"
|
#include "WallpaperEngine/Input/CMouseInput.h"
|
||||||
|
|
||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
#include "GLFW/glfw3.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Input
|
namespace WallpaperEngine::Render::Drivers
|
||||||
|
{
|
||||||
|
class CX11OpenGLDriver;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace WallpaperEngine::Input::Drivers
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Handles mouse input for the background
|
* Handles mouse input for the background
|
||||||
@ -13,7 +17,7 @@ namespace WallpaperEngine::Input
|
|||||||
class CGLFWMouseInput : public CMouseInput
|
class CGLFWMouseInput : public CMouseInput
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CGLFWMouseInput(GLFWwindow* window);
|
explicit CGLFWMouseInput(Render::Drivers::CX11OpenGLDriver* driver);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes current mouse position and updates it
|
* Takes current mouse position and updates it
|
||||||
@ -26,10 +30,7 @@ namespace WallpaperEngine::Input
|
|||||||
glm::dvec2 position () const override;
|
glm::dvec2 position () const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
Render::Drivers::CX11OpenGLDriver* m_driver;
|
||||||
* The GLFW window to get mouse position from
|
|
||||||
*/
|
|
||||||
GLFWwindow* m_window = nullptr;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current mouse position
|
* The current mouse position
|
29
src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.cpp
Normal file
29
src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <glm/common.hpp>
|
||||||
|
#include "CWaylandMouseInput.h"
|
||||||
|
|
||||||
|
using namespace WallpaperEngine::Input::Drivers;
|
||||||
|
|
||||||
|
CWaylandMouseInput::CWaylandMouseInput(WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver* driver) :
|
||||||
|
waylandDriver (driver)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWaylandMouseInput::update ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::dvec2 CWaylandMouseInput::position() const
|
||||||
|
{
|
||||||
|
if (!waylandDriver->viewportInFocus)
|
||||||
|
return {0, 0};
|
||||||
|
|
||||||
|
for (auto& o : waylandDriver->m_screens)
|
||||||
|
{
|
||||||
|
if (!o->rendering)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return o == waylandDriver->viewportInFocus ? o->mousePos : glm::dvec2{-1337, -1337};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {0, 0};
|
||||||
|
}
|
@ -1,13 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CMouseInput.h"
|
#include "WallpaperEngine/Input/CMouseInput.h"
|
||||||
#include "../Render/Drivers/CWaylandOpenGLDriver.h"
|
#include "WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h"
|
||||||
|
|
||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Input
|
namespace WallpaperEngine::Input::Drivers
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Handles mouse input for the background
|
* Handles mouse input for the background
|
@ -10,11 +10,10 @@
|
|||||||
namespace WallpaperEngine::Render
|
namespace WallpaperEngine::Render
|
||||||
{
|
{
|
||||||
CRenderContext::CRenderContext (
|
CRenderContext::CRenderContext (
|
||||||
const Drivers::Output::COutput* output, Drivers::CVideoDriver& driver, Input::CInputContext& input,
|
Drivers::CVideoDriver& driver, Input::CInputContext& input,
|
||||||
CWallpaperApplication& app
|
CWallpaperApplication& app
|
||||||
) :
|
) :
|
||||||
m_defaultWallpaper (nullptr),
|
m_defaultWallpaper (nullptr),
|
||||||
m_output (output),
|
|
||||||
m_driver (driver),
|
m_driver (driver),
|
||||||
m_app (app),
|
m_app (app),
|
||||||
m_input (input),
|
m_input (input),
|
||||||
@ -27,28 +26,24 @@ namespace WallpaperEngine::Render
|
|||||||
bool firstFrame = true;
|
bool firstFrame = true;
|
||||||
bool renderFrame = true;
|
bool renderFrame = true;
|
||||||
|
|
||||||
for (const auto& cur : this->m_output->getViewports ())
|
for (const auto& cur : this->getOutput ().getViewports ())
|
||||||
{
|
{
|
||||||
if (!this->m_driver.shouldRenderOutput(cur.first))
|
cur.second->makeCurrent ();
|
||||||
continue;
|
|
||||||
|
|
||||||
this->m_driver.makeCurrent(cur.first);
|
|
||||||
|
|
||||||
#if !NDEBUG
|
#if !NDEBUG
|
||||||
std::string str = "Rendering to output " + cur.first;
|
std::string str = "Rendering to output " + cur.first;
|
||||||
|
|
||||||
glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ());
|
glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ());
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
|
||||||
// search the background in the viewport selection
|
// search the background in the viewport selection
|
||||||
auto ref = this->m_wallpapers.find (cur.first);
|
auto ref = this->m_wallpapers.find (cur.first);
|
||||||
|
|
||||||
// render the background
|
// render the background
|
||||||
if (ref != this->m_wallpapers.end ())
|
if (ref != this->m_wallpapers.end ())
|
||||||
ref->second->render (cur.second.viewport, this->m_output->renderVFlip (), renderFrame, firstFrame);
|
ref->second->render (cur.second->viewport, this->getOutput ().renderVFlip (), renderFrame, firstFrame);
|
||||||
else
|
else
|
||||||
this->m_defaultWallpaper->render (
|
this->m_defaultWallpaper->render (
|
||||||
cur.second.viewport, this->m_output->renderVFlip (), renderFrame, firstFrame
|
cur.second->viewport, this->getOutput ().renderVFlip (), renderFrame, firstFrame
|
||||||
);
|
);
|
||||||
// scenes need to render a new frame for each viewport as they produce different results
|
// scenes need to render a new frame for each viewport as they produce different results
|
||||||
// but videos should only be rendered once per group of viewports
|
// but videos should only be rendered once per group of viewports
|
||||||
@ -57,22 +52,20 @@ namespace WallpaperEngine::Render
|
|||||||
glPopDebugGroup ();
|
glPopDebugGroup ();
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
|
||||||
if (this->m_driver.requiresSeparateFlips())
|
cur.second->swapOutput ();
|
||||||
this->m_driver.swapOutputBuffer(cur.first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the full texture into the image
|
// read the full texture into the image
|
||||||
if (this->m_output->haveImageBuffer ())
|
if (this->getOutput ().haveImageBuffer ())
|
||||||
glReadPixels (
|
glReadPixels (
|
||||||
0, 0, this->m_output->getFullWidth (), this->m_output->getFullHeight (), GL_BGRA, GL_UNSIGNED_BYTE,
|
0, 0, this->getOutput ().getFullWidth (), this->getOutput ().getFullHeight (), GL_BGRA, GL_UNSIGNED_BYTE,
|
||||||
this->m_output->getImageBuffer ()
|
this->getOutput ().getImageBuffer ()
|
||||||
);
|
);
|
||||||
|
|
||||||
// update the output with the given image
|
// update the output with the given image
|
||||||
this->m_output->updateRender ();
|
this->getOutput ().updateRender ();
|
||||||
// finally swap buffers
|
// finally swap buffers
|
||||||
if (!this->m_driver.requiresSeparateFlips())
|
this->m_driver.swapBuffers ();
|
||||||
this->m_driver.swapBuffers ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRenderContext::setDefaultWallpaper (CWallpaper* wallpaper)
|
void CRenderContext::setDefaultWallpaper (CWallpaper* wallpaper)
|
||||||
@ -100,9 +93,9 @@ namespace WallpaperEngine::Render
|
|||||||
return this->m_driver;
|
return this->m_driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Drivers::Output::COutput* CRenderContext::getOutput () const
|
const Drivers::Output::COutput& CRenderContext::getOutput () const
|
||||||
{
|
{
|
||||||
return this->m_output;
|
return this->m_driver.getOutput ();
|
||||||
}
|
}
|
||||||
|
|
||||||
const ITexture* CRenderContext::resolveTexture (const std::string& name)
|
const ITexture* CRenderContext::resolveTexture (const std::string& name)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "WallpaperEngine/Input/CMouseInput.h"
|
#include "WallpaperEngine/Input/CMouseInput.h"
|
||||||
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
||||||
#include "WallpaperEngine/Render/Drivers/Output/COutput.h"
|
#include "WallpaperEngine/Render/Drivers/Output/COutput.h"
|
||||||
|
#include "WallpaperEngine/Render/Drivers/Output/COutputViewport.h"
|
||||||
|
|
||||||
namespace WallpaperEngine
|
namespace WallpaperEngine
|
||||||
{
|
{
|
||||||
@ -26,6 +27,7 @@ namespace WallpaperEngine
|
|||||||
namespace Output
|
namespace Output
|
||||||
{
|
{
|
||||||
class COutput;
|
class COutput;
|
||||||
|
class COutputViewport;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ namespace WallpaperEngine
|
|||||||
class CRenderContext
|
class CRenderContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CRenderContext (const Drivers::Output::COutput* output, Drivers::CVideoDriver& driver, Input::CInputContext& input, CWallpaperApplication& app);
|
CRenderContext (Drivers::CVideoDriver& driver, Input::CInputContext& input, CWallpaperApplication& app);
|
||||||
|
|
||||||
void render ();
|
void render ();
|
||||||
void setDefaultWallpaper (CWallpaper* wallpaper);
|
void setDefaultWallpaper (CWallpaper* wallpaper);
|
||||||
@ -43,7 +45,7 @@ namespace WallpaperEngine
|
|||||||
[[nodiscard]] Input::CInputContext& getInputContext () const;
|
[[nodiscard]] Input::CInputContext& getInputContext () const;
|
||||||
[[nodiscard]] const CWallpaperApplication& getApp () const;
|
[[nodiscard]] const CWallpaperApplication& getApp () const;
|
||||||
[[nodiscard]] const Drivers::CVideoDriver& getDriver () const;
|
[[nodiscard]] const Drivers::CVideoDriver& getDriver () const;
|
||||||
[[nodiscard]] const Drivers::Output::COutput* getOutput () const;
|
[[nodiscard]] const Drivers::Output::COutput& getOutput () const;
|
||||||
const ITexture* resolveTexture (const std::string& name);
|
const ITexture* resolveTexture (const std::string& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -59,8 +61,6 @@ namespace WallpaperEngine
|
|||||||
CWallpaperApplication& m_app;
|
CWallpaperApplication& m_app;
|
||||||
/** Texture cache for the render */
|
/** Texture cache for the render */
|
||||||
CTextureCache* m_textureCache;
|
CTextureCache* m_textureCache;
|
||||||
/** Output driver that describes how the wallpapers are rendered */
|
|
||||||
const Drivers::Output::COutput* m_output;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -47,7 +47,8 @@ CVideo::CVideo (Core::CVideo* video, CRenderContext& context, CAudioContext& aud
|
|||||||
mpv_set_option (this->m_mpv, "volume", MPV_FORMAT_DOUBLE, &volume);
|
mpv_set_option (this->m_mpv, "volume", MPV_FORMAT_DOUBLE, &volume);
|
||||||
|
|
||||||
// initialize gl context for mpv
|
// initialize gl context for mpv
|
||||||
mpv_opengl_init_params gl_init_params {this->getContext().getDriver().getWindowHandle() ? get_proc_address_glfw : get_proc_address_wayland, nullptr};
|
mpv_opengl_init_params gl_init_params {get_proc_address_wayland, nullptr};
|
||||||
|
// mpv_opengl_init_params gl_init_params {this->getContext().getDriver().getWindowHandle() ? get_proc_address_glfw : get_proc_address_wayland, nullptr};
|
||||||
mpv_render_param params[] {
|
mpv_render_param params[] {
|
||||||
{MPV_RENDER_PARAM_API_TYPE, const_cast <char*> (MPV_RENDER_API_TYPE_OPENGL)},
|
{MPV_RENDER_PARAM_API_TYPE, const_cast <char*> (MPV_RENDER_API_TYPE_OPENGL)},
|
||||||
{MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &gl_init_params},
|
{MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &gl_init_params},
|
||||||
|
@ -2,26 +2,12 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Render::Drivers;
|
using namespace WallpaperEngine::Render::Drivers;
|
||||||
|
|
||||||
void CVideoDriver::dispatchEventQueue() const {
|
CVideoDriver::CVideoDriver (CWallpaperApplication& app) :
|
||||||
// intentionally left blank
|
m_app (app)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVideoDriver::makeCurrent(const std::string& outputName) const {
|
CWallpaperApplication& CVideoDriver::getApp () const
|
||||||
// intentionally left blank
|
{
|
||||||
}
|
return this->m_app;
|
||||||
|
|
||||||
bool CVideoDriver::shouldRenderOutput(const std::string& outputName) const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CVideoDriver::requiresSeparateFlips() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CVideoDriver::swapOutputBuffer(const std::string& outputName) {
|
|
||||||
// intentionally left blank
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CVideoDriver::getCurrentlyRendered() const {
|
|
||||||
return "";
|
|
||||||
}
|
}
|
@ -3,20 +3,37 @@
|
|||||||
#include <glm/vec4.hpp>
|
#include <glm/vec4.hpp>
|
||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "WallpaperEngine/Render/Drivers/Output/COutput.h"
|
||||||
|
|
||||||
|
namespace WallpaperEngine::Application
|
||||||
|
{
|
||||||
|
class CWallpaperApplication;
|
||||||
|
}
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Drivers
|
namespace WallpaperEngine::Render::Drivers
|
||||||
{
|
{
|
||||||
|
namespace Detectors
|
||||||
|
{
|
||||||
|
class CFullScreenDetector;
|
||||||
|
}
|
||||||
|
|
||||||
class CVideoDriver
|
class CVideoDriver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
CVideoDriver (CWallpaperApplication& app);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The window handle used by this video driver
|
* @return The fullscreen detector this video driver uses
|
||||||
*/
|
*/
|
||||||
virtual void* getWindowHandle () const = 0;
|
[[nodiscard]] virtual Detectors::CFullScreenDetector& getFullscreenDetector () = 0;
|
||||||
|
/**
|
||||||
|
* @return The current output in use
|
||||||
|
*/
|
||||||
|
[[nodiscard]] virtual Output::COutput& getOutput () = 0;
|
||||||
/**
|
/**
|
||||||
* @return The time that has passed since the driver started
|
* @return The time that has passed since the driver started
|
||||||
*/
|
*/
|
||||||
virtual float getRenderTime () const = 0;
|
[[nodiscard]] virtual float getRenderTime () const = 0;
|
||||||
/**
|
/**
|
||||||
* @return If a close was requested by the OS
|
* @return If a close was requested by the OS
|
||||||
*/
|
*/
|
||||||
@ -40,7 +57,7 @@ namespace WallpaperEngine::Render::Drivers
|
|||||||
/**
|
/**
|
||||||
* @return The size of the framebuffer available for the driver
|
* @return The size of the framebuffer available for the driver
|
||||||
*/
|
*/
|
||||||
virtual glm::ivec2 getFramebufferSize () const = 0;
|
[[nodiscard]] virtual glm::ivec2 getFramebufferSize () const = 0;
|
||||||
/**
|
/**
|
||||||
* Performs buffer swapping
|
* Performs buffer swapping
|
||||||
*/
|
*/
|
||||||
@ -48,30 +65,18 @@ namespace WallpaperEngine::Render::Drivers
|
|||||||
/**
|
/**
|
||||||
* @return The number of rendered frames since the start of the driver
|
* @return The number of rendered frames since the start of the driver
|
||||||
*/
|
*/
|
||||||
virtual uint32_t getFrameCounter () const = 0;
|
[[nodiscard]] virtual uint32_t getFrameCounter () const = 0;
|
||||||
/**
|
/**
|
||||||
* Wayland only: dispatch wayland event queue
|
* Process events on the driver and renders a frame
|
||||||
*/
|
*/
|
||||||
virtual void dispatchEventQueue() const;
|
virtual void dispatchEventQueue() const = 0;
|
||||||
/**
|
/**
|
||||||
* Wayland only: make EGL current
|
* @return The app that owns this driver
|
||||||
*/
|
*/
|
||||||
virtual void makeCurrent(const std::string& outputName) const;
|
[[nodiscard]] CWallpaperApplication& getApp () const;
|
||||||
/**
|
|
||||||
* Wayland only: whether an output should be rendered
|
private:
|
||||||
*/
|
/** App that owns this driver */
|
||||||
virtual bool shouldRenderOutput(const std::string& outputName) const;
|
CWallpaperApplication& m_app;
|
||||||
/**
|
|
||||||
* Wayland only: whether requires separate buffer flips on monitors
|
|
||||||
*/
|
|
||||||
virtual bool requiresSeparateFlips() const;
|
|
||||||
/**
|
|
||||||
* Wayland only: flip output
|
|
||||||
*/
|
|
||||||
virtual void swapOutputBuffer(const std::string& outputName);
|
|
||||||
/**
|
|
||||||
* Wayland only: gets currently rendered output
|
|
||||||
*/
|
|
||||||
virtual std::string getCurrentlyRendered() const;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -20,129 +20,97 @@ extern "C" {
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Render::Drivers;
|
using namespace WallpaperEngine::Render::Drivers;
|
||||||
|
|
||||||
static void handlePointerEnter(void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
static void handlePointerEnter (
|
||||||
const auto PDRIVER = (CWaylandOpenGLDriver*)data;
|
void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface,
|
||||||
const auto PLS = PDRIVER->surfaceToLS(surface);
|
wl_fixed_t surface_x, wl_fixed_t surface_y)
|
||||||
PDRIVER->lastLSInFocus = PLS;
|
{
|
||||||
wl_surface_set_buffer_scale(PLS->cursorSurface, PLS->output->scale);
|
const auto driver = static_cast <CWaylandOpenGLDriver*> (data);
|
||||||
wl_surface_attach(PLS->cursorSurface, wl_cursor_image_get_buffer(PLS->pointer->images[0]), 0, 0);
|
const auto viewport = driver->surfaceToViewport (surface);
|
||||||
wl_pointer_set_cursor(wl_pointer, serial, PLS->cursorSurface, PLS->pointer->images[0]->hotspot_x, PLS->pointer->images[0]->hotspot_y);
|
driver->viewportInFocus = viewport;
|
||||||
wl_surface_commit(PLS->cursorSurface);
|
wl_surface_set_buffer_scale(viewport->cursorSurface, viewport->scale);
|
||||||
|
wl_surface_attach(viewport->cursorSurface, wl_cursor_image_get_buffer(viewport->pointer->images[0]), 0, 0);
|
||||||
|
wl_pointer_set_cursor(wl_pointer, serial, viewport->cursorSurface, viewport->pointer->images[0]->hotspot_x, viewport->pointer->images[0]->hotspot_y);
|
||||||
|
wl_surface_commit(viewport->cursorSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handlePointerLeave(void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface) {
|
static void handlePointerLeave(void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface)
|
||||||
// ignored
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handlePointerAxis(void* data, wl_pointer* wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value) {
|
static void handlePointerAxis(void* data, wl_pointer* wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value)
|
||||||
// ignored
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handlePointerMotion(void* data, struct wl_pointer* wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
static void handlePointerMotion(
|
||||||
|
void* data, struct wl_pointer* wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
|
||||||
|
{
|
||||||
|
const auto driver = static_cast <CWaylandOpenGLDriver*> (data);
|
||||||
|
|
||||||
auto x = wl_fixed_to_double(surface_x);
|
auto x = wl_fixed_to_double(surface_x);
|
||||||
auto y = wl_fixed_to_double(surface_y);
|
auto y = wl_fixed_to_double(surface_y);
|
||||||
|
|
||||||
const auto PDRIVER = (CWaylandOpenGLDriver*)data;
|
if (!driver->viewportInFocus)
|
||||||
if (!PDRIVER->lastLSInFocus)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PDRIVER->lastLSInFocus->mousePos = {x * PDRIVER->lastLSInFocus->output->scale, y * PDRIVER->lastLSInFocus->output->scale};
|
driver->viewportInFocus->mousePos = {x * driver->viewportInFocus->scale, y * driver->viewportInFocus->scale};
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handlePointerButton(void* data, struct wl_pointer* wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t button_state) {
|
static void handlePointerButton(
|
||||||
// ignored
|
void* data, struct wl_pointer* wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t button_state)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct wl_pointer_listener pointerListener = { .enter = handlePointerEnter, .leave = handlePointerLeave, .motion = handlePointerMotion, .button = handlePointerButton, .axis = handlePointerAxis };
|
const struct wl_pointer_listener pointerListener =
|
||||||
|
{
|
||||||
|
.enter = handlePointerEnter,
|
||||||
|
.leave = handlePointerLeave,
|
||||||
|
.motion = handlePointerMotion,
|
||||||
|
.button = handlePointerButton,
|
||||||
|
.axis = handlePointerAxis
|
||||||
|
};
|
||||||
|
|
||||||
static void handleCapabilities(void* data, wl_seat* wl_seat, uint32_t capabilities) {
|
static void handleCapabilities(void* data, wl_seat* wl_seat, uint32_t capabilities)
|
||||||
|
{
|
||||||
if (capabilities & WL_SEAT_CAPABILITY_POINTER)
|
if (capabilities & WL_SEAT_CAPABILITY_POINTER)
|
||||||
wl_pointer_add_listener(wl_seat_get_pointer(wl_seat), &pointerListener, data);
|
wl_pointer_add_listener(wl_seat_get_pointer(wl_seat), &pointerListener, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct wl_seat_listener seatListener = { .capabilities = handleCapabilities };
|
const struct wl_seat_listener seatListener =
|
||||||
|
{
|
||||||
|
.capabilities = handleCapabilities
|
||||||
|
};
|
||||||
|
|
||||||
static void geometry(void* data, wl_output* output, int32_t x, int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, const char* make, const char* model,
|
static void handleGlobal(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
|
||||||
int32_t transform) {
|
{
|
||||||
// ignored
|
const auto driver = static_cast <CWaylandOpenGLDriver*> (data);
|
||||||
}
|
|
||||||
|
|
||||||
static void mode(void* data, wl_output* output, uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
|
|
||||||
const auto PMONITOR = (SWaylandOutput*)data;
|
|
||||||
PMONITOR->size = {width, height};
|
|
||||||
PMONITOR->lsSize = {width, height};
|
|
||||||
|
|
||||||
if (PMONITOR->layerSurface.get())
|
|
||||||
PMONITOR->driver->resizeLSSurfaceEGL(PMONITOR->layerSurface.get());
|
|
||||||
|
|
||||||
if (PMONITOR->initialized)
|
|
||||||
PMONITOR->driver->wallpaperApplication->getOutput()->reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void done(void* data, wl_output* wl_output) {
|
|
||||||
const auto PMONITOR = (SWaylandOutput*)data;
|
|
||||||
|
|
||||||
PMONITOR->initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void scale(void* data, wl_output* wl_output, int32_t scale) {
|
|
||||||
const auto PMONITOR = (SWaylandOutput*)data;
|
|
||||||
|
|
||||||
PMONITOR->scale = scale;
|
|
||||||
|
|
||||||
if (PMONITOR->layerSurface.get())
|
|
||||||
PMONITOR->driver->resizeLSSurfaceEGL(PMONITOR->layerSurface.get());
|
|
||||||
|
|
||||||
if (PMONITOR->initialized)
|
|
||||||
PMONITOR->driver->wallpaperApplication->getOutput()->reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void name(void* data, wl_output* wl_output, const char* name) {
|
|
||||||
const auto PMONITOR = (SWaylandOutput*)data;
|
|
||||||
|
|
||||||
if (name)
|
|
||||||
PMONITOR->name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void description(void* data, wl_output* wl_output, const char* description) {
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
const wl_output_listener outputListener = {.geometry = geometry, .mode = mode, .done = done, .scale = scale, .name = name, .description = description};
|
|
||||||
|
|
||||||
static void handleGlobal(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) {
|
|
||||||
const auto PDRIVER = (CWaylandOpenGLDriver*)data;
|
|
||||||
|
|
||||||
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
||||||
PDRIVER->waylandContext.compositor = (wl_compositor*)wl_registry_bind(registry, name, &wl_compositor_interface, 4);
|
driver->getWaylandContext()->compositor = (wl_compositor*)wl_registry_bind(registry, name, &wl_compositor_interface, 4);
|
||||||
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
|
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
|
||||||
PDRIVER->waylandContext.shm = (wl_shm*)wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
driver->getWaylandContext()->shm = (wl_shm*)wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
||||||
} else if (strcmp(interface, wl_output_interface.name) == 0) {
|
} else if (strcmp(interface, wl_output_interface.name) == 0) {
|
||||||
const auto POUTPUT = PDRIVER->m_outputs.emplace_back(std::make_unique<SWaylandOutput>()).get();
|
driver->m_screens.emplace_back (new WallpaperEngine::Render::Drivers::Output::CWaylandOutputViewport (driver, name, registry));
|
||||||
POUTPUT->output = (wl_output*)wl_registry_bind(registry, name, &wl_output_interface, 4);
|
|
||||||
POUTPUT->name = "";
|
|
||||||
POUTPUT->size = {0, 0};
|
|
||||||
POUTPUT->waylandName = name;
|
|
||||||
POUTPUT->driver = PDRIVER;
|
|
||||||
wl_output_add_listener(POUTPUT->output, &outputListener, POUTPUT);
|
|
||||||
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
|
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
|
||||||
PDRIVER->waylandContext.layerShell = (zwlr_layer_shell_v1*)wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 1);
|
driver->getWaylandContext()->layerShell = (zwlr_layer_shell_v1*)wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 1);
|
||||||
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
|
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
|
||||||
PDRIVER->waylandContext.seat = (wl_seat*)wl_registry_bind(registry, name, &wl_seat_interface, 1);
|
driver->getWaylandContext()->seat = (wl_seat*)wl_registry_bind(registry, name, &wl_seat_interface, 1);
|
||||||
wl_seat_add_listener(PDRIVER->waylandContext.seat, &seatListener, PDRIVER);
|
wl_seat_add_listener(driver->getWaylandContext()->seat, &seatListener, driver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleGlobalRemoved(void *data, struct wl_registry *registry, uint32_t id) {
|
static void handleGlobalRemoved(void *data, struct wl_registry *registry, uint32_t id)
|
||||||
|
{
|
||||||
// todo: outputs
|
// todo: outputs
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct wl_registry_listener registryListener = {
|
const struct wl_registry_listener registryListener =
|
||||||
|
{
|
||||||
.global = handleGlobal,
|
.global = handleGlobal,
|
||||||
.global_remove = handleGlobalRemoved,
|
.global_remove = handleGlobalRemoved,
|
||||||
};
|
};
|
||||||
|
|
||||||
void CWaylandOpenGLDriver::initEGL() {
|
void CWaylandOpenGLDriver::initEGL()
|
||||||
|
{
|
||||||
const char* CLIENT_EXTENSIONS = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
|
const char* CLIENT_EXTENSIONS = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
|
||||||
if (!CLIENT_EXTENSIONS)
|
if (!CLIENT_EXTENSIONS)
|
||||||
sLog.exception("Failed to query EGL Extensions");
|
sLog.exception("Failed to query EGL Extensions");
|
||||||
@ -156,31 +124,31 @@ void CWaylandOpenGLDriver::initEGL() {
|
|||||||
sLog.exception("EGL_EXT_platform_wayland not supported by EGL!");
|
sLog.exception("EGL_EXT_platform_wayland not supported by EGL!");
|
||||||
|
|
||||||
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
|
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
|
||||||
eglContext.eglCreatePlatformWindowSurfaceEXT = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
|
m_eglContext.eglCreatePlatformWindowSurfaceEXT = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
|
||||||
|
|
||||||
if (!eglGetPlatformDisplayEXT || !eglContext.eglCreatePlatformWindowSurfaceEXT)
|
if (!eglGetPlatformDisplayEXT || !m_eglContext.eglCreatePlatformWindowSurfaceEXT)
|
||||||
sLog.exception("EGL did not return EXT proc pointers!");
|
sLog.exception("EGL did not return EXT proc pointers!");
|
||||||
|
|
||||||
auto deinitEGL = [&] () -> void {
|
auto deinitEGL = [&] () -> void {
|
||||||
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
if (eglContext.display)
|
if (m_eglContext.display)
|
||||||
eglTerminate(eglContext.display);
|
eglTerminate(m_eglContext.display);
|
||||||
eglReleaseThread();
|
eglReleaseThread();
|
||||||
};
|
};
|
||||||
|
|
||||||
eglContext.display = eglGetPlatformDisplayEXT(EGL_PLATFORM_WAYLAND_EXT, waylandContext.display, nullptr);
|
m_eglContext.display = eglGetPlatformDisplayEXT(EGL_PLATFORM_WAYLAND_EXT, m_waylandContext.display, nullptr);
|
||||||
|
|
||||||
if (eglContext.display == EGL_NO_DISPLAY) {
|
if (m_eglContext.display == EGL_NO_DISPLAY) {
|
||||||
deinitEGL();
|
deinitEGL();
|
||||||
sLog.exception("eglGetPlatformDisplayEXT failed!");
|
sLog.exception("eglGetPlatformDisplayEXT failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!eglInitialize(eglContext.display, nullptr, nullptr)) {
|
if (!eglInitialize(m_eglContext.display, nullptr, nullptr)) {
|
||||||
deinitEGL();
|
deinitEGL();
|
||||||
sLog.exception("eglInitialize failed!");
|
sLog.exception("eglInitialize failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string CLIENTEXTENSIONSPOSTINIT = std::string(eglQueryString(eglContext.display, EGL_EXTENSIONS));
|
const std::string CLIENTEXTENSIONSPOSTINIT = std::string(eglQueryString(m_eglContext.display, EGL_EXTENSIONS));
|
||||||
|
|
||||||
if (CLIENTEXTENSIONSPOSTINIT.find("EGL_KHR_create_context") == std::string::npos) {
|
if (CLIENTEXTENSIONSPOSTINIT.find("EGL_KHR_create_context") == std::string::npos) {
|
||||||
deinitEGL();
|
deinitEGL();
|
||||||
@ -197,7 +165,8 @@ void CWaylandOpenGLDriver::initEGL() {
|
|||||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
||||||
EGL_NONE,
|
EGL_NONE,
|
||||||
};
|
};
|
||||||
if (!eglChooseConfig(eglContext.display, CONFIG_ATTRIBUTES, &eglContext.config, 1, &matchedConfigs)) {
|
|
||||||
|
if (!eglChooseConfig(m_eglContext.display, CONFIG_ATTRIBUTES, &m_eglContext.config, 1, &matchedConfigs)) {
|
||||||
deinitEGL();
|
deinitEGL();
|
||||||
sLog.exception("eglChooseConfig failed!");
|
sLog.exception("eglChooseConfig failed!");
|
||||||
}
|
}
|
||||||
@ -218,148 +187,91 @@ void CWaylandOpenGLDriver::initEGL() {
|
|||||||
EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
|
EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
|
||||||
EGL_NONE,
|
EGL_NONE,
|
||||||
};
|
};
|
||||||
eglContext.context = eglCreateContext(eglContext.display, eglContext.config, EGL_NO_CONTEXT, CONTEXT_ATTRIBUTES);
|
m_eglContext.context = eglCreateContext(m_eglContext.display, m_eglContext.config, EGL_NO_CONTEXT, CONTEXT_ATTRIBUTES);
|
||||||
|
|
||||||
if (eglContext.context == EGL_NO_CONTEXT) {
|
if (m_eglContext.context == EGL_NO_CONTEXT) {
|
||||||
sLog.error("eglCreateContext error " + std::to_string(eglGetError()));
|
sLog.error("eglCreateContext error " + std::to_string(eglGetError()));
|
||||||
deinitEGL();
|
deinitEGL();
|
||||||
sLog.exception("eglCreateContext failed!");
|
sLog.exception("eglCreateContext failed!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWaylandOpenGLDriver::finishEGL() {
|
void CWaylandOpenGLDriver::finishEGL()
|
||||||
eglMakeCurrent(eglContext.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
{
|
||||||
eglDestroyContext(eglContext.display, eglContext.context);
|
eglMakeCurrent(m_eglContext.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
eglTerminate(eglContext.display);
|
eglDestroyContext(m_eglContext.display, m_eglContext.context);
|
||||||
|
eglTerminate(m_eglContext.display);
|
||||||
eglReleaseThread();
|
eglReleaseThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CWaylandOpenGLDriver::onLayerClose(Output::CWaylandOutputViewport* viewport)
|
||||||
|
{
|
||||||
|
sLog.error ("Compositor closed our LS, freeing data...");
|
||||||
|
|
||||||
static void handleLSConfigure(void *data, zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t w, uint32_t h) {
|
if (viewport->eglSurface)
|
||||||
const auto PLS = (CLayerSurface*)data;
|
eglDestroySurface (m_eglContext.display, viewport->eglSurface);
|
||||||
PLS->size = {w, h};
|
|
||||||
|
|
||||||
PLS->output->driver->resizeLSSurfaceEGL(PLS);
|
if (viewport->eglWindow)
|
||||||
|
wl_egl_window_destroy(viewport->eglWindow);
|
||||||
|
|
||||||
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
if (viewport->layerSurface)
|
||||||
|
zwlr_layer_surface_v1_destroy(viewport->layerSurface);
|
||||||
|
|
||||||
|
if (viewport->surface)
|
||||||
|
wl_surface_destroy(viewport->surface);
|
||||||
|
|
||||||
|
// remove the output from the list
|
||||||
|
std::remove (this->m_screens.begin (), this->m_screens.end (), viewport);
|
||||||
|
// TODO: DELETE FROM VIEWPORT LIST
|
||||||
|
|
||||||
|
delete viewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleLSClosed(void *data, zwlr_layer_surface_v1 *surface) {
|
CWaylandOpenGLDriver::CWaylandOpenGLDriver(CApplicationContext& context, CWallpaperApplication& app) :
|
||||||
const auto PLS = (CLayerSurface*)data;
|
m_frameCounter(0),
|
||||||
PLS->output->driver->onLayerClose(PLS);
|
m_fullscreenDetector (context, *this),
|
||||||
}
|
m_output (context, *this),
|
||||||
|
CVideoDriver (app)
|
||||||
|
{
|
||||||
|
m_waylandContext.display = wl_display_connect (nullptr);
|
||||||
|
|
||||||
void CWaylandOpenGLDriver::onLayerClose(CLayerSurface* layerSurface) {
|
if (!m_waylandContext.display)
|
||||||
eglDestroySurface(eglContext.display, layerSurface->eglSurface);
|
sLog.exception ("Failed to query wayland display");
|
||||||
wl_egl_window_destroy(layerSurface->eglWindow);
|
|
||||||
zwlr_layer_surface_v1_destroy(layerSurface->layerSurface);
|
|
||||||
wl_surface_destroy(layerSurface->surface);
|
|
||||||
sLog.exception("Compositor closed our LS!"); // todo: handle this?
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct zwlr_layer_surface_v1_listener layerSurfaceListener = {
|
m_waylandContext.registry = wl_display_get_registry(m_waylandContext.display);
|
||||||
.configure = handleLSConfigure,
|
wl_registry_add_listener(m_waylandContext.registry, ®istryListener, this);
|
||||||
.closed = handleLSClosed,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void surfaceFrameCallback(void *data, struct wl_callback *cb, uint32_t time) {
|
wl_display_dispatch(m_waylandContext.display);
|
||||||
const auto PLS = (CLayerSurface*)data;
|
wl_display_roundtrip(m_waylandContext.display);
|
||||||
wl_callback_destroy(cb);
|
|
||||||
PLS->frameCallback = nullptr;
|
|
||||||
PLS->output->rendering = true;
|
|
||||||
PLS->output->driver->wallpaperApplication->renderFrame();
|
|
||||||
PLS->output->rendering = false;
|
|
||||||
|
|
||||||
float renderTime = PLS->output->driver->getRenderTime();
|
if (!m_waylandContext.compositor || !m_waylandContext.shm || !m_waylandContext.layerShell || this->m_screens.empty())
|
||||||
|
sLog.exception ("Failed to bind to required interfaces");
|
||||||
if ((renderTime - PLS->lastTime) < PLS->minimumTime)
|
|
||||||
usleep ((PLS->minimumTime - (renderTime - PLS->lastTime)) * CLOCKS_PER_SEC);
|
|
||||||
|
|
||||||
PLS->lastTime = renderTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct wl_callback_listener frameListener = {
|
|
||||||
.done = surfaceFrameCallback
|
|
||||||
};
|
|
||||||
|
|
||||||
CLayerSurface::CLayerSurface(CWaylandOpenGLDriver* pDriver, SWaylandOutput* pOutput) {
|
|
||||||
surface = wl_compositor_create_surface(pDriver->waylandContext.compositor);
|
|
||||||
layerSurface = zwlr_layer_shell_v1_get_layer_surface(pDriver->waylandContext.layerShell, surface, pOutput->output, ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "linux-wallpaperengine");
|
|
||||||
output = pOutput;
|
|
||||||
|
|
||||||
if (!layerSurface)
|
|
||||||
sLog.exception("Failed to get a layer surface");
|
|
||||||
|
|
||||||
wl_region* region = wl_compositor_create_region(pDriver->waylandContext.compositor);
|
|
||||||
wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX);
|
|
||||||
|
|
||||||
zwlr_layer_surface_v1_set_size(layerSurface, 0, 0);
|
|
||||||
zwlr_layer_surface_v1_set_anchor(layerSurface, ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM);
|
|
||||||
zwlr_layer_surface_v1_set_keyboard_interactivity(layerSurface, false);
|
|
||||||
zwlr_layer_surface_v1_add_listener(layerSurface, &layerSurfaceListener, this);
|
|
||||||
zwlr_layer_surface_v1_set_exclusive_zone(layerSurface, -1);
|
|
||||||
wl_surface_set_input_region(surface, region);
|
|
||||||
wl_surface_commit(surface);
|
|
||||||
wl_display_roundtrip(pDriver->waylandContext.display);
|
|
||||||
|
|
||||||
eglWindow = wl_egl_window_create(surface, size.x * output->scale, size.y * output->scale);
|
|
||||||
eglSurface = pDriver->eglContext.eglCreatePlatformWindowSurfaceEXT(pDriver->eglContext.display, pDriver->eglContext.config, eglWindow, nullptr);
|
|
||||||
output->lsSize = size;
|
|
||||||
wl_surface_commit(surface);
|
|
||||||
wl_display_roundtrip(pDriver->waylandContext.display);
|
|
||||||
wl_display_flush(pDriver->waylandContext.display);
|
|
||||||
|
|
||||||
static const auto XCURSORSIZE = getenv("XCURSOR_SIZE") ? std::stoi(getenv("XCURSOR_SIZE")) : 24;
|
|
||||||
const auto PRCURSORTHEME = wl_cursor_theme_load(getenv("XCURSOR_THEME"), XCURSORSIZE * output->scale, pDriver->waylandContext.shm);
|
|
||||||
|
|
||||||
if (!PRCURSORTHEME)
|
|
||||||
sLog.exception("Failed to get a cursor theme");
|
|
||||||
|
|
||||||
pointer = wl_cursor_theme_get_cursor(PRCURSORTHEME, "left_ptr");
|
|
||||||
cursorSurface = wl_compositor_create_surface(pDriver->waylandContext.compositor);
|
|
||||||
|
|
||||||
if (!cursorSurface)
|
|
||||||
sLog.exception("Failed to get a cursor surface");
|
|
||||||
|
|
||||||
if (eglMakeCurrent(pDriver->eglContext.display, eglSurface, eglSurface, pDriver->eglContext.context) == EGL_FALSE)
|
|
||||||
sLog.exception("Failed to make egl current");
|
|
||||||
|
|
||||||
minimumTime = 1.0f / pDriver->wallpaperApplication->getContext().settings.render.maximumFPS;
|
|
||||||
}
|
|
||||||
|
|
||||||
CLayerSurface::~CLayerSurface() {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
CWaylandOpenGLDriver::CWaylandOpenGLDriver(const char* windowTitle, CApplicationContext& context, CWallpaperApplication* app) : m_frameCounter(0) {
|
|
||||||
wallpaperApplication = app;
|
|
||||||
waylandContext.display = wl_display_connect(NULL);
|
|
||||||
|
|
||||||
if (!waylandContext.display)
|
|
||||||
sLog.exception("Failed to query wayland display");
|
|
||||||
|
|
||||||
waylandContext.registry = wl_display_get_registry(waylandContext.display);
|
|
||||||
wl_registry_add_listener(waylandContext.registry, ®istryListener, this);
|
|
||||||
|
|
||||||
wl_display_dispatch(waylandContext.display);
|
|
||||||
wl_display_roundtrip(waylandContext.display);
|
|
||||||
|
|
||||||
if (!waylandContext.compositor || !waylandContext.shm || !waylandContext.layerShell || m_outputs.empty())
|
|
||||||
sLog.exception("Failed to bind to required interfaces");
|
|
||||||
|
|
||||||
initEGL();
|
initEGL();
|
||||||
|
|
||||||
bool any = false;
|
bool any = false;
|
||||||
for (auto& o : m_outputs) {
|
|
||||||
if (std::find_if(context.settings.general.screenBackgrounds.begin(), context.settings.general.screenBackgrounds.end(), [&] (const auto& e) { return e.first == o->name; }) != context.settings.general.screenBackgrounds.end()) {
|
for (auto& o : this->m_screens)
|
||||||
o->layerSurface = std::make_unique<CLayerSurface>(this, o.get());
|
{
|
||||||
any = true;
|
const auto cur = context.settings.general.screenBackgrounds.find (o->name);
|
||||||
}
|
|
||||||
|
if (cur == context.settings.general.screenBackgrounds.end ())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
o->setupLS ();
|
||||||
|
any = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!any && std::find_if(context.settings.general.screenBackgrounds.begin(), context.settings.general.screenBackgrounds.end(), [&] (const auto& e) { return e.first == "auto"; }) != context.settings.general.screenBackgrounds.end()) {
|
if (!any)
|
||||||
m_outputs[0]->layerSurface = std::make_unique<CLayerSurface>(this, m_outputs[0].get());
|
{
|
||||||
any = true;
|
const auto cur = context.settings.general.screenBackgrounds.find ("auto");
|
||||||
|
|
||||||
|
if (cur != context.settings.general.screenBackgrounds.end ())
|
||||||
|
{
|
||||||
|
// initializes the default screen only...
|
||||||
|
m_screens [0]->setupLS ();
|
||||||
|
any = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!any)
|
if (!any)
|
||||||
@ -373,139 +285,82 @@ CWaylandOpenGLDriver::CWaylandOpenGLDriver(const char* windowTitle, CApplication
|
|||||||
FreeImage_Initialise (TRUE);
|
FreeImage_Initialise (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
CWaylandOpenGLDriver::~CWaylandOpenGLDriver() {
|
void CWaylandOpenGLDriver::dispatchEventQueue() const
|
||||||
;
|
{
|
||||||
|
// render one frame to force drawing the screens
|
||||||
|
this->getApp ().update ();
|
||||||
|
|
||||||
|
wl_display_dispatch(m_waylandContext.display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWaylandOpenGLDriver::dispatchEventQueue() const {
|
Detectors::CFullScreenDetector& CWaylandOpenGLDriver::getFullscreenDetector ()
|
||||||
wl_display_dispatch(waylandContext.display);
|
{
|
||||||
|
return this->m_fullscreenDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* CWaylandOpenGLDriver::getWindowHandle () const {
|
Output::COutput& CWaylandOpenGLDriver::getOutput ()
|
||||||
return nullptr;
|
{
|
||||||
|
return this->m_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CWaylandOpenGLDriver::getRenderTime () const {
|
float CWaylandOpenGLDriver::getRenderTime () const
|
||||||
|
{
|
||||||
return (float)std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - renderStart).count() / 1000000.0;
|
return (float)std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - renderStart).count() / 1000000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWaylandOpenGLDriver::closeRequested () {
|
bool CWaylandOpenGLDriver::closeRequested ()
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWaylandOpenGLDriver::resizeWindow (glm::ivec2 size) {
|
void CWaylandOpenGLDriver::resizeWindow (glm::ivec2 size)
|
||||||
;
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWaylandOpenGLDriver::resizeWindow (glm::ivec4 sizeandpos) {
|
void CWaylandOpenGLDriver::resizeWindow (glm::ivec4 sizeandpos)
|
||||||
;
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWaylandOpenGLDriver::showWindow () {
|
void CWaylandOpenGLDriver::showWindow ()
|
||||||
;
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWaylandOpenGLDriver::hideWindow () {
|
void CWaylandOpenGLDriver::hideWindow ()
|
||||||
;
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::ivec2 CWaylandOpenGLDriver::getFramebufferSize () const {
|
glm::ivec2 CWaylandOpenGLDriver::getFramebufferSize () const
|
||||||
|
{
|
||||||
return glm::ivec2{0, 0};
|
return glm::ivec2{0, 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWaylandOpenGLDriver::swapBuffers () {
|
void CWaylandOpenGLDriver::swapBuffers ()
|
||||||
;
|
{
|
||||||
|
m_frameCounter ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWaylandOpenGLDriver::resizeLSSurfaceEGL(CLayerSurface* layerSurface) {
|
uint32_t CWaylandOpenGLDriver::getFrameCounter () const
|
||||||
if (layerSurface->eglWindow) {
|
{
|
||||||
layerSurface->output->lsSize = layerSurface->size;
|
|
||||||
|
|
||||||
wl_egl_window_resize(layerSurface->eglWindow, layerSurface->size.x * layerSurface->output->scale, layerSurface->size.y * layerSurface->output->scale, 0, 0);
|
|
||||||
|
|
||||||
if (layerSurface->frameCallback) {
|
|
||||||
wl_callback_destroy(layerSurface->frameCallback);
|
|
||||||
layerSurface->frameCallback = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
wallpaperApplication->getOutput()->reset();
|
|
||||||
|
|
||||||
layerSurface->output->rendering = true;
|
|
||||||
wallpaperApplication->renderFrame();
|
|
||||||
layerSurface->output->rendering = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CWaylandOpenGLDriver::getFrameCounter () const {
|
|
||||||
return m_frameCounter;
|
return m_frameCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWwindow* CWaylandOpenGLDriver::getWindow () {
|
CWaylandOpenGLDriver::SEGLContext* CWaylandOpenGLDriver::getEGLContext ()
|
||||||
return nullptr;
|
{
|
||||||
|
return &this->m_eglContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <iostream>
|
CWaylandOpenGLDriver::SWaylandContext* CWaylandOpenGLDriver::getWaylandContext ()
|
||||||
|
{
|
||||||
void CWaylandOpenGLDriver::makeCurrent(const std::string& outputName) const {
|
return &this->m_waylandContext;
|
||||||
for (auto& o : m_outputs) {
|
|
||||||
if (o->name != outputName)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (eglMakeCurrent(eglContext.display, o->layerSurface->eglSurface, o->layerSurface->eglSurface, eglContext.context) == EGL_FALSE) {
|
|
||||||
std::cerr << "Couldn't make egl current";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CLayerSurface* CWaylandOpenGLDriver::surfaceToLS(wl_surface* surface) {
|
Output::CWaylandOutputViewport* CWaylandOpenGLDriver::surfaceToViewport(wl_surface* surface)
|
||||||
for (auto& o : m_outputs) {
|
{
|
||||||
if (!o->layerSurface.get())
|
for (auto& o : m_screens)
|
||||||
continue;
|
{
|
||||||
|
if (o->surface == surface)
|
||||||
if (o->layerSurface->surface == surface)
|
return o;
|
||||||
return o->layerSurface.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWaylandOpenGLDriver::shouldRenderOutput(const std::string& outputName) const {
|
|
||||||
for (auto& o : m_outputs) {
|
|
||||||
if (o->name == outputName)
|
|
||||||
return o->layerSurface.get() && (o->rendering || !o->layerSurface->callbackInitialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CWaylandOpenGLDriver::requiresSeparateFlips() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CWaylandOpenGLDriver::swapOutputBuffer(const std::string& outputName) {
|
|
||||||
for (auto& o : m_outputs) {
|
|
||||||
if (o->name != outputName)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
o->layerSurface->callbackInitialized = true;
|
|
||||||
|
|
||||||
eglMakeCurrent(eglContext.display, o->layerSurface->eglSurface, o->layerSurface->eglSurface, eglContext.context);
|
|
||||||
o->layerSurface->frameCallback = wl_surface_frame(o->layerSurface->surface);
|
|
||||||
wl_callback_add_listener(o->layerSurface->frameCallback, &frameListener, o->layerSurface.get());
|
|
||||||
eglSwapBuffers(eglContext.display, o->layerSurface->eglSurface);
|
|
||||||
wl_surface_set_buffer_scale(o->layerSurface->surface, o->scale);
|
|
||||||
wl_surface_damage_buffer(o->layerSurface->surface, 0, 0, INT32_MAX, INT32_MAX);
|
|
||||||
wl_surface_commit(o->layerSurface->surface);
|
|
||||||
|
|
||||||
m_frameCounter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CWaylandOpenGLDriver::getCurrentlyRendered() const {
|
|
||||||
for (auto& o : m_outputs) {
|
|
||||||
if (o->rendering)
|
|
||||||
return o->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
|
|
||||||
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
||||||
#include "WallpaperEngine/Application/CApplicationContext.h"
|
#include "WallpaperEngine/Application/CApplicationContext.h"
|
||||||
|
#include "WallpaperEngine/Render/Drivers/Detectors/CWaylandFullScreenDetector.h"
|
||||||
|
#include "WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.h"
|
||||||
|
#include "WallpaperEngine/Render/Drivers/Output/CWaylandOutput.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Application
|
namespace WallpaperEngine::Application
|
||||||
{
|
{
|
||||||
@ -16,56 +19,54 @@ namespace WallpaperEngine::Application
|
|||||||
class CWallpaperApplication;
|
class CWallpaperApplication;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GLFWwindow;
|
namespace WallpaperEngine::Input::Drivers
|
||||||
typedef GLFWwindow GLFWWindow;
|
{
|
||||||
|
class CWaylandMouseInput;
|
||||||
|
}
|
||||||
|
|
||||||
struct zwlr_layer_shell_v1;
|
struct zwlr_layer_shell_v1;
|
||||||
struct zwlr_layer_surface_v1;
|
struct zwlr_layer_surface_v1;
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Drivers
|
namespace WallpaperEngine::Render::Drivers
|
||||||
{
|
{
|
||||||
using namespace WallpaperEngine::Application;
|
using namespace WallpaperEngine::Application;
|
||||||
|
using namespace WallpaperEngine::Input::Drivers;
|
||||||
class CWaylandOpenGLDriver;
|
class CWaylandOpenGLDriver;
|
||||||
class CLayerSurface;
|
|
||||||
|
|
||||||
struct SWaylandOutput {
|
namespace Output
|
||||||
wl_output* output;
|
{
|
||||||
std::string name;
|
class CWaylandOutputViewport;
|
||||||
glm::ivec2 size;
|
class CWaylandOutput;
|
||||||
glm::ivec2 lsSize;
|
}
|
||||||
uint32_t waylandName;
|
|
||||||
int scale = 1;
|
|
||||||
CWaylandOpenGLDriver* driver = nullptr;
|
|
||||||
bool initialized = false;
|
|
||||||
std::unique_ptr<CLayerSurface> layerSurface;
|
|
||||||
bool rendering = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CLayerSurface {
|
|
||||||
public:
|
|
||||||
CLayerSurface(CWaylandOpenGLDriver*, SWaylandOutput*);
|
|
||||||
~CLayerSurface();
|
|
||||||
|
|
||||||
wl_egl_window* eglWindow = nullptr;
|
|
||||||
EGLSurface eglSurface = nullptr;
|
|
||||||
wl_surface* surface = nullptr;
|
|
||||||
zwlr_layer_surface_v1* layerSurface = nullptr;
|
|
||||||
glm::ivec2 size;
|
|
||||||
wl_callback* frameCallback = nullptr;
|
|
||||||
SWaylandOutput* output = nullptr;
|
|
||||||
glm::dvec2 mousePos = {0, 0};
|
|
||||||
wl_cursor* pointer = nullptr;
|
|
||||||
wl_surface* cursorSurface = nullptr;
|
|
||||||
bool callbackInitialized = false;
|
|
||||||
float lastTime, minimumTime;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CWaylandOpenGLDriver : public CVideoDriver
|
class CWaylandOpenGLDriver : public CVideoDriver
|
||||||
{
|
{
|
||||||
|
friend class Output::CWaylandOutput;
|
||||||
|
friend class CWaylandMouseInput;
|
||||||
public:
|
public:
|
||||||
explicit CWaylandOpenGLDriver (const char* windowTitle, CApplicationContext& context, CWallpaperApplication* app);
|
struct SEGLContext
|
||||||
|
{
|
||||||
|
EGLDisplay display = nullptr;
|
||||||
|
EGLConfig config = nullptr;
|
||||||
|
EGLContext context = nullptr;
|
||||||
|
PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC eglCreatePlatformWindowSurfaceEXT = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SWaylandContext
|
||||||
|
{
|
||||||
|
wl_display* display = nullptr;
|
||||||
|
wl_registry* registry = nullptr;
|
||||||
|
wl_compositor* compositor = nullptr;
|
||||||
|
wl_shm* shm = nullptr;
|
||||||
|
zwlr_layer_shell_v1* layerShell = nullptr;
|
||||||
|
wl_seat* seat = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit CWaylandOpenGLDriver (CApplicationContext& context, CWallpaperApplication& app);
|
||||||
~CWaylandOpenGLDriver();
|
~CWaylandOpenGLDriver();
|
||||||
|
|
||||||
void* getWindowHandle () const;
|
[[nodiscard]] Detectors::CFullScreenDetector& getFullscreenDetector () override;
|
||||||
|
[[nodiscard]] Output::COutput& getOutput () override;
|
||||||
float getRenderTime () const override;
|
float getRenderTime () const override;
|
||||||
bool closeRequested () override;
|
bool closeRequested () override;
|
||||||
void resizeWindow (glm::ivec2 size) override;
|
void resizeWindow (glm::ivec2 size) override;
|
||||||
@ -76,49 +77,34 @@ namespace WallpaperEngine::Render::Drivers
|
|||||||
void swapBuffers () override;
|
void swapBuffers () override;
|
||||||
uint32_t getFrameCounter () const override;
|
uint32_t getFrameCounter () const override;
|
||||||
void dispatchEventQueue() const override;
|
void dispatchEventQueue() const override;
|
||||||
void makeCurrent(const std::string& outputName) const override;
|
|
||||||
bool shouldRenderOutput(const std::string& outputName) const override;
|
|
||||||
bool requiresSeparateFlips() const override;
|
|
||||||
void swapOutputBuffer(const std::string& outputName) override;
|
|
||||||
std::string getCurrentlyRendered() const override;
|
|
||||||
|
|
||||||
GLFWwindow* getWindow ();
|
void onLayerClose(Output::CWaylandOutputViewport*);
|
||||||
|
Output::CWaylandOutputViewport* surfaceToViewport(wl_surface*);
|
||||||
|
|
||||||
struct {
|
Output::CWaylandOutputViewport* viewportInFocus = nullptr;
|
||||||
wl_display* display = nullptr;
|
|
||||||
wl_registry* registry = nullptr;
|
|
||||||
wl_compositor* compositor = nullptr;
|
|
||||||
wl_shm* shm = nullptr;
|
|
||||||
zwlr_layer_shell_v1* layerShell = nullptr;
|
|
||||||
wl_seat* seat = nullptr;
|
|
||||||
} waylandContext;
|
|
||||||
|
|
||||||
void onLayerClose(CLayerSurface*);
|
[[nodiscard]] SEGLContext* getEGLContext ();
|
||||||
void resizeLSSurfaceEGL(CLayerSurface*);
|
[[nodiscard]] SWaylandContext* getWaylandContext ();
|
||||||
CLayerSurface* surfaceToLS(wl_surface*);
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<SWaylandOutput>> m_outputs;
|
|
||||||
|
|
||||||
CWallpaperApplication* wallpaperApplication;
|
/** List of available screens */
|
||||||
|
std::vector <Output::CWaylandOutputViewport*> m_screens;
|
||||||
struct {
|
|
||||||
EGLDisplay display = nullptr;
|
|
||||||
EGLConfig config = nullptr;
|
|
||||||
EGLContext context = nullptr;
|
|
||||||
PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC eglCreatePlatformWindowSurfaceEXT = nullptr;
|
|
||||||
} eglContext;
|
|
||||||
|
|
||||||
CLayerSurface* lastLSInFocus = nullptr;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/** Fullscreen detection used by this driver */
|
||||||
|
Detectors::CWaylandFullScreenDetector m_fullscreenDetector;
|
||||||
|
/** The output used by the driver */
|
||||||
|
Output::CWaylandOutput m_output;
|
||||||
|
/** The EGL context in use */
|
||||||
|
SEGLContext m_eglContext;
|
||||||
|
/** The Wayland context in use */
|
||||||
|
SWaylandContext m_waylandContext;
|
||||||
|
|
||||||
void initEGL();
|
void initEGL();
|
||||||
void finishEGL();
|
void finishEGL();
|
||||||
|
|
||||||
uint32_t m_frameCounter;
|
uint32_t m_frameCounter;
|
||||||
|
|
||||||
std::chrono::high_resolution_clock::time_point renderStart = std::chrono::high_resolution_clock::now();
|
std::chrono::high_resolution_clock::time_point renderStart = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
friend class CWaylandOutput;
|
|
||||||
friend class CWallpaperApplication;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
#include "CX11OpenGLDriver.h"
|
#include "CX11OpenGLDriver.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.h"
|
||||||
#include <FreeImage.h>
|
#include <FreeImage.h>
|
||||||
|
|
||||||
#define GLFW_EXPOSE_NATIVE_X11
|
#define GLFW_EXPOSE_NATIVE_X11
|
||||||
@ -12,8 +13,11 @@ void CustomGLFWErrorHandler (int errorCode, const char* reason)
|
|||||||
sLog.error ("GLFW error ", errorCode, ": ", reason);
|
sLog.error ("GLFW error ", errorCode, ": ", reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
CX11OpenGLDriver::CX11OpenGLDriver (const char* windowTitle, CApplicationContext& context) :
|
CX11OpenGLDriver::CX11OpenGLDriver (const char* windowTitle, CApplicationContext& context, CWallpaperApplication& app) :
|
||||||
m_frameCounter (0)
|
m_frameCounter (0),
|
||||||
|
m_fullscreenDetector (context, *this),
|
||||||
|
m_context (context),
|
||||||
|
CVideoDriver (app)
|
||||||
{
|
{
|
||||||
glfwSetErrorCallback (CustomGLFWErrorHandler);
|
glfwSetErrorCallback (CustomGLFWErrorHandler);
|
||||||
|
|
||||||
@ -60,6 +64,17 @@ CX11OpenGLDriver::CX11OpenGLDriver (const char* windowTitle, CApplicationContext
|
|||||||
|
|
||||||
// initialize free image
|
// initialize free image
|
||||||
FreeImage_Initialise (TRUE);
|
FreeImage_Initialise (TRUE);
|
||||||
|
|
||||||
|
// setup output
|
||||||
|
if (context.settings.render.mode == CApplicationContext::EXPLICIT_WINDOW ||
|
||||||
|
context.settings.render.mode == CApplicationContext::NORMAL_WINDOW)
|
||||||
|
{
|
||||||
|
m_output = new WallpaperEngine::Render::Drivers::Output::CGLFWWindowOutput (context, *this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_output = new WallpaperEngine::Render::Drivers::Output::CX11Output (context, *this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CX11OpenGLDriver::~CX11OpenGLDriver ()
|
CX11OpenGLDriver::~CX11OpenGLDriver ()
|
||||||
@ -68,9 +83,14 @@ CX11OpenGLDriver::~CX11OpenGLDriver ()
|
|||||||
FreeImage_DeInitialise();
|
FreeImage_DeInitialise();
|
||||||
}
|
}
|
||||||
|
|
||||||
void* CX11OpenGLDriver::getWindowHandle () const
|
Detectors::CFullScreenDetector& CX11OpenGLDriver::getFullscreenDetector ()
|
||||||
{
|
{
|
||||||
return reinterpret_cast <void*> (glfwGetX11Window (this->m_window));
|
return this->m_fullscreenDetector;
|
||||||
|
}
|
||||||
|
|
||||||
|
Output::COutput& CX11OpenGLDriver::getOutput ()
|
||||||
|
{
|
||||||
|
return *this->m_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CX11OpenGLDriver::getRenderTime () const
|
float CX11OpenGLDriver::getRenderTime () const
|
||||||
@ -128,6 +148,20 @@ uint32_t CX11OpenGLDriver::getFrameCounter () const
|
|||||||
return this->m_frameCounter;
|
return this->m_frameCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CX11OpenGLDriver::dispatchEventQueue() const
|
||||||
|
{
|
||||||
|
static float startTime, endTime, minimumTime = 1.0f / this->m_context.settings.render.maximumFPS;
|
||||||
|
// get the start time of the frame
|
||||||
|
startTime = this->getRenderTime ();
|
||||||
|
this->getApp ().update ();
|
||||||
|
// get the end time of the frame
|
||||||
|
endTime = this->getRenderTime ();
|
||||||
|
|
||||||
|
// ensure the frame time is correct to not overrun FPS
|
||||||
|
if ((endTime - startTime) < minimumTime)
|
||||||
|
usleep ((minimumTime - (endTime - startTime)) * CLOCKS_PER_SEC);
|
||||||
|
}
|
||||||
|
|
||||||
GLFWwindow* CX11OpenGLDriver::getWindow ()
|
GLFWwindow* CX11OpenGLDriver::getWindow ()
|
||||||
{
|
{
|
||||||
return this->m_window;
|
return this->m_window;
|
||||||
|
@ -4,10 +4,15 @@
|
|||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
||||||
#include "WallpaperEngine/Application/CApplicationContext.h"
|
#include "WallpaperEngine/Application/CApplicationContext.h"
|
||||||
|
#include "WallpaperEngine/Render/Drivers/Detectors/CFullScreenDetector.h"
|
||||||
|
#include "WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.h"
|
||||||
|
#include "WallpaperEngine/Render/Drivers/Output/CX11Output.h"
|
||||||
|
#include "WallpaperEngine/Application/CWallpaperApplication.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Application
|
namespace WallpaperEngine::Application
|
||||||
{
|
{
|
||||||
class CApplicationContext;
|
class CApplicationContext;
|
||||||
|
class CWallpaperApplication;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Drivers
|
namespace WallpaperEngine::Render::Drivers
|
||||||
@ -17,23 +22,28 @@ namespace WallpaperEngine::Render::Drivers
|
|||||||
class CX11OpenGLDriver : public CVideoDriver
|
class CX11OpenGLDriver : public CVideoDriver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CX11OpenGLDriver (const char* windowTitle, CApplicationContext& context);
|
explicit CX11OpenGLDriver (const char* windowTitle, CApplicationContext& context, CWallpaperApplication& app);
|
||||||
~CX11OpenGLDriver();
|
~CX11OpenGLDriver();
|
||||||
|
|
||||||
void* getWindowHandle () const;
|
[[nodiscard]] Detectors::CFullScreenDetector& getFullscreenDetector () override;
|
||||||
float getRenderTime () const override;
|
[[nodiscard]] Output::COutput& getOutput () override;
|
||||||
|
[[nodiscard]] float getRenderTime () const override;
|
||||||
bool closeRequested () override;
|
bool closeRequested () override;
|
||||||
void resizeWindow (glm::ivec2 size) override;
|
void resizeWindow (glm::ivec2 size) override;
|
||||||
void resizeWindow (glm::ivec4 sizeandpos) override;
|
void resizeWindow (glm::ivec4 sizeandpos) override;
|
||||||
void showWindow () override;
|
void showWindow () override;
|
||||||
void hideWindow () override;
|
void hideWindow () override;
|
||||||
glm::ivec2 getFramebufferSize () const override;
|
[[nodiscard]] glm::ivec2 getFramebufferSize () const override;
|
||||||
void swapBuffers () override;
|
void swapBuffers () override;
|
||||||
uint32_t getFrameCounter () const override;
|
[[nodiscard]] uint32_t getFrameCounter () const override;
|
||||||
|
void dispatchEventQueue() const override;
|
||||||
|
|
||||||
GLFWwindow* getWindow ();
|
GLFWwindow* getWindow ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Detectors::CX11FullScreenDetector m_fullscreenDetector;
|
||||||
|
CApplicationContext& m_context;
|
||||||
|
Output::COutput* m_output;
|
||||||
GLFWwindow* m_window;
|
GLFWwindow* m_window;
|
||||||
uint32_t m_frameCounter;
|
uint32_t m_frameCounter;
|
||||||
};
|
};
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
using namespace WallpaperEngine::Render::Drivers::Detectors;
|
using namespace WallpaperEngine::Render::Drivers::Detectors;
|
||||||
|
|
||||||
CWaylandFullScreenDetector::CWaylandFullScreenDetector (Application::CApplicationContext& appContext, CWaylandOpenGLDriver& driver) :
|
CWaylandFullScreenDetector::CWaylandFullScreenDetector (Application::CApplicationContext& appContext, CWaylandOpenGLDriver& driver) :
|
||||||
CFullScreenDetector (appContext) {
|
CFullScreenDetector (appContext)
|
||||||
;
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CWaylandFullScreenDetector::~CWaylandFullScreenDetector () {
|
CWaylandFullScreenDetector::~CWaylandFullScreenDetector () {
|
||||||
|
@ -6,19 +6,21 @@
|
|||||||
|
|
||||||
#include "CFullScreenDetector.h"
|
#include "CFullScreenDetector.h"
|
||||||
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
||||||
#include "WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Drivers::Detectors
|
namespace WallpaperEngine::Render::Drivers
|
||||||
{
|
{
|
||||||
class CWaylandFullScreenDetector : public CFullScreenDetector
|
class CWaylandOpenGLDriver;
|
||||||
|
|
||||||
|
namespace Detectors
|
||||||
{
|
{
|
||||||
public:
|
class CWaylandFullScreenDetector : public CFullScreenDetector
|
||||||
CWaylandFullScreenDetector (Application::CApplicationContext& appContext, CWaylandOpenGLDriver& driver);
|
{
|
||||||
~CWaylandFullScreenDetector ();
|
public:
|
||||||
|
CWaylandFullScreenDetector (Application::CApplicationContext& appContext, CWaylandOpenGLDriver& driver);
|
||||||
|
~CWaylandFullScreenDetector ();
|
||||||
|
|
||||||
[[nodiscard]] bool anythingFullscreen () const override;
|
[[nodiscard]] bool anythingFullscreen () const override;
|
||||||
void reset () override;
|
void reset () override;
|
||||||
|
};
|
||||||
private:
|
}
|
||||||
};
|
|
||||||
}
|
}
|
@ -4,6 +4,7 @@
|
|||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/extensions/Xrandr.h>
|
#include <X11/extensions/Xrandr.h>
|
||||||
|
|
||||||
|
#include "WallpaperEngine/Render/Drivers/CX11OpenGLDriver.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Drivers::Detectors
|
namespace WallpaperEngine::Render::Drivers::Detectors
|
||||||
{
|
{
|
||||||
@ -31,7 +32,7 @@ namespace WallpaperEngine::Render::Drivers::Detectors
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CX11FullScreenDetector::CX11FullScreenDetector (Application::CApplicationContext& appContext, CVideoDriver& driver) :
|
CX11FullScreenDetector::CX11FullScreenDetector (Application::CApplicationContext& appContext, CX11OpenGLDriver& driver) :
|
||||||
CFullScreenDetector (appContext),
|
CFullScreenDetector (appContext),
|
||||||
m_driver (driver)
|
m_driver (driver)
|
||||||
{
|
{
|
||||||
@ -67,7 +68,7 @@ namespace WallpaperEngine::Render::Drivers::Detectors
|
|||||||
if (!XQueryTree (this->m_display, this->m_root, &_, &_, &children, &nchildren))
|
if (!XQueryTree (this->m_display, this->m_root, &_, &_, &children, &nchildren))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto ourWindow = reinterpret_cast <Window> (this->m_driver.getWindowHandle ());
|
auto ourWindow = reinterpret_cast <Window> (this->m_driver.getWindow ());
|
||||||
Window parentWindow;
|
Window parentWindow;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -5,34 +5,37 @@
|
|||||||
#include <glm/vec4.hpp>
|
#include <glm/vec4.hpp>
|
||||||
|
|
||||||
#include "CFullScreenDetector.h"
|
#include "CFullScreenDetector.h"
|
||||||
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Drivers::Detectors
|
namespace WallpaperEngine::Render::Drivers
|
||||||
{
|
{
|
||||||
class CX11FullScreenDetector : public CFullScreenDetector
|
class CX11OpenGLDriver;
|
||||||
|
|
||||||
|
namespace Detectors
|
||||||
{
|
{
|
||||||
public:
|
class CX11FullScreenDetector : public CFullScreenDetector
|
||||||
CX11FullScreenDetector (Application::CApplicationContext& appContext, CVideoDriver& driver);
|
|
||||||
~CX11FullScreenDetector ();
|
|
||||||
|
|
||||||
[[nodiscard]] bool anythingFullscreen () const override;
|
|
||||||
void reset () override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void initialize ();
|
|
||||||
void stop ();
|
|
||||||
|
|
||||||
struct ScreenInfo
|
|
||||||
{
|
{
|
||||||
glm::ivec4 viewport;
|
public:
|
||||||
std::string name;
|
CX11FullScreenDetector (Application::CApplicationContext& appContext, CX11OpenGLDriver& driver);
|
||||||
};
|
~CX11FullScreenDetector ();
|
||||||
|
|
||||||
Display* m_display;
|
[[nodiscard]] bool anythingFullscreen () const override;
|
||||||
Window m_root;
|
void reset () override;
|
||||||
std::vector <ScreenInfo> m_screens;
|
|
||||||
CVideoDriver& m_driver;
|
private:
|
||||||
};
|
void initialize ();
|
||||||
|
void stop ();
|
||||||
|
|
||||||
|
struct ScreenInfo
|
||||||
|
{
|
||||||
|
glm::ivec4 viewport;
|
||||||
|
std::string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
Display* m_display;
|
||||||
|
Window m_root;
|
||||||
|
std::vector <ScreenInfo> m_screens;
|
||||||
|
CX11OpenGLDriver& m_driver;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include "CGLFWWindowOutput.h"
|
#include "CGLFWWindowOutput.h"
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
#include "WallpaperEngine/Logging/CLog.h"
|
||||||
|
#include "CX11OutputViewport.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -8,9 +9,8 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Render::Drivers::Output;
|
using namespace WallpaperEngine::Render::Drivers::Output;
|
||||||
|
|
||||||
CGLFWWindowOutput::CGLFWWindowOutput (CApplicationContext& context, CVideoDriver& driver, Detectors::CFullScreenDetector& detector) :
|
CGLFWWindowOutput::CGLFWWindowOutput (CApplicationContext& context, CVideoDriver& driver) :
|
||||||
COutput (context, detector),
|
COutput (context, driver)
|
||||||
m_driver (driver)
|
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
this->m_context.settings.render.mode != Application::CApplicationContext::NORMAL_WINDOW &&
|
this->m_context.settings.render.mode != Application::CApplicationContext::NORMAL_WINDOW &&
|
||||||
@ -34,7 +34,7 @@ CGLFWWindowOutput::CGLFWWindowOutput (CApplicationContext& context, CVideoDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
// register the default viewport
|
// register the default viewport
|
||||||
this->m_viewports ["default"] = {{0, 0, this->m_fullWidth, this->m_fullHeight}, "default"};
|
this->m_viewports ["default"] = new CX11OutputViewport {{0, 0, this->m_fullWidth, this->m_fullHeight}, "default"};
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLFWWindowOutput::repositionWindow ()
|
void CGLFWWindowOutput::repositionWindow ()
|
||||||
@ -78,9 +78,9 @@ void CGLFWWindowOutput::updateRender () const
|
|||||||
this->m_fullHeight = this->m_driver.getFramebufferSize ().y;
|
this->m_fullHeight = this->m_driver.getFramebufferSize ().y;
|
||||||
|
|
||||||
// update the default viewport
|
// update the default viewport
|
||||||
this->m_viewports ["default"] = {{0, 0, this->m_fullWidth, this->m_fullHeight}, "default"};
|
this->m_viewports ["default"]->viewport = {0, 0, this->m_fullWidth, this->m_fullHeight};
|
||||||
|
|
||||||
// check for fullscreen windows and wait until there's none fullscreen
|
// check for fullscreen windows and wait until there's none fullscreen
|
||||||
while (this->m_detector.anythingFullscreen () && this->m_context.state.general.keepRunning)
|
while (this->m_driver.getFullscreenDetector ().anythingFullscreen () && this->m_context.state.general.keepRunning)
|
||||||
usleep (FULLSCREEN_CHECK_WAIT_TIME);
|
usleep (FULLSCREEN_CHECK_WAIT_TIME);
|
||||||
}
|
}
|
@ -8,7 +8,7 @@ namespace WallpaperEngine::Render::Drivers::Output
|
|||||||
class CGLFWWindowOutput : public COutput
|
class CGLFWWindowOutput : public COutput
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CGLFWWindowOutput (CApplicationContext& context, CVideoDriver& driver, Detectors::CFullScreenDetector& detector);
|
CGLFWWindowOutput (CApplicationContext& context, CVideoDriver& driver);
|
||||||
|
|
||||||
void reset () override;
|
void reset () override;
|
||||||
bool renderVFlip () const override;
|
bool renderVFlip () const override;
|
||||||
@ -19,7 +19,5 @@ namespace WallpaperEngine::Render::Drivers::Output
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void repositionWindow ();
|
void repositionWindow ();
|
||||||
|
|
||||||
CVideoDriver& m_driver;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Render::Drivers::Output;
|
using namespace WallpaperEngine::Render::Drivers::Output;
|
||||||
|
|
||||||
COutput::COutput (CApplicationContext& context, Detectors::CFullScreenDetector& detector) :
|
COutput::COutput (CApplicationContext& context, CVideoDriver& driver) :
|
||||||
m_context (context),
|
m_context (context),
|
||||||
m_detector (detector)
|
m_driver (driver)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map <std::string, COutput::ScreenInfo>& COutput::getViewports () const
|
const std::map <std::string, COutputViewport*>& COutput::getViewports () const
|
||||||
{
|
{
|
||||||
return this->m_viewports;
|
return this->m_viewports;
|
||||||
}
|
}
|
||||||
|
@ -14,41 +14,42 @@ namespace WallpaperEngine::Application
|
|||||||
class CApplicationContext;
|
class CApplicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Drivers::Detectors
|
namespace WallpaperEngine::Render::Drivers
|
||||||
{
|
{
|
||||||
class CFullScreenDetector;
|
class CVideoDriver;
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Drivers::Output
|
namespace Detectors
|
||||||
{
|
|
||||||
class COutput
|
|
||||||
{
|
{
|
||||||
public:
|
class CFullScreenDetector;
|
||||||
COutput (CApplicationContext& context, Detectors::CFullScreenDetector& detector);
|
}
|
||||||
|
|
||||||
virtual void reset () = 0;
|
namespace Output
|
||||||
|
{
|
||||||
|
class COutputViewport;
|
||||||
|
|
||||||
int getFullWidth () const;
|
class COutput
|
||||||
int getFullHeight () const;
|
|
||||||
|
|
||||||
struct ScreenInfo
|
|
||||||
{
|
{
|
||||||
glm::ivec4 viewport;
|
public:
|
||||||
std::string name;
|
COutput (CApplicationContext& context, CVideoDriver& driver);
|
||||||
|
|
||||||
|
virtual void reset () = 0;
|
||||||
|
|
||||||
|
int getFullWidth () const;
|
||||||
|
int getFullHeight () const;
|
||||||
|
|
||||||
|
virtual bool renderVFlip () const = 0;
|
||||||
|
virtual bool renderMultiple () const = 0;
|
||||||
|
virtual bool haveImageBuffer () const = 0;
|
||||||
|
const std::map <std::string, COutputViewport*>& getViewports () const;
|
||||||
|
virtual void* getImageBuffer () const = 0;
|
||||||
|
virtual void updateRender () const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
mutable int m_fullWidth;
|
||||||
|
mutable int m_fullHeight;
|
||||||
|
mutable std::map <std::string, COutputViewport*> m_viewports;
|
||||||
|
CApplicationContext& m_context;
|
||||||
|
CVideoDriver& m_driver;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
virtual bool renderVFlip () const = 0;
|
|
||||||
virtual bool renderMultiple () const = 0;
|
|
||||||
virtual bool haveImageBuffer () const = 0;
|
|
||||||
const std::map <std::string, ScreenInfo>& getViewports () const;
|
|
||||||
virtual void* getImageBuffer () const = 0;
|
|
||||||
virtual void updateRender () const = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
mutable int m_fullWidth;
|
|
||||||
mutable int m_fullHeight;
|
|
||||||
mutable std::map <std::string, ScreenInfo> m_viewports;
|
|
||||||
CApplicationContext& m_context;
|
|
||||||
Detectors::CFullScreenDetector& m_detector;
|
|
||||||
};
|
|
||||||
}
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
#include "COutputViewport.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
using namespace WallpaperEngine::Render::Drivers::Output;
|
||||||
|
|
||||||
|
COutputViewport::COutputViewport (glm::ivec4 viewport, std::string name, bool single) :
|
||||||
|
viewport (viewport),
|
||||||
|
name (std::move(name)),
|
||||||
|
single (single)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
COutputViewport::~COutputViewport ()
|
||||||
|
{
|
||||||
|
}
|
30
src/WallpaperEngine/Render/Drivers/Output/COutputViewport.h
Normal file
30
src/WallpaperEngine/Render/Drivers/Output/COutputViewport.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <glm/vec4.hpp>
|
||||||
|
|
||||||
|
namespace WallpaperEngine::Render::Drivers::Output
|
||||||
|
{
|
||||||
|
class COutputViewport
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
COutputViewport (glm::ivec4 viewport, std::string name, bool single = false);
|
||||||
|
virtual ~COutputViewport ();
|
||||||
|
|
||||||
|
glm::ivec4 viewport;
|
||||||
|
std::string name;
|
||||||
|
|
||||||
|
/** Whether this viewport is single in the framebuffer or shares space with more viewports */
|
||||||
|
bool single;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activates output's context for drawing
|
||||||
|
*/
|
||||||
|
virtual void makeCurrent () = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swaps buffers to present data on the viewport
|
||||||
|
*/
|
||||||
|
virtual void swapOutput () = 0;
|
||||||
|
};
|
||||||
|
}
|
@ -4,9 +4,8 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Render::Drivers::Output;
|
using namespace WallpaperEngine::Render::Drivers::Output;
|
||||||
|
|
||||||
CWaylandOutput::CWaylandOutput (CApplicationContext& context, CVideoDriver& driver, Detectors::CFullScreenDetector& detector) :
|
CWaylandOutput::CWaylandOutput (CApplicationContext& context, CWaylandOpenGLDriver& driver) :
|
||||||
COutput (context, detector),
|
COutput (context, driver)
|
||||||
m_driver (driver)
|
|
||||||
{
|
{
|
||||||
updateViewports();
|
updateViewports();
|
||||||
}
|
}
|
||||||
@ -15,15 +14,17 @@ CWaylandOutput::~CWaylandOutput ()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWaylandOutput::updateViewports() {
|
void CWaylandOutput::updateViewports()
|
||||||
|
{
|
||||||
m_viewports.clear();
|
m_viewports.clear();
|
||||||
const auto PDRIVER = (CWaylandOpenGLDriver*)&m_driver;
|
const auto PDRIVER = (CWaylandOpenGLDriver*)&m_driver;
|
||||||
glm::ivec2 fullw = {0,0};
|
glm::ivec2 fullw = {0,0};
|
||||||
for (auto& o : PDRIVER->m_outputs) {
|
for (auto& o : PDRIVER->m_screens)
|
||||||
if (!o->layerSurface.get())
|
{
|
||||||
|
if (!o->layerSurface)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
m_viewports[o->name] = {{0, 0, o->lsSize.x * o->scale, o->lsSize.y * o->scale}, o->name};
|
m_viewports[o->name] = o;
|
||||||
|
|
||||||
fullw = fullw + glm::ivec2{o->lsSize.x * o->scale, 0};
|
fullw = fullw + glm::ivec2{o->lsSize.x * o->scale, 0};
|
||||||
if (o->lsSize.y > fullw.y)
|
if (o->lsSize.y > fullw.y)
|
||||||
@ -34,26 +35,31 @@ void CWaylandOutput::updateViewports() {
|
|||||||
m_fullHeight = fullw.y;
|
m_fullHeight = fullw.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWaylandOutput::reset () {
|
void CWaylandOutput::reset ()
|
||||||
|
{
|
||||||
updateViewports();
|
updateViewports();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWaylandOutput::renderVFlip () const {
|
bool CWaylandOutput::renderVFlip () const
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWaylandOutput::renderMultiple () const {
|
bool CWaylandOutput::renderMultiple () const
|
||||||
|
{
|
||||||
return false; // todo
|
return false; // todo
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWaylandOutput::haveImageBuffer () const {
|
bool CWaylandOutput::haveImageBuffer () const
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* CWaylandOutput::getImageBuffer () const {
|
void* CWaylandOutput::getImageBuffer () const
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWaylandOutput::updateRender () const {
|
void CWaylandOutput::updateRender () const
|
||||||
;
|
{
|
||||||
}
|
}
|
@ -7,25 +7,28 @@
|
|||||||
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
||||||
#include "COutput.h"
|
#include "COutput.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Drivers::Output
|
namespace WallpaperEngine::Render::Drivers
|
||||||
{
|
{
|
||||||
class CWaylandOutput : public COutput
|
class CWaylandOpenGLDriver;
|
||||||
|
|
||||||
|
namespace Output
|
||||||
{
|
{
|
||||||
public:
|
class CWaylandOutput : public COutput
|
||||||
CWaylandOutput (CApplicationContext& context, CVideoDriver& driver, Detectors::CFullScreenDetector& detector);
|
{
|
||||||
~CWaylandOutput ();
|
public:
|
||||||
|
CWaylandOutput (CApplicationContext& context, CWaylandOpenGLDriver& driver);
|
||||||
|
~CWaylandOutput ();
|
||||||
|
|
||||||
void reset () override;
|
void reset () override;
|
||||||
|
|
||||||
bool renderVFlip () const override;
|
bool renderVFlip () const override;
|
||||||
bool renderMultiple () const override;
|
bool renderMultiple () const override;
|
||||||
bool haveImageBuffer () const override;
|
bool haveImageBuffer () const override;
|
||||||
void* getImageBuffer () const override;
|
void* getImageBuffer () const override;
|
||||||
void updateRender () const override;
|
void updateRender () const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateViewports();
|
void updateViewports();
|
||||||
|
};
|
||||||
CVideoDriver& m_driver;
|
}
|
||||||
};
|
|
||||||
}
|
}
|
@ -0,0 +1,236 @@
|
|||||||
|
#include "WallpaperEngine/Application/CWallpaperApplication.h"
|
||||||
|
#include "CWaylandOutputViewport.h"
|
||||||
|
#include "WallpaperEngine/Logging/CLog.h"
|
||||||
|
|
||||||
|
#define class _class
|
||||||
|
#define namespace _namespace
|
||||||
|
#define static
|
||||||
|
extern "C" {
|
||||||
|
#include "xdg-shell-protocol.h"
|
||||||
|
#include "wlr-layer-shell-unstable-v1-protocol.h"
|
||||||
|
}
|
||||||
|
#undef class
|
||||||
|
#undef namespace
|
||||||
|
#undef static
|
||||||
|
|
||||||
|
using namespace WallpaperEngine::Render::Drivers;
|
||||||
|
using namespace WallpaperEngine::Render::Drivers::Output;
|
||||||
|
|
||||||
|
static void handleLSConfigure(void *data, zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t w, uint32_t h)
|
||||||
|
{
|
||||||
|
const auto viewport = static_cast <CWaylandOutputViewport*> (data);
|
||||||
|
viewport->size = {w, h};
|
||||||
|
viewport->viewport = {0, 0, viewport->size.x * viewport->scale, viewport->size.y * viewport->scale};
|
||||||
|
viewport->resize ();
|
||||||
|
|
||||||
|
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handleLSClosed(void *data, zwlr_layer_surface_v1 *surface)
|
||||||
|
{
|
||||||
|
const auto viewport = static_cast <CWaylandOutputViewport*> (data);
|
||||||
|
|
||||||
|
viewport->getDriver ()->onLayerClose(viewport);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void geometry(
|
||||||
|
void* data, wl_output* output, int32_t x, int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel,
|
||||||
|
const char* make, const char* model, int32_t transform
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mode(void* data, wl_output* output, uint32_t flags, int32_t width, int32_t height, int32_t refresh)
|
||||||
|
{
|
||||||
|
const auto viewport = static_cast <CWaylandOutputViewport*> (data);
|
||||||
|
|
||||||
|
// update viewport size too
|
||||||
|
viewport->size = {width, height};
|
||||||
|
viewport->viewport = {0, 0, viewport->size.x * viewport->scale, viewport->size.y * viewport->scale};
|
||||||
|
|
||||||
|
if (viewport->layerSurface)
|
||||||
|
viewport->resize ();
|
||||||
|
|
||||||
|
if (viewport->initialized)
|
||||||
|
viewport->getDriver ()->getOutput ().reset ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void done(void* data, wl_output* wl_output)
|
||||||
|
{
|
||||||
|
static_cast <CWaylandOutputViewport*> (data)->initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void scale(void* data, wl_output* wl_output, int32_t scale)
|
||||||
|
{
|
||||||
|
const auto viewport = static_cast <CWaylandOutputViewport*> (data);
|
||||||
|
|
||||||
|
viewport->scale = scale;
|
||||||
|
|
||||||
|
if (viewport->layerSurface)
|
||||||
|
viewport->resize ();
|
||||||
|
|
||||||
|
if (viewport->initialized)
|
||||||
|
viewport->getDriver ()->getOutput ().reset ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void name(void* data, wl_output* wl_output, const char* name)
|
||||||
|
{
|
||||||
|
const auto viewport = static_cast <CWaylandOutputViewport*> (data);
|
||||||
|
|
||||||
|
if (name)
|
||||||
|
viewport->name = name;
|
||||||
|
|
||||||
|
// ensure the output is updated with the new name too
|
||||||
|
viewport->getDriver ()->getOutput ().reset ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void description(void* data, wl_output* wl_output, const char* description)
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
|
||||||
|
static void surfaceFrameCallback(void *data, struct wl_callback *cb, uint32_t time)
|
||||||
|
{
|
||||||
|
const auto viewport = static_cast <CWaylandOutputViewport*> (data);
|
||||||
|
|
||||||
|
wl_callback_destroy(cb);
|
||||||
|
|
||||||
|
viewport->frameCallback = nullptr;
|
||||||
|
viewport->rendering = true;
|
||||||
|
viewport->getDriver ()->getApp ().update ();
|
||||||
|
viewport->rendering = false;
|
||||||
|
|
||||||
|
float renderTime = viewport->getDriver ()->getRenderTime();
|
||||||
|
|
||||||
|
if ((renderTime - viewport->lastTime) < viewport->minimumTime)
|
||||||
|
usleep ((viewport->minimumTime - (renderTime - viewport->lastTime)) * CLOCKS_PER_SEC);
|
||||||
|
|
||||||
|
viewport->lastTime = renderTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct wl_callback_listener frameListener = {
|
||||||
|
.done = surfaceFrameCallback
|
||||||
|
};
|
||||||
|
|
||||||
|
const wl_output_listener outputListener =
|
||||||
|
{
|
||||||
|
.geometry = geometry,
|
||||||
|
.mode = mode,
|
||||||
|
.done = done,
|
||||||
|
.scale = scale,
|
||||||
|
.name = name,
|
||||||
|
.description = description
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct zwlr_layer_surface_v1_listener layerSurfaceListener = {
|
||||||
|
.configure = handleLSConfigure,
|
||||||
|
.closed = handleLSClosed,
|
||||||
|
};
|
||||||
|
|
||||||
|
CWaylandOutputViewport::CWaylandOutputViewport (CWaylandOpenGLDriver* driver, uint32_t waylandName, struct wl_registry *registry) :
|
||||||
|
m_driver (driver),
|
||||||
|
waylandName (waylandName),
|
||||||
|
COutputViewport ({0,0,0,0}, "", true)
|
||||||
|
{
|
||||||
|
// setup output listener
|
||||||
|
this->output = (wl_output*) wl_registry_bind(registry, waylandName, &wl_output_interface, 4);
|
||||||
|
this->name = "";
|
||||||
|
this->size = {0, 0};
|
||||||
|
wl_output_add_listener(output, &outputListener, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWaylandOutputViewport::setupLS ()
|
||||||
|
{
|
||||||
|
surface = wl_compositor_create_surface(m_driver->getWaylandContext()->compositor);
|
||||||
|
layerSurface = zwlr_layer_shell_v1_get_layer_surface(m_driver->getWaylandContext()->layerShell, surface, this->output, ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "linux-wallpaperengine");
|
||||||
|
|
||||||
|
if (!layerSurface)
|
||||||
|
sLog.exception("Failed to get a layer surface");
|
||||||
|
|
||||||
|
wl_region* region = wl_compositor_create_region(m_driver->getWaylandContext()->compositor);
|
||||||
|
wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX);
|
||||||
|
|
||||||
|
zwlr_layer_surface_v1_set_size(layerSurface, 0, 0);
|
||||||
|
zwlr_layer_surface_v1_set_anchor(layerSurface, ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM);
|
||||||
|
zwlr_layer_surface_v1_set_keyboard_interactivity(layerSurface, false);
|
||||||
|
zwlr_layer_surface_v1_add_listener(layerSurface, &layerSurfaceListener, this);
|
||||||
|
zwlr_layer_surface_v1_set_exclusive_zone(layerSurface, -1);
|
||||||
|
wl_surface_set_input_region(surface, region);
|
||||||
|
wl_surface_commit(surface);
|
||||||
|
wl_display_roundtrip(m_driver->getWaylandContext()->display);
|
||||||
|
|
||||||
|
eglWindow = wl_egl_window_create(surface, size.x * scale, size.y * scale);
|
||||||
|
eglSurface = m_driver->getEGLContext ()->eglCreatePlatformWindowSurfaceEXT(m_driver->getEGLContext ()->display, m_driver->getEGLContext ()->config, eglWindow, nullptr);
|
||||||
|
lsSize = size;
|
||||||
|
wl_surface_commit(surface);
|
||||||
|
wl_display_roundtrip(m_driver->getWaylandContext()->display);
|
||||||
|
wl_display_flush(m_driver->getWaylandContext()->display);
|
||||||
|
|
||||||
|
static const auto XCURSORSIZE = getenv("XCURSOR_SIZE") ? std::stoi(getenv("XCURSOR_SIZE")) : 24;
|
||||||
|
const auto PRCURSORTHEME = wl_cursor_theme_load(getenv("XCURSOR_THEME"), XCURSORSIZE * scale, m_driver->getWaylandContext()->shm);
|
||||||
|
|
||||||
|
if (!PRCURSORTHEME)
|
||||||
|
sLog.exception("Failed to get a cursor theme");
|
||||||
|
|
||||||
|
pointer = wl_cursor_theme_get_cursor(PRCURSORTHEME, "left_ptr");
|
||||||
|
cursorSurface = wl_compositor_create_surface(m_driver->getWaylandContext()->compositor);
|
||||||
|
|
||||||
|
if (!cursorSurface)
|
||||||
|
sLog.exception("Failed to get a cursor surface");
|
||||||
|
|
||||||
|
if (eglMakeCurrent(m_driver->getEGLContext ()->display, eglSurface, eglSurface, m_driver->getEGLContext ()->context) == EGL_FALSE)
|
||||||
|
sLog.exception("Failed to make egl current");
|
||||||
|
|
||||||
|
minimumTime = 1.0f / m_driver->getApp ().getContext().settings.render.maximumFPS;
|
||||||
|
|
||||||
|
// reset the output to notice the new viewport
|
||||||
|
m_driver->getOutput ().reset ();
|
||||||
|
}
|
||||||
|
|
||||||
|
CWaylandOpenGLDriver* CWaylandOutputViewport::getDriver ()
|
||||||
|
{
|
||||||
|
return this->m_driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWaylandOutputViewport::makeCurrent ()
|
||||||
|
{
|
||||||
|
EGLBoolean result = eglMakeCurrent (
|
||||||
|
m_driver->getEGLContext ()->display,
|
||||||
|
eglSurface,
|
||||||
|
eglSurface,
|
||||||
|
m_driver->getEGLContext ()->context
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result == EGL_FALSE)
|
||||||
|
sLog.error ("Couldn't make egl current");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWaylandOutputViewport::swapOutput ()
|
||||||
|
{
|
||||||
|
this->callbackInitialized = true;
|
||||||
|
|
||||||
|
this->makeCurrent ();
|
||||||
|
frameCallback = wl_surface_frame (surface);
|
||||||
|
wl_callback_add_listener (frameCallback, &frameListener, this);
|
||||||
|
eglSwapBuffers (m_driver->getEGLContext ()->display, this->eglSurface);
|
||||||
|
wl_surface_set_buffer_scale(surface, scale);
|
||||||
|
wl_surface_damage_buffer(surface, 0, 0, INT32_MAX, INT32_MAX);
|
||||||
|
wl_surface_commit(surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWaylandOutputViewport::resize ()
|
||||||
|
{
|
||||||
|
if (!this->eglWindow)
|
||||||
|
return;
|
||||||
|
|
||||||
|
wl_egl_window_resize(this->eglWindow, this->size.x * this->scale, this->size.y * this->scale, 0, 0);
|
||||||
|
|
||||||
|
if (this->frameCallback)
|
||||||
|
{
|
||||||
|
wl_callback_destroy(this->frameCallback);
|
||||||
|
this->frameCallback = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->getDriver ()->getOutput().reset();
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <wayland-client.h>
|
||||||
|
#include <wayland-cursor.h>
|
||||||
|
#include <wayland-egl.h>
|
||||||
|
#include <EGL/egl.h>
|
||||||
|
#include <EGL/eglext.h>
|
||||||
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
#include <glm/vec2.hpp>
|
||||||
|
#include "COutputViewport.h"
|
||||||
|
#include "../CWaylandOpenGLDriver.h"
|
||||||
|
|
||||||
|
struct zwlr_layer_shell_v1;
|
||||||
|
struct zwlr_layer_surface_v1;
|
||||||
|
|
||||||
|
namespace WallpaperEngine::Render::Drivers
|
||||||
|
{
|
||||||
|
class CWaylandOpenGLDriver;
|
||||||
|
|
||||||
|
namespace Output
|
||||||
|
{
|
||||||
|
class COutputViewport;
|
||||||
|
|
||||||
|
class CWaylandOutputViewport : public COutputViewport
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CWaylandOutputViewport (CWaylandOpenGLDriver* driver, uint32_t waylandName, struct wl_registry *registry);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The wayland driver
|
||||||
|
*/
|
||||||
|
CWaylandOpenGLDriver* getDriver ();
|
||||||
|
|
||||||
|
wl_output* output;
|
||||||
|
glm::ivec2 size;
|
||||||
|
glm::ivec2 lsSize;
|
||||||
|
uint32_t waylandName;
|
||||||
|
int scale = 1;
|
||||||
|
bool initialized = false;
|
||||||
|
bool rendering = false;
|
||||||
|
|
||||||
|
wl_egl_window* eglWindow = nullptr;
|
||||||
|
EGLSurface eglSurface = nullptr;
|
||||||
|
wl_surface* surface = nullptr;
|
||||||
|
zwlr_layer_surface_v1* layerSurface = nullptr;
|
||||||
|
wl_callback* frameCallback = nullptr;
|
||||||
|
glm::dvec2 mousePos = {0, 0};
|
||||||
|
wl_cursor* pointer = nullptr;
|
||||||
|
wl_surface* cursorSurface = nullptr;
|
||||||
|
bool callbackInitialized = false;
|
||||||
|
float lastTime, minimumTime;
|
||||||
|
|
||||||
|
void setupLS ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activates output's context for drawing
|
||||||
|
*/
|
||||||
|
void makeCurrent () override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swaps buffers to present data on the viewport
|
||||||
|
*/
|
||||||
|
void swapOutput () override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the viewport size
|
||||||
|
*/
|
||||||
|
void resize ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CWaylandOpenGLDriver* m_driver;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "CX11Output.h"
|
#include "CX11Output.h"
|
||||||
|
#include "CX11OutputViewport.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
@ -34,9 +35,8 @@ int CustomXIOErrorHandler (Display* dsp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CX11Output::CX11Output (CApplicationContext& context, CVideoDriver& driver, Detectors::CFullScreenDetector& detector) :
|
CX11Output::CX11Output (CApplicationContext& context, CVideoDriver& driver) :
|
||||||
COutput (context, detector),
|
COutput (context, driver)
|
||||||
m_driver (driver)
|
|
||||||
{
|
{
|
||||||
// do not use previous handler, it might stop the app under weird circumstances
|
// do not use previous handler, it might stop the app under weird circumstances
|
||||||
XSetErrorHandler (CustomXErrorHandler);
|
XSetErrorHandler (CustomXErrorHandler);
|
||||||
@ -57,11 +57,17 @@ void CX11Output::reset ()
|
|||||||
// re-load screen info
|
// re-load screen info
|
||||||
this->loadScreenInfo ();
|
this->loadScreenInfo ();
|
||||||
// do the same for the detector
|
// do the same for the detector
|
||||||
this->m_detector.reset ();
|
this->m_driver.getFullscreenDetector ().reset ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CX11Output::free ()
|
void CX11Output::free ()
|
||||||
{
|
{
|
||||||
|
// go through all the viewports and free them
|
||||||
|
for(const auto& cur : this->m_viewports)
|
||||||
|
delete cur.second;
|
||||||
|
|
||||||
|
this->m_viewports.clear ();
|
||||||
|
|
||||||
// free all the resources we've got
|
// free all the resources we've got
|
||||||
XDestroyImage (this->m_image);
|
XDestroyImage (this->m_image);
|
||||||
XFreeGC (this->m_display, this->m_gc);
|
XFreeGC (this->m_display, this->m_gc);
|
||||||
@ -132,6 +138,7 @@ void CX11Output::loadScreenInfo ()
|
|||||||
|
|
||||||
// add the screen to the list of screens
|
// add the screen to the list of screens
|
||||||
this->m_screens.push_back (
|
this->m_screens.push_back (
|
||||||
|
new CX11OutputViewport
|
||||||
{
|
{
|
||||||
{crtc->x, crtc->y, crtc->width, crtc->height},
|
{crtc->x, crtc->y, crtc->width, crtc->height},
|
||||||
info->name
|
info->name
|
||||||
@ -144,6 +151,7 @@ void CX11Output::loadScreenInfo ()
|
|||||||
sLog.out ("Found requested screen: ", info->name, " -> ", crtc->x, "x", crtc->y, ":", crtc->width, "x", crtc->height);
|
sLog.out ("Found requested screen: ", info->name, " -> ", crtc->x, "x", crtc->y, ":", crtc->width, "x", crtc->height);
|
||||||
|
|
||||||
this->m_viewports[info->name] =
|
this->m_viewports[info->name] =
|
||||||
|
new CX11OutputViewport
|
||||||
{
|
{
|
||||||
{crtc->x, crtc->y, crtc->width, crtc->height},
|
{crtc->x, crtc->y, crtc->width, crtc->height},
|
||||||
info->name
|
info->name
|
||||||
@ -187,6 +195,6 @@ void CX11Output::updateRender () const
|
|||||||
XFlush(this->m_display);
|
XFlush(this->m_display);
|
||||||
|
|
||||||
// check for fullscreen windows and wait until there's none fullscreen
|
// check for fullscreen windows and wait until there's none fullscreen
|
||||||
while (this->m_detector.anythingFullscreen () && this->m_context.state.general.keepRunning)
|
while (this->m_driver.getFullscreenDetector ().anythingFullscreen () && this->m_context.state.general.keepRunning)
|
||||||
usleep (FULLSCREEN_CHECK_WAIT_TIME);
|
usleep (FULLSCREEN_CHECK_WAIT_TIME);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ namespace WallpaperEngine::Render::Drivers::Output
|
|||||||
class CX11Output : public COutput
|
class CX11Output : public COutput
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CX11Output (CApplicationContext& context, CVideoDriver& driver, Detectors::CFullScreenDetector& detector);
|
CX11Output (CApplicationContext& context, CVideoDriver& driver);
|
||||||
~CX11Output ();
|
~CX11Output ();
|
||||||
|
|
||||||
void reset () override;
|
void reset () override;
|
||||||
@ -35,7 +35,6 @@ namespace WallpaperEngine::Render::Drivers::Output
|
|||||||
GC m_gc;
|
GC m_gc;
|
||||||
char* m_imageData;
|
char* m_imageData;
|
||||||
XImage* m_image;
|
XImage* m_image;
|
||||||
CVideoDriver& m_driver;
|
std::vector <COutputViewport*> m_screens;
|
||||||
std::vector <ScreenInfo> m_screens;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
#include "CX11OutputViewport.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
using namespace WallpaperEngine::Render::Drivers::Output;
|
||||||
|
|
||||||
|
CX11OutputViewport::CX11OutputViewport (glm::ivec4 viewport, std::string name) :
|
||||||
|
COutputViewport (viewport, std::move(name))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CX11OutputViewport::makeCurrent ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CX11OutputViewport::swapOutput ()
|
||||||
|
{
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "COutputViewport.h"
|
||||||
|
|
||||||
|
namespace WallpaperEngine::Render::Drivers::Output
|
||||||
|
{
|
||||||
|
class CX11OutputViewport : public COutputViewport
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CX11OutputViewport (glm::ivec4 viewport, std::string name);
|
||||||
|
|
||||||
|
void makeCurrent () override;
|
||||||
|
void swapOutput () override;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user