250 likes | 407 Views
X. Ricardo A. Baratto NCL. Overview. System overview X protocol X server Architecture Porting process XFree86 (device drivers). System Overview. History Created in 1984 in MIT. X11 released on 1987 (latest R6.6 - April 2001) The system X clients (Xlib) X protocol X server.
E N D
X Ricardo A. Baratto NCL
Overview • System overview • X protocol • X server • Architecture • Porting process • XFree86 (device drivers)
System Overview • History • Created in 1984 in MIT. • X11 released on 1987 (latest R6.6 - April 2001) • The system • X clients (Xlib) • X protocol • X server
System Overview (cont...) • Features • Event Driven • Network Transparent • Device Independent • Policy Independent • Extensible
X Protocol • Communication Client – Server • Object based • Asynchronous • Types of Messages: • Request (Client -> Server) • Reply • Event (Server -> Client) • Error
X Server • Does • Process Output • Process Input • Extension Mechanism • Doesn’t • Define User Interface (X Toolkits) • Window Management (WM) • Each client responsible for its windows (Backing store) • Interpret input (Input Methods – Input Server)
X Server (cont…) • Manages a Display • Screens (physical monitor) • Input Devices • Everything is a window • Cheap, unlimited • Tree structure • Root window: Complete screen • Top-level windows: main app window • Parent window clips children
X Server Architecture • Layered • DIX: Device Independent • DDX: Device Dependent • Extensions • Everything controlled through resources • Screens, GCs, windows, pixmaps, regions, colormaps, fonts, cursors • Created on demand • Used by clients to request operations -> Use ID
Dispatch Loop • Heart of X server processing (DIX) • Process client requests • Send input events • Looks like: for(;;) nready = WaitForSomething(…); while(nready--) while(!isItTimeToYield) if(!ReadRequestFromClient(…)) break; (execute request);
Dispatch Loop (cont…) • Requests serviced round-robin • Execs up to 10 requests from every client • Problems • Busy client can monopolize server • select() not called often enough • Busy clients are not managed efficiently • select() called too often
Dispatch Loop (cont…) • Fix: XFree86 smart scheduler • Use time metric, not request-count metric • Dedicate time slice to each client • Gather many clients on every iteration • Poll, don’t block • Delay yielding • Give clients a second chance • Prioritize clients • Penalize busy, praise user preferred
Screens • One for each physical screen • ScreenRec structure • Defines functions used to handle operations on resources • Main communication channel DIX-DDX
Drawables • Where drawing takes place • Windows • Used for display output • May have own colormap • Pixmaps • Off-screen – own depth • Used to speed up operations
Graphic Contexts • Describe how to draw • Colors (fg, bg), fonts, line width, … • Normally set up once, used by many • Stored in server • Requests specify GC, drawable and what to draw
Porting X Server • Code layers • DIX -> Dev.Independent, don’t touch • OS -> OS specific • DDX -> Graphics Device specific • Extensions -> Add features • Porting Layer: OS + DDX • Porting process: • Define functions required by DIX to handle resources
OS Layer • Maintain client connections • Schedule work to be done for clients • Ignore/AttendClient() • File and memory management • Fonts stored in files • Xalloc()/Xrealloc()/Xfree()
WaitForSomething() • Input events from user or hardware • SetInputCheck() • Requests pending from existing clients • ReadRequestFromClient() • New client • Access control -> ClientAuthorized() • Create it -> NextAvailableClient()
DDX Layer • Input Processing • Mouse movement • Key presses • Key mappings • Graphics Display
Graphics Output • Pixel based • Screen basic data structure • Manage all resources • Output done on drawables • Pixel data format defined by DDX • Pixmap format constant across screens • XYPixmap -> one bitmap for each plane • Zpixmap -> series of pixel values • Pixel values interpreted at display time
Output Initialization • InitOutput() • Process arguments • Discover screens • AddScreen() • Initialize pixmap formats • Additional implementation dependent stuff
DDX Drawables • Fields • Serial number, depth, size and position • Procedures to manipulate them • Private DDX data • Pixmaps • Rectangular array of pixel values • Reference counted • Bitmaps are depth-1
DDX Drawables (cont…) • Windows • Visible rectangle on screen • Border drawn by DDX • Create, move, resize • Contents drawn by client • Expose Events • Server may provide backing store • Bit gravity (resizing) • Clipped by parent and sibbling windows
DDX 2D Graphics • Procedures for drawing primitives • Lines, arcs, arc filling, text drawing • Clients may allow DDX optimizations e.g. Zero-width lines • GC defines how to draw primitives • May use MI functions • Need only define basic Pixblit routines • Read/write pixel values & deal with image data
XFree86 Device Drivers • Life’s easier • Another abstraction layer • Most previous procedures already defined • Drivers are loadable modules • Need not distribute/recompile whole server • Module format X specific • OS/Architecture independent • Additional formats supported (dlopen())
Device Drivers (cont…) • Define only device specific routines • Discovery of devices (PCI/ISA access) • Device Initialization • Device Drivers have access to ScreenRec • Can redefine resource procedures • Optimize for display hardware • Sample VGA device driver • Provides basic functionality usable by others • Interface still unstable