[glfw] Reduce memory use when window loses focus

This commit is contained in:
Mikhail Pozdnyakov
2019-07-09 16:29:30 +03:00
parent 286bc66ba4
commit eaed0036ef
2 changed files with 9 additions and 0 deletions

View File

@@ -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<GLFWView *>(glfwGetWindowUserPointer(window));
view->rendererFrontend->getRenderer()->reduceMemoryUse();
}
}
void GLFWView::run() {
auto callback = [&] {
if (glfwWindowShouldClose(window)) {

View File

@@ -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);