Commit Graph

3658 Commits

Author SHA1 Message Date
Frediano Ziglio
258fda6290 Remove now useless check
display_channel_surface_id_unref resets the surface so
display_channel_surface_has_canvas will return false.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:15 +01:00
Frediano Ziglio
d8bca15f2b Allows surfaces to be updated without having to wait
Store pointers to surface object in "surfaces" and allows to
have different surfaces with same ID in memory.
The surface was keep "busy" if there was pending drawing around.

Consider the following case:
 1- receive drawing command
 2- queue command on DCCs
 3- destroy surface
 4- send draw
Previously at point 4) you would have to use a surface from
"surfaces" which was destroyed, that is we would have to maintain
the pointer (and canvas) to the surface until reference counter
was 0.

However consider this case:
 1- receive drawing command
 2- queue command on DCCs
 3- destroy surface
 4- create surface
 5- send draw
What would happen in point 4) ?
We could not change the surface as it will be used by point 5).
To avoid this the code attempts to wait the commands to release the
surface. However this can be an issue, you can't force the clients
to receive pending data if network is slow.

So this patch change this allowing to create surfaces while the old
version will still be used.

This is also more clean from the reference pointer prospective,
as the reference is increased for a specific surface.

Note that now instead of checking for canvas to not be NULL a
simple check for surface pointer is enough.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:12 +01:00
Frediano Ziglio
f5c2043143 Remove last direct surface IDs usages
Mostly left on dcc-send.cpp.
Other minor too.

The change in BitmapData seems odd but the id for cached image
was not used so the only information left was the surface.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:09 +01:00
Frediano Ziglio
4434c6fb96 Change validate_surface to return surface pointer
Instead of computing the value inside the function to then
compute also in the caller return it.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:07 +01:00
Frediano Ziglio
1d123192e7 Use directly surface instead of id
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:05 +01:00
Frediano Ziglio
74c660ddad Pass surface directly to dcc_push_surface_image
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:04 +01:00
Frediano Ziglio
3b790b8ad6 Pass surface directly to dcc_create_surface
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:02 +01:00
Frediano Ziglio
78bc3a637a New function to pass surface directly to display_channel_draw
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:01 +01:00
Frediano Ziglio
5a5d1e21b5 Pass surface directly calling display_channel_current_flush
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:59 +01:00
Frediano Ziglio
58a612a039 Pass surface directly calling dcc_clear_surface_drawables_from_pipe
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:57 +01:00
Frediano Ziglio
2b219cace5 Pass surface directly calling draw_depend_on_me and display_channel_destroy_surface
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:55 +01:00
Frediano Ziglio
493077d080 Pass surface directly in is_primary_surface
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:54 +01:00
Frediano Ziglio
f418bbb522 Pass surface directly to display_channel_surface_unref
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:52 +01:00
Frediano Ziglio
977e72eb48 Pass surface directly to current_remove_all
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:51 +01:00
Frediano Ziglio
19eb9995b2 Pass surface directly for surface_read_bits
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:48 +01:00
Frediano Ziglio
6933c6dd14 Use direct pointers for surface and surface dependencies from Drawable
As we use reference counting is more direct to use direct pointers.
Also this will allow to have a surface in a "released state"
reducing the complexity of code destroying a surface.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:38 +01:00
Frediano Ziglio
708cd97212 red-parse-qxl: Encapsulate QXL resource management
Reuse code.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:14 +01:00
Frediano Ziglio
b6aa5798b7 red-parse-qxl: Use a base reference class for RedDrawable
Don't code manually reference counting for this structure

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:12 +01:00
Frediano Ziglio
110b97e51e red-parse-qxl: Use a base reference class for RedUpdateCmd
Don't code manually reference counting for this structure

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:10 +01:00
Frediano Ziglio
45f2d94ac3 red-parse-qxl: Use a base reference class for RedMessage
Don't code manually reference counting for this structure

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:09 +01:00
Frediano Ziglio
6eac8cc08f red-parse-qxl: Use a base reference class for RedSurfaceCmd
Don't code manually reference counting for this structure

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:07 +01:00
Frediano Ziglio
1d4fb2fee7 red-parse-qxl: Use a base reference class for RedCursorCmd
Don't code manually reference counting for this structure

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:05 +01:00
Frediano Ziglio
a3656e217d utils: Add a base light class for reference counting
Similar to shared_ptr_counted but avoid atomic counter and
polymorphism.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:01 +01:00
Frediano Ziglio
cc4d6559b2 sound: Use SpiceAudioDataMode type for audio mode
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-06-14 11:28:37 +01:00
Frediano Ziglio
0088659c37 cursor-channel-client: Remove unused variable
Both _cursor_count and DEBUG_CURSORS are not used.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-04 08:56:44 +01:00
Frediano Ziglio
71284c4984 red-worker: Limit visibility
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-01 22:08:55 +01:00
Frediano Ziglio
1b02f2d3d0 red-worker: Associate message structure and numbers
Makes sure a message is sent with the proper message number.
Reduce mistakes associating types with wrong registered number.
Make easier to add new messages in the future.
Avoids having to type the message number every time, it's inferred
from the type.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-01 22:08:55 +01:00
Frediano Ziglio
c8e4e467be red-worker: Reduce casts needed in dispatcher handlers
Use a template to deduct type and avoid casts in every handler.
The reinterpret_cast seems strong but is safe as converting
a function with 2 typed pointers and a void return into a function
with 2 void pointers and a void return.
The unsafety left (not a regressions) is the association between
handler number and message type.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-01 22:08:55 +01:00
Frediano Ziglio
84e1788d3a reds: Fix closure of SpiceServer in case of connected clients
When spice_server_destroy is called with pending clients (currently
not a big issue, usually the programs using SPICE server are
exiting then), some leaks can happen.
This is due to the fact that some dispatcher messages are queued
to handle some serialization but then they are neved executed as
the entire system is closed.
Close all connections and handle all main dispatcher messages
to remove these leaks.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-01 21:47:29 +01:00
Frediano Ziglio
c63f166bb1 display-channel: Rename parameter for consistency
display_channel -> display.
In all the rest of the file display is used.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-01 21:47:27 +01:00
Frediano Ziglio
435ba9228f display-channel: Use constructor and destructor for Drawable
This will allow to use not trivial objects inside the structure.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-01 21:47:21 +01:00
Rosen Penev
3f5ba6e565 red-client: Remove FOREACH_CHANNEL_CLIENT macro
Since the conversion to a for range loop, there's no point to this
macro.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-06-01 09:02:48 +01:00
Rosen Penev
4b56942bf5 reds: Remove FOREACH_QXL_INSTANCE macro
Since the conversion to a for range loop, there's no point to this
macro.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-06-01 09:02:32 +01:00
Rosen Penev
115260e4e5 Manual algorithm changes
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-31 08:08:26 +01:00
Frediano Ziglio
3de587a76c red-stream: Fix issue with SASL and no-Glibc
Using Unix sockets and no-Glibc C libraries (like Musl) getnameinfo
will fail causing SASL code to fail initialization.
Replicate Glibc behavior and report "localhost" as host and an
empty port string.

This fixes https://gitlab.freedesktop.org/spice/spice/-/issues/58.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-24 08:37:11 +01:00
Rosen Penev
8104fc3456 Manual algorithm changes
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-23 10:32:07 +01:00
Rosen Penev
51092046f7 Remove several usages of SPICE_N_ELEMENTS
It's simpler to just use a for range loop.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-23 10:01:39 +01:00
Frediano Ziglio
c5412b071a stream-channel: Fix compiler warning
This removes:

In function ‘stream_channel_get_supported_codecs’,
    inlined from ‘on_connect’ at ../server/stream-channel.cpp:364:60:
../server/stream-channel.cpp:326:31: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  326 |             out_codecs[num++] = codec;
      |                               ^
../server/stream-channel.cpp: In member function ‘on_connect’:
/usr/include/spice-1/spice/stream-device.h:209:13: note: destination object ‘codecs’ of size 0
  209 |     uint8_t codecs[0];
      |             ^

Reported by by Tomasz Kłoczko in
https://gitlab.freedesktop.org/spice/spice/-/issues/44

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 10:14:26 +01:00
Frediano Ziglio
0b86b6808a tests: Fix -Wodr warning compiling tests with LTO enabled
Avoid the compiler to see 2 different defines of the same
structure.
Reported by Tomasz Kłoczko in
https://gitlab.freedesktop.org/spice/spice/-/issues/44

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 10:14:21 +01:00
Frediano Ziglio
cb9bd1b09e Make headers independent
Make sure all headers can be compiled alone.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 10:13:41 +01:00
Frediano Ziglio
1201113acd build: Better version checks and handling for Meson
Strip dirty and git hash.
Check that there are at least 3 numbers at the beginning.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 09:40:28 +01:00
Frediano Ziglio
a5e0f86bc2 Removed only written "items" field from PixmapCache
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 08:38:27 +01:00
orbea
c5fe3df1ef build: Fix undefined pthread references
The build fails with slibtool while GNU libtool hide the issue
by silently ignoring -no-undefined.

ax_pthread.m4 is sourced from:

e68e8f6f62/m4/ax_pthread.m4

Downstream issue: https://bugs.gentoo.org/780027

Signed-off-by: orbea <orbea@riseup.net>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 08:30:15 +01:00
Rosen Penev
9462537d24 clang-tidy: fix inconsistent declarations
Found with readability-inconsistent-declaration-parameter-name

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-09 11:19:30 +01:00
Rosen Penev
aefcd7d1c4 clang-tidy: use uppercase numeric literals
Found with readability-uppercase-literal-suffix

Avoids readability problems between lower case l and uppercase I.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-09 07:00:21 +01:00
Rosen Penev
9fb945c31b clang-tidy: replace typedef with using
Found with modernize-use-using

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-09 06:38:36 +01:00
Frediano Ziglio
748cc409f6 dispatcher: Avoid casts for raw buffers
Usually buffers to raw data are passed using void* pointers
to avoid casts and mark the buffer as raw.
Use them for read_safe and write_safe to avoid useless casts
in caller code.
As a minor convert a parameter to bool as changing the same
lines.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-05-05 09:13:33 +01:00
Rosen Penev
0bc7e80ec6 clang-tidy: convert C casts to C++ ones
Found with google-readability-casting

https://google.github.io/styleguide/cppguide.html#Casting

Makes the operation clearer.

This commit uses const_cast where needed.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-05 07:03:55 +01:00
Frediano Ziglio
62dd7e47e9 tests: Remove some compiler warnings
Remove warnings like:

In file included from /usr/include/glib-2.0/glib.h:86,
                 from ../server/tests/test-glib-compat.h:21,
                 from ../server/tests/test-channel.cpp:25:
In function 'void send_ack_sync(int, uint32_t)',
    inlined from 'void channel_loop()' at ../server/tests/test-channel.cpp:250:18:
../server/sys-socket.h:28:43: error: 'ssize_t write(int, const void*, size_t)' reading 10 bytes from a region of size 2 [-Werror=stringop-overread]
   28 | #define socket_write(sock, buf, len) write(sock, buf, len)
/usr/include/glib-2.0/glib/gtestutils.h:50:61: note: in definition of macro 'g_assert_cmpint'
   50 |                                              gint64 __n1 = (n1), __n2 = (n2); \
      |                                                             ^~
../server/tests/test-channel.cpp:132:21: note: in expansion of macro 'socket_write'
  132 |     g_assert_cmpint(socket_write(socket, &msg.type, 10), ==, 10);
      |                     ^~~~~~~~~~~~
../server/tests/test-channel.cpp: In function 'void channel_loop()':
../server/tests/test-channel.cpp:123:18: note: source object 'send_ack_sync(int, uint32_t)::<unnamed struct>::type' of size 2
  123 |         uint16_t type;
      |                  ^~~~
In file included from ../server/tests/test-channel.cpp:22:
/usr/include/unistd.h:367:16: note: in a call to function 'ssize_t write(int, const void*, size_t)' declared with attribute 'access (read_only, 2, 3)'
  367 | extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur
      |                ^~~~~
cc1plus: all warnings being treated as errors

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-05-05 06:36:18 +01:00
Frediano Ziglio
e39412644c ci: Ignore a leak in glib threading pool
The leak is detected by Valgrind on Fedora 34as:

==19603== 400 bytes in 1 blocks are possibly lost in loss record 2,296 of 2,441
==19603==    at 0x4845464: calloc (vg_replace_malloc.c:1117)
==19603==    by 0x40135FB: _dl_allocate_tls (in /usr/lib64/ld-2.33.so)
==19603==    by 0x57EB008: pthread_create@@GLIBC_2.2.5 (in /usr/lib64/libpthread-2.33.so)
==19603==    by 0x53A1130: UnknownInlinedFun (gthread-posix.c:1323)
==19603==    by 0x53A1130: g_thread_new_internal (gthread.c:931)
==19603==    by 0x53C4953: g_thread_pool_start_thread.constprop.0 (gthreadpool.c:477)
==19603==    by 0x53A2902: g_thread_pool_push (gthreadpool.c:691)
==19603==    by 0x519AE11: g_task_run_in_thread_sync (gtask.c:1593)
==19603==    by 0x80D8A74: ??? (in /usr/lib64/gio/modules/libgiolibproxy.so)
==19603==    by 0x5181966: g_proxy_address_enumerator_next (gproxyaddressenumerator.c:176)
==19603==    by 0x519281A: g_socket_client_connect (gsocketclient.c:1098)

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-05-05 06:36:14 +01:00