usermode/axwin4 - Blit to screen planned
authorJohn Hodge <[email protected]>
Wed, 21 May 2014 15:22:33 +0000 (23:22 +0800)
committerJohn Hodge <[email protected]>
Wed, 21 May 2014 15:22:33 +0000 (23:22 +0800)
13 files changed:
Usermode/Applications/axwin4_src/Server/CRect.cpp
Usermode/Applications/axwin4_src/Server/CSurface.cpp [new file with mode: 0644]
Usermode/Applications/axwin4_src/Server/CWindow.cpp
Usermode/Applications/axwin4_src/Server/Makefile
Usermode/Applications/axwin4_src/Server/compositor.cpp
Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp
Usermode/Applications/axwin4_src/Server/include/CRect.hpp
Usermode/Applications/axwin4_src/Server/include/CSurface.hpp [new file with mode: 0644]
Usermode/Applications/axwin4_src/Server/include/CWindow.hpp
Usermode/Applications/axwin4_src/Server/include/common.hpp [new file with mode: 0644]
Usermode/Applications/axwin4_src/Server/include/video.hpp
Usermode/Applications/axwin4_src/Server/main.cpp
Usermode/Applications/axwin4_src/Server/video.cpp

index 5fd13c0..5d603e5 100644 (file)
@@ -6,17 +6,54 @@
  * - Rectangle
  */
 #include <CRect.hpp>
+#include <algorithm>
 
 namespace AxWin {
 
-CRect::CRect(int x, int y, int w, int h)
-       //m_x(x), m_y(y), m_w(w), m_h(h)
+CRect::CRect(int x, int y, unsigned int w, unsigned int h):
+       m_x(x), m_y(y),
+       m_w(w), m_h(h),
+       m_x2(x+w), m_y2(y+h)
 {
 }
 
-bool CRect::Contains(const CRect& other) const
+bool CRect::HasIntersection(const CRect& other) const
 {
-       return false;
+       // If other's origin is past our far corner
+       if( m_x2 < other.m_x )
+               return false;
+       if( m_y2 < other.m_y )
+               return false;
+       
+       // If other's far corner is before our origin
+       if( m_x > other.m_x2 )
+               return false;
+       if( m_y > other.m_y2 )
+               return false;
+       return true;
+}
+
+CRect CRect::Intersection(const CRect& other) const
+{
+       int x1 = ::std::max(m_x, other.m_x);
+       int y1 = ::std::max(m_y, other.m_y);
+       int x2 = ::std::min(m_x2, other.m_x2);
+       int y2 = ::std::min(m_y2, other.m_y2);
+       
+       if( x1 <= x2 || y2 <= y1 )
+               return CRect();
+       
+       return CRect(x1, y1, x2-x1, y2-y2);
+}
+
+CRect CRect::RelativeIntersection(const CRect& area)
+{
+       CRect   ret = Intersection(area);
+       ret.m_x -= m_x;
+       ret.m_x2 -= m_x;
+       ret.m_y -= m_y;
+       ret.m_y2 -= m_y;
+       return ret;
 }
 
 };
diff --git a/Usermode/Applications/axwin4_src/Server/CSurface.cpp b/Usermode/Applications/axwin4_src/Server/CSurface.cpp
new file mode 100644 (file)
index 0000000..a7206b6
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Acess2 GUI v4
+ * - By John Hodge (thePowersGang)
+ *
+ * CWindow.cpp
+ * - Window
+ */
+#include <CSurface.hpp>
+
+namespace AxWin {
+
+CSurface::CSurface(unsigned int x, unsigned int y, unsigned int w, unsigned int h):
+       m_rect(x,y, w,h)
+{
+}
+
+CSurface::~CSurface()
+{
+}
+
+const uint32_t* CSurface::GetScanline(unsigned int row, unsigned int x_ofs) const
+{
+       return 0;
+}
+
+
+};     // namespace AxWin
+
+
index 79308cc..4d1416e 100644 (file)
@@ -12,7 +12,7 @@ namespace AxWin {
 CWindow::CWindow(CClient& client, const ::std::string& name):
        m_client(client),
        m_name(name),
-       m_rect(0,0,0,0)
+       m_surface(0,0,0,0)
 {
        
 }
@@ -23,7 +23,16 @@ CWindow::~CWindow()
 
 void CWindow::Repaint(const CRect& rect)
 {
-       
+       #if 0
+       for( auto rgn : m_regions )
+       {
+               if( rect.Contains(rgn->m_rect) )
+               {
+                       CRect   rel_rect(rect, rgn->m_rect);
+                       rgn->Repaint();
+               } 
+       }
+       #endif
 }
 
 };
index 5f6ced4..2b8089f 100644 (file)
@@ -5,7 +5,7 @@ CPPFLAGS += -Iinclude/
 OBJ := main.o ipc.o CConfig.o video.o input.o timing.o
 OBJ += compositor.o CWindow.o
 OBJ += serialisation.o CClient.o
-OBJ += CRect.o
+OBJ += CRect.o CSurface.o
 BIN := AxWinServer
 
 LDFLAGS += -lc++
index 497bf74..9306e41 100644 (file)
@@ -11,7 +11,8 @@
 
 namespace AxWin {
 
-CCompositor::CCompositor()
+CCompositor::CCompositor(CVideo& video):
+       m_video(video)
 {
        // 
 }
@@ -35,9 +36,12 @@ void CCompositor::Redraw()
        {
                for( auto window : m_windows )
                {
-                       if( rect.Contains( window->m_rect ) )
+                       if( rect.HasIntersection( window->m_surface.m_rect ) )
                        {
-                               window->Repaint( rect );
+                               // TODO: just reblit
+                               CRect   rel_rect = window->m_surface.m_rect.RelativeIntersection(rect);
+                               BlitFromSurface( window->m_surface, rel_rect );
+                               //window->Repaint( rel_rect );
                        }
                }
        }
@@ -51,5 +55,18 @@ void CCompositor::DamageArea(const CRect& area)
        // 2. Append after removing intersections
 }
 
+void CCompositor::BlitFromSurface(const CSurface& dest, const CRect& src_rect)
+{
+       for( unsigned int i = 0; i < src_rect.m_h; i ++ )
+       {
+               m_video.BlitLine(
+                       dest.GetScanline(src_rect.m_y, src_rect.m_y),
+                       dest.m_rect.m_y + src_rect.m_y + i,
+                       dest.m_rect.m_x + src_rect.m_x,
+                       src_rect.m_w
+                       );
+       }
+}
+
 }      // namespace AxWin
 
index e86286a..0b051be 100644 (file)
@@ -9,25 +9,38 @@
 #define _CCOMPOSITOR_H_
 
 #include <list>
+#include <vector>
 #include "CRect.hpp"
 #include "CWindow.hpp"
 
 namespace AxWin {
 
 class CClient;
+class CVideo;
+
+struct TWindowID
+{
+       uint16_t        Client;
+       uint16_t        Window;
+};
 
 class CCompositor
 {
+       CVideo& m_video;
        ::std::list<CRect>      m_damageRects;
        ::std::list<CWindow*>   m_windows;
 
+       ::std::vector<TWindowID>        m_windowIDBuffer;       // One 32-bit value per pixel
+       //::std::vector<CPixel>         m_frameBuffer;  // Local copy of the framebuffer (needed?)
+       
 public:
-       CCompositor();
+       CCompositor(CVideo& video);
 
        CWindow* CreateWindow(CClient& client);
 
        void    Redraw();
        void    DamageArea(const CRect& rect);
+       void    BlitFromSurface(const CSurface& dest, const CRect& src_rect);
 };
 
 
index 69e7c19..7461568 100644 (file)
@@ -8,9 +8,23 @@ namespace AxWin {
 class CRect
 {
 public:
-       CRect(int X, int Y, int W, int H);
+       CRect():
+               CRect(0,0,0,0)
+       {
+       };
+       CRect(int X, int Y, unsigned int W, unsigned int H);
        
-       bool Contains(const CRect& other) const;
+       bool HasIntersection(const CRect& other) const;
+       CRect Intersection(const CRect& other) const;
+       
+       CRect RelativeIntersection(const CRect& area);
+       
+       int     m_x;
+       int     m_y;
+       int     m_w;
+       int     m_h;
+       int     m_x2;
+       int     m_y2;
 };
 
 };     // namespace AxWin
diff --git a/Usermode/Applications/axwin4_src/Server/include/CSurface.hpp b/Usermode/Applications/axwin4_src/Server/include/CSurface.hpp
new file mode 100644 (file)
index 0000000..91b61f8
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ */
+#ifndef _CSURFACE_H_
+#define _CSURFACE_H_
+
+#include <cstdint>
+#include "CRect.hpp"
+
+namespace AxWin {
+
+class CSurface
+{
+public:
+       CSurface(unsigned int x, unsigned int y, unsigned int w, unsigned int h);
+       ~CSurface();
+       
+       const uint32_t* GetScanline(unsigned int row, unsigned int x_ofs) const;
+       
+       CRect   m_rect;
+       uint32_t*       m_data;
+};
+
+};     // namespace AxWin
+
+#endif
+
index 86b49c9..00bc7e8 100644 (file)
@@ -12,6 +12,7 @@
 #include <vector>
 #include <cstdint>
 #include "CRect.hpp"
+#include "CSurface.hpp"
 
 namespace AxWin {
 
@@ -19,7 +20,6 @@ class CClient;
 
 class CWindow
 {
-       CClient&        m_client;
 public:
        CWindow(CClient& client, const ::std::string &name);
        ~CWindow();
@@ -30,9 +30,11 @@ public:
        void MouseMove(int NewX, int NewY);
        void KeyEvent(::uint32_t Scancode, const ::std::string &Translated, bool Down);
 
-       CRect   m_rect;
+       CSurface        m_surface;
 private:
        const ::std::string     m_name;
+       CClient&        m_client;
+       //::std::list<CRegion*> m_regions;
 };
 
 };     // namespace AxWin
diff --git a/Usermode/Applications/axwin4_src/Server/include/common.hpp b/Usermode/Applications/axwin4_src/Server/include/common.hpp
new file mode 100644 (file)
index 0000000..1a1facc
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ */
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+#include <exception>
+
+namespace AxWin {
+
+class InitFailure:
+       public ::std::exception
+{
+       const char *m_what;
+public:
+       InitFailure(const char *reason):
+               m_what(reason)
+       {
+       }
+       
+       virtual const char* what() const throw();
+};
+
+}      // namespace AxWin
+
+#endif
+
index cf0440b..baa75d2 100644 (file)
@@ -8,13 +8,20 @@
 #ifndef _VIDEO_H_
 #define _VIDEO_H_
 
+#include <cstdint>
 #include "CConfigVideo.hpp"
 
 namespace AxWin {
-namespace Graphics {
-
-extern void Initialise(const CConfigVideo& config);
 
+class CVideo
+{
+        int    m_fd;
+       unsigned int    m_width;
+       unsigned int    m_height;
+public:
+       CVideo(const CConfigVideo& config);
+       
+       void BlitLine(const uint32_t* src, unsigned int dst_y, unsigned int dst_x, unsigned int width);
 };
 
 };
index e14ef13..8f0d9e8 100644 (file)
@@ -1,4 +1,9 @@
 /*
+ * Acess2 GUI v4 (AxWin4)
+ * - By John Hodge (thePowesGang)
+ * 
+ * main.cpp
+ * - Program main
  */
 #include <CConfig.hpp>
 #include <ipc.hpp>
@@ -8,6 +13,7 @@
 #include <timing.hpp>
 #include <exception>
 #include <algorithm>
+#include <common.hpp>
 
 extern "C" {
 #include <stdio.h>
@@ -29,9 +35,9 @@ int main(int argc, char *argv[])
                return 1;
        }
        // - Open graphics
-       Graphics::Initialise(config.m_video);
+       CVideo* vid = new CVideo(config.m_video);
        // - Initialise compositor structures
-       CCompositor* compositor = new CCompositor(/*config.m_compositor*/);
+       CCompositor* compositor = new CCompositor(/*config.m_compositor,*/ *vid);
        // - Open input
        Input::Initialise(config.m_input);
        //  > Handles hotkeys?
@@ -63,3 +69,13 @@ int main(int argc, char *argv[])
        return 0;
 }
 
+namespace AxWin {
+
+const char* InitFailure::what() const throw()
+{
+       return m_what;
+}
+
+
+}
+
index a394922..6fde7aa 100644 (file)
@@ -5,17 +5,39 @@
  * video.cpp
  * - Graphics output
  */
+#include <cstddef>
 #include <video.hpp>
+#include <common.hpp>
 
-namespace AxWin {
+extern "C" {
+#include <acess/sys.h>
+#include <acess/devices/pty.h>
+}
 
-namespace Graphics {
+namespace AxWin {
 
-void Initialise(const CConfigVideo& config)
+CVideo::CVideo(const CConfigVideo& config):
+       m_fd(0)
 {
+       {
+               if( _SysIOCtl(m_fd, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL )
+                       throw AxWin::InitFailure("stdin isn't a terminal");
+               struct ptydims  dims;
+               if( _SysIOCtl(m_fd, PTY_IOCTL_GETDIMS, &dims) == -1 )
+                       throw AxWin::InitFailure("Failed to get dimensions from stdin");
+               m_width = dims.PW;
+               m_height = dims.PH;
+               if( m_width == 0 || m_height == 0 )
+                       throw AxWin::InitFailure("Terminal not capable of graphics");
+       }
 }
 
-};
+void CVideo::BlitLine(const uint32_t* src, unsigned int dst_y, unsigned int dst_x, unsigned int width)
+{
+       //_SysWriteAt(m_fd, (dst_y * m_width + dst_x) * 4, width * 4, src);
+       _SysSeek(m_fd, (dst_y * m_width + dst_x) * 4, SEEK_SET);
+       _SysWrite(m_fd, src, width * 4);
+}
 
 };     // namespace AxWin
 

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