2
0
mirror of synced 2025-02-23 23:08:14 +00:00

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>
This commit is contained in:
Burcu Dogan 2015-06-26 10:31:44 -07:00
parent d06bbc53e4
commit 383ad68fc0
2 changed files with 11 additions and 12 deletions

View File

@ -54,27 +54,25 @@ func OpenDevice() error {
} }
// CreateContext creates a new context. // CreateContext creates a new context.
func CreateContext() (*Context, error) { func CreateContext() (Context, error) {
ctx := alcCreateContext(device, nil) ctx := alcCreateContext(device, nil)
if ctx == 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. // Destroy destroys the context and frees the underlying resources.
// The current context cannot be destroyed. Use MakeContextCurrent // The current context cannot be destroyed. Use MakeContextCurrent
// to make a new context current or use nil. // to make a new context current or use nil.
func (c *Context) Destroy() { func (c Context) Destroy() {
alcDestroyContext(c.ptr) alcDestroyContext(c.ptr)
} }
// MakeContextCurrent makes the given context current. The current // MakeContextCurrent makes the given context current. Calls to
// context can be nil. // MakeContextCurrent can accept a zero value Context to allow
func MakeContextCurrent(c *Context) bool { // a program not to have an active current context.
if c == nil { func MakeContextCurrent(c Context) bool {
return alcMakeContextCurrent(nil)
}
return alcMakeContextCurrent(c.ptr) return alcMakeContextCurrent(c.ptr)
} }

View File

@ -104,7 +104,7 @@ var (
mu sync.Mutex // guards ctx mu sync.Mutex // guards ctx
// ctx is the shared al.Context used by multiple Player instances. // ctx is the shared al.Context used by multiple Player instances.
ctx *al.Context ctx al.Context
) )
type track struct { type track struct {
@ -170,9 +170,10 @@ func createContext() error {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
if ctx != nil { if ctx != (al.Context{}) {
return nil return nil
} }
var err error var err error
ctx, err = al.CreateContext() ctx, err = al.CreateContext()
if err != nil { if err != nil {