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 8eabd33 commit 85e5a75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 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 @@ -883,7 +883,8 @@ def paint_mmap(self, img_data, x:int, y:int, width:int, height:int, rowstride:in
""" must be called from UI thread
see _mmap_send() in server.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_window_backing
x, y = self.gravity_adjust(x, y, options)
Expand Down
12 changes: 7 additions & 5 deletions xpra/net/mmap_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import os
import sys
from ctypes import c_ubyte, c_char, c_uint32
from typing import Tuple, Optional, Any
from typing import Tuple, Optional, Any, Callable

from xpra.util import roundup
from xpra.common import noop
from xpra.os_util import memoryview_to_bytes, shellsub, get_group_id, WIN32, POSIX
from xpra.scripts.config import FALSE_OPTIONS, TRUE_OPTIONS
from xpra.simple_stats import std_unit
Expand Down Expand Up @@ -245,7 +246,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) -> bytes:
def mmap_read(mmap_area, *descr_data) -> tuple[bytes, Callable]:
"""
Reads data from the mmap_area as written by 'mmap_write'.
The descr_data is the list of mmap chunks used.
Expand All @@ -255,15 +256,16 @@ def mmap_read(mmap_area, *descr_data) -> bytes:
#construct an array directly from the mmap zone:
offset, length = descr_data[0]
arraytype = c_char * length
data_start.value = offset+length
return arraytype.from_buffer(mmap_area, offset)
def free_mem(*_args):
data_start.value = offset + length
return arraytype.from_buffer(mmap_area, offset), free_mem
#re-construct the buffer from discontiguous chunks:
data = []
for offset, length in descr_data:
mmap_area.seek(offset)
data.append(mmap_area.read(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 85e5a75

Please sign in to comment.