Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all 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 Mar 28, 2019
2953e13
Merge remote-tracking branch 'upstream/master'
cloudwebrtc Apr 9, 2019
42b7502
Merge remote-tracking branch 'upstream/master'
cloudwebrtc Apr 18, 2019
ee2a336
Merge remote-tracking branch 'upstream/master'
cloudwebrtc Jun 23, 2019
bfd31aa
Merge remote-tracking branch 'upstream/master'
cloudwebrtc Jul 11, 2019
08e9d07
Add Texture support for GLFW.
cloudwebrtc Jul 11, 2019
0af9192
Fixed EventChannel for embedder.
cloudwebrtc Jul 12, 2019
bfb06c2
Fixed compiler error for stub_flutter_api.cc.
cloudwebrtc Jul 12, 2019
d6529fb
Update texture registrar for glfw.
cloudwebrtc Jul 12, 2019
689f6e6
clang format.
cloudwebrtc Jul 13, 2019
e93c57c
Update.
cloudwebrtc Jul 14, 2019
eaec810
Update.
cloudwebrtc Jul 14, 2019
63ad181
Add comments and code modify.
cloudwebrtc Jul 16, 2019
f07279e
Update DEPS
cloudwebrtc Jul 16, 2019
d1266a8
Update external_texture_gl.h
cloudwebrtc Jul 16, 2019
7391e42
Fix compilation errors for linux and clang/gn format.
cloudwebrtc Jul 16, 2019
4c5f065
Fix license check error.
cloudwebrtc Jul 16, 2019
93fc359
Fixed the order of glad.h contains a run error.
cloudwebrtc Jul 21, 2019
184a13a
Update.
cloudwebrtc Sep 13, 2019
1c70e99
Merge remote-tracking branch 'upstream/master' into texture_glfw
cloudwebrtc Sep 14, 2019
63e1469
Fixed engine type definition error.
cloudwebrtc Sep 14, 2019
0669a9c
Merge remote-tracking branch 'upstream/master' into texture_glfw
cloudwebrtc Sep 24, 2019
2ccfeef
Use the new `glad' dependency.
cloudwebrtc Sep 24, 2019
dd1bffb
Update.
cloudwebrtc Sep 24, 2019
c400937
fix typo.
cloudwebrtc Sep 24, 2019
6456082
clang-format.
cloudwebrtc Sep 24, 2019
a46b562
update.
cloudwebrtc Oct 7, 2019
3ecb5fd
Add comment.
cloudwebrtc Oct 7, 2019
e1b7a8b
Add unit tests for texture.
cloudwebrtc Oct 8, 2019
4903666
update.
cloudwebrtc Oct 10, 2019
eed131a
update.
cloudwebrtc Nov 7, 2019
aba2fa2
update unit test.
cloudwebrtc Nov 7, 2019
d8efcdb
Fixed typo.
cloudwebrtc Dec 9, 2019
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
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_message_codec.h
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_method_codec.h
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/json_message_codec.cc
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/json_method_codec.cc
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/method_call_unittests.cc
Expand All @@ -704,6 +705,7 @@ FILE: ../../../flutter/shell/platform/common/cpp/incoming_message_dispatcher.h
FILE: ../../../flutter/shell/platform/common/cpp/public/flutter_export.h
FILE: ../../../flutter/shell/platform/common/cpp/public/flutter_messenger.h
FILE: ../../../flutter/shell/platform/common/cpp/public/flutter_plugin_registrar.h
FILE: ../../../flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h
FILE: ../../../flutter/shell/platform/common/cpp/text_input_model.cc
FILE: ../../../flutter/shell/platform/common/cpp/text_input_model.h
FILE: ../../../flutter/shell/platform/darwin/common/buffer_conversions.h
Expand Down Expand Up @@ -993,6 +995,8 @@ FILE: ../../../flutter/shell/platform/glfw/client_wrapper/flutter_window_control
FILE: ../../../flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window.h
FILE: ../../../flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h
FILE: ../../../flutter/shell/platform/glfw/client_wrapper/include/flutter/plugin_registrar_glfw.h
FILE: ../../../flutter/shell/platform/glfw/external_texture_gl.cc
FILE: ../../../flutter/shell/platform/glfw/external_texture_gl.h
FILE: ../../../flutter/shell/platform/glfw/flutter_glfw.cc
FILE: ../../../flutter/shell/platform/glfw/glfw_event_loop.cc
FILE: ../../../flutter/shell/platform/glfw/glfw_event_loop.h
Expand Down
1 change: 1 addition & 0 deletions shell/platform/common/cpp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ _public_headers = [
"public/flutter_export.h",
"public/flutter_messenger.h",
"public/flutter_plugin_registrar.h",
"public/flutter_texture_registrar.h",
]

# Any files that are built by clients (client_wrapper code, library headers for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ core_cpp_client_wrapper_includes =
"include/flutter/method_result.h",
"include/flutter/plugin_registrar.h",
"include/flutter/plugin_registry.h",
"include/flutter/texture_registrar.h",
"include/flutter/standard_message_codec.h",
"include/flutter/standard_method_codec.h",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <flutter_plugin_registrar.h>

#include "binary_messenger.h"
#include "texture_registrar.h"

namespace flutter {

Expand Down Expand Up @@ -40,6 +41,10 @@ class PluginRegistrar {
// This pointer will remain valid for the lifetime of this instance.
BinaryMessenger* messenger() { return messenger_.get(); }

// Returns the texture registrar to use for the plugin to render a pixel
// buffer.
TextureRegistrar* textures() { return textures_.get(); }

// Takes ownership of |plugin|.
//
// Plugins are not required to call this method if they have other lifetime
Expand All @@ -59,6 +64,8 @@ class PluginRegistrar {

std::unique_ptr<BinaryMessenger> messenger_;

std::unique_ptr<TextureRegistrar> textures_;

// Plugins registered for ownership.
std::set<std::unique_ptr<Plugin>> plugins_;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 {

// An external texture interface declaration.
class Texture {
public:
virtual ~Texture() {}
// This interface is used to respond to texture copy requests from the Flutter
// engine, Flutter engine will be providing the |height| and |width|
// parameters of bounds. In some cases, the user can be scale the texture to
// the size of the bounds to reduce memory usage.
virtual const PixelBuffer* CopyPixelBuffer(size_t width, size_t height) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the ownership model of the return value here? If it's a copy presumably something needs to release it, but in that case I would expect a unique_ptr. The meaning/use of the return value needs to be clearly documented.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be addressed.

};

class TextureRegistrar {
public:
virtual ~TextureRegistrar() {}

/**
* Registers a |texture| object and returns the ID for that texture.
*/
virtual int64_t RegisterTexture(Texture* texture) = 0;

/**
* Notify the flutter engine that the texture object corresponding
* to |texure_id| needs to render a new texture.
*/
virtual void MarkTextureFrameAvailable(int64_t texture_id) = 0;

/**
* Unregisters 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_
40 changes: 40 additions & 0 deletions shell/platform/common/cpp/client_wrapper/plugin_registrar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,52 @@ void BinaryMessengerImpl::SetMessageHandler(const std::string& channel,
ForwardToHandler, message_handler);
}

// Wrapper around a FlutterDesktopTextureRegistrarRef that implements the
// TextureRegistrar API.
class TextureRegistrarImpl : public TextureRegistrar {
public:
explicit TextureRegistrarImpl(
FlutterDesktopTextureRegistrarRef texture_registrar_ref)
: texture_registrar_ref_(texture_registrar_ref) {}

virtual ~TextureRegistrarImpl() = default;

// Prevent copying.
TextureRegistrarImpl(TextureRegistrarImpl const&) = delete;
TextureRegistrarImpl& operator=(TextureRegistrarImpl const&) = delete;

virtual int64_t RegisterTexture(Texture* texture) override {
FlutterTextureCallback callback =
[](size_t width, size_t height, void* user_data) -> const PixelBuffer* {
return static_cast<Texture*>(user_data)->CopyPixelBuffer(width, height);
};
int64_t texture_id = FlutterDesktopRegisterExternalTexture(
texture_registrar_ref_, callback, texture);
return texture_id;
}

virtual void MarkTextureFrameAvailable(int64_t texture_id) override {
FlutterDesktopMarkExternalTextureFrameAvailable(texture_registrar_ref_,
texture_id);
}

virtual void UnregisterTexture(int64_t texture_id) override {
FlutterDesktopUnregisterExternalTexture(texture_registrar_ref_, texture_id);
}

private:
// Handle for interacting with the C API.
FlutterDesktopTextureRegistrarRef texture_registrar_ref_;
};

// PluginRegistrar:

PluginRegistrar::PluginRegistrar(FlutterDesktopPluginRegistrarRef registrar)
: registrar_(registrar) {
auto core_messenger = FlutterDesktopRegistrarGetMessenger(registrar_);
messenger_ = std::make_unique<BinaryMessengerImpl>(core_messenger);
auto texture_registrar = FlutterDesktopGetTextureRegistrar(registrar_);
textures_ = std::make_unique<TextureRegistrarImpl>(texture_registrar);
}

PluginRegistrar::~PluginRegistrar() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <map>
#include <memory>
#include <vector>

#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h"
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h"
#include "flutter/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h"
#include "gtest/gtest.h"

Expand All @@ -15,6 +17,14 @@ namespace {

// Stub implementation to validate calls to the API.
class TestApi : public testing::StubFlutterApi {
public:
struct FakeTexture {
int64_t texture_id;
int32_t mark_count;
FlutterTextureCallback texture_callback;
void* user_data;
};

public:
// |flutter::testing::StubFlutterApi|
bool MessengerSend(const char* channel,
Expand All @@ -34,8 +44,53 @@ class TestApi : public testing::StubFlutterApi {

const uint8_t* last_data_sent() { return last_data_sent_; }

int64_t RegisterExternalTexture(FlutterTextureCallback texture_callback,
void* user_data) override {
last_texture_id_++;

auto texture = std::make_unique<FakeTexture>();
texture->texture_callback = texture_callback;
texture->user_data = user_data;
texture->mark_count = 0;
texture->texture_id = last_texture_id_;

textures_[last_texture_id_] = std::move(texture);
return last_texture_id_;
}

bool UnregisterExternalTexture(int64_t texture_id) override {
auto it = textures_.find(texture_id);
if (it != textures_.end()) {
textures_.erase(it);
return true;
}
return false;
}

bool TextureFrameAvailable(int64_t texture_id) override {
auto it = textures_.find(texture_id);
if (it != textures_.end()) {
it->second->mark_count++;
return true;
}
return false;
}

FakeTexture* GetFakeTexture(int64_t texture_id) {
auto it = textures_.find(texture_id);
if (it != textures_.end())
return it->second.get();
return nullptr;
}

int64_t last_texture_id() { return last_texture_id_; }

size_t textures_size() { return textures_.size(); }

private:
const uint8_t* last_data_sent_ = nullptr;
int64_t last_texture_id_ = -1;
std::map<int64_t, std::unique_ptr<FakeTexture>> textures_;
};

} // namespace
Expand All @@ -55,4 +110,37 @@ TEST(MethodCallTest, MessengerSend) {
EXPECT_EQ(test_api->last_data_sent(), &message[0]);
}

// Tests texture register that calls through to the C API.
TEST(MethodCallTest, RegisterTexture) {
testing::ScopedStubFlutterApi scoped_api_stub(std::make_unique<TestApi>());
auto test_api = static_cast<TestApi*>(scoped_api_stub.stub());

auto dummy_registrar_handle =
reinterpret_cast<FlutterDesktopPluginRegistrarRef>(1);
PluginRegistrar registrar(dummy_registrar_handle);
TextureRegistrar* textures = registrar.textures();

EXPECT_EQ(test_api->last_texture_id(), -1);
auto texture = test_api->GetFakeTexture(0);
EXPECT_EQ(texture, nullptr);

int64_t texture_id = textures->RegisterTexture(reinterpret_cast<Texture*>(2));
EXPECT_EQ(test_api->last_texture_id(), texture_id);
EXPECT_EQ(test_api->textures_size(), static_cast<size_t>(1));

texture = test_api->GetFakeTexture(texture_id);
EXPECT_EQ(texture->texture_id, texture_id);
EXPECT_EQ(texture->user_data, reinterpret_cast<Texture*>(2));

textures->MarkTextureFrameAvailable(texture_id);
textures->MarkTextureFrameAvailable(texture_id);
textures->MarkTextureFrameAvailable(texture_id);
EXPECT_EQ(texture->mark_count, 3);

textures->UnregisterTexture(texture_id);
texture = test_api->GetFakeTexture(texture_id);
EXPECT_EQ(texture, nullptr);
EXPECT_EQ(test_api->textures_size(), static_cast<size_t>(0));
}

} // namespace flutter
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,43 @@ FlutterDesktopMessengerRef FlutterDesktopRegistrarGetMessenger(
return reinterpret_cast<FlutterDesktopMessengerRef>(1);
}

FlutterDesktopTextureRegistrarRef FlutterDesktopGetTextureRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
return reinterpret_cast<FlutterDesktopTextureRegistrarRef>(1);
}

int64_t FlutterDesktopRegisterExternalTexture(
FlutterDesktopTextureRegistrarRef texture_registrar,
FlutterTextureCallback texture_callback,
void* user_data) {
uint64_t result = -1;
if (s_stub_implementation) {
result = s_stub_implementation->RegisterExternalTexture(texture_callback,
user_data);
}
return result;
}

bool FlutterDesktopUnregisterExternalTexture(
FlutterDesktopTextureRegistrarRef texture_registrar,
int64_t texture_id) {
bool result = false;
if (s_stub_implementation) {
result = s_stub_implementation->UnregisterExternalTexture(texture_id);
}
return result;
}

bool FlutterDesktopMarkExternalTextureFrameAvailable(
FlutterDesktopTextureRegistrarRef texture_registrar,
int64_t texture_id) {
bool result = false;
if (s_stub_implementation) {
result = s_stub_implementation->TextureFrameAvailable(texture_id);
}
return result;
}

void FlutterDesktopRegistrarEnableInputBlocking(
FlutterDesktopPluginRegistrarRef registrar,
const char* channel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ class StubFlutterApi {
virtual void MessengerSetCallback(const char* channel,
FlutterDesktopMessageCallback callback,
void* user_data) {}

// Called for FlutterDesktopRegisterExternalTexture.
virtual int64_t RegisterExternalTexture(
FlutterTextureCallback texture_callback,
void* user_data) {
return -1;
}

// Called for FlutterDesktopUnregisterExternalTexture.
virtual bool UnregisterExternalTexture(int64_t texture_id) { return false; }

// Called for FlutterDesktopMarkExternalTextureFrameAvailable.
virtual bool TextureFrameAvailable(int64_t texture_id) { return false; }
};

// A test helper that owns a stub implementation, making it the test stub for
Expand Down
5 changes: 5 additions & 0 deletions shell/platform/common/cpp/public/flutter_plugin_registrar.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "flutter_export.h"
#include "flutter_messenger.h"
#include "flutter_texture_registrar.h"

#if defined(__cplusplus)
extern "C" {
Expand All @@ -22,6 +23,10 @@ typedef struct FlutterDesktopPluginRegistrar* FlutterDesktopPluginRegistrarRef;
FLUTTER_EXPORT FlutterDesktopMessengerRef
FlutterDesktopRegistrarGetMessenger(FlutterDesktopPluginRegistrarRef registrar);

// Returns the texture registrar associated with this registrar.
FLUTTER_EXPORT FlutterDesktopTextureRegistrarRef
FlutterDesktopGetTextureRegistrar(FlutterDesktopPluginRegistrarRef registrar);

// Enables input blocking on the given channel.
//
// If set, then the Flutter window will disable input callbacks
Expand Down
Loading