OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "gpu/command_buffer/service/mailbox_manager.h" | 5 #include "gpu/command_buffer/service/mailbox_manager.h" |
6 | 6 |
| 7 #include "gpu/command_buffer/service/mailbox_synchronizer.h" |
7 #include "gpu/command_buffer/service/texture_manager.h" | 8 #include "gpu/command_buffer/service/texture_manager.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/gl/gl_mock.h" |
9 | 11 |
10 namespace gpu { | 12 namespace gpu { |
11 namespace gles2 { | 13 namespace gles2 { |
12 | 14 |
| 15 using namespace ::testing; |
| 16 |
13 class MailboxManagerTest : public testing::Test { | 17 class MailboxManagerTest : public testing::Test { |
14 public: | 18 public: |
15 MailboxManagerTest() : manager_(new MailboxManager()) {} | 19 MailboxManagerTest() {} |
16 virtual ~MailboxManagerTest() {} | 20 virtual ~MailboxManagerTest() {} |
17 | 21 |
18 protected: | 22 protected: |
| 23 virtual void SetUp() { |
| 24 testing::Test::SetUp(); |
| 25 manager_ = new MailboxManager; |
| 26 } |
| 27 |
19 Texture* CreateTexture() { | 28 Texture* CreateTexture() { |
20 return new Texture(0); | 29 return new Texture(0); |
21 } | 30 } |
22 | 31 |
| 32 void SetTarget(Texture* texture, GLenum target, GLuint max_level) { |
| 33 texture->SetTarget(NULL, target, max_level); |
| 34 } |
| 35 |
| 36 void SetLevelInfo( |
| 37 Texture* texture, |
| 38 GLenum target, |
| 39 GLint level, |
| 40 GLenum internal_format, |
| 41 GLsizei width, |
| 42 GLsizei height, |
| 43 GLsizei depth, |
| 44 GLint border, |
| 45 GLenum format, |
| 46 GLenum type, |
| 47 bool cleared) { |
| 48 texture->SetLevelInfo(NULL, |
| 49 target, |
| 50 level, |
| 51 internal_format, |
| 52 width, |
| 53 height, |
| 54 depth, |
| 55 border, |
| 56 format, |
| 57 type, |
| 58 cleared); |
| 59 } |
| 60 |
23 void DestroyTexture(Texture* texture) { | 61 void DestroyTexture(Texture* texture) { |
24 delete texture; | 62 delete texture; |
25 } | 63 } |
26 | 64 |
27 scoped_refptr<MailboxManager> manager_; | 65 scoped_refptr<MailboxManager> manager_; |
28 | 66 |
29 private: | 67 private: |
30 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest); | 68 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest); |
31 }; | 69 }; |
32 | 70 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 157 |
120 // Destroy texture1, shouldn't affect name2. | 158 // Destroy texture1, shouldn't affect name2. |
121 DestroyTexture(texture1); | 159 DestroyTexture(texture1); |
122 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name1)); | 160 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name1)); |
123 EXPECT_EQ(texture2, manager_->ConsumeTexture(0, name2)); | 161 EXPECT_EQ(texture2, manager_->ConsumeTexture(0, name2)); |
124 | 162 |
125 DestroyTexture(texture2); | 163 DestroyTexture(texture2); |
126 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name2)); | 164 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name2)); |
127 } | 165 } |
128 | 166 |
| 167 const GLsizei kMaxTextureWidth = 64; |
| 168 const GLsizei kMaxTextureHeight = 64; |
| 169 const GLsizei kMaxTextureDepth = 1; |
| 170 |
| 171 class MailboxManagerSyncTest : public MailboxManagerTest { |
| 172 public: |
| 173 MailboxManagerSyncTest() {} |
| 174 virtual ~MailboxManagerSyncTest() {} |
| 175 |
| 176 protected: |
| 177 virtual void SetUp() { |
| 178 MailboxSynchronizer::Initialize(); |
| 179 MailboxManagerTest::SetUp(); |
| 180 manager2_ = new MailboxManager; |
| 181 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
| 182 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); |
| 183 } |
| 184 |
| 185 Texture* DefineTexture() { |
| 186 Texture* texture = CreateTexture(); |
| 187 const GLsizei levels_needed = TextureManager::ComputeMipMapCount( |
| 188 GL_TEXTURE_2D, kMaxTextureWidth, kMaxTextureHeight, kMaxTextureDepth); |
| 189 SetTarget(texture, GL_TEXTURE_2D, levels_needed); |
| 190 SetLevelInfo(texture, |
| 191 GL_TEXTURE_2D, |
| 192 0, |
| 193 GL_RGBA, |
| 194 1, |
| 195 1, |
| 196 1, |
| 197 0, |
| 198 GL_RGBA, |
| 199 GL_UNSIGNED_BYTE, |
| 200 true); |
| 201 return texture; |
| 202 } |
| 203 |
| 204 virtual void TearDown() { |
| 205 MailboxManagerTest::TearDown(); |
| 206 MailboxSynchronizer::Terminate(); |
| 207 ::gfx::MockGLInterface::SetGLInterface(NULL); |
| 208 gl_.reset(); |
| 209 } |
| 210 |
| 211 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
| 212 scoped_refptr<MailboxManager> manager2_; |
| 213 |
| 214 private: |
| 215 DISALLOW_COPY_AND_ASSIGN(MailboxManagerSyncTest); |
| 216 }; |
| 217 |
| 218 TEST_F(MailboxManagerSyncTest, ProduceDestroy) { |
| 219 Texture* texture = DefineTexture(); |
| 220 Mailbox name = Mailbox::Generate(); |
| 221 |
| 222 InSequence sequence; |
| 223 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); |
| 224 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 225 |
| 226 DestroyTexture(texture); |
| 227 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 228 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 229 } |
| 230 |
| 231 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) { |
| 232 const EGLDisplay kDisplay = 0; |
| 233 const EGLContext kContext = 0; |
| 234 const EGLImageKHR kEglImage = reinterpret_cast<EGLImageKHR>(0xFEFEFEFE); |
| 235 InSequence sequence; |
| 236 |
| 237 Texture* texture = DefineTexture(); |
| 238 Mailbox name = Mailbox::Generate(); |
| 239 |
| 240 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); |
| 241 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 242 |
| 243 // Synchronize |
| 244 EXPECT_CALL(*gl_, EGLGetCurrentContext()).WillOnce(Return(kContext)); |
| 245 EXPECT_CALL(*gl_, EGLCreateImageKHR(_, _, _, _, _)) |
| 246 .WillOnce(Return(kEglImage)); |
| 247 manager_->PushTextureUpdates(); |
| 248 manager2_->PullTextureUpdates(); |
| 249 |
| 250 EXPECT_CALL(*gl_, EGLDestroyImageKHR(kDisplay, kEglImage)) |
| 251 .WillOnce(Return(EGL_TRUE)); |
| 252 DestroyTexture(texture); |
| 253 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 254 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 255 } |
| 256 |
| 257 TEST_F(MailboxManagerSyncTest, ProduceConsume) { |
| 258 const EGLDisplay kDisplay = 0; |
| 259 const EGLContext kContext = 0; |
| 260 const EGLImageKHR kEglImage = reinterpret_cast<EGLImageKHR>(0xFEFEFEFE); |
| 261 InSequence sequence; |
| 262 |
| 263 Texture* texture = DefineTexture(); |
| 264 Mailbox name = Mailbox::Generate(); |
| 265 |
| 266 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); |
| 267 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 268 |
| 269 // Synchronize |
| 270 EXPECT_CALL(*gl_, EGLGetCurrentContext()).WillOnce(Return(kContext)); |
| 271 EXPECT_CALL(*gl_, EGLCreateImageKHR(_, _, _, _, _)) |
| 272 .WillOnce(Return(kEglImage)); |
| 273 manager_->PushTextureUpdates(); |
| 274 manager2_->PullTextureUpdates(); |
| 275 |
| 276 Texture* new_texture = manager2_->ConsumeTexture(GL_TEXTURE_2D, name); |
| 277 EXPECT_FALSE(new_texture == NULL); |
| 278 EXPECT_NE(texture, new_texture); |
| 279 |
| 280 DestroyTexture(texture); |
| 281 // Should be still around since there is a ref from manager2. |
| 282 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 283 |
| 284 EXPECT_CALL(*gl_, EGLDestroyImageKHR(kDisplay, kEglImage)) |
| 285 .WillOnce(Return(EGL_TRUE)); |
| 286 DestroyTexture(new_texture); |
| 287 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 288 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 289 } |
| 290 |
| 291 TEST_F(MailboxManagerSyncTest, Resize) { |
| 292 const EGLDisplay kDisplay = 0; |
| 293 const EGLContext kContext = 0; |
| 294 const EGLImageKHR kEglImage = reinterpret_cast<EGLImageKHR>(0xFEFEFEFE); |
| 295 const EGLImageKHR kEglImage2 = reinterpret_cast<EGLImageKHR>(0xBABABABA); |
| 296 |
| 297 Texture* texture = DefineTexture(); |
| 298 Mailbox name = Mailbox::Generate(); |
| 299 |
| 300 InSequence sequence; |
| 301 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); |
| 302 |
| 303 // Synchronize |
| 304 EXPECT_CALL(*gl_, EGLGetCurrentContext()).WillOnce(Return(kContext)); |
| 305 EXPECT_CALL(*gl_, EGLCreateImageKHR(_, _, _, _, _)) |
| 306 .WillOnce(Return(kEglImage)); |
| 307 manager_->PushTextureUpdates(); |
| 308 manager2_->PullTextureUpdates(); |
| 309 |
| 310 // Resize |
| 311 SetLevelInfo(texture, |
| 312 GL_TEXTURE_2D, |
| 313 0, |
| 314 GL_RGBA, |
| 315 16, |
| 316 32, |
| 317 1, |
| 318 0, |
| 319 GL_RGBA, |
| 320 GL_UNSIGNED_BYTE, |
| 321 true); |
| 322 // Should have been orphaned |
| 323 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); |
| 324 |
| 325 // This should match the state from the last sync before we resized. |
| 326 Texture* new_texture = manager2_->ConsumeTexture(GL_TEXTURE_2D, name); |
| 327 GLsizei width, height; |
| 328 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height); |
| 329 EXPECT_EQ(1, width); |
| 330 EXPECT_EQ(1, height); |
| 331 |
| 332 // Synchronize |
| 333 EXPECT_CALL(*gl_, EGLGetCurrentContext()).WillOnce(Return(kContext)); |
| 334 EXPECT_CALL(*gl_, EGLCreateImageKHR(_, _, _, _, _)) |
| 335 .WillOnce(Return(kEglImage2)); |
| 336 EXPECT_CALL(*gl_, EGLDestroyImageKHR(kDisplay, kEglImage)) |
| 337 .WillOnce(Return(EGL_TRUE)); |
| 338 manager_->PushTextureUpdates(); |
| 339 manager2_->PullTextureUpdates(); |
| 340 |
| 341 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height); |
| 342 EXPECT_EQ(16, width); |
| 343 EXPECT_EQ(32, height); |
| 344 |
| 345 EXPECT_CALL(*gl_, EGLDestroyImageKHR(kDisplay, kEglImage2)) |
| 346 .WillOnce(Return(EGL_TRUE)); |
| 347 DestroyTexture(texture); |
| 348 DestroyTexture(new_texture); |
| 349 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 350 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 351 } |
| 352 |
| 353 // TODO: different texture into same mailbox |
| 354 |
| 355 // TODO: same texture, multiple mailboxes |
| 356 |
| 357 // TODO: Produce incomplete texture |
| 358 |
| 359 // TODO: Texture::level_infos_[][].size() |
| 360 |
| 361 // TODO: unsupported targets and formats |
| 362 |
129 } // namespace gles2 | 363 } // namespace gles2 |
130 } // namespace gpu | 364 } // namespace gpu |
OLD | NEW |