[broadway] Make the surface object a plain js object, not the context

This commit is contained in:
Alexander Larsson
2011-04-06 09:46:49 +02:00
parent 9f848aaf30
commit 7c20d59411

View File

@ -94,21 +94,26 @@ var inputSocket = null;
function createSurface(id, x, y, width, height, isTemp) function createSurface(id, x, y, width, height, isTemp)
{ {
var surface = { id: id, x: x, y:y, width: width, height: height, isTemp: isTemp };
surface.drawQueue = [];
surface.transientParent = 0;
var canvas = document.createElement("canvas"); var canvas = document.createElement("canvas");
canvas.width = width; canvas.width = width;
canvas.height = height; canvas.height = height;
canvas.surfaceId = id; canvas.surface = surface;
canvas.style["position"] = "absolute"; canvas.style["position"] = "absolute";
canvas.style["left"] = x + "px"; canvas.style["left"] = x + "px";
canvas.style["top"] = y + "px"; canvas.style["top"] = y + "px";
canvas.style["display"] = "none"; canvas.style["display"] = "none";
document.body.appendChild(canvas);
surface.canvas = canvas;
var context = canvas.getContext("2d"); var context = canvas.getContext("2d");
context.globalCompositeOperation = "source-over"; context.globalCompositeOperation = "source-over";
document.body.appendChild(canvas); surface.context = context;
context.drawQueue = [];
context.isTemp = isTemp; surfaces[id] = surface;
context.transientParent = 0;
surfaces[id] = context;
} }
var GDK_CROSSING_NORMAL = 0; var GDK_CROSSING_NORMAL = 0;
@ -152,19 +157,17 @@ function flushSurface(surface)
{ {
var commands = surface.drawQueue; var commands = surface.drawQueue;
surface.queue = []; surface.queue = [];
var context = surface.context;
var i = 0; var i = 0;
for (i = 0; i < commands.length; i++) { for (i = 0; i < commands.length; i++) {
var cmd = commands[i]; var cmd = commands[i];
var context = surfaces[cmd.id];
switch (cmd.op) { switch (cmd.op) {
/* put image data surface */ case 'i': // put image data surface
case 'i':
context.globalCompositeOperation = "source-over"; context.globalCompositeOperation = "source-over";
context.drawImage(cmd.img, cmd.x, cmd.y); context.drawImage(cmd.img, cmd.x, cmd.y);
break; break;
/* copy rects */ case 'b': // copy rects
case 'b':
context.save(); context.save();
context.beginPath(); context.beginPath();
@ -293,8 +296,8 @@ function handleCommands(cmdObj)
surface.canvas.width = w; surface.canvas.width = w;
surface.canvas.height = h; surface.canvas.height = h;
surface.globalCompositeOperation = "copy"; surface.context.globalCompositeOperation = "copy";
surface.drawImage(tmpCanvas, 0, 0, tmpCanvas.width, tmpCanvas.height); surface.context.drawImage(tmpCanvas, 0, 0, tmpCanvas.width, tmpCanvas.height);
break; break;
@ -411,9 +414,9 @@ function handleLoad(event)
} }
function getSurfaceId(ev) { function getSurfaceId(ev) {
var id = ev.target.surfaceId; var surface = ev.target.surface;
if (id != undefined) if (surface != undefined)
return id; return surface.id;
return 0; return 0;
} }