buffer.go (1220B)
1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package gldriver 6 7 import "image" 8 9 type bufferImpl struct { 10 // buf should always be equal to (i.e. the same ptr, len, cap as) rgba.Pix. 11 // It is a separate, redundant field in order to detect modifications to 12 // the rgba field that are invalid as per the screen.Buffer documentation. 13 buf []byte 14 rgba image.RGBA 15 size image.Point 16 } 17 18 func (b *bufferImpl) Release() {} 19 func (b *bufferImpl) Size() image.Point { return b.size } 20 func (b *bufferImpl) Bounds() image.Rectangle { return image.Rectangle{Max: b.size} } 21 func (b *bufferImpl) RGBA() *image.RGBA { return &b.rgba } 22 23 func (b *bufferImpl) preUpload() { 24 // Check that the program hasn't tried to modify the rgba field via the 25 // pointer returned by the bufferImpl.RGBA method. This check doesn't catch 26 // 100% of all cases; it simply tries to detect some invalid uses of a 27 // screen.Buffer such as: 28 // *buffer.RGBA() = anotherImageRGBA 29 if len(b.buf) != 0 && len(b.rgba.Pix) != 0 && &b.buf[0] != &b.rgba.Pix[0] { 30 panic("gldriver: invalid Buffer.RGBA modification") 31 } 32 }