summaryrefslogtreecommitdiff
path: root/video
diff options
context:
space:
mode:
Diffstat (limited to 'video')
-rw-r--r--video/compositor.c445
-rw-r--r--video/compositor.h76
2 files changed, 285 insertions, 236 deletions
diff --git a/video/compositor.c b/video/compositor.c
index 2b67385..e7fd15f 100644
--- a/video/compositor.c
+++ b/video/compositor.c
@@ -1,4 +1,6 @@
+// TODO OPTIMIZE //
#include "compositor.h"
+#include "scheduler.h"
#include "syscalls.h"
#include "kernel.h"
#include "kmalloc.h"
@@ -13,17 +15,24 @@
#include "lib/string/string.h"
#define MAX_WINDOWS 50
+#define MAX_PID 200
#define MAX_ICONS 50
+void load_bmp(uint8_t *dst,char *filename);
+
+static uint8_t backbuffer[VESA_MAX_WIDTH*VESA_MAX_HEIGHT*4];
+static uint8_t wallpaper [VESA_MAX_WIDTH*VESA_MAX_HEIGHT*4];
+static uint8_t icon_data [VESA_MAX_WIDTH*VESA_MAX_HEIGHT*4];
+
ringbuffer bg_invl;
// TODO: int16 int32 mixed nonsense !
struct window
{
uint32_t pid;
- ringbuffer *invl;
struct pdirectory *vmem; // retreive from task manager?
+ uint8_t *fb;
int16_t posx;
int16_t posy;
@@ -35,6 +44,7 @@ struct window
bool draw_border;
bool draw_meat;
+ bool on_close;
bool borderless; // never show borders
bool fixed; // can not be moved
@@ -55,12 +65,9 @@ struct icon
};
struct window windows[MAX_WINDOWS];
+struct window *pid_to_win[MAX_PID];
struct icon icons[MAX_ICONS];
-static uint8_t backbuffer [VESA_MAX_WIDTH*VESA_MAX_HEIGHT*4];
-static uint8_t bgimage [VESA_MAX_WIDTH*VESA_MAX_HEIGHT*4];
-static uint8_t icon_data [1920*1080*4];
-
static uint16_t next_window=0;
static uint16_t next_x=50;
static uint16_t next_y=50;
@@ -92,6 +99,12 @@ static int mouse_icon_lx=0;
static int mouse_icon_ly=0;
static int mouse_icon_active_lx=0;
static int mouse_icon_active_ly=25;
+static int X_icon_width=25;
+static int X_icon_height=25;
+static int X_icon_lx=0;
+static int X_icon_ly=50;
+static int X_icon_active_lx=0;
+static int X_icon_active_ly=75;
// costly but beautiful
static bool option_blending=false; // so better disable ! :P// also not allowed to read from vmem! :(
@@ -103,23 +116,25 @@ static bool skip_render;
static bool skip_render2;
/** print single pixel to dst without bound checking */
-static void put_pixel(uint8_t *dst, int x,int y, uint32_t color)
+static void put_pixel(uint8_t *dst, int x,int y, uint32_t color,uint16_t pitch,uint8_t depth,bool alpha)
{
- uint8_t *p=dst+y*vesa_pitch+x*vesa_depth;
- *p++=color; // waste for 24bit...
- *p++=color>>8; // waste for 24bit...
- *p=color>>16; // waste for 24bit...
+ uint8_t *p=dst+y*pitch+x*depth;
+ *p++=color;
+ *p++=color>>8;
+ *p++=color>>16;
+ if(alpha)*p=color>>24;
}
/** retrieves single pixel from src without bound checking */
-static uint32_t get_pixel(uint8_t *src, int x,int y)
+static uint32_t get_pixel(uint8_t *src, int x,int y,uint16_t pitch,uint8_t depth,bool alpha)
{
uint32_t col=0;
- uint8_t *p=src+y*vesa_pitch+x*vesa_depth;
- col=(*p++); // waste for 24bit...
- col+=(*p++)<<8; // waste for 24bit...
- col+=(*p)<<16; // waste for 24bit...
+ uint8_t *p=src+y*pitch+x*depth;
+ col=(*p++);
+ col+=(*p++)<<8;
+ col+=(*p++)<<16;
+ if(alpha)col+=(*p)<<24;
return col;
}
@@ -129,13 +144,10 @@ static uint32_t get_pixel(uint8_t *src, int x,int y)
encoded alpha in the highest octet. 1-opaque 0-transparent
no premultiplied alpha. TODO: change maybe for speedup!?
**/
-static void put_pixel_alpha(uint8_t *dst, int x,int y, uint32_t color)
+static void put_pixel_alpha(uint8_t *dst, int x,int y, uint32_t color,uint16_t pitch, uint8_t depth,bool alpha)
{
- // TODO: do not use hardcoded alpha!
-
- uint32_t col=get_pixel(dst,x,y);
+ uint32_t col=get_pixel(dst,x,y,vesa_pitch,vesa_depth,false);
- // TODO: optimize!!
uint8_t dst_b=col&0xff;
uint8_t dst_g=(col&0xff00)>>8;
uint8_t dst_r=(col&0xff0000)>>16;
@@ -149,11 +161,12 @@ static void put_pixel_alpha(uint8_t *dst, int x,int y, uint32_t color)
uint8_t out_g=((src_g*(src_a))>>8)+(((0xff-src_a)*dst_g)>>8);
uint8_t out_b=((src_b*(src_a))>>8)+(((0xff-src_a)*dst_b)>>8);
- put_pixel(dst, x,y,(out_r<<16)+(out_g<<8)+out_b);
+ put_pixel(dst, x,y,(out_r<<16)+(out_g<<8)+out_b,vesa_pitch,vesa_depth,false);
}
-static void cpy_rect(uint8_t *src, uint16_t src_x, uint16_t src_y,
- uint8_t *dst, uint16_t dst_x, uint16_t dst_y,
+// TODO fuck transparancey key. we have alfa now
+static void cpy_rect(uint8_t *src, uint16_t src_pitch, uint16_t src_x, uint16_t src_y,
+ uint8_t *dst, uint16_t dst_pitch, uint16_t dst_x, uint16_t dst_y,
uint16_t width, uint16_t height,
bool bnd_chk, uint8_t mult, uint8_t div,
bool transp,
@@ -163,16 +176,13 @@ static void cpy_rect(uint8_t *src, uint16_t src_x, uint16_t src_y,
for(int x=0;x<width;x++)
for(int y=0;y<height;y++)
{
- uint32_t val=get_pixel(src,src_x+x,src_y+y);
- if(transp&&transp_key==val)continue;
- // TODO: quick workaround for arrow black
- if(alpha)
- put_pixel_alpha(dst,dst_x+x,dst_y+y,val);
- else put_pixel(dst,dst_x+x,dst_y+y,val);
-
+ uint32_t val=get_pixel(src,src_x+x,src_y+y,src_pitch,4,true);//32bit and fuck alfa
+ if(alpha) put_pixel_alpha(dst,dst_x+x,dst_y+y,val,dst_pitch,vesa_depth,false);
+ else put_pixel(dst,dst_x+x,dst_y+y,val,dst_pitch,vesa_depth,false);
}
}
+/*
static void add_icon(char *cmd)
{
strcpy(icons[next_icon].command,cmd);
@@ -189,7 +199,6 @@ static void add_icon(char *cmd)
next_icon++;
}
-
static void put_icon(uint8_t *dst, struct icon *ico)
{
if(ico->active)
@@ -213,6 +222,7 @@ cpy_rect(icon_data,ico->iconx,ico->icony, // from
,true
);
}
+*/
static void put_win(uint8_t *dst, struct window *win)
{
@@ -223,63 +233,91 @@ static void put_win(uint8_t *dst, struct window *win)
mydir=x86_get_page_directory();
x86_set_page_directory(win->vmem);
- uint32_t *user_vmem=VMEM_USER_FRAMEBUFFER;
- // iterate over invalidated rects
- while(ringbuffer_has(win->invl))
- {
- int ry=ringbuffer_get(win->invl)+256*ringbuffer_get(win->invl);
- int rx=ringbuffer_get(win->invl)+256*ringbuffer_get(win->invl);
- int rh=ringbuffer_get(win->invl)+256*ringbuffer_get(win->invl);
- int rw=ringbuffer_get(win->invl)+256*ringbuffer_get(win->invl);
- if(!win->draw_meat)continue;
-
- uint32_t userx=rx;
- uint32_t usery=ry;
-
- // iterate over rect area
- for(uint16_t x=win->posx+rx;x<win->posx+rx+rw;x++)
- {
- usery=ry;
- for(uint16_t y=win->posy+ry;y<win->posy+ry+rh;y++)
- {
- // blending non-active windows (TODO: costly?)
- if(!win->active && option_blending)
- {
- /*
- uint8_t dst_b=backbuffer[y*vesa_width+x]&0xff;
- uint8_t dst_g=(backbuffer[y*vesa_width+x]&0xff00)>>8;
- uint8_t dst_r=(backbuffer[y*vesa_width+x]&0xff0000)>>16;
-
- uint16_t a;
-
- uint32_t col=0xff0000;
- col=user_vmem[userx+usery*640];
- uint8_t src_b=col&0xff;
- uint8_t src_g=(col&0xff00)>>8;
- uint8_t src_r=(col&0xff0000)>>16;
- a=0x44;
-
-
- uint8_t out_r=((src_r*(0xff-a))>>8)+((a*dst_r)>>8);
- uint8_t out_g=((src_g*(0xff-a))>>8)+((a*dst_g)>>8);
- uint8_t out_b=((src_b*(0xff-a))>>8)+((a*dst_b)>>8);
+cpy_rect(win->fb,win->width*4,0,0, // from
+ dst,vesa_pitch,win->posx,win->posy, // to
+ win->width,win->height, // icon dimensions
+ false,
+ 0, 0, // scaling not implemented yet anyway, not sure how to use them :P
+ true, // transparency color key
+ 0xff00ff // color key of transp
+ ,true
+ );
- backbuffer[y*vesa_width+x]=(out_r<<16)+(out_g<<8)+out_b;
- */
+int iconx=X_icon_lx;
+int icony=X_icon_ly;
+if(win->on_close)
+{
+ iconx=X_icon_active_lx;
+ icony=X_icon_active_ly;
+}
- put_pixel_alpha(dst,x,y,(user_vmem[userx+usery*640]));
- }
- else
- {
- put_pixel(dst,x,y,(user_vmem[userx+usery*640]));
- }
+cpy_rect(icon_data,vesa_pitch,iconx,icony, // from
+ dst, vesa_pitch,win->posx+win->width-X_icon_width,win->posy, // to
+ X_icon_width,X_icon_height, // icon dimensions
+ false,
+ 0, 0, // scaling not implemented yet anyway, not sure how to use them :P
+ true, // transparency color key
+ 0xff00ff // color key of transp
+ ,true
+ );
- usery++;
- }
- userx++;
- }
- }
+ // iterate over invalidated rects
+
+//// while(ringbuffer_has(win->invl))
+//// {
+//// int ry=ringbuffer_get(win->invl)+256*ringbuffer_get(win->invl);
+//// int rx=ringbuffer_get(win->invl)+256*ringbuffer_get(win->invl);
+//// int rh=ringbuffer_get(win->invl)+256*ringbuffer_get(win->invl);
+//// int rw=ringbuffer_get(win->invl)+256*ringbuffer_get(win->invl);
+//// if(!win->draw_meat)continue;
+////
+//// uint32_t userx=rx;
+//// uint32_t usery=ry;
+////
+//// // iterate over rect area
+//// for(uint16_t x=win->posx+rx;x<win->posx+rx+rw;x++)
+//// {
+//// usery=ry;
+//// for(uint16_t y=win->posy+ry;y<win->posy+ry+rh;y++)
+//// {
+//// // blending non-active windows (TODO: costly?)
+//// if(!win->active && option_blending)
+//// {
+//// /*
+//// uint8_t dst_b=backbuffer[y*vesa_width+x]&0xff;
+//// uint8_t dst_g=(backbuffer[y*vesa_width+x]&0xff00)>>8;
+//// uint8_t dst_r=(backbuffer[y*vesa_width+x]&0xff0000)>>16;
+////
+//// uint16_t a;
+////
+//// uint32_t col=0xff0000;
+//// col=user_vmem[userx+usery*640];
+//// uint8_t src_b=col&0xff;
+//// uint8_t src_g=(col&0xff00)>>8;
+//// uint8_t src_r=(col&0xff0000)>>16;
+//// a=0x44;
+////
+////
+//// uint8_t out_r=((src_r*(0xff-a))>>8)+((a*dst_r)>>8);
+//// uint8_t out_g=((src_g*(0xff-a))>>8)+((a*dst_g)>>8);
+//// uint8_t out_b=((src_b*(0xff-a))>>8)+((a*dst_b)>>8);
+////
+//// backbuffer[y*vesa_width+x]=(out_r<<16)+(out_g<<8)+out_b;
+//// */
+////
+//// put_pixel_alpha(dst,x,y,(user_vmem[userx+usery*640]));
+//// }
+//// else
+//// {
+//// put_pixel(dst,x,y,(user_vmem[userx+usery*640]));
+//// }
+////
+//// usery++;
+//// }
+//// userx++;
+//// }
+//// }
//if(win->vmem)
//{
x86_set_page_directory(mydir);
@@ -287,19 +325,20 @@ static void put_win(uint8_t *dst, struct window *win)
//}
//draw boundaries
-
if(option_win_borders&&win->draw_border)
{
- win->draw_border=false;
+ uint32_t border_col=0x002b36;
+ if(win->active)border_col=0xfdfd6e3;
+//TODO win->draw_border=false;
for(uint16_t x=win->posx;x<win->posx+win->width;x++)
{
- put_pixel(dst,x,win->posy,0xffffff); //TOP
- put_pixel(dst,x,win->posy+win->height-1,0xffffff); //BOTTOM
+ put_pixel(dst,x,win->posy,border_col,vesa_pitch,vesa_depth,false); //TOP
+ put_pixel(dst,x,win->posy+win->height-1,border_col,vesa_pitch,vesa_depth,false); //BOTTOM
}
for(uint16_t y=win->posy;y<win->posy+win->height;y++)
{
- put_pixel(dst,win->posx,y,0xffffff); //LEFT
- put_pixel(dst,win->posx+win->width-1,y,0xffffff); //RIGHT
+ put_pixel(dst,win->posx,y,border_col,vesa_pitch,vesa_depth,false); //LEFT
+ put_pixel(dst,win->posx+win->width-1,y,border_col,vesa_pitch,vesa_depth,false); //RIGHT
}
}
@@ -307,16 +346,10 @@ static void put_win(uint8_t *dst, struct window *win)
}
static void put_bg(uint8_t *dst)
{
- while(ringbuffer_has(&bg_invl))
- {
- int ry=ringbuffer_get(&bg_invl)+256*ringbuffer_get(&bg_invl);
- int rx=ringbuffer_get(&bg_invl)+256*ringbuffer_get(&bg_invl);
- int rh=ringbuffer_get(&bg_invl)+256*ringbuffer_get(&bg_invl);
- int rw=ringbuffer_get(&bg_invl)+256*ringbuffer_get(&bg_invl);
-cpy_rect(bgimage,rx,ry, // from
- dst,rx,ry, // to
- rw,rh, // icon dimensions
+ cpy_rect(wallpaper,vesa_pitch,0,0 , // from
+ dst,vesa_pitch,0,0, // to
+ vesa_width,vesa_height, // icon dimensions
false,
0, 0, // scaling not implemented yet anyway, not sure how to use them :P
false, // transparency color key
@@ -324,9 +357,8 @@ cpy_rect(bgimage,rx,ry, // from
,false
);
- }
}
-static void put_mouse(uint8_t *dst,bool before)
+static void put_mouse(uint8_t *dst)
{
static int last_put_mouse_x=0;
@@ -341,31 +373,17 @@ if(mouse_k&1)
icony=mouse_icon_active_ly;
}
-if(before)
-{
-cpy_rect(bgimage,last_put_mouse_x,last_put_mouse_y, // from
- dst, last_put_mouse_x,last_put_mouse_y, // to
- mouse_icon_width,mouse_icon_height, // icon dimensions
- false,
- 0, 0, // scaling not implemented yet anyway, not sure how to use them :P
- false, // transparency color key
- 0xffffff // color key of transp
- ,false
- );
-return;
-}
-
last_put_mouse_x=mouse_x;
last_put_mouse_y=mouse_y;
-cpy_rect(icon_data,iconx,icony, // from
- dst, mouse_x,mouse_y, // to
+cpy_rect(icon_data,vesa_pitch,iconx,icony, // from
+ dst, vesa_pitch,mouse_x,mouse_y, // to
mouse_icon_width,mouse_icon_height, // icon dimensions
false,
0, 0, // scaling not implemented yet anyway, not sure how to use them :P
true, // transparency color key
0xff00ff // color key of transp
- ,false
+ ,true
);
}
@@ -386,35 +404,9 @@ void compositor_del_window(uint32_t addr)
}
}
-void compositor_add_window(uint32_t addr,uint32_t pid,ringbuffer *r)
-{
- klog("window added");
- if (next_window>=MAX_WINDOWS)kpanic("max number of windows reached. increase MAX_WINDOWS");
-
- windows[next_window]=windows[0];
-
- windows[0].posx=next_x;
- windows[0].posy=next_y;
-
- next_x+=100;
- next_y+=100;
-
- windows[0].width=640;
- windows[0].height=400;
-
- windows[0].active=0;
- windows[0].vmem=addr;
- windows[0].pid=pid;
- windows[0].invl=r;
- windows[0].draw_border=true;
- windows[0].draw_meat=true;
-
- next_window++;
- compositor_mouse_handle(0,0,0);
-}
// TODO : TEXTMODE FALLBACK!
-void compositor_init(uint16_t width, uint16_t height, uint16_t depth, uint16_t pitch)
+void compositor_init(uint16_t width, uint16_t height,uint16_t depth, uint16_t pitch, uint8_t *fb)
{
bg_invl=ringbuffer_init(3);
@@ -431,13 +423,17 @@ void compositor_init(uint16_t width, uint16_t height, uint16_t depth, uint16_t p
klog("expected pitch = %d , actual pitch = %d",expected_pitch,pitch);
if(expected_pitch!=pitch)kpanic("sorry we need to fix this. padding not supported now");
+ /*
add_icon("vim");
add_icon("vim");
add_icon("vim");
add_icon("vim");
add_icon("vim");
add_icon("vim");
+ */
+ load_bmp(wallpaper,"/home/miguel/wallpaper.bmp");
+ load_bmp(icon_data,"/home/miguel/ico.bmp");
compositor_mouse_handle(200,200,0);
}
@@ -445,19 +441,14 @@ void compositor_wake()
{
skip_render=false;
}
-void compositor_wake2()
-{
- skip_render2=false;
-}
-void compositor_swap_buffers()
+void compositor_paint()
{
- //if(skip_render||skip_render2)return;
- if(skip_render2)return; // force rate
+ if(skip_render)return; // forced max rate
skip_render=true;
- skip_render2=true;
+ //FPS: TODO write to bar!
static frames=0;
static uint64_t last=0;
if(!last)last=timer_get_ms();
@@ -466,33 +457,20 @@ void compositor_swap_buffers()
if(now-last>3000)
{
klog("fps: %d",frames*1000/(now-last));
-
last=now;
frames=0;
}
- static bool first=true;
- if(first)memcpy(VMEM_FRAMEBUFFER,bgimage,vesa_pitch*vesa_height);// TODO optimize? rects only too??
- first=false;
-
- put_bg(VMEM_FRAMEBUFFER);
-
- put_mouse(VMEM_FRAMEBUFFER,true);
+ // // //
+ put_bg(backbuffer);
for(int i=next_window-1;i>=0;i--)
{
- put_win(VMEM_FRAMEBUFFER,&windows[i]);
- }
-
- for(int i=next_icon-1;i>=0;i--)
- {
- // put_icon(backbuffer,&icons[i]);
+ put_win(backbuffer,&windows[i]);
}
+ put_mouse(backbuffer);
- put_mouse(VMEM_FRAMEBUFFER,false);
-
- // TODO optimize? rects only too?
-// memcpy(VMEM_FRAMEBUFFER,backbuffer,vesa_pitch*vesa_height);
+ memcpy(VMEM_FRAMEBUFFER,backbuffer,vesa_pitch*vesa_height);
}
void compositor_kb_handle(char c)
@@ -543,6 +521,7 @@ void compositor_mouse_handle(int16_t diff_x,int16_t diff_y, uint8_t key)
for(int i=0;i<next_icon;i++)
{
+
struct icon *w=&icons[i];
if(active==-1&&mouse_x>w->posx&&mouse_x<w->posx+w->width&&mouse_y>w->posy&&mouse_y<w->posy+w->height)
{
@@ -574,6 +553,7 @@ void compositor_mouse_handle(int16_t diff_x,int16_t diff_y, uint8_t key)
for(int i=0;i<next_window;i++)
{
struct window *w=&windows[i];
+ w->on_close=false;
if(active==-1&&mouse_x>w->posx&&mouse_x<w->posx+w->width&&mouse_y>w->posy&&mouse_y<w->posy+w->height)
{
if(key&1)
@@ -618,15 +598,15 @@ void compositor_mouse_handle(int16_t diff_x,int16_t diff_y, uint8_t key)
uint32_t xy=(0<<16)|(0);
uint32_t wh=(640<<16)|(400);
- ringbuffer_put(w->invl,xy&0x000000ff);
- ringbuffer_put(w->invl,(xy&0x0000ff00)>>8);
- ringbuffer_put(w->invl,(xy&0x00ff0000)>>16);
- ringbuffer_put(w->invl,(xy&0xff000000)>>24);
-
- ringbuffer_put(w->invl,wh&0x000000ff);
- ringbuffer_put(w->invl,(wh&0x0000ff00)>>8);
- ringbuffer_put(w->invl,(wh&0x00ff0000)>>16);
- ringbuffer_put(w->invl,(wh&0xff000000)>>24);
+/// ringbuffer_put(w->invl,xy&0x000000ff);
+/// ringbuffer_put(w->invl,(xy&0x0000ff00)>>8);
+/// ringbuffer_put(w->invl,(xy&0x00ff0000)>>16);
+/// ringbuffer_put(w->invl,(xy&0xff000000)>>24);
+///
+/// ringbuffer_put(w->invl,wh&0x000000ff);
+/// ringbuffer_put(w->invl,(wh&0x0000ff00)>>8);
+/// ringbuffer_put(w->invl,(wh&0x00ff0000)>>16);
+/// ringbuffer_put(w->invl,(wh&0xff000000)>>24);
}
}
@@ -634,6 +614,7 @@ void compositor_mouse_handle(int16_t diff_x,int16_t diff_y, uint8_t key)
w->active=true;
active_win=true;
active=i;
+ if(mouse_x>w->posx+w->width-X_icon_width&&mouse_y<w->posy+X_icon_height)w->on_close=true;
}
else
{
@@ -647,8 +628,12 @@ void compositor_mouse_handle(int16_t diff_x,int16_t diff_y, uint8_t key)
{
struct window temp;
temp=windows[active];
+
windows[active]=windows[0];
+ pid_to_win[windows[0].pid]=&windows[active];
+
windows[0]=temp;
+ pid_to_win[windows[0].pid]=&windows[0];
}
lastkey=key;
@@ -658,7 +643,6 @@ void compositor_mouse_handle(int16_t diff_x,int16_t diff_y, uint8_t key)
/** THIS CAN LOAD WINDOWS ARGB BITMAPS WITH BITMAPINFOHEADER */
void load_bmp(uint8_t *dst,char *filename)
{
-
klog("loading bitmap %s",filename);
fd dat=mount_file_open(filename);
char B=fd_read(&dat); // 0x0
@@ -676,7 +660,7 @@ void load_bmp(uint8_t *dst,char *filename)
fd_read(&dat);
uint32_t off=(fd_read(&dat))+(fd_read(&dat)<<8)+(fd_read(&dat)<<16)+(fd_read(&dat)<<24); //0x0a
- //klog("offset = 0x%08X",off);
+ klog("offset = 0x%08X",off);
// skip next 4 bytes
fd_read(&dat);
@@ -688,72 +672,77 @@ void load_bmp(uint8_t *dst,char *filename)
uint32_t h=(fd_read(&dat))+(fd_read(&dat)<<8)+(fd_read(&dat)<<16)+(fd_read(&dat)<<24); //0x16
klog("width=%d,height=%d",w,h);
- for(int i=0;i<off-0xa;i++)fd_read(&dat); // skip to data
+ for(int i=0;i<off-0x1a;i++)fd_read(&dat); // skip to data
// read the image from left to right line by line
for(int y=0;y<h;y++)
for(int x=0;x<w;x++)
{
{
- uint32_t val=(fd_read(&dat)<<24)+(fd_read(&dat)<<16)+(fd_read(&dat)<<8)+(fd_read(&dat));
+ uint32_t val=(fd_read(&dat)<<24)+(fd_read(&dat))+(fd_read(&dat)<<8)+(fd_read(&dat)<<16);
+// klog("0x%08x",val);
if(x>=vesa_width)continue;
- if(y>=vesa_height)continue;
- put_pixel_alpha(dst,x,y,val);
+ if(h-y-1>=vesa_height)continue;
+ put_pixel(dst,x,h-y-1,val,vesa_pitch,4,true);
}
}
}
-// load background image or generate one if (param == 0)
-void compositor_set_background(char *ppm_raw_filename)
+
+void compositor_invalidate(uint32_t pid,uint16_t x, uint16_t y, uint16_t w, uint16_t h,uint32_t *fb)
{
- // TODO: think about funny things to do with timer and update
- // some generated / or modified bg regularly //
- // uint64_t t=timer_get_ms()/333; //
- klog("loading theme...");
- fd bg=mount_file_open(ppm_raw_filename);
+ if(fb!=0)pid_to_win[pid]->fb=fb;
+// klog("pid %d invalidating %dx%d rect at %d %d with fb addr 0x%08x",pid,w,h,x,y,fb);
+}
- uint32_t i=0;
+int compositor_create_window(uint32_t pid,uint16_t x, uint16_t y,uint16_t w,uint16_t h,uint16_t flags)
+{
+ klog("pid %d creating %dx%d win at %d %d with flags 0x%02x",pid,w,h,x,y,flags);
+ if (next_window>=MAX_WINDOWS)kpanic("max number of windows reached. increase MAX_WINDOWS");
- // read the image from left to right line by line
- for(int y=0;y<1080;y++)
- for(int x=0;x<1920;x++)
+ windows[next_window]=windows[0];
+ pid_to_win[windows[0].pid]=&windows[next_window];
+
+ // auto position
+ if(x==0xffff)
{
- {
- uint32_t val=(fd_read(&bg)<<16)+(fd_read(&bg)<<8)+fd_read(&bg);
- if(x>=vesa_width)continue;
- if(y>=vesa_height)continue;
- put_pixel(icon_data,x,y,val);
- put_pixel(bgimage,x,y,val);
- i++;
- }
+ next_x+=100;
+ next_y+=100;
+ windows[0].posx=next_x;
+ windows[0].posy=next_y;
+ }
+ else
+ {
+ windows[0].posx=x;
+ windows[0].posy=y;
}
- klog("finished");
+ windows[0].width=w;
+ windows[0].height=h;
- // generating simple background...
- int center_x=vesa_width/2;
- int center_y=vesa_height/2;
- int max_dist = center_x*center_x+center_y*center_y;
+ windows[0].active=0;
- for(int x=0;x<vesa_width;x++)
- {
- for(int y=0;y<vesa_height;y++)
- {
- uint32_t val;
- if(y%2)
- {
- int diffx=center_x-x;
- int diffy=center_y-y;
- int dist=diffx*diffx+diffy*diffy;
- val = 0xaa*dist/max_dist;
- }
- else val=0x0;
- //val=0x002b36;
+ windows[0].fb=0;
+ windows[0].vmem=scheduler_get_vmem(pid);
+ windows[0].pid=pid;
-// put_pixel(bgimage,x,y,val);
- }
- }
+ windows[0].draw_border=true;
+ windows[0].draw_meat=true;
+
+ windows[0].on_close=false;
+ windows[0].borderless=flags&1;
+ windows[0].fixed=flags&2;
- load_bmp(bgimage,"/home/miguel/skin.bmp");
+ pid_to_win[windows[0].pid]=&windows[0];
+
+ next_window++;
+ compositor_mouse_handle(0,0,0);
+
+ return 0;// ok
+}
+
+void compositor_destroy_window(uint32_t pid)
+{
+ klog("destroying win for pid %d",pid);
}
diff --git a/video/compositor.h b/video/compositor.h
index e3204a6..334dfa3 100644
--- a/video/compositor.h
+++ b/video/compositor.h
@@ -1,21 +1,81 @@
#include <stdint.h>
-#include "ringbuffer.h"
/**
* @file
*
- * Super Light composting window manager for Fool 0S.
+ * Super Light compositing window manager for Fool 0S.
* Can be run directly on a 32bit or 24bit Framebuffer.
*
+ * pid needed to get vmem directory of process for some calls.
+ * only pne window per pid allowed by now.
*
+ * Internals:
+ *
+ * framebuffer
+ * backbuffer - same format as framebuffer.
+ *
+ * icons and user-land buffers use ARGB.
+ * bitmaps loaded use ARGB.
+ *
+ * TODO: /dev/mouse
+ *
+ * Threads
+ * -------
+ * In general it should be accessed only by one gui thread anyway.
+ */
+
+/**
+ * Initialization of our window manager
+ * some obvious params and the address of the framebuffer.
+ */
+void compositor_init(uint16_t width, uint16_t height,uint16_t bpp, uint16_t pitch, uint8_t *fb);
+
+/**
+ * THE HEAVY WORK
+ *
+ * You can call this any time you want.
+ * It will have no effect unless there
+ * was a call to compositor_wake() before.
*/
+void compositor_paint();
+/**
+ * Call this at e.g. at 60HZ. To force a max refresh rate for
+ * compositor_paint(). Additonal calls to compositor_paint() will
+ * be jus skipped.
+ *
+ * This function just sets one variable so it can be caled
+ * from a interrupt handler (e.g. APIC Timer)
+ */
void compositor_wake();
-void compositor_wake2();
-void compositor_init(uint16_t width, uint16_t height,uint16_t bpp, uint16_t pitch);
-void compositor_set_background(char *ppm_raw_filename);
-void compositor_swap_buffers();
+
+/**
+ * Invalidates an area of the screen. so it will be repainted on the
+ * upcoming frame. can set the address of the user framebuffer
+ * (if changed since last call).
+ */
+void compositor_invalidate(uint32_t pid,uint16_t x, uint16_t y, uint16_t w, uint16_t h,uint32_t *fb);
+
+/**
+ * Window Create
+ *
+ * flag 1 - no decoration
+ * flag 2 - fixed (can not be moved and always in foreground)
+ */
+int compositor_create_window(uint32_t pid,uint16_t x, uint16_t y,uint16_t w,uint16_t h,uint16_t flags);
+
+/**
+ * Window Destroy
+ */
+void compositor_destroy_window(uint32_t pid);
+
+/**
+ * user input mouse
+ */
void compositor_mouse_handle(int16_t x,int16_t y, uint8_t key);
+
+/**
+ * user input keyboard
+ */
void compositor_kb_handle(char c);
-void compositor_add_window(uint32_t addr,uint32_t pid,ringbuffer *);
-void compositor_del_window(uint32_t addr);
+