Usermode/AxWin4 - Rendering random data successfully now
[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 bool CCompositor::GetScreenDims(unsigned int ScreenID, unsigned int* W, unsigned int* H)
26 {
27         assert(W && H);
28         if( ScreenID != 0 )
29         {
30                 *W = 0;
31                 *H = 0;
32                 return false;
33         }
34         else
35         {
36                 m_video.GetDims(*W, *H);
37                 return true;
38         }
39 }
40
41 void CCompositor::Redraw()
42 {
43         _SysDebug("CCompositor::Redraw");
44         // Redraw the screen and clear damage rects
45         if( m_damageRects.empty() )
46                 return ;
47         
48         // Build up foreground grid (Rects and windows)
49         // - This should already be built (mutated on window move/resize/reorder)
50         
51         // For all windows, check for intersection with damage rects
52         for( auto rect : m_damageRects )
53         {
54                 _SysDebug("rect=(%i,%i) %ix%i", rect.m_x, rect.m_y, rect.m_w, rect.m_h);
55                 // window list should be sorted by draw order (lowest first)
56                 for( auto window : m_windows )
57                 {
58                         if( rect.HasIntersection( window->m_surface.m_rect ) )
59                         {
60                                 // TODO: just reblit
61                                 CRect   rel_rect = window->m_surface.m_rect.RelativeIntersection(rect);
62                                 BlitFromSurface( window->m_surface, rel_rect );
63                                 //window->Repaint( rel_rect );
64                         }
65                 }
66                 
67                 // TODO: Blit from windows to a local surface, then blit from there to screen here
68         }
69
70         m_damageRects.clear();
71         m_video.Flush();
72 }
73
74 void CCompositor::DamageArea(const CRect& area)
75 {
76         m_damageRects.push_back( area );
77         // 1. Locate intersection with any existing damaged areas
78         // 2. Append after removing intersections
79 }
80
81 void CCompositor::BlitFromSurface(const CSurface& dest, const CRect& src_rect)
82 {
83         for( unsigned int i = 0; i < src_rect.m_h; i ++ )
84         {
85                 m_video.BlitLine(
86                         dest.GetScanline(src_rect.m_y, src_rect.m_y),
87                         dest.m_rect.m_y + src_rect.m_y + i,
88                         dest.m_rect.m_x + src_rect.m_x,
89                         src_rect.m_w
90                         );
91         }
92 }
93
94 }       // namespace AxWin
95

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