vdi-cloud/docs/evidence/kylin-mouse-20261104/inputecho-source.py

49 lines
2.8 KiB
Python

import gi,time,json,math
gi.require_version('Gtk','3.0')
from gi.repository import Gtk,Gdk,GLib
started=time.monotonic(); draws=0; ticks=0; marker=False
win=Gtk.Window(title='VDI Kylin quality benchmark')
win.connect('destroy',Gtk.main_quit)
area=Gtk.DrawingArea();win.add(area)
area.set_events(Gdk.EventMask.BUTTON_PRESS_MASK|Gdk.EventMask.KEY_PRESS_MASK)
area.set_can_focus(True)
def event(w,e):
global marker
if e.type==Gdk.EventType.KEY_PRESS and getattr(e,'keyval',None)==Gdk.KEY_F9:
marker=not marker; area.queue_draw_area(2180,80,220,140)
print(json.dumps({'event':e.type.value_nick,'keyval':getattr(e,'keyval',None),'button':getattr(e,'button',None),'x':getattr(e,'x',None),'y':getattr(e,'y',None),'width':area.get_allocated_width(),'height':area.get_allocated_height(),'t':time.monotonic()}),flush=True)
return False
win.connect('key-press-event',event);area.connect('button-press-event',event)
def draw(w,cr):
global draws
draws+=1; width=w.get_allocated_width();height=w.get_allocated_height()
cr.set_source_rgb(.96,.97,.99);cr.paint()
cr.set_source_rgb(*( (1,1,1) if marker else (0,0,0)));cr.rectangle(2180,80,220,140);cr.fill()
cr.select_font_face('sans');cr.set_font_size(30);cr.set_source_rgb(.08,.12,.18)
cr.move_to(60,65);cr.show_text('VDI Kylin - resolution / text / motion / input verification')
cr.set_font_size(22);cr.move_to(60,105);cr.show_text(f'Native desktop: {width} x {height} Temporary test window')
for row,size in enumerate([12,14,16,18,20,24]):
cr.set_font_size(size);cr.move_to(60,155+row*45);cr.set_source_rgb(.1,.1,.1)
cr.show_text(f'{size}px Cloud desktop 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz')
for i in range(600):
cr.set_source_rgb(0,0,0) if i%2 else cr.set_source_rgb(1,1,1)
cr.rectangle(60+i,445,1,80);cr.fill()
for i,color in enumerate([(1,0,0),(0,.65,0),(0,.2,1),(.6,0,.6)]):
cr.set_source_rgb(*color);cr.set_font_size(18);cr.move_to(60,565+i*28);cr.show_text('Color text 0123456789 - desktop quality test')
elapsed=time.monotonic()-started
for i in range(5):
x=70+((elapsed*220+i*173)%(max(200,width-400)))
cr.set_source_rgb(.1+i*.14,.35,.8-i*.1);cr.rectangle(x,height-280+i*35,120,28);cr.fill()
cr.set_source_rgb(.1,.15,.2);cr.set_font_size(16);cr.move_to(60,height-30)
cr.show_text(f'Source draw rate: {draws/max(.1,elapsed):.2f} FPS; elapsed {elapsed:.1f}s. Close after testing.')
return False
def tick():
global ticks
ticks+=1;area.queue_draw_area(0,max(0,area.get_allocated_height()-300),area.get_allocated_width(),300);return True
def report():
elapsed=time.monotonic()-started
print(json.dumps({'event':'source-stats','seconds':elapsed,'draws':draws,'ticks':ticks,'draw_fps':draws/elapsed}),flush=True);return True
area.connect('draw',draw);win.fullscreen();win.show_all();area.grab_focus()
GLib.timeout_add(16,tick);GLib.timeout_add_seconds(5,report)
print('READY',flush=True);Gtk.main()