mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
pixels: Remove image member
This commit is contained in:
parent
3bc2239a3b
commit
9b6b5372ef
13
imageimpl.go
13
imageimpl.go
@ -34,7 +34,7 @@ type imageImpl struct {
|
||||
width int
|
||||
height int
|
||||
filter Filter
|
||||
pixels *pixels.Pixels
|
||||
pixels pixels.Pixels
|
||||
volatile bool
|
||||
screen bool
|
||||
m sync.Mutex
|
||||
@ -51,7 +51,6 @@ func newImageImpl(width, height int, filter Filter, volatile bool) (*imageImpl,
|
||||
height: height,
|
||||
filter: filter,
|
||||
volatile: volatile,
|
||||
pixels: pixels.NewPixels(img),
|
||||
}
|
||||
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
||||
return i, nil
|
||||
@ -83,7 +82,6 @@ func newImageImplFromImage(source image.Image, filter Filter) (*imageImpl, error
|
||||
width: w,
|
||||
height: h,
|
||||
filter: filter,
|
||||
pixels: pixels.NewPixels(img),
|
||||
}
|
||||
i.pixels.ReplacePixels(p)
|
||||
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
||||
@ -101,7 +99,6 @@ func newScreenImageImpl(width, height int) (*imageImpl, error) {
|
||||
height: height,
|
||||
volatile: true,
|
||||
screen: true,
|
||||
pixels: pixels.NewPixels(img),
|
||||
}
|
||||
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
||||
return i, nil
|
||||
@ -181,7 +178,7 @@ func (i *imageImpl) At(x, y int, context *opengl.Context) color.Color {
|
||||
return color.Transparent
|
||||
}
|
||||
idx := 4*x + 4*y*i.width
|
||||
clr, err := i.pixels.At(idx, context)
|
||||
clr, err := i.pixels.At(idx, i.image, context)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -197,7 +194,7 @@ func (i *imageImpl) ensurePixels(context *opengl.Context) error {
|
||||
if i.volatile {
|
||||
return nil
|
||||
}
|
||||
if err := i.pixels.ReadPixelsFromVRAMIfStale(context); err != nil {
|
||||
if err := i.pixels.ReadPixelsFromVRAMIfStale(i.image, context); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -225,7 +222,7 @@ func (i *imageImpl) resetPixelsIfDependingOn(target *imageImpl, context *opengl.
|
||||
i.pixels.MakeStale()
|
||||
return nil
|
||||
}
|
||||
if err := i.pixels.ReadPixelsFromVRAM(context); err != nil {
|
||||
if err := i.pixels.ReadPixelsFromVRAM(i.image, context); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -282,7 +279,7 @@ func (i *imageImpl) Dispose() error {
|
||||
}
|
||||
i.image = nil
|
||||
i.disposed = true
|
||||
i.pixels = nil
|
||||
i.pixels.Clear()
|
||||
runtime.SetFinalizer(i, nil)
|
||||
return nil
|
||||
}
|
||||
|
@ -33,8 +33,6 @@ type drawImageHistoryItem struct {
|
||||
|
||||
// Pixels represents pixels of an image for restoring when GL context is lost.
|
||||
type Pixels struct {
|
||||
image *graphics.Image
|
||||
|
||||
// basePixels and baseColor are exclusive.
|
||||
basePixels []uint8
|
||||
baseColor color.Color
|
||||
@ -42,12 +40,6 @@ type Pixels struct {
|
||||
stale bool
|
||||
}
|
||||
|
||||
func NewPixels(image *graphics.Image) *Pixels {
|
||||
return &Pixels{
|
||||
image: image,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Pixels) MakeStale() {
|
||||
p.basePixels = nil
|
||||
p.baseColor = nil
|
||||
@ -97,9 +89,9 @@ func (p *Pixels) AppendDrawImageHistory(image *graphics.Image, vertices []int16,
|
||||
//
|
||||
// Note that this must not be called until context is available.
|
||||
// This means Pixels members must match with acutal state in VRAM.
|
||||
func (p *Pixels) At(idx int, context *opengl.Context) (color.Color, error) {
|
||||
func (p *Pixels) At(idx int, image *graphics.Image, context *opengl.Context) (color.Color, error) {
|
||||
if p.basePixels == nil || p.drawImageHistory != nil || p.stale {
|
||||
if err := p.ReadPixelsFromVRAM(context); err != nil {
|
||||
if err := p.ReadPixelsFromVRAM(image, context); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@ -119,9 +111,9 @@ func (p *Pixels) DependsOn(target *graphics.Image) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *Pixels) ReadPixelsFromVRAM(context *opengl.Context) error {
|
||||
func (p *Pixels) ReadPixelsFromVRAM(image *graphics.Image, context *opengl.Context) error {
|
||||
var err error
|
||||
p.basePixels, err = p.image.Pixels(context)
|
||||
p.basePixels, err = image.Pixels(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -131,11 +123,11 @@ func (p *Pixels) ReadPixelsFromVRAM(context *opengl.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Pixels) ReadPixelsFromVRAMIfStale(context *opengl.Context) error {
|
||||
func (p *Pixels) ReadPixelsFromVRAMIfStale(image *graphics.Image, context *opengl.Context) error {
|
||||
if !p.stale {
|
||||
return nil
|
||||
}
|
||||
return p.ReadPixelsFromVRAM(context)
|
||||
return p.ReadPixelsFromVRAM(image, context)
|
||||
}
|
||||
|
||||
func (p *Pixels) HasDependency() bool {
|
||||
@ -177,7 +169,6 @@ func (p *Pixels) CreateImage(context *opengl.Context, width, height int, filter
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
p.image = gimg
|
||||
p.basePixels, err = gimg.Pixels(context)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user