From eaed0036efe04cfaa50218f7041078972427dffb Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Tue, 9 Jul 2019 16:29:30 +0300 Subject: [glfw] Reduce memory use when window loses focus --- platform/glfw/glfw_view.cpp | 8 ++++++++ platform/glfw/glfw_view.hpp | 1 + 2 files changed, 9 insertions(+) (limited to 'platform') diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index 41c3e93b35..43c4de9759 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -102,6 +102,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_) glfwSetFramebufferSizeCallback(window, onFramebufferResize); glfwSetScrollCallback(window, onScroll); glfwSetKeyCallback(window, onKey); + glfwSetWindowFocusCallback(window, onWindowFocus); glfwGetWindowSize(window, &width, &height); @@ -559,6 +560,13 @@ void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) { view->lastY = y; } +void GLFWView::onWindowFocus(GLFWwindow *window, int focused) { + if (focused == GLFW_FALSE) { // Focus lost. + auto *view = reinterpret_cast(glfwGetWindowUserPointer(window)); + view->rendererFrontend->getRenderer()->reduceMemoryUse(); + } +} + void GLFWView::run() { auto callback = [&] { if (glfwWindowShouldClose(window)) { diff --git a/platform/glfw/glfw_view.hpp b/platform/glfw/glfw_view.hpp index 9c9661546c..54b89ba2d9 100644 --- a/platform/glfw/glfw_view.hpp +++ b/platform/glfw/glfw_view.hpp @@ -68,6 +68,7 @@ private: static void onFramebufferResize(GLFWwindow *window, int width, int height); static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers); static void onMouseMove(GLFWwindow *window, double x, double y); + static void onWindowFocus(GLFWwindow *window, int focused); // Internal void report(float duration); -- cgit v1.2.1