Skip to content
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

Add windows plugin texture support #19405

Merged
merged 18 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0c365e9
Add windows plugin texture support
jnschulze Jun 30, 2020
f07da6f
[windows] Rename Texture to PixelBufferTexture and make it a variant
jnschulze Nov 17, 2020
a44de99
Embedder API: Add PostPlatformThreadTask method
jnschulze Nov 18, 2020
92279aa
Windows textures: Allow calling MarkTextureFrameAvailable from arbitr…
jnschulze Nov 18, 2020
0c1c2f1
Windows textures: Do review-related cleanup
jnschulze Jan 7, 2021
f3d0dc4
Windows textures: Remove message when copying a pixel buffer fails as…
jnschulze Jan 7, 2021
b94d4f4
Embedder API: Add missing FlutterEnginePostPlatformThreadTask declara…
jnschulze Jan 7, 2021
018e479
Embedder API: Move PostPlatformThreadTask to end of proc table
jnschulze Jan 7, 2021
d9e7d5e
Windows textures: Make PixelBufferTexture's copy cb return type const
jnschulze Jan 7, 2021
6a8a20e
Windows: Extend TaskRunner to allow direct posting
jnschulze Jan 8, 2021
256db6a
Windows textures: Use TaskRunner::PostTask
jnschulze Jan 8, 2021
fa22152
Revert "Embedder API: Add PostPlatformThreadTask method"
jnschulze Jan 8, 2021
cfe1b34
Windows textures: Make texture registration/unregistration thread safe
jnschulze Jan 8, 2021
1d8057d
Windows textures: Improve comments in terms of thread safety
jnschulze Jan 8, 2021
c69c927
Windows task runner: PostTask: Remove unused target_time parameter
jnschulze Jan 11, 2021
8e2a2bc
Windows textures: minimize lock scope
jnschulze Jan 11, 2021
3e9977e
Windows textures: Clean up comments
jnschulze Jan 11, 2021
f4d3608
Merge branch 'master' into feature/windows-textures
jnschulze Jan 13, 2021
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
9 changes: 9 additions & 0 deletions ci/licenses_golden/licenses_flutter
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,7 @@ FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_codec_serializer.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/method_call_unittests.cc
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/method_channel_unittests.cc
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/method_result_functions_unittests.cc
Expand All @@ -1674,6 +1675,8 @@ FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/plugin_registrar
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/standard_codec.cc
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/standard_message_codec_unittests.cc
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/standard_method_codec_unittests.cc
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/texture_registrar_impl.h
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/texture_registrar_unittests.cc
FILE: ../../../flutter/shell/platform/common/cpp/engine_switches.cc
FILE: ../../../flutter/shell/platform/common/cpp/engine_switches.h
FILE: ../../../flutter/shell/platform/common/cpp/engine_switches_unittests.cc
Expand All @@ -1691,6 +1694,7 @@ FILE: ../../../flutter/shell/platform/common/cpp/path_utils_unittests.cc
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/common/cpp/text_input_model_unittests.cc
Expand Down Expand Up @@ -2179,13 +2183,18 @@ FILE: ../../../flutter/shell/platform/windows/client_wrapper/include/flutter/plu
FILE: ../../../flutter/shell/platform/windows/client_wrapper/plugin_registrar_windows_unittests.cc
FILE: ../../../flutter/shell/platform/windows/cursor_handler.cc
FILE: ../../../flutter/shell/platform/windows/cursor_handler.h
FILE: ../../../flutter/shell/platform/windows/external_texture_gl.cc
FILE: ../../../flutter/shell/platform/windows/external_texture_gl.h
FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle.cc
FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle.h
FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle_unittests.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows_engine.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows_engine.h
FILE: ../../../flutter/shell/platform/windows/flutter_windows_engine_unittests.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows_texture_registrar.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows_texture_registrar.h
FILE: ../../../flutter/shell/platform/windows/flutter_windows_texture_registrar_unittests.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.h
FILE: ../../../flutter/shell/platform/windows/flutter_windows_win32.cc
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 @@ -13,6 +13,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
1 change: 1 addition & 0 deletions shell/platform/common/cpp/client_wrapper/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ executable("client_wrapper_unittests") {
"standard_method_codec_unittests.cc",
"testing/test_codec_extensions.cc",
"testing/test_codec_extensions.h",
"texture_registrar_unittests.cc",
]

deps = [
Expand Down
42 changes: 42 additions & 0 deletions shell/platform/common/cpp/client_wrapper/core_implementations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

#include <cassert>
#include <iostream>
#include <variant>

#include "binary_messenger_impl.h"
#include "include/flutter/engine_method_result.h"
#include "texture_registrar_impl.h"

namespace flutter {

Expand Down Expand Up @@ -146,4 +148,44 @@ void ReplyManager::SendResponseData(const std::vector<uint8_t>* data) {

} // namespace internal

// ========== texture_registrar_impl.h ==========

TextureRegistrarImpl::TextureRegistrarImpl(
FlutterDesktopTextureRegistrarRef texture_registrar_ref)
: texture_registrar_ref_(texture_registrar_ref) {}

TextureRegistrarImpl::~TextureRegistrarImpl() = default;

int64_t TextureRegistrarImpl::RegisterTexture(TextureVariant* texture) {
if (auto pixel_buffer_texture = std::get_if<PixelBufferTexture>(texture)) {
FlutterDesktopTextureInfo info = {};
info.type = kFlutterDesktopPixelBufferTexture;
info.pixel_buffer_config.user_data = pixel_buffer_texture;
info.pixel_buffer_config.callback =
[](size_t width, size_t height,
void* user_data) -> const FlutterDesktopPixelBuffer* {
auto texture = static_cast<PixelBufferTexture*>(user_data);
auto buffer = texture->CopyPixelBuffer(width, height);
return buffer;
};

int64_t texture_id = FlutterDesktopTextureRegistrarRegisterExternalTexture(
texture_registrar_ref_, &info);
return texture_id;
}

std::cerr << "Attempting to register unknown texture variant." << std::endl;
return -1;
} // namespace flutter

bool TextureRegistrarImpl::MarkTextureFrameAvailable(int64_t texture_id) {
return FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(
texture_registrar_ref_, texture_id);
}

bool TextureRegistrarImpl::UnregisterTexture(int64_t texture_id) {
return FlutterDesktopTextureRegistrarUnregisterExternalTexture(
texture_registrar_ref_, texture_id);
}

} // namespace flutter
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ core_cpp_client_wrapper_includes =
"include/flutter/standard_codec_serializer.h",
"include/flutter/standard_message_codec.h",
"include/flutter/standard_method_codec.h",
"include/flutter/texture_registrar.h",
],
"abspath")

Expand All @@ -34,6 +35,7 @@ core_cpp_client_wrapper_internal_headers =
get_path_info([
"binary_messenger_impl.h",
"byte_buffer_streams.h",
"texture_registrar_impl.h",
],
"abspath")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string>

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

namespace flutter {

Expand Down Expand Up @@ -41,6 +42,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* texture_registrar() { return texture_registrar_.get(); }

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

std::unique_ptr<BinaryMessenger> messenger_;

std::unique_ptr<TextureRegistrar> texture_registrar_;

// 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,67 @@
// 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 <cstdint>

#include <memory>
#include <variant>

#include <functional>
jnschulze marked this conversation as resolved.
Show resolved Hide resolved

namespace flutter {

// A pixel buffer texture.
class PixelBufferTexture {
public:
// A callback used for retrieving pixel buffers.
typedef std::function<const FlutterDesktopPixelBuffer*(size_t width,
size_t height)>
CopyBufferCb;
jnschulze marked this conversation as resolved.
Show resolved Hide resolved

// Creates a pixel buffer texture that uses the provided |copy_buffer_cb| to
// retrieve the buffer.
PixelBufferTexture(CopyBufferCb copy_buffer_cb)
: copy_buffer_cb_(copy_buffer_cb) {}

// Returns the callback-provided FlutterDesktopPixelBuffer that contains the
// actual pixel data. The intended surface size is specified by |width| and
// |height|.
const FlutterDesktopPixelBuffer* CopyPixelBuffer(size_t width,
size_t height) const {
return copy_buffer_cb_(width, height);
}

private:
const CopyBufferCb copy_buffer_cb_;
};

// The available texture variants.
// While PixelBufferTexture is the only implementation we currently have,
jnschulze marked this conversation as resolved.
Show resolved Hide resolved
// this is going to be extended once we have additional implementations like
jnschulze marked this conversation as resolved.
Show resolved Hide resolved
// PBO-based textures etc.
typedef std::variant<PixelBufferTexture> TextureVariant;
jnschulze marked this conversation as resolved.
Show resolved Hide resolved

// An object keeping track of external textures.
class TextureRegistrar {
jnschulze marked this conversation as resolved.
Show resolved Hide resolved
public:
virtual ~TextureRegistrar() = default;

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

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

// Unregisters an existing Texture object.
virtual bool UnregisterTexture(int64_t texture_id) = 0;
};

} // namespace flutter

#endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_TEXTURE_REGISTRAR_H_
6 changes: 6 additions & 0 deletions shell/platform/common/cpp/client_wrapper/plugin_registrar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "binary_messenger_impl.h"
#include "include/flutter/engine_method_result.h"
#include "include/flutter/method_channel.h"
#include "texture_registrar_impl.h"

namespace flutter {

Expand All @@ -19,6 +20,11 @@ PluginRegistrar::PluginRegistrar(FlutterDesktopPluginRegistrarRef registrar)
: registrar_(registrar) {
auto core_messenger = FlutterDesktopPluginRegistrarGetMessenger(registrar_);
messenger_ = std::make_unique<BinaryMessengerImpl>(core_messenger);

auto texture_registrar =
FlutterDesktopRegistrarGetTextureRegistrar(registrar_);
texture_registrar_ =
std::make_unique<TextureRegistrarImpl>(texture_registrar);
}

PluginRegistrar::~PluginRegistrar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,15 @@ TEST(PluginRegistrarTest, ManagerRemovesOnDestruction) {
nullptr);
}

// Tests that the texture registrar getter returns a non-null TextureRegistrar
TEST(PluginRegistrarTest, TextureRegistrarNotNull) {
auto dummy_registrar_handle =
reinterpret_cast<FlutterDesktopPluginRegistrarRef>(1);
PluginRegistrar registrar(dummy_registrar_handle);

TextureRegistrar* texture_registrar = registrar.texture_registrar();

ASSERT_NE(texture_registrar, nullptr);
}
jnschulze marked this conversation as resolved.
Show resolved Hide resolved

} // namespace flutter
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,41 @@ void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger,
s_stub_implementation->MessengerSetCallback(channel, callback, user_data);
}
}

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

int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture(
FlutterDesktopTextureRegistrarRef texture_registrar,
const FlutterDesktopTextureInfo* info) {
uint64_t result = -1;
if (s_stub_implementation) {
result =
s_stub_implementation->TextureRegistrarRegisterExternalTexture(info);
}
return result;
}

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

bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(
FlutterDesktopTextureRegistrarRef texture_registrar,
int64_t texture_id) {
bool result = false;
if (s_stub_implementation) {
result = s_stub_implementation->TextureRegistrarMarkTextureFrameAvailable(
texture_id);
}
return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ class StubFlutterApi {
virtual void MessengerSetCallback(const char* channel,
FlutterDesktopMessageCallback callback,
void* user_data) {}

// Called for FlutterDesktopRegisterExternalTexture.
virtual int64_t TextureRegistrarRegisterExternalTexture(
const FlutterDesktopTextureInfo* info) {
return -1;
}

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

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

// A test helper that owns a stub implementation, making it the test stub for
Expand Down
40 changes: 40 additions & 0 deletions shell/platform/common/cpp/client_wrapper/texture_registrar_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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_TEXTURE_REGISTRAR_IMPL_H_
#define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_TEXTURE_REGISTRAR_IMPL_H_

#include "include/flutter/texture_registrar.h"

namespace flutter {

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

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

// |flutter::TextureRegistrar|
int64_t RegisterTexture(TextureVariant* texture) override;
jnschulze marked this conversation as resolved.
Show resolved Hide resolved

// |flutter::TextureRegistrar|
bool MarkTextureFrameAvailable(int64_t texture_id) override;

// |flutter::TextureRegistrar|
bool UnregisterTexture(int64_t texture_id) override;

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

} // namespace flutter

#endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_TEXTURE_REGISTRAR_IMPL_H_
Loading