Skip to content

Commit 9433e8d

Browse files
committed
Canvas implementation, started writing a desktop
1 parent fa1a7ff commit 9433e8d

35 files changed

+363
-132
lines changed

CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ This changelog is used to keep track of the major system changes for each versio
2424
0.5.3
2525
- removed old messaging interface
2626
- added handling of close syscall to fs delegates
27+
- fixed a bug for large shared memory mappings that would cause stack overflow

applications/login-screen/.cproject

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.cross.exe.release.1792932368" moduleId="org.eclipse.cdt.core.settings" name="build">
66
<externalSettings/>
77
<extensions>
8-
<extension id="org.eclipse.cdt.core.Cygwin_PE" point="org.eclipse.cdt.core.BinaryParser"/>
98
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
109
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
1110
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
1211
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
1312
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
13+
<extension id="org.eclipse.cdt.core.Cygwin_PE" point="org.eclipse.cdt.core.BinaryParser"/>
1414
</extensions>
1515
</storageModule>
1616
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
17-
<configuration artifactExtension="bin" artifactName="idle" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" description="" id="cdt.managedbuild.config.gnu.cross.exe.release.1792932368" name="build" parent="cdt.managedbuild.config.gnu.cross.exe.release">
17+
<configuration artifactExtension="bin" artifactName="idle" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" description="" id="cdt.managedbuild.config.gnu.cross.exe.release.1792932368" name="build" parent="cdt.managedbuild.config.gnu.cross.exe.release">
1818
<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.release.1792932368." name="/" resourcePath="">
1919
<toolChain id="cdt.managedbuild.toolchain.gnu.cygwin.base.620111594" name="Cygwin GCC" superClass="cdt.managedbuild.toolchain.gnu.cygwin.base">
2020
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.Cygwin_PE" id="cdt.managedbuild.target.gnu.platform.cygwin.base.1442479920" name="Debug Platform" osList="win32" superClass="cdt.managedbuild.target.gnu.platform.cygwin.base"/>

applications/login-screen/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SRC=src
66
OBJ=obj
77
ARTIFACT_NAME=login-screen.bin
88
CFLAGS="-std=c++11 -I$SRC"
9-
LDFLAGS=""
9+
LDFLAGS="-lcairo -lfreetype -lpixman-1 -lpng -lz"
1010

1111
# Include application build tasks
1212
. ../applications.sh

applications/login-screen/src/login-screen.cpp

+88-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <ghostuser/ui/ui.hpp>
2424
#include <ghostuser/ui/window.hpp>
2525
#include <ghostuser/ui/label.hpp>
26+
#include <ghostuser/ui/canvas.hpp>
2627
#include <ghostuser/ui/button.hpp>
2728
#include <ghostuser/ui/textfield.hpp>
2829
#include <ghostuser/ui/action_listener.hpp>
@@ -49,9 +50,7 @@ class test_layouting_bounds_listener_t: public g_bounds_listener {
4950
/**
5051
*
5152
*/
52-
virtual void handle_bounds_changed() {
53-
g_rectangle b = window->getBounds();
54-
53+
virtual void handle_bounds_changed(g_rectangle b) {
5554
b.x = 10;
5655
b.y = b.height - 80;
5756
b.height = 40;
@@ -89,7 +88,7 @@ class login_button_action_listener_t: public g_action_listener {
8988

9089
test_layouting_bounds_listener_t* layouter = new test_layouting_bounds_listener_t(dialog, button);
9190
dialog->setBoundsListener(layouter);
92-
layouter->handle_bounds_changed();
91+
layouter->handle_bounds_changed(dialog->getBounds());
9392

9493
} else {
9594
g_label* label = g_label::create();
@@ -144,14 +143,98 @@ int main(int argc, char** argv) {
144143
loginButton->setBounds(g_rectangle(10, 120, 200, 30));
145144
loginButton->setTitle("Login");
146145

146+
g_canvas* canvas = g_canvas::create();
147+
loginWindow->addChild(canvas);
148+
canvas->setBounds(g_rectangle(10, 160, 200, 30));
149+
147150
loginButton->setActionListener(new login_button_action_listener_t());
148151

149-
g_rectangle login_window_bounds(800 / 2 - 100, 600 / 2 - 100, 220, 190);
152+
g_rectangle login_window_bounds(800 / 2 - 100, 600 / 2 - 100, 220, 250);
150153
loginWindow->setBounds(login_window_bounds);
151154

152155
loginWindow->setResizable(false);
153156
loginWindow->setVisible(true);
154157

158+
// canvas test
159+
auto bufferInfo = canvas->getBuffer();
160+
klog("buffer: %x, size: %ix%i", bufferInfo.buffer, bufferInfo.width, bufferInfo.height);
161+
162+
int x = 0;
163+
double rainbowR = 0;
164+
double rainbowG = 0.5;
165+
double rainbowB = 1;
166+
167+
bool dir = true;
168+
while (true) {
169+
170+
double fact = 0.05;
171+
if ((rainbowR == 1) && (rainbowG < 1) && (rainbowB == 0)) {
172+
rainbowG += fact;
173+
}
174+
if ((rainbowG == 1) && (rainbowR > 0) && (rainbowB == 0)) {
175+
rainbowR -= fact;
176+
}
177+
if ((rainbowG == 1) && (rainbowB < 1) && (rainbowR == 0)) {
178+
rainbowB += fact;
179+
}
180+
if ((rainbowB == 1) && (rainbowG > 0) && (rainbowR == 0)) {
181+
rainbowG -= fact;
182+
}
183+
if ((rainbowB == 1) && (rainbowR < 1) && (rainbowG == 0)) {
184+
rainbowR += fact;
185+
}
186+
if ((rainbowR == 1) && (rainbowB > 0) && (rainbowG == 0)) {
187+
rainbowB -= fact;
188+
}
189+
if (rainbowR > 1) {
190+
rainbowR = 1;
191+
} else if (rainbowR < 0) {
192+
rainbowR = 0;
193+
}
194+
if (rainbowG > 1) {
195+
rainbowG = 1;
196+
} else if (rainbowG < 0) {
197+
rainbowG = 0;
198+
}
199+
if (rainbowB > 1) {
200+
rainbowB = 1;
201+
} else if (rainbowB < 0) {
202+
rainbowB = 0;
203+
}
204+
205+
if (dir) {
206+
++x;
207+
} else {
208+
--x;
209+
}
210+
211+
if (dir && x > 200 - 10) {
212+
dir = false;
213+
214+
} else if (!dir && x < 10) {
215+
dir = true;
216+
}
217+
218+
cairo_surface_t* bufferSurface = cairo_image_surface_create_for_data((uint8_t*) bufferInfo.buffer, CAIRO_FORMAT_ARGB32, bufferInfo.width,
219+
bufferInfo.height, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, bufferInfo.width));
220+
auto cr = cairo_create(bufferSurface);
221+
222+
cairo_save(cr);
223+
cairo_set_source_rgba(cr, 0, 0, 0, 0);
224+
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
225+
cairo_paint(cr);
226+
cairo_restore(cr);
227+
228+
cairo_set_source_rgb(cr, rainbowR, rainbowG, rainbowB);
229+
cairo_rectangle(cr, x, 0, 10, 100);
230+
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
231+
cairo_fill(cr);
232+
233+
canvas->blit(g_rectangle(0, 0, bufferInfo.width, bufferInfo.height));
234+
235+
g_sleep(10);
236+
}
237+
155238
uint8_t blocker = true;
156239
g_atomic_block(&blocker);
157240
}

applications/ps2driver/src/ps2_driver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int main() {
8383

8484
// wait for control requests
8585
size_t buflen = sizeof(g_message_header) + sizeof(g_ps2_register_request);
86-
uint8_t buf[buflen];
86+
uint8_t* buf = new uint8_t[buflen];
8787
g_tid tid = g_get_tid();
8888
while (true) {
8989
g_message_receive_status stat = g_receive_message(buf, buflen);

applications/vbedriver/.cproject

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.cross.exe.release.1792932368" moduleId="org.eclipse.cdt.core.settings" name="build">
66
<externalSettings/>
77
<extensions>
8-
<extension id="org.eclipse.cdt.core.Cygwin_PE" point="org.eclipse.cdt.core.BinaryParser"/>
98
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
109
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
1110
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
1211
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
1312
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
13+
<extension id="org.eclipse.cdt.core.Cygwin_PE" point="org.eclipse.cdt.core.BinaryParser"/>
1414
</extensions>
1515
</storageModule>
1616
<storageModule moduleId="cdtBuildSystem" version="4.0.0">

applications/windowserver/src/components/component.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ class component_t: public bounds_event_component_t {
7676
bool visible;
7777

7878
public:
79+
g_ui_component_id id;
80+
7981
/**
8082
* Creates the component; initially marks it as dirty
8183
* and sets no parent
8284
*/
8385
component_t(bool transparentBackground = false) :
84-
graphics(transparentBackground), visible(true), requirements(COMPONENT_REQUIREMENT_ALL), childRequirements(COMPONENT_REQUIREMENT_ALL), parent(0), layoutManager(
85-
0), bounds_event_component_t(this) {
86+
id(-1), graphics(transparentBackground), visible(true), requirements(COMPONENT_REQUIREMENT_ALL), childRequirements(COMPONENT_REQUIREMENT_ALL), parent(
87+
0), layoutManager(0), bounds_event_component_t(this) {
8688
}
8789

8890
/**

applications/windowserver/src/events/event_processor.cpp

+48-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@
2020

2121
#include <components/cursor.hpp>
2222
#include <events/event_processor.hpp>
23-
#include <ghostuser/tasking/lock.hpp>
2423
#include <input/input_receiver.hpp>
2524
#include <interface/component_registry.hpp>
2625

26+
#include <ghostuser/tasking/lock.hpp>
27+
#include <ghostuser/ui/interface_specification.hpp>
28+
2729
#include <windowserver.hpp>
2830
#include <components/window.hpp>
2931
#include <components/button.hpp>
3032
#include <components/text/text_field.hpp>
3133
#include <components/label.hpp>
34+
#include <components/canvas.hpp>
3235

3336
#include <events/event.hpp>
3437
#include <events/mouse_event.hpp>
@@ -83,7 +86,7 @@ void event_processor_t::process() {
8386
buf_response.message = 0;
8487

8588
// process the actual action
86-
process_command((g_ui_message_header*) G_MESSAGE_CONTENT(request_buffer), buf_response);
89+
process_command(message->sender, (g_ui_message_header*) G_MESSAGE_CONTENT(request_buffer), buf_response);
8790

8891
// add generated response to queue
8992
if (buf_response.message != 0) {
@@ -98,7 +101,7 @@ void event_processor_t::process() {
98101
/**
99102
*
100103
*/
101-
void event_processor_t::process_command(g_ui_message_header* request_header, command_message_response_t& response_out) {
104+
void event_processor_t::process_command(g_tid sender_tid, g_ui_message_header* request_header, command_message_response_t& response_out) {
102105

103106
if (request_header->id == G_UI_PROTOCOL_CREATE_COMPONENT) {
104107
component_t* component = 0;
@@ -112,16 +115,24 @@ void event_processor_t::process_command(g_ui_message_header* request_header, com
112115
component = new window_t();
113116
windowserver_t::instance()->screen->addChild(component);
114117
break;
118+
115119
case G_UI_COMPONENT_TYPE_LABEL:
116120
component = new label_t();
117121
break;
122+
118123
case G_UI_COMPONENT_TYPE_BUTTON:
119124
component = new button_t();
120125
break;
126+
121127
case G_UI_COMPONENT_TYPE_TEXTFIELD:
122128
component = new text_field_t();
123129
break;
124130

131+
case G_UI_COMPONENT_TYPE_CANVAS: {
132+
component = new canvas_t(sender_tid);
133+
break;
134+
}
135+
125136
default:
126137
klog("don't know how to create a component of type %i", create_request->type);
127138
break;
@@ -130,6 +141,7 @@ void event_processor_t::process_command(g_ui_message_header* request_header, com
130141
// register the component
131142
if (component != 0) {
132143
component_id = component_registry_t::add(component);
144+
133145
// apply default properties
134146
component->setBounds(g_rectangle(100, 100, 200, 80));
135147
}
@@ -319,6 +331,39 @@ void event_processor_t::process_command(g_ui_message_header* request_header, com
319331
response_out.message = response;
320332
response_out.length = sizeof(g_ui_component_get_title_response);
321333

334+
} else if (request_header->id == G_UI_PROTOCOL_CANVAS_ACK_BUFFER_REQUEST) {
335+
g_ui_component_canvas_ack_buffer_request* request = (g_ui_component_canvas_ack_buffer_request*) request_header;
336+
component_t* component = component_registry_t::get(request->id);
337+
338+
canvas_t* canvas = (canvas_t*) component;
339+
canvas->acknowledgeCurrentBuffer();
340+
341+
} else if (request_header->id == G_UI_PROTOCOL_CANVAS_BLIT) {
342+
g_ui_component_canvas_ack_buffer_request* request = (g_ui_component_canvas_ack_buffer_request*) request_header;
343+
component_t* component = component_registry_t::get(request->id);
344+
345+
canvas_t* canvas = (canvas_t*) component;
346+
canvas->blit();
347+
348+
} else if (request_header->id == G_UI_PROTOCOL_REGISTER_DESKTOP_CANVAS) {
349+
g_ui_register_desktop_canvas_request* request = (g_ui_register_desktop_canvas_request*) request_header;
350+
component_t* component = component_registry_t::get(request->canvas_id);
351+
352+
// create response message
353+
g_ui_register_desktop_canvas_response* response = new g_ui_register_desktop_canvas_response;
354+
if (component == 0) {
355+
response->status = G_UI_PROTOCOL_FAIL;
356+
} else {
357+
response->status = G_UI_PROTOCOL_SUCCESS;
358+
359+
canvas_t* canvas = (canvas_t*) component;
360+
screen_t* screen = windowserver_t::instance()->screen;
361+
screen->addChild(canvas);
362+
canvas->setBounds(screen->getBounds());
363+
}
364+
365+
response_out.message = response;
366+
response_out.length = sizeof(g_ui_register_desktop_canvas_response);
322367
}
323368

324369
}

applications/windowserver/src/events/event_processor.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class event_processor_t {
4646
void bufferCommandMessage(void* commandMessage);
4747

4848
void process();
49-
void process_command(g_ui_message_header* request_header, command_message_response_t& response_out);
49+
void process_command(g_tid sender_tid, g_ui_message_header* request_header, command_message_response_t& response_out);
5050

5151
void translateKeyEvent(g_key_info& info);
5252
void processMouseState();

applications/windowserver/src/interface/component_registry.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static g_ui_component_id next_id = 1;
3030
g_ui_component_id component_registry_t::add(component_t* component) {
3131
g_ui_component_id id = next_id++;
3232
components[id] = component;
33+
component->id = id;
3334
return id;
3435
}
3536

kernel/iso/boot/grub/grub.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set timeout=0
12
set default=0
23

34
menuentry "Ghost" {

kernel/src-kernel/calls/syscall_handler_memory.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ G_SYSCALL_HANDLER(alloc_mem) {
4747
data->virtualResult = 0;
4848

4949
// Get the number of pages
50-
uint32_t pages = PAGE_ALIGN_UP(data->size) / G_PAGE_SIZE;
50+
uint32_t pages = G_PAGE_ALIGN_UP(data->size) / G_PAGE_SIZE;
5151
if (pages > 0) {
5252
// Allocate a virtual range, we are physical owner
5353
uint8_t virtualRangeFlags = G_PROC_VIRTUAL_RANGE_FLAG_PHYSICAL_OWNER;
@@ -116,7 +116,7 @@ G_SYSCALL_HANDLER(share_mem) {
116116

117117
// Get the number of pages
118118
uint32_t memory = (uint32_t) data->memory;
119-
uint32_t pages = PAGE_ALIGN_UP(data->size) / G_PAGE_SIZE;
119+
uint32_t pages = G_PAGE_ALIGN_UP(data->size) / G_PAGE_SIZE;
120120

121121
// Only allow sharing in user memory
122122
if (memory < G_CONST_KERNEL_AREA_START && (memory + pages * G_PAGE_SIZE) <= G_CONST_KERNEL_AREA_START) {
@@ -133,19 +133,15 @@ G_SYSCALL_HANDLER(share_mem) {
133133
if (virtualRangeBase != 0) {
134134

135135
g_page_directory executing_space = g_address_space::get_current_space();
136-
g_physical_address pagesPhysical[pages];
137136

138137
// Map the pages to the other processes space
139138
for (uint32_t i = 0; i < pages; i++) {
140-
pagesPhysical[i] = g_address_space::virtual_to_physical(memory + i * G_PAGE_SIZE);
141-
}
139+
g_physical_address physical_addr = g_address_space::virtual_to_physical(memory + i * G_PAGE_SIZE);
142140

143-
g_address_space::switch_to_space(targetProcess->pageDirectory);
144-
for (uint32_t i = 0; i < pages; i++) {
145-
g_address_space::map(virtualRangeBase + i * G_PAGE_SIZE, pagesPhysical[i],
146-
DEFAULT_USER_TABLE_FLAGS, DEFAULT_USER_PAGE_FLAGS);
141+
g_address_space::switch_to_space(targetProcess->pageDirectory);
142+
g_address_space::map(virtualRangeBase + i * G_PAGE_SIZE, physical_addr, DEFAULT_USER_TABLE_FLAGS, DEFAULT_USER_PAGE_FLAGS);
143+
g_address_space::switch_to_space(executing_space);
147144
}
148-
g_address_space::switch_to_space(executing_space);
149145

150146
// Done
151147
data->virtualAddress = (void*) virtualRangeBase;
@@ -185,7 +181,7 @@ G_SYSCALL_HANDLER(map_mmio) {
185181
// Only kernel and drivers may do this
186182
if (process->securityLevel <= G_SECURITY_LEVEL_DRIVER) {
187183

188-
uint32_t pages = PAGE_ALIGN_UP(data->size) / G_PAGE_SIZE;
184+
uint32_t pages = G_PAGE_ALIGN_UP(data->size) / G_PAGE_SIZE;
189185

190186
// Allocate a virtual range (but not be physical owner)
191187
g_virtual_address range = process->virtualRanges.allocate(pages,

kernel/src-kernel/calls/syscall_handler_spawning.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ G_SYSCALL_HANDLER(write_tls_master_for_process) {
267267
g_process* target_process = target_thread->process;
268268

269269
// Get a virtual address range for the TLS master copy
270-
uint32_t required_pages = PAGE_ALIGN_UP(data->copysize) / G_PAGE_SIZE;
270+
uint32_t required_pages = G_PAGE_ALIGN_UP(data->copysize) / G_PAGE_SIZE;
271271
g_virtual_address tls_master_virt = target_process->virtualRanges.allocate(required_pages, G_PROC_VIRTUAL_RANGE_FLAG_PHYSICAL_OWNER);
272272

273273
// Temporarily copy master contents to kernel heap because we switch directories

0 commit comments

Comments
 (0)