Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture support #217

Merged
merged 19 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# go-flutter - A package that brings Flutter to the desktop

[![Awesome Flutter](https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat)](https://github.com/Solido/awesome-flutter)
[![Documentation](https://godoc.org/github.com/go-flutter-desktop/go-flutter?status.svg)](http://godoc.org/github.com/go-flutter-desktop/go-flutter)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-flutter-desktop/go-flutter)](https://goreportcard.com/report/github.com/go-flutter-desktop/go-flutter)
[![Join the chat at https://gitter.im/go-flutter-desktop/go-flutter](https://badges.gitter.im/go-flutter-desktop/go-flutter.svg)](https://gitter.im/go-flutter-desktop/go-flutter?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Expand Down
20 changes: 20 additions & 0 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func (a *Application) Run() error {
return errors.Errorf("invalid window mode %T", a.config.windowMode)
}

glfw.WindowHint(glfw.ContextVersionMajor, 4)
glfw.WindowHint(glfw.ContextVersionMinor, 1)
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)

if a.config.windowInitialLocations.xpos != 0 {
// To create the window at a specific position, make it initially invisible
// using the Visible window hint, set its position and then show it.
Expand Down Expand Up @@ -217,6 +222,11 @@ func (a *Application) Run() error {

a.engine.PlatfromMessage = messenger.handlePlatformMessage

texturer := newRegistry(a.engine, a.window)
a.engine.GLExternalTextureFrameCallback = texturer.handleExternalTexture

texturer.init()

// Not very nice, but we can only really fix this when there's a pluggable
// renderer.
defaultTextinputPlugin.keyboardLayout = a.config.keyboardLayout
Expand Down Expand Up @@ -254,6 +264,16 @@ func (a *Application) Run() error {
// platfrom message can be corectly handled by ui.Window.onPlatformMessage.
glfw.WaitEvents()

for _, p := range a.config.plugins {
// Extra init call for plugins that satisfy the PluginTexture interface.
if glfwPlugin, ok := p.(PluginTexture); ok {
err = glfwPlugin.InitPluginTexture(texturer)
if err != nil {
return errors.Wrap(err, "failed to initialize texture plugin"+fmt.Sprintf("%T", p))
}
}
}

a.window.SetKeyCallback(
func(window *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
defaultTextinputPlugin.glfwKeyCallback(window, key, scancode, action, mods)
Expand Down
57 changes: 51 additions & 6 deletions embedder/embedder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ const (
ResultEngineNotRunning Result = -1
)

// FlutterOpenGLTexture corresponds to the C.FlutterOpenGLTexture struct.
type FlutterOpenGLTexture struct {
// Target texture of the active texture unit (example GL_TEXTURE_2D)
Target uint32
// The name of the texture
Name uint32
// The texture format (example GL_RGBA8)
Format uint32
}

// FlutterEngine corresponds to the C.FlutterEngine with his associated callback's method.
type FlutterEngine struct {
// Flutter Engine.
Expand All @@ -65,12 +75,13 @@ type FlutterEngine struct {
index int

// GL callback functions
GLMakeCurrent func() bool
GLClearCurrent func() bool
GLPresent func() bool
GLFboCallback func() int32
GLMakeResourceCurrent func() bool
GLProcResolver func(procName string) unsafe.Pointer
GLMakeCurrent func() bool
GLClearCurrent func() bool
GLPresent func() bool
GLFboCallback func() int32
GLMakeResourceCurrent func() bool
GLProcResolver func(procName string) unsafe.Pointer
GLExternalTextureFrameCallback func(textureID int64, width int, height int) *FlutterOpenGLTexture

// platform message callback function
PlatfromMessage func(message *PlatformMessage)
Expand Down Expand Up @@ -299,6 +310,40 @@ func (flu *FlutterEngine) SendPlatformMessageResponse(
return (Result)(res)
}

// RegisterExternalTexture registers an external texture with a unique identifier.
func (flu *FlutterEngine) RegisterExternalTexture(textureID int64) Result {
flu.sync.Lock()
defer flu.sync.Unlock()
if flu.closed {
return ResultEngineNotRunning
}
res := C.FlutterEngineRegisterExternalTexture(flu.Engine, C.int64_t(textureID))
return (Result)(res)
}

// UnregisterExternalTexture unregisters a previous texture registration.
func (flu *FlutterEngine) UnregisterExternalTexture(textureID int64) Result {
flu.sync.Lock()
defer flu.sync.Unlock()
if flu.closed {
return ResultEngineNotRunning
}
res := C.FlutterEngineUnregisterExternalTexture(flu.Engine, C.int64_t(textureID))
return (Result)(res)
}

// MarkExternalTextureFrameAvailable marks that a new texture frame is
// available for a given texture identifier.
func (flu *FlutterEngine) MarkExternalTextureFrameAvailable(textureID int64) Result {
flu.sync.Lock()
defer flu.sync.Unlock()
if flu.closed {
return ResultEngineNotRunning
}
res := C.FlutterEngineMarkExternalTextureFrameAvailable(flu.Engine, C.int64_t(textureID))
return (Result)(res)
}

// FlutterEngineFlushPendingTasksNow flush tasks on a message loop not
// controlled by the Flutter engine.
//
Expand Down
Loading