exp/audio: APIs should not use Context pointer type
This CL is a followup of CL/11315 where it is suggested to remove
Context pointer types from the signatures.
Change-Id: Ice68bfabad0e345f7d93102257a99402be8760b5
Reviewed-on: https://go-review.googlesource.com/11560
Reviewed-by: Nigel Tao <nigeltao@golang.org>
diff --git a/exp/audio/al/alc.go b/exp/audio/al/alc.go
index 9212c71..da40e8d 100644
--- a/exp/audio/al/alc.go
+++ b/exp/audio/al/alc.go
@@ -54,27 +54,25 @@
}
// CreateContext creates a new context.
-func CreateContext() (*Context, error) {
+func CreateContext() (Context, error) {
ctx := alcCreateContext(device, nil)
if ctx == nil {
- return nil, errors.New("al: cannot create a new context")
+ return Context{}, errors.New("al: cannot create a new context")
}
- return &Context{ptr: ctx}, nil
+ return Context{ptr: ctx}, nil
}
// Destroy destroys the context and frees the underlying resources.
// The current context cannot be destroyed. Use MakeContextCurrent
// to make a new context current or use nil.
-func (c *Context) Destroy() {
+func (c Context) Destroy() {
alcDestroyContext(c.ptr)
}
-// MakeContextCurrent makes the given context current. The current
-// context can be nil.
-func MakeContextCurrent(c *Context) bool {
- if c == nil {
- return alcMakeContextCurrent(nil)
- }
+// MakeContextCurrent makes the given context current. Calls to
+// MakeContextCurrent can accept a zero value Context to allow
+// a program not to have an active current context.
+func MakeContextCurrent(c Context) bool {
return alcMakeContextCurrent(c.ptr)
}
diff --git a/exp/audio/audio.go b/exp/audio/audio.go
index 8167e20..43f00dc 100644
--- a/exp/audio/audio.go
+++ b/exp/audio/audio.go
@@ -104,7 +104,7 @@
mu sync.Mutex // guards ctx
// ctx is the shared al.Context used by multiple Player instances.
- ctx *al.Context
+ ctx al.Context
)
type track struct {
@@ -170,9 +170,10 @@
mu.Lock()
defer mu.Unlock()
- if ctx != nil {
+ if ctx != (al.Context{}) {
return nil
}
+
var err error
ctx, err = al.CreateContext()
if err != nil {