Page 1 of 1

resizeable shared memory entities

Posted: Tue Jun 27, 2006 6:48 am
by distantvoices
After some *very* idle time merely churning thoughts about differential equations, complex numbers and transient processes (electronics - rc or rl members) - yeah and complex analysis of circuits (with capacities, inductivities and impedances, I have finally found a bit of time to do osdeving. ;-)

and what happens: I'm ripping apart the gui service & gui library.

I want to do the following:

Upon request of a window, the gui service creates a shm entity the Id of which it passes over to the client which is to map the shm entity into its own address space.

The client does all its drawing in this shm entity.

The gui service can take the entity and perform any operation it wants on it. say "transparency", "clipping", "hide", "move", "resize"

The "resize" is which gives me a little bit to think.

It is a shared memory entity after all.

Is it reasonable to actually resize the thing or to simply drop it and create a new one for both the client and the server to map in?

How's that stuff done in other OS's?

What do you propose? (Yeah, for first I am going to use the xor lasso trick to avoid redrawing window upon resizing action)

Stay safe :-)

Re:resizeable shared memory entities

Posted: Tue Jun 27, 2006 8:35 am
by Pype.Clicker
anyone willing to avoid redrawing-while-resize is a true friend of mine ;)

When you say "shared memory", do you mean "shared offscreen buffer" or maybe even "shared onscreen buffer"? or just "shared area where to put drawing commands"?

I ask just because none really seems appealing to me. If onscreen, you'll need to make sure the app doesn't overwrite its area (unless it works over a compositing/textured window manager, of course ;D )

If offscreen, that'd mean you may have to copy too much bits to keep the drawing up-to-date (unless you rsync between the two :P) Just thinking about an animated version of "hangman"... you imagine your program just drawing white lines and then black lines to "wave" the character and the GUI service would have to blit the shm to the vram ... (eeks).

Not such a weird idea, though, that "rsyncing" between the two. You pick a block of pixels, compute a CRC and blit them to VRAM only if the CRC differs with the previous CRC for this block. (e.g. you keep CRCs in DRAM ... maybe even hierarchically-computed CRCs ;) )

hm. wait, CRC will not catch all updates. we'd need SHA1 or MD5... nevermind.

<edit>
oh, and about resizing, what about just stating that the shm you created is large enough for the largest possible window size and that you'll just drop some virtual memory when you don't need everything ?

The GUI service would notify the app. that the window has been resized, and ignore shm content until the app. acknowledges "okay, now the shm is refreshed with 1234x567 content instead of 890x123"

Re:resizeable shared memory entities

Posted: Tue Jun 27, 2006 9:50 am
by Candy
I'm going for the easy approach (imo): I divide all application-content into two sections, either it's active content or it's dead content. If it's active, the content will change by so much that a diff would do no good (dense change), if it's nonactive it doesn't change by much or a context-dependant diff would do it much good. The first category gets a shmem buffer to write to, which is bitblted to the screen on a vertical retrace after the application signals the buffer changed, the second category gets a shared buffer to do changes in after requesting a buffer to perform changes, is notified of overlaps & redraws (and given a buffer) and can send explicit area-change or move-area messages to the UI server, causing the UI to move the area / change the area on screen too, with more efficient operations (such as partial bitblt or screen-to-screen bitblt, both only on vertical retrace, being queued after the quick operations defined before).

That way, all active content is updated quickly (movies, visualizations, games etc.) and nonactive content is updated efficiently (window borders, text content, a blinking cursor etc).

Active buffers are always allocated as a subcontainer of a nonactive buffer. They can be equal or smaller in size. You can then use the C64 idea of sprites for an idea of what it would be like, except that you can size them as you prefer.


Final note: I haven't thought about 3d buffering, but I expect active content to be similar (but you can just give the user a video memory buffer and use it as a texture) and passive content to be similar too (except that they'll now be polygons or static bitmaps).

Re:resizeable shared memory entities

Posted: Tue Jun 27, 2006 4:10 pm
by 0Scoder
About the shared memory resizing - how do your shared memory areas work? Perhaps you could, at the creation of one, reserve a space for its maximum size then just expand into that?

Or am I missing the point completely?
OScoder

Re:resizeable shared memory entities

Posted: Wed Jun 28, 2006 3:04 pm
by dc0d32
@Candy : it reminds me of the video compression techniques. Quite useful.

Re:resizeable shared memory entities

Posted: Thu Jun 29, 2006 10:07 am
by Candy
0Scoder wrote: About the shared memory resizing - how do your shared memory areas work? Perhaps you could, at the creation of one, reserve a space for its maximum size then just expand into that?

Or am I missing the point completely?
OScoder
What are you going to resize?


Shared memory in UI server is allocated, then used, then freed.

If you allocate normal shared memory and want to increase it, I'd use the realloc algorithm - if you want more, allocate new size, copy all data, free old, return new. If you can't allocate more,signal that it's impossible and return.

Since the UI server never tries to realloc, it either can update its screen or it can't. Somehow I'll have to quota shmem too, so no application can truly misbehave.

Re:resizeable shared memory entities

Posted: Fri Jun 30, 2006 2:31 am
by distantvoices
Hi, lads! first year's over! *pfuh*

Thanks for your replies at first. I'm just able to reply in coherent manner. Have had a feast yesterday evening (*gulp* loooootsa beer)

@osdever: shm in my os is arrays of pages assigned to a shm entity. Usually, their size is predetermined, i.e. one can't change it afterwards without first detaching from the entity and realloc the stuff.

I want to be able to resize them in a given min - max range. The entity is mapped into a virtual address space with its max range so others won't overlap with it. Oh, I love virtual address space, have I said this already?

@candy: resizing a window. In my opinion this is not an application related operation but something the ui service has to handle. So, upon resizing, the shm entity shared between service and client for that window - it is meant as a backing store for the window - shouldn't be reallocated but adjusted in size.

This means: upon growth: add pages to the page array. map the new pages into the address space of both the service and the client. upon shrinking: remove pages at the bottom of the page array and remove them from client/service address space. And yeah, I know, it would require quite some cr3 reloading which trashes the tlb. Not nice. Not nifty. SO I'll stick with the xor lasso technique for now.

YOu know, with that backing store trick per window, one can do all sorts of dirty & nifty tricks like transparency & shadows nearby onthe fly with some composing stuff. Further, the window moving stuff is eased to quite great a deal. and updating a changed region of the window is merely a clipped blit of that region to screen memory.

STay safe :-)

Re:resizeable shared memory entities

Posted: Fri Jun 30, 2006 5:31 am
by Pype.Clicker
there's a down side of shm between GUI clients and server, though ... you can hardly make it work over the network ...

I mean, okay, it will work (VNC does), but it will involve a significantly higher load than what X protocol allows, no ?

(Not meaning that i love X, you all know i plan to implement Y instead ;D )

Re:resizeable shared memory entities

Posted: Fri Jun 30, 2006 9:47 am
by mystran
beyond infinity wrote: The client does all its drawing in this shm entity.

The gui service can take the entity and perform any operation it wants on it. say "transparency", "clipping", "hide", "move", "resize"

The "resize" is which gives me a little bit to think.

It is a shared memory entity after all.

Is it reasonable to actually resize the thing or to simply drop it and create a new one for both the client and the server to map in?
Don't do it that way.

Instead, let server do the drawing. It can accelerate them if it wants, and it can make efficient use of device offscreen memory and whatever.

Instead, use shared memory as a bitmap buffer. It can be of any size, as long as it's "large enough". Application can fill that area with whatever data it wants, and then tell that "beginning at offset is the (top,left)-corner of the image I want to copy at x,y in my window. I want to copy an area of <x_width,y_width> and a line in the source bitmap is n bytes wide".

Now, application can draw it's whole image into the buffer, and then tell a Blit, but it can just cache bitmaps into it as well, and then do intelligent drawing that server can accelerate given proper drivers. Graphics server can even map parts of the buffer into offscreen memory if your share memory allows that and theres room.

Now resize is just a graphics server side issue, and all you need to tell application is the new size and a request to redraw.