gioui.org/ui@v0.0.0-20190926171558-ce74bc0cbaea/app/gl_macos.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 // +build darwin,!ios 4 5 package app 6 7 import ( 8 "gioui.org/ui/app/internal/gl" 9 ) 10 11 /* 12 #cgo CFLAGS: -DGL_SILENCE_DEPRECATION -fmodules -fobjc-arc -x objective-c 13 14 #include <CoreFoundation/CoreFoundation.h> 15 #include <CoreGraphics/CoreGraphics.h> 16 #include <AppKit/AppKit.h> 17 #include <OpenGL/gl3.h> 18 #include "gl_macos.h" 19 */ 20 import "C" 21 22 type context struct { 23 c *gl.Functions 24 ctx C.CFTypeRef 25 view C.CFTypeRef 26 } 27 28 func init() { 29 viewFactory = func() C.CFTypeRef { 30 return C.gio_createGLView() 31 } 32 } 33 34 func newContext(w *window) (*context, error) { 35 view := w.contextView() 36 ctx := C.gio_contextForView(view) 37 c := &context{ 38 ctx: ctx, 39 c: new(gl.Functions), 40 view: view, 41 } 42 return c, nil 43 } 44 45 func (c *context) Functions() *gl.Functions { 46 return c.c 47 } 48 49 func (c *context) Release() { 50 c.Lock() 51 defer c.Unlock() 52 C.gio_clearCurrentContext() 53 } 54 55 func (c *context) Present() error { 56 // Assume the caller already locked the context. 57 C.glFlush() 58 return nil 59 } 60 61 func (c *context) Lock() { 62 C.gio_lockContext(c.ctx) 63 } 64 65 func (c *context) Unlock() { 66 C.gio_unlockContext(c.ctx) 67 } 68 69 func (c *context) MakeCurrent() error { 70 c.Lock() 71 defer c.Unlock() 72 C.gio_makeCurrentContext(c.ctx) 73 return nil 74 }