diff --git a/CHANGELOG b/CHANGELOG index 6b147d243..98fed4b61 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,8 @@ For a complete change history, see the SVN log. Mapnik Trunk ------------ +- Optimized rendering speeds by avoiding locking the projection code (r2063) + - Added support for setting global alignment of polygon pattern fills (#203) - Added support for choosing OGR layer by index number using 'layer_by_index' parameter (r1904) diff --git a/include/mapnik/proj_transform.hpp b/include/mapnik/proj_transform.hpp index 479617284..f2f4dbcab 100644 --- a/include/mapnik/proj_transform.hpp +++ b/include/mapnik/proj_transform.hpp @@ -38,6 +38,7 @@ public: proj_transform(projection const& source, projection const& dest); + bool equal() const; bool forward (double& x, double& y , double& z) const; bool backward (double& x, double& y , double& z) const; mapnik::projection const& source() const; @@ -48,7 +49,7 @@ private: projection const& dest_; bool is_source_latlong_; bool is_dest_latlong_; - bool is_source_equal_dest; + bool is_source_equal_dest_; }; } diff --git a/include/mapnik/projection.hpp b/include/mapnik/projection.hpp index 31f9372d1..a9a78cd1e 100644 --- a/include/mapnik/projection.hpp +++ b/include/mapnik/projection.hpp @@ -73,6 +73,7 @@ private: private: std::string params_; void * proj_; + bool is_geographic_; #ifdef MAPNIK_THREADSAFE static boost::mutex mutex_; #endif diff --git a/src/proj_transform.cpp b/src/proj_transform.cpp index 9b2846be3..44c1179ff 100644 --- a/src/proj_transform.cpp +++ b/src/proj_transform.cpp @@ -35,20 +35,19 @@ proj_transform::proj_transform(projection const& source, : source_(source), dest_(dest) { -#ifdef MAPNIK_THREADSAFE - mutex::scoped_lock lock(projection::mutex_); -#endif - is_source_latlong_ = pj_is_latlong(source_.proj_) ? true : false; - is_dest_latlong_ = pj_is_latlong(dest_.proj_) ? true : false ; - is_source_equal_dest = (source_ == dest_); + is_source_latlong_ = source_.is_geographic(); + is_dest_latlong_ = dest_.is_geographic(); + is_source_equal_dest_ = (source_ == dest_); } - + +bool proj_transform::equal() const +{ + return is_source_equal_dest_; +} + bool proj_transform::forward (double & x, double & y , double & z) const { -#ifdef MAPNIK_THREADSAFE - mutex::scoped_lock lock(projection::mutex_); -#endif - if (is_source_equal_dest) + if (is_source_equal_dest_) return true; if (is_source_latlong_) @@ -56,6 +55,10 @@ bool proj_transform::forward (double & x, double & y , double & z) const x *= DEG_TO_RAD; y *= DEG_TO_RAD; } + +#ifdef MAPNIK_THREADSAFE + mutex::scoped_lock lock(projection::mutex_); +#endif if (pj_transform( source_.proj_, dest_.proj_, 1, 0, &x,&y,&z) != 0) @@ -74,10 +77,7 @@ bool proj_transform::forward (double & x, double & y , double & z) const bool proj_transform::backward (double & x, double & y , double & z) const { -#ifdef MAPNIK_THREADSAFE - mutex::scoped_lock lock(projection::mutex_); -#endif - if (is_source_equal_dest) + if (is_source_equal_dest_) return true; if (is_dest_latlong_) @@ -86,6 +86,10 @@ bool proj_transform::backward (double & x, double & y , double & z) const y *= DEG_TO_RAD; } +#ifdef MAPNIK_THREADSAFE + mutex::scoped_lock lock(projection::mutex_); +#endif + if (pj_transform( dest_.proj_, source_.proj_, 1, 0, &x,&y,&z) != 0) { diff --git a/src/projection.cpp b/src/projection.cpp index 235a5123b..e7f091201 100644 --- a/src/projection.cpp +++ b/src/projection.cpp @@ -70,10 +70,7 @@ bool projection::is_initialized() const bool projection::is_geographic() const { -#ifdef MAPNIK_THREADSAFE - mutex::scoped_lock lock(mutex_); -#endif - return pj_is_latlong(proj_) ? true : false; + return is_geographic_; } std::string const& projection::params() const @@ -92,7 +89,7 @@ void projection::forward(double & x, double &y ) const p = pj_fwd(p,proj_); x = p.u; y = p.v; - if (pj_is_latlong(proj_)) + if (is_geographic_) { x *=RAD_TO_DEG; y *=RAD_TO_DEG; @@ -104,7 +101,7 @@ void projection::inverse(double & x,double & y) const #ifdef MAPNIK_THREADSAFE mutex::scoped_lock lock(mutex_); #endif - if (pj_is_latlong(proj_)) + if (is_geographic_) { x *=DEG_TO_RAD; y *=DEG_TO_RAD; @@ -127,11 +124,13 @@ projection::~projection() void projection::init() { -#ifdef MAPNIK_THREADSAFE +// http://trac.osgeo.org/proj/wiki/ThreadSafety +#if PJ_VERSION < 470 && MAPNIK_THREADSAFE mutex::scoped_lock lock(mutex_); #endif proj_=pj_init_plus(params_.c_str()); if (!proj_) throw proj_init_error(params_); + is_geographic_ = pj_is_latlong(proj_) ? true : false; } void projection::swap (projection& rhs)