in main.go [745:811]
func (b *sessionInfo) populateInfoPyDict(updateN map[string][]*vncclient.FramebufferUpdateMessage) bool {
C.PyDict_Clear(b.infoPyDict)
for name, update := range updateN {
dict := C.PyDict_New()
// Put the new dictionary into the info dict we're returning
ok := C.PyDict_SetItemString(b.infoPyDict, b.names[name], dict)
C.go_vncdriver_decref(dict)
if ok != C.int(0) {
return false
}
// Retain our reference!
// C.go_vncdriver_incref(vncUpdatesN)
updatePy := C.PyLong_FromLong(C.long(len(update)))
ok = C.PyDict_SetItem(dict, vncUpdatesN, updatePy)
C.go_vncdriver_decref(updatePy)
if ok != C.int(0) {
return false
}
// Count up number of pixels changed
pixels := 0
rectangles := 0
bytes := 0 // TODO: should we just compute this from the byte stream directly?
for _, updateI := range update {
for _, rect := range updateI.Rectangles {
pixels += int(rect.Width) * int(rect.Height)
rectangles++
// Each rectangle consists of X, Y,
// Width, Height (each 2 bytes) and an
// encoding.
//
// Technically, we should consider
// including other control messages in
// bytes, but this is ok for now.
bytes += rect.Enc.Size() + 8
}
}
// C.go_vncdriver_incref(vncUpdatesPixels)
pixelsPy := C.PyLong_FromLong(C.long(pixels))
ok = C.PyDict_SetItem(dict, vncUpdatesPixels, pixelsPy)
C.go_vncdriver_decref(pixelsPy)
if ok != C.int(0) {
return false
}
// C.go_vncdriver_incref(vncUpdatesRectangles)
rectsPy := C.PyLong_FromLong(C.long(rectangles))
ok = C.PyDict_SetItem(dict, vncUpdatesRectangles, rectsPy)
C.go_vncdriver_decref(rectsPy)
if ok != C.int(0) {
return false
}
// C.go_vncdriver_incref(vncUpdatesBytes)
bytesPy := C.PyLong_FromLong(C.long(bytes))
ok = C.PyDict_SetItem(dict, vncUpdatesBytes, bytesPy)
C.go_vncdriver_decref(bytesPy)
if ok != C.int(0) {
return false
}
}
return true
}