Excellent program Ape's nature is curious, how the software works, how the screen is displayed, why the desktop window can be so human-dragged by the mouse?
Let's say you have a lot of questions going on in your mind, congratulations, you're a great potential program ape.
What I read in college was my own initiative, the electronics, and the computer, and the first time I saw this thing, I thought it was amazing (in fact, it was just to see something with the screen that was amazing). Hardware + software In depth let me directly through the understanding of this magical machine of the two-pulse.
Software I am not the best, hardware in fact, I am very much a break. But looking at software through hardware is expected to have a little say in me. The following related content is a small personal perceptual knowledge, hope to have a certain revelation to everyone. Since the individual has done about 2 years since graduating from the Android, so take Android to see it.
Android is an operating system (hereinafter referred to as OS), executed on the hardware, OS can be equipped with App,app based on the OS burst API written.
When you write an Android program, you see that the program refers to Android.jar (which is under "Ad Folder \sdk\platforms\android-17", about 18.2M), and most of the APIs used in the program are here (e.g. activity), But a strange phenomenon, in the compiled apk does not have this thing, a simple demo-compiled apk only a few m. However, assuming that a third-party class library is referenced (such as importing a jar package in Libs, referencing an external package), the jar package is included in the compiled APK and the volume is increased. This is because the code in Android.jar already exists in the operating system (not necessarily called Android.jar, and scattered in multiple jars), and the Android.jar used to write code is used to do compile-time checks, support code hints, jump to the source code, Android.jar is a programming model.
OK, after writing the minimum demo, it can be executed on the Android phone, a small piece of code can display a very rich interface, button, click Processing.
But this little piece of code out of the OS is not working, the simple effect behind the pang system is supporting.
For example, XML-written layout files, executed will be translated into Java, classes, attributes, structure level one by one corresponding (so the XML is written in general can be completely replaced by Java).
Most of the views displayed are based on View,view.draw, which is responsible for all the drawing of the view, the default background of the button you have shown and the Click Effect is the PNG image that comes with the system. But View.draw is who call it, assuming that interrupt point debugging, will find the level is very, from the outward tune, very easy to see Halo (breakpoint find mechanism such things to long-tempered, cold day). Breakpoint can see finally initiator is choreographer (this thing is responsible for "draw/event" and so on "initiation"), that choreographer and who is driven to "start drawing", Activitythread, Activitythread is the source of the APK's operation at each frame. Understanding GUI programming students know that the program is not working, but can respond to click, is because the app has been watching you, such a monitoring called "message loop" (plainly, is a dead loop), this cycle has been inferred there is no message (you can simply interpret it as a sign) arrival (for example, click ), assuming there is a corresponding handler function for the branch callback.
How Ok,choreographer is driven is a clear step, and someone has cast a "draw message" to Activitythread's message loop.
But where did the news come from? The first time the program executes, it will actively throw one (you can pretend to throw in the program initialization), when executed, various clicks, animations will be thrown (something like view.invalidate), triggering another draw.
OK, the source of the draw trigger is probably traced to a certain extent. But how does the view appear on the screen, even though the view.draw can clearly see what is being written with canvas (such as the most frequently used canvas.drawbitmap), but how does the canvas draw on the screen?
This part of the root I have not explored the source code, but after all, arm, manually driven through the display, here just to do a rough test, the basic principle should not go.
The basic idea is that the app draw →os→ drive → hardware, haha, seemingly all and hardware-related finally mechanisms are so.
Drivers are directly involved with the hardware, usually compiled or C-written, directly control the hardware interface, generally known as the HAL (Hardware abstraction layer). Os function Intermediate Bridge.
Canvas contains a piece of bitmap (the corresponding piece of memory), the various draw of the canvas will form a pixel matrix (descriptive narration of the screen Pixel point) exists in the bitmap, through the OS to drive, drive the direct drive screen. The details of the code, the mechanism is quite cumbersome. But in theory, the description of the image in memory, basically can be displayed, that bitmap this memory is how to display it?
There is a piece of memory called "Video Memory" (is not very familiar with, desktop memory can generally be placed in the video card, in fact, which is a block of memory), as the name implies, memory is used to display the RAM.
The rationale is that the driver scans the video memory with two for (rows and columns), reads each pixel, and sets a single pixel signal to a point on the corresponding screen. Two for is a face. But how does this single pixel signal be set to a single point on the screen? Here we can simplify the single point to "light bulb", there are only two colors (white + black), the bulb is connected to the motherboard of an IO interface, IO port power on, light on. The light is black when it is broken. Driver code according to the memory of the single point of data, control the IO interface on the power off.
OK, more complicated, now the screen color is RGB (0xffffff table white, ARGB alpha is only used to give multiple layers of the operation of mixing, finally display or RGB).
A screen point is actually made up of three dots (red/green/Blue) (the TV closer to your home will look clearer). Each point of strength from not light to the brightest class, with a byte (0x00~0xff, that is, 0~255, a total of 256 levels), a point of 8 IO interface can be controlled, the driver control 8x3 IO Port can display a point of the full color.
is not a lot clearer.
But a screen with so many points (1024x768=69632), the chip is small, but there is no way to have so many interfaces it.
Played the embedded students know, generally after a display, should not exceed 50 lines (should be less than this, remember not very clear). Just said that the drive is usually drawn with two for a point of a point sweep, so theoretically leak a point of the interface (8X3) can be (actually slightly different), but how the screen know this point is drawn at which actual point?
The motherboard, the screen through the agreed-upon timing synchronization will be able to (plus a few synchronization signal interface, which row which column).
This time probably roaming here, Chase is not to die brick niu Jiao Jian, but step by step to verify their own ideas, exercise their left brain. Wirelessly structure the best source code is Andorid-os, that is the cohesion of how much thinking crystallization.
"Caprice" Android is a thing, andorid mechanism Caprice