5#include "flutter/common/graphics/texture.h"
9#include "flutter/flow/testing/mock_texture.h"
10#include "gmock/gmock.h"
11#include "gtest/gtest.h"
19struct TestContextListener :
public ContextListener {
20 TestContextListener(uintptr_t p_id,
22 int_closure p_destroy)
25 virtual ~TestContextListener() =
default;
31 void OnGrContextCreated()
override {
create(
id); }
33 void OnGrContextDestroyed()
override {
destroy(
id); }
37TEST(TextureRegistryTest, UnregisterTextureCallbackTriggered) {
39 auto mock_texture1 = std::make_shared<MockTexture>(0);
40 auto mock_texture2 = std::make_shared<MockTexture>(1);
44 ASSERT_EQ(registry.
GetTexture(0), mock_texture1);
45 ASSERT_EQ(registry.
GetTexture(1), mock_texture2);
46 ASSERT_FALSE(mock_texture1->unregistered());
47 ASSERT_FALSE(mock_texture2->unregistered());
51 ASSERT_TRUE(mock_texture1->unregistered());
52 ASSERT_FALSE(mock_texture2->unregistered());
56 ASSERT_TRUE(mock_texture1->unregistered());
57 ASSERT_TRUE(mock_texture2->unregistered());
60TEST(TextureRegistryTest, GrContextCallbackTriggered) {
62 auto mock_texture1 = std::make_shared<MockTexture>(0);
63 auto mock_texture2 = std::make_shared<MockTexture>(1);
67 ASSERT_FALSE(mock_texture1->gr_context_created());
68 ASSERT_FALSE(mock_texture2->gr_context_created());
69 ASSERT_FALSE(mock_texture1->gr_context_destroyed());
70 ASSERT_FALSE(mock_texture2->gr_context_destroyed());
73 ASSERT_TRUE(mock_texture1->gr_context_created());
74 ASSERT_TRUE(mock_texture2->gr_context_created());
78 ASSERT_FALSE(mock_texture1->gr_context_destroyed());
79 ASSERT_TRUE(mock_texture2->gr_context_created());
82TEST(TextureRegistryTest, RegisterTextureTwice) {
84 auto mock_texture1 = std::make_shared<MockTexture>(0);
85 auto mock_texture2 = std::make_shared<MockTexture>(0);
88 ASSERT_EQ(registry.
GetTexture(0), mock_texture1);
90 ASSERT_EQ(registry.
GetTexture(0), mock_texture2);
91 ASSERT_FALSE(mock_texture1->unregistered());
92 ASSERT_FALSE(mock_texture2->unregistered());
96 ASSERT_FALSE(mock_texture1->unregistered());
97 ASSERT_TRUE(mock_texture2->unregistered());
100TEST(TextureRegistryTest, ReuseSameTextureSlot) {
102 auto mock_texture1 = std::make_shared<MockTexture>(0);
103 auto mock_texture2 = std::make_shared<MockTexture>(0);
106 ASSERT_EQ(registry.
GetTexture(0), mock_texture1);
110 ASSERT_TRUE(mock_texture1->unregistered());
111 ASSERT_FALSE(mock_texture2->unregistered());
114 ASSERT_EQ(registry.
GetTexture(0), mock_texture2);
118 ASSERT_TRUE(mock_texture1->unregistered());
119 ASSERT_TRUE(mock_texture2->unregistered());
122TEST(TextureRegistryTest, CallsOnGrContextCreatedInInsertionOrder) {
124 std::vector<int> create_order;
125 std::vector<int> destroy_order;
126 auto create = [&](
int id) { create_order.push_back(
id); };
127 auto destroy = [&](
int id) { destroy_order.push_back(
id); };
128 auto a = std::make_shared<TestContextListener>(5,
create,
destroy);
129 auto b = std::make_shared<TestContextListener>(4,
create,
destroy);
130 auto c = std::make_shared<TestContextListener>(3,
create,
destroy);
137 EXPECT_THAT(create_order, ::testing::ElementsAre(5, 4, 3));
138 EXPECT_THAT(destroy_order, ::testing::ElementsAre(5, 4, 3));
void OnGrContextDestroyed()
void OnGrContextCreated()
void RegisterTexture(const std::shared_ptr< Texture > &texture)
void RegisterContextListener(uintptr_t id, std::weak_ptr< ContextListener > image)
std::shared_ptr< Texture > GetTexture(int64_t id)
void UnregisterTexture(int64_t id)
Dart_NativeFunction function
TEST(DisplayListComplexity, EmptyDisplayList)