graphics: Add (*mipmap).original()

This commit is contained in:
Hajime Hoshi 2018-10-25 02:11:54 +09:00
parent 15cad6ed9a
commit ce60f44490
2 changed files with 12 additions and 8 deletions

View File

@ -152,7 +152,7 @@ func (c *graphicsContext) needsRestoring() (bool, error) {
if web.IsBrowser() { if web.IsBrowser() {
return c.invalidated, nil return c.invalidated, nil
} }
return c.offscreen.mipmap.level(0).IsInvalidated() return c.offscreen.mipmap.original().IsInvalidated()
} }
func (c *graphicsContext) restoreIfNeeded() error { func (c *graphicsContext) restoreIfNeeded() error {

View File

@ -45,6 +45,10 @@ func newMipmap(s *shareable.Image) *mipmap {
} }
} }
func (m *mipmap) original() *shareable.Image {
return m.imgs[0]
}
func (m *mipmap) level(i int) *shareable.Image { func (m *mipmap) level(i int) *shareable.Image {
w, h := m.imgs[len(m.imgs) - 1].Size() w, h := m.imgs[len(m.imgs) - 1].Size()
for len(m.imgs) < i+1 { for len(m.imgs) < i+1 {
@ -117,7 +121,7 @@ func (i *Image) copyCheck() {
// Size returns the size of the image. // Size returns the size of the image.
func (i *Image) Size() (width, height int) { func (i *Image) Size() (width, height int) {
return i.mipmap.level(0).Size() return i.mipmap.original().Size()
} }
func (i *Image) isDisposed() bool { func (i *Image) isDisposed() bool {
@ -155,7 +159,7 @@ func (i *Image) Fill(clr color.Color) error {
func (i *Image) fill(r, g, b, a uint8) { func (i *Image) fill(r, g, b, a uint8) {
if r == 0 && g == 0 && b == 0 && a == 0 { if r == 0 && g == 0 && b == 0 && a == 0 {
i.mipmap.level(0).ReplacePixels(nil) i.mipmap.original().ReplacePixels(nil)
i.disposeMipmaps() i.disposeMipmaps()
return return
} }
@ -363,7 +367,7 @@ func (i *Image) drawImage(img *Image, options *DrawImageOptions) {
if colorm.ScaleOnly() { if colorm.ScaleOnly() {
colorm = nil colorm = nil
} }
i.mipmap.level(0).DrawImage(src, vs, is, colorm, mode, filter) i.mipmap.original().DrawImage(src, vs, is, colorm, mode, filter)
} }
i.disposeMipmaps() i.disposeMipmaps()
} }
@ -439,11 +443,11 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
} }
vs := []float32{} vs := []float32{}
src := img.mipmap.level(0) src := img.mipmap.original()
for _, v := range vertices { for _, v := range vertices {
vs = append(vs, src.Vertex(float32(v.DstX), float32(v.DstY), v.SrcX, v.SrcY, v.ColorR, v.ColorG, v.ColorB, v.ColorA)...) vs = append(vs, src.Vertex(float32(v.DstX), float32(v.DstY), v.SrcX, v.SrcY, v.ColorR, v.ColorG, v.ColorB, v.ColorA)...)
} }
i.mipmap.level(0).DrawImage(img.mipmap.level(0), vs, indices, options.ColorM.impl, mode, filter) i.mipmap.original().DrawImage(img.mipmap.original(), vs, indices, options.ColorM.impl, mode, filter)
} }
// Bounds returns the bounds of the image. // Bounds returns the bounds of the image.
@ -471,7 +475,7 @@ func (i *Image) At(x, y int) color.Color {
if i.isDisposed() { if i.isDisposed() {
return color.RGBA{} return color.RGBA{}
} }
return i.mipmap.level(0).At(x, y) return i.mipmap.original().At(x, y)
} }
// Dispose disposes the image data. After disposing, most of image functions do nothing and returns meaningless values. // Dispose disposes the image data. After disposing, most of image functions do nothing and returns meaningless values.
@ -507,7 +511,7 @@ func (i *Image) ReplacePixels(p []byte) error {
if i.isDisposed() { if i.isDisposed() {
return nil return nil
} }
i.mipmap.level(0).ReplacePixels(p) i.mipmap.original().ReplacePixels(p)
i.disposeMipmaps() i.disposeMipmaps()
return nil return nil
} }