From b6fdf4d6ab815718d3e3210a0947f25850f1df52 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 19 Jun 2015 16:02:52 -0700 Subject: [PATCH] [Plot] Fall back from WebGL on context loss When a WebGL context is loss, fall back to displaying plots using regular canvas 2d API. WTD-475. --- platform/features/plot/src/MCTChart.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platform/features/plot/src/MCTChart.js b/platform/features/plot/src/MCTChart.js index d07eb398aa..2ca51b2309 100644 --- a/platform/features/plot/src/MCTChart.js +++ b/platform/features/plot/src/MCTChart.js @@ -155,6 +155,7 @@ define( } } + // Switch from WebGL to plain 2D if context is lost function fallbackFromWebGL() { element.html(TEMPLATE); canvas = element.find("canvas")[0]; @@ -173,6 +174,11 @@ define( return; } + // WebGL is a bit of a special case; it may work, then fail + // later for various reasons, so we need to listen for this + // and fall back to plain canvas drawing when it occurs. + canvas.addEventListener("webglcontextlost", fallbackFromWebGL); + // Check for resize, on a timer activeInterval = $interval(drawIfResized, 1000);