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

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

Issue 1682113003: Mojo C++ bindings: Generate InterfaceHandle<> instead of InterfacePtr<>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebase ontop of master, address trung's comments 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "mojo/gpu/gl_context.h" 7 #include "mojo/gpu/gl_context.h"
8 #include "mojo/gpu/gl_texture.h" 8 #include "mojo/gpu/gl_texture.h"
9 #include "mojo/public/cpp/application/application_impl.h" 9 #include "mojo/public/cpp/application/application_impl.h"
10 #include "mojo/public/cpp/application/application_test_base.h" 10 #include "mojo/public/cpp/application/application_test_base.h"
11 #include "mojo/services/geometry/interfaces/geometry.mojom.h" 11 #include "mojo/services/geometry/interfaces/geometry.mojom.h"
12 #include "mojo/services/gfx/composition/interfaces/resources.mojom.h" 12 #include "mojo/services/gfx/composition/interfaces/resources.mojom.h"
13 #include "mojo/ui/gl_renderer.h" 13 #include "mojo/ui/gl_renderer.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using mojo::gfx::composition::MailboxTextureCallbackPtr;
17
16 namespace { 18 namespace {
17 19
18 static const base::TimeDelta kDefaultMessageDelay = 20 static const base::TimeDelta kDefaultMessageDelay =
19 base::TimeDelta::FromMilliseconds(20); 21 base::TimeDelta::FromMilliseconds(20);
20 22
21 class GLRendererTest : public mojo::test::ApplicationTestBase { 23 class GLRendererTest : public mojo::test::ApplicationTestBase {
22 public: 24 public:
23 GLRendererTest() : weak_factory_(this) {} 25 GLRendererTest() : weak_factory_(this) {}
24 ~GLRendererTest() override {} 26 ~GLRendererTest() override {}
25 27
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 std::unique_ptr<mojo::GLTexture> texture = renderer.GetTexture(size); 61 std::unique_ptr<mojo::GLTexture> texture = renderer.GetTexture(size);
60 EXPECT_NE(texture.get(), nullptr); 62 EXPECT_NE(texture.get(), nullptr);
61 63
62 mojo::gfx::composition::ResourcePtr resource = 64 mojo::gfx::composition::ResourcePtr resource =
63 renderer.BindTextureResource(std::move(texture)); 65 renderer.BindTextureResource(std::move(texture));
64 EXPECT_NE(resource.get(), nullptr); 66 EXPECT_NE(resource.get(), nullptr);
65 EXPECT_NE(resource->get_mailbox_texture().get(), nullptr); 67 EXPECT_NE(resource->get_mailbox_texture().get(), nullptr);
66 EXPECT_FALSE(resource->get_mailbox_texture()->mailbox_name.is_null()); 68 EXPECT_FALSE(resource->get_mailbox_texture()->mailbox_name.is_null());
67 EXPECT_TRUE(resource->get_mailbox_texture()->size->Equals(size)); 69 EXPECT_TRUE(resource->get_mailbox_texture()->size->Equals(size));
68 EXPECT_NE(resource->get_mailbox_texture()->sync_point, 0u); 70 EXPECT_NE(resource->get_mailbox_texture()->sync_point, 0u);
69 EXPECT_NE(resource->get_mailbox_texture()->callback.get(), nullptr); 71 EXPECT_TRUE(resource->get_mailbox_texture()->callback.is_valid());
70 } 72 }
71 73
72 TEST_F(GLRendererTest, GetTextureTwiceSameSize) { 74 TEST_F(GLRendererTest, GetTextureTwiceSameSize) {
73 mojo::ui::GLRenderer renderer(gl_context_); 75 mojo::ui::GLRenderer renderer(gl_context_);
74 mojo::Size size; 76 mojo::Size size;
75 size.width = 100; 77 size.width = 100;
76 size.height = 100; 78 size.height = 100;
77 79
78 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size); 80 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size);
79 EXPECT_NE(texture1.get(), nullptr); 81 EXPECT_NE(texture1.get(), nullptr);
80 82
81 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size); 83 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size);
82 EXPECT_NE(texture2.get(), nullptr); 84 EXPECT_NE(texture2.get(), nullptr);
83 85
84 EXPECT_NE(texture2.get(), texture1.get()); 86 EXPECT_NE(texture2.get(), texture1.get());
85 EXPECT_NE(texture2->texture_id(), texture1->texture_id()); 87 EXPECT_NE(texture2->texture_id(), texture1->texture_id());
86 88
87 mojo::gfx::composition::ResourcePtr resource1 = 89 mojo::gfx::composition::ResourcePtr resource1 =
88 renderer.BindTextureResource(std::move(texture1)); 90 renderer.BindTextureResource(std::move(texture1));
89 EXPECT_NE(resource1.get(), nullptr); 91 EXPECT_NE(resource1.get(), nullptr);
90 EXPECT_NE(resource1->get_mailbox_texture().get(), nullptr); 92 EXPECT_NE(resource1->get_mailbox_texture().get(), nullptr);
91 EXPECT_FALSE(resource1->get_mailbox_texture()->mailbox_name.is_null()); 93 EXPECT_FALSE(resource1->get_mailbox_texture()->mailbox_name.is_null());
92 EXPECT_TRUE(resource1->get_mailbox_texture()->size->Equals(size)); 94 EXPECT_TRUE(resource1->get_mailbox_texture()->size->Equals(size));
93 EXPECT_NE(resource1->get_mailbox_texture()->sync_point, 0u); 95 EXPECT_NE(resource1->get_mailbox_texture()->sync_point, 0u);
94 EXPECT_NE(resource1->get_mailbox_texture()->callback.get(), nullptr); 96 EXPECT_TRUE(resource1->get_mailbox_texture()->callback.is_valid());
95 97
96 mojo::gfx::composition::ResourcePtr resource2 = 98 mojo::gfx::composition::ResourcePtr resource2 =
97 renderer.BindTextureResource(std::move(texture2)); 99 renderer.BindTextureResource(std::move(texture2));
98 EXPECT_NE(resource2.get(), nullptr); 100 EXPECT_NE(resource2.get(), nullptr);
99 EXPECT_NE(resource2->get_mailbox_texture().get(), nullptr); 101 EXPECT_NE(resource2->get_mailbox_texture().get(), nullptr);
100 EXPECT_FALSE(resource2->get_mailbox_texture()->mailbox_name.is_null()); 102 EXPECT_FALSE(resource2->get_mailbox_texture()->mailbox_name.is_null());
101 EXPECT_TRUE(resource2->get_mailbox_texture()->size->Equals(size)); 103 EXPECT_TRUE(resource2->get_mailbox_texture()->size->Equals(size));
102 EXPECT_NE(resource2->get_mailbox_texture()->sync_point, 0u); 104 EXPECT_NE(resource2->get_mailbox_texture()->sync_point, 0u);
103 EXPECT_NE(resource2->get_mailbox_texture()->callback.get(), nullptr); 105 EXPECT_TRUE(resource2->get_mailbox_texture()->callback.is_valid());
104 106
105 EXPECT_NE(resource2->get_mailbox_texture()->sync_point, 107 EXPECT_NE(resource2->get_mailbox_texture()->sync_point,
106 resource1->get_mailbox_texture()->sync_point); 108 resource1->get_mailbox_texture()->sync_point);
107 } 109 }
108 110
109 TEST_F(GLRendererTest, GetTextureAfterRecycleSameSize) { 111 TEST_F(GLRendererTest, GetTextureAfterRecycleSameSize) {
110 mojo::ui::GLRenderer renderer(gl_context_); 112 mojo::ui::GLRenderer renderer(gl_context_);
111 mojo::Size size; 113 mojo::Size size;
112 size.width = 100; 114 size.width = 100;
113 size.height = 100; 115 size.height = 100;
114 116
115 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size); 117 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size);
116 EXPECT_NE(texture1.get(), nullptr); 118 EXPECT_NE(texture1.get(), nullptr);
117 mojo::GLTexture* original_texture = texture1.get(); 119 mojo::GLTexture* original_texture = texture1.get();
118 120
119 // Return the texture. 121 // Return the texture.
120 mojo::gfx::composition::ResourcePtr resource1 = 122 mojo::gfx::composition::ResourcePtr resource1 =
121 renderer.BindTextureResource(std::move(texture1)); 123 renderer.BindTextureResource(std::move(texture1));
122 EXPECT_NE(resource1.get(), nullptr); 124 EXPECT_NE(resource1.get(), nullptr);
123 resource1->get_mailbox_texture()->callback->OnMailboxTextureReleased(); 125 MailboxTextureCallbackPtr::Create(
126 std::move(resource1->get_mailbox_texture()->callback))
127 ->OnMailboxTextureReleased();
124 128
125 KickMessageLoop(); 129 KickMessageLoop();
126 130
127 // Get a texture of the same size, it should be the same one as before. 131 // Get a texture of the same size, it should be the same one as before.
128 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size); 132 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size);
129 EXPECT_EQ(texture2.get(), original_texture); 133 EXPECT_EQ(texture2.get(), original_texture);
130 } 134 }
131 135
132 TEST_F(GLRendererTest, GetTextureAfterRecycleDifferentSize) { 136 TEST_F(GLRendererTest, GetTextureAfterRecycleDifferentSize) {
133 mojo::ui::GLRenderer renderer(gl_context_); 137 mojo::ui::GLRenderer renderer(gl_context_);
134 mojo::Size size1; 138 mojo::Size size1;
135 size1.width = 100; 139 size1.width = 100;
136 size1.height = 100; 140 size1.height = 100;
137 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size1); 141 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size1);
138 EXPECT_NE(texture1.get(), nullptr); 142 EXPECT_NE(texture1.get(), nullptr);
139 EXPECT_TRUE(texture1->size().Equals(size1)); 143 EXPECT_TRUE(texture1->size().Equals(size1));
140 144
141 // Return the texture. 145 // Return the texture.
142 mojo::gfx::composition::ResourcePtr resource1 = 146 mojo::gfx::composition::ResourcePtr resource1 =
143 renderer.BindTextureResource(std::move(texture1)); 147 renderer.BindTextureResource(std::move(texture1));
144 EXPECT_NE(resource1.get(), nullptr); 148 EXPECT_NE(resource1.get(), nullptr);
145 resource1->get_mailbox_texture()->callback->OnMailboxTextureReleased(); 149 MailboxTextureCallbackPtr::Create(
150 std::move(resource1->get_mailbox_texture()->callback))
151 ->OnMailboxTextureReleased();
146 152
147 KickMessageLoop(); 153 KickMessageLoop();
148 154
149 // Get a texture of the a different size, it should be a new one 155 // Get a texture of the a different size, it should be a new one
150 // with the new size. 156 // with the new size.
151 mojo::Size size2; 157 mojo::Size size2;
152 size2.width = size1.width - 1; 158 size2.width = size1.width - 1;
153 size2.height = size1.height - 1; 159 size2.height = size1.height - 1;
154 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size2); 160 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size2);
155 EXPECT_NE(texture2.get(), nullptr); 161 EXPECT_NE(texture2.get(), nullptr);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 size.height = 100; 197 size.height = 100;
192 198
193 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size); 199 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size);
194 EXPECT_NE(texture1.get(), nullptr); 200 EXPECT_NE(texture1.get(), nullptr);
195 201
196 mojo::gfx::composition::ResourcePtr resource1 = 202 mojo::gfx::composition::ResourcePtr resource1 =
197 renderer.BindTextureResource(std::move(texture1)); 203 renderer.BindTextureResource(std::move(texture1));
198 EXPECT_NE(resource1.get(), nullptr); 204 EXPECT_NE(resource1.get(), nullptr);
199 205
200 gl_context_->Destroy(); 206 gl_context_->Destroy();
201 resource1->get_mailbox_texture()->callback->OnMailboxTextureReleased(); 207 MailboxTextureCallbackPtr::Create(
208 std::move(resource1->get_mailbox_texture()->callback))
209 ->OnMailboxTextureReleased();
202 210
203 KickMessageLoop(); 211 KickMessageLoop();
204 212
205 // Get a texture of the same size, should be null due to the released context. 213 // Get a texture of the same size, should be null due to the released context.
206 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size); 214 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size);
207 EXPECT_EQ(texture2.get(), nullptr); 215 EXPECT_EQ(texture2.get(), nullptr);
208 } 216 }
209 217
210 } // namespace 218 } // namespace
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_cpp_generator.py ('k') | mojo/ui/view_provider_app.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698