speed optimizations by more careful use (or avoidance) of locking around projection code
This commit is contained in:
parent
e4bfdfecf5
commit
f802d21865
5 changed files with 30 additions and 23 deletions
|
@ -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)
|
||||
|
|
|
@ -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_;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ private:
|
|||
private:
|
||||
std::string params_;
|
||||
void * proj_;
|
||||
bool is_geographic_;
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
static boost::mutex mutex_;
|
||||
#endif
|
||||
|
|
|
@ -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_)
|
||||
|
@ -57,6 +56,10 @@ bool proj_transform::forward (double & x, double & y , double & z) const
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue