summaryrefslogblamecommitdiff
path: root/0001-evas-render-support.patch
blob: 3f9b5464616dbebd6103750504c577e931a0180e (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457








































































































































































































































































































































































































































































                                                                                                                                 
From e1ef4ae5dc17f0eedd6c3e16cbc6dea2753d0c52 Mon Sep 17 00:00:00 2001
From: discomfitor <michael.blumenkrantz@gmail.com>
Date: Sun, 8 Sep 2013 10:34:30 +0100
Subject: [PATCH] evas render support

---
 configure.ac               |  21 +++++-
 gtk/Makefile.am            |   9 +++
 gtk/spice-widget-evas.c    | 164 +++++++++++++++++++++++++++++++++++++++++++++
 gtk/spice-widget-priv.h    |   4 ++
 gtk/spice-widget.c         |  84 ++++++++++++-----------
 spice-client-gtk-2.0.pc.in |   1 +
 6 files changed, 244 insertions(+), 39 deletions(-)
 create mode 100644 gtk/spice-widget-evas.c

diff --git a/configure.ac b/configure.ac
index bd59ccf..2077cb9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -216,6 +216,9 @@ fi
 AC_ARG_WITH([x11],
   AS_HELP_STRING([--with-x11], [Use x11/shm display backend instead of cairo @<:@default=no@:>@]))
 
+AC_ARG_WITH([evas],
+  AS_HELP_STRING([--with-evas], [Use evas backend instead of x11/cairo @<:@default=no@:>@]))
+
 AC_MSG_CHECKING([What rendering backend to use..])
 if [test "x$with_x11" = "xyes" ]
 then
@@ -225,10 +228,25 @@ then
   fi
   AC_MSG_RESULT([x11])
   AC_DEFINE([WITH_X11], 1, [Use X11 backend?])
-else
+elif [test "x$with_evas" = "xyes" ] ; then
+  PKG_CHECK_MODULES([EVAS], [evas], [with_evas=yes], [with_evas=no])
+fi
+if [test "x$with_evas" = "xyes"] ; then
+  AC_MSG_RESULT([evas])
+  AC_DEFINE([WITH_EVAS], 1, [Use Evas backend])
+  SPICE_GTK_REQUIRES+=" evas"
+elif [test "x$with_x11" != "xyes" ] ; then
   AC_MSG_RESULT([cairo])
 fi
+
+if [test "x$with_evas" != "xyes"] ; then
+  with_evas=
+fi
+
 AM_CONDITIONAL([WITH_X11], [test "x$with_x11" = "xyes"])
+AM_CONDITIONAL([WITH_EVAS], [test "x$with_evas" = "xyes"])
+
+AC_SUBST([with_evas])
 
 AC_ARG_WITH([pnp-ids-path],
   AC_HELP_STRING([--with-pnp-ids-path],
@@ -688,6 +706,7 @@ AC_MSG_NOTICE([
         Smartcard support:        ${have_smartcard}
         USB redirection support:  ${have_usbredir}
         Gtk:                      $GTK_API_VERSION
+        Evas:                     $with_evas
 
         Now type 'make' to build $PACKAGE
 
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index d1e6f66..d106263 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -140,10 +140,19 @@ SPICE_GTK_SOURCES_COMMON +=		\
 	spice-widget-x11.c		\
 	$(NULL)
 else
+if WITH_EVAS
+SPICE_GTK_SOURCES_COMMON +=		\
+	spice-widget-evas.c		\
+	$(NULL)
+SPICE_COMMON_CPPFLAGS += @EVAS_CFLAGS@
+SPICE_GTK_LIBADD_COMMON += @EVAS_LIBS@
+
+else
 SPICE_GTK_SOURCES_COMMON +=		\
 	spice-widget-cairo.c		\
 	$(NULL)
 endif
+endif
 
 if HAVE_GTK_2
 libspice_client_gtk_2_0_la_LDFLAGS = $(SPICE_GTK_LDFLAGS_COMMON)
diff --git a/gtk/spice-widget-evas.c b/gtk/spice-widget-evas.c
new file mode 100644
index 0000000..6a108bc
--- /dev/null
+++ b/gtk/spice-widget-evas.c
@@ -0,0 +1,164 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+  Copyright (C) 2010 Red Hat, Inc.
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#include "spice-widget.h"
+#include "spice-widget-priv.h"
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <Evas.h>
+
+G_GNUC_INTERNAL void spice_display_mouse_move(SpiceDisplay *display, int ex, int ey, int button_mask);
+G_GNUC_INTERNAL void spice_display_mouse_button(SpiceDisplay *display, int bx, int by, int button, int button_mask, bool press);
+
+static int
+button_mask_evas_to_spice(int button)
+{
+    int spice = 0;
+
+    if (button & (1 << 0))
+        spice |= SPICE_MOUSE_BUTTON_MASK_LEFT;
+    if (button & (1 << 1))
+        spice |= SPICE_MOUSE_BUTTON_MASK_MIDDLE;
+    if (button & (1 << 2))
+        spice |= SPICE_MOUSE_BUTTON_MASK_RIGHT;
+    return spice;
+}
+
+static int
+button_evas_to_spice(int evas)
+{
+    static const int map[] = {
+        [ 1 ] = SPICE_MOUSE_BUTTON_LEFT,
+        [ 2 ] = SPICE_MOUSE_BUTTON_MIDDLE,
+        [ 3 ] = SPICE_MOUSE_BUTTON_RIGHT,
+        [ 4 ] = SPICE_MOUSE_BUTTON_UP,
+        [ 5 ] = SPICE_MOUSE_BUTTON_DOWN,
+    };
+
+    if (evas < SPICE_N_ELEMENTS(map)) {
+        return map [ evas ];
+    }
+    return 0;
+}
+
+static void
+_evas_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
+{
+    Evas_Event_Mouse_Move *ev = event_info;
+
+    spice_display_mouse_move(data, ev->cur.output.x, ev->cur.output.y, button_mask_evas_to_spice(ev->buttons));
+}
+
+static void
+_evas_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
+{
+    Evas_Event_Mouse_Down *ev = event_info;
+
+    spice_display_mouse_button(data, ev->output.x, ev->output.y, button_evas_to_spice(ev->button), 0, true);
+}
+
+static void
+_evas_mouse_up(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
+{
+    Evas_Event_Mouse_Up *ev = event_info;
+
+    spice_display_mouse_button(data, ev->output.x, ev->output.y, button_evas_to_spice(ev->button), 0, false);
+}
+
+static void
+_evas_mouse_in(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info)
+{
+   evas_object_focus_set(obj, EINA_TRUE);
+}
+
+static void
+_evas_mouse_out(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info)
+{
+   evas_object_focus_set(obj, EINA_FALSE);
+}
+
+static void
+_evas_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
+{
+   Evas_Event_Key_Down *ev = event_info;
+   guint key = gdk_keyval_from_name(ev->keyname);
+
+   spice_display_send_keys(data, &key, 1, SPICE_DISPLAY_KEY_EVENT_PRESS);
+}
+
+static void
+_evas_key_up(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
+{
+   Evas_Event_Key_Up *ev = event_info;
+   guint key = gdk_keyval_from_name(ev->keyname);
+
+   spice_display_send_keys(data, &key, 1, SPICE_DISPLAY_KEY_EVENT_RELEASE);
+}
+
+G_GNUC_INTERNAL
+int spicex_image_create(SpiceDisplay *display)
+{
+    SpiceDisplayPrivate   *d = SPICE_DISPLAY_GET_PRIVATE(display);
+
+    if (d->ximage != NULL)
+        return 0;
+
+    GObject     *window = G_OBJECT(gtk_widget_get_toplevel(GTK_WIDGET(display)));
+
+    d->convert = false;
+    
+    d->ximage = g_object_get_data(window, "evas_image");
+    evas_object_event_callback_add(d->ximage, EVAS_CALLBACK_MOUSE_IN, _evas_mouse_in, display);
+    evas_object_event_callback_add(d->ximage, EVAS_CALLBACK_MOUSE_OUT, _evas_mouse_out, display);
+    evas_object_event_callback_add(d->ximage, EVAS_CALLBACK_MOUSE_MOVE, _evas_mouse_move, display);
+    evas_object_event_callback_add(d->ximage, EVAS_CALLBACK_MOUSE_DOWN, _evas_mouse_down, display);
+    evas_object_event_callback_add(d->ximage, EVAS_CALLBACK_MOUSE_UP, _evas_mouse_up, display);
+    evas_object_event_callback_add(d->ximage, EVAS_CALLBACK_KEY_DOWN, _evas_key_down, display);
+    evas_object_event_callback_add(d->ximage, EVAS_CALLBACK_KEY_UP, _evas_key_up, display);
+    evas_object_image_size_set(d->ximage, d->width, d->height);
+    evas_object_image_data_set(d->ximage, d->data);
+    return 0;
+}
+
+G_GNUC_INTERNAL
+void spicex_image_destroy(SpiceDisplay *display)
+{
+    SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+
+    evas_object_event_callback_del_full(d->ximage, EVAS_CALLBACK_MOUSE_IN, _evas_mouse_in, display);
+    evas_object_event_callback_del_full(d->ximage, EVAS_CALLBACK_MOUSE_OUT, _evas_mouse_out, display);
+    evas_object_event_callback_del_full(d->ximage, EVAS_CALLBACK_MOUSE_MOVE, _evas_mouse_move, display);
+    evas_object_event_callback_del_full(d->ximage, EVAS_CALLBACK_MOUSE_DOWN, _evas_mouse_down, display);
+    evas_object_event_callback_del_full(d->ximage, EVAS_CALLBACK_MOUSE_UP, _evas_mouse_up, display);
+    d->ximage = NULL;
+}
+
+G_GNUC_INTERNAL
+void spicex_expose_event(SpiceDisplay *display, GdkEventExpose *expose)
+{
+    /* WOOOOOOOOO SCENEGRAPH!!! */
+    return;
+}
+
+G_GNUC_INTERNAL
+gboolean spicex_is_scaled(SpiceDisplay *display)
+{
+    return FALSE; /* backend doesn't support scaling yet */
+}
diff --git a/gtk/spice-widget-priv.h b/gtk/spice-widget-priv.h
index 597ce10..1563893 100644
--- a/gtk/spice-widget-priv.h
+++ b/gtk/spice-widget-priv.h
@@ -28,6 +28,8 @@ G_BEGIN_DECLS
 #include <X11/Xlib.h>
 #include <X11/extensions/XShm.h>
 #include <gdk/gdkx.h>
+#elif WITH_EVAS
+#include <Evas.h>
 #endif
 
 #ifdef WIN32
@@ -77,6 +79,8 @@ struct _SpiceDisplayPrivate {
     XImage                  *ximage;
     XShmSegmentInfo         *shminfo;
     GC                      gc;
+#elif defined(WITH_EVAS)
+    Evas_Object             *ximage;
 #else
     cairo_surface_t         *ximage;
 #endif
diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index d25edca..60b965e 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -1542,25 +1542,23 @@ void spicex_transform_input (SpiceDisplay *display,
     *input_y = floor (window_y * is);
 }
 
-static gboolean motion_event(GtkWidget *widget, GdkEventMotion *motion)
+G_GNUC_INTERNAL
+void spice_display_mouse_move(SpiceDisplay *display, int ex, int ey, int button_mask)
 {
-    SpiceDisplay *display = SPICE_DISPLAY(widget);
     SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
     int x, y;
 
     if (!d->inputs)
-        return true;
+        return;
     if (d->disable_inputs)
-        return true;
-
-    spicex_transform_input (display, motion->x, motion->y, &x, &y);
-
+        return;
+    spicex_transform_input (display, ex, ey, &x, &y);
     switch (d->mouse_mode) {
     case SPICE_MOUSE_MODE_CLIENT:
         if (x >= 0 && x < d->area.width &&
             y >= 0 && y < d->area.height) {
             spice_inputs_position(d->inputs, x, y, get_display_id(display),
-                                  button_mask_gdk_to_spice(motion->state));
+                                  button_mask);
         }
         break;
     case SPICE_MOUSE_MODE_SERVER:
@@ -1568,19 +1566,27 @@ static gboolean motion_event(GtkWidget *widget, GdkEventMotion *motion)
             gint dx = d->mouse_last_x != -1 ? x - d->mouse_last_x : 0;
             gint dy = d->mouse_last_y != -1 ? y - d->mouse_last_y : 0;
 
-            spice_inputs_motion(d->inputs, dx, dy,
-                                button_mask_gdk_to_spice(motion->state));
+            spice_inputs_motion(d->inputs, dx, dy, button_mask);
 
             d->mouse_last_x = x;
             d->mouse_last_y = y;
-            if (dx != 0 || dy != 0)
-                mouse_wrap(display, motion);
+#warning FIXME WRAP
+            //if (dx != 0 || dy != 0)
+                //mouse_wrap(display, motion);
         }
         break;
     default:
         g_warn_if_reached();
         break;
     }
+
+}
+
+static gboolean motion_event(GtkWidget *widget, GdkEventMotion *motion)
+{
+    SpiceDisplay *display = SPICE_DISPLAY(widget);
+
+    spice_display_mouse_move(display, motion->x, motion->y, button_mask_gdk_to_spice(motion->state));
     return true;
 }
 
@@ -1613,32 +1619,28 @@ static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *scroll)
     return true;
 }
 
-static gboolean button_event(GtkWidget *widget, GdkEventButton *button)
+G_GNUC_INTERNAL void
+spice_display_mouse_button(SpiceDisplay *display, int bx, int by, int button, int button_mask, bool press)
 {
-    SpiceDisplay *display = SPICE_DISPLAY(widget);
     SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
     int x, y;
 
-    SPICE_DEBUG("%s %s: button %d, state 0x%x", __FUNCTION__,
-            button->type == GDK_BUTTON_PRESS ? "press" : "release",
-            button->button, button->state);
-
     if (d->disable_inputs)
-        return true;
+        return;
 
-    spicex_transform_input (display, button->x, button->y, &x, &y);
+    spicex_transform_input (display, bx, by, &x, &y);
     if ((x < 0 || x >= d->area.width ||
          y < 0 || y >= d->area.height) &&
         d->mouse_mode == SPICE_MOUSE_MODE_CLIENT) {
         /* rule out clicks in outside region */
-        return true;
+        return;
     }
 
-    gtk_widget_grab_focus(widget);
+    gtk_widget_grab_focus(GTK_WIDGET(display));
     if (d->mouse_mode == SPICE_MOUSE_MODE_SERVER) {
         if (!d->mouse_grab_active) {
             try_mouse_grab(display);
-            return true;
+            return;
         }
     } else
         /* allow to drag and drop between windows/displays:
@@ -1656,22 +1658,23 @@ static gboolean button_event(GtkWidget *widget, GdkEventButton *button)
         gdk_pointer_ungrab(GDK_CURRENT_TIME);
 
     if (!d->inputs)
-        return true;
+        return;
 
-    switch (button->type) {
-    case GDK_BUTTON_PRESS:
-        spice_inputs_button_press(d->inputs,
-                                  button_gdk_to_spice(button->button),
-                                  button_mask_gdk_to_spice(button->state));
-        break;
-    case GDK_BUTTON_RELEASE:
-        spice_inputs_button_release(d->inputs,
-                                    button_gdk_to_spice(button->button),
-                                    button_mask_gdk_to_spice(button->state));
-        break;
-    default:
-        break;
-    }
+    if (press)
+       spice_inputs_button_press(d->inputs, button, button_mask);
+    else
+       spice_inputs_button_release(d->inputs, button, button_mask);
+}
+
+static gboolean button_event(GtkWidget *widget, GdkEventButton *button)
+{
+    SPICE_DEBUG("%s %s: button %d, state 0x%x", __FUNCTION__,
+            button->type == GDK_BUTTON_PRESS ? "press" : "release",
+            button->button, button->state);
+    spice_display_mouse_button(SPICE_DISPLAY(widget), button->x, button->y,
+                               button_gdk_to_spice(button->button),
+                               button_mask_gdk_to_spice(button->state),
+                               button->type == GDK_BUTTON_PRESS);
     return true;
 }
 
@@ -2156,9 +2159,14 @@ static void invalidate(SpiceChannel *channel,
     x2 = ceil ((rect.x - d->area.x + rect.width) * s);
     y2 = ceil ((rect.y - d->area.y + rect.height) * s);
 
+#ifdef WITH_EVAS
+    evas_object_image_data_update_add(d->ximage, display_x + x1, display_y + y1,
+                               x2 - x1, y2-y1);
+#else
     gtk_widget_queue_draw_area(GTK_WIDGET(display),
                                display_x + x1, display_y + y1,
                                x2 - x1, y2-y1);
+#endif
 }
 
 static void mark(SpiceDisplay *display, gint mark)
diff --git a/spice-client-gtk-2.0.pc.in b/spice-client-gtk-2.0.pc.in
index a5b96e2..9526b11 100644
--- a/spice-client-gtk-2.0.pc.in
+++ b/spice-client-gtk-2.0.pc.in
@@ -2,6 +2,7 @@ prefix=@prefix@
 exec_prefix=@exec_prefix@
 libdir=@libdir@
 includedir=@includedir@
+evas=@with_evas@
 
 Name: spice-client-gtk-2.0
 Description: SPICE Client Gtk 2.0 library
-- 
1.8.3.2