app/internal/d3d11: tolerate padded row pitches from D3DDeviceContext::Map

Fixes gio#136 (I think)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-06-13 11:46:20 +02:00
parent 2dc19a3695
commit 1b944c8e65
+8 -6
View File
@@ -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
}