Flutter Engine
texture_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/flow/texture.h"
6 
7 #include "flutter/flow/testing/mock_texture.h"
8 #include "gtest/gtest.h"
9 
10 namespace flutter {
11 namespace testing {
12 
13 TEST(TextureRegistryTest, UnregisterTextureCallbackTriggered) {
14  TextureRegistry registry;
15  auto mock_texture1 = std::make_shared<MockTexture>(0);
16  auto mock_texture2 = std::make_shared<MockTexture>(1);
17 
18  registry.RegisterTexture(mock_texture1);
19  registry.RegisterTexture(mock_texture2);
20  ASSERT_EQ(registry.GetTexture(0), mock_texture1);
21  ASSERT_EQ(registry.GetTexture(1), mock_texture2);
22  ASSERT_FALSE(mock_texture1->unregistered());
23  ASSERT_FALSE(mock_texture2->unregistered());
24 
25  registry.UnregisterTexture(0);
26  ASSERT_EQ(registry.GetTexture(0), nullptr);
27  ASSERT_TRUE(mock_texture1->unregistered());
28  ASSERT_FALSE(mock_texture2->unregistered());
29 
30  registry.UnregisterTexture(1);
31  ASSERT_EQ(registry.GetTexture(1), nullptr);
32  ASSERT_TRUE(mock_texture1->unregistered());
33  ASSERT_TRUE(mock_texture2->unregistered());
34 }
35 
36 TEST(TextureRegistryTest, GrContextCallbackTriggered) {
37  TextureRegistry registry;
38  auto mock_texture1 = std::make_shared<MockTexture>(0);
39  auto mock_texture2 = std::make_shared<MockTexture>(1);
40 
41  registry.RegisterTexture(mock_texture1);
42  registry.RegisterTexture(mock_texture2);
43  ASSERT_FALSE(mock_texture1->gr_context_created());
44  ASSERT_FALSE(mock_texture2->gr_context_created());
45  ASSERT_FALSE(mock_texture1->gr_context_destroyed());
46  ASSERT_FALSE(mock_texture2->gr_context_destroyed());
47 
48  registry.OnGrContextCreated();
49  ASSERT_TRUE(mock_texture1->gr_context_created());
50  ASSERT_TRUE(mock_texture2->gr_context_created());
51 
52  registry.UnregisterTexture(0);
53  registry.OnGrContextDestroyed();
54  ASSERT_FALSE(mock_texture1->gr_context_destroyed());
55  ASSERT_TRUE(mock_texture2->gr_context_created());
56 }
57 
58 TEST(TextureRegistryTest, RegisterTextureTwice) {
59  TextureRegistry registry;
60  auto mock_texture1 = std::make_shared<MockTexture>(0);
61  auto mock_texture2 = std::make_shared<MockTexture>(0);
62 
63  registry.RegisterTexture(mock_texture1);
64  ASSERT_EQ(registry.GetTexture(0), mock_texture1);
65  registry.RegisterTexture(mock_texture2);
66  ASSERT_EQ(registry.GetTexture(0), mock_texture2);
67  ASSERT_FALSE(mock_texture1->unregistered());
68  ASSERT_FALSE(mock_texture2->unregistered());
69 
70  registry.UnregisterTexture(0);
71  ASSERT_EQ(registry.GetTexture(0), nullptr);
72  ASSERT_FALSE(mock_texture1->unregistered());
73  ASSERT_TRUE(mock_texture2->unregistered());
74 }
75 
76 TEST(TextureRegistryTest, ReuseSameTextureSlot) {
77  TextureRegistry registry;
78  auto mock_texture1 = std::make_shared<MockTexture>(0);
79  auto mock_texture2 = std::make_shared<MockTexture>(0);
80 
81  registry.RegisterTexture(mock_texture1);
82  ASSERT_EQ(registry.GetTexture(0), mock_texture1);
83 
84  registry.UnregisterTexture(0);
85  ASSERT_EQ(registry.GetTexture(0), nullptr);
86  ASSERT_TRUE(mock_texture1->unregistered());
87  ASSERT_FALSE(mock_texture2->unregistered());
88 
89  registry.RegisterTexture(mock_texture2);
90  ASSERT_EQ(registry.GetTexture(0), mock_texture2);
91 
92  registry.UnregisterTexture(0);
93  ASSERT_EQ(registry.GetTexture(0), nullptr);
94  ASSERT_TRUE(mock_texture1->unregistered());
95  ASSERT_TRUE(mock_texture2->unregistered());
96 }
97 
98 } // namespace testing
99 } // namespace flutter
void RegisterTexture(std::shared_ptr< Texture > texture)
Definition: texture.cc:15
void UnregisterTexture(int64_t id)
Definition: texture.cc:22
std::shared_ptr< Texture > GetTexture(int64_t id)
Definition: texture.cc:43
TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithNoMutations)