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