Author: max
Date: 2007-07-17 12:53:18 -0700 (Tue, 17 Jul 2007)
New Revision: 5689

Modified:
   openlaszlo/branches/legals/lps/components/extensions/drawview.lzx
Log:
Change 20070716-maxcarlson-I by [EMAIL PROTECTED] on 2007-07-16 16:29:08 PDT
    in /Users/maxcarlson/openlaszlo/legals-clean
    for http://svn.openlaszlo.org/openlaszlo/branches/legals

Summary: Improve drawview performance in DHTML

New Features:

Bugs Fixed:

Technical Reviewer: promanik
QA Reviewer: jcrowley
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details: cache all canvas properties and don't reset unless changed.  Flatten 
_path array to contain one list.  Store method names as numbers instead of 
strings. move *_OP properties to static variables instead of setting on 
construct for swf.
    

Tests: 
http://localhost:8080/legals-clean/lps/components/extensions/test/drawing.lzx?lzr=dhtml
 functions like before.



Modified: openlaszlo/branches/legals/lps/components/extensions/drawview.lzx
===================================================================
--- openlaszlo/branches/legals/lps/components/extensions/drawview.lzx   
2007-07-17 19:44:35 UTC (rev 5688)
+++ openlaszlo/branches/legals/lps/components/extensions/drawview.lzx   
2007-07-17 19:53:18 UTC (rev 5689)
@@ -346,38 +346,38 @@
             }
     
             function beginPath() {
-                this.__path = ['moveTo', [0,0]];
+                this.__path = [[1,0,0]];
                 this.__pathisopen = true;
             }
     
             function closePath() {
                 if (this.__pathisopen) {
-                    this.__path.push('closePath', arguments);
+                    this.__path.push([0]);
                 }
                 this.__pathisopen = false;
             }
     
-            function moveTo() {
+            function moveTo(x,y) {
                 if (this.__pathisopen) {
-                    this.__path.push('moveTo', arguments);
+                    this.__path.push([1, x,y]);
                 }
             }
     
-            function lineTo() {
+            function lineTo(x,y) {
                 if (this.__pathisopen) {
-                    this.__path.push('lineTo', arguments);
+                    this.__path.push([2, x,y]);
                 }
             }
     
-            function quadraticCurveTo() {
+            function quadraticCurveTo(cpx, cpy, x, y) {
                 if (this.__pathisopen) {
-                    this.__path.push('quadraticCurveTo', arguments);
+                    this.__path.push([3, cpx, cpy, x, y]);
                 }
             }
     
-            function bezierCurveTo() {
+            function bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
                 if (this.__pathisopen) {
-                    this.__path.push('bezierCurveTo', arguments);
+                    this.__path.push([4, cp1x, cp1y, cp2x, cp2y, x, y]);
                 }
             }
     
@@ -387,41 +387,56 @@
             }
     
             function __playPath() {
+                if (this.__path.length == 0) return;
                 if ($debug) this.__checkContext();
-                this.context.lineWidth = this.lineWidth;
-                this.context.lineCap = this.lineCap;
-                if (this.fillStyle instanceof LzCanvasGradient) {
-                    //Debug.write('before apply');
-                    this.fillStyle.__applyTo(this.context);
-                } else {
-                    if (! this._colorcache[this.fillStyle]) {
-                        this._colorcache[this.fillStyle] = 
LzUtils.color.torgb(this.fillStyle);
+                if (this._lineWidth != this.lineWidth) {
+                    this.context.lineWidth = this.lineWidth;
+                    this._lineWidth = this.lineWidth;
+                }
+                if (this._lineCap != this.lineCap) {
+                    this.context.lineCap = this.lineCap;
+                    this._lineCap = this.lineCap;
+                }
+                if (this._fillStyle != this.fillStyle) {
+                    if (this.fillStyle instanceof LzCanvasGradient) {
+                        //Debug.write('before apply');
+                        this.fillStyle.__applyTo(this.context);
+                    } else {
+                        if (! this._colorcache[this.fillStyle]) {
+                            this._colorcache[this.fillStyle] = 
LzUtils.color.torgb(this.fillStyle);
+                        }
+                        this.context.fillStyle = 
this._colorcache[this.fillStyle];
                     }
-                    this.context.fillStyle = this._colorcache[this.fillStyle];
+                    this._fillStyle = this.fillStyle;
                 }
     
-                if (! this._colorcache[this.strokeStyle]) {
-                    this._colorcache[this.strokeStyle] = 
LzUtils.color.torgb(this.strokeStyle);
+                if (this._strokeStyle != this.strokeStyle) {
+                    if (! this._colorcache[this.strokeStyle]) {
+                        this._colorcache[this.strokeStyle] = 
LzUtils.color.torgb(this.strokeStyle);
+                    }
+                    this.context.strokeStyle = 
this._colorcache[this.strokeStyle];
+                    this._strokeStyle = this.strokeStyle;
                 }
-                this.context.strokeStyle = this._colorcache[this.strokeStyle];
 
-                this.context.globalAlpha = this.globalAlpha;
-                if (this.__path.length) {
-                    this.context.beginPath();
-                    for (var i = 0; i < this.__path.length; i += 2) {
-                        var n = this.__path[i];
-                        var a = this.__path[i + 1];
-                        if (n == 'closePath') {
-                            this.context.closePath();
-                        } else if (n == 'quadraticCurveTo') {
-                            this.context.quadraticCurveTo(a[0], a[1], a[2], 
a[3]); 
-                        } else if (n == 'bezierCurveTo') {
-                            this.context.bezierCurveTo(a[0], a[1], a[2], a[3], 
a[4], a[5]); 
-                        } else if (n == 'moveTo') {
-                            this.context.moveTo(a[0], a[1]); 
-                        } else if (n == 'lineTo') {
-                            this.context.lineTo(a[0], a[1]); 
-                        }
+                if (this._globalAlpha != this.globalAlpha) {
+                    this.context.globalAlpha = this.globalAlpha;
+                    this._globalAlpha = this.globalAlpha;
+                }
+
+                this.context.beginPath();
+                for (var i = 0; i < this.__path.length; i += 1) {
+                    var a = this.__path[i];
+                    var n = a[0];
+                    if (n == 0) {
+                        this.context.closePath();
+                    } else if (n == 3) {
+                        this.context.quadraticCurveTo(a[1], a[2], a[3], a[4]); 
+                    } else if (n == 4) {
+                        this.context.bezierCurveTo(a[1], a[2], a[3], a[4], 
a[5], a[6]); 
+                    } else if (n == 1) {
+                        this.context.moveTo(a[1], a[2]); 
+                    } else if (n == 2) {
+                        this.context.lineTo(a[1], a[2]); 
                     }
                 }
             }
@@ -505,6 +520,9 @@
             var context = null;
             var cachebitmap = true;
             var _colorcache = {}
+            var __MOVETO_OP = 0;
+            var __LINETO_OP = 1;
+            var __QCURVE_OP = 2;
             
             DeclareEvent(prototype, 'oncontext');
     
@@ -513,9 +531,6 @@
                 args['height'] = args['height'] > -1 ? args.height : null;
                 args['clip'] = args['clip'] == true ? args.clip : null;
                 super.construct(parent, args);
-                this.__MOVETO_OP = 0;
-                this.__LINETO_OP = 1;
-                this.__QCURVE_OP = 2;
                 this.context = this.getMCRef();
                 this.context.cacheAsBitmap = args['cachebitmap'] != null ? 
args['cachebitmap'] : this.cachebitmap;
                 this.beginPath();


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to