embedder

package
v0.52.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

README

embedder

This package wraps the Flutter embedder API in Go and adds some helper functions to work with it. This package does NOT contain any platform specific code (glfw, etc.) and may eventualy be used for platforms other than the ones targeted by go-flutter right now. Note that this package does not promise a stable API: types, functions, methods may all change in a breaking way.

Build

To build this package set the CGO_LDFLAGS and run go build. For example:

On Linux:

export CGO_LDFLAGS="-L${HOME}/.cache/hover/engine/linux/"
go build

To build this package on Mac OS

export CGO_LDFLAGS="-F ${HOME}/Library/Caches/hover/engine/darwin"
go build

To build this package on Windows

set CGO_LDFLAGS="-L%HOMEPATH%/.cache/hover/engine/windows/"
go build

This works if hover has cached the flutter engine for the local user.

Documentation

Overview

Package embedder wraps the Flutter Embedder C API to Go.

The package contains some GLFW specific implementation helpers. These may be removed in the future.

If you wish to publish a Flutter application to desktop, you shouldn't use this package directly. Instead, use the go-flutter package. There is NO compatibility promise on this package (embedder). Breaking changes can and will occur.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlutterEngineGetCurrentTime

func FlutterEngineGetCurrentTime() uint64

FlutterEngineGetCurrentTime gets the current time in nanoseconds from the clock used by the flutter engine.

Types

type DataCallback

type DataCallback struct {
	// Handle func
	Handle func(binaryReply []byte)
}

DataCallback is a function called when a PlatformMessage response send back to the embedder.

type FlutterEngine

type FlutterEngine struct {
	// Flutter Engine.
	Engine C.FlutterEngine

	// GL callback functions
	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

	// task runner interop
	TaskRunnerRunOnCurrentThread func() bool
	TaskRunnerPostTask           func(trask FlutterTask, targetTimeNanos uint64)

	// platform message callback function
	PlatfromMessage func(message *PlatformMessage)

	// Engine arguments
	AssetsPath  string
	IcuDataPath string

	// AOT ELF snopshot path
	// only required for AOT app.
	ElfSnapshotPath string
	// contains filtered or unexported fields
}

FlutterEngine corresponds to the C.FlutterEngine with his associated callback's method.

func NewFlutterEngine

func NewFlutterEngine() *FlutterEngine

NewFlutterEngine creates an empty FlutterEngine.

func (*FlutterEngine) CreatePlatformMessageResponseHandle

func (flu *FlutterEngine) CreatePlatformMessageResponseHandle(callback *DataCallback) (PlatformMessageResponseHandle, error)

CreatePlatformMessageResponseHandle creates a platform message response handle that allows the embedder to set a native callback for a response to a message. Must be collected via `ReleasePlatformMessageResponseHandle` after the call to `SendPlatformMessage`.

func (*FlutterEngine) MarkExternalTextureFrameAvailable

func (flu *FlutterEngine) MarkExternalTextureFrameAvailable(textureID int64) error

MarkExternalTextureFrameAvailable marks that a new texture frame is available for a given texture identifier.

func (*FlutterEngine) RegisterExternalTexture

func (flu *FlutterEngine) RegisterExternalTexture(textureID int64) error

RegisterExternalTexture registers an external texture with a unique identifier.

func (*FlutterEngine) ReleasePlatformMessageResponseHandle

func (flu *FlutterEngine) ReleasePlatformMessageResponseHandle(responseHandle PlatformMessageResponseHandle)

ReleasePlatformMessageResponseHandle collects a platform message response handle.

func (*FlutterEngine) Run

func (flu *FlutterEngine) Run(userData unsafe.Pointer, vmArgs []string, dartArgs []string) error

Run launches the Flutter Engine in a background thread.

func (*FlutterEngine) RunTask

func (flu *FlutterEngine) RunTask(task *FlutterTask) error

RunTask inform the engine to run the specified task.

func (*FlutterEngine) SendPlatformMessage

func (flu *FlutterEngine) SendPlatformMessage(msg *PlatformMessage) error

SendPlatformMessage is used to send a PlatformMessage to the Flutter engine.

func (*FlutterEngine) SendPlatformMessageResponse

func (flu *FlutterEngine) SendPlatformMessageResponse(
	responseTo PlatformMessageResponseHandle,
	encodedMessage []byte,
) error

SendPlatformMessageResponse is used to send a message to the Flutter side using the correct ResponseHandle.

func (*FlutterEngine) SendPointerEvent

func (flu *FlutterEngine) SendPointerEvent(event PointerEvent) error

SendPointerEvent is used to send an PointerEvent to the Flutter engine.

func (*FlutterEngine) SendWindowMetricsEvent

func (flu *FlutterEngine) SendWindowMetricsEvent(event WindowMetricsEvent) error

SendWindowMetricsEvent is used to send a WindowMetricsEvent to the Flutter Engine.

func (*FlutterEngine) Shutdown

func (flu *FlutterEngine) Shutdown() error

Shutdown stops the Flutter engine.

func (*FlutterEngine) UnregisterExternalTexture

func (flu *FlutterEngine) UnregisterExternalTexture(textureID int64) error

UnregisterExternalTexture unregisters a previous texture registration.

func (*FlutterEngine) UpdateSystemLocale

func (flu *FlutterEngine) UpdateSystemLocale(lang, country, script string) error

UpdateSystemLocale is used to update the flutter locale to the system locale

type FlutterOpenGLTexture

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
}

FlutterOpenGLTexture corresponds to the C.FlutterOpenGLTexture struct.

type FlutterTask

type FlutterTask = C.FlutterTask

FlutterTask is a type alias to C.FlutterTask

type PlatformMessage

type PlatformMessage struct {
	Channel string
	Message []byte

	// ResponseHandle is set on some received platform message. All
	// PlatformMessage received with this attribute must send a response with
	// `SendPlatformMessageResponse`.
	// ResponseHandle can also be created from the embedder side when a
	// platform(golang) message needs native callback.
	ResponseHandle PlatformMessageResponseHandle
}

PlatformMessage represents a binary message sent from or to the flutter application.

func (PlatformMessage) ExpectsResponse

func (p PlatformMessage) ExpectsResponse() bool

ExpectsResponse indicates whether the platform message should receive a response.

type PlatformMessageResponseHandle

type PlatformMessageResponseHandle uintptr

PlatformMessageResponseHandle is a pointer that is used to wire a platform message response to the original platform message.

type PointerButtonMouse

type PointerButtonMouse int64

PointerButtonMouse corresponds to the C.enum describing the mouse buttons.

const (
	PointerButtonMousePrimary   PointerButtonMouse = C.kFlutterPointerButtonMousePrimary
	PointerButtonMouseSecondary PointerButtonMouse = C.kFlutterPointerButtonMouseSecondary
	PointerButtonMouseMiddle    PointerButtonMouse = C.kFlutterPointerButtonMouseMiddle
)

Values representing the mouse buttons.

type PointerDeviceKind

type PointerDeviceKind int32

PointerDeviceKind corresponds to the C.enum describing device kind of the mouse pointer.

const (
	PointerDeviceKindMouse PointerDeviceKind = C.kFlutterPointerDeviceKindMouse
	PointerDeviceKindTouch PointerDeviceKind = C.kFlutterPointerDeviceKindTouch
)

Values representing the pointer signal kind.

type PointerEvent

type PointerEvent struct {
	Phase        PointerPhase
	X            float64
	Y            float64
	SignalKind   PointerSignalKind
	ScrollDeltaX float64
	ScrollDeltaY float64
	Buttons      PointerButtonMouse
}

PointerEvent represents the position and phase of the mouse at a given time.

type PointerPhase

type PointerPhase int32

PointerPhase corresponds to the C.enum describing phase of the mouse pointer.

const (
	PointerPhaseCancel PointerPhase = C.kCancel
	PointerPhaseUp     PointerPhase = C.kUp
	PointerPhaseDown   PointerPhase = C.kDown
	PointerPhaseMove   PointerPhase = C.kMove
	PointerPhaseAdd    PointerPhase = C.kAdd
	PointerPhaseRemove PointerPhase = C.kRemove
	PointerPhaseHover  PointerPhase = C.kHover
)

Values representing the mouse phase.

type PointerSignalKind

type PointerSignalKind int32

PointerSignalKind corresponds to the C.enum describing signal kind of the mouse pointer.

const (
	PointerSignalKindNone   PointerSignalKind = C.kFlutterPointerSignalKindNone
	PointerSignalKindScroll PointerSignalKind = C.kFlutterPointerSignalKindScroll
)

Values representing the pointer signal kind.

type Result

type Result int32

Result corresponds to the C.enum retuned by the shared flutter library whenever we call it.

const (
	ResultSuccess               Result = C.kSuccess
	ResultInvalidLibraryVersion Result = C.kInvalidLibraryVersion
	ResultInvalidArguments      Result = C.kInvalidArguments
	ResultInternalInconsistency Result = C.kInternalInconsistency
	ResultEngineNotRunning      Result = -1
)

Values representing the status of an Result.

func (Result) GoError

func (res Result) GoError(caller string) error

GoError convert a FlutterEngineResult to a golang readable error

type WindowMetricsEvent

type WindowMetricsEvent struct {
	Width      int
	Height     int
	PixelRatio float64
}

WindowMetricsEvent represents a window's resolution.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL