Permalink
Browse files

Canvas implementation, started writing a desktop

  • Loading branch information...
maxdev1 committed Jul 12, 2016
1 parent fa1a7ff commit 9433e8dafc45fbaeca1d220379dfcee042d98966
Showing with 363 additions and 132 deletions.
  1. +1 −0 CHANGELOG
  2. +2 −2 applications/login-screen/.cproject
  3. +1 −1 applications/login-screen/build.sh
  4. +88 −5 applications/login-screen/src/login-screen.cpp
  5. +1 −1 applications/ps2driver/src/ps2_driver.cpp
  6. +1 −1 applications/vbedriver/.cproject
  7. +4 −2 applications/windowserver/src/components/component.hpp
  8. +48 −3 applications/windowserver/src/events/event_processor.cpp
  9. +1 −1 applications/windowserver/src/events/event_processor.hpp
  10. +1 −0 applications/windowserver/src/interface/component_registry.cpp
  11. +1 −0 kernel/iso/boot/grub/grub.cfg
  12. +7 −11 kernel/src-kernel/calls/syscall_handler_memory.cpp
  13. +1 −1 kernel/src-kernel/calls/syscall_handler_spawning.cpp
  14. +3 −3 kernel/src-kernel/executable/elf32_loader.cpp
  15. +4 −4 kernel/src-kernel/filesystem/fs_delegate_tasked.cpp
  16. +1 −1 kernel/src-kernel/kernel.cpp
  17. +8 −8 kernel/src-kernel/memory/address_space.cpp
  18. +4 −4 kernel/src-kernel/memory/physical/pp_reference_tracker.cpp
  19. +3 −3 kernel/src-kernel/system/acpi/acpi.cpp
  20. +5 −5 kernel/src-kernel/system/interrupts/handling/interrupt_exception_handler.cpp
  21. +3 −3 kernel/src-kernel/system/interrupts/ioapic.cpp
  22. +2 −2 kernel/src-kernel/tasking/thread_manager.cpp
  23. +3 −3 kernel/src-loader/kernelloader/kernel_loader.cpp
  24. +5 −5 kernel/src-loader/loader.cpp
  25. +3 −3 kernel/src-loader/memory/multiboot_mmap_interpreter.cpp
  26. +7 −7 kernel/src-loader/memory/paging_initializer.cpp
  27. +1 −15 kernel/src-shared/memory/paging.hpp
  28. +1 −1 libc/.settings/language.settings.xml
  29. +5 −0 libc/src/_conformity.c
  30. +4 −2 libuser/inc/ghostuser/ui/bounds_listener.hpp
  31. +16 −3 libuser/inc/ghostuser/ui/canvas.hpp
  32. +37 −7 libuser/inc/ghostuser/ui/interface_specification.hpp
  33. +4 −0 libuser/inc/ghostuser/ui/ui.hpp
  34. +55 −24 libuser/src/ghostuser/ui/canvas.cpp
  35. +32 −1 libuser/src/ghostuser/ui/ui.cpp
View
@@ -24,3 +24,4 @@ This changelog is used to keep track of the major system changes for each versio
0.5.3
- removed old messaging interface
- added handling of close syscall to fs delegates
- fixed a bug for large shared memory mappings that would cause stack overflow
@@ -5,16 +5,16 @@
<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">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.Cygwin_PE" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.Cygwin_PE" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<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">
<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">
<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.release.1792932368." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.cygwin.base.620111594" name="Cygwin GCC" superClass="cdt.managedbuild.toolchain.gnu.cygwin.base">
<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"/>
@@ -6,7 +6,7 @@ SRC=src
OBJ=obj
ARTIFACT_NAME=login-screen.bin
CFLAGS="-std=c++11 -I$SRC"
LDFLAGS=""
LDFLAGS="-lcairo -lfreetype -lpixman-1 -lpng -lz"
# Include application build tasks
. ../applications.sh
@@ -23,6 +23,7 @@
#include <ghostuser/ui/ui.hpp>
#include <ghostuser/ui/window.hpp>
#include <ghostuser/ui/label.hpp>
#include <ghostuser/ui/canvas.hpp>
#include <ghostuser/ui/button.hpp>
#include <ghostuser/ui/textfield.hpp>
#include <ghostuser/ui/action_listener.hpp>
@@ -49,9 +50,7 @@ class test_layouting_bounds_listener_t: public g_bounds_listener {
/**
*
*/
virtual void handle_bounds_changed() {
g_rectangle b = window->getBounds();
virtual void handle_bounds_changed(g_rectangle b) {
b.x = 10;
b.y = b.height - 80;
b.height = 40;
@@ -89,7 +88,7 @@ class login_button_action_listener_t: public g_action_listener {
test_layouting_bounds_listener_t* layouter = new test_layouting_bounds_listener_t(dialog, button);
dialog->setBoundsListener(layouter);
layouter->handle_bounds_changed();
layouter->handle_bounds_changed(dialog->getBounds());
} else {
g_label* label = g_label::create();
@@ -144,14 +143,98 @@ int main(int argc, char** argv) {
loginButton->setBounds(g_rectangle(10, 120, 200, 30));
loginButton->setTitle("Login");
g_canvas* canvas = g_canvas::create();
loginWindow->addChild(canvas);
canvas->setBounds(g_rectangle(10, 160, 200, 30));
loginButton->setActionListener(new login_button_action_listener_t());
g_rectangle login_window_bounds(800 / 2 - 100, 600 / 2 - 100, 220, 190);
g_rectangle login_window_bounds(800 / 2 - 100, 600 / 2 - 100, 220, 250);
loginWindow->setBounds(login_window_bounds);
loginWindow->setResizable(false);
loginWindow->setVisible(true);
// canvas test
auto bufferInfo = canvas->getBuffer();
klog("buffer: %x, size: %ix%i", bufferInfo.buffer, bufferInfo.width, bufferInfo.height);
int x = 0;
double rainbowR = 0;
double rainbowG = 0.5;
double rainbowB = 1;
bool dir = true;
while (true) {
double fact = 0.05;
if ((rainbowR == 1) && (rainbowG < 1) && (rainbowB == 0)) {
rainbowG += fact;
}
if ((rainbowG == 1) && (rainbowR > 0) && (rainbowB == 0)) {
rainbowR -= fact;
}
if ((rainbowG == 1) && (rainbowB < 1) && (rainbowR == 0)) {
rainbowB += fact;
}
if ((rainbowB == 1) && (rainbowG > 0) && (rainbowR == 0)) {
rainbowG -= fact;
}
if ((rainbowB == 1) && (rainbowR < 1) && (rainbowG == 0)) {
rainbowR += fact;
}
if ((rainbowR == 1) && (rainbowB > 0) && (rainbowG == 0)) {
rainbowB -= fact;
}
if (rainbowR > 1) {
rainbowR = 1;
} else if (rainbowR < 0) {
rainbowR = 0;
}
if (rainbowG > 1) {
rainbowG = 1;
} else if (rainbowG < 0) {
rainbowG = 0;
}
if (rainbowB > 1) {
rainbowB = 1;
} else if (rainbowB < 0) {
rainbowB = 0;
}
if (dir) {
++x;
} else {
--x;
}
if (dir && x > 200 - 10) {
dir = false;
} else if (!dir && x < 10) {
dir = true;
}
cairo_surface_t* bufferSurface = cairo_image_surface_create_for_data((uint8_t*) bufferInfo.buffer, CAIRO_FORMAT_ARGB32, bufferInfo.width,
bufferInfo.height, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, bufferInfo.width));
auto cr = cairo_create(bufferSurface);
cairo_save(cr);
cairo_set_source_rgba(cr, 0, 0, 0, 0);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_paint(cr);
cairo_restore(cr);
cairo_set_source_rgb(cr, rainbowR, rainbowG, rainbowB);
cairo_rectangle(cr, x, 0, 10, 100);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_fill(cr);
canvas->blit(g_rectangle(0, 0, bufferInfo.width, bufferInfo.height));
g_sleep(10);
}
uint8_t blocker = true;
g_atomic_block(&blocker);
}
@@ -83,7 +83,7 @@ int main() {
// wait for control requests
size_t buflen = sizeof(g_message_header) + sizeof(g_ps2_register_request);
uint8_t buf[buflen];
uint8_t* buf = new uint8_t[buflen];
g_tid tid = g_get_tid();
while (true) {
g_message_receive_status stat = g_receive_message(buf, buflen);
@@ -5,12 +5,12 @@
<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">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.Cygwin_PE" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.Cygwin_PE" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
@@ -76,13 +76,15 @@ class component_t: public bounds_event_component_t {
bool visible;
public:
g_ui_component_id id;
/**
* Creates the component; initially marks it as dirty
* and sets no parent
*/
component_t(bool transparentBackground = false) :
graphics(transparentBackground), visible(true), requirements(COMPONENT_REQUIREMENT_ALL), childRequirements(COMPONENT_REQUIREMENT_ALL), parent(0), layoutManager(
0), bounds_event_component_t(this) {
id(-1), graphics(transparentBackground), visible(true), requirements(COMPONENT_REQUIREMENT_ALL), childRequirements(COMPONENT_REQUIREMENT_ALL), parent(
0), layoutManager(0), bounds_event_component_t(this) {
}
/**
@@ -20,15 +20,18 @@
#include <components/cursor.hpp>
#include <events/event_processor.hpp>
#include <ghostuser/tasking/lock.hpp>
#include <input/input_receiver.hpp>
#include <interface/component_registry.hpp>
#include <ghostuser/tasking/lock.hpp>
#include <ghostuser/ui/interface_specification.hpp>
#include <windowserver.hpp>
#include <components/window.hpp>
#include <components/button.hpp>
#include <components/text/text_field.hpp>
#include <components/label.hpp>
#include <components/canvas.hpp>
#include <events/event.hpp>
#include <events/mouse_event.hpp>
@@ -83,7 +86,7 @@ void event_processor_t::process() {
buf_response.message = 0;
// process the actual action
process_command((g_ui_message_header*) G_MESSAGE_CONTENT(request_buffer), buf_response);
process_command(message->sender, (g_ui_message_header*) G_MESSAGE_CONTENT(request_buffer), buf_response);
// add generated response to queue
if (buf_response.message != 0) {
@@ -98,7 +101,7 @@ void event_processor_t::process() {
/**
*
*/
void event_processor_t::process_command(g_ui_message_header* request_header, command_message_response_t& response_out) {
void event_processor_t::process_command(g_tid sender_tid, g_ui_message_header* request_header, command_message_response_t& response_out) {
if (request_header->id == G_UI_PROTOCOL_CREATE_COMPONENT) {
component_t* component = 0;
@@ -112,16 +115,24 @@ void event_processor_t::process_command(g_ui_message_header* request_header, com
component = new window_t();
windowserver_t::instance()->screen->addChild(component);
break;
case G_UI_COMPONENT_TYPE_LABEL:
component = new label_t();
break;
case G_UI_COMPONENT_TYPE_BUTTON:
component = new button_t();
break;
case G_UI_COMPONENT_TYPE_TEXTFIELD:
component = new text_field_t();
break;
case G_UI_COMPONENT_TYPE_CANVAS: {
component = new canvas_t(sender_tid);
break;
}
default:
klog("don't know how to create a component of type %i", create_request->type);
break;
@@ -130,6 +141,7 @@ void event_processor_t::process_command(g_ui_message_header* request_header, com
// register the component
if (component != 0) {
component_id = component_registry_t::add(component);
// apply default properties
component->setBounds(g_rectangle(100, 100, 200, 80));
}
@@ -319,6 +331,39 @@ void event_processor_t::process_command(g_ui_message_header* request_header, com
response_out.message = response;
response_out.length = sizeof(g_ui_component_get_title_response);
} else if (request_header->id == G_UI_PROTOCOL_CANVAS_ACK_BUFFER_REQUEST) {
g_ui_component_canvas_ack_buffer_request* request = (g_ui_component_canvas_ack_buffer_request*) request_header;
component_t* component = component_registry_t::get(request->id);
canvas_t* canvas = (canvas_t*) component;
canvas->acknowledgeCurrentBuffer();
} else if (request_header->id == G_UI_PROTOCOL_CANVAS_BLIT) {
g_ui_component_canvas_ack_buffer_request* request = (g_ui_component_canvas_ack_buffer_request*) request_header;
component_t* component = component_registry_t::get(request->id);
canvas_t* canvas = (canvas_t*) component;
canvas->blit();
} else if (request_header->id == G_UI_PROTOCOL_REGISTER_DESKTOP_CANVAS) {
g_ui_register_desktop_canvas_request* request = (g_ui_register_desktop_canvas_request*) request_header;
component_t* component = component_registry_t::get(request->canvas_id);
// create response message
g_ui_register_desktop_canvas_response* response = new g_ui_register_desktop_canvas_response;
if (component == 0) {
response->status = G_UI_PROTOCOL_FAIL;
} else {
response->status = G_UI_PROTOCOL_SUCCESS;
canvas_t* canvas = (canvas_t*) component;
screen_t* screen = windowserver_t::instance()->screen;
screen->addChild(canvas);
canvas->setBounds(screen->getBounds());
}
response_out.message = response;
response_out.length = sizeof(g_ui_register_desktop_canvas_response);
}
}
@@ -46,7 +46,7 @@ class event_processor_t {
void bufferCommandMessage(void* commandMessage);
void process();
void process_command(g_ui_message_header* request_header, command_message_response_t& response_out);
void process_command(g_tid sender_tid, g_ui_message_header* request_header, command_message_response_t& response_out);
void translateKeyEvent(g_key_info& info);
void processMouseState();
@@ -30,6 +30,7 @@ static g_ui_component_id next_id = 1;
g_ui_component_id component_registry_t::add(component_t* component) {
g_ui_component_id id = next_id++;
components[id] = component;
component->id = id;
return id;
}
@@ -1,3 +1,4 @@
set timeout=0
set default=0
menuentry "Ghost" {
@@ -47,7 +47,7 @@ G_SYSCALL_HANDLER(alloc_mem) {
data->virtualResult = 0;
// Get the number of pages
uint32_t pages = PAGE_ALIGN_UP(data->size) / G_PAGE_SIZE;
uint32_t pages = G_PAGE_ALIGN_UP(data->size) / G_PAGE_SIZE;
if (pages > 0) {
// Allocate a virtual range, we are physical owner
uint8_t virtualRangeFlags = G_PROC_VIRTUAL_RANGE_FLAG_PHYSICAL_OWNER;
@@ -116,7 +116,7 @@ G_SYSCALL_HANDLER(share_mem) {
// Get the number of pages
uint32_t memory = (uint32_t) data->memory;
uint32_t pages = PAGE_ALIGN_UP(data->size) / G_PAGE_SIZE;
uint32_t pages = G_PAGE_ALIGN_UP(data->size) / G_PAGE_SIZE;
// Only allow sharing in user memory
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) {
if (virtualRangeBase != 0) {
g_page_directory executing_space = g_address_space::get_current_space();
g_physical_address pagesPhysical[pages];
// Map the pages to the other processes space
for (uint32_t i = 0; i < pages; i++) {
pagesPhysical[i] = g_address_space::virtual_to_physical(memory + i * G_PAGE_SIZE);
}
g_physical_address physical_addr = g_address_space::virtual_to_physical(memory + i * G_PAGE_SIZE);
g_address_space::switch_to_space(targetProcess->pageDirectory);
for (uint32_t i = 0; i < pages; i++) {
g_address_space::map(virtualRangeBase + i * G_PAGE_SIZE, pagesPhysical[i],
DEFAULT_USER_TABLE_FLAGS, DEFAULT_USER_PAGE_FLAGS);
g_address_space::switch_to_space(targetProcess->pageDirectory);
g_address_space::map(virtualRangeBase + i * G_PAGE_SIZE, physical_addr, DEFAULT_USER_TABLE_FLAGS, DEFAULT_USER_PAGE_FLAGS);
g_address_space::switch_to_space(executing_space);
}
g_address_space::switch_to_space(executing_space);
// Done
data->virtualAddress = (void*) virtualRangeBase;
@@ -185,7 +181,7 @@ G_SYSCALL_HANDLER(map_mmio) {
// Only kernel and drivers may do this
if (process->securityLevel <= G_SECURITY_LEVEL_DRIVER) {
uint32_t pages = PAGE_ALIGN_UP(data->size) / G_PAGE_SIZE;
uint32_t pages = G_PAGE_ALIGN_UP(data->size) / G_PAGE_SIZE;
// Allocate a virtual range (but not be physical owner)
g_virtual_address range = process->virtualRanges.allocate(pages,
@@ -267,7 +267,7 @@ G_SYSCALL_HANDLER(write_tls_master_for_process) {
g_process* target_process = target_thread->process;
// Get a virtual address range for the TLS master copy
uint32_t required_pages = PAGE_ALIGN_UP(data->copysize) / G_PAGE_SIZE;
uint32_t required_pages = G_PAGE_ALIGN_UP(data->copysize) / G_PAGE_SIZE;
g_virtual_address tls_master_virt = target_process->virtualRanges.allocate(required_pages, G_PROC_VIRTUAL_RANGE_FLAG_PHYSICAL_OWNER);
// Temporarily copy master contents to kernel heap because we switch directories
Oops, something went wrong.

0 comments on commit 9433e8d

Please sign in to comment.