Skip to content

Commit 2c8f7c4

Browse files
committed
handle updated regl cache mechanism
1 parent aec12ef commit 2c8f7c4

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

devtools/regl_codegen/devtools.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
var mocks = require('../../build/test_dashboard_mocks.json');
66
var reglTraces = require('../../build/regl_traces.json');
77
var Lib = require('@src/lib');
8+
const { fillGroupStyle } = require('../../src/components/drawing');
89

910
// Our gracious testing object
1011
var Tabs = {
@@ -59,7 +60,6 @@ var Tabs = {
5960
graphDiv.on('plotly_afterplot', function() {
6061
res(graphDiv);
6162
});
62-
6363

6464
} else {
6565
console.error(this.statusText);
@@ -107,7 +107,7 @@ async function handleOnLoad() {
107107
a.innerHTML = mock.name;
108108
a.href = '#' + mock.name;
109109
a.onclick = function() {
110-
Tabs.plotMock(this.innerHTML);
110+
Tabs.plotMock(this.innerHTML)
111111
};
112112
div.appendChild(a);
113113
div.appendChild(document.createElement('br'));
@@ -117,16 +117,25 @@ async function handleOnLoad() {
117117
// visit the mocks one by one.
118118
for (var trace of Object.keys(mocksByReglTrace)) {
119119
var thisMocks = mocksByReglTrace[trace];
120+
var generated = {}
120121
for (var mock of thisMocks) {
121-
await Tabs.plotMock(mock.name);
122+
var gd = await Tabs.plotMock(mock.name);
123+
var fullLayout = gd._fullLayout;
124+
fullLayout._glcanvas.each(function (d) {
125+
if (d.regl) {
126+
console.log("found regl", d.regl);
127+
var cachedCode = d.regl.getCachedCode();
128+
Object.entries(cachedCode).forEach(([hash, code]) => {
129+
generated[hash] = code.toString();
130+
});
131+
console.log("merging entries", Object.keys(cachedCode));
132+
}
133+
})
122134
}
123135

124136
console.log(window.__regl_codegen_cache);
125137
var body = JSON.stringify({
126-
generated: Object.entries(window.__regl_codegen_cache).reduce((acc, [key, value]) => {
127-
acc[key] = value.toString();
128-
return acc;
129-
}, {}),
138+
generated,
130139
trace: trace
131140
});
132141
window.__regl_codegen_cache = {};

src/lib/prepare_regl.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ var showNoWebGlMsg = require('./show_no_webgl_msg');
88
// regl and all its bytes.
99
var createRegl = require('regl');
1010

11-
12-
function loadCodegenCache(generated) {
13-
window.__regl_codegen_cache = window.__regl_codegen_cache || {};
14-
Object.entries(generated).forEach(function([key, value]) {
15-
window.__regl_codegen_cache[key] = window.__regl_codegen_cache[key] || value;
16-
});
17-
}
18-
1911
/**
2012
* Idempotent version of createRegl. Create regl instances
2113
* in the correct canvases with the correct attributes and
@@ -27,15 +19,16 @@ function loadCodegenCache(generated) {
2719
* @return {boolean} true if all createRegl calls succeeded, false otherwise
2820
*/
2921
module.exports = function prepareRegl(gd, extensions, reglPrecompiled) {
22+
console.log("Somethign is happeneing");
3023
var fullLayout = gd._fullLayout;
3124
var success = true;
3225

33-
if (reglPrecompiled) {
34-
loadCodegenCache(reglPrecompiled);
35-
}
36-
3726
fullLayout._glcanvas.each(function(d) {
38-
if(d.regl) return;
27+
if(d.regl) {
28+
console.log("Preloading existing regl", Object.keys(reglPrecompiled));
29+
d.regl.preloadCachedCode(reglPrecompiled);
30+
return;
31+
}
3932
// only parcoords needs pick layer
4033
if(d.pick && !fullLayout._has('parcoords')) return;
4134

@@ -47,9 +40,11 @@ module.exports = function prepareRegl(gd, extensions, reglPrecompiled) {
4740
preserveDrawingBuffer: true
4841
},
4942
pixelRatio: gd._context.plotGlPixelRatio || global.devicePixelRatio,
50-
extensions: extensions || []
43+
extensions: extensions || [],
44+
cachedCode: reglPrecompiled || {}
5145
});
5246
} catch(e) {
47+
throw e;
5348
success = false;
5449
}
5550

0 commit comments

Comments
 (0)