Skip to content

Commit

Permalink
Fix accessing webkitBackingStorePixelRatio of context on iOS10 (#26)
Browse files Browse the repository at this point in the history
On iOS 10 webkitBackingStorePixelRatio can be accessed only by using
instance of CanvasRenderingContext2D. Using Object.create(prototype)
in that case doesn't work so the only way to access that property is by
getting context 2d from canvas element.
  • Loading branch information
hinok authored and jondavidjohn committed Sep 23, 2016
1 parent 4f07a73 commit 34db1af
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules
npm-debug.log
18 changes: 10 additions & 8 deletions dist/hidpi-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
*/
(function(prototype) {

var pixelRatio = (function(context) {
var backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;
var pixelRatio = (function() {
var canvas = document.createElement('canvas'),
context = canvas.getContext('2d'),
backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;

return (window.devicePixelRatio || 1) / backingStore;
})(prototype),
})(),

forEach = function(obj, func) {
for (var p in obj) {
Expand Down
2 changes: 1 addition & 1 deletion dist/hidpi-canvas.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions src/CanvasRenderingContext2D.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
(function(prototype) {

var pixelRatio = (function(context) {
var backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;
var pixelRatio = (function() {
var canvas = document.createElement('canvas'),
context = canvas.getContext('2d'),
backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;

return (window.devicePixelRatio || 1) / backingStore;
})(prototype),
})(),

forEach = function(obj, func) {
for (var p in obj) {
Expand Down

0 comments on commit 34db1af

Please sign in to comment.