Usermode/AxWin4 - Screen dimensions acquisition, speedup, window render
[tpg/acess2.git] / Usermode / Applications / axwin4_src / Server / compositor.cpp
1 /*
2  * Acess2 GUI v4
3  * - By John Hodge (thePowersGang)
4  *
5  * compositor.cpp
6  * - Window compositor
7  */
8 #include <video.hpp>
9 #include <CCompositor.hpp>
10 #include <cassert>
11
12 namespace AxWin {
13
14 CCompositor::CCompositor(CVideo& video):
15         m_video(video)
16 {
17         // 
18 }
19
20 CWindow* CCompositor::CreateWindow(CClient& client, const ::std::string& name)
21 {
22         return new CWindow(*this, client, name);
23 }
24
25 void CCompositor::ShowWindow(CWindow* window)
26 {
27         DamageArea(window->m_surface.m_rect);
28         // TODO: Append to separate sub-lists (or to separate lists all together)
29         //   if flags AXWIN4_WNDFLAG_KEEPBELOW or AXWIN4_WNDFLAG_KEEPABOVE are set
30         m_windows.push_back(window);
31 }
32 void CCompositor::HideWindow(CWindow* window)
33 {
34         DamageArea(window->m_surface.m_rect);
35         m_windows.remove(window);
36 }
37
38 bool CCompositor::GetScreenDims(unsigned int ScreenID, unsigned int* W, unsigned int* H)
39 {
40         assert(W && H);
41         if( ScreenID != 0 )
42         {
43                 *W = 0;
44                 *H = 0;
45                 return false;
46         }
47         else
48         {
49                 m_video.GetDims(*W, *H);
50                 return true;
51         }
52 }
53
54 void CCompositor::Redraw()
55 {
56         // Redraw the screen and clear damage rects
57         if( m_damageRects.empty() ) {
58                 _SysDebug("- No damaged regions");
59                 return ;
60         }
61         
62         // Build up foreground grid (Rects and windows)
63         // - This should already be built (mutated on window move/resize/reorder)
64         
65         // For all windows, check for intersection with damage rects
66         for( auto rect : m_damageRects )
67         {
68                 // window list should be sorted by draw order (lowest first)
69                 for( auto window : m_windows )
70                 {
71                         if( window->m_is_shown && rect.HasIntersection( window->m_surface.m_rect ) )
72                         {
73                                 // TODO: just reblit
74                                 CRect   rel_rect = window->m_surface.m_rect.RelativeIntersection(rect);
75                                 //_SysDebug("Reblit (%i,%i) %ix%i", rel_rect.m_x, rel_rect.m_y, rel_rect.m_w, rel_rect.m_h);
76                                 BlitFromSurface( window->m_surface, rel_rect );
77                                 //window->Repaint( rel_rect );
78                         }
79                 }
80                 
81                 // TODO: Blit from windows to a local surface, then blit from there to screen here
82         }
83
84         m_damageRects.clear();
85         m_video.Flush();
86 }
87
88 void CCompositor::DamageArea(const CRect& area)
89 {
90         m_damageRects.push_back( area );
91         // 1. Locate intersection with any existing damaged areas
92         // 2. Append after removing intersections
93 }
94
95 void CCompositor::BlitFromSurface(const CSurface& dest, const CRect& src_rect)
96 {
97         for( unsigned int i = 0; i < src_rect.m_h; i ++ )
98         {
99                 m_video.BlitLine(
100                         dest.GetScanline(src_rect.m_y, src_rect.m_y),
101                         dest.m_rect.m_y + src_rect.m_y + i,
102                         dest.m_rect.m_x + src_rect.m_x,
103                         src_rect.m_w
104                         );
105         }
106 }
107
108 void CCompositor::MouseMove(unsigned int Cursor, unsigned int X, unsigned int Y, int dX, int dY)
109 {
110         _SysDebug("MouseButton(%i, %i,%i, %+i,%+i)", Cursor, X, Y, dX, dY);
111         m_video.SetCursorPos(X+dX, Y+dY);
112         // TODO: Pass event on to window
113 }
114
115 void CCompositor::MouseButton(unsigned int Cursor, unsigned int X, unsigned int Y, eMouseButton Button, bool Press)
116 {
117         _SysDebug("MouseButton(%i, %i,%i, %i=%i)", Cursor, X, Y, Button, Press);
118         // TODO: Pass event on to window
119 }
120
121 void CCompositor::KeyState(unsigned int KeyboardID, uint32_t KeySym, bool Press, uint32_t Codepoint)
122 {
123         _SysDebug("KeyState(%i, 0x%x, %b, 0x%x)", KeyboardID, KeySym, Press, Codepoint);
124 }
125
126 }       // namespace AxWin
127

UCC git Repository :: git.ucc.asn.au