weex-gcanvas
Advanced tools
Comparing version 0.5.47 to 0.5.48
@@ -120,3 +120,3 @@ /** | ||
//----------------------------- | ||
GLog.d('gcanvas#=====>>>version: 0.5.47'); | ||
GLog.d('gcanvas#=====>>>version: 0.5.48'); | ||
@@ -127,4 +127,4 @@ GCanvas.start = function(el){ | ||
if( (typeof weex!=='undefined' && weex.supports && weex.supports('@weex-module/userTrack')) || | ||
(__weex_module_supports__ && __weex_module_supports__('@weex-module/userTrack')) ) | ||
if( (typeof(weex)!=='undefined' && weex.supports && weex.supports('@weex-module/userTrack')) || | ||
(typeof(__weex_module_supports__) == "function" && __weex_module_supports__('@weex-module/userTrack')) ) | ||
{ | ||
@@ -131,0 +131,0 @@ try { |
@@ -20,13 +20,13 @@ var GBridge = require("./gutil").GBridge; | ||
this._font = "10px sans-serif"; | ||
this._images = {}; | ||
this._canvases1 = {}; | ||
this._canvases2 = {}; | ||
this._getImageData = new Array(); | ||
// this._images = {}; | ||
// this._canvases1 = {}; | ||
// this._canvases2 = {}; | ||
// this._getImageData = new Array(); | ||
// GCanvas._forbiddenAutoReplaceCanvas =true; | ||
// this._apiCanvas = document.createElement('canvas'); | ||
// GCanvas._forbiddenAutoReplaceCanvas =false; | ||
// console.error("apicanvas="+this._apiCanvas); | ||
// this._apiContext = this._apiCanvas.getContext("2d"); | ||
// this._apiContext.font = this._font; | ||
// GCanvas._forbiddenAutoReplaceCanvas =true; | ||
// this._apiCanvas = document.createElement('canvas'); | ||
// GCanvas._forbiddenAutoReplaceCanvas =false; | ||
// console.error("apicanvas="+this._apiCanvas); | ||
// this._apiContext = this._apiCanvas.getContext("2d"); | ||
// this._apiContext.font = this._font; | ||
@@ -39,9 +39,7 @@ this._savedGlobalAlpha =[]; | ||
this._textureMap = new GHashMap(); | ||
this._firstBindFlag = true; | ||
this._checkVersionFlag = false; | ||
this._useNewAPIFlag = true; | ||
} | ||
///////////////////////////////////////////////////////////////// | ||
// FillStylePattern | ||
///////////////////////////////////////////////////////////////// | ||
function FillStylePattern(img, pattern) { | ||
@@ -52,2 +50,6 @@ this._style = pattern; | ||
///////////////////////////////////////////////////////////////// | ||
// FillStyleLinearGradient | ||
///////////////////////////////////////////////////////////////// | ||
function FillStyleLinearGradient(x0, y0, x1, y1) { | ||
@@ -67,2 +69,6 @@ this._start_pos = { _x : x0, _y : y0 }; | ||
///////////////////////////////////////////////////////////////// | ||
// FillStyleRadialGradient | ||
///////////////////////////////////////////////////////////////// | ||
function FillStyleRadialGradient(x0, y0, r0, x1, y1, r1) { | ||
@@ -121,15 +127,4 @@ this._start_pos = { _x : x0, _y : y0, _r : r0 }; | ||
else if (value instanceof FillStylePattern) { | ||
if (value._img instanceof Image) { | ||
if (!(value._img.src in this._images)) { | ||
var new_image = GCanvas.createImage(); | ||
new_image.width = value._img.width; | ||
new_image.height = value._img.height; | ||
new_image.src = value._img.src; | ||
new_image.complete = value._img.complete; | ||
this._images[value._img.src] = new_image; | ||
} else { | ||
this._drawCommands = this._drawCommands.concat("G" + this._images[value._img.src]._id + "," + value._style + ";"); | ||
} | ||
} | ||
else if (value._img instanceof GCanvasImage){ | ||
if (value._img instanceof GCanvasImage){ | ||
GBridge.bindImageTexture(this.componentId, [value._img.src, value._img.id], function(){}); | ||
this._drawCommands = this._drawCommands.concat("G" + value._img._id + "," + value._style + ";"); | ||
@@ -139,4 +134,5 @@ } | ||
else if (value instanceof FillStyleLinearGradient) { | ||
var command = "D" + value._start_pos._x + "," + value._start_pos._y + "," | ||
+ value._end_pos._x + "," + value._end_pos._y + "," + value._stop_count; | ||
var command = "D" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," | ||
+ value._end_pos._x.toFixed(2) + "," + value._end_pos._y.toFixed(2) + "," | ||
+ value._stop_count; | ||
@@ -147,7 +143,7 @@ for (var i = 0; i < value._stop_count; ++i) { | ||
this._drawCommands = this._drawCommands.concat(command + ";"); | ||
//console.log('createLinearGradient command -> ' + command); | ||
} | ||
else if (value instanceof FillStyleRadialGradient) { | ||
var command = "H" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," + value._start_pos._r + "," | ||
+ value._end_pos._x.toFixed(2) + "," + value._end_pos._y.toFixed(2) + "," + value._end_pos._r + "," + value._stop_count; | ||
var command = "H" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," + value._start_pos._r.toFixed(2) + "," | ||
+ value._end_pos._x.toFixed(2) + "," + value._end_pos._y.toFixed(2) + "," + value._end_pos._r.toFixed(2) + "," | ||
+ value._stop_count; | ||
@@ -158,3 +154,2 @@ for (var i = 0; i < value._stop_count; ++i) { | ||
this._drawCommands = this._drawCommands.concat(command + ";"); | ||
//console.log('FillStyleRadialGradient command -> ' + command); | ||
} | ||
@@ -183,15 +178,4 @@ } | ||
else if (value instanceof FillStylePattern) { | ||
if (value._img instanceof Image) { | ||
if (!(value._img.src in this._images)) { | ||
var new_image = GCanvas.createImage(); | ||
new_image.width = value._img.width; | ||
new_image.height = value._img.height; | ||
new_image.src = value._img.src; | ||
new_image.complete = value._img.complete; | ||
this._images[value._img.src] = new_image; | ||
} else { | ||
this._drawCommands = this._drawCommands.concat("G" + this._images[value._img.src]._id + "," + value._style + ";"); | ||
} | ||
} | ||
else if (value._img instanceof GCanvasImage){ | ||
if (value._img instanceof GCanvasImage){ | ||
GBridge.bindImageTexture(this.componentId, [value._img.src, value._img.id], function(){}); | ||
this._drawCommands = this._drawCommands.concat("G" + value._img._id + "," + value._style + ";"); | ||
@@ -201,4 +185,5 @@ } | ||
else if (value instanceof FillStyleLinearGradient) { | ||
var command = "D" + value._start_pos._x + "," + value._start_pos._y + "," | ||
+ value._end_pos._x + "," + value._end_pos._y + "," + value._stop_count; | ||
var command = "D" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," | ||
+ value._end_pos._x.toFixed(2) + "," + value._end_pos._y.toFixed(2) + "," | ||
+ value._stop_count; | ||
@@ -209,7 +194,7 @@ for (var i = 0; i < value._stop_count; ++i) { | ||
this._drawCommands = this._drawCommands.concat(command + ";"); | ||
//console.log('createLinearGradient command -> ' + command); | ||
} | ||
else if (value instanceof FillStyleRadialGradient) { | ||
var command = "H" + value._start_pos._x + "," + value._start_pos._y + "," + value._start_pos._r + "," | ||
+ value._end_pos._x + "," + value._end_pos._y + "," + value._end_pos._r + "," + value._stop_count; | ||
var command = "H" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," + value._start_pos._r.toFixed(2) + "," | ||
+ value._end_pos._x.toFixed(2) + "," + value._end_pos._y + ",".toFixed(2) + value._end_pos._r.toFixed(2) + "," | ||
+ value._stop_count; | ||
@@ -220,3 +205,2 @@ for (var i = 0; i < value._stop_count; ++i) { | ||
this._drawCommands = this._drawCommands.concat(command + ";"); | ||
//console.log('FillStyleRadialGradient command -> ' + command); | ||
} | ||
@@ -239,4 +223,3 @@ } | ||
this._lineWidth = value; | ||
this._drawCommands = this._drawCommands.concat("W" + value | ||
+ ";"); | ||
this._drawCommands = this._drawCommands.concat("W" + value + ";"); | ||
} | ||
@@ -395,3 +378,2 @@ }); | ||
} | ||
}); | ||
@@ -439,3 +421,2 @@ | ||
} | ||
}); | ||
@@ -456,7 +437,5 @@ | ||
this._font = value; | ||
//this._apiContext.font = this._font; | ||
this._drawCommands = this._drawCommands.concat("j" + value + ";"); | ||
// } | ||
} | ||
}); | ||
@@ -485,4 +464,3 @@ | ||
var data = this._imageMap.get(image.src); | ||
if( data ) | ||
{ | ||
if( data ) { | ||
successCallback && successCallback(data); | ||
@@ -498,3 +476,2 @@ return; | ||
}else{ | ||
// GLog.d("GContext2D loadTexture errorCallback!"); | ||
errorCallback && errorCallback(e); | ||
@@ -695,44 +672,2 @@ } | ||
//------------------------------------------------- | ||
// iOS bindImageTexture 增加版本检测 | ||
// 手淘小于6.11.2.3, 天猫小于6.4.2 使用老接口 | ||
// 之后这段逻辑可以去掉 | ||
//------------------------------------------------- | ||
//ver1 < ver2, return true | ||
function versionLessThen(ver1, ver2) | ||
{ | ||
var arr1 = ver1.split('.'); | ||
var arr2 = ver2.split('.'); | ||
var len = Math.min(arr1.length, arr2.length); | ||
for (var i = 0; i < len; i++) | ||
{ | ||
var v1 = parseInt(arr1[i]); | ||
var v2 = parseInt(arr2[i]); | ||
if( v1 < v2 ) return true; | ||
else if( v1 > v2 ) return false; | ||
} | ||
return arr1.length < arr2.length; | ||
} | ||
function useNewAPI() | ||
{ | ||
var appName = WXEnvironment.appName.toUpperCase(); | ||
var appVersion = WXEnvironment.appVersion; | ||
if( (appName == "TB") && versionLessThen(appVersion, "6.11.2.3") ) //低于6.11.2.3的使用老接口 | ||
{ | ||
return false; | ||
} | ||
else if(appName == "TM" && versionLessThen(appVersion, "6.4.1.2") ) //低于6.4.1.2的使用老接口 | ||
{ | ||
return false; | ||
} | ||
//其他的都使用新接口 | ||
return true; | ||
} | ||
GContext2D.prototype.drawImage = function(image, // image | ||
@@ -747,33 +682,44 @@ sx, sy, sw, sh, // source (or destination if fewer args) | ||
var cacheKey = this.componentId + "_" + image.id; | ||
//Offscreen image is GCanvas instance | ||
if (typeof(image.componentId) != 'undefined') { | ||
var destComponentId = image.componentId; | ||
var gcanvasImage = new GCanvasImage(); | ||
gcanvasImage.width = image.width; | ||
gcanvasImage.height = image.height; | ||
// var imageCache = this._getImageTexture(image.src); | ||
var imageCache = this._getImageTexture(cacheKey); | ||
if( GBridge.isIOS() ){ | ||
gcanvasImage.src = "offscreen_" + destComponentId; | ||
//延迟调用 | ||
setTimeout(function(){ | ||
GBridge.bindImageTexture(that.componentId, [gcanvasImage.src, gcanvasImage.id], function(){}); | ||
that._concatDrawCmd(numArgs, gcanvasImage, sx, sy, sw, sh, dx, dy, dw, dh); | ||
}, 200 ); | ||
} else { | ||
gcanvasImage.id = 0; | ||
var destContext = image.context; | ||
destContext._drawCommands = destContext._drawCommands.concat("X"+this.componentId+";"); | ||
GBridge.callRender(this.componentId, "Y"+destComponentId+";"); | ||
this._concatDrawCmd(numArgs, gcanvasImage, sx, sy, sw, sh, dx, dy, dw, dh); | ||
} | ||
return; | ||
} | ||
if (imageCache) { | ||
this._concatDrawCmd(numArgs, image, sx, sy, sw, sh, dx, dy, dw, dh); | ||
return; | ||
} | ||
if( GBridge.isIOS() ) | ||
{ | ||
if( !that._checkVersionFlag ) | ||
{ | ||
that._useNewAPIFlag = useNewAPI(); | ||
that._checkVersionFlag = true; | ||
} | ||
var cacheKey = this.componentId + "_" + image.id; | ||
var imageCache = this._getImageTexture(cacheKey); | ||
if( that._useNewAPIFlag ){ | ||
GBridge.bindImageTexture(that.componentId, [image.src, image.id], function(){}); | ||
}else{ | ||
GBridge.bindImageTexture(that.componentId, image.src, function(){}); | ||
} | ||
that._concatDrawCmd(numArgs, image, sx, sy, sw, sh, dx, dy, dw, dh); | ||
// that._saveImageTexture(image.src, image); | ||
that._saveImageTexture(cacheKey, image); | ||
if (imageCache) { | ||
this._concatDrawCmd(numArgs, image, sx, sy, sw, sh, dx, dy, dw, dh); | ||
return; | ||
} | ||
if( GBridge.isIOS() ) | ||
{ | ||
GBridge.bindImageTexture(this.componentId, [image.src, image.id], function(){}); | ||
this._concatDrawCmd(numArgs, image, sx, sy, sw, sh, dx, dy, dw, dh); | ||
this._saveImageTexture(cacheKey, image); | ||
} | ||
else | ||
{ | ||
if(typeof callGCanvasLinkNative !== 'undefined') { | ||
// GLog.d('gcontext2d#drawImage() with callGCanvasLinkNative'); | ||
if(typeof callGCanvasLinkNative !== 'undefined') { | ||
GBridge.bindImageTexture(that.componentId, [image.src, image.id], function(e){ | ||
@@ -784,14 +730,12 @@ if( !e.error ) | ||
image.width = e.width; | ||
} | ||
} | ||
if(image.height === 0 && e.height > 0){ | ||
image.height = e.height; | ||
} | ||
that._concatDrawCmd(numArgs, image, sx, sy, sw, sh, dx, dy, dw, dh); | ||
// that._saveImageTexture(image.src, image); | ||
if(image.height === 0 && e.height > 0){ | ||
image.height = e.height; | ||
} | ||
that._concatDrawCmd(numArgs, image, sx, sy, sw, sh, dx, dy, dw, dh); | ||
that._saveImageTexture(cacheKey, image); | ||
} | ||
}); | ||
} else { | ||
} else { | ||
// GLog.d('gcontext2d#drawImage()'); | ||
@@ -801,17 +745,15 @@ GBridge.bindImageTexture(that.componentId, image.src, function(e){ | ||
{ | ||
if(image.width === 0 && e.width > 0){ | ||
image.width = e.width; | ||
} | ||
if(image.width === 0 && e.width > 0){ | ||
image.width = e.width; | ||
} | ||
if(image.height === 0 && e.height > 0){ | ||
image.height = e.height; | ||
} | ||
that._concatDrawCmd(numArgs, image, sx, sy, sw, sh, dx, dy, dw, dh); | ||
// that._saveImageTexture(image.src, image); | ||
that._saveImageTexture(cacheKey, image); | ||
} | ||
}); | ||
} | ||
} | ||
if(image.height === 0 && e.height > 0){ | ||
image.height = e.height; | ||
} | ||
that._concatDrawCmd(numArgs, image, sx, sy, sw, sh, dx, dy, dw, dh); | ||
that._saveImageTexture(cacheKey, image); | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
@@ -1095,10 +1037,8 @@ | ||
//TODO:不支持 | ||
GContext2D.prototype.isPointInPath = function(x,y) { | ||
return true; | ||
return false; | ||
}; | ||
///////////////////////////////////////////////////////////////// | ||
//base64 | ||
///////////////////////////////////////////////////////////////// | ||
@@ -1108,3 +1048,3 @@ | ||
///////////////////////////////////////////////////////////////// | ||
//GCanvasImage | ||
//GImageData | ||
///////////////////////////////////////////////////////////////// | ||
@@ -1111,0 +1051,0 @@ function GImageData(w, h) { |
@@ -125,7 +125,2 @@ ///////////////////////////////////////////////////////////////// | ||
return canvasModule.enable && canvasModule.enable(params); | ||
// canvasModule.enable(params, function (e) { | ||
// GLog.d('bridge#callEnable() return val:' + JSON.stringify(e)); | ||
// callback && callback(e); | ||
// }); | ||
}, | ||
@@ -182,4 +177,3 @@ | ||
* 设置日志级别 | ||
* | ||
* @param context_type 0代表2d,1代表3d | ||
* | ||
* */ | ||
@@ -195,3 +189,2 @@ setLogLevel: function (level){ | ||
* | ||
* @param context_type 0代表2d,1代表3d | ||
* */ | ||
@@ -198,0 +191,0 @@ setHiQuality: function (quality){ |
@@ -670,2 +670,3 @@ var GBridge = require("./gutil").GBridge; | ||
var result = GBridge.callExtendCallNative({"className":"WXGCanvasCallNative", "contextId": this.componentId, "type":type}); | ||
G_NeedRender = false; | ||
} else{ | ||
@@ -1329,3 +1330,4 @@ callGCanvasLinkNative(this.componentId,type,"render"); | ||
GContextWebGL.prototype.shaderSource = function(shader, source){ | ||
var cmd = (this.shaderSourceId + shader + "," + btoa(source) + ";"); | ||
// var cmd = (this.shaderSourceId + shader + "," + btoa(source) + ";"); | ||
var cmd = (this.shaderSourceId + shader + "," + source); | ||
WebGLCallNative(this.componentId, cmd); | ||
@@ -1410,4 +1412,16 @@ }; | ||
var cmd = (this.texImage2DId + argc + "," + target + "," + level + "," + internalformat + "," + | ||
width + "," + height + "," + border + "," + format + "," + type + "," + | ||
GetArrayType(array) + "," + GarrToBase64(array) + ";"); | ||
width + "," + height + "," + border + "," + format + "," + type + ","); | ||
if( array == null ) | ||
{ | ||
cmd = cmd + 0 + ";"; | ||
} | ||
else | ||
{ | ||
cmd = cmd + GetArrayType(array) + "," + GarrToBase64(array) + ";"; | ||
} | ||
// var cmd = (this.texImage2DId + argc + "," + target + "," + level + "," + internalformat + "," + | ||
// width + "," + height + "," + border + "," + format + "," + type + "," + | ||
// GetArrayType(array) + "," + GarrToBase64(array) + ";"); | ||
WebGLCallNative(this.componentId, cmd); | ||
@@ -1482,3 +1496,3 @@ } | ||
value = trans2ArrayType(type, value); | ||
var cmd = (cmdId + id + "," + GarrToBase64(value) + ";"); | ||
var cmd = (cmdId + id + "," + 0 + "," + GarrToBase64(value) + ";"); | ||
WebGLCallNative(this.componentId, cmd); | ||
@@ -1562,3 +1576,3 @@ }; | ||
return; | ||
var cmd = (apiId + location + "," + (transpose?1:0)) + "," + GarrToBase64(value) + (";"); | ||
var cmd = (apiId + location + "," + (transpose?1:0)) + ","+0+"," + GarrToBase64(value) + (";"); | ||
WebGLCallNative(this.componentId, cmd); | ||
@@ -1565,0 +1579,0 @@ }; |
{ | ||
"name": "weex-gcanvas", | ||
"version": "0.5.47", | ||
"version": "0.5.48", | ||
"main":"gcanvas.js", | ||
@@ -5,0 +5,0 @@ "platform": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
206066
5610