From 217d18a996cd6a377720b6c6a050124e12cb8cd9 Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Thu, 16 Jun 2016 22:34:24 +0200 Subject: [PATCH 1/3] use std::deque to store svg::path_attributes - refs #3453 --- include/mapnik/cairo/cairo_render_vector.hpp | 11 ++------ include/mapnik/marker.hpp | 3 +- include/mapnik/marker_helpers.hpp | 4 +-- include/mapnik/svg/svg_converter.hpp | 29 ++++++++++++-------- include/mapnik/svg/svg_renderer_agg.hpp | 4 +-- src/agg/agg_renderer.cpp | 13 ++++----- src/agg/process_group_symbolizer.cpp | 9 +++--- src/agg/process_markers_symbolizer.cpp | 10 +++---- src/cairo/cairo_render_vector.cpp | 8 ++---- src/cairo/cairo_renderer.cpp | 2 +- src/grid/grid_renderer.cpp | 12 ++++---- src/grid/process_group_symbolizer.cpp | 13 ++++----- src/grid/process_markers_symbolizer.cpp | 11 +++----- src/marker_helpers.cpp | 2 +- src/renderer_common/render_pattern.cpp | 13 ++++----- src/svg/svg_parser.cpp | 3 +- 16 files changed, 65 insertions(+), 82 deletions(-) diff --git a/include/mapnik/cairo/cairo_render_vector.hpp b/include/mapnik/cairo/cairo_render_vector.hpp index 37bd44925..e5d06684d 100644 --- a/include/mapnik/cairo/cairo_render_vector.hpp +++ b/include/mapnik/cairo/cairo_render_vector.hpp @@ -26,19 +26,14 @@ #define MAPNIK_CAIRO_RENDER_VECTOR_HPP // mapnik -#include - -namespace agg { struct trans_affine; } +#include namespace mapnik { class cairo_context; -struct pixel_position; -template class box2d; -namespace svg { struct path_attributes; } -void render_vector_marker(cairo_context & context, svg::svg_path_adapter & svg_path, - agg::pod_bvector const & attributes, +void render_vector_marker(cairo_context & context, svg_path_adapter & svg_path, + svg_attribute_type const& attributes, box2d const& bbox, agg::trans_affine const& tr, double opacity); diff --git a/include/mapnik/marker.hpp b/include/mapnik/marker.hpp index 1feb0fecf..ee24871bd 100644 --- a/include/mapnik/marker.hpp +++ b/include/mapnik/marker.hpp @@ -35,6 +35,7 @@ #pragma GCC diagnostic pop // stl +#include #include namespace mapnik @@ -45,7 +46,7 @@ namespace svg { struct path_attributes; } using svg::svg_path_adapter; -using svg_attribute_type = agg::pod_bvector; +using svg_attribute_type = std::deque; using svg_storage_type = svg::svg_storage; using svg_path_ptr = std::shared_ptr; using image_ptr = std::shared_ptr; diff --git a/include/mapnik/marker_helpers.hpp b/include/mapnik/marker_helpers.hpp index 8ba3c6f4b..de62b3b2e 100644 --- a/include/mapnik/marker_helpers.hpp +++ b/include/mapnik/marker_helpers.hpp @@ -29,7 +29,7 @@ #include #include #include -#include // for svg_storage_type +#include // svg_attribute_type, svg_storage_type #include #include #include @@ -50,8 +50,6 @@ namespace mapnik { struct clip_poly_tag; -using svg_attribute_type = agg::pod_bvector; - template struct vector_markers_dispatch : util::noncopyable { diff --git a/include/mapnik/svg/svg_converter.hpp b/include/mapnik/svg/svg_converter.hpp index 9cf3c9c16..33c698057 100644 --- a/include/mapnik/svg/svg_converter.hpp +++ b/include/mapnik/svg/svg_converter.hpp @@ -41,6 +41,7 @@ #pragma GCC diagnostic pop // stl +#include #include namespace mapnik { @@ -61,16 +62,16 @@ public: void begin_path() { std::size_t idx = source_.start_new_path(); - attributes_.add(path_attributes(cur_attr(), safe_cast(idx))); + attributes_.emplace_back(cur_attr(), safe_cast(idx)); } void end_path() { - if(attributes_.size() == 0) + if (attributes_.empty()) { throw std::runtime_error("end_path : The path was not begun"); } - path_attributes& attr = attributes_[attributes_.size() - 1]; + path_attributes& attr = attributes_.back(); unsigned idx = attr.index; attr = cur_attr(); attr.index = idx; @@ -183,17 +184,19 @@ public: void push_attr() { - attr_stack_.add(attr_stack_.size() ? - attr_stack_[attr_stack_.size() - 1] : - path_attributes()); + if (attr_stack_.empty()) + attr_stack_.push_back(path_attributes()); + else + attr_stack_.push_back(attr_stack_.back()); } + void pop_attr() { - if(attr_stack_.size() == 0) + if (attr_stack_.empty()) { throw std::runtime_error("pop_attr : Attribute stack is empty"); } - attr_stack_.remove_last(); + attr_stack_.pop_back(); } // Attribute setting functions. @@ -226,15 +229,18 @@ public: attr.stroke_color.opacity(a * s.opacity()); attr.stroke_flag = true; } + void dash_array(dash_array && dash) { path_attributes& attr = cur_attr(); attr.dash = std::move(dash); } + void dash_offset(double offset) { cur_attr().dash_offset = offset; } + void even_odd(bool flag) { cur_attr().even_odd_flag = flag; @@ -264,6 +270,7 @@ public: { cur_attr().stroke_width = w; } + void fill_none() { cur_attr().fill_none = true; @@ -352,11 +359,11 @@ public: path_attributes& cur_attr() { - if(attr_stack_.size() == 0) + if (attr_stack_.empty()) { throw std::runtime_error("cur_attr : Attribute stack is empty"); } - return attr_stack_[attr_stack_.size() - 1]; + return attr_stack_.back(); } private: @@ -370,7 +377,7 @@ private: }; -using svg_converter_type = svg_converter >; +using svg_converter_type = svg_converter >; }} diff --git a/include/mapnik/svg/svg_renderer_agg.hpp b/include/mapnik/svg/svg_renderer_agg.hpp index d99575b4d..44d5c093c 100644 --- a/include/mapnik/svg/svg_renderer_agg.hpp +++ b/include/mapnik/svg/svg_renderer_agg.hpp @@ -103,7 +103,7 @@ private: }; template -class svg_renderer_agg : util::noncopyable +class renderer_agg : util::noncopyable { public: using curved_type = agg::conv_curve; @@ -122,7 +122,7 @@ public: using vertex_source_type = VertexSource; using attribute_source_type = AttributeSource; - svg_renderer_agg(VertexSource & source, AttributeSource const& attributes) + renderer_agg(VertexSource & source, AttributeSource const& attributes) : source_(source), curved_(source_), curved_dashed_(curved_), diff --git a/src/agg/agg_renderer.cpp b/src/agg/agg_renderer.cpp index f144ceaad..1cf58d85a 100644 --- a/src/agg/agg_renderer.cpp +++ b/src/agg/agg_renderer.cpp @@ -376,7 +376,6 @@ struct agg_render_marker_visitor using pixfmt_comp_type = agg::pixfmt_custom_blend_rgba; using renderer_base = agg::renderer_base; using renderer_type = agg::renderer_scanline_aa_solid; - using svg_attribute_type = agg::pod_bvector; ras_ptr_->reset(); if (gamma_method_ != GAMMA_POWER || gamma_ != 1.0) @@ -403,14 +402,12 @@ struct agg_render_marker_visitor mtx *= agg::trans_affine_scaling(common_.scale_factor_); // render the marker at the center of the marker box mtx.translate(pos_.x, pos_.y); - using namespace mapnik::svg; - vertex_stl_adapter stl_storage(marker.get_data()->source()); + svg::vertex_stl_adapter stl_storage(marker.get_data()->source()); svg_path_adapter svg_path(stl_storage); - svg_renderer_agg svg_renderer(svg_path, - marker.get_data()->attributes()); + svg::renderer_agg svg_renderer(svg_path, marker.get_data()->attributes()); // https://github.com/mapnik/mapnik/issues/1316 // https://github.com/mapnik/mapnik/issues/1866 diff --git a/src/agg/process_group_symbolizer.cpp b/src/agg/process_group_symbolizer.cpp index 6ba5605dc..2e97797dc 100644 --- a/src/agg/process_group_symbolizer.cpp +++ b/src/agg/process_group_symbolizer.cpp @@ -75,11 +75,10 @@ struct thunk_renderer : render_thunk_list_dispatch using pixfmt_comp_type = agg::pixfmt_custom_blend_rgba; using renderer_base = agg::renderer_base; using renderer_type = agg::renderer_scanline_aa_solid; - using svg_attribute_type = agg::pod_bvector; - using svg_renderer_type = svg::svg_renderer_agg; + using svg_renderer_type = svg::renderer_agg; ras_ptr_->reset(); buf_type render_buffer(buf_->bytes(), buf_->width(), buf_->height(), buf_->row_size()); pixfmt_comp_type pixf(render_buffer); diff --git a/src/agg/process_markers_symbolizer.cpp b/src/agg/process_markers_symbolizer.cpp index 3fc122dcb..7f674a5d7 100644 --- a/src/agg/process_markers_symbolizer.cpp +++ b/src/agg/process_markers_symbolizer.cpp @@ -109,7 +109,6 @@ void agg_renderer::process(markers_symbolizer const& sym, feature_impl & feature, proj_transform const& prj_trans) { - using namespace mapnik::svg; using color_type = agg::rgba8; using order_type = agg::order_rgba; using blender_type = agg::comp_op_adaptor_rgba_pre; // comp blender @@ -117,11 +116,10 @@ void agg_renderer::process(markers_symbolizer const& sym, using pixfmt_comp_type = agg::pixfmt_custom_blend_rgba; using renderer_base = agg::renderer_base; using renderer_type = agg::renderer_scanline_aa_solid; - using svg_attribute_type = agg::pod_bvector; - using svg_renderer_type = svg_renderer_agg; + using svg_renderer_type = svg::renderer_agg; ras_ptr->reset(); diff --git a/src/cairo/cairo_render_vector.cpp b/src/cairo/cairo_render_vector.cpp index 160002dd2..7881367e3 100644 --- a/src/cairo/cairo_render_vector.cpp +++ b/src/cairo/cairo_render_vector.cpp @@ -32,17 +32,15 @@ namespace mapnik { -void render_vector_marker(cairo_context & context, svg::svg_path_adapter & svg_path, - agg::pod_bvector const & attributes, +void render_vector_marker(cairo_context & context, svg_path_adapter & svg_path, + svg_attribute_type const& attributes, box2d const& bbox, agg::trans_affine const& tr, double opacity) { - using namespace mapnik::svg; agg::trans_affine transform; - for(unsigned i = 0; i < attributes.size(); ++i) + for (auto const& attr : attributes) { - mapnik::svg::path_attributes const& attr = attributes[i]; if (!attr.visibility_flag) continue; cairo_save_restore guard(context); diff --git a/src/cairo/cairo_renderer.cpp b/src/cairo/cairo_renderer.cpp index 83e1208b1..34b4659fe 100644 --- a/src/cairo/cairo_renderer.cpp +++ b/src/cairo/cairo_renderer.cpp @@ -233,7 +233,7 @@ struct cairo_render_marker_visitor marker_tr *= tr_; } marker_tr *= agg::trans_affine_scaling(common_.scale_factor_); - agg::pod_bvector const & attributes = vmarker->attributes(); + auto const& attributes = vmarker->attributes(); svg::vertex_stl_adapter stl_storage(vmarker->source()); svg::svg_path_adapter svg_path(stl_storage); marker_tr.translate(pos_.x, pos_.y); diff --git a/src/grid/grid_renderer.cpp b/src/grid/grid_renderer.cpp index fd970f580..13e6cf526 100644 --- a/src/grid/grid_renderer.cpp +++ b/src/grid/grid_renderer.cpp @@ -172,14 +172,12 @@ struct grid_render_marker_visitor mtx *= agg::trans_affine_scaling(common_.scale_factor_); // render the marker at the center of the marker box mtx.translate(pos_.x, pos_.y); - using namespace mapnik::svg; - vertex_stl_adapter stl_storage(marker.get_data()->source()); + svg::vertex_stl_adapter stl_storage(marker.get_data()->source()); svg_path_adapter svg_path(stl_storage); - svg_renderer_agg, - renderer_type, - pixfmt_type> svg_renderer(svg_path, - marker.get_data()->attributes()); + svg::renderer_agg svg_renderer(svg_path, marker.get_data()->attributes()); svg_renderer.render_id(*ras_ptr_, sl, renb, feature_.id(), mtx, opacity_, bbox); } diff --git a/src/grid/process_group_symbolizer.cpp b/src/grid/process_group_symbolizer.cpp index ba7f48ece..2ecebf5f7 100644 --- a/src/grid/process_group_symbolizer.cpp +++ b/src/grid/process_group_symbolizer.cpp @@ -72,20 +72,17 @@ struct thunk_renderer : render_thunk_list_dispatch using buf_type = grid_rendering_buffer; using pixfmt_type = typename grid_renderer_base_type::pixfmt_type; using renderer_type = agg::renderer_scanline_bin_solid; - - using namespace mapnik::svg; - using svg_attribute_type = agg::pod_bvector; - using svg_renderer_type = svg_renderer_agg; + using svg_renderer_type = svg::renderer_agg; buf_type render_buf(pixmap_.raw_data(), common_.width_, common_.height_, common_.width_); ras_.reset(); pixfmt_type pixf(render_buf); grid_renderer_base_type renb(pixf); renderer_type ren(renb); - vertex_stl_adapter stl_storage(thunk.src_->source()); + svg::vertex_stl_adapter stl_storage(thunk.src_->source()); svg_path_adapter svg_path(stl_storage); svg_renderer_type svg_renderer(svg_path, thunk.attrs_); agg::trans_affine offset_tr = thunk.tr_; diff --git a/src/grid/process_markers_symbolizer.cpp b/src/grid/process_markers_symbolizer.cpp index 380923211..e0157dcd2 100644 --- a/src/grid/process_markers_symbolizer.cpp +++ b/src/grid/process_markers_symbolizer.cpp @@ -141,13 +141,10 @@ void grid_renderer::process(markers_symbolizer const& sym, using buf_type = grid_rendering_buffer; using pixfmt_type = typename grid_renderer_base_type::pixfmt_type; using renderer_type = agg::renderer_scanline_bin_solid; - - using namespace mapnik::svg; - using svg_attribute_type = agg::pod_bvector; - using svg_renderer_type = svg_renderer_agg; + using svg_renderer_type = svg::renderer_agg; buf_type render_buf(pixmap_.raw_data(), common_.width_, common_.height_, common_.width_); ras_ptr->reset(); diff --git a/src/marker_helpers.cpp b/src/marker_helpers.cpp index eb0202169..89c43e305 100644 --- a/src/marker_helpers.cpp +++ b/src/marker_helpers.cpp @@ -94,7 +94,7 @@ bool push_explicit_style(svg_attribute_type const& src, for(unsigned i = 0; i < src.size(); ++i) { dst.push_back(src[i]); - mapnik::svg::path_attributes & attr = dst.last(); + mapnik::svg::path_attributes & attr = dst.back(); if (!attr.visibility_flag) continue; success = true; diff --git a/src/renderer_common/render_pattern.cpp b/src/renderer_common/render_pattern.cpp index 5e6f95820..5aed4d350 100644 --- a/src/renderer_common/render_pattern.cpp +++ b/src/renderer_common/render_pattern.cpp @@ -62,13 +62,12 @@ void render_pattern(rasterizer & ras, pixfmt pixf(buf); renderer_base renb(pixf); - mapnik::svg::vertex_stl_adapter stl_storage(marker.get_data()->source()); - mapnik::svg::svg_path_adapter svg_path(stl_storage); - mapnik::svg::svg_renderer_agg, - renderer_solid, - pixfmt > svg_renderer(svg_path, - marker.get_data()->attributes()); + svg::vertex_stl_adapter stl_storage(marker.get_data()->source()); + svg_path_adapter svg_path(stl_storage); + svg::renderer_agg svg_renderer(svg_path, marker.get_data()->attributes()); svg_renderer.render(ras, sl, renb, mtx, opacity, bbox); } diff --git a/src/svg/svg_parser.cpp b/src/svg/svg_parser.cpp index 2483bae56..e70f5cd39 100644 --- a/src/svg/svg_parser.cpp +++ b/src/svg/svg_parser.cpp @@ -1046,8 +1046,7 @@ void parse_linear_gradient(svg_parser & parser, rapidxml::xml_node const* parser.gradient_map_[parser.temporary_gradient_.first] = parser.temporary_gradient_.second; } -svg_parser::svg_parser(svg_converter > & path) +svg_parser::svg_parser(svg_converter_type & path) : path_(path), is_defs_(false) {} From fc3d194ad2f547a402a3f7cad18e6c2120d9c42a Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Thu, 16 Jun 2016 23:16:39 +0200 Subject: [PATCH 2/3] missed svg2png when renaming svg_renderer_agg --- utils/svg2png/svg2png.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/svg2png/svg2png.cpp b/utils/svg2png/svg2png.cpp index b78f53b16..334f26691 100644 --- a/utils/svg2png/svg2png.cpp +++ b/utils/svg2png/svg2png.cpp @@ -95,8 +95,9 @@ struct main_marker_visitor mapnik::svg::vertex_stl_adapter stl_storage(marker.get_data()->source()); mapnik::svg::svg_path_adapter svg_path(stl_storage); - mapnik::svg::svg_renderer_agg, + mapnik::svg::renderer_agg< + mapnik::svg_path_adapter, + mapnik::svg_attribute_type, renderer_solid, agg::pixfmt_rgba32_pre > svg_renderer_this(svg_path, marker.get_data()->attributes()); From 8d3c08f3ef4ad726f6f1bdc6394d04a97b85aede Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Fri, 17 Jun 2016 17:09:16 +0200 Subject: [PATCH 3/3] libc++ implementation of std::deque needs T to be complete --- include/mapnik/marker.hpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/include/mapnik/marker.hpp b/include/mapnik/marker.hpp index ee24871bd..9a30ab67c 100644 --- a/include/mapnik/marker.hpp +++ b/include/mapnik/marker.hpp @@ -27,13 +27,9 @@ #include #include #include +#include #include -#pragma GCC diagnostic push -#include -#include "agg_array.h" -#pragma GCC diagnostic pop - // stl #include #include @@ -42,10 +38,8 @@ namespace mapnik { struct image_any; -namespace svg { struct path_attributes; } using svg::svg_path_adapter; - using svg_attribute_type = std::deque; using svg_storage_type = svg::svg_storage; using svg_path_ptr = std::shared_ptr;