Skip to content

Support Texture widget #107

Closed
Closed
@cloudwebrtc

Description

@cloudwebrtc

We have ported the WebRTC plugin for iOS/Android, but there is no Texture widget in flutter-desktop-embedding, Texture is needed to support video rendering and video player development.

Activity

ghost

ghost commented on Jul 13, 2018

@ghost
cloudwebrtc

cloudwebrtc commented on Jul 13, 2018

@cloudwebrtc
ContributorAuthor

Yes, use C++ to write the plugins for all desktops.

stuartmorgan-g

stuartmorgan-g commented on Jul 13, 2018

@stuartmorgan-g
Collaborator

From a quick skim of the existing implementations it looks like Texture implementation requires access to engine APIs that aren't currently exposed via the embedding API.

@chinmaygarde Is that accurate?

ghost

ghost commented on Sep 19, 2018

@ghost

Not having the Texture implementation is a bit of s show stopper for me too. I want to use the Texture to push 2D and 3D graphics to the GUI.

Polite hint to @chinmaygarde. If you can comment on this ?

chinmaygarde

chinmaygarde commented on Sep 20, 2018

@chinmaygarde
Member

Apologies for the late reply.

Support for external textures to embedders is definitely something on the roadmap. Currently, external textures are handled very differently on iOS (CoreVideo) and Android (GL_OES_EGL_image_external) and so exposing the same to embedders is not straightforward. It would be great if we could collaborate on figuring out a few things first. For example, should the embedder API try to create an abstraction over textures on the various platforms or support platform specific APIs? In the specific case of the WebRTC plugin linked, I suspect the easiest way for the platform to express its textures would be in the form of CoreVideo pixel buffers. OTOH, on Linux, I suspect EGL images would be better. Should the embedder API support both platform specific APIs? Or, should the engine only deal with plain old GL_TEXTURE_2D objects and have the embedder render into the same. That would require sharing of the OpenGL context used by Flutter with the embedder or creating another context within the same sharegroup.

@cloudwebrtc: I think exposing the current support for CoreVideo and EGL_Image_External as-is would be the easiest way to support your use case.

@gedw99: How are you going to generate and update the textures with the graphics you mentioned? Are you going to push new textures (from a pool) to Flutter each frame or do you want to update the same texture? Are there threading restrictions to the way you are going to be generating your textures? Can you provide a reduced test case for how you want to generate your textures? That would be extremely helpful to try to pin down an API that works for the broadest audience. Thanks!

ghost

ghost commented on Sep 22, 2018

@ghost

Hey @chinmaygarde

Answers to the questions

How are you going to generate and update the textures with the graphics you mentioned?

  • generated using opengl buffers

Are you going to push new textures (from a pool) to Flutter each frame or do you want to update the same texture?

  • yes new textures

Are there threading restrictions to the way you are going to be generating your textures?

  • I will be computin the textures from many threads back to a singleton.

Can you provide a reduced test case for how you want to generate your textures?

  • Not yet. Its most a mish mash of test use cases.

Some Background:
I am building things like Inkscape for 2D editing or Blender for 3d editing if you need a well known analogy. At the end of the day they output a raster image to the Texture.
But whats interesting is that everything i am building is interactive in that there is a heavy use of the Flutter gestures to determine the users intent. The User interactions hints are rendering at the Dart / Flutter level - for example the cross hairs when moving an object in 3D or the orbit tool when doing a rotate or scale transformation of a 3D object. Or even when doing basic hit testing in 3D. The mutation is sent back to the backend and it produces a new texture.
Hopefully the background helps. I learnt a fair bit form looking at the Cloud Webrtc code too, although very different between IOS and Android. But they have a sink and a channel and the use cases i just describes have the same.

chinmaygarde

chinmaygarde commented on Dec 4, 2018

@chinmaygarde
Member

Engine patch with example embedder implementation has been posted flutter/engine#7087.
screen shot 2018-12-04 at 1 36 24 pm

cloudwebrtc

cloudwebrtc commented on Dec 16, 2018

@cloudwebrtc
ContributorAuthor

@chinmaygarde I used your branch to create a webrtc plugin example that seems to work fine, thank you.
@stuartmorgan @gedw99
I modified some code:
1, FLETextureDelegate needs to be placed in the FLEViewController.h public declaration in order to provide it to the external framework to link it.
https://github.com/cloudwebrtc/flutter-desktop-embedding/blob/flutter-webrtc/library/macos/FLEViewController.h#L21
2. I added a FlutterEventChannel object to adapt the listen method of the dart layer EventChannel.
https://github.com/cloudwebrtc/flutter-desktop-embedding/blob/flutter-webrtc/plugins/flutter_webrtc/macos/FlutterEventChannel.h

/**
 * An event sink callback.
 *
 * @param event The event.
 */
typedef void (^FlutterEventSink)(id _Nullable event);

extern NSObject const* FlutterEndOfEventStream;

@protocol FlutterStreamHandler

- (FLEMethodError* _Nullable)onListenWithArguments:(id _Nullable)arguments
                                       eventSink:(FlutterEventSink)events;

- (FLEMethodError* _Nullable)onCancelWithArguments:(id _Nullable)arguments;

@end

@interface FlutterEventChannel : NSObject

+ (instancetype)eventChannelWithName:(NSString*)name
                     binaryMessenger:(NSObject<FLEBinaryMessenger>*)messenger;

- (void)setStreamHandler:(NSObject<FlutterStreamHandler>* _Nullable)handler;
@end
  1. added a FlutterTextureRegistry class, adapted to the iOS-like Texture interface.
    https://github.com/cloudwebrtc/flutter-desktop-embedding/blob/flutter-webrtc/plugins/flutter_webrtc/macos/FlutterTextureRegistry.h
@protocol FlutterTexture<NSObject>
- (CVPixelBufferRef _Nullable)copyPixelBuffer;
@end

@protocol FlutterTextureRegistry<NSObject>
- (int64_t)registerTexture:(NSObject<FlutterTexture> *)texture;
- (void)textureFrameAvailable:(int64_t)textureId;
- (void)unregisterTexture:(int64_t)textureId;
@end

NS_ASSUME_NONNULL_BEGIN

@interface FLETextureRegister : NSObject<FlutterTextureRegistry, FLETextureDelegate>
@property(nullable, weak) FLEViewController *controller;
-(instancetype) initWithController:(FLEViewController *)controller;
@end

NS_ASSUME_NONNULL_END

Should I add FlutterEventChannel and FlutterTextureRegistry to FlutterEmbedderMac.framework?

Thanks again, the Linux/Win plugin should be easier to port, just copy the FlutterOpenGLTexture object and provide the GL_RGBA8 buffer.

For testing please refer to:flutter-webrtc/flutter-webrtc#37 (comment)

screenshots

stuartmorgan-g

stuartmorgan-g commented on Dec 16, 2018

@stuartmorgan-g
Collaborator

Should I add FlutterEventChannel and FlutterTextureRegistry to FlutterEmbedderMac.framework?

I'd be happy to accept a patch that adds FLEEventChannel (the naming convention I've been using for the macOS code in this project is to use FLE as a prefix, replacing Flutter when the iOS class starts with Flutter) and related classes to the framework!

It'll need to wait to land until the engine change lands though, and then the texture APIs will need to be added to the macOS framework (which will likely have some changes from what's in that branch), but feel free to start the PR whenever you like and it go through review in the meantime.

cloudwebrtc

cloudwebrtc commented on Dec 17, 2018

@cloudwebrtc
ContributorAuthor

Okay, I created a PR for FELEventChannel. #174

chinmaygarde

chinmaygarde commented on Jan 9, 2019

@chinmaygarde
Member

Engine support landed in flutter/engine#7087

cloudwebrtc

cloudwebrtc commented on Feb 1, 2019

@cloudwebrtc
ContributorAuthor

New PR for FLETexture on [macOS] #263.

stuartmorgan-g

stuartmorgan-g commented on Apr 8, 2019

@stuartmorgan-g
Collaborator

Moved to flutter/flutter#30717 and flutter/flutter#30718

@cloudwebrtc If you are still interested in moving forward with #263, 30717 would be the bug to associate a flutter/engine PR with.

tttzof351

tttzof351 commented on May 3, 2019

@tttzof351

How I understand for start work with flutter Texture widget, I must get TextureRegister from plugin, but for linux target platform in PluginRegistrar or FlutterDesktopPluginRegistrarRef I can't see method or ref like Registrar::texture() for get TextureRegistry

stuartmorgan-g

stuartmorgan-g commented on May 4, 2019

@stuartmorgan-g
Collaborator

See my last comment; this bug is closed because the relevant code is in Flutter now, and the open bugs tracking the work are there now. The right place for your question is flutter/flutter#30718 (where there's a link to a patch with an implementation, which should answer your question).

chichid

chichid commented on Oct 6, 2019

@chichid

Is texture widget supported on Windows at all?

stuartmorgan-g

stuartmorgan-g commented on Oct 6, 2019

@stuartmorgan-g
Collaborator
locked as resolved and limited conversation to collaborators on Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @chinmaygarde@stuartmorgan-g@tttzof351@chichid@cloudwebrtc

        Issue actions

          Support Texture widget · Issue #107 · google/flutter-desktop-embedding