Window Manager Repainting

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Window Manager Repainting

Post by max »

Hello :)

I'm currently implementing my window manager (for the second time :mrgreen:). For performance reasons, I don't want to repaint/blit everything on the screen each time it refreshes. I'd like to hear some feedback on the model I came up with, and how you have done this.

Theres a screen class containing the root component. Everything on the screen is a component and has a buffer of its width * height * 4 bytes (ARGB) for the content. Each component has a bool "needsRepaint" that indicates whether the component needs to be repainted. The screen holds a rectangle that contains the absolute invalid area on the screen of what has changed.

Updating:
The root component of the screen is asked to update; this updates itself and tells each child to do the same. Each component may now do animation stuff and the like and decide if it needs to be repainted.

Painting:
The root component of the screen is asked to paint; this paints itself to the buffer if "needsRepaint" is set and then tells each child to do the same. Each component may then use the "invalidate" method giving the area on itself that must be copied to the graphics buffer to its parent, which does the same recursively until the screen is reached. The screen then adds this area to it's invalid rectangle.

Blitting:
The buffers of all components are recursively added to the screen buffer.

Posting:
The area that is marked as invalid on the screen is converted to the output graphics format and copied to the buffer of the graphics driver.

For illustration purposes, this is pseudocode of how the two basic classes look like:

Code: Select all

class Screen {
  Rectangle invalid;
}

class Component {
  Component* parent;
  list children;
  bool needsRepaint;
  void update();
  void paint();
  void invalidate(Rectangle r);
}
What do you think about this?

Greets, Max
embryo

Re: Window Manager Repainting

Post by embryo »

max wrote:What do you think about this?
It reminds me the Java's Abstract Windowing Toolkit. The AWT is a good designed thing, then why not to copy it's design decisions?
User avatar
KemyLand
Member
Member
Posts: 213
Joined: Mon Jun 16, 2014 5:33 pm
Location: Costa Rica

Re: Window Manager Repainting

Post by KemyLand »

Nice and clean OO model for a WinMan (much like Java's AWT and Swing :wink: ) I would suggest to implement an abstraction layer between the actual window manager and the apps. It isn't nice to do putpixel(x,y,r,g,b,a) for every pixel, or even something like paintstar(x,y,w,h,r,g,b,a) isn't always the best. If not in raw draw mode, the apps must have a general way to "make a window", or else they could make all sorts of strange things (though thats not a bad idea :D )

Anyway, you're only talking about the WM Repainting Model. For me, its fine. Just remember that Torvalds won't like your code if it uses C++ :mrgreen: :mrgreen: :mrgreen:. (Just a joke. In my opinion its a good language IF used PROPERLY).

I would give the WinMan a 65HZ+ frequency for checking if necessary/doing repainting.

Note: In Java you can also revalidate() && setVisible(false) && .addComponent(new TuxToy());
Happy New Code!
Hello World in Brainfuck :D:

Code: Select all

++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
[/size]
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Window Manager Repainting

Post by max »

Yes it is similar to the AWT model, because I have made a lot good experiences with that framework. Also, I'll port a JVM to the system and that will make AWT-bindings quite easy :P

To the API part you mentioned: there will be an API (accessed mostly via messaging) that allows programs to create a list of standard components, like windows, buttons, checkboxes, whatever is used in normal UIs. If applications want to draw something freely, they must first create a canvas component, place it somewhere, and then they can obtain a shared memory area to the canvas' paint buffer.

Maybe I'll also allow sharing the internal buffer of standard components with applications too later, so applications have maximal freedom. Also like this I can create for example screenshots of windows only, as I just have to blit all its components to a buffer.
KemyLand wrote:Note: In Java you can also revalidate() && setVisible(false) && .addComponent(new TuxToy());
revalidate is basically what my invalidate is. Visibility is something I have to add, yes :) Adding components would just be adding it to the child list of the parent component.

Thanks for the feedback so far :)
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: Window Manager Repainting

Post by alexfru »

KemyLand wrote: I would give the WinMan a 65HZ+ frequency for checking if necessary/doing repainting.
I don't think there should be any kind of explicit polling here. The manager should be able to postpone work when it knows there's something to be done, but it shouldn't just scan and check things in the background in the hope to find work to do. It should know exactly.
User avatar
KemyLand
Member
Member
Posts: 213
Joined: Mon Jun 16, 2014 5:33 pm
Location: Costa Rica

Re: Window Manager Repainting

Post by KemyLand »

alexfru wrote:
KemyLand wrote: I would give the WinMan a 65HZ+ frequency for checking if necessary/doing repainting.
I don't think there should be any kind of explicit polling here. The manager should be able to postpone work when it knows there's something to be done, but it shouldn't just scan and check things in the background in the hope to find work to do. It should know exactly.
I was talking about an estimated timeslice, not a forced polling frequency nor similar things. Also (to max :wink: ). You could save A LOT of work by porting the Mono Project instead of, for example, OpenJDK. You'll also have runtime support for .NET and many managed languages. Check here for more info.
Happy New Code!
Hello World in Brainfuck :D:

Code: Select all

++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
[/size]
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Window Manager Repainting

Post by max »

KemyLand wrote:I was talking about an estimated timeslice, not a forced polling frequency nor similar things. Also (to max :wink: ). You could save A LOT of work by porting the Mono Project instead of, for example, OpenJDK. You'll also have runtime support for .NET and many managed languages. Check here for more info.
I will not port OpenJDK to Ghost, but the JVM that a friend of mine is developing :)
Thanks for the idea, i dont like .NET very much though :P
User avatar
KemyLand
Member
Member
Posts: 213
Joined: Mon Jun 16, 2014 5:33 pm
Location: Costa Rica

Re: Window Manager Repainting

Post by KemyLand »

Jeje, I don't think none of us really likes .NET, it was just promoting :twisted:

BTW, good luck with that JVM, I would like to use it (for porting simplicity and low error pronity).
Happy New Code!
Hello World in Brainfuck :D:

Code: Select all

++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
[/size]
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Window Manager Repainting

Post by max »

KemyLand wrote:Jeje, I don't think none of us really likes .NET, it was just promoting :twisted:

BTW, good luck with that JVM, I would like to use it (for porting simplicity and low error pronity).
Sure you can, the VM itself soon reaches beta status, biggest thing left is the java library. The VM will be open source and is made with high portability in mind, we'll announce it here, too ;)
Post Reply