From: John Hodge Date: Wed, 21 May 2014 15:22:33 +0000 (+0800) Subject: usermode/axwin4 - Blit to screen planned X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b471bc9adca2cf2126c2b579bf0b33cedd2839a4;p=tpg%2Facess2.git usermode/axwin4 - Blit to screen planned --- diff --git a/Usermode/Applications/axwin4_src/Server/CRect.cpp b/Usermode/Applications/axwin4_src/Server/CRect.cpp index 5fd13c08..5d603e5a 100644 --- a/Usermode/Applications/axwin4_src/Server/CRect.cpp +++ b/Usermode/Applications/axwin4_src/Server/CRect.cpp @@ -6,17 +6,54 @@ * - Rectangle */ #include +#include 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 index 00000000..a7206b67 --- /dev/null +++ b/Usermode/Applications/axwin4_src/Server/CSurface.cpp @@ -0,0 +1,29 @@ +/* + * Acess2 GUI v4 + * - By John Hodge (thePowersGang) + * + * CWindow.cpp + * - Window + */ +#include + +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 + + diff --git a/Usermode/Applications/axwin4_src/Server/CWindow.cpp b/Usermode/Applications/axwin4_src/Server/CWindow.cpp index 79308cc4..4d1416ed 100644 --- a/Usermode/Applications/axwin4_src/Server/CWindow.cpp +++ b/Usermode/Applications/axwin4_src/Server/CWindow.cpp @@ -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 } }; diff --git a/Usermode/Applications/axwin4_src/Server/Makefile b/Usermode/Applications/axwin4_src/Server/Makefile index 5f6ced4d..2b8089f2 100644 --- a/Usermode/Applications/axwin4_src/Server/Makefile +++ b/Usermode/Applications/axwin4_src/Server/Makefile @@ -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++ diff --git a/Usermode/Applications/axwin4_src/Server/compositor.cpp b/Usermode/Applications/axwin4_src/Server/compositor.cpp index 497bf741..9306e413 100644 --- a/Usermode/Applications/axwin4_src/Server/compositor.cpp +++ b/Usermode/Applications/axwin4_src/Server/compositor.cpp @@ -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 diff --git a/Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp b/Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp index e86286a6..0b051be2 100644 --- a/Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/CCompositor.hpp @@ -9,25 +9,38 @@ #define _CCOMPOSITOR_H_ #include +#include #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 m_damageRects; ::std::list m_windows; + ::std::vector m_windowIDBuffer; // One 32-bit value per pixel + //::std::vector 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); }; diff --git a/Usermode/Applications/axwin4_src/Server/include/CRect.hpp b/Usermode/Applications/axwin4_src/Server/include/CRect.hpp index 69e7c194..7461568c 100644 --- a/Usermode/Applications/axwin4_src/Server/include/CRect.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/CRect.hpp @@ -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 index 00000000..91b61f8c --- /dev/null +++ b/Usermode/Applications/axwin4_src/Server/include/CSurface.hpp @@ -0,0 +1,26 @@ +/* + */ +#ifndef _CSURFACE_H_ +#define _CSURFACE_H_ + +#include +#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 + diff --git a/Usermode/Applications/axwin4_src/Server/include/CWindow.hpp b/Usermode/Applications/axwin4_src/Server/include/CWindow.hpp index 86b49c99..00bc7e87 100644 --- a/Usermode/Applications/axwin4_src/Server/include/CWindow.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/CWindow.hpp @@ -12,6 +12,7 @@ #include #include #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 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 index 00000000..1a1facc3 --- /dev/null +++ b/Usermode/Applications/axwin4_src/Server/include/common.hpp @@ -0,0 +1,26 @@ +/* + */ +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#include + +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 + diff --git a/Usermode/Applications/axwin4_src/Server/include/video.hpp b/Usermode/Applications/axwin4_src/Server/include/video.hpp index cf0440b2..baa75d24 100644 --- a/Usermode/Applications/axwin4_src/Server/include/video.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/video.hpp @@ -8,13 +8,20 @@ #ifndef _VIDEO_H_ #define _VIDEO_H_ +#include #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); }; }; diff --git a/Usermode/Applications/axwin4_src/Server/main.cpp b/Usermode/Applications/axwin4_src/Server/main.cpp index e14ef135..8f0d9e87 100644 --- a/Usermode/Applications/axwin4_src/Server/main.cpp +++ b/Usermode/Applications/axwin4_src/Server/main.cpp @@ -1,4 +1,9 @@ /* + * Acess2 GUI v4 (AxWin4) + * - By John Hodge (thePowesGang) + * + * main.cpp + * - Program main */ #include #include @@ -8,6 +13,7 @@ #include #include #include +#include extern "C" { #include @@ -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; +} + + +} + diff --git a/Usermode/Applications/axwin4_src/Server/video.cpp b/Usermode/Applications/axwin4_src/Server/video.cpp index a3949221..6fde7aa0 100644 --- a/Usermode/Applications/axwin4_src/Server/video.cpp +++ b/Usermode/Applications/axwin4_src/Server/video.cpp @@ -5,17 +5,39 @@ * video.cpp * - Graphics output */ +#include #include +#include -namespace AxWin { +extern "C" { +#include +#include +} -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