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/feature_info.h" | 7 #include "gpu/command_buffer/service/feature_info.h" |
8 #include "gpu/command_buffer/service/mailbox_synchronizer.h" | 8 #include "gpu/command_buffer/service/mailbox_synchronizer.h" |
9 #include "gpu/command_buffer/service/texture_manager.h" | 9 #include "gpu/command_buffer/service/texture_manager.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/gl/gl_context_stub.h" | |
12 #include "ui/gl/gl_mock.h" | 11 #include "ui/gl/gl_mock.h" |
13 #include "ui/gl/gl_surface_stub.h" | |
14 | 12 |
15 namespace gpu { | 13 namespace gpu { |
16 namespace gles2 { | 14 namespace gles2 { |
17 | 15 |
18 using namespace ::testing; | 16 using namespace ::testing; |
19 | 17 |
20 class MailboxManagerTest : public testing::Test { | 18 class MailboxManagerTest : public testing::Test { |
21 public: | 19 public: |
22 MailboxManagerTest() {} | 20 MailboxManagerTest() {} |
23 virtual ~MailboxManagerTest() {} | 21 virtual ~MailboxManagerTest() {} |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 MailboxManagerSyncTest() {} | 181 MailboxManagerSyncTest() {} |
184 virtual ~MailboxManagerSyncTest() {} | 182 virtual ~MailboxManagerSyncTest() {} |
185 | 183 |
186 protected: | 184 protected: |
187 virtual void SetUp() { | 185 virtual void SetUp() { |
188 MailboxSynchronizer::Initialize(); | 186 MailboxSynchronizer::Initialize(); |
189 MailboxManagerTest::SetUp(); | 187 MailboxManagerTest::SetUp(); |
190 manager2_ = new MailboxManager; | 188 manager2_ = new MailboxManager; |
191 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 189 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
192 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); | 190 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); |
193 context_ = new gfx::GLContextStub(); | |
194 surface_ = new gfx::GLSurfaceStub(); | |
195 context_->MakeCurrent(surface_); | |
196 } | 191 } |
197 | 192 |
198 Texture* DefineTexture() { | 193 Texture* DefineTexture() { |
199 Texture* texture = CreateTexture(); | 194 Texture* texture = CreateTexture(); |
200 const GLsizei levels_needed = TextureManager::ComputeMipMapCount( | 195 const GLsizei levels_needed = TextureManager::ComputeMipMapCount( |
201 GL_TEXTURE_2D, kMaxTextureWidth, kMaxTextureHeight, kMaxTextureDepth); | 196 GL_TEXTURE_2D, kMaxTextureWidth, kMaxTextureHeight, kMaxTextureDepth); |
202 SetTarget(texture, GL_TEXTURE_2D, levels_needed); | 197 SetTarget(texture, GL_TEXTURE_2D, levels_needed); |
203 SetLevelInfo(texture, | 198 SetLevelInfo(texture, |
204 GL_TEXTURE_2D, | 199 GL_TEXTURE_2D, |
205 0, | 200 0, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 .Times(1) | 242 .Times(1) |
248 .RetiresOnSaturation(); | 243 .RetiresOnSaturation(); |
249 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kCurrentTexture)) | 244 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kCurrentTexture)) |
250 .Times(1) | 245 .Times(1) |
251 .RetiresOnSaturation(); | 246 .RetiresOnSaturation(); |
252 } | 247 } |
253 | 248 |
254 virtual void TearDown() { | 249 virtual void TearDown() { |
255 MailboxManagerTest::TearDown(); | 250 MailboxManagerTest::TearDown(); |
256 MailboxSynchronizer::Terminate(); | 251 MailboxSynchronizer::Terminate(); |
257 context_->ReleaseCurrent(NULL); | |
258 ::gfx::MockGLInterface::SetGLInterface(NULL); | 252 ::gfx::MockGLInterface::SetGLInterface(NULL); |
259 gl_.reset(); | 253 gl_.reset(); |
260 } | 254 } |
261 | 255 |
262 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | 256 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
263 scoped_refptr<MailboxManager> manager2_; | 257 scoped_refptr<MailboxManager> manager2_; |
264 scoped_refptr<gfx::GLContext> context_; | |
265 scoped_refptr<gfx::GLSurface> surface_; | |
266 | 258 |
267 private: | 259 private: |
268 DISALLOW_COPY_AND_ASSIGN(MailboxManagerSyncTest); | 260 DISALLOW_COPY_AND_ASSIGN(MailboxManagerSyncTest); |
269 }; | 261 }; |
270 | 262 |
271 TEST_F(MailboxManagerSyncTest, ProduceDestroy) { | 263 TEST_F(MailboxManagerSyncTest, ProduceDestroy) { |
272 Texture* texture = DefineTexture(); | 264 Texture* texture = DefineTexture(); |
273 Mailbox name = Mailbox::Generate(); | 265 Mailbox name = Mailbox::Generate(); |
274 | 266 |
275 InSequence sequence; | 267 InSequence sequence; |
276 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); | 268 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); |
277 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); | 269 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
278 | 270 |
279 DestroyTexture(texture); | 271 DestroyTexture(texture); |
280 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); | 272 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
281 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); | 273 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); |
282 } | 274 } |
283 | 275 |
284 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) { | 276 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) { |
285 InSequence sequence; | 277 InSequence sequence; |
286 | 278 |
287 Texture* texture = DefineTexture(); | 279 Texture* texture = DefineTexture(); |
288 Mailbox name = Mailbox::Generate(); | 280 Mailbox name = Mailbox::Generate(); |
289 | 281 |
290 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); | 282 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); |
291 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); | 283 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
292 | 284 |
293 // Synchronize | 285 // Synchronize |
| 286 EXPECT_CALL(*gl_, Flush()).Times(1); |
294 manager_->PushTextureUpdates(); | 287 manager_->PushTextureUpdates(); |
295 manager2_->PullTextureUpdates(); | 288 manager2_->PullTextureUpdates(); |
296 | 289 |
297 DestroyTexture(texture); | 290 DestroyTexture(texture); |
298 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); | 291 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
299 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); | 292 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); |
300 } | 293 } |
301 | 294 |
302 // Duplicates a texture into a second manager instance, and then | 295 // Duplicates a texture into a second manager instance, and then |
303 // makes sure a redefinition becomes visible there too. | 296 // makes sure a redefinition becomes visible there too. |
304 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) { | 297 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) { |
305 const GLuint kNewTextureId = 1234; | 298 const GLuint kNewTextureId = 1234; |
306 InSequence sequence; | 299 InSequence sequence; |
307 | 300 |
308 Texture* texture = DefineTexture(); | 301 Texture* texture = DefineTexture(); |
309 Mailbox name = Mailbox::Generate(); | 302 Mailbox name = Mailbox::Generate(); |
310 | 303 |
311 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); | 304 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); |
312 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); | 305 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
313 | 306 |
314 // Synchronize | 307 // Synchronize |
| 308 EXPECT_CALL(*gl_, Flush()).Times(1); |
315 manager_->PushTextureUpdates(); | 309 manager_->PushTextureUpdates(); |
316 manager2_->PullTextureUpdates(); | 310 manager2_->PullTextureUpdates(); |
317 | 311 |
318 EXPECT_CALL(*gl_, GenTextures(1, _)) | 312 EXPECT_CALL(*gl_, GenTextures(1, _)) |
319 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 313 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
320 SetupUpdateTexParamExpectations( | 314 SetupUpdateTexParamExpectations( |
321 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 315 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
322 Texture* new_texture = manager2_->ConsumeTexture(GL_TEXTURE_2D, name); | 316 Texture* new_texture = manager2_->ConsumeTexture(GL_TEXTURE_2D, name); |
323 EXPECT_FALSE(new_texture == NULL); | 317 EXPECT_FALSE(new_texture == NULL); |
324 EXPECT_NE(texture, new_texture); | 318 EXPECT_NE(texture, new_texture); |
325 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 319 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
326 | 320 |
327 // Resize original texture | 321 // Resize original texture |
328 SetLevelInfo(texture, | 322 SetLevelInfo(texture, |
329 GL_TEXTURE_2D, | 323 GL_TEXTURE_2D, |
330 0, | 324 0, |
331 GL_RGBA, | 325 GL_RGBA, |
332 16, | 326 16, |
333 32, | 327 32, |
334 1, | 328 1, |
335 0, | 329 0, |
336 GL_RGBA, | 330 GL_RGBA, |
337 GL_UNSIGNED_BYTE, | 331 GL_UNSIGNED_BYTE, |
338 true); | 332 true); |
339 // Should have been orphaned | 333 // Should have been orphaned |
340 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); | 334 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); |
341 | 335 |
342 // Synchronize again | 336 // Synchronize again |
| 337 EXPECT_CALL(*gl_, Flush()).Times(1); |
343 manager_->PushTextureUpdates(); | 338 manager_->PushTextureUpdates(); |
344 SetupUpdateTexParamExpectations( | 339 SetupUpdateTexParamExpectations( |
345 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 340 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
346 manager2_->PullTextureUpdates(); | 341 manager2_->PullTextureUpdates(); |
347 GLsizei width, height; | 342 GLsizei width, height; |
348 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height); | 343 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height); |
349 EXPECT_EQ(16, width); | 344 EXPECT_EQ(16, width); |
350 EXPECT_EQ(32, height); | 345 EXPECT_EQ(32, height); |
351 | 346 |
352 // Should have gotten a new attachment | 347 // Should have gotten a new attachment |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 Mailbox name1 = Mailbox::Generate(); | 389 Mailbox name1 = Mailbox::Generate(); |
395 Texture* texture2 = DefineTexture(); | 390 Texture* texture2 = DefineTexture(); |
396 Mailbox name2 = Mailbox::Generate(); | 391 Mailbox name2 = Mailbox::Generate(); |
397 Texture* new_texture1 = NULL; | 392 Texture* new_texture1 = NULL; |
398 Texture* new_texture2 = NULL; | 393 Texture* new_texture2 = NULL; |
399 | 394 |
400 manager_->ProduceTexture(GL_TEXTURE_2D, name1, texture1); | 395 manager_->ProduceTexture(GL_TEXTURE_2D, name1, texture1); |
401 manager2_->ProduceTexture(GL_TEXTURE_2D, name2, texture2); | 396 manager2_->ProduceTexture(GL_TEXTURE_2D, name2, texture2); |
402 | 397 |
403 // Make visible. | 398 // Make visible. |
| 399 EXPECT_CALL(*gl_, Flush()).Times(2); |
404 manager_->PushTextureUpdates(); | 400 manager_->PushTextureUpdates(); |
405 manager2_->PushTextureUpdates(); | 401 manager2_->PushTextureUpdates(); |
406 | 402 |
407 // Create textures in the other manager instances for texture1 and texture2, | 403 // Create textures in the other manager instances for texture1 and texture2, |
408 // respectively to create a real sharing scenario. Otherwise, there would | 404 // respectively to create a real sharing scenario. Otherwise, there would |
409 // never be conflicting updates/pushes. | 405 // never be conflicting updates/pushes. |
410 { | 406 { |
411 InSequence sequence; | 407 InSequence sequence; |
412 EXPECT_CALL(*gl_, GenTextures(1, _)) | 408 EXPECT_CALL(*gl_, GenTextures(1, _)) |
413 .WillOnce(SetArgPointee<1>(kNewTextureId1)); | 409 .WillOnce(SetArgPointee<1>(kNewTextureId1)); |
(...skipping 18 matching lines...) Expand all Loading... |
432 manager_->PullTextureUpdates(); | 428 manager_->PullTextureUpdates(); |
433 | 429 |
434 // Make a change to texture2 | 430 // Make a change to texture2 |
435 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture2->mag_filter()); | 431 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture2->mag_filter()); |
436 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), | 432 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), |
437 SetParameter(texture2, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); | 433 SetParameter(texture2, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); |
438 | 434 |
439 Mock::VerifyAndClearExpectations(gl_.get()); | 435 Mock::VerifyAndClearExpectations(gl_.get()); |
440 | 436 |
441 // Synchronize in both directions | 437 // Synchronize in both directions |
| 438 EXPECT_CALL(*gl_, Flush()).Times(2); |
442 manager_->PushTextureUpdates(); | 439 manager_->PushTextureUpdates(); |
443 manager2_->PushTextureUpdates(); | 440 manager2_->PushTextureUpdates(); |
444 // manager1 should see the change to texture2 mag_filter being applied. | 441 // manager1 should see the change to texture2 mag_filter being applied. |
445 SetupUpdateTexParamExpectations( | 442 SetupUpdateTexParamExpectations( |
446 new_texture2->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); | 443 new_texture2->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); |
447 manager_->PullTextureUpdates(); | 444 manager_->PullTextureUpdates(); |
448 // manager2 should see the change to texture1 min_filter being applied. | 445 // manager2 should see the change to texture1 min_filter being applied. |
449 SetupUpdateTexParamExpectations( | 446 SetupUpdateTexParamExpectations( |
450 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 447 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
451 manager2_->PullTextureUpdates(); | 448 manager2_->PullTextureUpdates(); |
452 | 449 |
453 DestroyTexture(texture1); | 450 DestroyTexture(texture1); |
454 DestroyTexture(texture2); | 451 DestroyTexture(texture2); |
455 DestroyTexture(new_texture1); | 452 DestroyTexture(new_texture1); |
456 DestroyTexture(new_texture2); | 453 DestroyTexture(new_texture2); |
457 } | 454 } |
458 | 455 |
459 // TODO: different texture into same mailbox | 456 // TODO: different texture into same mailbox |
460 | 457 |
461 // TODO: same texture, multiple mailboxes | 458 // TODO: same texture, multiple mailboxes |
462 | 459 |
463 // TODO: Produce incomplete texture | 460 // TODO: Produce incomplete texture |
464 | 461 |
465 // TODO: Texture::level_infos_[][].size() | 462 // TODO: Texture::level_infos_[][].size() |
466 | 463 |
467 // TODO: unsupported targets and formats | 464 // TODO: unsupported targets and formats |
468 | 465 |
469 } // namespace gles2 | 466 } // namespace gles2 |
470 } // namespace gpu | 467 } // namespace gpu |
OLD | NEW |