-
Notifications
You must be signed in to change notification settings - Fork 6k
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 for glfw. #9822
Changes from 10 commits
5302cf8
2953e13
42b7502
ee2a336
bfd31aa
08e9d07
0af9192
bfb06c2
d6529fb
689f6e6
e93c57c
eaec810
63ad181
f07279e
d1266a8
7391e42
4c5f065
93fc359
184a13a
1c70e99
63e1469
0669a9c
2ccfeef
dd1bffb
c400937
6456082
a46b562
3ecb5fd
e1b7a8b
4903666
eed131a
aba2fa2
d8efcdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
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. 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_ |
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.
Show resolved
Hide resolved
|
||
*/ | ||
virtual int64_t RegisterTexture(Texture *texture) = 0; | ||
|
||
/** | ||
* Mark a texture buffer is ready. | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
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_ |
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.
Show resolved
Hide resolved
|
||
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.
Show resolved
Hide 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.
Show resolved
Hide 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_ |
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.