Multiple SDL Contexts

Is there a way to launch multiple SDL windows w/o forking/spawning a new program (actually would that work).

Is there a way to launch multiple SDL windows w/o forking/spawning a
new program

(We just had that discussion here…)

No, it’s not possible with current SDL versions.

(actually would that work).

Forking? Yes. Anything that ensures that each window has it’s own
instance of SDL (which basically means that processes may not share
global variables) should work.

Or you could start tracking all global variables and stuff in the SDL
sources. :slight_smile: I’ll help with the API extensions and actually getting it to
work on Linux, and possibly Win32 (Linux/Mingw32 cross).

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Thursday 11 October 2001 01:28, Joe Tennies wrote:

Actually, on Linux, you might get away with creating “fake” processes
without CPU contexts. You’d have to use the underlying syscall for
thread/process creation, and say “I want private data, but that’s it!”.
(There’s only one call, and a very flexible one, as opposed to the case
with most other systems.)

You’d have to do explicit context switches (to switch data pages) to
switch between the SDL instances, and the “instances” would actually be
instances of all global variables, not just those of SDL.

It would be messy and non-portable, but you avoid going through the
scheduler to switch context, and you avoid IPC… :wink:

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Thursday 11 October 2001 01:28, Joe Tennies wrote:

Is there a way to launch multiple SDL windows w/o forking/spawning a
new program (actually would that work).

[…]

Or you could start tracking all global variables and stuff in the SDL
sources. :slight_smile: I’ll help with the API extensions and actually getting it
to work on Linux, and possibly Win32 (Linux/Mingw32 cross).

Wait. Before anyone starts working on this, is there any point? That is,
is there a way that multiple window support is going into mainstream SDL
before SDL 1.2, provided someone hacks it in a way that preserves
performance and compatibility?

Hacking Plan:
1. Wrap SDL’s global “instance” variables related to video in
a struct “SDL_Context”.

2. Use an instance 'SDL_Context current' instead of the globals.

3. Implement API to switch between different SDL_Contexts.
   (SDL_Set/GetContext()?)

4. Add a new "video open" that creates a new SDL_Context,
   switches to it and then runs SDL_SetVideoMode(). (Which will
   act as if SDL had been started cold.) It should probably
   return the address or handle of the SDL_Context, rather than
   the screen surface.

5. Add a hidden, internal field to SDL_Event to hold a handle
   or pointer to a source SDL_Context.

6. Make the old SDL event API implicitly deal only with events
   related to the current context.

7. Add new event API calls that explicitly deals with context
   info, so that it's possible to write applications with only
   one event loop for all windows.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Thursday 11 October 2001 01:46, David Olofson wrote:

^^^^^^^
SDL 1.3, of course.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Thursday 11 October 2001 02:21, David Olofson wrote:

mainstream SDL before SDL 1.2, provided someone hacks it in a way that

The use I have for this would be to create a cross platform widget set. I
am seeing something like Borland’s VCL library.> ----- Original Message -----

From: david.olofson@reologica.se (David Olofson)
To:
Sent: Wednesday, October 10, 2001 7:21 PM
Subject: Re: [SDL] Multiple SDL Contexts

On Thursday 11 October 2001 01:46, David Olofson wrote:
[…]

Or you could start tracking all global variables and stuff in the SDL
sources. :slight_smile: I’ll help with the API extensions and actually getting it
to work on Linux, and possibly Win32 (Linux/Mingw32 cross).

Wait. Before anyone starts working on this, is there any point? That is,
is there a way that multiple window support is going into mainstream SDL
before SDL 1.2, provided someone hacks it in a way that preserves
performance and compatibility?

Hacking Plan:

  1. Wrap SDL’s global “instance” variables related to video in
    a struct “SDL_Context”.

  2. Use an instance ‘SDL_Context current’ instead of the globals.

  3. Implement API to switch between different SDL_Contexts.
    (SDL_Set/GetContext()?)

  4. Add a new “video open” that creates a new SDL_Context,
    switches to it and then runs SDL_SetVideoMode(). (Which will
    act as if SDL had been started cold.) It should probably
    return the address or handle of the SDL_Context, rather than
    the screen surface.

  5. Add a hidden, internal field to SDL_Event to hold a handle
    or pointer to a source SDL_Context.

  6. Make the old SDL event API implicitly deal only with events
    related to the current context.

  7. Add new event API calls that explicitly deals with context
    info, so that it’s possible to write applications with only
    one event loop for all windows.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -’


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

The use I have for this would be to create a cross platform widget
set. I
am seeing something like Borland’s VCL library.

you don’t like ParaGUI ? (http://www.paragui.org) ??

[…]

Or you could start tracking all global variables and stuff in the SDL
sources. :slight_smile: I’ll help with the API extensions and actually getting it
to work on Linux, and possibly Win32 (Linux/Mingw32 cross).

Wait. Before anyone starts working on this, is there any point? That is,
is there a way that multiple window support is going into mainstream SDL
before SDL 1.2, provided someone hacks it in a way that preserves
performance and compatibility?

Hacking Plan:

[clip good steps]
note that it looks like Windows has TSS storage where a local version of
the SDL_Context could go… linux does -not- afaik. (actually it does,
but it’s not a simple call :slight_smile:

Just to make life easier in some respects… g.

Note of course that sometimes only one context is available (svga).
Although FWIW with FBcon it’s possible to open multiple virtual
terminals… not that I see a lot of point to it but it -is- possible g

The thing I note is that windowed event-handling can get a wee bit
tricky… either one SDL-event system needs to run per context, making
inter-context events a trick, or there’s a centralized eventsystem not
attached to -any- context that acts as an event router. Note that at the
moment there’s not enough contextual info in the events to say where the
event came from g.

G’day, eh? :slight_smile:
- Teunis, wandering off again…On Thu, 11 Oct 2001, David Olofson wrote:

On Thursday 11 October 2001 01:46, David Olofson wrote:

Joe Tennies wrote:

Is there a way to launch multiple SDL windows w/o forking/spawning a
new program (actually would that work).

If you think you need more than one SDL window, the odds are that
you’re in the wrong place — you don’t want to use SDL, but a
traditional windowed user-interface toolkit instead

We’re not thinking about too different things, then; my toolkit is just
more similar to what you’d build a "point&click multimedia creation tool"
on, than what you’d use for “normal” applications.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Thursday 11 October 2001 07:32, Joe Tennies wrote:

The use I have for this would be to create a cross platform widget set.
I am seeing something like Borland’s VCL library.

[…]

Or you could start tracking all global variables and stuff in the
SDL sources. :slight_smile: I’ll help with the API extensions and actually
getting it to work on Linux, and possibly Win32 (Linux/Mingw32
cross).

Wait. Before anyone starts working on this, is there any point? That
is, is there a way that multiple window support is going into
mainstream SDL before SDL 1.2, provided someone hacks it in a way
that preserves performance and compatibility?

Hacking Plan:

[clip good steps]
note that it looks like Windows has TSS storage where a local version
of the SDL_Context could go… linux does -not- afaik. (actually it
does, but it’s not a simple call :slight_smile:

Just to make life easier in some respects… g.

I think we should stay faaaaar away from that kind of features - it’s not
much better than the lowlevel Linux threads hack I mentioned before.

What’s wrong with a plain C struct, of which there is one global
instance? :slight_smile: (Results in exactly the same code as if the variables
were still plain globals - the difference is that the entire state can be
swapped very easily.)

Note of course that sometimes only one context is available (svga).
Although FWIW with FBcon it’s possible to open multiple virtual
terminals… not that I see a lot of point to it but it -is- possible
g

How about opening a local SVGAlib context and an X context on a remote
machine? (You’d have to change system variables in between calls to
SDL_SetVideoMode() to do that, but it should work as soon as the globals
are “captured”. :slight_smile:

The thing I note is that windowed event-handling can get a wee bit
tricky… either one SDL-event system needs to run per context, making
inter-context events a trick, or there’s a centralized eventsystem not
attached to -any- context that acts as an event router.

The latter is what I had in mind. I guess the code behind
SDL_PeepEvents() could be extended to deal with the context field, so
that one could extract events for a particular context, if desired. (The
old API would use this filter behind the scenes, in order to only return
events from the current context.)

Note that at
the moment there’s not enough contextual info in the events to say
where the event came from g.

I’ve addressed that too in the list; just add it to the internal version
of SDL_Event, but keep the real SDL_Event as is, to preserve binary
compatibility.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Thursday 11 October 2001 11:36, winterlion wrote:

On Thu, 11 Oct 2001, David Olofson wrote:

On Thursday 11 October 2001 01:46, David Olofson wrote: