Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2095 from yurydelendik/gfxinterface
Browse files Browse the repository at this point in the history
Refactoring of the player sandbox interfaces
  • Loading branch information
yurydelendik committed Mar 4, 2015
2 parents 7f77cac + 1baa322 commit 0923dd2
Show file tree
Hide file tree
Showing 20 changed files with 543 additions and 303 deletions.
13 changes: 8 additions & 5 deletions examples/inspector/js/inspector.js
Expand Up @@ -186,9 +186,11 @@ function executeFile(file, buffer, movieParams, remoteDebugging) {
showMessage("Running in the Interpreter");
}

Shumway.SystemResourcesLoadingService.instance =
new Shumway.Player.BrowserSystemResourcesLoadingService(builtinPath, playerglobalInfo, shellAbcPath);

if (filename.endsWith(".abc")) {
libraryScripts = {};
Shumway.createAVM2(builtinPath, shellAbcPath, sysMode, appMode, function (avm2) {
Shumway.createAVM2(Shumway.AVM2LoadLibrariesFlags.Builtin | Shumway.AVM2LoadLibrariesFlags.Shell, sysMode, appMode).then(function (avm2) {
function runAbc(file, buffer) {
avm2.applicationDomain.executeAbc(new Shumway.AVM2.ABC.AbcFile(new Uint8Array(buffer), file));
}
Expand All @@ -201,7 +203,7 @@ function executeFile(file, buffer, movieParams, remoteDebugging) {
}
});
} else if (filename.endsWith(".swf")) {
Shumway.createAVM2(builtinPath, playerglobalInfo, sysMode, appMode, function (avm2) {
Shumway.createAVM2(Shumway.AVM2LoadLibrariesFlags.Builtin | Shumway.AVM2LoadLibrariesFlags.Playerglobal, sysMode, appMode).then(function (avm2) {
function runSWF(file, buffer) {
var swfURL = Shumway.FileLoadingService.instance.resolveUrl(file);

Expand All @@ -212,7 +214,8 @@ function executeFile(file, buffer, movieParams, remoteDebugging) {
easel.stage.invalidate();
});
syncGFXOptions(easel.options);
var player = new Shumway.Player.Test.TestPlayer();
var gfxService = new Shumway.Player.Test.TestGFXService();
var player = new Shumway.Player.Player(gfxService);
player.movieParams = movieParams;
player.stageAlign = state.salign;
player.stageScale = state.scale;
Expand Down Expand Up @@ -246,7 +249,7 @@ function executeFile(file, buffer, movieParams, remoteDebugging) {
}
});
} else if (filename.endsWith(".js") || filename.endsWith("/")) {
Shumway.createAVM2(builtinPath, playerglobalInfo, sysMode, appMode, function (avm2) {
Shumway.createAVM2(Shumway.AVM2LoadLibrariesFlags.Builtin | Shumway.AVM2LoadLibrariesFlags.Playerglobal, sysMode, appMode).then(function (avm2) {
executeUnitTests(file, avm2);
});
}
Expand Down
7 changes: 5 additions & 2 deletions examples/inspector/js/inspectorPlayer.js
Expand Up @@ -52,9 +52,12 @@ function runSwfPlayer(data) {
Shumway.FileLoadingService.instance = new Shumway.Player.BrowserFileLoadingService();
Shumway.FileLoadingService.instance.init(file, data.fileReadChunkSize);
}
Shumway.createAVM2(builtinPath, playerglobalInfo, sysMode, appMode, function (avm2) {
Shumway.SystemResourcesLoadingService.instance =
new Shumway.Player.BrowserSystemResourcesLoadingService(builtinPath, playerglobalInfo);
Shumway.createAVM2(Shumway.AVM2LoadLibrariesFlags.Builtin | Shumway.AVM2LoadLibrariesFlags.Playerglobal, sysMode, appMode).then(function (avm2) {
function runSWF(file) {
var player = new Shumway.Player.Window.WindowPlayer(window);
var gfxService = new Shumway.Player.Window.WindowGFXService(window);
var player = new Shumway.Player.Player(gfxService);
player.movieParams = movieParams;
player.stageAlign = stageAlign;
player.stageScale = stageScale;
Expand Down
7 changes: 5 additions & 2 deletions extension/firefox/content/web/viewerPlayer.js
Expand Up @@ -42,9 +42,12 @@ function runSwfPlayer(flashParams) {
Shumway.frameRateOption.value = flashParams.turboMode ? 60 : -1;
Shumway.AVM2.Verifier.enabled.value = compilerSettings.verifier;

Shumway.createAVM2(builtinPath, viewerPlayerglobalInfo, sysMode, appMode, function (avm2) {
Shumway.SystemResourcesLoadingService.instance =
new Shumway.Player.BrowserSystemResourcesLoadingService(builtinPath, viewerPlayerglobalInfo);
Shumway.createAVM2(Shumway.AVM2LoadLibrariesFlags.Builtin | Shumway.AVM2LoadLibrariesFlags.Playerglobal, sysMode, appMode).then(function (avm2) {
function runSWF(file, buffer, baseUrl) {
var player = new Shumway.Player.Window.WindowPlayer(window, window.parent);
var gfxService = new Shumway.Player.Window.WindowGFXService(window, window.parent);
var player = new Shumway.Player.Player(gfxService);
player.defaultStageColor = flashParams.bgcolor;
player.movieParams = flashParams.movieParams;
player.stageAlign = (objectParams && (objectParams.salign || objectParams.align)) || '';
Expand Down
33 changes: 4 additions & 29 deletions src/avm2/domain.ts
Expand Up @@ -103,29 +103,6 @@ module Shumway.AVM2.Runtime {
return null;
}

function promiseFile(path, responseType) {
return new Promise(function (resolve, reject) {
SWF.enterTimeline('Load file', path);
var xhr = new XMLHttpRequest();
xhr.open('GET', path);
xhr.responseType = responseType;
xhr.onload = function () {
SWF.leaveTimeline();
var response = xhr.response;
if (response) {
if (responseType === 'json' && xhr.responseType !== 'json') {
// some browsers (e.g. Safari) have no idea what json is
response = JSON.parse(response);
}
resolve(response);
} else {
reject('Unable to load ' + path + ': ' + xhr.statusText);
}
};
xhr.send();
});
}

enum StackFormat {
SpiderMonkey,
V8
Expand Down Expand Up @@ -197,12 +174,13 @@ module Shumway.AVM2.Runtime {
return !!playerglobal;
}

public static loadPlayerglobal(abcsPath, catalogPath) {
public static loadPlayerglobal(): Promise<any> {
if (playerglobalLoadedPromise) {
return Promise.reject('Playerglobal is already loaded');
}
playerglobalLoadedPromise = Promise.all([
promiseFile(abcsPath, 'arraybuffer'), promiseFile(catalogPath, 'json')]).
return Promise.all([
SystemResourcesLoadingService.instance.load(SystemResourceId.PlayerglobalAbcs),
SystemResourcesLoadingService.instance.load(SystemResourceId.PlayerglobalManifest)]).
then(function (result) {
playerglobal = {
abcs: result[0],
Expand All @@ -223,10 +201,7 @@ module Shumway.AVM2.Runtime {
}
}
}
}, function (e) {
console.error(e);
});
return playerglobalLoadedPromise;
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/base/remoting.ts
Expand Up @@ -197,4 +197,25 @@ module Shumway.Remoting {
screenWidth: number;
screenHeight: number;
}

export interface IGFXServiceObserver {
displayParameters(displayParameters: DisplayParameters);
focusEvent(data: any);
keyboardEvent(data: any);
mouseEvent(data: any);
videoEvent(id: number, eventType: VideoPlaybackEvent, data: any);
}

export interface IGFXService {
addObserver(observer: IGFXServiceObserver);
removeObserver(observer: IGFXServiceObserver);

update(updates: DataBuffer, assets: Array<DataBuffer>): void;
updateAndGet(updates: DataBuffer, assets: Array<DataBuffer>): any;
frame(): void;
videoControl(id: number, eventType: VideoControlEvent, data: any): any;
registerFont(syncId: number, data: any): Promise<any>;
registerImage(syncId: number, symbolId: number, data: any): Promise<any>;
fscommand(command: string, args: string): void;
}
}
15 changes: 15 additions & 0 deletions src/base/utilities.ts
Expand Up @@ -3421,6 +3421,21 @@ module Shumway {
export var instance: IFileLoadingService;
}

export enum SystemResourceId {
BuiltinAbc = 0,
PlayerglobalAbcs = 1,
PlayerglobalManifest = 2,
ShellAbc = 3
}

export interface ISystemResourcesLoadingService {
load(id: SystemResourceId): Promise<any>;
}

export module SystemResourcesLoadingService {
export var instance: ISystemResourcesLoadingService;
}

export function registerCSSFont(id: number, buffer: ArrayBuffer, forceFontInit: boolean) {
if (!inBrowser) {
Debug.warning('Cannot register CSS font outside the browser');
Expand Down
3 changes: 1 addition & 2 deletions src/flash/display/Loader.ts
Expand Up @@ -472,9 +472,8 @@ module Shumway.AVM2.AS.flash.display {
var symbol = BitmapSymbol.FromData(data);
this._imageSymbol = symbol;
var resolver: Timeline.IAssetResolver = AVM2.instance.globals['Shumway.Player.Utils'];
resolver.registerFontOrImage(symbol, data);
resolver.registerImage(symbol, data);
release || assert(symbol.resolveAssetPromise);
release || assert(symbol.ready === false);
}

private _applyDecodedImage(symbol: BitmapSymbol) {
Expand Down
17 changes: 15 additions & 2 deletions src/flash/display/LoaderInfo.ts
Expand Up @@ -370,12 +370,25 @@ module Shumway.AVM2.AS.flash.display {
release || assert(symbol, "Unknown symbol type " + data.type);
this._dictionary[id] = symbol;
if (symbol.ready === false) {
var resolver: Timeline.IAssetResolver = AVM2.Runtime.AVM2.instance.globals['Shumway.Player.Utils'];
resolver.registerFontOrImage(<Timeline.EagerlyResolvedSymbol><any>symbol, data);
this._registerFontOrImage(<Timeline.EagerlyResolvedSymbol><any>symbol, data);
}
return symbol;
}

private _registerFontOrImage(symbol: Timeline.EagerlyResolvedSymbol, data: any) {
var resolver: Timeline.IAssetResolver = AVM2.Runtime.AVM2.instance.globals['Shumway.Player.Utils'];
switch (data.type) {
case 'font':
resolver.registerFont(<Timeline.EagerlyResolvedSymbol><any>symbol, data);
break;
case 'image':
resolver.registerImage(<Timeline.EagerlyResolvedSymbol><any>symbol, data);
break;
default:
throw new Error('Unsupported assert type: ' + data.type);
}
}

getRootSymbol(): flash.display.SpriteSymbol {
release || assert(this._file instanceof SWFFile);
release || assert(this._file.framesLoaded > 0);
Expand Down
3 changes: 2 additions & 1 deletion src/flash/symbol.ts
Expand Up @@ -27,7 +27,8 @@ module Shumway.Timeline {
import ActionScriptVersion = flash.display.ActionScriptVersion;

export interface IAssetResolver {
registerFontOrImage(symbol: Timeline.EagerlyResolvedSymbol, data: any): void;
registerFont(symbol: Timeline.EagerlyResolvedSymbol, data: any): void;
registerImage(symbol: Timeline.EagerlyResolvedSymbol, data: any): void;
}

export interface EagerlyResolvedSymbol {
Expand Down
10 changes: 9 additions & 1 deletion src/gfx/test/testEaselHost.ts
Expand Up @@ -91,6 +91,14 @@ module Shumway.GFX.Test {
return Promise.resolve(buffer);
}

private _sendRegisterFontOrImageResponse(requestId: number, result: any) {
this._worker.postMessage({
type: 'registerFontOrImageResponse',
requestId: requestId,
result: result
});
}

_onWorkerMessage(e, async: boolean = true): any {
var data = e.data;
if (typeof data !== 'object' || data === null) {
Expand Down Expand Up @@ -118,7 +126,7 @@ module Shumway.GFX.Test {
break;
case 'registerFontOrImage':
this.processRegisterFontOrImage(data.syncId, data.symbolId, data.assetType, data.data,
data.resolve);
this._sendRegisterFontOrImageResponse.bind(this, data.requestId));
e.handled = true;
break;
case 'fscommand':
Expand Down
10 changes: 9 additions & 1 deletion src/gfx/window/windowEaselHost.ts
Expand Up @@ -80,6 +80,14 @@ module Shumway.GFX.Window {
}.bind(this));
}

private _sendRegisterFontOrImageResponse(requestId: number, result: any) {
this._playerWindow.postMessage({
type: 'registerFontOrImageResponse',
requestId: requestId,
result: result
}, '*');
}

private onWindowMessage(data, async: boolean = true) {
if (typeof data === 'object' && data !== null) {
if (data.type === 'player') {
Expand All @@ -97,7 +105,7 @@ module Shumway.GFX.Window {
data.result = this.processVideoControl(data.id, data.eventType, data.data);
} else if (data.type === 'registerFontOrImage') {
this.processRegisterFontOrImage(data.syncId, data.symbolId, data.assetType, data.data,
data.resolve);
this._sendRegisterFontOrImageResponse.bind(this, data.requestId));
} else if (data.type === 'fscommand') {
this.processFSCommand(data.command, data.args);
} else if (data.type === 'timelineResponse' && data.timeline) {
Expand Down
47 changes: 26 additions & 21 deletions src/player/avmLoader.ts
Expand Up @@ -21,19 +21,20 @@ module Shumway {
import assert = Shumway.Debug.assert;
import ExecutionMode = Shumway.AVM2.Runtime.ExecutionMode;

export interface LibraryPathInfo {
abcs: string;
catalog: string;
export enum AVM2LoadLibrariesFlags {
Builtin = 1,
Playerglobal = 2,
Shell = 4
}

export function createAVM2(builtinPath: string,
libraryPath: any, /* LibraryPathInfo | string */
sysMode: ExecutionMode, appMode: ExecutionMode,
next: (avm2: AVM2) => void) {
export function createAVM2(libraries: AVM2LoadLibrariesFlags,
sysMode: ExecutionMode,
appMode: ExecutionMode): Promise<AVM2> {
var avm2;
release || assert (builtinPath);
SWF.enterTimeline('Load file', builtinPath);
new BinaryFileReader(builtinPath).readAll(null, function (buffer) {
var result = new PromiseWrapper<AVM2>();
release || assert (!!(libraries & AVM2LoadLibrariesFlags.Builtin));
SWF.enterTimeline('Load builton.abc file');
SystemResourcesLoadingService.instance.load(SystemResourceId.BuiltinAbc).then(function (buffer) {
SWF.leaveTimeline();
AVM2.initialize(sysMode, appMode);
avm2 = AVM2.instance;
Expand All @@ -47,20 +48,24 @@ module Shumway {

// If library is shell.abc, then just go ahead and run it now since
// it's not worth doing it lazily given that it is so small.
if (typeof libraryPath === 'string') {
new BinaryFileReader(libraryPath).readAll(null, function (buffer) {
avm2.systemDomain.executeAbc(new AbcFile(new Uint8Array(buffer), <string>libraryPath));
next(avm2);
});
if (!!(libraries & AVM2LoadLibrariesFlags.Shell)) {
SystemResourcesLoadingService.instance.load(SystemResourceId.ShellAbc).then(function (buffer) {
avm2.systemDomain.executeAbc(new AbcFile(new Uint8Array(buffer), "shell.abc"));
result.resolve(avm2);
}, result.reject);
return;
}

var libraryPathInfo: LibraryPathInfo = libraryPath;
if (!AVM2.isPlayerglobalLoaded()) {
AVM2.loadPlayerglobal(libraryPathInfo.abcs, libraryPathInfo.catalog).then(function () {
next(avm2);
});
if (!!(libraries & AVM2LoadLibrariesFlags.Playerglobal) &&
!AVM2.isPlayerglobalLoaded()) {
AVM2.loadPlayerglobal().then(function () {
result.resolve(avm2);
}, result.reject);
return;
}
});

result.resolve(avm2);
}, result.reject);
return result.promise;
}
}

0 comments on commit 0923dd2

Please sign in to comment.