Commit 48eed1ac authored by Joel Martin's avatar Joel Martin

Refactor canvas imageData test slightly.

parent 486cd527
...@@ -13,12 +13,14 @@ ...@@ -13,12 +13,14 @@
var Canvas, Canvas_native; var Canvas, Canvas_native;
(function () { (function () {
var pre, extra = "", start, end; var pre, start = "<script src='", end = "'><\/script>";
if (document.createElement('canvas').getContext) { if (document.createElement('canvas').getContext) {
Canvas_native = true; Canvas_native = true;
} else { } else {
pre = (typeof VNC_uri_prefix !== "undefined") ?
VNC_uri_prefix : "include/";
document.write(start + pre + "excanvas.js" + end);
Canvas_native = false; Canvas_native = false;
document.write("<script src='excanvas'><\/script>");
} }
}()); }());
...@@ -146,6 +148,7 @@ init: function (id) { ...@@ -146,6 +148,7 @@ init: function (id) {
// Use default Canvas functions // Use default Canvas functions
} else { } else {
console.warn("Using excanvas canvas emulation"); console.warn("Using excanvas canvas emulation");
//G_vmlCanvasManager.init(c);
G_vmlCanvasManager.initElement(c); G_vmlCanvasManager.initElement(c);
} }
...@@ -154,21 +157,25 @@ init: function (id) { ...@@ -154,21 +157,25 @@ init: function (id) {
Canvas.clear(); Canvas.clear();
/* /*
* Determine browser feature support and most optimal rendering * Determine browser Canvas feature support
* methods * and select fastest rendering methods
*/ */
tval = 0; tval = 0;
Canvas.has_imageData = false;
try { try {
imgTest = Canvas.ctx.getImageData(0, 0, 1,1); imgTest = Canvas.ctx.getImageData(0, 0, 1,1);
imgTest.data[0] = 123; imgTest.data[0] = 123;
imgTest.data[3] = 255; imgTest.data[3] = 255;
Canvas.ctx.putImageData(imgTest, 0, 0); Canvas.ctx.putImageData(imgTest, 0, 0);
tval = Canvas.ctx.getImageData(0, 0, 1, 1).data[0]; tval = Canvas.ctx.getImageData(0, 0, 1, 1).data[0];
} catch (exc) { if (tval === 123) {
} Canvas.has_imageData = true;
if (tval === 123) { }
} catch (exc) {}
if (Canvas.has_imageData) {
console.log("Canvas supports imageData");
Canvas._rgbxImage = Canvas._rgbxImageData; Canvas._rgbxImage = Canvas._rgbxImageData;
Canvas._cmapImage = Canvas._cmapImageData; Canvas._cmapImage = Canvas._cmapImageData;
if (Canvas.ctx.createImageData) { if (Canvas.ctx.createImageData) {
...@@ -178,9 +185,6 @@ init: function (id) { ...@@ -178,9 +185,6 @@ init: function (id) {
} else if (Canvas.ctx.getImageData) { } else if (Canvas.ctx.getImageData) {
console.log("Using Canvas getImageData"); console.log("Using Canvas getImageData");
Canvas._imageData = Canvas._imageDataGet; Canvas._imageData = Canvas._imageDataGet;
} else {
console.log("No imageData support");
return false;
} }
if (Util.Engine.webkit) { if (Util.Engine.webkit) {
console.log("Prefering javascript operations"); console.log("Prefering javascript operations");
...@@ -190,7 +194,7 @@ init: function (id) { ...@@ -190,7 +194,7 @@ init: function (id) {
Canvas.prefer_js = false; Canvas.prefer_js = false;
} }
} else { } else {
console.log("No imageData, using fillRect (slow)"); console.log("Canvas lacks imageData, using fillRect (slow)");
Canvas._rgbxImage = Canvas._rgbxImageFill; Canvas._rgbxImage = Canvas._rgbxImageFill;
Canvas._cmapImage = Canvas._cmapImageFill; Canvas._cmapImage = Canvas._cmapImageFill;
Canvas.prefer_js = false; Canvas.prefer_js = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment