The entry paint
The source src/modules/demonstrations/paint built with the setting DRAWING_THROUGH_MODULE=true. The text after this paragraph is the comment of that source.
A paint program: brushes, an eraser, a palette and a custom color, the tools line, rectangle, ellipse and fill, undo and redo, and pictures in the private store of the process. The design is in The paint application in the repository.
This process is also a service: it serves its exports while it runs. Another process draws on the picture with isolated calls. The calls run in the one thread of this process, between two input events.
What it is for. It is the paint program of the desktop, and the smallest process that is both an application and a service: the same window takes the pointer and the calls of the console, with one thread and no lock, because a call runs between two events.
Start: start("paint") in the console, or the bar of the desktop. Then, from the console: connect("paint"), paint.line(0, 0, 479, 295, 4), paint.write(20, 20, "hello", 9). The log has "paint: ok" when the window opens.
The keys: B brush, E eraser, L line, R rectangle, O ellipse, F fill, [ and ] the size, Ctrl+Z undo, Ctrl+Shift+Z and Ctrl+Y redo, Ctrl+O the pictures, C clear, Escape closes a panel. The right button draws with the paper.
Grants, as the root service gives them:
- Serve: its exports, for the console.
- Store: its private store, for the pictures.
The picture: the largest is the logical screen of the reference screen. The window shows its top left part; a resize never cuts it. The colors of the exports are the 16 colors of the palette, numbered 0 to 15: dark, white, gray, light gray, red, orange, yellow, green, teal, blue, violet, pink, brown, sand, navy, paper.
paint module with an entry
- Hash
d26f75573e0a69453839edae794795fa09c292f0626d1ba45468f3de35a3f629- Size
312987 bytes- Exports
4- Imports
1- Imported by
0- License
- MIT
A paint program: brushes, an eraser, a palette and a custom color, the tools line, rectangle, ellipse and fill, undo and redo, and pictures in the private store of the process
| Fact | Value |
|---|---|
| Kind | Modules with an entry |
| Source | src/modules/demonstrations/paint |
| Boot image | yes: in the boot image, 312987 bytes in this build |
| Build settings |
|
| Imports | |
| Imported by | none |
Neighbours
What it imports, at its left, and what imports it, at its right: the part of the module graph that touches it.
Exports
| Export | What it does |
|---|---|
line(from_x: Integer, from_y: Integer, to_x: Integer, to_y: Integer, color: Integer) -> Integer | draws a line on the picture, with a color of the palette (0 to 15) |
write(x: Integer, y: Integer, text: Text, color: Integer) -> Integer | draws a text on the picture, with a color of the palette (0 to 15) |
clear() | erases the picture |
lines() -> Integer | gives the count of lines that calls drew since the last clear |
entry() | The entry of paint: it opens its service, its window and its store, then runs the calls and the events in one loop until the principal closes the window |
line
line(from_x: , from_y: , to_x: , to_y: , color: ) ->
line draws a line on the picture, with a color of the palette (0 to 15). A point off the picture is fine: the picture shows the part of the line on it.
The line is 3 pixels wide. A coordinate beyond 4096 in either direction is taken as 4096: the picture is far smaller, so the visible part does not change. The line is not a step of undo.
- from_x, from_y: the first point, in pixels of the picture (0, 0 is its top left corner).
- to_x, to_y: the last point.
- color: the number of a color of the palette, 0 to 15.
The result is the count of lines that calls drew since the last clear. It fails with -1 and an error record: Bad_Value when the color is not 0 to 15; the record names the fifth argument.
Example: paint.line(0, 0, 479, 295, 4) draws a red diagonal.
from_x:from_y:to_x:to_y:color:
- When it fails
- a negative result, and the error record
src/modules/demonstrations/paint/main.odin:282
write
write(x: , y: , text: , color: ) ->
write draws a text on the picture, with a color of the palette (0 to 15).
The text is drawn with the font of the system, from its top left corner. A text that passes the edge of the picture is cut there. The text is not a step of undo.
- x: the left of the text, in the picture: 0 to its width less 1.
- y: the top of the text, in the picture: 0 to its height less 1.
- text: the bytes of the text.
- color: the number of a color of the palette, 0 to 15.
The result is the count of bytes of the text. It fails with -1 and an error record: Bad_Value when x or y is outside the picture, or when the color is not 0 to 15; the record names the argument.
x:y:text:color:
- When it fails
- a negative result, and the error record
src/modules/demonstrations/paint/main.odin:305
clear
clear()
clear erases the picture.
It also sets the count of lines that lines gives back to 0. The key c in the window clears the picture too, as a step of undo. It has no parameter, no result, and never fails.
lines
lines() ->
lines gives the count of lines that calls drew since the last clear.
Only the calls of line count: the lines that the pointer draws do not. A test draws through calls, then reads this count to check that each call ran one time.
entry
entry()
The entry of paint: it opens its service, its window and its store, then runs the calls and the events in one loop until the principal closes the window.
With no window it stops with Failed. Each turn draws a frame, then waits for an event or a call. The calls run first, then the events.
- Form
- The entry of the module: one parameter, an address, fixed by the contract.
src/modules/demonstrations/paint/main.odin:1374
Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).
What the root service gives it
| What | Value | As the root service says |
|---|---|---|
| Grants | A service: the console calls its exports through a connection. Its private store keeps the pictures that the principal saves . See: The paint application in the repository | |
| Other terms of its start grant set | store_blocks = 12000 | |
| Budget that it asks for |
| The budget of paint, under the largest budget that the root service gives a process (module.LARGEST_BUDGET_PAGES of the module contract, which the root service reads too: 16384 pages), with a margin. The tool counts the module pages (the code, the data and each array below), the stacks of the two threads and the two pictures of the window at its largest size; the source states the working memory. The arrays, in pages of 4 KiB:
The window: 1536 x 864 logical pixels at the largest scale, cut on each axis to the reference screen as the tool counts it : 1920 x 1080 pixels, 4 bytes each, two pictures: 4050 pages. A resize holds the old surface and the new one together until the compositor shows the new one, so the working memory holds a second surface: 4050 pages. It also holds the least budget of 2048 pages less a window of 480 x 320 (300 pages): 1748 pages for the stack, the tables and the glyph memory; the glyph memory of the copy of the text rendering of the drawing module, 354 pages (display.TEXT_MEMORY_PAGES); and 48 pages, the stack of the worker thread past the 16 pages that the tool counts for a thread. 4050 + 1748 + 354 + 48 = 6200. The tool reads the literal; a check below ties it to these parts. See: From the desktop of today to a light web browser: The budgets in the repository |
The start grant set is read from start_grant_sets in src/modules/system/root/start_grant_sets.odin. The stated budget is read from the constant MODULE_BUDGET of the source of the module (its line); the build adds the counted parts and writes the sum in the module (tools/modustool/build/budget_count.odin); the root service accepts it up to the largest budget of a process, and adds the limits of processor time and of log records (src/modules/system/root/budgets.odin).
Integer wire form
A wire form of the module contract: one word of a call. A signed integer of 64 bits, in a register.
Error_Record record of a module
A record of the module paint: 56 bytes, aligned on 8 bytes, 0 bytes of padding.
kindi6408 bytesuniti6488 bytesoperationi64168 bytesargumenti64248 bytesvaluei64328 byteslimiti64408 bytesfoundi64488 bytes
Text wire form
A wire form of the module contract: one word of a call. The address of a slice record {address, count} of UTF-8 bytes.
