Skip to content

Instantly share code, notes, and snippets.

@ochameau
Created June 21, 2018 08:18
Show Gist options
  • Save ochameau/e73ac190b11567369436056c7b2c2f2c to your computer and use it in GitHub Desktop.
Save ochameau/e73ac190b11567369436056c7b2c2f2c to your computer and use it in GitHub Desktop.
commit 816bb258dfd315b5c2385e4ced6ac2e6a91b5c4f
Author: Alexandre Poirot <[email protected]>
Date: Wed Jun 20 14:28:06 2018 -0700
refactor shader editor initializer.
MozReview-Commit-ID: sLVVmv8ZUF
diff --git a/devtools/client/definitions.js b/devtools/client/definitions.js
index 75dd62686eb67..c2552eccb9d9f 100644
--- a/devtools/client/definitions.js
+++ b/devtools/client/definitions.js
@@ -6,6 +6,7 @@
const Services = require("Services");
const osString = Services.appinfo.OS;
+const { Cu } = require("chrome");
// Panels
loader.lazyGetter(this, "OptionsPanel", () => require("devtools/client/framework/toolbox-options").OptionsPanel);
@@ -14,7 +15,6 @@ loader.lazyGetter(this, "WebConsolePanel", () => require("devtools/client/webcon
loader.lazyGetter(this, "DebuggerPanel", () => require("devtools/client/debugger/panel").DebuggerPanel);
loader.lazyGetter(this, "NewDebuggerPanel", () => require("devtools/client/debugger/new/panel").DebuggerPanel);
loader.lazyGetter(this, "StyleEditorPanel", () => require("devtools/client/styleeditor/styleeditor-panel").StyleEditorPanel);
-loader.lazyGetter(this, "ShaderEditorPanel", () => require("devtools/client/shadereditor/panel").ShaderEditorPanel);
loader.lazyGetter(this, "CanvasDebuggerPanel", () => require("devtools/client/canvasdebugger/panel").CanvasDebuggerPanel);
loader.lazyGetter(this, "WebAudioEditorPanel", () => require("devtools/client/webaudioeditor/panel").WebAudioEditorPanel);
loader.lazyGetter(this, "MemoryPanel", () => require("devtools/client/memory/panel").MemoryPanel);
@@ -219,7 +219,7 @@ Tools.shaderEditor = {
ordinal: 5,
visibilityswitch: "devtools.shadereditor.enabled",
icon: "chrome://devtools/skin/images/tool-shadereditor.svg",
- url: "chrome://devtools/content/shadereditor/shadereditor.xul",
+ url: "chrome://devtools/content/shadereditor/index.xul",
label: l10n("ToolboxShaderEditor.label"),
panelLabel: l10n("ToolboxShaderEditor.panelLabel"),
tooltip: l10n("ToolboxShaderEditor.tooltip"),
@@ -229,7 +229,13 @@ Tools.shaderEditor = {
},
build: function(iframeWindow, toolbox) {
- return new ShaderEditorPanel(iframeWindow, toolbox);
+ const { BrowserLoader } = Cu.import("resource://devtools/client/shared/browser-loader.js", {});
+ const browserRequire = BrowserLoader({
+ baseURI: "resource://devtools/client/shadereditor/",
+ window: iframeWindow
+ }).require;
+ const { ShaderEditorPanel } = browserRequire("devtools/client/shadereditor/panel");
+ return new ShaderEditorPanel(toolbox);
}
};
diff --git a/devtools/client/jar.mn b/devtools/client/jar.mn
index 4b8f55c9e7472..33dbe7fec1515 100644
--- a/devtools/client/jar.mn
+++ b/devtools/client/jar.mn
@@ -44,8 +44,7 @@ devtools.jar:
content/debugger/views/stack-frames-classic-view.js (debugger/views/stack-frames-classic-view.js)
content/debugger/views/filter-view.js (debugger/views/filter-view.js)
content/debugger/utils.js (debugger/utils.js)
- content/shadereditor/shadereditor.xul (shadereditor/shadereditor.xul)
- content/shadereditor/shadereditor.js (shadereditor/shadereditor.js)
+ content/shadereditor/index.xul (shadereditor/index.xul)
content/canvasdebugger/canvasdebugger.xul (canvasdebugger/canvasdebugger.xul)
content/canvasdebugger/canvasdebugger.js (canvasdebugger/canvasdebugger.js)
content/canvasdebugger/snapshotslist.js (canvasdebugger/snapshotslist.js)
diff --git a/devtools/client/shadereditor/shadereditor.xul b/devtools/client/shadereditor/index.xul
similarity index 97%
rename from devtools/client/shadereditor/shadereditor.xul
rename to devtools/client/shadereditor/index.xul
index 1582d27739801..e42a06f94b5f8 100644
--- a/devtools/client/shadereditor/shadereditor.xul
+++ b/devtools/client/shadereditor/index.xul
@@ -16,8 +16,6 @@
<script type="application/javascript"
src="chrome://devtools/content/shared/theme-switching.js"/>
- <script type="application/javascript" src="shadereditor.js"/>
-
<vbox class="theme-body" flex="1">
<hbox id="reload-notice"
class="notice-container"
diff --git a/devtools/client/shadereditor/moz.build b/devtools/client/shadereditor/moz.build
index 4e8337dfae73e..327f02cdbe2a9 100644
--- a/devtools/client/shadereditor/moz.build
+++ b/devtools/client/shadereditor/moz.build
@@ -4,7 +4,8 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DevToolsModules(
- 'panel.js'
+ 'panel.js',
+ 'shadereditor.js'
)
BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
diff --git a/devtools/client/shadereditor/panel.js b/devtools/client/shadereditor/panel.js
index 4a452f0286bdb..b0332beab7a29 100644
--- a/devtools/client/shadereditor/panel.js
+++ b/devtools/client/shadereditor/panel.js
@@ -9,11 +9,13 @@ const promise = require("promise");
const EventEmitter = require("devtools/shared/event-emitter");
const { WebGLFront } = require("devtools/shared/fronts/webgl");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
+const { startupShaderEditor, shutdownShaderEditor,
+ EventsHandler, ShadersListView, ShadersEditorsView, EVENTS } = require("./shadereditor");
-function ShaderEditorPanel(iframeWindow, toolbox) {
- this.panelWin = iframeWindow;
+function ShaderEditorPanel(toolbox) {
this._toolbox = toolbox;
this._destroyer = null;
+ this.panelWin = window;
EventEmitter.decorate(this);
}
@@ -21,6 +23,12 @@ function ShaderEditorPanel(iframeWindow, toolbox) {
exports.ShaderEditorPanel = ShaderEditorPanel;
ShaderEditorPanel.prototype = {
+
+ EventsHandler,
+ ShadersListView,
+ ShadersEditorsView,
+ EVENTS,
+
/**
* Open is effectively an asynchronous constructor.
*
@@ -39,10 +47,12 @@ ShaderEditorPanel.prototype = {
return targetPromise
.then(() => {
- this.panelWin.gToolbox = this._toolbox;
- this.panelWin.gTarget = this.target;
- this.panelWin.gFront = new WebGLFront(this.target.client, this.target.form);
- return this.panelWin.startupShaderEditor();
+ this.front = new WebGLFront(this.target.client, this.target.form);
+ return startupShaderEditor({
+ toolbox: this._toolbox,
+ target: this.target,
+ front: this.front,
+ });
})
.then(() => {
this.isReady = true;
@@ -66,9 +76,9 @@ ShaderEditorPanel.prototype = {
return this._destroyer;
}
- return (this._destroyer = this.panelWin.shutdownShaderEditor().then(() => {
+ return (this._destroyer = shutdownShaderEditor().then(() => {
// Destroy front to ensure packet handler is removed from client
- this.panelWin.gFront.destroy();
+ this.front.destroy();
this.emit("destroyed");
}));
}
diff --git a/devtools/client/shadereditor/shadereditor.js b/devtools/client/shadereditor/shadereditor.js
index c66984a69ae5d..d0376fb4633d5 100644
--- a/devtools/client/shadereditor/shadereditor.js
+++ b/devtools/client/shadereditor/shadereditor.js
@@ -3,11 +3,8 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
-/* exported startupShaderEditor, shutdownShaderEditor */
-
-const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
const {XPCOMUtils} = require("resource://gre/modules/XPCOMUtils.jsm");
-const {SideMenuWidget} = require("resource://devtools/client/shared/widgets/SideMenuWidget.jsm");
+const {SideMenuWidget} = require("devtools/client/shared/widgets/SideMenuWidget.jsm");
const promise = require("promise");
const defer = require("devtools/shared/defer");
const {Task} = require("devtools/shared/task");
@@ -42,7 +39,7 @@ const EVENTS = {
// When the editor's error markers are all removed
EDITOR_ERROR_MARKERS_REMOVED: "ShaderEditor:EditorCleaned"
};
-XPCOMUtils.defineConstant(this, "EVENTS", EVENTS);
+exports.EVENTS = EVENTS;
const STRINGS_URI = "devtools/client/locales/shadereditor.properties";
const HIGHLIGHT_TINT = [1, 0, 0.25, 1]; // rgba
@@ -64,13 +61,17 @@ var gToolbox, gTarget, gFront;
/**
* Initializes the shader editor controller and views.
*/
-function startupShaderEditor() {
+function startupShaderEditor({ toolbox, target, front }) {
+ gToolbox = toolbox;
+ gTarget = target;
+ gFront = front;
return promise.all([
EventsHandler.initialize(),
ShadersListView.initialize(),
ShadersEditorsView.initialize()
]);
}
+exports.startupShaderEditor = startupShaderEditor;
/**
* Destroys the shader editor controller and views.
@@ -82,6 +83,7 @@ function shutdownShaderEditor() {
ShadersEditorsView.destroy()
]);
}
+exports.shutdownShaderEditor = shutdownShaderEditor;
/**
* Functions handling target-related lifetime events.
@@ -190,6 +192,7 @@ var EventsHandler = {
ShadersListView.addProgram(programActor);
}
};
+exports.EventsHandler = EventsHandler;
/**
* Functions handling the sources UI.
@@ -358,6 +361,7 @@ var ShadersListView = extend(WidgetMethods, {
}
}
});
+exports.ShadersListView = ShadersListView;
/**
* Functions handling the editors displaying the vertex and fragment shaders.
@@ -617,6 +621,7 @@ var ShadersEditorsView = {
fs: []
}
};
+exports.ShadersEditorsView = ShadersEditorsView;
/**
* Localization convenience methods.
@@ -626,7 +631,7 @@ var L10N = new LocalizationHelper(STRINGS_URI);
/**
* Convenient way of emitting events from the panel window.
*/
-EventEmitter.decorate(this);
+EventEmitter.decorate(window);
/**
* DOM query helper.
diff --git a/devtools/client/shadereditor/test/browser_se_editors-contents.js b/devtools/client/shadereditor/test/browser_se_editors-contents.js
index a36d7b6f874b5..dc8fb626afe3e 100644
--- a/devtools/client/shadereditor/test/browser_se_editors-contents.js
+++ b/devtools/client/shadereditor/test/browser_se_editors-contents.js
@@ -8,11 +8,11 @@
async function ifWebGLSupported() {
const { target, panel } = await initShaderEditor(SIMPLE_CANVAS_URL);
- const { gFront, ShadersEditorsView, EVENTS } = panel.panelWin;
+ const { front, ShadersEditorsView, EVENTS } = panel;
reload(target);
await promise.all([
- once(gFront, "program-linked"),
+ once(front, "program-linked"),
once(panel.panelWin, EVENTS.SOURCES_SHOWN)
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment