Skip to content

Commit

Permalink
#4271 move shared pointer via paint callback
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jul 1, 2024
1 parent 744eac3 commit d07d9ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion xpra/client/gui/window_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,8 @@ def paint_mmap(self, img_data, x: int, y: int, width: int, height: int, rowstrid
""" must be called from UI thread
see _mmap_send() in seamless.py for details """
assert self.mmap_enabled
data = mmap_read(self.mmap, *img_data)
data, free_cb = mmap_read(self.mmap, *img_data)
callbacks.append(free_cb)
rgb_format = options.strget("rgb_format", "RGB")
# Note: BGR(A) is only handled by gl.backing
x, y = self.gravity_adjust(x, y, options)
Expand Down
13 changes: 7 additions & 6 deletions xpra/net/mmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import sys
from ctypes import c_ubyte, c_uint32
from typing import Any
from collections.abc import ByteString
from collections.abc import ByteString, Callable

from xpra.common import roundup
from xpra.common import roundup, noop
from xpra.util.env import envbool, shellsub
from xpra.os_util import get_group_id, WIN32, POSIX
from xpra.scripts.config import FALSE_OPTIONS
Expand Down Expand Up @@ -268,7 +268,7 @@ def int_from_buffer(mmap_area, pos: int) -> c_uint32:

# descr_data is a list of (offset, length)
# areas from the mmap region
def mmap_read(mmap_area, *descr_data) -> ByteString:
def mmap_read(mmap_area, *descr_data) -> tuple[ByteString, Callable]:
"""
Reads data from the mmap_area as written by 'mmap_write'.
The descr_data is the list of mmap chunks used.
Expand All @@ -278,14 +278,15 @@ def mmap_read(mmap_area, *descr_data) -> ByteString:
if len(descr_data) == 1:
# construct an array directly from the mmap zone:
offset, length = descr_data[0]
data_start.value = offset + length
return (mv[offset:offset + length]).toreadonly()
def free_mem(*_args):
data_start.value = offset + length
return (mv[offset:offset + length]).toreadonly(), free_mem
# re-construct the buffer from discontiguous chunks:
data = []
for offset, length in descr_data:
data.append(mv[offset:offset + length])
data_start.value = offset + length
return b"".join(data)
return b"".join(data), noop


def mmap_write(mmap_area, mmap_size: int, data):
Expand Down

0 comments on commit d07d9ca

Please sign in to comment.