Skip to content

Extending TVirtualX interface, avoid gVirtualX in painters#21586

Open
linev wants to merge 37 commits intoroot-project:masterfrom
linev:virtualx_attributes
Open

Extending TVirtualX interface, avoid gVirtualX in painters#21586
linev wants to merge 37 commits intoroot-project:masterfrom
linev:virtualx_attributes

Conversation

@linev
Copy link
Member

@linev linev commented Mar 12, 2026

Current TVirtualX api is not thread safe.
There is no way to create several canvases and update them individually from different threads.
Main reason - several global X11 objects which are modified all the time during painting.
But already in the current implementation there is array of XWindow_t structures which is used to manage
widget-related data.

So idea to extend XWindow_t structure and put there all data which are relevant for widgets painting.
And then provide API methods where window id or directly XWindow_t pointer used as first argument.
So one can implement painting which in theory can be fully independent from other parallel actions.

This PR is the exercise if such transition is possible. It moves all attributes to XWindow_t structure and
provide all painting methods using these attributes. And this seems to be working!

Missing part is refactoring of TTF class. It is crucial for text drawing and currently has fully static interface - which does not allow multi-threaded usage. But there is no principal problem to solve this. Similar problem is code in Rotated.cxx - which used for text rotation.

In all classes where gVirtualX used directly in painting - replace it by calls to TVirtualPadPainter.
So only in very special places - like TASImage or TLatex - implement painting code which differs for PS and X11 interface. But these places are very few and can be adjusted later,

@linev linev self-assigned this Mar 12, 2026
@linev linev marked this pull request as draft March 12, 2026 13:37
@github-actions
Copy link

github-actions bot commented Mar 12, 2026

Test Results

    21 files      21 suites   3d 0h 19m 49s ⏱️
 3 835 tests  3 834 ✅ 1 💤 0 ❌
71 965 runs  71 956 ✅ 9 💤 0 ❌

Results for commit 71398df.

♻️ This comment has been updated with latest results.

@linev linev force-pushed the virtualx_attributes branch 2 times, most recently from dc8ec78 to b9748a6 Compare March 18, 2026 11:44
linev added 19 commits March 18, 2026 15:29
Move from plain array to unordered_map.
So pointer on XWindow_t will not change if new window will be created later.
Idea to use this pointer later as main handle for graphics operation -
while using window id will costs locking of the mutex which need to be
introduced later for threads safety
First provide window context for each active window.
Window context should allow access per-window functionality fully independent from each other

As a first interfaces declare methods to change attributes.
So one can set different drawing attributes independently for each window.
Allows to use native X11 types without casting.
List of windows now defined as:
```
std::unordered_map<Int_t,std::unique_ptr<XWindow_t>> fWindows
```
In TCanvas::Feedback() method first select fCanvasID before
changing draw mode. Only becase of global GC attributes it was possible before.
If GC allocated per window - one should do it correctly
Only window-specific contexts are used
Remove unused method CopyWindowtoPixmap
So setting line/fill style to TGX11 will change attributes for
currently selected window.
Comment out most of members
Allocate marker attributes per window,
comment aout global gMarker structures
Where it make sense - use XDrawSegments for markerS
Without TTF support X11 fonts are used.
Move text attributes handling to XWindow_t structure,
keep only global gTextFont for text size handling.
One can add hook there to allocate and initialize there TTF structures.
For now keep global members
Last place was PutImage method - used either special window GC or just temporary created GC
PutImage is not used at all
Now only window-special contexts are used
Use when TGX11TTF instance must be created.
Copy constructor it too complicated.
So one can specify window where drawing operation is performed
Old signatures redirects to new methods
linev added 8 commits March 18, 2026 15:29
Remember context of selected window and use this context
when performing drawing on the pad
Provide protected methods to return window, GC and textAlign for selected window context.
And use context in TTF rendering methods.

So now TGX11TTF also correctly implementes API,
but not yet thread-safe because of TTF global states.
Instead set individiual line or fill attributes use new
methods with TAtt... object as instance.
In TPadPainter it is redirected to selected window context
So even if there are several canvases displayed - attributes will be modified in the correct window context.
While some objects painters analyze attributes
like gVirtualX->GetLineWidth(), provide such getters.
But only for transition phase - later one can dismiss methods again
line width and fill style used in drawing.
While attributes set anyway via pad painter interface,
just remember them to avoid need provide getters from TVirtualX
To avoid complication with derived classes
@linev linev force-pushed the virtualx_attributes branch from b9748a6 to e9c0a76 Compare March 18, 2026 14:29
@linev linev marked this pull request as ready for review March 18, 2026 14:29
@linev linev changed the title [experimental] modifying TVirtualX interface [DO NOT MERGE!] Extending TVirtualX interface Mar 18, 2026
linev added 9 commits March 18, 2026 15:37
For some special applications like TASImage provide
access to PS instance from pad painter. So one
do not need to duplicate interface several times.
Instead of gVirtualX or gVirtualPS use pad painter instance
Use pad painter for exclusive text drawing on
screen or on PS device. In rare cases provide
special handling of PS output (like tilde).
One cannot use TGX11 itself while one access
attributes via getter methods which already redefined
in TGX11. So make copy of stored attributes
Replace usage of gVirtualX
While both TPad and TWbox uses same code,
put it together in TWbox::PaintBorderOn method.
So fully avoid usage of PaintBorderPS method,
can be removed in the future
@linev linev changed the title Extending TVirtualX interface Extending TVirtualX interface, avoid gVirtualX in painters Mar 18, 2026
Now border decorations of the sub-pad drawn slightly
different using TWbox method. So ref file size
is slightly changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant