diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-08-30 04:06:49 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-30 04:06:49 +0200 |
commit | d69aded7faee43837dfd17342da50c1aa93de58f (patch) | |
tree | 08cef4dac321b71f5ec753bd1206d642ce893520 /src/main.cpp | |
parent | e215d62dfddd792cc5589600279ffb014905cecf (diff) |
Slightly improve performance by only swapping buffer on redraw
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/src/main.cpp b/src/main.cpp index d4fa686..a4eb0f7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,7 +37,6 @@ #include <GLFW/glfw3.h> #include <X11/extensions/Xcomposite.h> -#include <X11/extensions/Xdamage.h> extern "C" { #include <libavcodec/avcodec.h> @@ -699,7 +698,7 @@ int main(int argc, char **argv) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); - GLFWwindow *window = glfwCreateWindow(32, 32, "gpu-screen-recorder", nullptr, nullptr); + GLFWwindow *window = glfwCreateWindow(1, 1, "gpu-screen-recorder", nullptr, nullptr); if (!window) { fprintf(stderr, "Error: Failed to create glfw window\n"); glfwTerminate(); @@ -810,15 +809,6 @@ int main(int argc, char **argv) { XSelectInput(dpy, src_window_id, StructureNotifyMask); - int damage_event; - int damage_error; - if (!XDamageQueryExtension(dpy, &damage_event, &damage_error)) { - fprintf(stderr, "Error: XDamage is not supported by your X11 server\n"); - return 1; - } - - Damage xdamage = XDamageCreate(dpy, src_window_id, XDamageReportNonEmpty); - int frame_count = 0; CUresult res; @@ -960,8 +950,7 @@ int main(int argc, char **argv) { while (running) { double frame_start = glfwGetTime(); - glClear(GL_COLOR_BUFFER_BIT); - glfwSwapBuffers(window); + /*glClear(GL_COLOR_BUFFER_BIT);*/ glfwPollEvents(); if (XCheckTypedWindowEvent(dpy, src_window_id, ConfigureNotify, &e) && e.xconfigure.window == src_window_id) { @@ -974,17 +963,7 @@ int main(int argc, char **argv) { } } - if (XCheckTypedWindowEvent(dpy, src_window_id, damage_event + XDamageNotify, &e)) { - // fprintf(stderr, "Redraw!\n"); - XDamageNotifyEvent *de = (XDamageNotifyEvent *)&e; - // de->drawable is the window ID of the damaged window - XserverRegion region = XFixesCreateRegion(dpy, nullptr, 0); - // Subtract all the damage, repairing the window - XDamageSubtract(dpy, de->damage, None, region); - XFixesDestroyRegion(dpy, region); - - redraw = true; - } + redraw = true; const double window_resize_timeout = 1.0; // 1 second if(window_resized && glfwGetTime() - window_resize_timer >= window_resize_timeout) { @@ -1064,6 +1043,7 @@ int main(int argc, char **argv) { memcpy_struct.Height = frame->height; cuMemcpy2D(&memcpy_struct); // res = cuCtxPopCurrent(&old_ctx); + glfwSwapBuffers(window); } frame->pts = frame_count; @@ -1153,7 +1133,6 @@ int main(int argc, char **argv) { if(!(output_format->flags & AVFMT_NOFILE)) avio_close(av_format_context->pb); // avformat_free_context(av_format_context); - // XDamageDestroy(dpy, xdamage); // cleanup_window_pixmap(dpy, window_pixmap); XCompositeUnredirectWindow(dpy, src_window_id, CompositeRedirectAutomatic); |