summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-12-04 15:19:12 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-12-07 11:19:08 -0800
commit0a0007e0acdce85576857bec76e1333d771472f1 (patch)
tree07b0ecc27aa064332c989e50dcd2b4bf8942b8ad
parentfc0c839fc87088a9e3a3c0b6bd031544162b6ebf (diff)
downloadqtlocation-mapboxgl-0a0007e0acdce85576857bec76e1333d771472f1.tar.gz
[core] More efficient layer cloning
-rw-r--r--src/mbgl/layer/background_layer.cpp5
-rw-r--r--src/mbgl/layer/circle_layer.cpp5
-rw-r--r--src/mbgl/layer/fill_layer.cpp5
-rw-r--r--src/mbgl/layer/line_layer.cpp6
-rw-r--r--src/mbgl/layer/raster_layer.cpp5
-rw-r--r--src/mbgl/layer/symbol_layer.cpp7
-rw-r--r--src/mbgl/style/paint_property.hpp16
-rw-r--r--src/mbgl/style/style_layer.cpp12
-rw-r--r--src/mbgl/style/style_layer.hpp8
-rw-r--r--test/style/style_layer.cpp24
-rw-r--r--test/test.gypi1
11 files changed, 41 insertions, 53 deletions
diff --git a/src/mbgl/layer/background_layer.cpp b/src/mbgl/layer/background_layer.cpp
index f3ea723b33..cea4c2c9b9 100644
--- a/src/mbgl/layer/background_layer.cpp
+++ b/src/mbgl/layer/background_layer.cpp
@@ -4,10 +4,7 @@
namespace mbgl {
std::unique_ptr<StyleLayer> BackgroundLayer::clone() const {
- std::unique_ptr<BackgroundLayer> result = std::make_unique<BackgroundLayer>();
- result->copy(*this);
- result->paint = paint;
- return std::move(result);
+ return std::make_unique<BackgroundLayer>(*this);
}
void BackgroundLayer::parsePaints(const JSVal& layer) {
diff --git a/src/mbgl/layer/circle_layer.cpp b/src/mbgl/layer/circle_layer.cpp
index 7559a03284..9001723439 100644
--- a/src/mbgl/layer/circle_layer.cpp
+++ b/src/mbgl/layer/circle_layer.cpp
@@ -5,10 +5,7 @@
namespace mbgl {
std::unique_ptr<StyleLayer> CircleLayer::clone() const {
- std::unique_ptr<CircleLayer> result = std::make_unique<CircleLayer>();
- result->copy(*this);
- result->paint = paint;
- return std::move(result);
+ return std::make_unique<CircleLayer>(*this);
}
void CircleLayer::parsePaints(const JSVal& layer) {
diff --git a/src/mbgl/layer/fill_layer.cpp b/src/mbgl/layer/fill_layer.cpp
index c2b9227558..cde5c26837 100644
--- a/src/mbgl/layer/fill_layer.cpp
+++ b/src/mbgl/layer/fill_layer.cpp
@@ -5,10 +5,7 @@
namespace mbgl {
std::unique_ptr<StyleLayer> FillLayer::clone() const {
- std::unique_ptr<FillLayer> result = std::make_unique<FillLayer>();
- result->copy(*this);
- result->paint = paint;
- return std::move(result);
+ return std::make_unique<FillLayer>(*this);
}
void FillLayer::parsePaints(const JSVal& layer) {
diff --git a/src/mbgl/layer/line_layer.cpp b/src/mbgl/layer/line_layer.cpp
index 1e25ed30cb..136721fb01 100644
--- a/src/mbgl/layer/line_layer.cpp
+++ b/src/mbgl/layer/line_layer.cpp
@@ -6,11 +6,7 @@
namespace mbgl {
std::unique_ptr<StyleLayer> LineLayer::clone() const {
- std::unique_ptr<LineLayer> result = std::make_unique<LineLayer>();
- result->copy(*this);
- result->layout = layout;
- result->paint = paint;
- return std::move(result);
+ return std::make_unique<LineLayer>(*this);
}
void LineLayer::parseLayout(const JSVal& value) {
diff --git a/src/mbgl/layer/raster_layer.cpp b/src/mbgl/layer/raster_layer.cpp
index 87199f24f7..3ce9ed36e8 100644
--- a/src/mbgl/layer/raster_layer.cpp
+++ b/src/mbgl/layer/raster_layer.cpp
@@ -4,10 +4,7 @@
namespace mbgl {
std::unique_ptr<StyleLayer> RasterLayer::clone() const {
- std::unique_ptr<RasterLayer> result = std::make_unique<RasterLayer>();
- result->copy(*this);
- result->paint = paint;
- return std::move(result);
+ return std::make_unique<RasterLayer>(*this);
}
void RasterLayer::parsePaints(const JSVal& layer) {
diff --git a/src/mbgl/layer/symbol_layer.cpp b/src/mbgl/layer/symbol_layer.cpp
index c7b4824deb..dd810941d9 100644
--- a/src/mbgl/layer/symbol_layer.cpp
+++ b/src/mbgl/layer/symbol_layer.cpp
@@ -6,12 +6,7 @@
namespace mbgl {
std::unique_ptr<StyleLayer> SymbolLayer::clone() const {
- std::unique_ptr<SymbolLayer> result = std::make_unique<SymbolLayer>();
- result->copy(*this);
- result->layout = layout;
- result->paint = paint;
- result->spriteAtlas = spriteAtlas;
- return std::move(result);
+ return std::make_unique<SymbolLayer>(*this);
}
void SymbolLayer::parseLayout(const JSVal& value) {
diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp
index 710ce34a4f..f6ab430ed9 100644
--- a/src/mbgl/style/paint_property.hpp
+++ b/src/mbgl/style/paint_property.hpp
@@ -8,6 +8,7 @@
#include <mbgl/style/style_cascade_parameters.hpp>
#include <mbgl/style/style_calculation_parameters.hpp>
#include <mbgl/util/interpolate.hpp>
+#include <mbgl/util/std.hpp>
#include <rapidjson/document.h>
@@ -23,9 +24,8 @@ class PaintProperty {
public:
using Fn = Function<Result>;
- PaintProperty(T fallbackValue_)
- : fallbackValue(fallbackValue_),
- value(fallbackValue_) {
+ PaintProperty(T fallbackValue)
+ : value(fallbackValue) {
values.emplace(ClassID::Fallback, Fn(fallbackValue));
}
@@ -34,14 +34,8 @@ public:
transitions(other.transitions) {
}
- void operator=(const PaintProperty& other) {
- values = other.values;
- transitions = other.transitions;
- }
-
void parse(const char* name, const JSVal& layer) {
- values.clear();
- values.emplace(ClassID::Fallback, Fn(fallbackValue));
+ mbgl::util::erase_if(values, [] (const auto& p) { return p.first != ClassID::Fallback; });
std::string transitionName = { name };
transitionName += "-transition";
@@ -104,9 +98,9 @@ public:
return cascaded->prior.operator bool();
}
+ void operator=(const T& v) { values.emplace(ClassID::Default, Fn(v)); }
operator T() const { return value; }
- T fallbackValue;
std::map<ClassID, Fn> values;
std::map<ClassID, PropertyTransition> transitions;
diff --git a/src/mbgl/style/style_layer.cpp b/src/mbgl/style/style_layer.cpp
index 3220a018a7..4c8503b436 100644
--- a/src/mbgl/style/style_layer.cpp
+++ b/src/mbgl/style/style_layer.cpp
@@ -35,16 +35,4 @@ bool StyleLayer::hasRenderPass(RenderPass pass) const {
return bool(passes & pass);
}
-void StyleLayer::copy(const StyleLayer& src) {
- id = src.id;
- ref = src.ref;
- type = src.type;
- source = src.source;
- sourceLayer = src.sourceLayer;
- filter = src.filter;
- minZoom = src.minZoom;
- maxZoom = src.maxZoom;
- visibility = src.visibility;
-}
-
} // namespace mbgl
diff --git a/src/mbgl/style/style_layer.hpp b/src/mbgl/style/style_layer.hpp
index ec29cc6790..49c3355f6e 100644
--- a/src/mbgl/style/style_layer.hpp
+++ b/src/mbgl/style/style_layer.hpp
@@ -21,7 +21,7 @@ class Bucket;
using JSVal = rapidjson::Value;
-class StyleLayer : public util::noncopyable {
+class StyleLayer {
public:
static std::unique_ptr<StyleLayer> create(StyleLayerType);
virtual std::unique_ptr<StyleLayer> clone() const = 0;
@@ -58,11 +58,13 @@ public:
VisibilityType visibility = VisibilityType::Visible;
protected:
+ StyleLayer() = default;
+ StyleLayer(const StyleLayer&) = default;
+ StyleLayer& operator=(const StyleLayer&) = delete;
+
// Stores what render passes this layer is currently enabled for. This depends on the
// evaluated StyleProperties object and is updated accordingly.
RenderPass passes = RenderPass::None;
-
- void copy(const StyleLayer& source);
};
} // namespace mbgl
diff --git a/test/style/style_layer.cpp b/test/style/style_layer.cpp
new file mode 100644
index 0000000000..d005371fef
--- /dev/null
+++ b/test/style/style_layer.cpp
@@ -0,0 +1,24 @@
+#include "../fixtures/util.hpp"
+
+#include <mbgl/style/style_layer.hpp>
+#include <mbgl/layer/background_layer.hpp>
+
+using namespace mbgl;
+
+TEST(StyleLayer, Create) {
+ std::unique_ptr<StyleLayer> layer = StyleLayer::create(StyleLayerType::Background);
+ EXPECT_TRUE(reinterpret_cast<BackgroundLayer*>(layer.get()));
+}
+
+TEST(StyleLayer, Clone) {
+ std::unique_ptr<StyleLayer> layer = StyleLayer::create(StyleLayerType::Background);
+ std::unique_ptr<StyleLayer> clone = layer->clone();
+ EXPECT_NE(layer.get(), clone.get());
+ EXPECT_TRUE(reinterpret_cast<BackgroundLayer*>(layer.get()));
+}
+
+TEST(StyleLayer, CloneCopiesBaseProperties) {
+ std::unique_ptr<BackgroundLayer> layer = std::make_unique<BackgroundLayer>();
+ layer->id = "test";
+ EXPECT_EQ("test", layer->clone()->id);
+}
diff --git a/test/test.gypi b/test/test.gypi
index 708b89e74f..2188ed905a 100644
--- a/test/test.gypi
+++ b/test/test.gypi
@@ -91,6 +91,7 @@
'style/glyph_store.cpp',
'style/pending_resources.cpp',
'style/resource_loading.cpp',
+ 'style/style_layer.cpp',
'sprite/sprite_atlas.cpp',
'sprite/sprite_image.cpp',