graphics: Add Image.noSave

This commit is contained in:
Hajime Hoshi 2016-07-03 01:08:47 +09:00
parent fb8b6e93e5
commit 0519c69c13
2 changed files with 15 additions and 13 deletions

View File

@ -48,6 +48,8 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale flo
if err != nil { if err != nil {
return err return err
} }
offscreen.impl.noSave = true
intScreenScale := int(math.Ceil(screenScale)) intScreenScale := int(math.Ceil(screenScale))
w := screenWidth * intScreenScale w := screenWidth * intScreenScale
h := screenHeight * intScreenScale h := screenHeight * intScreenScale
@ -55,13 +57,17 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale flo
if err != nil { if err != nil {
return err return err
} }
offscreen2.impl.noSave = true
w = int(float64(screenWidth) * screenScale) w = int(float64(screenWidth) * screenScale)
h = int(float64(screenHeight) * screenScale) h = int(float64(screenHeight) * screenScale)
c.screen, err = newImageWithScreenFramebuffer(w, h) c.screen, err = newImageWithScreenFramebuffer(w, h)
if err != nil { if err != nil {
return err return err
} }
c.screen.impl.noSave = true
c.screen.Clear() c.screen.Clear()
c.offscreen = offscreen c.offscreen = offscreen
c.offscreen2 = offscreen2 c.offscreen2 = offscreen2
c.screenScale = screenScale c.screenScale = screenScale
@ -148,12 +154,7 @@ func (c *graphicsContext) UpdateAndDraw() error {
if err := c.drawToDefaultRenderTarget(); err != nil { if err := c.drawToDefaultRenderTarget(); err != nil {
return err return err
} }
exceptions := map[*imageImpl]struct{}{ if err := theImages.savePixels(ui.GLContext()); err != nil {
c.offscreen.impl: {},
c.offscreen2.impl: {},
c.screen.impl: {},
}
if err := theImages.savePixels(ui.GLContext(), exceptions); err != nil {
return err return err
} }
return nil return nil

View File

@ -57,16 +57,10 @@ func (i *images) remove(img *Image) {
delete(i.images, img.impl) delete(i.images, img.impl)
} }
func (i *images) savePixels(context *opengl.Context, exceptions map[*imageImpl]struct{}) error { func (i *images) savePixels(context *opengl.Context) error {
i.m.Lock() i.m.Lock()
defer i.m.Unlock() defer i.m.Unlock()
for img := range i.images { for img := range i.images {
if _, ok := exceptions[img]; ok {
continue
}
if img.isDisposed() {
continue
}
if err := img.savePixels(context); err != nil { if err := img.savePixels(context); err != nil {
return err return err
} }
@ -200,6 +194,7 @@ type imageImpl struct {
height int height int
filter Filter filter Filter
pixels []uint8 pixels []uint8
noSave bool
} }
func (i *imageImpl) Fill(clr color.Color) error { func (i *imageImpl) Fill(clr color.Color) error {
@ -275,6 +270,12 @@ func (i *imageImpl) At(x, y int) color.Color {
} }
func (i *imageImpl) savePixels(context *opengl.Context) error { func (i *imageImpl) savePixels(context *opengl.Context) error {
if i.noSave {
return nil
}
if i.disposed {
return nil
}
if i.pixels != nil { if i.pixels != nil {
return nil return nil
} }