Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: mojo/ui/gl_renderer_unittest.cc

Issue 1556803002: Add helpers for creating UI components. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-13
Patch Set: address feedback Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/ui/gl_renderer.cc ('k') | mojo/ui/gl_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium 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 "base/bind.h"
6 #include "base/message_loop/message_loop.h"
7 #include "mojo/gpu/gl_context.h"
8 #include "mojo/gpu/gl_texture.h"
9 #include "mojo/public/cpp/application/application_impl.h"
10 #include "mojo/public/cpp/application/application_test_base.h"
11 #include "mojo/services/geometry/interfaces/geometry.mojom.h"
12 #include "mojo/services/gfx/composition/interfaces/resources.mojom.h"
13 #include "mojo/ui/gl_renderer.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace {
17
18 static const base::TimeDelta kDefaultMessageDelay =
19 base::TimeDelta::FromMilliseconds(20);
20
21 class GLRendererTest : public mojo::test::ApplicationTestBase {
22 public:
23 GLRendererTest() : weak_factory_(this) {}
24 ~GLRendererTest() override {}
25
26 void SetUp() override {
27 mojo::test::ApplicationTestBase::SetUp();
28 gl_context_ = mojo::GLContext::CreateOffscreen(
29 mojo::MakeProxy(application_impl()->CreateApplicationConnector())
30 .get());
31 quit_message_loop_callback_ = base::Bind(
32 &GLRendererTest::QuitMessageLoopCallback, weak_factory_.GetWeakPtr());
33 }
34
35 void QuitMessageLoopCallback() { base::MessageLoop::current()->Quit(); }
36
37 void KickMessageLoop() {
38 base::MessageLoop::current()->PostDelayedTask(
39 FROM_HERE, quit_message_loop_callback_, kDefaultMessageDelay);
40 base::MessageLoop::current()->Run();
41 }
42
43 protected:
44 base::WeakPtr<mojo::GLContext> gl_context_;
45 base::Closure quit_message_loop_callback_;
46 base::WeakPtrFactory<GLRendererTest> weak_factory_;
47
48 private:
49 DISALLOW_COPY_AND_ASSIGN(GLRendererTest);
50 };
51
52 TEST_F(GLRendererTest, GetTextureOnce) {
53 mojo::ui::GLRenderer renderer(gl_context_);
54 mojo::Size size;
55 size.width = 100;
56 size.height = 100;
57
58 std::unique_ptr<mojo::GLTexture> texture = renderer.GetTexture(size);
59 EXPECT_NE(texture.get(), nullptr);
60
61 mojo::gfx::composition::ResourcePtr resource =
62 renderer.BindTextureResource(std::move(texture));
63 EXPECT_NE(resource.get(), nullptr);
64 EXPECT_NE(resource->get_mailbox_texture().get(), nullptr);
65 EXPECT_FALSE(resource->get_mailbox_texture()->mailbox_name.is_null());
66 EXPECT_TRUE(resource->get_mailbox_texture()->size->Equals(size));
67 EXPECT_NE(resource->get_mailbox_texture()->sync_point, 0u);
68 EXPECT_NE(resource->get_mailbox_texture()->callback.get(), nullptr);
69 }
70
71 TEST_F(GLRendererTest, GetTextureTwiceSameSize) {
72 mojo::ui::GLRenderer renderer(gl_context_);
73 mojo::Size size;
74 size.width = 100;
75 size.height = 100;
76
77 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size);
78 EXPECT_NE(texture1.get(), nullptr);
79
80 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size);
81 EXPECT_NE(texture2.get(), nullptr);
82
83 EXPECT_NE(texture2.get(), texture1.get());
84 EXPECT_NE(texture2->texture_id(), texture1->texture_id());
85
86 mojo::gfx::composition::ResourcePtr resource1 =
87 renderer.BindTextureResource(std::move(texture1));
88 EXPECT_NE(resource1.get(), nullptr);
89 EXPECT_NE(resource1->get_mailbox_texture().get(), nullptr);
90 EXPECT_FALSE(resource1->get_mailbox_texture()->mailbox_name.is_null());
91 EXPECT_TRUE(resource1->get_mailbox_texture()->size->Equals(size));
92 EXPECT_NE(resource1->get_mailbox_texture()->sync_point, 0u);
93 EXPECT_NE(resource1->get_mailbox_texture()->callback.get(), nullptr);
94
95 mojo::gfx::composition::ResourcePtr resource2 =
96 renderer.BindTextureResource(std::move(texture2));
97 EXPECT_NE(resource2.get(), nullptr);
98 EXPECT_NE(resource2->get_mailbox_texture().get(), nullptr);
99 EXPECT_FALSE(resource2->get_mailbox_texture()->mailbox_name.is_null());
100 EXPECT_TRUE(resource2->get_mailbox_texture()->size->Equals(size));
101 EXPECT_NE(resource2->get_mailbox_texture()->sync_point, 0u);
102 EXPECT_NE(resource2->get_mailbox_texture()->callback.get(), nullptr);
103
104 EXPECT_NE(resource2->get_mailbox_texture()->sync_point,
105 resource1->get_mailbox_texture()->sync_point);
106 }
107
108 TEST_F(GLRendererTest, GetTextureAfterRecycleSameSize) {
109 mojo::ui::GLRenderer renderer(gl_context_);
110 mojo::Size size;
111 size.width = 100;
112 size.height = 100;
113
114 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size);
115 EXPECT_NE(texture1.get(), nullptr);
116 mojo::GLTexture* original_texture = texture1.get();
117
118 // Return the texture.
119 mojo::gfx::composition::ResourcePtr resource1 =
120 renderer.BindTextureResource(std::move(texture1));
121 EXPECT_NE(resource1.get(), nullptr);
122 resource1->get_mailbox_texture()->callback->OnMailboxTextureReleased();
123
124 KickMessageLoop();
125
126 // Get a texture of the same size, it should be the same one as before.
127 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size);
128 EXPECT_EQ(texture2.get(), original_texture);
129 }
130
131 TEST_F(GLRendererTest, GetTextureAfterRecycleDifferentSize) {
132 mojo::ui::GLRenderer renderer(gl_context_);
133 mojo::Size size1;
134 size1.width = 100;
135 size1.height = 100;
136 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size1);
137 EXPECT_NE(texture1.get(), nullptr);
138 EXPECT_TRUE(texture1->size().Equals(size1));
139
140 // Return the texture.
141 mojo::gfx::composition::ResourcePtr resource1 =
142 renderer.BindTextureResource(std::move(texture1));
143 EXPECT_NE(resource1.get(), nullptr);
144 resource1->get_mailbox_texture()->callback->OnMailboxTextureReleased();
145
146 KickMessageLoop();
147
148 // Get a texture of the a different size, it should be a new one
149 // with the new size.
150 mojo::Size size2;
151 size2.width = size1.width - 1;
152 size2.height = size1.height - 1;
153 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size2);
154 EXPECT_NE(texture2.get(), nullptr);
155 EXPECT_TRUE(texture2->size().Equals(size2));
156 }
157
158 TEST_F(GLRendererTest, GetTextureReleasedGlContext) {
159 gl_context_->Destroy();
160
161 mojo::ui::GLRenderer renderer(gl_context_);
162 mojo::Size size;
163 size.width = 100;
164 size.height = 100;
165
166 std::unique_ptr<mojo::GLTexture> texture = renderer.GetTexture(size);
167 EXPECT_EQ(texture.get(), nullptr);
168 }
169
170 TEST_F(GLRendererTest, BindTextureResourceReleasedGlContext) {
171 mojo::ui::GLRenderer renderer(gl_context_);
172 mojo::Size size;
173 size.width = 100;
174 size.height = 100;
175
176 std::unique_ptr<mojo::GLTexture> texture = renderer.GetTexture(size);
177 EXPECT_NE(texture.get(), nullptr);
178
179 gl_context_->Destroy();
180
181 mojo::gfx::composition::ResourcePtr resource =
182 renderer.BindTextureResource(std::move(texture));
183 EXPECT_EQ(resource.get(), nullptr);
184 }
185
186 TEST_F(GLRendererTest, RecycledAfterReleasedGlContext) {
187 mojo::ui::GLRenderer renderer(gl_context_);
188 mojo::Size size;
189 size.width = 100;
190 size.height = 100;
191
192 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size);
193 EXPECT_NE(texture1.get(), nullptr);
194
195 mojo::gfx::composition::ResourcePtr resource1 =
196 renderer.BindTextureResource(std::move(texture1));
197 EXPECT_NE(resource1.get(), nullptr);
198
199 gl_context_->Destroy();
200 resource1->get_mailbox_texture()->callback->OnMailboxTextureReleased();
201
202 KickMessageLoop();
203
204 // Get a texture of the same size, should be null due to the released context.
205 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size);
206 EXPECT_EQ(texture2.get(), nullptr);
207 }
208
209 } // namespace
OLDNEW
« no previous file with comments | « mojo/ui/gl_renderer.cc ('k') | mojo/ui/gl_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698