summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-09 16:29:30 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-09 17:36:10 +0300
commiteaed0036efe04cfaa50218f7041078972427dffb (patch)
treeefa8ef193a77436b6c84f201013ab3c7a4bd1c71 /platform
parent286bc66ba4eef043af1d67858f8f5ec540717f31 (diff)
downloadqtlocation-mapboxgl-eaed0036efe04cfaa50218f7041078972427dffb.tar.gz
[glfw] Reduce memory use when window loses focus
Diffstat (limited to 'platform')
-rw-r--r--platform/glfw/glfw_view.cpp8
-rw-r--r--platform/glfw/glfw_view.hpp1
2 files changed, 9 insertions, 0 deletions
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<GLFWView *>(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);