Title: [286610] trunk/Websites/webkit.org
Revision
286610
Author
[email protected]
Date
2021-12-07 12:51:03 -0800 (Tue, 07 Dec 2021)

Log Message

Puzzle feature detection followup
https://bugs.webkit.org/show_bug.cgi?id=233946

Unreviewed.


* blog-files/wide-gamut-canvas/puzzle.html:

Modified Paths

Diff

Modified: trunk/Websites/webkit.org/ChangeLog (286609 => 286610)


--- trunk/Websites/webkit.org/ChangeLog	2021-12-07 20:42:25 UTC (rev 286609)
+++ trunk/Websites/webkit.org/ChangeLog	2021-12-07 20:51:03 UTC (rev 286610)
@@ -1,5 +1,14 @@
 2021-12-07  Cameron McCormack  <[email protected]>
 
+        Puzzle feature detection followup
+        https://bugs.webkit.org/show_bug.cgi?id=233946
+
+        Unreviewed.
+
+        * blog-files/wide-gamut-canvas/puzzle.html:
+
+2021-12-07  Cameron McCormack  <[email protected]>
+
         Tweak puzzle to use feature detection
         https://bugs.webkit.org/show_bug.cgi?id=233946
 

Modified: trunk/Websites/webkit.org/blog-files/wide-gamut-canvas/puzzle.html (286609 => 286610)


--- trunk/Websites/webkit.org/blog-files/wide-gamut-canvas/puzzle.html	2021-12-07 20:42:25 UTC (rev 286609)
+++ trunk/Websites/webkit.org/blog-files/wide-gamut-canvas/puzzle.html	2021-12-07 20:51:03 UTC (rev 286610)
@@ -31,6 +31,7 @@
 const EMPTY_SQUARE = SIZE * SIZE - 1;
 const TILE_CORNER_RADIUS = 8;
 
+let supported = false;
 let width, height, board, blank;
 let canvas, ctx;
 let scale = 1;
@@ -68,7 +69,21 @@
     return "data:image/svg+xml;base64," + btoa(svg);
 }
 
+function canvasSupportsDisplayP3() {
+    let canvas = document.createElement("canvas");
+    try {
+        let context = canvas.getContext("2d", { colorSpace: "display-p3" });
+        return context.getContextAttributes().colorSpace == "display-p3";
+    } catch {
+    }
+    return false;
+}
+
 function init() {
+    supported = canvasSupportsDisplayP3();
+    if (!supported)
+        document.body.className = "unsupported";
+
     canvas = placeholder;
     width = image.naturalWidth;
     height = image.naturalHeight;
@@ -163,7 +178,7 @@
 }
 
 function updateCanvas() {
-    let colorSpace = displayP3.checked ? "display-p3" : "srgb";
+    let colorSpace = displayP3.checked && supported ? "display-p3" : "srgb";
 
     let newCanvas = cachedCanvases[colorSpace];
     if (newCanvas != canvas) {
@@ -182,12 +197,7 @@
     canvas.style.width = `${width / scale}px`;
     canvas.style.height = `${height / scale}px`;
 
-    try {
-        ctx = canvas.getContext("2d", { colorSpace });
-    } catch {
-        ctx = canvas.getContext("2d");
-        document.body.className = "unsupported";
-    }
+    ctx = canvas.getContext("2d", { colorSpace });
 
     drawBoard();
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to