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
|
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 setting global alignment of polygon pattern fills (#203)
|
||||||
|
|
||||||
- Added support for choosing OGR layer by index number using 'layer_by_index' parameter (r1904)
|
- 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,
|
proj_transform(projection const& source,
|
||||||
projection const& dest);
|
projection const& dest);
|
||||||
|
|
||||||
|
bool equal() const;
|
||||||
bool forward (double& x, double& y , double& z) const;
|
bool forward (double& x, double& y , double& z) const;
|
||||||
bool backward (double& x, double& y , double& z) const;
|
bool backward (double& x, double& y , double& z) const;
|
||||||
mapnik::projection const& source() const;
|
mapnik::projection const& source() const;
|
||||||
|
@ -48,7 +49,7 @@ private:
|
||||||
projection const& dest_;
|
projection const& dest_;
|
||||||
bool is_source_latlong_;
|
bool is_source_latlong_;
|
||||||
bool is_dest_latlong_;
|
bool is_dest_latlong_;
|
||||||
bool is_source_equal_dest;
|
bool is_source_equal_dest_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@ private:
|
||||||
private:
|
private:
|
||||||
std::string params_;
|
std::string params_;
|
||||||
void * proj_;
|
void * proj_;
|
||||||
|
bool is_geographic_;
|
||||||
#ifdef MAPNIK_THREADSAFE
|
#ifdef MAPNIK_THREADSAFE
|
||||||
static boost::mutex mutex_;
|
static boost::mutex mutex_;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,20 +35,19 @@ proj_transform::proj_transform(projection const& source,
|
||||||
: source_(source),
|
: source_(source),
|
||||||
dest_(dest)
|
dest_(dest)
|
||||||
{
|
{
|
||||||
#ifdef MAPNIK_THREADSAFE
|
is_source_latlong_ = source_.is_geographic();
|
||||||
mutex::scoped_lock lock(projection::mutex_);
|
is_dest_latlong_ = dest_.is_geographic();
|
||||||
#endif
|
is_source_equal_dest_ = (source_ == dest_);
|
||||||
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_);
|
bool proj_transform::equal() const
|
||||||
|
{
|
||||||
|
return is_source_equal_dest_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool proj_transform::forward (double & x, double & y , double & z) const
|
bool proj_transform::forward (double & x, double & y , double & z) const
|
||||||
{
|
{
|
||||||
#ifdef MAPNIK_THREADSAFE
|
if (is_source_equal_dest_)
|
||||||
mutex::scoped_lock lock(projection::mutex_);
|
|
||||||
#endif
|
|
||||||
if (is_source_equal_dest)
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (is_source_latlong_)
|
if (is_source_latlong_)
|
||||||
|
@ -57,6 +56,10 @@ bool proj_transform::forward (double & x, double & y , double & z) const
|
||||||
y *= 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,
|
if (pj_transform( source_.proj_, dest_.proj_, 1,
|
||||||
0, &x,&y,&z) != 0)
|
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
|
bool proj_transform::backward (double & x, double & y , double & z) const
|
||||||
{
|
{
|
||||||
#ifdef MAPNIK_THREADSAFE
|
if (is_source_equal_dest_)
|
||||||
mutex::scoped_lock lock(projection::mutex_);
|
|
||||||
#endif
|
|
||||||
if (is_source_equal_dest)
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (is_dest_latlong_)
|
if (is_dest_latlong_)
|
||||||
|
@ -86,6 +86,10 @@ bool proj_transform::backward (double & x, double & y , double & z) const
|
||||||
y *= DEG_TO_RAD;
|
y *= DEG_TO_RAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MAPNIK_THREADSAFE
|
||||||
|
mutex::scoped_lock lock(projection::mutex_);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (pj_transform( dest_.proj_, source_.proj_, 1,
|
if (pj_transform( dest_.proj_, source_.proj_, 1,
|
||||||
0, &x,&y,&z) != 0)
|
0, &x,&y,&z) != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -70,10 +70,7 @@ bool projection::is_initialized() const
|
||||||
|
|
||||||
bool projection::is_geographic() const
|
bool projection::is_geographic() const
|
||||||
{
|
{
|
||||||
#ifdef MAPNIK_THREADSAFE
|
return is_geographic_;
|
||||||
mutex::scoped_lock lock(mutex_);
|
|
||||||
#endif
|
|
||||||
return pj_is_latlong(proj_) ? true : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const& projection::params() const
|
std::string const& projection::params() const
|
||||||
|
@ -92,7 +89,7 @@ void projection::forward(double & x, double &y ) const
|
||||||
p = pj_fwd(p,proj_);
|
p = pj_fwd(p,proj_);
|
||||||
x = p.u;
|
x = p.u;
|
||||||
y = p.v;
|
y = p.v;
|
||||||
if (pj_is_latlong(proj_))
|
if (is_geographic_)
|
||||||
{
|
{
|
||||||
x *=RAD_TO_DEG;
|
x *=RAD_TO_DEG;
|
||||||
y *=RAD_TO_DEG;
|
y *=RAD_TO_DEG;
|
||||||
|
@ -104,7 +101,7 @@ void projection::inverse(double & x,double & y) const
|
||||||
#ifdef MAPNIK_THREADSAFE
|
#ifdef MAPNIK_THREADSAFE
|
||||||
mutex::scoped_lock lock(mutex_);
|
mutex::scoped_lock lock(mutex_);
|
||||||
#endif
|
#endif
|
||||||
if (pj_is_latlong(proj_))
|
if (is_geographic_)
|
||||||
{
|
{
|
||||||
x *=DEG_TO_RAD;
|
x *=DEG_TO_RAD;
|
||||||
y *=DEG_TO_RAD;
|
y *=DEG_TO_RAD;
|
||||||
|
@ -127,11 +124,13 @@ projection::~projection()
|
||||||
|
|
||||||
void projection::init()
|
void projection::init()
|
||||||
{
|
{
|
||||||
#ifdef MAPNIK_THREADSAFE
|
// http://trac.osgeo.org/proj/wiki/ThreadSafety
|
||||||
|
#if PJ_VERSION < 470 && MAPNIK_THREADSAFE
|
||||||
mutex::scoped_lock lock(mutex_);
|
mutex::scoped_lock lock(mutex_);
|
||||||
#endif
|
#endif
|
||||||
proj_=pj_init_plus(params_.c_str());
|
proj_=pj_init_plus(params_.c_str());
|
||||||
if (!proj_) throw proj_init_error(params_);
|
if (!proj_) throw proj_init_error(params_);
|
||||||
|
is_geographic_ = pj_is_latlong(proj_) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void projection::swap (projection& rhs)
|
void projection::swap (projection& rhs)
|
||||||
|
|
Loading…
Reference in a new issue