You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by jm...@apache.org on 2017/01/29 19:54:47 UTC

[2/3] incubator-guacamole-client git commit: GUACAMOLE-187: Only preserve canvas contents during resize if there are contents to preserve.

GUACAMOLE-187: Only preserve canvas contents during resize if there are contents to preserve.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/053f34a5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/053f34a5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/053f34a5

Branch: refs/heads/master
Commit: 053f34a54d9e283042592a6492b7bd300d2c3a19
Parents: 7f176d0
Author: Michael Jumper <mj...@apache.org>
Authored: Fri Oct 7 23:08:51 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Fri Jan 27 16:43:07 2017 -0800

----------------------------------------------------------------------
 .../src/main/webapp/modules/Layer.js            | 22 ++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/053f34a5/guacamole-common-js/src/main/webapp/modules/Layer.js
----------------------------------------------------------------------
diff --git a/guacamole-common-js/src/main/webapp/modules/Layer.js b/guacamole-common-js/src/main/webapp/modules/Layer.js
index a3eb227..1ed9d4c 100644
--- a/guacamole-common-js/src/main/webapp/modules/Layer.js
+++ b/guacamole-common-js/src/main/webapp/modules/Layer.js
@@ -67,6 +67,16 @@ Guacamole.Layer = function(width, height) {
     context.save();
 
     /**
+     * Whether the layer has not yet been drawn to. Once any draw operation
+     * which affects the underlying canvas is invoked, this flag will be set to
+     * false.
+     *
+     * @private
+     * @type Boolean
+     */
+    var empty = true;
+
+    /**
      * Whether a new path should be started with the next path drawing
      * operations.
      * @private
@@ -132,9 +142,9 @@ Guacamole.Layer = function(width, height) {
         // Resize only if canvas dimensions are actually changing
         if (canvas.width !== canvasWidth || canvas.height !== canvasHeight) {
 
-            // Copy old data only if relevant
+            // Copy old data only if relevant and non-empty
             var oldData = null;
-            if (canvas.width !== 0 && canvas.height !== 0) {
+            if (!empty && canvas.width !== 0 && canvas.height !== 0) {
 
                 // Create canvas and context for holding old data
                 oldData = document.createElement("canvas");
@@ -289,6 +299,7 @@ Guacamole.Layer = function(width, height) {
     this.drawImage = function(x, y, image) {
         if (layer.autosize) fitRect(x, y, image.width, image.height);
         context.drawImage(image, x, y);
+        empty = false;
     };
 
     /**
@@ -367,6 +378,7 @@ Guacamole.Layer = function(width, height) {
 
         // Draw image data
         context.putImageData(dst, x, y);
+        empty = false;
 
     };
 
@@ -410,6 +422,7 @@ Guacamole.Layer = function(width, height) {
         // Get image data from src and dst
         var src = srcLayer.getCanvas().getContext("2d").getImageData(srcx, srcy, srcw, srch);
         context.putImageData(src, x, y);
+        empty = false;
 
     };
 
@@ -453,6 +466,7 @@ Guacamole.Layer = function(width, height) {
 
         if (layer.autosize) fitRect(x, y, srcw, srch);
         context.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch);
+        empty = false;
 
     };
 
@@ -615,6 +629,7 @@ Guacamole.Layer = function(width, height) {
         context.lineWidth = thickness;
         context.strokeStyle = "rgba(" + r + "," + g + "," + b + "," + a/255.0 + ")";
         context.stroke();
+        empty = false;
 
         // Path now implicitly closed
         pathClosed = true;
@@ -637,6 +652,7 @@ Guacamole.Layer = function(width, height) {
         // Fill with color
         context.fillStyle = "rgba(" + r + "," + g + "," + b + "," + a/255.0 + ")";
         context.fill();
+        empty = false;
 
         // Path now implicitly closed
         pathClosed = true;
@@ -669,6 +685,7 @@ Guacamole.Layer = function(width, height) {
             "repeat"
         );
         context.stroke();
+        empty = false;
 
         // Path now implicitly closed
         pathClosed = true;
@@ -693,6 +710,7 @@ Guacamole.Layer = function(width, height) {
             "repeat"
         );
         context.fill();
+        empty = false;
 
         // Path now implicitly closed
         pathClosed = true;