-
Notifications
You must be signed in to change notification settings - Fork 282
/
texture.go
41 lines (36 loc) · 1.22 KB
/
texture.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package flutter
import (
"github.com/pkg/errors"
)
// Texture is an identifier for texture declaration
type Texture struct {
ID int64
registry *TextureRegistry
}
// Register registers a textureID with his associated handler
func (t *Texture) Register(handler ExternalTextureHanlderFunc) error {
t.registry.setTextureHandler(t.ID, handler)
err := t.registry.engine.RegisterExternalTexture(t.ID)
if err != nil {
t.registry.setTextureHandler(t.ID, nil)
return errors.Errorf("'go-flutter' couldn't register texture with id: '%v': %v", t.ID, err)
}
return nil
}
// FrameAvailable mark a texture buffer is ready to be draw in the flutter scene
func (t *Texture) FrameAvailable() error {
err := t.registry.engine.MarkExternalTextureFrameAvailable(t.ID)
if err != nil {
return errors.Errorf("'go-flutter' couldn't mark frame available of texture with id: '%v': %v", t.ID, err)
}
return nil
}
// UnRegister unregisters a textureID with his associated handler
func (t *Texture) UnRegister() error {
err := t.registry.engine.UnregisterExternalTexture(t.ID)
if err != nil {
return errors.Errorf("'go-flutter' couldn't unregisters texture with id: '%v': %v", t.ID, err)
}
t.registry.setTextureHandler(t.ID, nil)
return nil
}