From f28a01df9786b6014f8a7ccaefdb54fb07581cfb Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Tue, 17 Mar 2015 12:39:21 -0400 Subject: [PATCH] app: set valid geom.Width/Height on darwin/arm Change-Id: Id3c5c58050fa11ec57e8efd2661047dc5e0dfc2d Reviewed-on: https://go-review.googlesource.com/7665 Reviewed-by: Hyang-Ah Hana Kim --- app/darwin_arm.go | 16 ++++++++++------ app/darwin_arm.m | 11 +++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/darwin_arm.go b/app/darwin_arm.go index 335fc32..7ee7dce 100644 --- a/app/darwin_arm.go +++ b/app/darwin_arm.go @@ -96,16 +96,20 @@ var machinePPI = map[string]int{ } func ppi() int { - // TODO(crawshaw): use lookup table to get the correct PPI. - //C.uname(&C.sysInfo) - //machine := C.GoString(C.sysInfo.machine) - //return machinePPI[machine] - return 326 + C.uname(&C.sysInfo) + name := C.GoString(&C.sysInfo.machine[0]) + v, ok := machinePPI[name] + if !ok { + log.Fatalf("unknown machine: %s", name) + } + return v } //export setGeom func setGeom(width, height int) { - geom.PixelsPerPt = float32(ppi()) / 72 + if geom.PixelsPerPt == 0 { + geom.PixelsPerPt = float32(ppi()) / 72 + } geom.Width = geom.Pt(float32(width) / geom.PixelsPerPt) geom.Height = geom.Pt(float32(height) / geom.PixelsPerPt) } diff --git a/app/darwin_arm.m b/app/darwin_arm.m index 5a2f52e..5baf3e3 100644 --- a/app/darwin_arm.m +++ b/app/darwin_arm.m @@ -43,14 +43,13 @@ struct utsname sysInfo; GLKView *view = (GLKView *)self.view; view.context = self.context; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; - - // TODO(crawshaw): set correct geometry. - //CGRect bounds = view.bounds; - //view.contentScaleFactor; - setGeom(300, 300); } - (void)update { - NSLog(@"AppController update"); + GLKView *view = (GLKView *)self.view; + int w = [view drawableWidth]; + int h = [view drawableHeight]; + setGeom(w, h); + drawgl((GoUintptr)self.context); } @end