-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't use dirty rect putImageData option on platforms where it's buggy.
Fixes #95
- Loading branch information
Showing
2 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Chrome on Windows, Android and Chrome OS appears to be buggy when using the | ||
* dirty rect option of putImageData. This function returns true if we can use | ||
* it. | ||
* https://github.com/mihaip/infinite-mac/issues/95 | ||
*/ | ||
export function canUseCanvasDirtyRect(): boolean { | ||
if (cached !== undefined) { | ||
return cached; | ||
} | ||
|
||
cached = check(); | ||
return cached; | ||
} | ||
|
||
function check(): boolean { | ||
// Ideally we'd test for this bug via putImageData and getImageData, but | ||
// the read back pixels are OK (at least in simple test cases). | ||
const {userAgent} = navigator; | ||
if (!userAgent.includes("Chrome")) { | ||
return true; | ||
} | ||
return ( | ||
!userAgent.includes("Android") && | ||
!userAgent.includes("CrOS") && | ||
!userAgent.includes("Windows") | ||
); | ||
} | ||
|
||
let cached: boolean | undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters