| 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/gpu_service_test.h" | |
| 9 #include "gpu/command_buffer/service/mailbox_synchronizer.h" | 8 #include "gpu/command_buffer/service/mailbox_synchronizer.h" |
| 10 #include "gpu/command_buffer/service/texture_manager.h" | 9 #include "gpu/command_buffer/service/texture_manager.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/gl/gl_context_stub.h" | 11 #include "ui/gl/gl_context_stub.h" |
| 13 #include "ui/gl/gl_mock.h" | 12 #include "ui/gl/gl_mock.h" |
| 14 #include "ui/gl/gl_surface_stub.h" | 13 #include "ui/gl/gl_surface_stub.h" |
| 15 | 14 |
| 16 namespace gpu { | 15 namespace gpu { |
| 17 namespace gles2 { | 16 namespace gles2 { |
| 18 | 17 |
| 19 using namespace ::testing; | 18 using namespace ::testing; |
| 20 | 19 |
| 21 class MailboxManagerTest : public GpuServiceTest { | 20 class MailboxManagerTest : public testing::Test { |
| 22 public: | 21 public: |
| 23 MailboxManagerTest() : initialized_synchronizer_(false) {} | 22 MailboxManagerTest() {} |
| 24 virtual ~MailboxManagerTest() {} | 23 virtual ~MailboxManagerTest() {} |
| 25 | 24 |
| 26 protected: | 25 protected: |
| 27 virtual void SetUp() { | 26 virtual void SetUp() { |
| 28 GpuServiceTest::SetUp(); | 27 testing::Test::SetUp(); |
| 29 feature_info_ = new FeatureInfo; | 28 feature_info_ = new FeatureInfo; |
| 30 manager_ = new MailboxManager; | 29 manager_ = new MailboxManager; |
| 31 } | 30 } |
| 32 | 31 |
| 33 virtual void SetUpWithSynchronizer() { | |
| 34 GpuServiceTest::SetUp(); | |
| 35 MailboxSynchronizer::Initialize(); | |
| 36 initialized_synchronizer_ = true; | |
| 37 feature_info_ = new FeatureInfo; | |
| 38 manager_ = new MailboxManager; | |
| 39 } | |
| 40 | |
| 41 virtual void TearDown() { | |
| 42 if (initialized_synchronizer_) | |
| 43 MailboxSynchronizer::Terminate(); | |
| 44 GpuServiceTest::TearDown(); | |
| 45 } | |
| 46 | |
| 47 Texture* CreateTexture() { | 32 Texture* CreateTexture() { |
| 48 return new Texture(1); | 33 return new Texture(1); |
| 49 } | 34 } |
| 50 | 35 |
| 51 void SetTarget(Texture* texture, GLenum target, GLuint max_level) { | 36 void SetTarget(Texture* texture, GLenum target, GLuint max_level) { |
| 52 texture->SetTarget(NULL, target, max_level); | 37 texture->SetTarget(NULL, target, max_level); |
| 53 } | 38 } |
| 54 | 39 |
| 55 void SetLevelInfo( | 40 void SetLevelInfo( |
| 56 Texture* texture, | 41 Texture* texture, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 81 return texture->SetParameteri(feature_info_, pname, param); | 66 return texture->SetParameteri(feature_info_, pname, param); |
| 82 } | 67 } |
| 83 | 68 |
| 84 void DestroyTexture(Texture* texture) { | 69 void DestroyTexture(Texture* texture) { |
| 85 delete texture; | 70 delete texture; |
| 86 } | 71 } |
| 87 | 72 |
| 88 scoped_refptr<MailboxManager> manager_; | 73 scoped_refptr<MailboxManager> manager_; |
| 89 | 74 |
| 90 private: | 75 private: |
| 91 bool initialized_synchronizer_; | |
| 92 scoped_refptr<FeatureInfo> feature_info_; | 76 scoped_refptr<FeatureInfo> feature_info_; |
| 93 | 77 |
| 94 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest); | 78 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest); |
| 95 }; | 79 }; |
| 96 | 80 |
| 97 // Tests basic produce/consume behavior. | 81 // Tests basic produce/consume behavior. |
| 98 TEST_F(MailboxManagerTest, Basic) { | 82 TEST_F(MailboxManagerTest, Basic) { |
| 99 Texture* texture = CreateTexture(); | 83 Texture* texture = CreateTexture(); |
| 100 | 84 |
| 101 Mailbox name = Mailbox::Generate(); | 85 Mailbox name = Mailbox::Generate(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 const GLsizei kMaxTextureHeight = 64; | 178 const GLsizei kMaxTextureHeight = 64; |
| 195 const GLsizei kMaxTextureDepth = 1; | 179 const GLsizei kMaxTextureDepth = 1; |
| 196 | 180 |
| 197 class MailboxManagerSyncTest : public MailboxManagerTest { | 181 class MailboxManagerSyncTest : public MailboxManagerTest { |
| 198 public: | 182 public: |
| 199 MailboxManagerSyncTest() {} | 183 MailboxManagerSyncTest() {} |
| 200 virtual ~MailboxManagerSyncTest() {} | 184 virtual ~MailboxManagerSyncTest() {} |
| 201 | 185 |
| 202 protected: | 186 protected: |
| 203 virtual void SetUp() { | 187 virtual void SetUp() { |
| 204 MailboxManagerTest::SetUpWithSynchronizer(); | 188 MailboxSynchronizer::Initialize(); |
| 189 MailboxManagerTest::SetUp(); |
| 205 manager2_ = new MailboxManager; | 190 manager2_ = new MailboxManager; |
| 191 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
| 192 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); |
| 206 context_ = new gfx::GLContextStub(); | 193 context_ = new gfx::GLContextStub(); |
| 207 surface_ = new gfx::GLSurfaceStub(); | 194 surface_ = new gfx::GLSurfaceStub(); |
| 208 context_->MakeCurrent(surface_); | 195 context_->MakeCurrent(surface_); |
| 209 } | 196 } |
| 210 | 197 |
| 211 Texture* DefineTexture() { | 198 Texture* DefineTexture() { |
| 212 Texture* texture = CreateTexture(); | 199 Texture* texture = CreateTexture(); |
| 213 const GLsizei levels_needed = TextureManager::ComputeMipMapCount( | 200 const GLsizei levels_needed = TextureManager::ComputeMipMapCount( |
| 214 GL_TEXTURE_2D, kMaxTextureWidth, kMaxTextureHeight, kMaxTextureDepth); | 201 GL_TEXTURE_2D, kMaxTextureWidth, kMaxTextureHeight, kMaxTextureDepth); |
| 215 SetTarget(texture, GL_TEXTURE_2D, levels_needed); | 202 SetTarget(texture, GL_TEXTURE_2D, levels_needed); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 .RetiresOnSaturation(); | 245 .RetiresOnSaturation(); |
| 259 EXPECT_CALL(*gl_, Flush()) | 246 EXPECT_CALL(*gl_, Flush()) |
| 260 .Times(1) | 247 .Times(1) |
| 261 .RetiresOnSaturation(); | 248 .RetiresOnSaturation(); |
| 262 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kCurrentTexture)) | 249 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kCurrentTexture)) |
| 263 .Times(1) | 250 .Times(1) |
| 264 .RetiresOnSaturation(); | 251 .RetiresOnSaturation(); |
| 265 } | 252 } |
| 266 | 253 |
| 267 virtual void TearDown() { | 254 virtual void TearDown() { |
| 255 MailboxManagerTest::TearDown(); |
| 256 MailboxSynchronizer::Terminate(); |
| 268 context_->ReleaseCurrent(NULL); | 257 context_->ReleaseCurrent(NULL); |
| 269 MailboxManagerTest::TearDown(); | 258 ::gfx::MockGLInterface::SetGLInterface(NULL); |
| 259 gl_.reset(); |
| 270 } | 260 } |
| 271 | 261 |
| 262 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
| 272 scoped_refptr<MailboxManager> manager2_; | 263 scoped_refptr<MailboxManager> manager2_; |
| 273 scoped_refptr<gfx::GLContext> context_; | 264 scoped_refptr<gfx::GLContext> context_; |
| 274 scoped_refptr<gfx::GLSurface> surface_; | 265 scoped_refptr<gfx::GLSurface> surface_; |
| 275 | 266 |
| 276 private: | 267 private: |
| 277 DISALLOW_COPY_AND_ASSIGN(MailboxManagerSyncTest); | 268 DISALLOW_COPY_AND_ASSIGN(MailboxManagerSyncTest); |
| 278 }; | 269 }; |
| 279 | 270 |
| 280 TEST_F(MailboxManagerSyncTest, ProduceDestroy) { | 271 TEST_F(MailboxManagerSyncTest, ProduceDestroy) { |
| 281 Texture* texture = DefineTexture(); | 272 Texture* texture = DefineTexture(); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 // TODO: same texture, multiple mailboxes | 461 // TODO: same texture, multiple mailboxes |
| 471 | 462 |
| 472 // TODO: Produce incomplete texture | 463 // TODO: Produce incomplete texture |
| 473 | 464 |
| 474 // TODO: Texture::level_infos_[][].size() | 465 // TODO: Texture::level_infos_[][].size() |
| 475 | 466 |
| 476 // TODO: unsupported targets and formats | 467 // TODO: unsupported targets and formats |
| 477 | 468 |
| 478 } // namespace gles2 | 469 } // namespace gles2 |
| 479 } // namespace gpu | 470 } // namespace gpu |
| OLD | NEW |