OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/texture_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "gpu/command_buffer/service/feature_info.h" | 8 #include "gpu/command_buffer/service/feature_info.h" |
9 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" |
10 #include "gpu/command_buffer/service/memory_tracking.h" | 10 #include "gpu/command_buffer/service/memory_tracking.h" |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 static const GLuint kService1Id = 11; | 361 static const GLuint kService1Id = 11; |
362 | 362 |
363 TextureTestBase() | 363 TextureTestBase() |
364 : feature_info_(new FeatureInfo()) { | 364 : feature_info_(new FeatureInfo()) { |
365 } | 365 } |
366 virtual ~TextureTestBase() { | 366 virtual ~TextureTestBase() { |
367 texture_ = NULL; | 367 texture_ = NULL; |
368 } | 368 } |
369 | 369 |
370 protected: | 370 protected: |
371 void SetUpBase(MemoryTracker* memory_tracker) { | 371 void SetUpBase(MemoryTracker* memory_tracker, std::string extensions) { |
372 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 372 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
373 ::gfx::GLInterface::SetGLInterface(gl_.get()); | 373 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
| 374 |
| 375 if (!extensions.empty()) { |
| 376 TestHelper::SetupFeatureInfoInitExpectations(gl_.get(), |
| 377 extensions.c_str()); |
| 378 feature_info_->Initialize(NULL); |
| 379 } |
| 380 |
374 manager_.reset(new TextureManager( | 381 manager_.reset(new TextureManager( |
375 memory_tracker, feature_info_.get(), | 382 memory_tracker, feature_info_.get(), |
376 kMaxTextureSize, kMaxCubeMapTextureSize)); | 383 kMaxTextureSize, kMaxCubeMapTextureSize)); |
377 decoder_.reset(new ::testing::StrictMock<gles2::MockGLES2Decoder>()); | 384 decoder_.reset(new ::testing::StrictMock<gles2::MockGLES2Decoder>()); |
378 manager_->CreateTexture(kClient1Id, kService1Id); | 385 manager_->CreateTexture(kClient1Id, kService1Id); |
379 texture_ = manager_->GetTexture(kClient1Id); | 386 texture_ = manager_->GetTexture(kClient1Id); |
380 ASSERT_TRUE(texture_.get() != NULL); | 387 ASSERT_TRUE(texture_.get() != NULL); |
381 } | 388 } |
382 | 389 |
383 virtual void TearDown() { | 390 virtual void TearDown() { |
(...skipping 27 matching lines...) Expand all Loading... |
411 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | 418 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
412 scoped_refptr<FeatureInfo> feature_info_; | 419 scoped_refptr<FeatureInfo> feature_info_; |
413 scoped_ptr<TextureManager> manager_; | 420 scoped_ptr<TextureManager> manager_; |
414 scoped_ptr<MockGLES2Decoder> decoder_; | 421 scoped_ptr<MockGLES2Decoder> decoder_; |
415 scoped_refptr<Texture> texture_; | 422 scoped_refptr<Texture> texture_; |
416 }; | 423 }; |
417 | 424 |
418 class TextureTest : public TextureTestBase { | 425 class TextureTest : public TextureTestBase { |
419 protected: | 426 protected: |
420 virtual void SetUp() { | 427 virtual void SetUp() { |
421 SetUpBase(NULL); | 428 SetUpBase(NULL, std::string()); |
422 } | 429 } |
423 }; | 430 }; |
424 | 431 |
425 class TextureMemoryTrackerTest : public TextureTestBase { | 432 class TextureMemoryTrackerTest : public TextureTestBase { |
426 protected: | 433 protected: |
427 virtual void SetUp() { | 434 virtual void SetUp() { |
428 mock_memory_tracker_ = new StrictMock<MockMemoryTracker>(); | 435 mock_memory_tracker_ = new StrictMock<MockMemoryTracker>(); |
429 SetUpBase(mock_memory_tracker_.get()); | 436 SetUpBase(mock_memory_tracker_.get(), std::string()); |
430 } | 437 } |
431 | 438 |
432 scoped_refptr<MockMemoryTracker> mock_memory_tracker_; | 439 scoped_refptr<MockMemoryTracker> mock_memory_tracker_; |
433 }; | 440 }; |
434 | 441 |
435 #define EXPECT_MEMORY_ALLOCATION_CHANGE(old_size, new_size, pool) \ | 442 #define EXPECT_MEMORY_ALLOCATION_CHANGE(old_size, new_size, pool) \ |
436 EXPECT_CALL(*mock_memory_tracker_, \ | 443 EXPECT_CALL(*mock_memory_tracker_, \ |
437 TrackMemoryAllocatedChange(old_size, new_size, pool)) \ | 444 TrackMemoryAllocatedChange(old_size, new_size, pool)) \ |
438 .Times(1) \ | 445 .Times(1) \ |
439 .RetiresOnSaturation() \ | 446 .RetiresOnSaturation() \ |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 manager_->AddToSignature(texture_, GL_TEXTURE_2D, 1, &signature2); | 1283 manager_->AddToSignature(texture_, GL_TEXTURE_2D, 1, &signature2); |
1277 EXPECT_EQ(signature1, signature2); | 1284 EXPECT_EQ(signature1, signature2); |
1278 | 1285 |
1279 // Check the set was acutally getting different signatures. | 1286 // Check the set was acutally getting different signatures. |
1280 EXPECT_EQ(11u, string_set.size()); | 1287 EXPECT_EQ(11u, string_set.size()); |
1281 } | 1288 } |
1282 | 1289 |
1283 class SaveRestoreTextureTest : public TextureTest { | 1290 class SaveRestoreTextureTest : public TextureTest { |
1284 public: | 1291 public: |
1285 virtual void SetUp() { | 1292 virtual void SetUp() { |
1286 TextureTest::SetUp(); | 1293 TextureTest::SetUpBase(NULL, "GL_OES_EGL_image_external"); |
1287 manager_->CreateTexture(kClient2Id, kService2Id); | 1294 manager_->CreateTexture(kClient2Id, kService2Id); |
1288 texture2_ = manager_->GetTexture(kClient2Id); | 1295 texture2_ = manager_->GetTexture(kClient2Id); |
1289 } | 1296 } |
1290 | 1297 |
1291 virtual void TearDown() { | 1298 virtual void TearDown() { |
1292 if (texture2_.get()) { | 1299 if (texture2_.get()) { |
1293 GLuint client_id = 0; | 1300 GLuint client_id = 0; |
1294 // If it's not in the manager then setting texture2_ to NULL will | 1301 // If it's not in the manager then setting texture2_ to NULL will |
1295 // delete the texture. | 1302 // delete the texture. |
1296 if (!manager_->GetClientId(texture2_->service_id(), &client_id)) { | 1303 if (!manager_->GetClientId(texture2_->service_id(), &client_id)) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 EXPECT_TRUE(texture->GetLevelSize(target, level, &info.width, | 1380 EXPECT_TRUE(texture->GetLevelSize(target, level, &info.width, |
1374 &info.height)); | 1381 &info.height)); |
1375 EXPECT_TRUE(texture->GetLevelType(target, level, &info.type, | 1382 EXPECT_TRUE(texture->GetLevelType(target, level, &info.type, |
1376 &info.format)); | 1383 &info.format)); |
1377 info.cleared = texture->IsLevelCleared(target, level); | 1384 info.cleared = texture->IsLevelCleared(target, level); |
1378 return info; | 1385 return info; |
1379 } | 1386 } |
1380 | 1387 |
1381 TextureDefinition* Save(Texture* texture) { | 1388 TextureDefinition* Save(Texture* texture) { |
1382 EXPECT_CALL(*gl_, GenTextures(_, _)) | 1389 EXPECT_CALL(*gl_, GenTextures(_, _)) |
1383 .WillOnce(SetArgumentPointee<1>(kService2Id)); | 1390 .WillOnce(SetArgumentPointee<1>(kEmptyTextureServiceId)); |
1384 TextureDefinition* definition = manager_->Save(texture); | 1391 TextureDefinition* definition = manager_->Save(texture); |
1385 EXPECT_TRUE(definition != NULL); | 1392 EXPECT_TRUE(definition != NULL); |
1386 return definition; | 1393 return definition; |
1387 } | 1394 } |
1388 | 1395 |
1389 void Restore(Texture* texture, TextureDefinition* definition) { | 1396 void Restore(Texture* texture, TextureDefinition* definition) { |
1390 EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(texture->service_id()))) | 1397 EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(texture->service_id()))) |
1391 .Times(1).RetiresOnSaturation(); | 1398 .Times(1).RetiresOnSaturation(); |
1392 EXPECT_CALL(*gl_, | 1399 EXPECT_CALL(*gl_, |
1393 BindTexture(definition->target(), definition->service_id())) | 1400 BindTexture(definition->target(), definition->service_id())) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 Restore(texture2_, definition.release()); | 1469 Restore(texture2_, definition.release()); |
1463 | 1470 |
1464 // See if we can clear the previously uncleared level now. | 1471 // See if we can clear the previously uncleared level now. |
1465 EXPECT_EQ(level0, GetLevelInfo(texture2_.get(), GL_TEXTURE_RECTANGLE_ARB, 0)); | 1472 EXPECT_EQ(level0, GetLevelInfo(texture2_.get(), GL_TEXTURE_RECTANGLE_ARB, 0)); |
1466 EXPECT_CALL(*decoder_, ClearLevel(_, _, _, _, _, _, _, _, _)) | 1473 EXPECT_CALL(*decoder_, ClearLevel(_, _, _, _, _, _, _, _, _)) |
1467 .WillRepeatedly(Return(true)); | 1474 .WillRepeatedly(Return(true)); |
1468 EXPECT_TRUE(manager_->ClearTextureLevel( | 1475 EXPECT_TRUE(manager_->ClearTextureLevel( |
1469 decoder_.get(), texture2_, GL_TEXTURE_RECTANGLE_ARB, 0)); | 1476 decoder_.get(), texture2_, GL_TEXTURE_RECTANGLE_ARB, 0)); |
1470 } | 1477 } |
1471 | 1478 |
| 1479 TEST_F(SaveRestoreTextureTest, SaveRestoreStreamTexture) { |
| 1480 manager_->SetTarget(texture_, GL_TEXTURE_EXTERNAL_OES); |
| 1481 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), texture_->target()); |
| 1482 texture_->SetStreamTexture(true); |
| 1483 GLuint service_id = texture_->service_id(); |
| 1484 scoped_ptr<TextureDefinition> definition(Save(texture_)); |
| 1485 EXPECT_FALSE(texture_->IsStreamTexture()); |
| 1486 manager_->SetTarget(texture2_, GL_TEXTURE_EXTERNAL_OES); |
| 1487 Restore(texture2_, definition.release()); |
| 1488 EXPECT_TRUE(texture2_->IsStreamTexture()); |
| 1489 EXPECT_TRUE(texture2_->IsImmutable()); |
| 1490 EXPECT_EQ(service_id, texture2_->service_id()); |
| 1491 } |
| 1492 |
1472 TEST_F(SaveRestoreTextureTest, SaveRestoreCube) { | 1493 TEST_F(SaveRestoreTextureTest, SaveRestoreCube) { |
1473 manager_->SetTarget(texture_, GL_TEXTURE_CUBE_MAP); | 1494 manager_->SetTarget(texture_, GL_TEXTURE_CUBE_MAP); |
1474 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_CUBE_MAP), texture_->target()); | 1495 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_CUBE_MAP), texture_->target()); |
1475 LevelInfo face0(GL_TEXTURE_CUBE_MAP_POSITIVE_X, | 1496 LevelInfo face0(GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
1476 GL_RGBA, | 1497 GL_RGBA, |
1477 1, | 1498 1, |
1478 1, | 1499 1, |
1479 1, | 1500 1, |
1480 0, | 1501 0, |
1481 GL_UNSIGNED_BYTE, | 1502 GL_UNSIGNED_BYTE, |
(...skipping 18 matching lines...) Expand all Loading... |
1500 EXPECT_EQ(face0, | 1521 EXPECT_EQ(face0, |
1501 GetLevelInfo(texture2_.get(), GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)); | 1522 GetLevelInfo(texture2_.get(), GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)); |
1502 EXPECT_EQ(face5, | 1523 EXPECT_EQ(face5, |
1503 GetLevelInfo(texture2_.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0)); | 1524 GetLevelInfo(texture2_.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0)); |
1504 } | 1525 } |
1505 | 1526 |
1506 } // namespace gles2 | 1527 } // namespace gles2 |
1507 } // namespace gpu | 1528 } // namespace gpu |
1508 | 1529 |
1509 | 1530 |
OLD | NEW |