orders

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: GPL-3.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package orders renders the drawing orders a server sends when the client says it supports them.

Orders are how RDP drew things before bitmap updates and EGFX. The server puts bitmaps into a cache with secondary orders and then blits them to the screen with MEMBLT, often with a couple of fills alongside. That is the whole model in practice: a session measured against Windows 10 consisted of 1770 MEMBLTs, 1000 cache fills and 62 alternate secondary orders, and nothing else.

Whether to advertise support is a trade: the server stops sending bitmap updates entirely, so a client that cannot render orders gets a blank screen rather than a slower one. See docs/windows-verification.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {

	// RFXMode is the entropy coder for RemoteFX cache entries. RemoteFX data
	// does not say which coder produced it, so this has to match what the
	// session negotiated. A cache keeps its own copy rather than reading
	// codec.RFXMode, since that global belongs to whichever session set it and
	// decoding garbage is worse than failing. Set it before the cache is used;
	// the default, RLGR1, is what codec.RFXMode defaults to and what every
	// server supports.
	RFXMode codec.RLGRMode
	// contains filtered or unexported fields
}

Cache holds the bitmaps the server stores with secondary orders and reads back with MEMBLT.

Entries are dropped rather than reused when the server overwrites a slot, which is what it does when its own cache fills up: the protocol has no eviction message for the client because the client is not expected to hand anything back.

func NewCache

func NewCache() *Cache

NewCache returns an empty cache.

func (*Cache) Get

func (c *Cache) Get(cacheID uint32, index uint32) *Entry

Get returns a cache entry, or nil if the slot is empty. The caller must not modify the pixels.

func (*Cache) Len

func (c *Cache) Len() int

Len is the number of entries held, for tests and diagnostics.

func (*Cache) Put

func (c *Cache) Put(cb *pdu.CacheBitmap)

Put stores a bitmap from a cache order. Entries the server says not to keep are still stored, because a MEMBLT usually follows immediately and expects to find them; they are simply not relied upon to last.

The order's own pixels are in the bitmap's pixel format and are converted to BGRA here, so that blitting is a copy.

func (*Cache) Reset

func (c *Cache) Reset()

Reset empties the cache. A reset graphics or a new connection invalidates everything in it.

type Entry

type Entry struct {
	// Width and Height are the entry's size in pixels.
	Width  int
	Height int
	// Pixels are BGRA, top down.
	Pixels []byte
}

Entry is one bitmap in the cache, already decoded to BGRA.

type GlyphCache added in v0.5.0

type GlyphCache struct {
	// contains filtered or unexported fields
}

GlyphCache holds the monochrome glyphs a server has cached and the glyph fragments it has stored while drawing them.

A fragment is a run of glyph indices and their advances, stored by an ADD and replayed by a USE so a repeated string does not put every glyph in the cache again. Fragments and glyphs are indexed separately, which is why there are two lookups.

func NewGlyphCache added in v0.5.0

func NewGlyphCache() *GlyphCache

NewGlyphCache returns an empty glyph cache.

func (*GlyphCache) Fragment added in v0.5.0

func (c *GlyphCache) Fragment(index uint32) []byte

Fragment returns a stored glyph fragment, or nil. The caller must not modify it.

func (*GlyphCache) Glyph added in v0.5.0

func (c *GlyphCache) Glyph(cacheID, index uint32) *pdu.Glyph

Glyph returns a cached glyph, or nil if the slot is empty. The caller must not modify it.

func (*GlyphCache) Len added in v0.5.0

func (c *GlyphCache) Len() int

Len is the number of glyphs held, for tests and diagnostics.

func (*GlyphCache) Put added in v0.5.0

func (c *GlyphCache) Put(order *pdu.GlyphCacheOrder)

Put stores the glyphs of a Cache Glyph secondary order. A slot the server fills again is replaced, which is all the protocol offers: there is no eviction message for the client.

func (*GlyphCache) Reset added in v0.5.0

func (c *GlyphCache) Reset()

Reset empties the cache. A new connection, or a reset graphics, invalidates everything in it.

type Screen

type Screen struct {

	// Cache holds the bitmaps the server blits from. Without it MEMBLT has
	// nothing to read.
	Cache *Cache

	// Glyphs holds the glyph cache the TEXT2 order draws from. The server fills
	// it with cache glyph orders before it sends any text.
	Glyphs *GlyphCache
	// contains filtered or unexported fields
}

Screen is a framebuffer that renders drawing orders. It holds BGRA pixels, top down, like the surfaces EGFX uses.

func NewScreen

func NewScreen(width, height int) *Screen

NewScreen returns a black screen of the given size.

func (*Screen) Blit added in v0.7.0

func (s *Screen) Blit(src []byte, srcW, srcH, srcPP int, dst image.Rectangle) image.Rectangle

Blit copies a decoded bitmap into the screen at dst, converting the source pixels to the screen's BGRA, and returns the area that changed, clipped to the screen. An empty result means nothing landed.

This is the bitmap update path's way in. Drawing orders do not come through here: they read the screen and the caches directly.

srcPP is the source bytes per pixel, which is what client.Bpp returns: one, two, three or four. Three and four byte pixels are BGR and BGRA. Two byte pixels are RGB565 read most significant byte first, which is the byte order the RLE decoder emits them in (core/rle.go decompress2 finishes with PutUint16BE), and not the little endian order of a DIB. One byte pixels are palette indices, and the palette is not tracked here, so they are counted as unsupported rather than drawn in whatever colour the index happens to be: a wrong picture that looks plausible is worse than a missing one.

func (*Screen) Buffer added in v0.7.0

func (s *Screen) Buffer() []byte

Buffer returns the screen pixels themselves, as BGRA, top down, with a stride of four bytes per pixel and no padding. Unlike Pixels this does not copy, so it is the one to use for handing a frame to an encoder; the slice stays valid until the next Draw, Blit or Resize, and reading it while another goroutine draws is a data race.

func (*Screen) Draw

func (s *Screen) Draw(pdus []pdu.OrderPdu) (image.Rectangle, error)

Draw renders a batch of orders and returns the area they changed, which is empty when nothing was drawn. The returned error is for a batch that could not be applied at all; orders that are merely unsupported are counted instead, since the rest of the batch is still worth drawing.

func (*Screen) DrawMulti added in v0.5.0

func (s *Screen) DrawMulti(o *pdu.OrderPdu, clip image.Rectangle) image.Rectangle

DrawMulti draws the primary orders that carry a list of rectangles, and MEM3BLT. It is the single entry point the batch dispatch calls for them.

The four multi-rectangle orders are MULTI_DSTBLT, MULTI_PATBLT, MULTI_SCRBLT and MULTI_OPAQUE_RECT. Each is the matching single-rectangle order repeated over its rectangle list, so each is drawn here by filling in that order's value and calling the renderer that already exists for it. That is what reuses the raster operation handling, the clipping and the fill and blit helpers, instead of a second copy of them.

FreeRDP renders only MultiOpaqueRect of the four: its GDI client leaves the other three unset, so there is no reference drawing to copy for them. Drawing each rectangle on its own is the reading their fields support, and the bounds the order carries still clip the whole lot.

MEM3BLT is a MEMBLT against a third colour table that also carries a raster operation, so it copies only when the operation is SRCCOPY.

The batch dispatch calls this once per order from Screen.drawOne, where the screen lock is already held and the clip rectangle is known, so it must not be called concurrently with other drawing.

func (*Screen) DrawText2 added in v0.5.0

func (s *Screen) DrawText2(d *pdu.GlyphIndex, glyphs *GlyphCache, clip image.Rectangle) image.Rectangle

DrawText2 draws a TEXT2 (GlyphIndex) order out of a glyph cache.

The pen starts at the order's X and Y, each glyph is placed where the pen is plus the glyph's own origin, and the pen then advances by whatever the order says. The order's data is a packed run, per FreeRDP's update_process_glyph_fragments: a glyph cache index, a GLYPH_FRAGMENT_USE with a fragment cache index, or a GLYPH_FRAGMENT_ADD with an index and a size. When the font is not fixed pitch an advance byte follows a glyph index or a USE, and the bytes a USE names are replayed as the same kind of run.

It must be called with the screen lock held, which is how Screen.Draw calls it from the dispatch.

func (*Screen) Pixels

func (s *Screen) Pixels() []byte

Pixels returns a copy of the screen as BGRA, top down.

func (*Screen) Resize

func (s *Screen) Resize(width, height int)

Resize discards the contents and changes the size. Servers send a fresh set of orders after a resize, so there is nothing worth keeping.

func (*Screen) Size

func (s *Screen) Size() (int, int)

Size returns the screen size.

func (*Screen) Unsupported

func (s *Screen) Unsupported() map[string]int

Unsupported reports how many orders were recognised but not drawn, by kind. A stream of MEMBLTs with an unhandled ROP shows up here rather than as a silently wrong screen.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL