6
6
7
7
"github.com/go-flutter-desktop/go-flutter/embedder"
8
8
"github.com/go-flutter-desktop/go-flutter/internal/opengl"
9
+ "github.com/go-flutter-desktop/go-flutter/internal/tasker"
9
10
"github.com/go-gl/glfw/v3.2/glfw"
10
11
"github.com/pkg/errors"
11
12
)
@@ -21,6 +22,9 @@ type TextureRegistry struct {
21
22
channels map [int64 ]* externalTextureHanlder
22
23
channelsLock sync.RWMutex
23
24
25
+ // engineTasker holds tasks which must be executed in the engine thread
26
+ engineTasker * tasker.Tasker
27
+
24
28
texture int64
25
29
texturesLock sync.Mutex
26
30
}
@@ -34,12 +38,14 @@ type externalTextureHanlder struct {
34
38
35
39
func newTextureRegistry (engine * embedder.FlutterEngine , window * glfw.Window ) * TextureRegistry {
36
40
return & TextureRegistry {
37
- window : window ,
38
- engine : engine ,
39
- channels : make (map [int64 ]* externalTextureHanlder ),
41
+ window : window ,
42
+ engine : engine ,
43
+ channels : make (map [int64 ]* externalTextureHanlder ),
44
+ engineTasker : tasker .New (),
40
45
}
41
46
}
42
47
48
+ // init must happen in engine thread
43
49
func (t * TextureRegistry ) init () error {
44
50
t .window .MakeContextCurrent ()
45
51
// Important! Call open.Init only under the presence of an active OpenGL context,
@@ -80,7 +86,10 @@ func (t *TextureRegistry) setTextureHandler(textureID int64, handler ExternalTex
80
86
if handler == nil {
81
87
texture := t .channels [textureID ]
82
88
if texture != nil {
83
- opengl .DeleteTextures (1 , & texture .texture )
89
+ t .engineTasker .Do (func () {
90
+ // Must run on the main tread
91
+ opengl .DeleteTextures (1 , & texture .texture )
92
+ })
84
93
}
85
94
delete (t .channels , textureID )
86
95
} else {
@@ -91,6 +100,10 @@ func (t *TextureRegistry) setTextureHandler(textureID int64, handler ExternalTex
91
100
t .channelsLock .Unlock ()
92
101
}
93
102
103
+ // handleExternalTexture receive low level C calls to create and/or update the
104
+ // content of a OpenGL TexImage2D.
105
+ // Calls must happen on the engine thread, no need to use engineTasker as this
106
+ // function is a callback directly managed by the engine.
94
107
func (t * TextureRegistry ) handleExternalTexture (textureID int64 ,
95
108
width int , height int ) * embedder.FlutterOpenGLTexture {
96
109
0 commit comments