[mapguide-commits] r1290 - trunk/MgDev/Common/Stylization

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Mar 19 14:25:04 EDT 2007


Author: traianstanev
Date: 2007-03-19 14:25:04 -0400 (Mon, 19 Mar 2007)
New Revision: 1290

Modified:
   trunk/MgDev/Common/Stylization/SE_ExpressionBase.cpp
   trunk/MgDev/Common/Stylization/SE_ExpressionBase.h
   trunk/MgDev/Common/Stylization/SE_StyleVisitor.cpp
   trunk/MgDev/Common/Stylization/SE_SymbolDefProxies.cpp
   trunk/MgDev/Common/Stylization/SE_SymbolDefProxies.h
Log:
MapGuideRfc14
Implemented caching of evaluated styles. Custom styles which are detected to be constant will not be evaluated for every feature, but only once for the whole layer.

Modified: trunk/MgDev/Common/Stylization/SE_ExpressionBase.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/SE_ExpressionBase.cpp	2007-03-19 18:06:15 UTC (rev 1289)
+++ trunk/MgDev/Common/Stylization/SE_ExpressionBase.cpp	2007-03-19 18:25:04 UTC (rev 1290)
@@ -237,11 +237,11 @@
 
     if (len == 0)
     {
-        val = 0;
+        val.value.argb = 0;
         return;
     }
 
-    int ret = swscanf(cstr, L"%X%n", &val.argb(), &chars);
+    int ret = swscanf(cstr, L"%X%n", &val.value.argb, &chars);
 
     if (ret == 1 && chars == len)
     {

Modified: trunk/MgDev/Common/Stylization/SE_ExpressionBase.h
===================================================================
--- trunk/MgDev/Common/Stylization/SE_ExpressionBase.h	2007-03-19 18:06:15 UTC (rev 1289)
+++ trunk/MgDev/Common/Stylization/SE_ExpressionBase.h	2007-03-19 18:25:04 UTC (rev 1290)
@@ -26,10 +26,18 @@
 //////////////////////////////////////////////////////////////////////////////
 struct SE_Color
 {
-    unsigned char b, g, r, a; // argb, but little endian
+    union
+    {
+        struct
+        {
+            unsigned char b, g, r, a; // argb, but little endian
+        } comps;
+        unsigned int argb;
+    } value; //g++ doesn't like nameless structs, otherwise things would be far cleaner
+
     FdoExpression* expression;
 
-    SE_INLINE SE_Color() : expression(NULL) { *((unsigned int*)this) = 0; }
+    SE_INLINE SE_Color() : expression(NULL) { value.argb = 0; }
     ~SE_Color() { if (expression) expression->Release(); }
 
     // Retrieve argb color
@@ -40,7 +48,7 @@
             try
             {
                 expression->Process(processor);
-                *((unsigned int*)this) = (unsigned int)processor->GetInt64Result();
+                value.argb = (unsigned int)processor->GetInt64Result();
             }
             catch (FdoException* e)
             {
@@ -48,16 +56,15 @@
                 processor->Reset();
 
                 // set a default
-                *((unsigned int*)this) = 0xff000000;
+                value.argb = 0xff000000;
             }
         }
 
-        return *((unsigned int*)this);
+        return value.argb;
     }
 
-    SE_INLINE void operator=(unsigned int val) { *((unsigned int*)this) = val; }
-    SE_INLINE bool empty() { return (*(unsigned int*)this) == 0 && expression == NULL; }
-    SE_INLINE unsigned int& argb() { return (*(unsigned int*)this); }
+    SE_INLINE bool empty() { return value.argb == 0 && expression == NULL; }
+    SE_INLINE void operator=(unsigned int argb) { value.argb = argb; }
 };
 
 
@@ -172,7 +179,7 @@
 //////////////////////////////////////////////////////////////////////////////
 struct SE_String
 {
-    const wchar_t* value;
+    wchar_t* value;
     FdoExpression* expression;
 
     SE_INLINE SE_String() : value(NULL), expression(NULL) { }
@@ -190,8 +197,7 @@
 
     ~SE_String()
     {
-        if (value)
-            delete[] value;
+        delete[] value;
         if (expression)
             expression->Release();
     }
@@ -200,11 +206,8 @@
     {
         if (expression)
         {
-            if (value)
-            {
-                delete[] value;
-                value = NULL;
-            }
+            delete[] value;
+            value = NULL;
 
             try
             {
@@ -229,8 +232,7 @@
 
     SE_INLINE void operator=(const wchar_t* s)
     {
-        if (value)
-            delete[] value;
+        delete[] value;
 
         if (s)
         {

Modified: trunk/MgDev/Common/Stylization/SE_StyleVisitor.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/SE_StyleVisitor.cpp	2007-03-19 18:06:15 UTC (rev 1289)
+++ trunk/MgDev/Common/Stylization/SE_StyleVisitor.cpp	2007-03-19 18:25:04 UTC (rev 1290)
@@ -60,6 +60,13 @@
     ParseDoubleExpression(pointUsage.GetOriginOffsetX(), style->originOffset[0]);
     ParseDoubleExpression(pointUsage.GetOriginOffsetY(), style->originOffset[1]);
     ParseStringExpression(pointUsage.GetAngleControl(), style->angleControl);
+
+    //set flag if all properties are constant
+    style->cacheable = ! (style->angle.expression 
+                        || style->angleControl.expression
+                        || style->originOffset[0].expression 
+                        || style->originOffset[1].expression);
+
     return style;
 }
 
@@ -75,6 +82,18 @@
     ParseDoubleExpression(lineUsage.GetEndOffset(), style->endOffset);
     ParseDoubleExpression(lineUsage.GetRepeat(), style->repeat);
     ParseDoubleExpression(lineUsage.GetVertexAngleLimit(), style->vertexAngleLimit);
+
+    //set flag if all properties are constant
+    style->cacheable = ! (  style->angle.expression
+        || style->angleControl.expression
+        || style->unitsControl.expression
+        || style->vertexControl.expression
+        || style->angle.expression
+        || style->startOffset.expression
+        || style->endOffset.expression
+        || style->repeat.expression
+        || style->vertexAngleLimit.expression);
+
     return style;
 }
 
@@ -90,6 +109,19 @@
     ParseDoubleExpression(areaUsage.GetRepeatX(), style->repeat[0]);
     ParseDoubleExpression(areaUsage.GetRepeatY(), style->repeat[1]);
     ParseDoubleExpression(areaUsage.GetBufferWidth(), style->bufferWidth);
+
+    //set flag if all properties are constant
+    style->cacheable = !(  style->angle.expression
+                        || style->angleControl.expression
+                        || style->originControl.expression
+                        || style->clippingControl.expression
+                        || style->angle.expression
+                        || style->origin[0].expression
+                        || style->origin[1].expression
+                        || style->repeat[0].expression
+                        || style->repeat[1].expression
+                        || style->bufferWidth.expression);
+
     return style;
 }
 
@@ -394,8 +426,8 @@
 
         /* If the color is transparent, there is no point in drawing this path,
          * so we will change it to black. */
-        if (line->color.argb() == 0)
-            line->color.a = 255;
+        if (line->color.value.argb == 0)
+            line->color.value.comps.a = 255;
         line->cacheable = !(line->weight.expression ||
                             line->color.expression ||
                             line->weightScalable.expression);
@@ -431,7 +463,7 @@
     {
         //TODO: Disallow expressions for now since
         //ParseStringExpression(image.GetReference(), primitive->pngPath);
-        primitive->pngPath.value = image.GetReference().c_str();
+        primitive->pngPath = image.GetReference().c_str();
         primitive->pngPath.expression = NULL;
 
         if (primitive->pngPath.expression == NULL) // constant path
@@ -526,6 +558,9 @@
         {
             m_primitive->resize = elem->GetResizeControl();
             m_style->symbol.push_back(m_primitive);
+
+            //also update the style's cacheable flag to take into account the primitive's flag
+            m_style->cacheable = m_style->cacheable && m_primitive->cacheable;
         }
 
         m_primitive = NULL;
@@ -540,6 +575,12 @@
         ParseDoubleExpression(box->GetPositionX(), m_style->resizePosition[0]);
         ParseDoubleExpression(box->GetPositionY(), m_style->resizePosition[1]);
         m_style->resize = box->GetGrowControl();
+
+        m_style->cacheable = m_style->cacheable &&
+                             ! (  m_style->resizeSize[0].expression
+                               || m_style->resizeSize[1].expression
+                               || m_style->resizePosition[0].expression
+                               || m_style->resizePosition[1].expression);
     }
 
     m_symbolization->styles.push_back(m_style);

Modified: trunk/MgDev/Common/Stylization/SE_SymbolDefProxies.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/SE_SymbolDefProxies.cpp	2007-03-19 18:06:15 UTC (rev 1289)
+++ trunk/MgDev/Common/Stylization/SE_SymbolDefProxies.cpp	2007-03-19 18:25:04 UTC (rev 1290)
@@ -341,8 +341,20 @@
 
 void SE_PointStyle::evaluate(SE_EvalContext* cxt) 
 { 
-    SE_RenderPointStyle* render = new SE_RenderPointStyle();
+    SE_RenderPointStyle* render;
 
+    if (cacheable && rstyle)
+    {
+        //style is constant and has been evluated once -- we can skip out of evaluation
+        return;
+    }
+    else
+    {
+        render = new SE_RenderPointStyle();
+        delete rstyle;
+        rstyle = render;
+    }
+
     LineBuffer::GeomOperationType type;
     switch(cxt->geometry->geom_type())
     {
@@ -392,19 +404,26 @@
     sxform.premultiply(*cxt->xform);
     *cxt->xform = sxform; //BAD here we modify the passed in transform -- figure out a way to avoid this
 
-    //set the cached renderStyle member variable
-    //TODO: cache constant render styles
-    delete rstyle;
-    rstyle = render;
-
     //evaluate all the primitives too
     SE_Style::evaluate(cxt);
 }
 
 void SE_LineStyle::evaluate(SE_EvalContext* cxt) 
 { 
-    SE_RenderLineStyle* render = new SE_RenderLineStyle();
+    SE_RenderLineStyle* render;
 
+    if (cacheable && rstyle)
+    {
+        //style is constant and has been evluated once -- we can skip out of evaluation
+        return;
+    }
+    else
+    {
+        render = new SE_RenderLineStyle();
+        delete rstyle;
+        rstyle = render;
+    }
+
     render->angleControl = angleControl.evaluate(cxt->exec);
     render->unitsControl = unitsControl.evaluate(cxt->exec);
     render->vertexControl = vertexControl.evaluate(cxt->exec);
@@ -416,18 +435,24 @@
     render->repeat = repeat.evaluate(cxt->exec)*cxt->mm2px;
     render->vertexAngleLimit = vertexAngleLimit.evaluate(cxt->exec) * M_PI180;
 
-    //set the cached renderStyle member variable
-    //TODO: cache constant render styles
-    delete rstyle;
-    rstyle = render;
-
     //evaluate all the primitives too
     SE_Style::evaluate(cxt);
 }
 
 void SE_AreaStyle::evaluate(SE_EvalContext* cxt) 
 { 
-    SE_RenderAreaStyle* render = new SE_RenderAreaStyle();
+    SE_RenderAreaStyle* render;
+    if (cacheable && rstyle)
+    {
+        //style is constant and has been evluated once -- we can skip out of evaluation
+        return;
+    }
+    else
+    {
+        render = new SE_RenderAreaStyle();
+        delete rstyle;
+        rstyle = render;
+    }
 
     render->angleControl = angleControl.evaluate(cxt->exec);
     render->originControl = originControl.evaluate(cxt->exec);
@@ -440,11 +465,6 @@
     render->repeat[1] = repeat[1].evaluate(cxt->exec);
     render->bufferWidth = bufferWidth.evaluate(cxt->exec);
 
-    //set the cached renderStyle member variable
-    //TODO: cache constant render styles
-    delete rstyle;
-    rstyle = render;
-
     //evaluate all the primitives too
     SE_Style::evaluate(cxt);
 }

Modified: trunk/MgDev/Common/Stylization/SE_SymbolDefProxies.h
===================================================================
--- trunk/MgDev/Common/Stylization/SE_SymbolDefProxies.h	2007-03-19 18:06:15 UTC (rev 1289)
+++ trunk/MgDev/Common/Stylization/SE_SymbolDefProxies.h	2007-03-19 18:25:04 UTC (rev 1290)
@@ -132,6 +132,7 @@
 struct SE_Style
 {
     SE_RenderStyle* rstyle; // cached evaluated RenderStyle
+    bool cacheable;
     SE_PrimitiveList symbol;
     SE_Integer renderPass;
 
@@ -140,7 +141,7 @@
     SE_Double resizeSize[2];
     ResizeBox::GrowControl resize;
 
-    SE_INLINE SE_Style() : rstyle(NULL) { }
+    SE_INLINE SE_Style() : rstyle(NULL), cacheable(false) { }
 
     virtual ~SE_Style();
 
@@ -212,8 +213,6 @@
     ~SE_Symbolization()
     {
         for (std::vector<SE_Style*>::iterator iter = styles.begin(); iter != styles.end(); iter++)
-            //TODO: SE_Styles have no virtual destructor but they don't seem to need
-            //to free stuff specific to the derived classes
             delete *iter;
 
         styles.clear();
@@ -224,9 +223,11 @@
 struct SE_Rule
 {
     std::vector<SE_Symbolization*> symbolization;
-    RS_String legendLabel;  // no expressions on this guy
+    RS_String legendLabel;  // no expressions on this guy?
     FdoFilter* filter;
 
+    SE_Rule() : filter(NULL)  {  }
+
     ~SE_Rule()
     {
         if (filter) filter->Release();



More information about the mapguide-commits mailing list