Merge branch 'fix-context-shutdown-merge' into libuv-0.10-fix-context-shutdown
Conflicts: src/map/map.cpp
This commit is contained in:
@@ -8,7 +8,10 @@ GLFWView::GLFWView(bool fullscreen) : fullscreen(fullscreen) {
|
||||
#endif
|
||||
}
|
||||
|
||||
GLFWView::~GLFWView() { glfwTerminate(); }
|
||||
GLFWView::~GLFWView() {
|
||||
map->terminate();
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
void GLFWView::initialize(mbgl::Map *map) {
|
||||
View::initialize(map);
|
||||
@@ -192,6 +195,10 @@ void GLFWView::make_active() {
|
||||
glfwMakeContextCurrent(window);
|
||||
}
|
||||
|
||||
void GLFWView::make_inactive() {
|
||||
glfwMakeContextCurrent(nullptr);
|
||||
}
|
||||
|
||||
void GLFWView::swap() {
|
||||
glfwPostEmptyEvent();
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
void initialize(mbgl::Map *map);
|
||||
void swap();
|
||||
void make_active();
|
||||
void make_inactive();
|
||||
void notify_map_change(mbgl::MapChange change, mbgl::timestamp delay = 0);
|
||||
|
||||
static void key(GLFWwindow *window, int key, int scancode, int action, int mods);
|
||||
|
||||
@@ -181,6 +181,19 @@ void HeadlessView::make_active() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void HeadlessView::make_inactive() {
|
||||
#if MBGL_USE_CGL
|
||||
CGLError error = CGLSetCurrentContext(nullptr);
|
||||
if (error) {
|
||||
fprintf(stderr, "Removing OpenGL context failed\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MBGL_USE_GLX
|
||||
// no-op
|
||||
#endif
|
||||
}
|
||||
|
||||
void HeadlessView::swap() {}
|
||||
|
||||
unsigned int HeadlessView::root_fbo() {
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
|
||||
void notify_map_change(MapChange change, timestamp delay = 0);
|
||||
void make_active();
|
||||
void make_inactive();
|
||||
void swap();
|
||||
unsigned int root_fbo();
|
||||
|
||||
|
||||
@@ -53,6 +53,9 @@ public:
|
||||
// Triggers a cleanup that releases resources.
|
||||
void cleanup();
|
||||
|
||||
// Releases resources immediately
|
||||
void terminate();
|
||||
|
||||
// Controls buffer swapping.
|
||||
bool needsSwap();
|
||||
void swapped();
|
||||
|
||||
@@ -35,6 +35,10 @@ public:
|
||||
// renderer setup since the render thread doesn't switch the contexts.
|
||||
virtual void make_active() = 0;
|
||||
|
||||
// Called from the render thread. Makes the GL context inactive in the current
|
||||
// thread. This is called once just before the rendering thread terminates.
|
||||
virtual void make_inactive() = 0;
|
||||
|
||||
// Returns the base framebuffer object, if any, and 0 if using the system
|
||||
// provided framebuffer.
|
||||
virtual unsigned int root_fbo() {
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
// lazy initialization) in case rendering continues.
|
||||
void cleanup();
|
||||
|
||||
void terminate();
|
||||
|
||||
// Renders the backdrop of the OpenGL view. This also paints in areas where we don't have any
|
||||
// tiles whatsoever.
|
||||
@@ -123,6 +124,7 @@ public:
|
||||
|
||||
private:
|
||||
void setupShaders();
|
||||
void deleteShaders();
|
||||
mat4 translatedMatrix(const mat4& matrix, const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchorType anchor);
|
||||
|
||||
void prepareTile(const Tile& tile);
|
||||
|
||||
@@ -114,6 +114,8 @@ void Map::run() {
|
||||
prepare();
|
||||
render();
|
||||
}
|
||||
|
||||
view.make_inactive();
|
||||
}
|
||||
|
||||
void Map::rerender() {
|
||||
@@ -151,6 +153,11 @@ void Map::cleanup(uv_async_t *async, int status) {
|
||||
map->painter.cleanup();
|
||||
}
|
||||
|
||||
void Map::terminate() {
|
||||
view.make_active();
|
||||
painter.terminate();
|
||||
}
|
||||
|
||||
void Map::render(uv_async_t *async, int status) {
|
||||
Map *map = static_cast<Map *>(async->data);
|
||||
|
||||
|
||||
@@ -82,9 +82,28 @@ void Painter::setupShaders() {
|
||||
if (!gaussianShader) gaussianShader = std::make_unique<GaussianShader>();
|
||||
}
|
||||
|
||||
void Painter::deleteShaders() {
|
||||
plainShader = nullptr;
|
||||
outlineShader = nullptr;
|
||||
lineShader = nullptr;
|
||||
linejoinShader = nullptr;
|
||||
patternShader = nullptr;
|
||||
iconShader = nullptr;
|
||||
rasterShader = nullptr;
|
||||
textShader = nullptr;
|
||||
dotShader = nullptr;
|
||||
compositeShader = nullptr;
|
||||
gaussianShader = nullptr;
|
||||
}
|
||||
|
||||
void Painter::cleanup() {
|
||||
}
|
||||
|
||||
void Painter::terminate() {
|
||||
cleanup();
|
||||
deleteShaders();
|
||||
}
|
||||
|
||||
void Painter::resize() {
|
||||
const TransformState &state = map.getState();
|
||||
if (gl_viewport != state.getFramebufferDimensions()) {
|
||||
|
||||
Reference in New Issue
Block a user