Project

General

Profile

performance_issue_1.txt

Sergey Ivanovskiy, 02/12/2016 05:43 AM

Download (2.85 KB)

 
1
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.canvas_renderer.js'
2
--- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.canvas_renderer.js	2016-01-29 15:50:34 +0000
3
+++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.canvas_renderer.js	2016-02-12 09:27:24 +0000
4
@@ -502,7 +502,7 @@
5
 {
6
    // holds the line pixels to draw
7
    var path = [];
8
-
9
+   
10
    x1 = x1 + this.origin.x;
11
    x2 = x2 + this.origin.x;
12
    
13
@@ -513,16 +513,21 @@
14
    var d = this.cutLine(x1, y1, x2, y2);
15
    if (d === null)
16
    {
17
-      return path;
18
+      return {path : path, imageData : null};
19
    }
20
    x1 = d[0];
21
    y1 = d[1];
22
    x2 = d[2];
23
    y2 = d[3];
24
    
25
+   
26
    var dx = Math.abs(x2 - x1);
27
    var dy = Math.abs(y2 - y1);
28
-   
29
+   var width  = dx + 1;
30
+   var height = dy + 1;
31
+   var buffer = new ArrayBuffer(4 * width * height);
32
+   var imageData = new Uint8ClampedArray(buffer);
33
+
34
    var xIncr = x1 < x2 ? 1 : -1;
35
    var yIncr = y1 < y2 ? 1 : -1;
36
    
37
@@ -533,7 +538,7 @@
38
    
39
    var x = x1;
40
    var y = y1;
41
-   
42
+   var curr = 0;
43
    var tooMany = 0;
44
    var directStroke = this.strokesManager.isDirectDrawingStrokeStyle(this.strokeStyleId);
45
    
46
@@ -541,7 +546,11 @@
47
    {
48
       if (directStroke)
49
       {
50
-         this.drawPixel(x, y, color);
51
+         //this.drawPixel(x, y, color);
52
+         imageData[curr++] = color[0];
53
+         imageData[curr++] = color[1];
54
+         imageData[curr++] = color[2];
55
+         imageData[curr++] = 255;
56
       }
57
       path.push({x : x, y : y});
58
       
59
@@ -577,7 +586,7 @@
60
       }
61
    }
62
    
63
-   return path;
64
+   return {path : path, imageData : imageData, x1 : x1, y1 : y1, width : width, height : height , draw : directStroke};
65
 };
66
 
67
 /**
68
@@ -605,7 +614,13 @@
69
 CanvasRenderer.prototype.drawLine = function(x1, y1, x2, y2, color, path)
70
 {
71
    var segment = this.drawLineSegment(x1, y1, x2, y2, color);
72
-   Array.prototype.push.apply(path, segment);
73
+   if (segment.imageData && segment.draw)
74
+   {
75
+      var img = this.ctx.getImageData(segment.x1, segment.y1, segment.width, segment.height);
76
+      img.data.set(segment.imageData, 0);
77
+      this.ctx.putImageData(img, segment.x1, segment.y1);
78
+   }
79
+   Array.prototype.push.apply(path, segment.path);
80
    return segment;
81
 }
82
 
83
@@ -631,12 +646,18 @@
84
  */
85
 CanvasRenderer.prototype.strokeLineSegment = function(x1, y1, x2, y2, color)
86
 {
87
-   var path = this.drawLineSegment(x1, y1, x2, y2, color);
88
+   var segment = this.drawLineSegment(x1, y1, x2, y2, color);
89
+   if (segment.imageData && segment.draw)
90
+   {
91
+      var img = this.ctx.getImageData(segment.x1, segment.y1, segment.width, segment.height);
92
+      img.data.set(segment.imageData, 0);
93
+      this.ctx.putImageData(img, segment.x1, segment.y1);
94
+   }
95
    this.strokesManager.applyStrokeToPath(this,
96
          this.strokeStyleId,
97
          this.strokeWidth,
98
          color,
99
-         path);
100
+         segment.path);
101
 }
102
 
103
 /**
104