[core] use raii to guard backend deactivation

This commit is contained in:
Ivo van Dongen
2016-12-06 17:24:32 +01:00
committed by Ivo van Dongen
parent ffd74c309e
commit c76a933514
4 changed files with 37 additions and 28 deletions

View File

@@ -147,7 +147,7 @@ Map::Impl::Impl(Map& map_,
}
Map::~Map() {
impl->backend.activate();
BackendScope guard(impl->backend);
impl->styleRequest = nullptr;
@@ -156,8 +156,6 @@ Map::~Map() {
impl->style.reset();
impl->annotationManager.reset();
impl->painter.reset();
impl->backend.deactivate();
}
void Map::renderStill(View& view, StillImageCallback callback) {
@@ -282,9 +280,8 @@ void Map::Impl::update() {
backend.invalidate();
} else if (stillImageRequest && style->isLoaded()) {
// TODO: determine whether we need activate/deactivate
backend.activate();
BackendScope guard(backend);
render(stillImageRequest->view);
backend.deactivate();
}
updateFlags = Update::Nothing;
@@ -882,12 +879,10 @@ void Map::addLayer(std::unique_ptr<Layer> layer, const optional<std::string>& be
}
impl->styleMutated = true;
impl->backend.activate();
BackendScope guard(impl->backend);
impl->style->addLayer(std::move(layer), before);
impl->onUpdate(Update::Classes);
impl->backend.deactivate();
}
std::unique_ptr<Layer> Map::removeLayer(const std::string& id) {
@@ -896,13 +891,11 @@ std::unique_ptr<Layer> Map::removeLayer(const std::string& id) {
}
impl->styleMutated = true;
impl->backend.activate();
BackendScope guard(impl->backend);
auto removedLayer = impl->style->removeLayer(id);
impl->onUpdate(Update::Classes);
impl->backend.deactivate();
return removedLayer;
}
@@ -1060,9 +1053,8 @@ void Map::setSourceTileCacheSize(size_t size) {
void Map::onLowMemory() {
if (impl->painter) {
impl->backend.activate();
BackendScope guard(impl->backend);
impl->painter->cleanup();
impl->backend.deactivate();
}
if (impl->style) {
impl->style->onLowMemory();