Fixes behaviour of DOMCanvasFactory to return {canvas, context}.
This commit is contained in:
parent
3e5c6e4287
commit
41d092d04b
@ -207,23 +207,22 @@ var CachedCanvases = (function CachedCanvasesClosure() {
|
|||||||
var canvasEntry;
|
var canvasEntry;
|
||||||
if (this.cache[id] !== undefined) {
|
if (this.cache[id] !== undefined) {
|
||||||
canvasEntry = this.cache[id];
|
canvasEntry = this.cache[id];
|
||||||
this.canvasFactory.reset(canvasEntry.canvas, width, height);
|
this.canvasFactory.reset(canvasEntry, width, height);
|
||||||
// reset canvas transform for emulated mozCurrentTransform, if needed
|
// reset canvas transform for emulated mozCurrentTransform, if needed
|
||||||
canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
|
canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
var canvas = this.canvasFactory.create(width, height);
|
canvasEntry = this.canvasFactory.create(width, height);
|
||||||
var ctx = canvas.getContext('2d');
|
this.cache[id] = canvasEntry;
|
||||||
if (trackTransform) {
|
}
|
||||||
addContextCurrentTransform(ctx);
|
if (trackTransform) {
|
||||||
}
|
addContextCurrentTransform(canvasEntry.context);
|
||||||
this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
|
|
||||||
}
|
}
|
||||||
return canvasEntry;
|
return canvasEntry;
|
||||||
},
|
},
|
||||||
clear: function () {
|
clear: function () {
|
||||||
for (var id in this.cache) {
|
for (var id in this.cache) {
|
||||||
var canvasEntry = this.cache[id];
|
var canvasEntry = this.cache[id];
|
||||||
this.canvasFactory.destroy(canvasEntry.canvas);
|
this.canvasFactory.destroy(canvasEntry);
|
||||||
delete this.cache[id];
|
delete this.cache[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1440,7 +1439,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
get isFontSubpixelAAEnabled() {
|
get isFontSubpixelAAEnabled() {
|
||||||
// Checks if anti-aliasing is enabled when scaled text is painted.
|
// Checks if anti-aliasing is enabled when scaled text is painted.
|
||||||
// On Windows GDI scaled fonts looks bad.
|
// On Windows GDI scaled fonts looks bad.
|
||||||
var ctx = this.canvasFactory.create(10, 10).getContext('2d');
|
var ctx = this.canvasFactory.create(10, 10).context;
|
||||||
ctx.scale(1.5, 1);
|
ctx.scale(1.5, 1);
|
||||||
ctx.fillText('I', 0, 10);
|
ctx.fillText('I', 0, 10);
|
||||||
var data = ctx.getImageData(0, 0, 10, 10).data;
|
var data = ctx.getImageData(0, 0, 10, 10).data;
|
||||||
|
@ -39,24 +39,30 @@ DOMCanvasFactory.prototype = {
|
|||||||
create: function DOMCanvasFactory_create(width, height) {
|
create: function DOMCanvasFactory_create(width, height) {
|
||||||
assert(width > 0 && height > 0, 'invalid canvas size');
|
assert(width > 0 && height > 0, 'invalid canvas size');
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
|
var context = canvas.getContext('2d');
|
||||||
canvas.width = width;
|
canvas.width = width;
|
||||||
canvas.height = height;
|
canvas.height = height;
|
||||||
return canvas;
|
return {
|
||||||
|
canvas: canvas,
|
||||||
|
context: context,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
reset: function DOMCanvasFactory_reset(canvas, width, height) {
|
reset: function DOMCanvasFactory_reset(canvasAndContextPair, width, height) {
|
||||||
assert(canvas, 'canvas is not specified');
|
assert(canvasAndContextPair.canvas, 'canvas is not specified');
|
||||||
assert(width > 0 && height > 0, 'invalid canvas size');
|
assert(width > 0 && height > 0, 'invalid canvas size');
|
||||||
canvas.width = width;
|
canvasAndContextPair.canvas.width = width;
|
||||||
canvas.height = height;
|
canvasAndContextPair.canvas.height = height;
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy: function DOMCanvasFactory_destroy(canvas) {
|
destroy: function DOMCanvasFactory_destroy(canvasAndContextPair) {
|
||||||
assert(canvas, 'canvas is not specified');
|
assert(canvasAndContextPair.canvas, 'canvas is not specified');
|
||||||
// Zeroing the width and height cause Firefox to release graphics
|
// Zeroing the width and height cause Firefox to release graphics
|
||||||
// resources immediately, which can greatly reduce memory consumption.
|
// resources immediately, which can greatly reduce memory consumption.
|
||||||
canvas.width = 0;
|
canvasAndContextPair.canvas.width = 0;
|
||||||
canvas.height = 0;
|
canvasAndContextPair.canvas.height = 0;
|
||||||
|
canvasAndContextPair.canvas = null;
|
||||||
|
canvasAndContextPair.context = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user