diff --git a/src/qt/qt_openglrenderer.cpp b/src/qt/qt_openglrenderer.cpp index 860b5d303..37afd4810 100644 --- a/src/qt/qt_openglrenderer.cpp +++ b/src/qt/qt_openglrenderer.cpp @@ -1612,95 +1612,35 @@ OpenGLRenderer::render() render_pass(&data); } - if (1) { - // if (video_focus_dim && !(SDL_GetWindowFlags(window) & SDL_WINDOW_INPUT_FOCUS)) { -#if 0 - if (0) { - struct shader_pass *pass = &active_shader->fs_color; - GLfloat r = 0; - GLfloat g = 0; - GLfloat b = 0; - GLfloat a = 0x80 / (float) 0xff; + if (monitors[r_monitor_index].mon_screenshots) { + int width = destination.width() * devicePixelRatio(), height = destination.height() * devicePixelRatio(); + char path[1024]; + char fn[256]; + + memset(fn, 0, sizeof(fn)); + memset(path, 0, sizeof(path)); + + path_append_filename(path, usr_path, SCREENSHOT_PATH); + + if (!plat_dir_check(path)) + plat_dir_create(path); + + path_slash(path); + strcat(path, "Monitor_"); + snprintf(&path[strlen(path)], 42, "%d_", r_monitor_index + 1); + + plat_tempfile(fn, NULL, (char*)".png"); + strcat(path, fn); - GLfloat colors[] = { r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a }; + unsigned char *rgba = (unsigned char *)calloc(1, width * height * 4); + + glw.glFinish(); + glw.glReadPixels(window_rect.x, window_rect.y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, rgba); - glw.glBindVertexArray(pass->vertex_array); - - glw.glBindBuffer(GL_ARRAY_BUFFER, pass->vbo.color); - glw.glBufferSubData(GL_ARRAY_BUFFER, 0, 16 * sizeof(GLfloat), colors); - glw.glBindBuffer(GL_ARRAY_BUFFER, 0); - - memset(&data, 0, sizeof(struct render_data)); - data.pass = -3; - data.shader_pass = pass; - data.texture = 0; - data.output_size = orig_output_size; - data.orig_pass = orig; - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - render_pass(&data); - glDisable(GL_BLEND); - } - - if (flash.enabled) { - struct shader_pass *pass = &active_shader->fs_color; - GLfloat r = (flash.color[0] & 0xff) / (float)0xff; - GLfloat g = (flash.color[1] & 0xff) / (float)0xff; - GLfloat b = (flash.color[2] & 0xff) / (float)0xff; - GLfloat a = (flash.color[3] & 0xff) / (float)0xff; - - GLfloat colors[] = {r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a}; - - glw.glBindVertexArray(pass->vertex_array); - - glw.glBindBuffer(GL_ARRAY_BUFFER, pass->vbo.color); - glw.glBufferSubData(GL_ARRAY_BUFFER, 0, 16 * sizeof(GLfloat), colors); - glw.glBindBuffer(GL_ARRAY_BUFFER, 0); - - memset(&data, 0, sizeof(struct render_data)); - data.pass = -3; - data.shader_pass = pass; - data.texture = 0; - data.output_size = orig_output_size; - data.orig_pass = orig; - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - render_pass(&data); - glDisable(GL_BLEND); - } -#endif - } else { -#if 0 - take_screenshot = 0; - - int width = window_rect.w; - int height = window_rect.h; - - SDL_GetWindowSize(window, &width, &height); - - unsigned char *rgba = (unsigned char *)malloc(width * height * 4); - - glFinish(); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, rgba); - - int x, y; - unsigned char *rgb = (unsigned char *)malloc(width * height * 3); - - for (x = 0; x < width; ++x) { - for (y = 0; y < height; ++y) { - rgb[(y * width + x) * 3 + 0] = rgba[((height - y - 1) * width + x) * 4 + 0]; - rgb[(y * width + x) * 3 + 1] = rgba[((height - y - 1) * width + x) * 4 + 1]; - rgb[(y * width + x) * 3 + 2] = rgba[((height - y - 1) * width + x) * 4 + 2]; - } - } - - screenshot_taken(rgb, width, height); - - free(rgb); - free(rgba); -#endif + QImage image(rgba, width, height, QImage::Format_RGBA8888); + image.mirrored(false, true).save(path, "png"); + monitors[r_monitor_index].mon_screenshots--; + free(rgba); } glw.glDisable(GL_FRAMEBUFFER_SRGB); diff --git a/src/qt/qt_renderercommon.hpp b/src/qt/qt_renderercommon.hpp index f3f5d2223..bbda9516b 100644 --- a/src/qt/qt_renderercommon.hpp +++ b/src/qt/qt_renderercommon.hpp @@ -36,6 +36,8 @@ public: virtual void reloadOptions() { } /* Make the renderer reload itself */ virtual bool reloadRendererOption() { return false; } + /* Should the renderer take screenshots itself? */ + virtual bool rendererTakeScreenshot() { return false; } int r_monitor_index = 0; diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index ca16b680e..38f087622 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -63,6 +63,7 @@ RendererStack::RendererStack(QWidget *parent, int monitor_index) : QStackedWidget(parent) , ui(new Ui::RendererStack) { + rendererTakesScreenshots = false; #ifdef Q_OS_WINDOWS int raw = 1; #else @@ -305,6 +306,7 @@ RendererStack::switchRenderer(Renderer renderer) void RendererStack::createRenderer(Renderer renderer) { + rendererTakesScreenshots = false; switch (renderer) { default: case Renderer::Software: @@ -360,6 +362,7 @@ RendererStack::createRenderer(Renderer renderer) case Renderer::OpenGL3: { this->createWinId(); + this->rendererTakesScreenshots = true; auto hw = new OpenGLRenderer(this); rendererWindow = hw; connect(this, &RendererStack::blitToRenderer, hw, &OpenGLRenderer::onBlit, Qt::QueuedConnection); @@ -424,6 +427,8 @@ RendererStack::createRenderer(Renderer renderer) this->setStyleSheet("background-color: black"); + rendererWindow->r_monitor_index = m_monitor_index; + currentBuf = 0; if (renderer != Renderer::OpenGL3 && renderer != Renderer::Vulkan && renderer != Renderer::OpenGL3PCem) { @@ -454,7 +459,7 @@ RendererStack::blit(int x, int y, int w, int h) video_copy(scanline, &(monitors[m_monitor_index].target_buffer->line[y1][x]), w * 4); } - if (monitors[m_monitor_index].mon_screenshots) { + if (monitors[m_monitor_index].mon_screenshots && !rendererTakesScreenshots) { video_screenshot_monitor((uint32_t *) imagebits, x, y, 2048, m_monitor_index); } video_blit_complete_monitor(m_monitor_index); diff --git a/src/qt/qt_rendererstack.hpp b/src/qt/qt_rendererstack.hpp index 32ed5f7ca..a84773c72 100644 --- a/src/qt/qt_rendererstack.hpp +++ b/src/qt/qt_rendererstack.hpp @@ -15,6 +15,8 @@ #include "qt_renderercommon.hpp" +#include + namespace Ui { class RendererStack; } @@ -110,6 +112,8 @@ private: RendererCommon *rendererWindow { nullptr }; std::unique_ptr current; + + std::atomic_bool rendererTakesScreenshots; }; #endif // QT_RENDERERCONTAINER_HPP