| OLD | NEW |
| 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 28 matching lines...) Expand all Loading... |
| 54 mojo::ui::GLRenderer renderer(gl_context_); | 56 mojo::ui::GLRenderer renderer(gl_context_); |
| 55 mojo::Size size; | 57 mojo::Size size; |
| 56 size.width = 100; | 58 size.width = 100; |
| 57 size.height = 100; | 59 size.height = 100; |
| 58 | 60 |
| 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)); |
| 66 |
| 64 EXPECT_NE(resource.get(), nullptr); | 67 EXPECT_NE(resource.get(), nullptr); |
| 65 EXPECT_NE(resource->get_mailbox_texture().get(), nullptr); | 68 EXPECT_NE(resource->get_mailbox_texture().get(), nullptr); |
| 66 EXPECT_FALSE(resource->get_mailbox_texture()->mailbox_name.is_null()); | 69 EXPECT_FALSE(resource->get_mailbox_texture()->mailbox_name.is_null()); |
| 67 EXPECT_TRUE(resource->get_mailbox_texture()->size->Equals(size)); | 70 EXPECT_TRUE(resource->get_mailbox_texture()->size->Equals(size)); |
| 68 EXPECT_NE(resource->get_mailbox_texture()->sync_point, 0u); | 71 EXPECT_NE(resource->get_mailbox_texture()->sync_point, 0u); |
| 69 EXPECT_NE(resource->get_mailbox_texture()->callback.get(), nullptr); | 72 EXPECT_TRUE(resource->get_mailbox_texture()->callback.is_valid()); |
| 70 } | 73 } |
| 71 | 74 |
| 72 TEST_F(GLRendererTest, GetTextureTwiceSameSize) { | 75 TEST_F(GLRendererTest, GetTextureTwiceSameSize) { |
| 73 mojo::ui::GLRenderer renderer(gl_context_); | 76 mojo::ui::GLRenderer renderer(gl_context_); |
| 74 mojo::Size size; | 77 mojo::Size size; |
| 75 size.width = 100; | 78 size.width = 100; |
| 76 size.height = 100; | 79 size.height = 100; |
| 77 | 80 |
| 78 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size); | 81 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size); |
| 79 EXPECT_NE(texture1.get(), nullptr); | 82 EXPECT_NE(texture1.get(), nullptr); |
| 80 | 83 |
| 81 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size); | 84 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size); |
| 82 EXPECT_NE(texture2.get(), nullptr); | 85 EXPECT_NE(texture2.get(), nullptr); |
| 83 | 86 |
| 84 EXPECT_NE(texture2.get(), texture1.get()); | 87 EXPECT_NE(texture2.get(), texture1.get()); |
| 85 EXPECT_NE(texture2->texture_id(), texture1->texture_id()); | 88 EXPECT_NE(texture2->texture_id(), texture1->texture_id()); |
| 86 | 89 |
| 87 mojo::gfx::composition::ResourcePtr resource1 = | 90 mojo::gfx::composition::ResourcePtr resource1 = |
| 88 renderer.BindTextureResource(std::move(texture1)); | 91 renderer.BindTextureResource(std::move(texture1)); |
| 89 EXPECT_NE(resource1.get(), nullptr); | 92 EXPECT_NE(resource1.get(), nullptr); |
| 90 EXPECT_NE(resource1->get_mailbox_texture().get(), nullptr); | 93 EXPECT_NE(resource1->get_mailbox_texture().get(), nullptr); |
| 91 EXPECT_FALSE(resource1->get_mailbox_texture()->mailbox_name.is_null()); | 94 EXPECT_FALSE(resource1->get_mailbox_texture()->mailbox_name.is_null()); |
| 92 EXPECT_TRUE(resource1->get_mailbox_texture()->size->Equals(size)); | 95 EXPECT_TRUE(resource1->get_mailbox_texture()->size->Equals(size)); |
| 93 EXPECT_NE(resource1->get_mailbox_texture()->sync_point, 0u); | 96 EXPECT_NE(resource1->get_mailbox_texture()->sync_point, 0u); |
| 94 EXPECT_NE(resource1->get_mailbox_texture()->callback.get(), nullptr); | 97 EXPECT_TRUE(resource1->get_mailbox_texture()->callback.is_valid()); |
| 95 | 98 |
| 96 mojo::gfx::composition::ResourcePtr resource2 = | 99 mojo::gfx::composition::ResourcePtr resource2 = |
| 97 renderer.BindTextureResource(std::move(texture2)); | 100 renderer.BindTextureResource(std::move(texture2)); |
| 98 EXPECT_NE(resource2.get(), nullptr); | 101 EXPECT_NE(resource2.get(), nullptr); |
| 99 EXPECT_NE(resource2->get_mailbox_texture().get(), nullptr); | 102 EXPECT_NE(resource2->get_mailbox_texture().get(), nullptr); |
| 100 EXPECT_FALSE(resource2->get_mailbox_texture()->mailbox_name.is_null()); | 103 EXPECT_FALSE(resource2->get_mailbox_texture()->mailbox_name.is_null()); |
| 101 EXPECT_TRUE(resource2->get_mailbox_texture()->size->Equals(size)); | 104 EXPECT_TRUE(resource2->get_mailbox_texture()->size->Equals(size)); |
| 102 EXPECT_NE(resource2->get_mailbox_texture()->sync_point, 0u); | 105 EXPECT_NE(resource2->get_mailbox_texture()->sync_point, 0u); |
| 103 EXPECT_NE(resource2->get_mailbox_texture()->callback.get(), nullptr); | 106 EXPECT_TRUE(resource2->get_mailbox_texture()->callback.is_valid()); |
| 104 | 107 |
| 105 EXPECT_NE(resource2->get_mailbox_texture()->sync_point, | 108 EXPECT_NE(resource2->get_mailbox_texture()->sync_point, |
| 106 resource1->get_mailbox_texture()->sync_point); | 109 resource1->get_mailbox_texture()->sync_point); |
| 107 } | 110 } |
| 108 | 111 |
| 109 TEST_F(GLRendererTest, GetTextureAfterRecycleSameSize) { | 112 TEST_F(GLRendererTest, GetTextureAfterRecycleSameSize) { |
| 110 mojo::ui::GLRenderer renderer(gl_context_); | 113 mojo::ui::GLRenderer renderer(gl_context_); |
| 111 mojo::Size size; | 114 mojo::Size size; |
| 112 size.width = 100; | 115 size.width = 100; |
| 113 size.height = 100; | 116 size.height = 100; |
| 114 | 117 |
| 115 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size); | 118 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size); |
| 116 EXPECT_NE(texture1.get(), nullptr); | 119 EXPECT_NE(texture1.get(), nullptr); |
| 117 mojo::GLTexture* original_texture = texture1.get(); | 120 mojo::GLTexture* original_texture = texture1.get(); |
| 118 | 121 |
| 119 // Return the texture. | 122 // Return the texture. |
| 120 mojo::gfx::composition::ResourcePtr resource1 = | 123 mojo::gfx::composition::ResourcePtr resource1 = |
| 121 renderer.BindTextureResource(std::move(texture1)); | 124 renderer.BindTextureResource(std::move(texture1)); |
| 122 EXPECT_NE(resource1.get(), nullptr); | 125 EXPECT_NE(resource1.get(), nullptr); |
| 123 resource1->get_mailbox_texture()->callback->OnMailboxTextureReleased(); | 126 MailboxTextureCallbackPtr::Create( |
| 127 std::move(resource1->get_mailbox_texture()->callback)) |
| 128 ->OnMailboxTextureReleased(); |
| 124 | 129 |
| 125 KickMessageLoop(); | 130 KickMessageLoop(); |
| 126 | 131 |
| 127 // Get a texture of the same size, it should be the same one as before. | 132 // 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); | 133 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size); |
| 129 EXPECT_EQ(texture2.get(), original_texture); | 134 EXPECT_EQ(texture2.get(), original_texture); |
| 130 } | 135 } |
| 131 | 136 |
| 132 TEST_F(GLRendererTest, GetTextureAfterRecycleDifferentSize) { | 137 TEST_F(GLRendererTest, GetTextureAfterRecycleDifferentSize) { |
| 133 mojo::ui::GLRenderer renderer(gl_context_); | 138 mojo::ui::GLRenderer renderer(gl_context_); |
| 134 mojo::Size size1; | 139 mojo::Size size1; |
| 135 size1.width = 100; | 140 size1.width = 100; |
| 136 size1.height = 100; | 141 size1.height = 100; |
| 137 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size1); | 142 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size1); |
| 138 EXPECT_NE(texture1.get(), nullptr); | 143 EXPECT_NE(texture1.get(), nullptr); |
| 139 EXPECT_TRUE(texture1->size().Equals(size1)); | 144 EXPECT_TRUE(texture1->size().Equals(size1)); |
| 140 | 145 |
| 141 // Return the texture. | 146 // Return the texture. |
| 142 mojo::gfx::composition::ResourcePtr resource1 = | 147 mojo::gfx::composition::ResourcePtr resource1 = |
| 143 renderer.BindTextureResource(std::move(texture1)); | 148 renderer.BindTextureResource(std::move(texture1)); |
| 144 EXPECT_NE(resource1.get(), nullptr); | 149 EXPECT_NE(resource1.get(), nullptr); |
| 145 resource1->get_mailbox_texture()->callback->OnMailboxTextureReleased(); | 150 MailboxTextureCallbackPtr::Create( |
| 151 std::move(resource1->get_mailbox_texture()->callback)) |
| 152 ->OnMailboxTextureReleased(); |
| 146 | 153 |
| 147 KickMessageLoop(); | 154 KickMessageLoop(); |
| 148 | 155 |
| 149 // Get a texture of the a different size, it should be a new one | 156 // Get a texture of the a different size, it should be a new one |
| 150 // with the new size. | 157 // with the new size. |
| 151 mojo::Size size2; | 158 mojo::Size size2; |
| 152 size2.width = size1.width - 1; | 159 size2.width = size1.width - 1; |
| 153 size2.height = size1.height - 1; | 160 size2.height = size1.height - 1; |
| 154 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size2); | 161 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size2); |
| 155 EXPECT_NE(texture2.get(), nullptr); | 162 EXPECT_NE(texture2.get(), nullptr); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 size.height = 100; | 198 size.height = 100; |
| 192 | 199 |
| 193 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size); | 200 std::unique_ptr<mojo::GLTexture> texture1 = renderer.GetTexture(size); |
| 194 EXPECT_NE(texture1.get(), nullptr); | 201 EXPECT_NE(texture1.get(), nullptr); |
| 195 | 202 |
| 196 mojo::gfx::composition::ResourcePtr resource1 = | 203 mojo::gfx::composition::ResourcePtr resource1 = |
| 197 renderer.BindTextureResource(std::move(texture1)); | 204 renderer.BindTextureResource(std::move(texture1)); |
| 198 EXPECT_NE(resource1.get(), nullptr); | 205 EXPECT_NE(resource1.get(), nullptr); |
| 199 | 206 |
| 200 gl_context_->Destroy(); | 207 gl_context_->Destroy(); |
| 201 resource1->get_mailbox_texture()->callback->OnMailboxTextureReleased(); | 208 MailboxTextureCallbackPtr::Create( |
| 209 std::move(resource1->get_mailbox_texture()->callback)) |
| 210 ->OnMailboxTextureReleased(); |
| 202 | 211 |
| 203 KickMessageLoop(); | 212 KickMessageLoop(); |
| 204 | 213 |
| 205 // Get a texture of the same size, should be null due to the released context. | 214 // 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); | 215 std::unique_ptr<mojo::GLTexture> texture2 = renderer.GetTexture(size); |
| 207 EXPECT_EQ(texture2.get(), nullptr); | 216 EXPECT_EQ(texture2.get(), nullptr); |
| 208 } | 217 } |
| 209 | 218 |
| 210 } // namespace | 219 } // namespace |
| OLD | NEW |