Skip to content

Moved project #76

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

Merged
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/BUG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Golang's compiling errors

## Does the prebuilt and portable version works ?

###### Download [Link](https://github.com/Drakirus/go-flutter-desktop-embedder/releases)
###### Download [Link](https://github.com/go-flutter-desktop/go-flutter/releases)
<!-- Please answer either yes or no -->
- Yes / No

Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The choice of [Golang](https://github.com/golang/go) comes from the fact that it
<details>
<summary> :package: :penguin: Linux</summary>
<h4>From binaries</h4>
Check out the <a href="https://github.com/Drakirus/go-flutter-desktop-embedder/releases">Release</a> page for prebuilt versions.
Check out the <a href="https://github.com/go-flutter-desktop/go-flutter/releases">Release</a> page for prebuilt versions.

<h4>From source</h4>

Expand All @@ -34,7 +34,7 @@ Go read first: [go-gl/glfw](https://github.com/go-gl/glfw/)

```bash
# Clone
git clone https://github.com/Drakirus/go-flutter-desktop-embedder.git
git clone https://github.com/go-flutter-desktop/go-flutter.git
cd go-flutter-desktop-embedder

# Build the flutter simpleDemo project
Expand All @@ -51,7 +51,7 @@ export CGO_LDFLAGS="-L${PWD}"
# The share library must stay next to the generated binary.

# Get the libraries
go get -u -v github.com/Drakirus/go-flutter-desktop-embedder
go get -u -v github.com/go-flutter-desktop/go-flutter

# Build the example project
go build main.go
Expand All @@ -64,7 +64,7 @@ go build main.go
<details>
<summary> :package: :checkered_flag: Windows</summary>
<h4>From binaries</h4>
Check out the <a href="https://github.com/Drakirus/go-flutter-desktop-embedder/releases">Release</a> page for prebuilt versions.
Check out the <a href="https://github.com/go-flutter-desktop/go-flutter/releases">Release</a> page for prebuilt versions.

<h4>From source</h4>

Expand All @@ -73,7 +73,7 @@ Go read first: [go-gl/glfw](https://github.com/go-gl/glfw/)

```bash
# Clone
git clone https://github.com/Drakirus/go-flutter-desktop-embedder.git
git clone https://github.com/go-flutter-desktop/go-flutter.git
cd go-flutter-desktop-embedder

# Build the flutter simpleDemo project
Expand All @@ -88,10 +88,10 @@ go run engineDownloader.go
# REQUIRED before every `go build`. The CGO compiler need to know where to look for the share library
set CGO_LDFLAGS=-L%cd%
# The share library must stay next to the generated binary.
# If you ran into a MinGW ld error, checkout: https://github.com/Drakirus/go-flutter-desktop-embedder/issues/34
# If you ran into a MinGW ld error, checkout: https://github.com/go-flutter-desktop/go-flutter/issues/34

# Get the libraries
go get -u -v github.com/Drakirus/go-flutter-desktop-embedder
go get -u -v github.com/go-flutter-desktop/go-flutter

# Build the example project
go build main.go
Expand All @@ -104,7 +104,7 @@ go build main.go
<details>
<summary> :package: :apple: MacOS</summary>
<h4>From binaries</h4>
Check out the <a href="https://github.com/Drakirus/go-flutter-desktop-embedder/releases">Release</a> page for prebuilt versions.
Check out the <a href="https://github.com/go-flutter-desktop/go-flutter/releases">Release</a> page for prebuilt versions.

<h4>From source</h4>

Expand All @@ -113,7 +113,7 @@ Go read first: [go-gl/glfw](https://github.com/go-gl/glfw/)

```bash
# Clone
git clone https://github.com/Drakirus/go-flutter-desktop-embedder.git
git clone https://github.com/go-flutter-desktop/go-flutter.git
cd go-flutter-desktop-embedder

# Build the flutter simpleDemo project
Expand All @@ -130,7 +130,7 @@ export CGO_LDFLAGS="-F${PWD} -Wl,-rpath,@executable_path"
# The share library must stay next to the generated binary.

# Get the libraries
go get -u -v github.com/Drakirus/go-flutter-desktop-embedder
go get -u -v github.com/go-flutter-desktop/go-flutter

# Build the example project
go build main.go
Expand Down
4 changes: 2 additions & 2 deletions flutter/build.go → embedder/build.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package flutter
package embedder

/*
// Linux Build Tags
Expand All @@ -21,5 +21,5 @@ import "C"

import (
// prevents dep from stripping out the c source files in flutter library.
_ "github.com/Drakirus/go-flutter-desktop-embedder/flutter/library"
_ "github.com/go-flutter-desktop/go-flutter/embedder/library"
)
58 changes: 29 additions & 29 deletions flutter/flutter.go → embedder/embedder.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package flutter
package embedder

// #include "flutter_embedder.h"
// FlutterResult runFlutter(uintptr_t window, FlutterEngine *engine, FlutterProjectArgs * Args,
Expand All @@ -12,21 +12,21 @@ import (
"unsafe"
)

// the current FlutterEngine running (associated with his callback)
var flutterEngines []*EngineOpenGL
// A list of flutter engines that are managed by this embedder.
var flutterEngines []*FlutterEngine
var flutterEnginesLock sync.RWMutex

// SelectEngine return a EngineOpenGL from an index
func SelectEngine(index int) *EngineOpenGL {
// FlutterEngineByIndex returns an existing FlutterEngine by its index in this embedder.
func FlutterEngineByIndex(index int) *FlutterEngine {
flutterEnginesLock.RLock()
engine := flutterEngines[index]
flutterEnginesLock.RUnlock()
return engine
}

// NumberOfEngines return the number of engine registered into this embedder
func NumberOfEngines() C.int {
return C.int(len(flutterEngines))
// CountFlutterEngines return the number of engines registered in this embedder.
func CountFlutterEngines() int {
return len(flutterEngines)
}

// Result corresponds to the C.enum retuned by the shared flutter library
Expand All @@ -40,8 +40,8 @@ const (
KInvalidArguments Result = C.kInvalidArguments
)

// EngineOpenGL corresponds to the C.FlutterEngine with his associated callback's method.
type EngineOpenGL struct {
// FlutterEngine corresponds to the C.FlutterEngine with his associated callback's method.
type FlutterEngine struct {
// Flutter Engine.
Engine C.FlutterEngine

Expand All @@ -63,28 +63,28 @@ type EngineOpenGL struct {
IcuDataPath string
}

// NewEngineOpenGL creates an empty EngineOpenGL
// NewFlutterEngine creates an empty FlutterEngine
// and assigns it an index for global lookup.
func NewEngineOpenGL() *EngineOpenGL {
flu := &EngineOpenGL{}
func NewFlutterEngine() *FlutterEngine {
fe := &FlutterEngine{}
flutterEnginesLock.Lock()
flutterEngines = append(flutterEngines, flu)
flu.index = len(flutterEngines) - 1
flutterEngines = append(flutterEngines, fe)
fe.index = len(flutterEngines) - 1
flutterEnginesLock.Unlock()
return flu
return fe
}

// Index returns the index of the engine in the global flutterEngines slice
func (flu *EngineOpenGL) Index() int {
func (flu *FlutterEngine) Index() int {
return flu.index
}

// Run launches the Flutter Engine in a background thread.
func (flu *EngineOpenGL) Run(window uintptr, vmArgs []string) Result {
// validate this EngineOpenGL was created correctly
func (flu *FlutterEngine) Run(window uintptr, vmArgs []string) Result {
// validate this FlutterEngine was created correctly
flutterEnginesLock.RLock()
if len(flutterEngines) <= flu.index || flutterEngines[flu.index] != flu {
panic("EngineOpenGL was wrongly created. Use embedder.NewEngineOpenGL().")
panic("FlutterEngine was wrongly created. Use embedder.NewFlutterEngine().")
}
flutterEnginesLock.RUnlock()

Expand All @@ -109,7 +109,7 @@ func (flu *EngineOpenGL) Run(window uintptr, vmArgs []string) Result {
}

// Shutdown stops the Flutter engine.
func (flu *EngineOpenGL) Shutdown() Result {
func (flu *FlutterEngine) Shutdown() Result {
res := C.FlutterEngineShutdown(flu.Engine)
return (Result)(res)
}
Expand All @@ -133,8 +133,8 @@ type PointerEvent struct {
Y float64
}

// EngineSendPointerEvent is used to send an PointerEvent to the Flutter engine.
func (flu *EngineOpenGL) EngineSendPointerEvent(Event PointerEvent) Result {
// SendPointerEvent is used to send an PointerEvent to the Flutter engine.
func (flu *FlutterEngine) SendPointerEvent(Event PointerEvent) Result {

cEvents := C.FlutterPointerEvent{
phase: (_Ctype_FlutterPointerPhase)(Event.Phase),
Expand All @@ -156,8 +156,8 @@ type WindowMetricsEvent struct {
PixelRatio float64
}

// EngineSendWindowMetricsEvent is used to send a WindowMetricsEvent to the Flutter Engine.
func (flu *EngineOpenGL) EngineSendWindowMetricsEvent(Metric WindowMetricsEvent) Result {
// SendWindowMetricsEvent is used to send a WindowMetricsEvent to the Flutter Engine.
func (flu *FlutterEngine) SendWindowMetricsEvent(Metric WindowMetricsEvent) Result {

cMetric := C.FlutterWindowMetricsEvent{
width: C.size_t(Metric.Width),
Expand Down Expand Up @@ -188,7 +188,7 @@ type Message struct {
}

// SendPlatformMessage is used to send a PlatformMessage to the Flutter engine.
func (flu *EngineOpenGL) SendPlatformMessage(Message *PlatformMessage) Result {
func (flu *FlutterEngine) SendPlatformMessage(Message *PlatformMessage) Result {

marshalled, err := json.Marshal(&Message.Message)
if err != nil {
Expand All @@ -213,7 +213,7 @@ func (flu *EngineOpenGL) SendPlatformMessage(Message *PlatformMessage) Result {
}

// SendPlatformMessageResponse is used to send a message to the Flutter side using the correct ResponseHandle!
func (flu *EngineOpenGL) SendPlatformMessageResponse(
func (flu *FlutterEngine) SendPlatformMessageResponse(
responseTo *PlatformMessage,
data []byte,
) Result {
Expand All @@ -228,8 +228,8 @@ func (flu *EngineOpenGL) SendPlatformMessageResponse(

}

// EngineFlushPendingTasksNow flush tasks on a message loop not controlled by the Flutter engine.
// FlutterEngineFlushPendingTasksNow flush tasks on a message loop not controlled by the Flutter engine.
// deprecated soon.
func EngineFlushPendingTasksNow() {
func FlutterEngineFlushPendingTasksNow() {
C.__FlutterEngineFlushPendingTasksNow()
}
45 changes: 45 additions & 0 deletions embedder/embedder_helper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

#include "library/flutter_embedder.h"
#include <stdlib.h>

// C proxies def
bool proxy_make_current(void *v);
bool proxy_clear_current(void *v);
bool proxy_present(void *v);
uint32_t proxy_fbo_callback(void *v);
bool proxy_make_resource_current(void *v);
void *proxy_gl_proc_resolver(void *v, const char *procname);
bool proxy_on_platform_message(FlutterPlatformMessage *message, void *window);

// C helper
FlutterResult runFlutter(uintptr_t window, FlutterEngine *engine, FlutterProjectArgs *Args,
const char *const *vmArgs, int nVmAgrs)
{

FlutterRendererConfig config = {};
config.type = kOpenGL;

config.open_gl.struct_size = sizeof(FlutterOpenGLRendererConfig);
config.open_gl.make_current = proxy_make_current;
config.open_gl.clear_current = proxy_clear_current;
config.open_gl.present = proxy_present;
config.open_gl.fbo_callback = proxy_fbo_callback;
config.open_gl.make_resource_current = proxy_make_resource_current;
config.open_gl.gl_proc_resolver = proxy_gl_proc_resolver;

Args->command_line_argc = nVmAgrs;
Args->command_line_argv = vmArgs;
Args->platform_message_callback = (FlutterPlatformMessageCallback)proxy_on_platform_message;

return FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, Args, (void *)window, engine);
}

char **makeCharArray(int size)
{
return calloc(sizeof(char *), size);
}

void setArrayString(char **a, char *s, int n)
{
a[n] = s;
}
26 changes: 13 additions & 13 deletions flutter/flutter_proxy_glfw.go → embedder/embedder_proxy_glfw.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package flutter
package embedder

/*
#include "flutter_embedder.h"
Expand Down Expand Up @@ -31,8 +31,8 @@ func proxy_on_platform_message(message *C.FlutterPlatformMessage, window unsafe.
ResponseHandle: message.response_handle,
}
index := *(*int)(glfw.GoWindow(window).GetUserPointer())
engine := SelectEngine(index)
return C.bool(engine.FPlatfromMessage(FlutterPlatformMessage, window))
flutterEngine := FlutterEngineByIndex(index)
return C.bool(flutterEngine.FPlatfromMessage(FlutterPlatformMessage, window))
}
return C.bool(false)
}
Expand All @@ -41,40 +41,40 @@ func proxy_on_platform_message(message *C.FlutterPlatformMessage, window unsafe.
func proxy_make_current(v unsafe.Pointer) C.bool {
w := glfw.GoWindow(v)
index := *(*int)(w.GetUserPointer())
engine := SelectEngine(index)
return C.bool(engine.FMakeCurrent(v))
flutterEngine := FlutterEngineByIndex(index)
return C.bool(flutterEngine.FMakeCurrent(v))
}

//export proxy_clear_current
func proxy_clear_current(v unsafe.Pointer) C.bool {
w := glfw.GoWindow(v)
index := *(*int)(w.GetUserPointer())
engine := SelectEngine(index)
return C.bool(engine.FClearCurrent(v))
flutterEngine := FlutterEngineByIndex(index)
return C.bool(flutterEngine.FClearCurrent(v))
}

//export proxy_present
func proxy_present(v unsafe.Pointer) C.bool {
w := glfw.GoWindow(v)
index := *(*int)(w.GetUserPointer())
engine := SelectEngine(index)
return C.bool(engine.FPresent(v))
flutterEngine := FlutterEngineByIndex(index)
return C.bool(flutterEngine.FPresent(v))
}

//export proxy_fbo_callback
func proxy_fbo_callback(v unsafe.Pointer) C.uint32_t {
w := glfw.GoWindow(v)
index := *(*int)(w.GetUserPointer())
engine := SelectEngine(index)
return C.uint32_t(engine.FFboCallback(v))
flutterEngine := FlutterEngineByIndex(index)
return C.uint32_t(flutterEngine.FFboCallback(v))
}

//export proxy_make_resource_current
func proxy_make_resource_current(v unsafe.Pointer) C.bool {
w := glfw.GoWindow(v)
index := *(*int)(w.GetUserPointer())
engine := SelectEngine(index)
return C.bool(engine.FMakeResourceCurrent(v))
flutterEngine := FlutterEngineByIndex(index)
return C.bool(flutterEngine.FMakeResourceCurrent(v))
}

//export proxy_gl_proc_resolver
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions example/simpleDemo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
icudtl.dat
main
Loading