Files
gio/ui/app/gl_macos.go
T
Elias Naur e5ddb0b903 ui/app: (macOS) use CFTypeRef for the view factory
The os and gl packages were separate in the past, which required
uintptr for cross-package CFTypeRefs. That's no longer needed.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-24 14:05:30 +02:00

74 lines
1.2 KiB
Go

// SPDX-License-Identifier: Unlicense OR MIT
// +build darwin,!ios
package app
import (
"gioui.org/ui/app/internal/gl"
)
/*
#cgo CFLAGS: -DGL_SILENCE_DEPRECATION -fmodules -fobjc-arc -x objective-c
#include <CoreFoundation/CoreFoundation.h>
#include <CoreGraphics/CoreGraphics.h>
#include <AppKit/AppKit.h>
#include <OpenGL/gl3.h>
#include "gl_macos.h"
*/
import "C"
type context struct {
c *gl.Functions
ctx C.CFTypeRef
}
func init() {
viewFactory = func() C.CFTypeRef {
return C.gio_createGLView()
}
}
func newContext(w *window) (*context, error) {
ctx := C.gio_contextForView(w.contextView())
c := &context{
ctx: ctx,
c: new(gl.Functions),
}
return c, nil
}
func (c *context) Functions() *gl.Functions {
return c.c
}
func (c *context) Release() {
c.Lock()
defer c.Unlock()
C.gio_clearCurrentContext()
C.CFRelease(c.ctx)
c.ctx = 0
}
func (c *context) Present() error {
// Assume the caller already locked the context.
C.glFlush()
return nil
}
func (c *context) Lock() {
C.gio_lockContext(c.ctx)
}
func (c *context) Unlock() {
C.gio_unlockContext(c.ctx)
}
func (c *context) MakeCurrent() error {
c.Lock()
defer c.Unlock()
C.gio_makeCurrentContext(c.ctx)
return nil
}