graphics: Smaller scope for the lock

This commit is contained in:
Hajime Hoshi 2016-07-03 03:08:41 +09:00
parent 5826a958e1
commit 22655682fb

View File

@ -379,12 +379,12 @@ func NewImage(width, height int, filter Filter) (*Image, error) {
height: height, height: height,
filter: filter, filter: filter,
} }
imageM.Lock()
defer imageM.Unlock()
eimg, err := theImages.add(image) eimg, err := theImages.add(image)
if err != nil { if err != nil {
return nil, err return nil, err
} }
imageM.Lock()
defer imageM.Unlock()
image.image, err = graphics.NewImage(width, height, glFilter(ui.GLContext(), filter)) image.image, err = graphics.NewImage(width, height, glFilter(ui.GLContext(), filter))
if err != nil { if err != nil {
return nil, err return nil, err
@ -417,14 +417,14 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
for j := 0; j < h; j++ { for j := 0; j < h; j++ {
copy(pixels[j*w*4:(j+1)*w*4], rgbaImg.Pix[j*rgbaImg.Stride:]) copy(pixels[j*w*4:(j+1)*w*4], rgbaImg.Pix[j*rgbaImg.Stride:])
} }
imageM.Lock()
defer imageM.Unlock()
img := &imageImpl{ img := &imageImpl{
width: w, width: w,
height: h, height: h,
filter: filter, filter: filter,
pixels: pixels, pixels: pixels,
} }
imageM.Lock()
defer imageM.Unlock()
var err error var err error
img.image, err = graphics.NewImageFromImage(rgbaImg, glFilter(ui.GLContext(), filter)) img.image, err = graphics.NewImageFromImage(rgbaImg, glFilter(ui.GLContext(), filter))
if err != nil { if err != nil {