11 #include "flutter/fml/synchronization/waitable_event.h" 
   13 #include "flutter/shell/platform/common/client_wrapper/testing/stub_flutter_api.h" 
   14 #include "gtest/gtest.h" 
   21 class TestApi : 
public testing::StubFlutterApi {
 
   23   struct FakePixelBufferTexture {
 
   31   int64_t TextureRegistrarRegisterExternalTexture(
 
   35     auto texture = std::make_unique<FakePixelBufferTexture>();
 
   38     texture->mark_count = 0;
 
   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_;
 
   87 TEST(TextureRegistrarTest, RegisterUnregisterTexture) {
 
   88   testing::ScopedStubFlutterApi scoped_api_stub(std::make_unique<TestApi>());
 
   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);
 
   99   EXPECT_EQ(texture, 
nullptr);
 
  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));
 
  107   texture = test_api->GetFakeTexture(
texture_id);
 
  109   EXPECT_EQ(texture->user_data,
 
  110             std::get_if<PixelBufferTexture>(pixel_buffer_texture.get()));
 
  115   EXPECT_TRUE(success);
 
  116   EXPECT_EQ(texture->mark_count, 3);
 
  118   fml::AutoResetWaitableEvent unregister_latch;
 
  120   unregister_latch.Wait();
 
  122   texture = test_api->GetFakeTexture(
texture_id);
 
  123   EXPECT_EQ(texture, 
nullptr);
 
  124   EXPECT_EQ(test_api->textures_size(), 
static_cast<size_t>(0));
 
  129 TEST(TextureRegistrarTest, UnregisterInvalidTexture) {
 
  130   auto dummy_registrar_handle =
 
  136   fml::AutoResetWaitableEvent latch;
 
  143 TEST(TextureRegistrarTest, MarkFrameAvailableInvalidTexture) {
 
  144   auto dummy_registrar_handle =
 
  151   EXPECT_FALSE(success);
 
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
 
const FlutterDesktopPixelBuffer *(* FlutterDesktopPixelBufferTextureCallback)(size_t width, size_t height, void *user_data)
 
FlutterDesktopBinaryReply callback
 
TEST(FlutterEngineTest, CreateDestroy)
 
FlutterDesktopPixelBufferTextureCallback callback
 
FlutterDesktopPixelBufferTextureConfig pixel_buffer_config
 
FlutterDesktopPixelBufferTextureCallback texture_callback