P.clear = function () {
const {element, engine, backgroundColor, clearAlpha, currentDimensions} = this;
const [width, height] = currentDimensions;
this.prepareStamp();
let dpr = checkEngineScale(engine);
let w = width * dpr,
h = height * dpr;
if (this.useAsPattern) {
element.width = width;
element.height = height;
}
if (backgroundColor) {
engine.save();
engine.fillStyle = backgroundColor;
engine.globalCompositeOperation = 'source-over';
engine.globalAlpha = 1;
engine.fillRect(0, 0, width, height);
engine.restore();
}
else if (clearAlpha) {
engine.save();
let tempCell = requestCell();
let {engine:tempEngine, element:tempEl} = tempCell;
if (this.useAsPattern) {
tempEl.width = width;
tempEl.height = height;
tempEngine.drawImage(element, 0, 0, width, height, 0, 0, width, height);
engine.clearRect(0, 0, width, height);
engine.globalAlpha = clearAlpha;
engine.drawImage(tempEl, 0, 0, width, height, 0, 0, width, height);
}
else {
tempEl.width = w;
tempEl.height = h;
tempEngine.drawImage(element, 0, 0, width, height, 0, 0, width, height);
engine.clearRect(0, 0, width, height);
engine.globalAlpha = clearAlpha;
engine.drawImage(tempEl, 0, 0, w, h, 0, 0, width, height);
}
engine.restore();
releaseCell(tempCell);
}
else engine.clearRect(0, 0, width, height);
};