Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit eaed003

Browse files
committed
[glfw] Reduce memory use when window loses focus
1 parent 286bc66 commit eaed003

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

platform/glfw/glfw_view.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_)
102102
glfwSetFramebufferSizeCallback(window, onFramebufferResize);
103103
glfwSetScrollCallback(window, onScroll);
104104
glfwSetKeyCallback(window, onKey);
105+
glfwSetWindowFocusCallback(window, onWindowFocus);
105106

106107
glfwGetWindowSize(window, &width, &height);
107108

@@ -559,6 +560,13 @@ void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) {
559560
view->lastY = y;
560561
}
561562

563+
void GLFWView::onWindowFocus(GLFWwindow *window, int focused) {
564+
if (focused == GLFW_FALSE) { // Focus lost.
565+
auto *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
566+
view->rendererFrontend->getRenderer()->reduceMemoryUse();
567+
}
568+
}
569+
562570
void GLFWView::run() {
563571
auto callback = [&] {
564572
if (glfwWindowShouldClose(window)) {

platform/glfw/glfw_view.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class GLFWView : public mbgl::MapObserver {
6868
static void onFramebufferResize(GLFWwindow *window, int width, int height);
6969
static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers);
7070
static void onMouseMove(GLFWwindow *window, double x, double y);
71+
static void onWindowFocus(GLFWwindow *window, int focused);
7172

7273
// Internal
7374
void report(float duration);

0 commit comments

Comments
 (0)