Author: toshok
Date: 2007-07-27 18:08:53 -0400 (Fri, 27 Jul 2007)
New Revision: 82893

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/transform.cpp
   trunk/moon/src/transform.h
Log:
2007-07-27  Chris Toshok  <[EMAIL PROTECTED]>

        * transform.h, transform.cpp: cache the transformation matrix once
        we recompute it.  This gives us the responsiveness of delayed
        updating without the cost of calculating the matrix once per
        object associated with it.  a property change just sets the
        "need_update" flag, which causes a recompute on the next
        GetTransform call.



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-07-27 21:52:22 UTC (rev 82892)
+++ trunk/moon/src/ChangeLog    2007-07-27 22:08:53 UTC (rev 82893)
@@ -1,3 +1,12 @@
+2007-07-27  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * transform.h, transform.cpp: cache the transformation matrix once
+       we recompute it.  This gives us the responsiveness of delayed
+       updating without the cost of calculating the matrix once per
+       object associated with it.  a property change just sets the
+       "need_update" flag, which causes a recompute on the next
+       GetTransform call.
+
 2007-07-27  Larry Ewing  <[EMAIL PROTECTED]>
 
        * uielement.cpp: implement initial support for OpacityMask.

Modified: trunk/moon/src/transform.cpp
===================================================================
--- trunk/moon/src/transform.cpp        2007-07-27 21:52:22 UTC (rev 82892)
+++ trunk/moon/src/transform.cpp        2007-07-27 22:08:53 UTC (rev 82893)
@@ -28,6 +28,7 @@
                return;
        }
 
+       need_update = true;
        //
        // If the transform changes, we need to notify our owners
        // that they must repaint (all of our properties have
@@ -43,15 +44,16 @@
 }
 
 void
+Transform::UpdateTransform ()
+{
+       g_warning ("Transform:UpdateTransform has been called. The derived 
class should have overridden it.");
+}
+
+void
 transform_get_transform (Transform *t, cairo_matrix_t *value)
 {
        t->GetTransform (value);
 }
-void 
-Transform::GetTransform (cairo_matrix_t *value)
-{
-       g_warning ("Transform:GetTransform has been called. The derived class 
should have overridden it.");
-}
 
 Transform *
 transform_new (void)
@@ -66,7 +68,7 @@
 DependencyProperty* RotateTransform::AngleProperty;
 
 void
-RotateTransform::GetTransform (cairo_matrix_t *value)
+RotateTransform::UpdateTransform ()
 {
        double angle, center_x, center_y;
        double radians;
@@ -78,13 +80,13 @@
        radians = angle / 180.0 * M_PI;
 
        if (center_x == 0.0 && center_y == 0.0) {
-               cairo_matrix_init_rotate (value, radians);
+               cairo_matrix_init_rotate (&_matrix, radians);
        }
        else {
-               cairo_matrix_init_identity (value);
-               cairo_matrix_translate (value, center_x, center_y);
-               cairo_matrix_rotate (value, radians);
-               cairo_matrix_translate (value, -center_x, -center_y);
+               cairo_matrix_init_identity (&_matrix);
+               cairo_matrix_translate (&_matrix, center_x, center_y);
+               cairo_matrix_rotate (&_matrix, radians);
+               cairo_matrix_translate (&_matrix, -center_x, -center_y);
        }
        //printf ("Returning2 %g %g %g %g %g %g\n", value->xx, value->yx, 
value->xy, value->yy, value->x0, value->y0);
 }
@@ -138,12 +140,12 @@
 DependencyProperty* TranslateTransform::YProperty;
 
 void
-TranslateTransform::GetTransform (cairo_matrix_t *value)
+TranslateTransform::UpdateTransform ()
 {
        double x = translate_transform_get_x (this);
        double y = translate_transform_get_y (this);
 
-       cairo_matrix_init_translate (value, x, y);
+       cairo_matrix_init_translate (&_matrix, x, y);
        //printf ("translating dx %g dy %g", x, y);
        //printf ("TranslateTransform %g %g %g %g %g %g\n", value->xx, 
value->yx, value->xy, value->yy, value->x0, value->y0);
 }
@@ -186,7 +188,7 @@
 DependencyProperty* ScaleTransform::ScaleYProperty;
 
 void
-ScaleTransform::GetTransform (cairo_matrix_t *value)
+ScaleTransform::UpdateTransform ()
 {
        double sx = scale_transform_get_scale_x (this);
        double sy = scale_transform_get_scale_y (this);
@@ -206,13 +208,13 @@
        double cy = scale_transform_get_center_y (this);
 
        if (cx == 0.0 && cy == 0.0) {
-               cairo_matrix_init_scale (value, sx, sy);
+               cairo_matrix_init_scale (&_matrix, sx, sy);
        }
        else {
-               cairo_matrix_init_identity (value);
-               cairo_matrix_translate (value, cx, cy);
-               cairo_matrix_scale (value, sx, sy);
-               cairo_matrix_translate (value, -cx, -cy);
+               cairo_matrix_init_identity (&_matrix);
+               cairo_matrix_translate (&_matrix, cx, cy);
+               cairo_matrix_scale (&_matrix, sx, sy);
+               cairo_matrix_translate (&_matrix, -cx, -cy);
        }
        //printf ("scaling sx %g sy %g at center cx %g cy %g\n", sx, sy, cx, 
cy);
        //printf ("ScaleTransform %g %g %g %g %g %g\n", value->xx, value->yx, 
value->xy, value->yy, value->x0, value->y0);
@@ -281,27 +283,27 @@
 DependencyProperty* SkewTransform::CenterYProperty;
 
 void
-SkewTransform::GetTransform (cairo_matrix_t *value)
+SkewTransform::UpdateTransform ()
 {
-       cairo_matrix_init_identity (value);
+       cairo_matrix_init_identity (&_matrix);
 
        double cx = skew_transform_get_center_x (this);
        double cy = skew_transform_get_center_y (this);
 
        bool translation = ((cx != 0.0) || (cy != 0.0));
        if (translation)
-               cairo_matrix_translate (value, cx, cy);
+               cairo_matrix_translate (&_matrix, cx, cy);
 
        double ax = skew_transform_get_angle_x (this);
        if (ax != 0.0)
-               value->xy = tan (ax * M_PI / 180);
+               _matrix.xy = tan (ax * M_PI / 180);
 
        double ay = skew_transform_get_angle_y (this);
        if (ay != 0.0)
-               value->yx = tan (ay * M_PI / 180);
+               _matrix.yx = tan (ay * M_PI / 180);
 
        if (translation)
-               cairo_matrix_translate (value, -cx, -cy);
+               cairo_matrix_translate (&_matrix, -cx, -cy);
 
        //printf ("SkewTransform %g %g %g %g %g %g\n", value->xx, value->yx, 
value->xy, value->yy, value->x0, value->y0);
 }
@@ -365,13 +367,13 @@
 DependencyProperty* MatrixTransform::MatrixProperty;
 
 void
-MatrixTransform::GetTransform (cairo_matrix_t *value)
+MatrixTransform::UpdateTransform ()
 {
        cairo_matrix_t* matrix = matrix_transform_get_matrix (this);
        if (matrix)
-               memcpy (value, matrix, sizeof (cairo_matrix_t));
+               _matrix = *matrix;
        else
-               cairo_matrix_init_identity (value);
+               cairo_matrix_init_identity (&_matrix);
        //printf ("Returning1 %g %g %g %g %g %g\n", value->xx, value->yx, 
value->xy, value->yy, value->x0, value->y0);
 }
 
@@ -421,6 +423,8 @@
                                printf ("Warning we attached a property that 
was already attached\n");
                        newcol->closure = this;
                }
+
+               need_update = true;
        }
 
        NotifyAttacheesOfPropertyChange (prop);
@@ -429,23 +433,24 @@
 void
 TransformGroup::OnSubPropertyChanged (DependencyProperty *prop, 
DependencyProperty *subprop)
 {
+       need_update = true;
        NotifyAttacheesOfPropertyChange (subprop);
 }
 
 void
-TransformGroup::GetTransform (cairo_matrix_t *value)
+TransformGroup::UpdateTransform ()
 {
        TransformCollection *children = GetValue 
(TransformGroup::ChildrenProperty)->AsTransformCollection ();
        Collection::Node *node = (Collection::Node *) children->list->First ();
        
-       cairo_matrix_init_identity (value);
+       cairo_matrix_init_identity (&_matrix);
        
        for ( ; node != NULL; node = (Collection::Node *) node->Next ()) {
                Transform *transform = (Transform *) node->obj;
                cairo_matrix_t matrix;
                
                transform->GetTransform (&matrix);
-               cairo_matrix_multiply (value, value, &matrix);
+               cairo_matrix_multiply (&_matrix, &_matrix, &matrix);
        }
 }
 

Modified: trunk/moon/src/transform.h
===================================================================
--- trunk/moon/src/transform.h  2007-07-27 21:52:22 UTC (rev 82892)
+++ trunk/moon/src/transform.h  2007-07-27 22:08:53 UTC (rev 82893)
@@ -21,10 +21,21 @@
 
 class Transform : public DependencyObject {
  public:
-       Transform () { }
+       Transform () : need_update (true) { }
        virtual void OnPropertyChanged (DependencyProperty *prop);
        virtual Type::Kind GetObjectType () { return Type::TRANSFORM; };
-       virtual void GetTransform (cairo_matrix_t *value);
+       virtual void GetTransform (cairo_matrix_t *value) {
+               if (need_update) {
+                       UpdateTransform ();
+                       need_update = false;
+               }
+               *value = _matrix;
+       };
+
+       virtual void UpdateTransform ();
+ protected:
+       cairo_matrix_t _matrix;
+       bool need_update;
 };
 
 Transform* transform_new ();
@@ -35,12 +46,11 @@
 
        RotateTransform () { }
        virtual Type::Kind GetObjectType () { return Type::ROTATETRANSFORM; };
+       virtual void UpdateTransform ();
 
        static DependencyProperty* AngleProperty;
        static DependencyProperty* CenterXProperty;
        static DependencyProperty* CenterYProperty;
-
-       virtual void GetTransform (cairo_matrix_t *value);
 };
 
 RotateTransform * rotate_transform_new ();
@@ -59,11 +69,10 @@
 
        TranslateTransform () {  }
        virtual Type::Kind GetObjectType () { return Type::TRANSLATETRANSFORM; 
};
+       virtual void UpdateTransform ();
 
        static DependencyProperty* XProperty;
        static DependencyProperty* YProperty;
-
-       virtual void GetTransform (cairo_matrix_t *value);
 };
 
 TranslateTransform *translate_transform_new ();
@@ -79,13 +88,12 @@
 
        ScaleTransform () {  }
        virtual Type::Kind GetObjectType () { return Type::SCALETRANSFORM; };
+       virtual void UpdateTransform ();
 
        static DependencyProperty* ScaleXProperty;
        static DependencyProperty* ScaleYProperty;
        static DependencyProperty* CenterXProperty;
        static DependencyProperty* CenterYProperty;
-
-       virtual void GetTransform (cairo_matrix_t *value);
 };
 
 ScaleTransform * scale_transform_new ();
@@ -107,13 +115,12 @@
 
        SkewTransform () {  }
        virtual Type::Kind GetObjectType () { return Type::SKEWTRANSFORM; };
+       virtual void UpdateTransform ();
 
        static DependencyProperty* AngleXProperty;
        static DependencyProperty* AngleYProperty;
        static DependencyProperty* CenterXProperty;
        static DependencyProperty* CenterYProperty;
-
-       virtual void GetTransform (cairo_matrix_t *value);
 };
 
 SkewTransform * skew_transform_new ();
@@ -139,8 +146,7 @@
        /* these are dependency properties
           Matrix matrix;
        */
-
-       virtual void GetTransform (cairo_matrix_t *value);
+       virtual void UpdateTransform ();
 };
 
 MatrixTransform *matrix_transform_new ();
@@ -166,7 +172,7 @@
 
        virtual void OnSubPropertyChanged (DependencyProperty *prop, 
DependencyProperty *subprop);
        virtual void OnPropertyChanged (DependencyProperty *prop);
-       virtual void GetTransform (cairo_matrix_t *value);
+       virtual void UpdateTransform ();
 };
 
 TransformGroup *transform_group_new ();

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to