From 3a96ffc381c2442120912153e9fbd136724ab5d1 Mon Sep 17 00:00:00 2001 From: cxl Date: Sat, 1 Feb 2014 16:35:46 +0000 Subject: [PATCH] .developing Turtle git-svn-id: svn://ultimatepp.org/upp/trunk@6844 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- rainbow/Turtle/Ctrl.h | 26 ++++++---- rainbow/Turtle/Draw.cpp | 2 + rainbow/Turtle/DrawDragRect.cpp | 2 +- rainbow/Turtle/Event.cpp | 69 +++++++++++++++++++------- rainbow/Turtle/FB.iml | 74 ++++++++++++++-------------- rainbow/Turtle/Image.cpp | 86 +++++++++++++++++++++++++++++++++ rainbow/Turtle/Output.cpp | 16 +++--- rainbow/Turtle/Server.cpp | 2 +- rainbow/Turtle/Turtle.h | 72 ++++++++++++++++----------- rainbow/Turtle/Turtle.html | 14 ++++-- rainbow/WebWord/WebWord.cpp | 4 +- 11 files changed, 260 insertions(+), 107 deletions(-) diff --git a/rainbow/Turtle/Ctrl.h b/rainbow/Turtle/Ctrl.h index 39d412222..dee3a85f2 100644 --- a/rainbow/Turtle/Ctrl.h +++ b/rainbow/Turtle/Ctrl.h @@ -86,22 +86,28 @@ private: friend void DrawDragRect(Ctrl& q, const Rect& rect1, const Rect& rect2, const Rect& clip, int n, Color color, int type, int animation); friend void DrawDragLine(SystemDraw& w, bool horz, int x, int y, int len, int n, int animation); + + static int serial_time0; + static int64 serial_0; + friend struct ImageSysData; public: static bool DoKeyFB(dword key, int cnt); - static String host; - static int port; - static bool debugmode; - static String ip; + static String host; + static int port; + static bool debugmode; + static String ip; - static Time stat_started; - static int64 stat_data_send; - static int stat_putrect; - static int stat_putimage; - static int stat_setimage; - static int64 stat_setimage_len; + static Time stat_started; + static int64 stat_data_send; + static int stat_putrect; + static int stat_putimage; + static int stat_setimage; + static int64 stat_setimage_len; + static int stat_roundtrip_ms; + static int stat_client_ms; static bool StartSession(); static Callback WhenDisconnect; diff --git a/rainbow/Turtle/Draw.cpp b/rainbow/Turtle/Draw.cpp index 5405e0995..c8c8712b2 100644 --- a/rainbow/Turtle/Draw.cpp +++ b/rainbow/Turtle/Draw.cpp @@ -6,6 +6,7 @@ NAMESPACE_UPP +#if 0 Index SystemDraw::img_index[3]; int SystemDraw::GetImageI(int from, Index& img_index, int maxcount, const Image& img) @@ -68,6 +69,7 @@ void SystemDraw::PutImage(Point p, const Image& img, const Rect& src) Ctrl::Put(src); pos = p; } +#endif void SystemDraw::PutRect(const Rect& r, Color color) { diff --git a/rainbow/Turtle/DrawDragRect.cpp b/rainbow/Turtle/DrawDragRect.cpp index 586328c1a..4615490db 100644 --- a/rainbow/Turtle/DrawDragRect.cpp +++ b/rainbow/Turtle/DrawDragRect.cpp @@ -16,7 +16,7 @@ void DrawDragLine(SystemDraw& w, bool horz, int x, int y, int len, int n, int an if(len <= 0) return; for(int i = 0; i < n; i++) { - Ctrl::Put8(horz ? SystemDraw::HORZDRAGLINE : SystemDraw::VERTDRAGLINE); + Ctrl::Put8(horz ? HORZDRAGLINE : VERTDRAGLINE); Ctrl::Put16(x + !horz * i); Ctrl::Put16(y + horz * i); Ctrl::Put16(len); diff --git a/rainbow/Turtle/Event.cpp b/rainbow/Turtle/Event.cpp index 08f565416..3d00dd5fe 100644 --- a/rainbow/Turtle/Event.cpp +++ b/rainbow/Turtle/Event.cpp @@ -8,12 +8,17 @@ NAMESPACE_UPP #define LDUMP(x) // RDUMP(x) #define LTIMING(x) +int Ctrl::serial_time0 = Null; +int64 Ctrl::serial_0; + Time Ctrl::stat_started; int64 Ctrl::stat_data_send; int Ctrl::stat_putrect; int Ctrl::stat_putimage; int Ctrl::stat_setimage; int64 Ctrl::stat_setimage_len; +int Ctrl::stat_roundtrip_ms; +int Ctrl::stat_client_ms; static Point MousePos; @@ -64,12 +69,18 @@ bool Ctrl::IsWaitingEvent() uint32 l = p.ReadNumber(); uint32 h = p.ReadNumber(); recieved_update_serial = MAKEQWORD(l, h); + stat_client_ms = p.ReadNumber(); } else event_queue.AddTail(s); } catch(CParser::Error) {} } + if(recieved_update_serial == serial_0) { + serial_0 = 0; + stat_roundtrip_ms = msecs() - serial_time0; + serial_time0 = Null; + } } socket.Timeout(20000); if(socket.IsError()) @@ -77,23 +88,6 @@ bool Ctrl::IsWaitingEvent() return event_queue.GetCount(); } -bool Ctrl::ProcessEvents(bool *quit) -{ - GuiLock __; - LLOG("---- Process events"); - bool r = false; - while(IsWaitingEvent()) { - while(event_queue.GetCount() >= 2 && *event_queue[0] == 'M' && *event_queue[1] == 'M') - event_queue.DropHead(); // MouseMove compression - String ev = event_queue[0]; - event_queue.DropHead(); - ProcessEvent(ev); - r = true; - } - TimerAndPaint(); - return r; -} - void Ctrl::GuiSleep(int ms) { GuiLock __; @@ -317,8 +311,25 @@ bool Ctrl::ProcessEvent(const String& event) if(p.Id("K")) { int code = p.ReadInt(); int which = p.ReadInt(); + int count = 1; + for(;;) { + if(event_queue.GetCount() && event_queue[0] == event) { // Chrome autorepeat + event_queue.DropHead(); + count++; + } + else + if(event_queue.GetCount() >= 2 && *event_queue[0] == 'C' && event_queue[1] == event) { // Firefox autorepeat + String h = event_queue[0]; + event_queue.DropHead(); + event_queue.DropHead(); + event_queue.AddHead(h); + count++; + } + else + break; + } ReadKeyMods(p); - DoKeyFB(fbKEYtoK(which), 1); + DoKeyFB(fbKEYtoK(which), count); } else if(p.Id("k")) { @@ -332,6 +343,11 @@ bool Ctrl::ProcessEvent(const String& event) int code = p.ReadInt(); int which = p.ReadInt(); ReadKeyMods(p); + int count = 1; + while(event_queue.GetCount() && event_queue[0] == event) { // 'K's are not there anymore + event_queue.DropHead(); + count++; + } if(which && !keyAlt && !keyCtrl && findarg(which, 9, 0xd) < 0) DoKeyFB(which, 1); } @@ -340,6 +356,23 @@ bool Ctrl::ProcessEvent(const String& event) return true; } +bool Ctrl::ProcessEvents(bool *quit) +{ + GuiLock __; + LLOG("---- Process events"); + bool r = false; + while(IsWaitingEvent()) { + while(event_queue.GetCount() >= 2 && *event_queue[0] == 'M' && *event_queue[1] == 'M') + event_queue.DropHead(); // MouseMove compression + String ev = event_queue[0]; + event_queue.DropHead(); + ProcessEvent(ev); + r = true; + } + TimerAndPaint(); + return r; +} + Point GetMousePos() { return MousePos; } diff --git a/rainbow/Turtle/FB.iml b/rainbow/Turtle/FB.iml index c36090ae7..91e9806c4 100644 --- a/rainbow/Turtle/FB.iml +++ b/rainbow/Turtle/FB.iml @@ -23,41 +23,41 @@ IMAGE_ID(border) IMAGE_ID(Hand) IMAGE_BEGIN_DATA -IMAGE_DATA(120,156,237,90,61,104,20,65,20,30,77,162,9,92,144,248,135,160,133,117,42,177,18,21,4,171,84,65,76,22,4,149) -IMAGE_DATA(136,17,37,49,66,4,13,40,72,34,4,145,128,120,133,196,20,49,30,24,11,207,104,33,105,196,4,114,133,34,66,68) -IMAGE_DATA(52,129,67,20,65,4,145,52,218,217,61,103,214,157,117,118,110,126,222,91,247,240,135,157,229,177,55,51,223,247,230,205) -IMAGE_DATA(247,222,206,94,244,88,129,109,98,162,173,97,171,196,13,184,5,12,223,128,200,129,114,153,196,129,239,223,183,195,244,244) -IMAGE_DATA(22,44,7,190,125,219,13,95,191,238,131,169,169,29,24,14,172,172,28,128,47,95,186,225,243,231,195,48,62,190,223,199) -IMAGE_DATA(129,79,159,122,225,227,199,83,240,225,195,25,120,255,254,28,20,139,7,93,28,120,247,238,60,188,125,123,1,170,213,97) -IMAGE_DATA(88,90,186,2,175,95,95,131,177,177,99,54,14,44,47,143,194,155,55,87,225,213,171,235,240,242,229,4,188,120,113,7) -IMAGE_DATA(158,63,159,134,209,209,126,19,135,99,138,176,184,120,131,227,38,225,217,179,123,176,176,176,16,217,3,24,30,30,208,57) -IMAGE_DATA(220,215,4,199,77,194,211,167,119,160,82,121,24,98,75,165,146,196,169,22,226,43,149,91,220,74,48,63,127,23,230,230) -IMAGE_DATA(238,195,227,199,143,156,251,125,242,228,54,92,188,120,58,246,51,52,52,232,196,15,13,245,169,243,194,96,112,112,64,141) -IMAGE_DATA(33,129,55,105,208,223,127,210,170,167,97,44,92,163,183,247,152,109,13,83,131,158,158,35,148,186,13,215,8,130,110,210) -IMAGE_DATA(26,93,93,7,41,248,128,16,143,185,53,177,117,108,53,91,27,26,211,18,47,76,54,237,115,28,176,214,255,231,199,44) -IMAGE_DATA(251,173,209,133,21,184,112,77,92,180,166,164,112,88,11,51,183,245,222,184,211,20,44,147,248,109,101,179,41,248,120,83) -IMAGE_DATA(155,175,93,50,114,196,152,152,211,240,65,203,174,157,176,254,236,137,4,71,124,22,99,98,142,25,158,36,149,227,193,38) -IMAGE_DATA(56,98,125,97,30,108,204,209,180,115,98,9,254,41,241,83,245,161,234,79,201,47,181,126,104,245,217,198,175,230,232,178) -IMAGE_DATA(9,103,33,163,143,70,132,89,147,230,193,81,230,93,241,186,252,164,225,215,36,80,233,99,215,183,125,166,196,111,138,139) -IMAGE_DATA(194,151,205,231,195,199,247,249,192,240,77,62,108,251,196,232,100,251,236,203,117,205,97,237,136,203,23,131,105,140,194,255) -IMAGE_DATA(157,231,129,82,79,212,231,22,227,203,204,69,28,72,63,189,242,38,94,217,226,142,8,194,200,47,151,203,130,15,209,157) -IMAGE_DATA(228,71,229,243,110,42,63,81,252,9,97,162,109,185,14,139,68,12,160,180,200,101,220,92,177,168,92,137,83,125,216,48) -IMAGE_DATA(166,253,171,241,234,62,212,125,170,250,232,250,233,205,54,166,250,49,233,135,53,25,119,22,113,100,161,71,86,121,201,170) -IMAGE_DATA(62,212,102,210,153,82,167,186,62,204,160,95,26,63,105,248,170,31,148,6,109,252,107,127,51,107,8,77,39,251,4,176) -IMAGE_DATA(9,109,43,22,155,15,234,195,99,106,236,15,60,60,152,56,178,208,35,147,188,228,137,206,19,157,39,250,127,74,244,90) -IMAGE_DATA(158,234,134,40,213,186,67,87,2,93,137,241,9,174,196,155,16,72,235,199,65,203,57,211,134,254,230,57,215,254,92,186) -IMAGE_DATA(184,244,116,229,65,205,83,77,254,90,249,181,38,186,106,235,19,87,61,166,96,41,28,204,151,17,149,211,222,222,142,230) -IMAGE_DATA(72,49,132,117,118,118,122,121,74,18,2,41,40,134,167,182,44,121,152,167,88,231,97,79,15,201,19,122,178,72,91,44) -IMAGE_DATA(135,41,249,195,228,91,47,106,12,199,88,139,249,201,84,191,57,215,254,92,186,212,253,100,114,53,107,165,120,56,212,138) -IMAGE_DATA(76,83,249,212,39,140,250,36,83,79,12,204,201,164,36,27,125,2,74,61,169,39,173,212,132,114,162,51,150,254,205,193) -IMAGE_DATA(8,111,40,106,77,229,5,155,23,172,147,195,254,182,130,205,95,165,245,155,115,237,207,165,75,221,95,165,105,42,69,110) -IMAGE_DATA(66,15,150,194,201,191,228,219,121,174,19,208,198,251,175,191,228,23,248,149,81,3,143,153,240,46,95,105,241,152,56,116) -IMAGE_DATA(188,111,205,172,240,24,125,234,165,139,58,70,201,19,190,101,80,76,190,224,40,98,153,48,57,62,123,60,37,95,248,246) -IMAGE_DATA(187,197,180,177,177,49,216,219,218,10,226,142,153,19,253,61,220,244,113,137,149,115,182,113,209,55,141,153,214,13,231,11) -IMAGE_DATA(133,208,108,216,4,71,96,35,156,248,108,195,82,241,148,120,168,251,77,171,39,54,95,164,214,200,47,217,186,186,38,224) -IMAGE_DATA(80,223,12,28,189,60,3,199,111,206,0,181,31,59,107,8,255,111,102,4,90,218,203,176,33,88,134,109,195,226,37,76) -IMAGE_DATA(236,139,50,111,226,87,244,183,44,246,121,74,188,249,125,77,252,166,90,197,255,250,77,182,217,70,70,70,114,124,157,240) -IMAGE_DATA(178,239,179,52,181,16,22,147,227,31,70,228,175,156,212,187,11,7,197,98,49,113,183,112,226,249,106,181,154,184,91,56) -IMAGE_DATA(53,56,121,87,214,97,234,198,108,120,101,157,56,142,142,142,14,52,94,244,165,97,240,179,179,179,9,142,201,20,124,32) -IMAGE_DATA(98,17,49,33,241,94,142,88,95,195,199,28,19,94,140,219,114,230,139,229,7,18,241,124,50,0,0,0,0,0,0,0) +IMAGE_DATA(120,156,237,90,77,72,85,65,20,158,82,251,129,39,97,84,4,181,104,253,86,209,42,42,8,90,185,146,200,46,36,21) +IMAGE_DATA(70,70,161,21,24,148,80,16,26,72,68,32,189,69,152,139,50,65,91,248,178,22,225,38,52,208,69,17,66,17,253,192) +IMAGE_DATA(35,138,32,4,17,55,182,107,119,154,185,222,185,205,157,55,63,231,92,239,163,31,238,185,28,238,157,153,239,59,115,230) +IMAGE_DATA(156,51,115,47,143,199,10,108,43,19,178,142,173,17,55,224,26,48,188,0,145,3,229,50,137,3,63,127,238,130,177,177) +IMAGE_DATA(237,88,14,252,248,177,15,150,151,15,194,240,240,110,12,7,150,150,14,195,226,226,81,88,88,56,14,131,131,135,124,28) +IMAGE_DATA(152,159,239,128,239,223,207,193,183,111,23,225,235,215,203,80,42,29,113,113,224,203,151,43,240,249,243,85,168,84,122,225) +IMAGE_DATA(227,199,155,240,254,253,0,220,190,125,202,198,129,79,159,250,225,195,135,91,240,238,221,29,120,251,118,8,230,230,70,225) +IMAGE_DATA(245,235,49,232,239,239,50,113,56,166,4,111,222,220,229,184,251,240,234,213,56,204,204,204,68,250,4,122,123,47,232,28) +IMAGE_DATA(110,107,136,227,238,195,203,151,163,48,59,251,52,196,142,140,140,72,156,170,33,126,118,246,1,215,17,120,241,226,17,76) +IMAGE_DATA(79,63,134,231,207,159,57,215,59,53,245,16,174,93,59,31,219,233,233,233,118,226,123,122,58,213,113,161,208,221,125,65) +IMAGE_DATA(245,33,129,55,197,160,171,235,172,53,158,134,190,112,142,142,142,83,182,57,76,2,237,237,39,40,117,27,206,17,4,71) +IMAGE_DATA(73,115,180,182,30,161,224,3,130,63,102,105,96,155,216,90,182,62,84,166,37,94,168,20,237,57,118,88,107,255,243,125) +IMAGE_DATA(150,245,86,197,133,21,120,224,26,120,208,26,146,129,195,106,152,185,29,227,131,78,85,176,76,226,119,150,205,170,224,227) +IMAGE_DATA(69,109,27,184,110,228,136,62,49,166,225,131,141,123,247,192,230,75,103,18,28,241,44,250,196,24,51,236,36,149,227,193) +IMAGE_DATA(38,56,98,126,161,30,108,204,209,98,231,196,18,236,83,252,167,198,135,26,127,74,126,169,245,67,171,207,38,126,109,136) +IMAGE_DATA(46,91,224,44,100,244,209,136,80,107,210,60,56,202,184,203,95,151,157,52,252,170,4,42,109,236,252,182,103,138,255,38) +IMAGE_DATA(191,40,124,41,62,27,62,190,207,6,134,111,178,97,91,39,38,78,182,103,95,174,171,14,107,135,95,62,31,76,125,20) +IMAGE_DATA(254,106,246,3,165,158,168,251,22,99,203,204,69,28,72,43,86,185,136,87,182,184,35,156,48,242,203,229,178,224,67,116) +IMAGE_DATA(39,217,81,249,188,153,202,78,228,127,34,48,209,178,92,135,69,194,7,80,36,50,25,139,203,23,149,43,113,170,13,27) +IMAGE_DATA(198,180,126,213,95,221,134,186,78,53,62,122,252,116,177,245,169,118,76,241,195,170,244,59,11,63,178,136,71,86,121,201) +IMAGE_DATA(170,62,84,49,197,153,82,167,122,124,152,33,126,105,236,164,225,171,118,80,49,104,226,159,253,27,88,93,168,58,217,23) +IMAGE_DATA(0,91,160,109,197,98,179,65,221,60,38,97,127,96,243,96,252,200,34,30,153,228,37,79,116,158,232,60,209,255,83,162) +IMAGE_DATA(215,243,84,215,69,169,214,13,186,18,232,74,140,47,224,138,191,137,0,105,237,216,105,57,102,90,208,223,60,230,90,159) +IMAGE_DATA(43,46,174,120,186,242,160,230,169,42,127,141,252,90,23,93,213,245,137,171,30,147,179,20,14,230,99,68,229,20,139,69) +IMAGE_DATA(52,71,6,67,104,75,75,139,151,167,36,33,144,1,197,240,84,201,146,135,217,197,58,15,123,122,72,158,136,39,139,98) +IMAGE_DATA(139,229,48,37,127,152,124,235,69,141,225,24,107,49,63,153,106,55,230,90,159,43,46,53,63,153,92,98,173,20,15,135) +IMAGE_DATA(90,145,105,42,159,186,195,168,59,153,122,98,96,78,38,37,217,232,19,80,198,147,122,210,202,152,80,78,116,198,210,191) +IMAGE_DATA(57,24,225,13,69,173,169,188,96,243,130,117,114,216,223,86,176,249,171,180,118,99,174,245,185,226,82,243,87,105,154,74) +IMAGE_DATA(145,139,208,157,165,112,242,143,124,59,207,117,2,218,120,255,245,71,126,129,95,89,72,80,228,197,234,80,19,222,101,107) +IMAGE_DATA(21,248,149,141,83,180,254,142,100,194,219,236,103,138,71,198,199,149,72,235,156,68,188,75,211,75,6,197,228,115,78,119) +IMAGE_DATA(18,227,112,142,175,45,158,146,47,188,172,182,152,182,212,215,7,7,26,27,65,220,49,99,162,189,159,171,222,47,177,114) +IMAGE_DATA(204,214,47,218,166,62,211,188,225,120,161,16,170,13,155,224,8,108,132,19,207,54,44,21,79,241,135,186,222,180,241,196) +IMAGE_DATA(230,139,36,245,252,146,210,218,58,4,199,58,39,224,228,141,9,56,125,111,2,168,237,216,88,29,191,6,202,131,176,26) +IMAGE_DATA(13,203,188,129,95,226,139,177,173,173,13,168,138,17,241,159,106,21,255,251,63,217,102,237,235,235,203,241,53,194,203,182) +IMAGE_DATA(79,211,212,66,88,76,142,31,70,228,191,156,212,187,11,7,165,82,41,113,183,112,226,241,74,165,146,184,91,56,85,56) +IMAGE_DATA(121,87,230,97,10,223,138,87,230,137,253,104,110,110,70,227,69,91,42,6,63,57,57,153,224,152,84,193,7,194,23,225) +IMAGE_DATA(19,18,239,229,136,249,53,124,204,49,225,69,191,45,103,62,95,126,1,244,79,194,252,0,0,0,0,0,0,0,0,0) IMAGE_END_DATA(1184, 22) diff --git a/rainbow/Turtle/Image.cpp b/rainbow/Turtle/Image.cpp index 7c2f58f11..e671813d0 100644 --- a/rainbow/Turtle/Image.cpp +++ b/rainbow/Turtle/Image.cpp @@ -4,8 +4,94 @@ NAMESPACE_UPP +#define LLOG(x) // LOG(x) #define LTIMING(x) // RTIMING(x) +Vector SystemDraw::ImageSysData::free_handle; +int SystemDraw::ImageSysData::handle_count; + +int SystemDraw::ImageSysData::AllocImageHandle() +{ + if(free_handle.GetCount()) + return free_handle.Pop(); + return handle_count++; +} + +void SystemDraw::ImageSysData::FreeImageHandle(int handle) +{ + free_handle.Add(handle); +} + +void SystemDraw::ImageSysData::Init(const Image& m) +{ + img = m; + handle = AllocImageHandle(); + DLOG("SetImage " << handle << ", size: " << img.GetSize() << ", cache size: " << SystemDraw::cache.GetSize()); + Ctrl::Put8(SETIMAGE); + Ctrl::Put16(handle); + Ctrl::Put(img.GetSize()); + const RGBA *end = ~img + img.GetLength(); + for(const RGBA *s = ~img; s < end; s++) { + Ctrl::Put8(s->r); + Ctrl::Put8(s->g); + Ctrl::Put8(s->b); + Ctrl::Put8(s->a); + } + Ctrl::stat_setimage++; + Ctrl::stat_setimage_len += img.GetLength() * sizeof(RGBA); + SysImageRealized(img); +} + +SystemDraw::ImageSysData::~ImageSysData() +{ + SysImageReleased(img); + FreeImageHandle(handle); +} + +struct ImageSysDataMaker : LRUCache::Maker { + Image img; + + virtual int64 Key() const { return img.GetSerialId(); } + virtual int Make(SystemDraw::ImageSysData& object) const { object.Init(img); return img.GetLength(); } +}; + +LRUCache SystemDraw::cache; + +void SystemDraw::PutImage(Point p, const Image& img, const Rect& src) +{ + LLOG("Ctrl::PutImage " << p << ", size: " << img.GetSize() << ", src: " << src << ", id: " << img.GetSerialId()); + Ctrl::stat_putimage++; + ImageSysDataMaker m; + LLOG("SysImage cache pixels " << cache.GetSize() << ", count " << cache.GetCount()); + m.img = img; + ImageSysData& sd = cache.Get(m); + if(Rect(img.GetSize()) == src) { + Point dp = p - pos; + if(abs(dp.x) < 256 && abs(dp.y) < 256) { + Ctrl::Put8(dp.x < 0 ? dp.y < 0 ? IMAGENN : IMAGENP : dp.y < 0 ? IMAGEPN : IMAGEPP); + Ctrl::Put8(abs(dp.x)); + Ctrl::Put8(abs(dp.y)); + Ctrl::Put16(sd.handle); + pos = p; + cache.Shrink(25000000, 5000); // Cache must be after Paint because of PaintOnly! + return; + } + } + Ctrl::Put8(IMAGE); + Ctrl::Put16(sd.handle); + Ctrl::Put(p); + Ctrl::Put(src); + pos = p; + cache.Shrink(25000000, 5000); // Cache must be after Paint because of PaintOnly! +} + +void SystemDraw::ResetI() +{ + cache.Clear(); + ImageSysData::free_handle.Clear(); + ImageSysData::handle_count = 0; +} + void SetSurface(SystemDraw& w, int x, int y, int cx, int cy, const RGBA *pixels) { GuiLock __; diff --git a/rainbow/Turtle/Output.cpp b/rainbow/Turtle/Output.cpp index c6c19afca..88ad3c4a9 100644 --- a/rainbow/Turtle/Output.cpp +++ b/rainbow/Turtle/Output.cpp @@ -50,9 +50,13 @@ void Ctrl::Output() { socket.Timeout(20000); if(turtle_stream.HasData()) { - websocket.SendBinary(ZCompress(String(SystemDraw::DISABLESENDING, 1))); // Do not send events until data transfered and processed + websocket.SendBinary(ZCompress(String(DISABLESENDING, 1))); // Do not send events until data transfered and processed int64 x = ++update_serial; - Put8(SystemDraw::UPDATESERIAL); + if(IsNull(serial_time0)) { + serial_time0 = msecs(); + serial_0 = update_serial; + } + Put8(UPDATESERIAL); Put32(LODWORD(x)); Put32(HIDWORD(x)); String s = turtle_stream.FlushStream(); @@ -81,7 +85,7 @@ void Ctrl::SyncCaret() cr = (RectC(focusCtrl->caretx, focusCtrl->carety, focusCtrl->caretcx, focusCtrl->caretcy) + focusCtrl->GetScreenView().TopLeft()) & focusCtrl->GetScreenView(); if(cr != fbCaretRect) { // TODO: SetCaret should perhaps be called on Ctrl::SetCaret - Put8(SystemDraw::SETCARET); + Put8(SETCARET); Put(cr); fbCaretRect = cr; } @@ -147,7 +151,7 @@ void Ctrl::DoPaint() prev_cursor_id = id; int64 q = fbCursorImage.GetAuxData(); if(q) { - Put8(SystemDraw::STD_CURSORIMAGE); + Put8(STD_CURSORIMAGE); Put8(clamp((int)q, 1, 16)); } else { @@ -156,10 +160,10 @@ void Ctrl::DoPaint() h << "url('data:image/png;base64," << Base64Encode(PNGEncoder().SaveString(fbCursorImage)) << "') " << p.x << ' ' << p.y << ", default"; - Put8(SystemDraw::SETCURSORIMAGE); + Put8(SETCURSORIMAGE); Put16(0); // _TODO_ Cursor cache Put(h); - Put8(SystemDraw::CURSORIMAGE); + Put8(CURSORIMAGE); Put16(0); // _TODO_ Cursor cache } } diff --git a/rainbow/Turtle/Server.cpp b/rainbow/Turtle/Server.cpp index 22100ff2d..78dae431f 100644 --- a/rainbow/Turtle/Server.cpp +++ b/rainbow/Turtle/Server.cpp @@ -23,7 +23,7 @@ void Ctrl::Broadcast(int signal) { #ifdef PLATFORM_POSIX if(getpid() == main_pid) for(int i = 0; i < pid.GetCount(); i++) - kill(pid[i], signal); + kill(pid[i], signal); #endif } diff --git a/rainbow/Turtle/Turtle.h b/rainbow/Turtle/Turtle.h index d8f7aded3..49798c4ee 100644 --- a/rainbow/Turtle/Turtle.h +++ b/rainbow/Turtle/Turtle.h @@ -32,46 +32,60 @@ public: TurtleStream() { Reset(); } }; +enum Command { + RECT = 0, + IMAGE = 1, + SETIMAGE = 2, + INVERTRECT = 3, + STD_CURSORIMAGE = 4, + SETCURSORIMAGE = 5, + CURSORIMAGE = 6, + DISABLESENDING = 7, + UPDATESERIAL = 8, + + IMAGEPP = 9, + IMAGENP = 10, + IMAGEPN = 11, + IMAGENN = 12, + + RECTPP = 13, + RECTNP = 14, + RECTPN = 15, + RECTNN = 16, + + SETCARET = 17, + + HORZDRAGLINE = 18, + VERTDRAGLINE = 19, +}; + + class SystemDraw : public SDraw { public: virtual void PutImage(Point p, const Image& img, const Rect& src); virtual void PutRect(const Rect& r, Color color); - -public: - enum Code { - RECT = 0, - IMAGE = 1, - SETIMAGE = 2, - INVERTRECT = 3, - STD_CURSORIMAGE = 4, - SETCURSORIMAGE = 5, - CURSORIMAGE = 6, - DISABLESENDING = 7, - UPDATESERIAL = 8, - - IMAGEPP = 9, - IMAGENP = 10, - IMAGEPN = 11, - IMAGENN = 12, - RECTPP = 13, - RECTNP = 14, - RECTPN = 15, - RECTNN = 16, +public: + struct ImageSysData { + Image img; + int handle; - SETCARET = 17, + static Vector free_handle; + static int handle_count; + + static int AllocImageHandle(); + static void FreeImageHandle(int handle); - HORZDRAGLINE = 18, - VERTDRAGLINE = 19, + void Init(const Image& img); + ~ImageSysData(); }; + - static Index img_index[3]; + static LRUCache cache; Point pos; - - int GetImageI(int from, Index& img_index, int maxcount, const Image& img); - int GetImageI(const Image& img); - static void ResetI() { for(int i = 0; i < 3; i++) img_index[i].Clear(); } + + static void ResetI(); bool CanSetSurface() { return false; } static void Flush() {} diff --git a/rainbow/Turtle/Turtle.html b/rainbow/Turtle/Turtle.html index 87c33512a..29f5583f1 100644 --- a/rainbow/Turtle/Turtle.html +++ b/rainbow/Turtle/Turtle.html @@ -173,6 +173,8 @@ function ProcessDraw(s) // Log("Painting started " + s.length); // window.document.title = "Processing draw"; + + var time0 = (new Date).getTime(); var p = new Object; p.data = s; @@ -299,7 +301,7 @@ function ProcessDraw(s) if(Char(p, 8)) { // UPDATESERIAL update_serial_l = Get32(p); update_serial_h = Get32(p); - ws.send("S " + update_serial_l + " " + update_serial_h + "\n"); + ws.send("S " + update_serial_l + " " + update_serial_h + " " + ((new Date).getTime() - time0) + "\n"); } else if(Char(p, 9)) // IMAGEPP @@ -477,7 +479,13 @@ window.onresize = ResizeCanvas; var timerID; -var ws = new WebSocket("%%host%%"); +function ConnectWebsocket() +{ + return new WebSocket("%%host%%"); +} + +var ws = ConnectWebsocket(); + ws.binaryType = "arraybuffer"; function ScheduleSend() @@ -507,7 +515,7 @@ function SendEvents() ws.onopen = function() { - Log("websocket connection opened"); +// Log("websocket connection opened"); ResizeCanvas(); }; diff --git a/rainbow/WebWord/WebWord.cpp b/rainbow/WebWord/WebWord.cpp index 7bdcaa01b..aa2da21fc 100644 --- a/rainbow/WebWord/WebWord.cpp +++ b/rainbow/WebWord/WebWord.cpp @@ -80,6 +80,8 @@ void UWord::ShowInfo() s << ", putimage " << Ctrl::stat_putimage; s << ", putrect " << Ctrl::stat_putrect; s << ", setimage " << Ctrl::stat_setimage << " len " << FormatSize(Ctrl::stat_setimage_len); + s << ", roundtrip " << Ctrl::stat_roundtrip_ms << " ms"; + s << ", client " << Ctrl::stat_client_ms << " ms"; sent_prev = Ctrl::stat_data_send; statusbar.Set(s); } @@ -319,8 +321,6 @@ CONSOLE_APP_MAIN SetLanguage(LNG_ENGLISH); SetDefaultCharset(CHARSET_UTF8); - PromptOK("Session started"); - UWordFs().Type("QTF files", "*.qtf") .AllFilesType() .DefaultExt("qtf");