diff options
Diffstat (limited to 'nexgb/xf86vidmode/xf86vidmode.go')
-rw-r--r-- | nexgb/xf86vidmode/xf86vidmode.go | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/nexgb/xf86vidmode/xf86vidmode.go b/nexgb/xf86vidmode/xf86vidmode.go index 8abb44e..5b0f1f8 100644 --- a/nexgb/xf86vidmode/xf86vidmode.go +++ b/nexgb/xf86vidmode/xf86vidmode.go @@ -408,7 +408,7 @@ func (v ModeInfo) Bytes() []byte { xgb.Put32(buf[b:], v.Privsize) b += 4 - return buf + return buf[:b] } // ModeInfoListBytes writes a list of ModeInfo values to a byte slice. @@ -676,7 +676,7 @@ func addModeLineRequest(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay b += 12 // padding copy(buf[b:], Private[:Privsize]) - b += xgb.Pad(int(Privsize)) + b += int(Privsize) return buf } @@ -774,7 +774,7 @@ func deleteModeLineRequest(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdispl b += 4 copy(buf[b:], Private[:Privsize]) - b += xgb.Pad(int(Privsize)) + b += int(Privsize) return buf } @@ -956,7 +956,6 @@ func getDotClocksReply(buf []byte) *GetDotClocksReply { v.Clock[i] = xgb.Get32(buf[b:]) b += 4 } - b = xgb.Pad(b) return v } @@ -1120,9 +1119,11 @@ type GetGammaRampReply struct { // padding: 1 bytes Size uint16 // padding: 22 bytes - Red []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) + Red []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) + // alignment gap to multiple of 2 Green []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) - Blue []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) + // alignment gap to multiple of 2 + Blue []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) } // Reply blocks and returns the reply data for a GetGammaRamp request. @@ -1160,21 +1161,22 @@ func getGammaRampReply(buf []byte) *GetGammaRampReply { v.Red[i] = xgb.Get16(buf[b:]) b += 2 } - b = xgb.Pad(b) + + b = (b + 1) & ^1 // alignment gap v.Green = make([]uint16, ((int(v.Size) + 1) & -2)) for i := 0; i < int(((int(v.Size) + 1) & -2)); i++ { v.Green[i] = xgb.Get16(buf[b:]) b += 2 } - b = xgb.Pad(b) + + b = (b + 1) & ^1 // alignment gap v.Blue = make([]uint16, ((int(v.Size) + 1) & -2)) for i := 0; i < int(((int(v.Size) + 1) & -2)); i++ { v.Blue[i] = xgb.Get16(buf[b:]) b += 2 } - b = xgb.Pad(b) return v } @@ -1413,7 +1415,7 @@ func getModeLineReply(buf []byte) *GetModeLineReply { v.Private = make([]byte, v.Privsize) copy(v.Private[:v.Privsize], buf[b:]) - b += xgb.Pad(int(v.Privsize)) + b += int(v.Privsize) return v } @@ -1479,7 +1481,8 @@ type GetMonitorReply struct { NumHsync byte NumVsync byte // padding: 20 bytes - Hsync []Syncrange // size: xgb.Pad((int(NumHsync) * 4)) + Hsync []Syncrange // size: xgb.Pad((int(NumHsync) * 4)) + // alignment gap to multiple of 4 Vsync []Syncrange // size: xgb.Pad((int(NumVsync) * 4)) Vendor string // size: xgb.Pad((int(VendorLength) * 1)) AlignmentPad []byte // size: xgb.Pad(((((int(VendorLength) + 3) & -4) - int(VendorLength)) * 1)) @@ -1530,14 +1533,14 @@ func getMonitorReply(buf []byte) *GetMonitorReply { v.Hsync[i] = Syncrange(xgb.Get32(buf[b:])) b += 4 } - b = xgb.Pad(b) + + b = (b + 3) & ^3 // alignment gap v.Vsync = make([]Syncrange, v.NumVsync) for i := 0; i < int(v.NumVsync); i++ { v.Vsync[i] = Syncrange(xgb.Get32(buf[b:])) b += 4 } - b = xgb.Pad(b) { byteString := make([]byte, v.VendorLength) @@ -1548,7 +1551,7 @@ func getMonitorReply(buf []byte) *GetMonitorReply { v.AlignmentPad = make([]byte, (((int(v.VendorLength) + 3) & -4) - int(v.VendorLength))) copy(v.AlignmentPad[:(((int(v.VendorLength)+3)&-4)-int(v.VendorLength))], buf[b:]) - b += xgb.Pad(int((((int(v.VendorLength) + 3) & -4) - int(v.VendorLength)))) + b += int((((int(v.VendorLength) + 3) & -4) - int(v.VendorLength))) { byteString := make([]byte, v.ModelLength) @@ -1922,7 +1925,7 @@ func modModeLineRequest(c *xgb.Conn, Screen uint32, Hdisplay uint16, Hsyncstart b += 4 copy(buf[b:], Private[:Privsize]) - b += xgb.Pad(int(Privsize)) + b += int(Privsize) return buf } @@ -2178,7 +2181,7 @@ func (cook SetGammaRampCookie) Check() error { // Write request to wire for SetGammaRamp // setGammaRampRequest writes a SetGammaRamp request to a byte slice. func setGammaRampRequest(c *xgb.Conn, Screen uint16, Size uint16, Red []uint16, Green []uint16, Blue []uint16) []byte { - size := xgb.Pad((((8 + xgb.Pad((((int(Size) + 1) & -2) * 2))) + xgb.Pad((((int(Size) + 1) & -2) * 2))) + xgb.Pad((((int(Size) + 1) & -2) * 2)))) + size := xgb.Pad((((((8 + xgb.Pad((((int(Size) + 1) & -2) * 2))) + 2) + xgb.Pad((((int(Size) + 1) & -2) * 2))) + 2) + xgb.Pad((((int(Size) + 1) & -2) * 2)))) b := 0 buf := make([]byte, size) @@ -2188,7 +2191,7 @@ func setGammaRampRequest(c *xgb.Conn, Screen uint16, Size uint16, Red []uint16, buf[b] = 18 // request opcode b += 1 - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + blen := b b += 2 xgb.Put16(buf[b:], Screen) @@ -2201,21 +2204,24 @@ func setGammaRampRequest(c *xgb.Conn, Screen uint16, Size uint16, Red []uint16, xgb.Put16(buf[b:], Red[i]) b += 2 } - b = xgb.Pad(b) + + b = (b + 1) & ^1 // alignment gap for i := 0; i < int(((int(Size) + 1) & -2)); i++ { xgb.Put16(buf[b:], Green[i]) b += 2 } - b = xgb.Pad(b) + + b = (b + 1) & ^1 // alignment gap for i := 0; i < int(((int(Size) + 1) & -2)); i++ { xgb.Put16(buf[b:], Blue[i]) b += 2 } - b = xgb.Pad(b) - return buf + b = xgb.Pad(b) + xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units + return buf[:b] } // SetViewPortCookie is a cookie used only for SetViewPort requests. @@ -2432,7 +2438,7 @@ func switchToModeRequest(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay b += 4 copy(buf[b:], Private[:Privsize]) - b += xgb.Pad(int(Privsize)) + b += int(Privsize) return buf } @@ -2566,7 +2572,7 @@ func validateModeLineRequest(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdis b += 4 copy(buf[b:], Private[:Privsize]) - b += xgb.Pad(int(Privsize)) + b += int(Privsize) return buf } |