This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Texture support for glfw. #9822
Closed
cloudwebrtc
wants to merge
33
commits into
flutter-team-archive:master
from
cloudwebrtc:texture_glfw
Closed
Changes from 10 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
5302cf8
Merge pull request #1 from flutter/master
cloudwebrtc 2953e13
Merge remote-tracking branch 'upstream/master'
cloudwebrtc 42b7502
Merge remote-tracking branch 'upstream/master'
cloudwebrtc ee2a336
Merge remote-tracking branch 'upstream/master'
cloudwebrtc bfd31aa
Merge remote-tracking branch 'upstream/master'
cloudwebrtc 08e9d07
Add Texture support for GLFW.
cloudwebrtc 0af9192
Fixed EventChannel for embedder.
cloudwebrtc bfb06c2
Fixed compiler error for stub_flutter_api.cc.
cloudwebrtc d6529fb
Update texture registrar for glfw.
cloudwebrtc 689f6e6
clang format.
cloudwebrtc e93c57c
Update.
cloudwebrtc eaec810
Update.
cloudwebrtc 63ad181
Add comments and code modify.
cloudwebrtc f07279e
Update DEPS
cloudwebrtc d1266a8
Update external_texture_gl.h
cloudwebrtc 7391e42
Fix compilation errors for linux and clang/gn format.
cloudwebrtc 4c5f065
Fix license check error.
cloudwebrtc 93fc359
Fixed the order of glad.h contains a run error.
cloudwebrtc 184a13a
Update.
cloudwebrtc 1c70e99
Merge remote-tracking branch 'upstream/master' into texture_glfw
cloudwebrtc 63e1469
Fixed engine type definition error.
cloudwebrtc 0669a9c
Merge remote-tracking branch 'upstream/master' into texture_glfw
cloudwebrtc 2ccfeef
Use the new `glad' dependency.
cloudwebrtc dd1bffb
Update.
cloudwebrtc c400937
fix typo.
cloudwebrtc 6456082
clang-format.
cloudwebrtc a46b562
update.
cloudwebrtc 3ecb5fd
Add comment.
cloudwebrtc e1b7a8b
Add unit tests for texture.
cloudwebrtc 4903666
update.
cloudwebrtc eed131a
update.
cloudwebrtc aba2fa2
update unit test.
cloudwebrtc d8efcdb
Fixed typo.
cloudwebrtc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_CHANNEL_H_ | ||
| #define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_CHANNEL_H_ | ||
|
|
||
| #include <iostream> | ||
| #include <string> | ||
|
|
||
| #include "binary_messenger.h" | ||
| #include "engine_method_result.h" | ||
| #include "message_codec.h" | ||
| #include "method_call.h" | ||
| #include "method_codec.h" | ||
| #include "method_result.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| template <typename T> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of the things in this file need declaration comments, per Google's C++ style guide.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This applies to all of the class declarations, method declarations, and typedefs in this PR, not just this file. |
||
| using SuccessHandler = std::function<void(const T *event)>; | ||
|
|
||
| template <typename T> | ||
| using ErrorHandler = | ||
| std::function<void(const std::string &errorCode, | ||
| const std::string &errorMessage, const T *errorDetails)>; | ||
|
|
||
| template <typename T> | ||
| struct EventSink { | ||
| SuccessHandler<T> Success; | ||
| ErrorHandler<T> Error; | ||
| }; | ||
|
|
||
| template <typename T> | ||
| struct StreamHandler { | ||
| std::function<MethodResult<T> *(const T *arguments, | ||
| const EventSink<T> *event_sink)> | ||
| onListen; | ||
| std::function<MethodResult<T> *(const T *arguments)> onCancel; | ||
| }; | ||
|
|
||
| template <typename T> | ||
| class EventChannel { | ||
| public: | ||
| EventChannel(BinaryMessenger *messenger, const std::string &name, | ||
| const MethodCodec<T> *codec) | ||
| : messenger_(messenger), name_(name), codec_(codec) {} | ||
| ~EventChannel() {} | ||
|
|
||
| // Prevent copying. | ||
| EventChannel(EventChannel const &) = delete; | ||
| EventChannel &operator=(EventChannel const &) = delete; | ||
|
|
||
| void SetStreamHandler(StreamHandler<T> stream_handler) { | ||
| stream_handler_ = stream_handler; | ||
| const auto messenger = messenger_; | ||
| std::string channel_name = name_; | ||
| const auto *codec = codec_; | ||
|
|
||
| EventSink<T> event_sink = {}; | ||
|
|
||
| event_sink.Success = [messenger, channel_name, codec](const T *events) { | ||
| std::unique_ptr<std::vector<uint8_t>> message = | ||
| codec->EncodeSuccessEnvelope(events); | ||
| messenger->Send(channel_name, message->data(), message->size()); | ||
| }; | ||
|
|
||
| event_sink.Error = [messenger, channel_name, codec]( | ||
| const std::string &errorCode, | ||
| const std::string &errorMessage, | ||
| const T *errorDetails) { | ||
| std::unique_ptr<std::vector<uint8_t>> message = | ||
| codec->EncodeErrorEnvelope(errorCode, errorMessage, errorDetails); | ||
| messenger->Send(channel_name, message->data(), message->size()); | ||
| }; | ||
|
|
||
| BinaryMessageHandler binary_handler = [&, event_sink, codec, channel_name]( | ||
| const uint8_t *message, | ||
| const size_t message_size, | ||
| BinaryReply reply) { | ||
| auto result = | ||
| std::make_unique<EngineMethodResult<T>>(std::move(reply), codec); | ||
| std::unique_ptr<MethodCall<T>> method_call = | ||
| codec->DecodeMethodCall(message, message_size); | ||
| if (!method_call) { | ||
| std::cerr << "Unable to construct method call from message on channel " | ||
| << channel_name << std::endl; | ||
| result->NotImplemented(); | ||
| return; | ||
| } | ||
| if (method_call->method_name().compare("listen") == 0) { | ||
| stream_handler_.onListen(method_call->arguments(), &event_sink); | ||
| result->Success(nullptr); | ||
| return; | ||
| } else if (method_call->method_name().compare("cancel") == 0) { | ||
| stream_handler_.onCancel(method_call->arguments()); | ||
| result->Success(nullptr); | ||
| return; | ||
| } else { | ||
| result->NotImplemented(); | ||
| } | ||
| }; | ||
|
|
||
| messenger_->SetMessageHandler(name_, std::move(binary_handler)); | ||
| } | ||
|
|
||
| private: | ||
| BinaryMessenger *messenger_; | ||
| std::string name_; | ||
| const MethodCodec<T> *codec_; | ||
| StreamHandler<T> stream_handler_; | ||
| }; | ||
|
|
||
| } // namespace flutter | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_CHANNEL_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_TEXTURE_REGISTRAR_H_ | ||
| #define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_TEXTURE_REGISTRAR_H_ | ||
|
|
||
| #include <flutter_texture_registrar.h> | ||
|
|
||
| #include <stdint.h> | ||
| #include <memory> | ||
|
|
||
| namespace flutter { | ||
|
|
||
| class Texture { | ||
| public: | ||
| virtual ~Texture() {} | ||
|
|
||
| virtual std::shared_ptr<GLFWPixelBuffer> CopyTextureBuffer(size_t width, | ||
| size_t height) = 0; | ||
| }; | ||
|
|
||
| class TextureRegistrar { | ||
| public: | ||
| virtual ~TextureRegistrar() {} | ||
|
|
||
| /** | ||
| * Register a |texture| object and return textureId. | ||
|
cloudwebrtc marked this conversation as resolved.
Outdated
|
||
| */ | ||
| virtual int64_t RegisterTexture(Texture *texture) = 0; | ||
|
|
||
| /** | ||
| * Mark a texture buffer is ready. | ||
|
cloudwebrtc marked this conversation as resolved.
Outdated
|
||
| */ | ||
| virtual void MarkTextureFrameAvailable(int64_t texture_id) = 0; | ||
|
|
||
| /** | ||
| * Unregister an existing Texture object. | ||
| */ | ||
| virtual void UnregisterTexture(int64_t texture_id) = 0; | ||
| }; | ||
|
|
||
| } // namespace flutter | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_TEXTURE_REGISTRAR_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
shell/platform/common/cpp/public/flutter_texture_registrar.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CPP_PUBLIC_FLUTTER_TEXTURE_REGISTRAR_H_ | ||
| #define FLUTTER_SHELL_PLATFORM_COMMON_CPP_PUBLIC_FLUTTER_TEXTURE_REGISTRAR_H_ | ||
|
|
||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
| #include <memory> | ||
|
|
||
| #include "flutter_export.h" | ||
|
|
||
| #if defined(__cplusplus) | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| // Opaque reference to a texture registrar. | ||
| typedef struct FlutterDesktopTextureRegistrar* | ||
| FlutterDesktopTextureRegistrarRef; | ||
|
|
||
| struct GLFWPixelBuffer { | ||
|
cloudwebrtc marked this conversation as resolved.
Outdated
|
||
| std::shared_ptr<uint8_t> buffer; | ||
| size_t width; | ||
| size_t height; | ||
| }; | ||
|
|
||
| typedef std::shared_ptr<GLFWPixelBuffer> (*FlutterTexutreCallback)( | ||
| size_t width, size_t height, void* user_data); | ||
|
|
||
| FLUTTER_EXPORT int64_t FlutterDesktopRegisterExternalTexture( | ||
| FlutterDesktopTextureRegistrarRef texture_registrar, | ||
| FlutterTexutreCallback texture_callback, void* user_data); | ||
|
|
||
| FLUTTER_EXPORT bool FlutterDesktopUnregisterExternalTexture( | ||
|
cloudwebrtc marked this conversation as resolved.
|
||
| FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id); | ||
|
|
||
| // Mark that a new texture frame is available for a given texture identifier. | ||
| FLUTTER_EXPORT bool FlutterDesktopMarkExternalTextureFrameAvailable( | ||
|
cloudwebrtc marked this conversation as resolved.
|
||
| FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id); | ||
|
|
||
| #if defined(__cplusplus) | ||
| } // extern "C" | ||
| #endif | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_PUBLIC_FLUTTER_TEXTURE_REGISTRAR_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split event channel support out into a separate precursor PR to keep the scope smaller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will submit event_channel.h in another PR.