0

So I have been doing a lot of reading about execution environments (Python's, JVM...) and I am starting to implement one on my own. It is a register-based environment written in C. I have a basic byte code format defined and the execution is going pretty smooth so far. My question is how does VEs render GUIs. In a more detailed description about my work so far, my VE has a screen buffer (experimenting with it). Every time I poke it, I output the screen buffer completely to know the output.

So far so good with basic calculations and stuff but I hit a bump when I wanted to understand how to render GUIs. I am nowhere with this. Any help would be appreciated. Even if I am thinking completely wrong about this, any pointers as a start in the right direction would be really great. Thanks.

1 Answer 1

1

All GUI toolkits on Python are a wrapper around C/C++ code. On Java there a some "pure" Java toolkits like Swing, but a the lowest level they depend on C code to do the drawing and handle user input. There's no special support for things like graphics in the Java VM.

As for how the GUI gets rendered at the lowest level, it depends. On Windows, user mode software isn't allowed direct access the video hardware. Ultimately any C/C++ GUI code has to go through either GDI or Direct3D to do the rendering. The kernel mode GDI code is able to do all the rendering itself by writing to the framebuffer, but also supports acceleration by passing operations to display driver. On the other hand, the Direct3D kernel code passes pretty much everything to the driver which in turn passes everything on to the GPU. Almost all of the kernel mode code is written in C, while code running on the GPU is a mixture of hand coded assembly from and code written in higher level shading languages.

Note that GPU assembly language is very different from Intel x86 assembly language, and varies considerably between manufacturers and GPU generations.

I'm not sure what current practice is on Linux and other Unix type operating systems, but it used to be common to give the X server, which is a user mode process, direct access to the framebuffer. C code in the X server was ultimately responsible for rendering. Presumably this has changed at least somewhat now that GPU acceleration is more common.

Sign up to request clarification or add additional context in comments.

5 Comments

Ross, Thank you for that. So I found out about NASM and FASM (essentially assemblers that outputs executables) which does GUI but they are platform specific. I couldn't find much examples for GUI on linux using NASM or FASM though. Coming to your point, do you have any idea about those C/C++ code|libraries which Python|Java uses to render GUIs. I am writing my VE in C so it shouldn't too much of a problem for me to give it a try. Thanks.
I'm not really really sure what you're asking, but I think you'd be better off not trying to render GUIs in your VM and leaving it to existing GUI toolkits. Also if you're not familiar with GUI programming, trying to implement one in your own VM is not a good way to learn.
Ross, I have done GUI using Win32 APIs and also on a higher level using C# and WPF. Now I want to understand how exactly it is being done in the real low level. Like rendering windows, controls, event capturing,... After a long dig, I found out about the cross-platform GTK+ SDK designed ground up from C. But I want some pointers regarding how it is really done at the low level. I am sorry if there are any confusions.
I've added an overview of how things ultimately get rendered to my answer, hopefully that will give you some insight.
@ShankarMJ - This answer seems pretty complete to me. FYI, the open-jdk-7-jre package on Ubuntu depends on the libgtk2 package for GUIs, which in turn depends on Cairo for 2D drawing. If you want to develop a VM, there's no point in re-inventing the wheel for rendering GUI components. At some point you're going to start developing an operating system that happens to have a virtual machine it can run...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.