mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Smaller scope for the lock
This commit is contained in:
parent
5826a958e1
commit
22655682fb
8
image.go
8
image.go
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user