forked from ampproject/worker-dom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,069 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { WorkerContext } from "../worker"; | ||
import { TransferrableKeys } from "../../transfer/TransferrableKeys"; | ||
import { MessageType } from "../../transfer/Messages"; | ||
import { NodeContext } from "../nodes"; | ||
import { TransferrableMutationRecord } from "../../transfer/TransferrableRecord"; | ||
import { NumericBoolean } from "../../utils"; | ||
|
||
declare var OffscreenCanvas: any; | ||
|
||
export class OffscreenCanvasProcessor { | ||
private nodeContext: NodeContext; | ||
private workerContext: WorkerContext; | ||
|
||
constructor(nodeContext: NodeContext, workerContext: WorkerContext) { | ||
this.nodeContext = nodeContext; | ||
this.workerContext = workerContext; | ||
} | ||
|
||
process(mutation: TransferrableMutationRecord): void { | ||
const nodeId = mutation[TransferrableKeys.target]; | ||
const target = this.nodeContext.getNode(nodeId); | ||
|
||
if (!target) { | ||
console.error('getNode() yields a null value. Node id (' + nodeId + ') was not found.'); | ||
return; | ||
} | ||
|
||
// Probably should find a way to pass in w and h | ||
const offscreenCanvasInstance = new OffscreenCanvas(100, 100); | ||
|
||
this.workerContext.messageToWorker({ | ||
[TransferrableKeys.type]: MessageType.OFFSCREEN_CANVAS_INSTANCE, | ||
[TransferrableKeys.target]: { | ||
// This is a TransferredNode (index: number, transferred: NumericBoolean) | ||
[TransferrableKeys.index]: target._index_, | ||
[TransferrableKeys.transferred]: NumericBoolean.TRUE, | ||
}, // TransferredNode - canvas element???? | ||
[TransferrableKeys.data]: offscreenCanvasInstance, // Object, an OffscreenCanvas | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.