5#include "flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h"
11#include "flutter/fml/synchronization/waitable_event.h"
12#include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h"
13#include "flutter/shell/platform/common/client_wrapper/testing/stub_flutter_api.h"
14#include "gtest/gtest.h"
21class TestApi :
public testing::StubFlutterApi {
23 struct FakePixelBufferTexture {
31 int64_t TextureRegistrarRegisterExternalTexture(
35 auto texture = std::make_unique<FakePixelBufferTexture>();
36 texture->texture_callback =
info->pixel_buffer_config.callback;
37 texture->user_data =
info->pixel_buffer_config.user_data;
39 texture->texture_id = last_texture_id_;
41 textures_[last_texture_id_] = std::move(
texture);
42 return last_texture_id_;
45 void TextureRegistrarUnregisterExternalTexture(
50 if (it != textures_.end()) {
58 bool TextureRegistrarMarkTextureFrameAvailable(int64_t
texture_id)
override {
60 if (it != textures_.end()) {
61 it->second->mark_count++;
67 FakePixelBufferTexture* GetFakeTexture(int64_t
texture_id) {
69 if (it != textures_.end()) {
70 return it->second.get();
75 int64_t last_texture_id() {
return last_texture_id_; }
77 size_t textures_size() {
return textures_.size(); }
80 int64_t last_texture_id_ = -1;
81 std::map<int64_t, std::unique_ptr<FakePixelBufferTexture>> textures_;
87TEST(TextureRegistrarTest, RegisterUnregisterTexture) {
89 auto test_api =
static_cast<TestApi*
>(scoped_api_stub.
stub());
91 auto dummy_registrar_handle =
95 ASSERT_NE(textures,
nullptr);
97 EXPECT_EQ(test_api->last_texture_id(), -1);
98 auto texture = test_api->GetFakeTexture(0);
101 auto pixel_buffer_texture = std::make_unique<TextureVariant>(
104 EXPECT_EQ(test_api->last_texture_id(),
texture_id);
105 EXPECT_EQ(test_api->textures_size(),
static_cast<size_t>(1));
110 std::get_if<PixelBufferTexture>(pixel_buffer_texture.get()));
116 EXPECT_EQ(
texture->mark_count, 3);
120 unregister_latch.
Wait();
124 EXPECT_EQ(test_api->textures_size(),
static_cast<size_t>(0));
129TEST(TextureRegistrarTest, UnregisterInvalidTexture) {
130 auto dummy_registrar_handle =
143TEST(TextureRegistrarTest, MarkFrameAvailableInvalidTexture) {
144 auto dummy_registrar_handle =
151 EXPECT_FALSE(success);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
TextureRegistrar * texture_registrar()
virtual void UnregisterTexture(int64_t texture_id, std::function< void()> callback)=0
virtual bool MarkTextureFrameAvailable(int64_t texture_id)=0
virtual int64_t RegisterTexture(TextureVariant *texture)=0
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
const FlutterDesktopPixelBuffer *(* FlutterDesktopPixelBufferTextureCallback)(size_t width, size_t height, void *user_data)
TEST(FrameTimingsRecorderTest, RecordVsync)
FlutterDesktopPixelBufferTextureCallback texture_callback
#define EXPECT_TRUE(handle)