From 11e67d0eed392a033bf34828a6b8d429ad550828 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 5 Jul 2016 03:15:32 +0900 Subject: [PATCH] graphics: Refactoring --- image.go | 7 +------ imageimpl.go | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/image.go b/image.go index 27692302e..4f745ec24 100644 --- a/image.go +++ b/image.go @@ -20,7 +20,6 @@ import ( "runtime" "sync" - "github.com/hajimehoshi/ebiten/internal/graphics" "github.com/hajimehoshi/ebiten/internal/graphics/opengl" ) @@ -195,11 +194,7 @@ type DrawImageOptions struct { // // This function is concurrent-safe. func NewImage(width, height int, filter Filter) (*Image, error) { - i, err := graphics.NewImage(width, height, glFilter(filter)) - if err != nil { - return nil, err - } - img, err := newImageImpl(i, filter) + img, err := newImageImpl(width, height, filter) if err != nil { return nil, err } diff --git a/imageimpl.go b/imageimpl.go index 0b71478bc..24e4bb92d 100644 --- a/imageimpl.go +++ b/imageimpl.go @@ -41,12 +41,15 @@ type imageImpl struct { m sync.Mutex } -func newImageImpl(image *graphics.Image, filter Filter) (*imageImpl, error) { - w, h := image.Size() +func newImageImpl(width, height int, filter Filter) (*imageImpl, error) { + img, err := graphics.NewImage(width, height, glFilter(filter)) + if err != nil { + return nil, err + } i := &imageImpl{ - image: image, - width: w, - height: h, + image: img, + width: width, + height: height, filter: filter, } runtime.SetFinalizer(i, (*imageImpl).Dispose) @@ -86,16 +89,18 @@ func newImageImplFromImage(source image.Image, filter Filter) (*imageImpl, error } func newScreenImageImpl(width, height int) (*imageImpl, error) { - i, err := graphics.NewScreenFramebufferImage(width, height) + img, err := graphics.NewScreenFramebufferImage(width, height) if err != nil { return nil, err } - img, err := newImageImpl(i, FilterNearest) - if err != nil { - return nil, err + i := &imageImpl{ + image: img, + width: width, + height: height, + screen: true, } - img.screen = true - return img, nil + runtime.SetFinalizer(i, (*imageImpl).Dispose) + return i, nil } func (i *imageImpl) Fill(clr color.Color) error {