Make go vet a little happier on macOS

Updates #889
This commit is contained in:
Hajime Hoshi 2019-07-22 20:02:37 +09:00
parent e6a88a7d1f
commit 4a9a7f936d
8 changed files with 26 additions and 21 deletions

View File

@ -610,7 +610,14 @@ func (d *Driver) Draw(indexLen int, indexOffset int, mode driver.CompositeMode,
compositeMode: mode, compositeMode: mode,
}]) }])
} }
rce.SetViewport(mtl.Viewport{0, 0, float64(w), float64(h), -1, 1}) rce.SetViewport(mtl.Viewport{
OriginX: 0,
OriginY: 0,
Width: float64(w),
Height: float64(h),
ZNear: -1,
ZFar: 1,
})
rce.SetVertexBuffer(d.vb, 0, 0) rce.SetVertexBuffer(d.vb, 0, 0)
viewportSize := [...]float32{float32(w), float32(h)} viewportSize := [...]float32{float32(w), float32(h)}
@ -767,7 +774,7 @@ func (i *Image) Pixels() ([]byte, error) {
b := make([]byte, 4*i.width*i.height) b := make([]byte, 4*i.width*i.height)
i.driver.t.Call(func() error { i.driver.t.Call(func() error {
i.texture.GetBytes(&b[0], uintptr(4*i.width), mtl.Region{ i.texture.GetBytes(&b[0], uintptr(4*i.width), mtl.Region{
Size: mtl.Size{i.width, i.height, 1}, Size: mtl.Size{Width: i.width, Height: i.height, Depth: 1},
}, 0) }, 0)
return nil return nil
}) })
@ -793,8 +800,8 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
i.driver.t.Call(func() error { i.driver.t.Call(func() error {
i.texture.ReplaceRegion(mtl.Region{ i.texture.ReplaceRegion(mtl.Region{
Origin: mtl.Origin{x, y, 0}, Origin: mtl.Origin{X: x, Y: y, Z: 0},
Size: mtl.Size{width, height, 1}, Size: mtl.Size{Width: width, Height: height, Depth: 1},
}, 0, unsafe.Pointer(&pixels[0]), 4*width) }, 0, unsafe.Pointer(&pixels[0]), 4*width)
return nil return nil
}) })

View File

@ -36,11 +36,11 @@ import "C"
// //
// Reference: https://developer.apple.com/documentation/appkit/nswindow. // Reference: https://developer.apple.com/documentation/appkit/nswindow.
type Window struct { type Window struct {
window unsafe.Pointer window uintptr
} }
// NewWindow returns a Window that wraps an existing NSWindow * pointer. // NewWindow returns a Window that wraps an existing NSWindow * pointer.
func NewWindow(window unsafe.Pointer) Window { func NewWindow(window uintptr) Window {
return Window{window} return Window{window}
} }
@ -49,7 +49,7 @@ func NewWindow(window unsafe.Pointer) Window {
// //
// Reference: https://developer.apple.com/documentation/appkit/nswindow/1419160-contentview. // Reference: https://developer.apple.com/documentation/appkit/nswindow/1419160-contentview.
func (w Window) ContentView() View { func (w Window) ContentView() View {
return View{C.Window_ContentView(w.window)} return View{C.Window_ContentView(C.uintptr_t(w.window))}
} }
// View is the infrastructure for drawing, printing, and handling events in an app. // View is the infrastructure for drawing, printing, and handling events in an app.

View File

@ -14,9 +14,11 @@
// +build darwin // +build darwin
#include <stdint.h>
typedef signed char BOOL; typedef signed char BOOL;
void *Window_ContentView(void *window); void *Window_ContentView(uintptr_t window);
void View_SetLayer(void *view, void *layer); void View_SetLayer(void *view, void *layer);
void View_SetWantsLayer(void *view, BOOL wantsLayer); void View_SetWantsLayer(void *view, BOOL wantsLayer);

View File

@ -17,7 +17,7 @@
#include "ns.h" #include "ns.h"
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
void *Window_ContentView(void *window) { void *Window_ContentView(uintptr_t window) {
return ((NSWindow *)window).contentView; return ((NSWindow *)window).contentView;
} }

View File

@ -18,8 +18,6 @@
package metal package metal
import ( import (
"unsafe"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/ca" "github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/ca"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl" "github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/ns" "github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/ns"
@ -76,7 +74,7 @@ func (v *view) reset() error {
func (v *view) update() { func (v *view) update() {
// NSView can be changed anytime (probably). Set this everyframe. // NSView can be changed anytime (probably). Set this everyframe.
cocoaWindow := ns.NewWindow(unsafe.Pointer(v.window)) cocoaWindow := ns.NewWindow(v.window)
cocoaWindow.ContentView().SetLayer(v.ml) cocoaWindow.ContentView().SetLayer(v.ml)
cocoaWindow.ContentView().SetWantsLayer(true) cocoaWindow.ContentView().SetWantsLayer(true)
} }

View File

@ -22,7 +22,7 @@ package glfw
// //
// #import <AppKit/AppKit.h> // #import <AppKit/AppKit.h>
// //
// static void currentMonitorPos(void* windowPtr, int* x, int* y) { // static void currentMonitorPos(uintptr_t windowPtr, int* x, int* y) {
// NSScreen* screen = [NSScreen mainScreen]; // NSScreen* screen = [NSScreen mainScreen];
// if (windowPtr) { // if (windowPtr) {
// NSWindow* window = (NSWindow*)windowPtr; // NSWindow* window = (NSWindow*)windowPtr;
@ -42,8 +42,6 @@ package glfw
import "C" import "C"
import ( import (
"unsafe"
"github.com/hajimehoshi/ebiten/internal/glfw" "github.com/hajimehoshi/ebiten/internal/glfw"
) )
@ -59,8 +57,8 @@ func (u *UserInterface) currentMonitorFromPosition() *glfw.Monitor {
x := C.int(0) x := C.int(0)
y := C.int(0) y := C.int(0)
// Note: [NSApp mainWindow] is nil when it doesn't have its border. Use u.window here. // Note: [NSApp mainWindow] is nil when it doesn't have its border. Use u.window here.
win := unsafe.Pointer(u.window.GetCocoaWindow()) win := u.window.GetCocoaWindow()
C.currentMonitorPos(win, &x, &y) C.currentMonitorPos(C.uintptr_t(win), &x, &y)
for _, m := range glfw.GetMonitors() { for _, m := range glfw.GetMonitors() {
mx, my := m.GetPos() mx, my := m.GetPos()
if int(x) == mx && int(y) == my { if int(x) == mx && int(y) == my {

View File

@ -169,7 +169,7 @@ func getGlyphImages(face font.Face, runes []rune) []*glyphImage {
Src: image.White, Src: image.White,
Face: face, Face: face,
} }
d.Dot = fixed.Point26_6{fixed.I(x) - b.Min.X, -b.Min.Y} d.Dot = fixed.Point26_6{X: fixed.I(x) - b.Min.X, Y: -b.Min.Y}
d.DrawString(string(r)) d.DrawString(string(r))
xs[r] = x xs[r] = x

View File

@ -44,7 +44,7 @@ type Path struct {
// MoveTo skips the current position of the path to the given position (x, y) without adding any strokes. // MoveTo skips the current position of the path to the given position (x, y) without adding any strokes.
func (p *Path) MoveTo(x, y float32) { func (p *Path) MoveTo(x, y float32) {
p.cur = math.Point{x, y} p.cur = math.Point{X: x, Y: y}
if len(p.segs) > 0 && len(p.segs[len(p.segs)-1]) == 0 { if len(p.segs) > 0 && len(p.segs[len(p.segs)-1]) == 0 {
return return
} }
@ -58,8 +58,8 @@ func (p *Path) LineTo(x, y float32) {
if len(p.segs) == 0 { if len(p.segs) == 0 {
p.segs = append(p.segs, []math.Segment{}) p.segs = append(p.segs, []math.Segment{})
} }
p.segs[len(p.segs)-1] = append(p.segs[len(p.segs)-1], math.Segment{p.cur, math.Point{x, y}}) p.segs[len(p.segs)-1] = append(p.segs[len(p.segs)-1], math.Segment{P0: p.cur, P1: math.Point{X: x, Y: y}})
p.cur = math.Point{x, y} p.cur = math.Point{X: x, Y: y}
} }
func (p *Path) strokeVertices(lineWidth float32, clr color.Color) (vertices []ebiten.Vertex, indices []uint16) { func (p *Path) strokeVertices(lineWidth float32, clr color.Color) (vertices []ebiten.Vertex, indices []uint16) {