From 1b944c8e65563c0adb4d5685d13d5438d6b5376e Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 13 Jun 2020 11:46:20 +0200 Subject: [PATCH] app/internal/d3d11: tolerate padded row pitches from D3DDeviceContext::Map Fixes gio#136 (I think) Signed-off-by: Elias Naur --- app/internal/d3d11/backend_windows.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/internal/d3d11/backend_windows.go b/app/internal/d3d11/backend_windows.go index c35a6252..48ff1752 100644 --- a/app/internal/d3d11/backend_windows.go +++ b/app/internal/d3d11/backend_windows.go @@ -777,13 +777,15 @@ func (f *Framebuffer) ReadPixels(src image.Rectangle, pixels []byte) error { return fmt.Errorf("ReadPixels: %v", err) } defer f.dev.ctx.Unmap(res, 0) - pitch := w * 4 - if int(resMap.RowPitch) != pitch { - return fmt.Errorf("ReadPixels: got row pitch %d, expected %d", resMap.RowPitch, pitch) + srcPitch := w * 4 + dstPitch := int(resMap.RowPitch) + mapSize := dstPitch * h + data := gunsafe.SliceOf(resMap.pData)[:mapSize:mapSize] + width := w * 4 + for r := 0; r < h; r++ { + pixels := pixels[r*srcPitch:] + copy(pixels[:width], data[r*dstPitch:]) } - n := pitch * h - data := gunsafe.SliceOf(resMap.pData)[:n:n] - copy(pixels, data) return nil }