mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-19 08:33:24 +02:00
Start to add canvas auto-scaling for retina.
This commit is contained in:
@@ -1,6 +1,29 @@
|
||||
function CanvasRender(canvasElement, options) {
|
||||
this.options = options
|
||||
this.context = canvasElement.getContext('2d')
|
||||
|
||||
var devicePixelRatio = window.devicePixelRatio || 1
|
||||
|
||||
var backingStoreRatio = this.context.webkitBackingStorePixelRatio ||
|
||||
this.context.mozBackingStorePixelRatio ||
|
||||
this.context.msBackingStorePixelRatio ||
|
||||
this.context.oBackingStorePixelRatio ||
|
||||
this.context.backingStorePixelRatio || 1
|
||||
|
||||
this.frontBackRatio = devicePixelRatio / backingStoreRatio
|
||||
|
||||
if (options.autoScaleForRetina && devicePixelRatio !== backingStoreRatio) {
|
||||
var oldWidth = canvas.width;
|
||||
var oldHeight = canvas.height;
|
||||
|
||||
canvasElement.width = oldWidth * this.frontBackRatio
|
||||
canvasElement.height = oldHeight * this.frontBackRatio
|
||||
|
||||
canvasElement.style.width = oldWidth + 'px'
|
||||
canvasElement.style.height = oldHeight + 'px'
|
||||
|
||||
this.context.scale(this.frontBackRatio, this.frontBackRatio)
|
||||
}
|
||||
}
|
||||
|
||||
CanvasRender.prototype.draw = function (image) {
|
||||
|
||||
Reference in New Issue
Block a user