broadway: Actually upload textures to client

This commit is contained in:
Alexander Larsson 2017-11-18 17:36:38 +01:00
parent ef79621c44
commit a4636a06a7
5 changed files with 69 additions and 1 deletions

View File

@ -330,3 +330,23 @@ broadway_output_put_buffer (BroadwayOutput *output,
g_object_unref (out);
g_object_unref (out_mem);
}
void
broadway_output_upload_texture (BroadwayOutput *output,
guint32 id,
GBytes *texture)
{
gsize len = g_bytes_get_size (texture);
write_header (output, BROADWAY_OP_UPLOAD_TEXTURE);
append_uint32 (output, id);
append_uint32 (output, (guint32)len);
g_string_append_len (output->buf, g_bytes_get_data (texture, NULL), len);
}
void
broadway_output_release_texture (BroadwayOutput *output,
guint32 id)
{
write_header (output, BROADWAY_OP_RELEASE_TEXTURE);
append_uint32 (output, id);
}

View File

@ -58,6 +58,11 @@ void broadway_output_put_buffer (BroadwayOutput *output,
int id,
BroadwayBuffer *prev_buffer,
BroadwayBuffer *buffer);
void broadway_output_upload_texture (BroadwayOutput *output,
guint32 id,
GBytes *texture);
void broadway_output_release_texture (BroadwayOutput *output,
guint32 id);
void broadway_output_grab_pointer (BroadwayOutput *output,
int id,
gboolean owner_event);

View File

@ -43,6 +43,8 @@ typedef enum {
BROADWAY_OP_DISCONNECTED = 'D',
BROADWAY_OP_PUT_BUFFER = 'b',
BROADWAY_OP_SET_SHOW_KEYBOARD = 'k',
BROADWAY_OP_UPLOAD_TEXTURE = 't',
BROADWAY_OP_RELEASE_TEXTURE = 'T',
} BroadwayOpType;
typedef struct {

View File

@ -1647,6 +1647,9 @@ broadway_server_upload_texture (BroadwayServer *server,
GINT_TO_POINTER (id),
g_bytes_ref (texture));
if (server->output)
broadway_output_upload_texture (server->output, id, texture);
return id;
}
@ -1655,6 +1658,9 @@ broadway_server_release_texture (BroadwayServer *server,
guint32 id)
{
g_hash_table_remove (server->textures, GINT_TO_POINTER (id));
if (server->output)
broadway_output_release_texture (server->output, id);
}
gboolean
@ -1901,12 +1907,21 @@ broadway_server_new_window (BroadwayServer *server,
static void
broadway_server_resync_windows (BroadwayServer *server)
{
GHashTableIter iter;
gpointer key, value;
GList *l;
if (server->output == NULL)
return;
/* First create all windows */
/* First upload all textures */
g_hash_table_iter_init (&iter, server->textures);
while (g_hash_table_iter_next (&iter, &key, &value))
broadway_output_upload_texture (server->output,
GPOINTER_TO_INT (key),
(GBytes *)value);
/* Then create all windows */
for (l = server->toplevels; l != NULL; l = l->next)
{
BroadwayWindow *window = l->data;

View File

@ -99,6 +99,7 @@ var lastTimeStamp = 0;
var realWindowWithMouse = 0;
var windowWithMouse = 0;
var surfaces = {};
var textures = {};
var stackingOrder = [];
var outstandingCommands = new Array();
var inputSocket = null;
@ -528,6 +529,20 @@ function cmdPutBuffer(id, w, h, compressed)
surface.imageData = imageData;
}
function cmdUploadTexture(id, data)
{
var blob = new Blob([data],{type: "image/png"});
var url = window.URL.createObjectURL(blob);
textures[id] = url;
}
function cmdReleaseTexture(id)
{
var url = textures[id];
window.URL.revokeObjectURL(url);
delete textures[id];
}
function cmdGrabPointer(id, ownerEvents)
{
doGrab(id, ownerEvents, false);
@ -624,6 +639,17 @@ function handleCommands(cmd)
cmdPutBuffer(id, w, h, data);
break;
case 't': // Upload texture
id = cmd.get_32();
var data = cmd.get_data();
cmdUploadTexture(id, data);
break;
case 'T': // Upload texture
id = cmd.get_32();
cmdReleaseTexture(id);
break;
case 'g': // Grab
id = cmd.get_16();
var ownerEvents = cmd.get_bool ();